This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove duplicate entry
[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
3cbf51f5
DM
99static int
100S_pending_ident(pTHX);
199e78b7 101
0bd48802 102static const char ident_too_long[] = "Identifier too long";
c445ea15 103static const char commaless_variable_list[] = "comma-less variable list";
8903cb82 104
6e3aabd6 105#ifndef PERL_NO_UTF16_FILTER
acfe0abc
GS
106static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
107static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
6e3aabd6 108#endif
51371543 109
29595ff2 110#ifdef PERL_MAD
29595ff2 111# define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; }
cd81e915 112# define NEXTVAL_NEXTTOKE PL_nexttoke[PL_curforce].next_val
9ded7720 113#else
5db06880 114# define CURMAD(slot,sv)
9ded7720 115# define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
29595ff2
NC
116#endif
117
9059aa12
LW
118#define XFAKEBRACK 128
119#define XENUMMASK 127
120
39e02b42
JH
121#ifdef USE_UTF8_SCRIPTS
122# define UTF (!IN_BYTES)
2b9d42f0 123#else
746b446a 124# define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
2b9d42f0 125#endif
a0ed51b3 126
61f0cdd9 127/* In variables named $^X, these are the legal values for X.
2b92dfce
GS
128 * 1999-02-27 mjd-perl-patch@plover.com */
129#define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
130
bf4acbe4
GS
131/* On MacOS, respect nonbreaking spaces */
132#ifdef MACOS_TRADITIONAL
133#define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
134#else
135#define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
136#endif
137
ffb4593c
NT
138/* LEX_* are values for PL_lex_state, the state of the lexer.
139 * They are arranged oddly so that the guard on the switch statement
79072805
LW
140 * can get by with a single comparison (if the compiler is smart enough).
141 */
142
fb73857a 143/* #define LEX_NOTPARSING 11 is done in perl.h. */
144
b6007c36
DM
145#define LEX_NORMAL 10 /* normal code (ie not within "...") */
146#define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
147#define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
148#define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
149#define LEX_INTERPSTART 6 /* expecting the start of a $var */
150
151 /* at end of code, eg "$x" followed by: */
152#define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
153#define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
154
155#define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
156 string or after \E, $foo, etc */
157#define LEX_INTERPCONST 2 /* NOT USED */
158#define LEX_FORMLINE 1 /* expecting a format line */
159#define LEX_KNOWNEXT 0 /* next token known; just return it */
160
79072805 161
bbf60fe6 162#ifdef DEBUGGING
27da23d5 163static const char* const lex_state_names[] = {
bbf60fe6
DM
164 "KNOWNEXT",
165 "FORMLINE",
166 "INTERPCONST",
167 "INTERPCONCAT",
168 "INTERPENDMAYBE",
169 "INTERPEND",
170 "INTERPSTART",
171 "INTERPPUSH",
172 "INTERPCASEMOD",
173 "INTERPNORMAL",
174 "NORMAL"
175};
176#endif
177
79072805
LW
178#ifdef ff_next
179#undef ff_next
d48672a2
LW
180#endif
181
79072805 182#include "keywords.h"
fe14fcc3 183
ffb4593c
NT
184/* CLINE is a macro that ensures PL_copline has a sane value */
185
ae986130
LW
186#ifdef CLINE
187#undef CLINE
188#endif
57843af0 189#define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
3280af22 190
5db06880 191#ifdef PERL_MAD
29595ff2
NC
192# define SKIPSPACE0(s) skipspace0(s)
193# define SKIPSPACE1(s) skipspace1(s)
194# define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
195# define PEEKSPACE(s) skipspace2(s,0)
196#else
197# define SKIPSPACE0(s) skipspace(s)
198# define SKIPSPACE1(s) skipspace(s)
199# define SKIPSPACE2(s,tsv) skipspace(s)
200# define PEEKSPACE(s) skipspace(s)
201#endif
202
ffb4593c
NT
203/*
204 * Convenience functions to return different tokens and prime the
9cbb5ea2 205 * lexer for the next token. They all take an argument.
ffb4593c
NT
206 *
207 * TOKEN : generic token (used for '(', DOLSHARP, etc)
208 * OPERATOR : generic operator
209 * AOPERATOR : assignment operator
210 * PREBLOCK : beginning the block after an if, while, foreach, ...
211 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
212 * PREREF : *EXPR where EXPR is not a simple identifier
213 * TERM : expression term
214 * LOOPX : loop exiting command (goto, last, dump, etc)
215 * FTST : file test operator
216 * FUN0 : zero-argument function
2d2e263d 217 * FUN1 : not used, except for not, which isn't a UNIOP
ffb4593c
NT
218 * BOop : bitwise or or xor
219 * BAop : bitwise and
220 * SHop : shift operator
221 * PWop : power operator
9cbb5ea2 222 * PMop : pattern-matching operator
ffb4593c
NT
223 * Aop : addition-level operator
224 * Mop : multiplication-level operator
225 * Eop : equality-testing operator
e5edeb50 226 * Rop : relational operator <= != gt
ffb4593c
NT
227 *
228 * Also see LOP and lop() below.
229 */
230
998054bd 231#ifdef DEBUGGING /* Serve -DT. */
704d4215 232# define REPORT(retval) tokereport((I32)retval, &pl_yylval)
998054bd 233#else
bbf60fe6 234# define REPORT(retval) (retval)
998054bd
SC
235#endif
236
bbf60fe6
DM
237#define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
238#define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
239#define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
240#define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
241#define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
242#define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
243#define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
6154021b
RGS
244#define LOOPX(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
245#define FTST(f) return (pl_yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
246#define FUN0(f) return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
247#define FUN1(f) return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
248#define BOop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
249#define BAop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
250#define SHop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
251#define PWop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
252#define PMop(f) return(pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
253#define Aop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
254#define Mop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
255#define Eop(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
256#define Rop(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
2f3197b3 257
a687059c
LW
258/* This bit of chicanery makes a unary function followed by
259 * a parenthesis into a function with one argument, highest precedence.
6f33ba73
RGS
260 * The UNIDOR macro is for unary functions that can be followed by the //
261 * operator (such as C<shift // 0>).
a687059c 262 */
376fcdbf 263#define UNI2(f,x) { \
6154021b 264 pl_yylval.ival = f; \
376fcdbf
AL
265 PL_expect = x; \
266 PL_bufptr = s; \
267 PL_last_uni = PL_oldbufptr; \
268 PL_last_lop_op = f; \
269 if (*s == '(') \
270 return REPORT( (int)FUNC1 ); \
29595ff2 271 s = PEEKSPACE(s); \
376fcdbf
AL
272 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
273 }
6f33ba73
RGS
274#define UNI(f) UNI2(f,XTERM)
275#define UNIDOR(f) UNI2(f,XTERMORDORDOR)
a687059c 276
376fcdbf 277#define UNIBRACK(f) { \
6154021b 278 pl_yylval.ival = f; \
376fcdbf
AL
279 PL_bufptr = s; \
280 PL_last_uni = PL_oldbufptr; \
281 if (*s == '(') \
282 return REPORT( (int)FUNC1 ); \
29595ff2 283 s = PEEKSPACE(s); \
376fcdbf
AL
284 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
285 }
79072805 286
9f68db38 287/* grandfather return to old style */
6154021b 288#define OLDLOP(f) return(pl_yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
79072805 289
8fa7f367
JH
290#ifdef DEBUGGING
291
6154021b 292/* how to interpret the pl_yylval associated with the token */
bbf60fe6
DM
293enum token_type {
294 TOKENTYPE_NONE,
295 TOKENTYPE_IVAL,
6154021b 296 TOKENTYPE_OPNUM, /* pl_yylval.ival contains an opcode number */
bbf60fe6
DM
297 TOKENTYPE_PVAL,
298 TOKENTYPE_OPVAL,
299 TOKENTYPE_GVVAL
300};
301
6d4a66ac
NC
302static struct debug_tokens {
303 const int token;
304 enum token_type type;
305 const char *name;
306} const debug_tokens[] =
9041c2e3 307{
bbf60fe6
DM
308 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
309 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
310 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
311 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
312 { ARROW, TOKENTYPE_NONE, "ARROW" },
313 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
314 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
315 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
316 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
317 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
0d863452 318 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
bbf60fe6
DM
319 { DO, TOKENTYPE_NONE, "DO" },
320 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
321 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
322 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
323 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
324 { ELSE, TOKENTYPE_NONE, "ELSE" },
325 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
326 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
327 { FOR, TOKENTYPE_IVAL, "FOR" },
328 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
329 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
330 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
331 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
332 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
333 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
0d863452 334 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
bbf60fe6
DM
335 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
336 { IF, TOKENTYPE_IVAL, "IF" },
337 { LABEL, TOKENTYPE_PVAL, "LABEL" },
338 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
339 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
340 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
341 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
342 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
343 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
344 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
345 { MY, TOKENTYPE_IVAL, "MY" },
346 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
347 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
348 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
349 { OROP, TOKENTYPE_IVAL, "OROP" },
350 { OROR, TOKENTYPE_NONE, "OROR" },
351 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
352 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
353 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
354 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
355 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
356 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
357 { PREINC, TOKENTYPE_NONE, "PREINC" },
358 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
359 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
360 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
361 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
362 { SUB, TOKENTYPE_NONE, "SUB" },
363 { THING, TOKENTYPE_OPVAL, "THING" },
364 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
365 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
366 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
367 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
368 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
369 { USE, TOKENTYPE_IVAL, "USE" },
0d863452 370 { WHEN, TOKENTYPE_IVAL, "WHEN" },
bbf60fe6
DM
371 { WHILE, TOKENTYPE_IVAL, "WHILE" },
372 { WORD, TOKENTYPE_OPVAL, "WORD" },
be25f609 373 { YADAYADA, TOKENTYPE_IVAL, "YADAYADA" },
c35e046a 374 { 0, TOKENTYPE_NONE, NULL }
bbf60fe6
DM
375};
376
6154021b 377/* dump the returned token in rv, plus any optional arg in pl_yylval */
998054bd 378
bbf60fe6 379STATIC int
704d4215 380S_tokereport(pTHX_ I32 rv, const YYSTYPE* lvalp)
bbf60fe6 381{
97aff369 382 dVAR;
7918f24d
NC
383
384 PERL_ARGS_ASSERT_TOKEREPORT;
385
bbf60fe6 386 if (DEBUG_T_TEST) {
bd61b366 387 const char *name = NULL;
bbf60fe6 388 enum token_type type = TOKENTYPE_NONE;
f54cb97a 389 const struct debug_tokens *p;
396482e1 390 SV* const report = newSVpvs("<== ");
bbf60fe6 391
f54cb97a 392 for (p = debug_tokens; p->token; p++) {
bbf60fe6
DM
393 if (p->token == (int)rv) {
394 name = p->name;
395 type = p->type;
396 break;
397 }
398 }
399 if (name)
54667de8 400 Perl_sv_catpv(aTHX_ report, name);
bbf60fe6
DM
401 else if ((char)rv > ' ' && (char)rv < '~')
402 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
403 else if (!rv)
396482e1 404 sv_catpvs(report, "EOF");
bbf60fe6
DM
405 else
406 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
407 switch (type) {
408 case TOKENTYPE_NONE:
409 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
410 break;
411 case TOKENTYPE_IVAL:
704d4215 412 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)lvalp->ival);
bbf60fe6
DM
413 break;
414 case TOKENTYPE_OPNUM:
415 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
704d4215 416 PL_op_name[lvalp->ival]);
bbf60fe6
DM
417 break;
418 case TOKENTYPE_PVAL:
704d4215 419 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", lvalp->pval);
bbf60fe6
DM
420 break;
421 case TOKENTYPE_OPVAL:
704d4215 422 if (lvalp->opval) {
401441c0 423 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
704d4215
GG
424 PL_op_name[lvalp->opval->op_type]);
425 if (lvalp->opval->op_type == OP_CONST) {
b6007c36 426 Perl_sv_catpvf(aTHX_ report, " %s",
704d4215 427 SvPEEK(cSVOPx_sv(lvalp->opval)));
b6007c36
DM
428 }
429
430 }
401441c0 431 else
396482e1 432 sv_catpvs(report, "(opval=null)");
bbf60fe6
DM
433 break;
434 }
b6007c36 435 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
bbf60fe6
DM
436 };
437 return (int)rv;
998054bd
SC
438}
439
b6007c36
DM
440
441/* print the buffer with suitable escapes */
442
443STATIC void
15f169a1 444S_printbuf(pTHX_ const char *const fmt, const char *const s)
b6007c36 445{
396482e1 446 SV* const tmp = newSVpvs("");
7918f24d
NC
447
448 PERL_ARGS_ASSERT_PRINTBUF;
449
b6007c36
DM
450 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
451 SvREFCNT_dec(tmp);
452}
453
8fa7f367
JH
454#endif
455
ffb4593c
NT
456/*
457 * S_ao
458 *
c963b151
BD
459 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
460 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
ffb4593c
NT
461 */
462
76e3520e 463STATIC int
cea2e8a9 464S_ao(pTHX_ int toketype)
a0d0e21e 465{
97aff369 466 dVAR;
3280af22
NIS
467 if (*PL_bufptr == '=') {
468 PL_bufptr++;
a0d0e21e 469 if (toketype == ANDAND)
6154021b 470 pl_yylval.ival = OP_ANDASSIGN;
a0d0e21e 471 else if (toketype == OROR)
6154021b 472 pl_yylval.ival = OP_ORASSIGN;
c963b151 473 else if (toketype == DORDOR)
6154021b 474 pl_yylval.ival = OP_DORASSIGN;
a0d0e21e
LW
475 toketype = ASSIGNOP;
476 }
477 return toketype;
478}
479
ffb4593c
NT
480/*
481 * S_no_op
482 * When Perl expects an operator and finds something else, no_op
483 * prints the warning. It always prints "<something> found where
484 * operator expected. It prints "Missing semicolon on previous line?"
485 * if the surprise occurs at the start of the line. "do you need to
486 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
487 * where the compiler doesn't know if foo is a method call or a function.
488 * It prints "Missing operator before end of line" if there's nothing
489 * after the missing operator, or "... before <...>" if there is something
490 * after the missing operator.
491 */
492
76e3520e 493STATIC void
15f169a1 494S_no_op(pTHX_ const char *const what, char *s)
463ee0b2 495{
97aff369 496 dVAR;
9d4ba2ae
AL
497 char * const oldbp = PL_bufptr;
498 const bool is_first = (PL_oldbufptr == PL_linestart);
68dc0745 499
7918f24d
NC
500 PERL_ARGS_ASSERT_NO_OP;
501
1189a94a
GS
502 if (!s)
503 s = oldbp;
07c798fb 504 else
1189a94a 505 PL_bufptr = s;
cea2e8a9 506 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
56da5a46
RGS
507 if (ckWARN_d(WARN_SYNTAX)) {
508 if (is_first)
509 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
510 "\t(Missing semicolon on previous line?)\n");
511 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
f54cb97a 512 const char *t;
c35e046a
AL
513 for (t = PL_oldoldbufptr; (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
514 NOOP;
56da5a46
RGS
515 if (t < PL_bufptr && isSPACE(*t))
516 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
517 "\t(Do you need to predeclare %.*s?)\n",
551405c4 518 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
56da5a46
RGS
519 }
520 else {
521 assert(s >= oldbp);
522 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
551405c4 523 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
56da5a46 524 }
07c798fb 525 }
3280af22 526 PL_bufptr = oldbp;
8990e307
LW
527}
528
ffb4593c
NT
529/*
530 * S_missingterm
531 * Complain about missing quote/regexp/heredoc terminator.
d4c19fe8 532 * If it's called with NULL then it cauterizes the line buffer.
ffb4593c
NT
533 * If we're in a delimited string and the delimiter is a control
534 * character, it's reformatted into a two-char sequence like ^C.
535 * This is fatal.
536 */
537
76e3520e 538STATIC void
cea2e8a9 539S_missingterm(pTHX_ char *s)
8990e307 540{
97aff369 541 dVAR;
8990e307
LW
542 char tmpbuf[3];
543 char q;
544 if (s) {
9d4ba2ae 545 char * const nl = strrchr(s,'\n');
d2719217 546 if (nl)
8990e307
LW
547 *nl = '\0';
548 }
463559e7 549 else if (isCNTRL(PL_multi_close)) {
8990e307 550 *tmpbuf = '^';
585ec06d 551 tmpbuf[1] = (char)toCTRL(PL_multi_close);
8990e307
LW
552 tmpbuf[2] = '\0';
553 s = tmpbuf;
554 }
555 else {
eb160463 556 *tmpbuf = (char)PL_multi_close;
8990e307
LW
557 tmpbuf[1] = '\0';
558 s = tmpbuf;
559 }
560 q = strchr(s,'"') ? '\'' : '"';
cea2e8a9 561 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
463ee0b2 562}
79072805 563
ef89dcc3 564#define FEATURE_IS_ENABLED(name) \
0d863452 565 ((0 != (PL_hints & HINT_LOCALIZE_HH)) \
89529cee 566 && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
4a731d7b
NC
567/* The longest string we pass in. */
568#define MAX_FEATURE_LEN (sizeof("switch")-1)
569
0d863452
RH
570/*
571 * S_feature_is_enabled
572 * Check whether the named feature is enabled.
573 */
574STATIC bool
15f169a1 575S_feature_is_enabled(pTHX_ const char *const name, STRLEN namelen)
0d863452 576{
97aff369 577 dVAR;
0d863452 578 HV * const hinthv = GvHV(PL_hintgv);
4a731d7b 579 char he_name[8 + MAX_FEATURE_LEN] = "feature_";
7918f24d
NC
580
581 PERL_ARGS_ASSERT_FEATURE_IS_ENABLED;
582
4a731d7b
NC
583 assert(namelen <= MAX_FEATURE_LEN);
584 memcpy(&he_name[8], name, namelen);
d4c19fe8 585
7b9ef140 586 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
0d863452
RH
587}
588
ffb4593c
NT
589/*
590 * Perl_deprecate
ffb4593c
NT
591 */
592
79072805 593void
15f169a1 594Perl_deprecate(pTHX_ const char *const s)
a0d0e21e 595{
7918f24d
NC
596 PERL_ARGS_ASSERT_DEPRECATE;
597
599cee73 598 if (ckWARN(WARN_DEPRECATED))
9014280d 599 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
a0d0e21e
LW
600}
601
12bcd1a6 602void
15f169a1 603Perl_deprecate_old(pTHX_ const char *const s)
12bcd1a6
PM
604{
605 /* This function should NOT be called for any new deprecated warnings */
606 /* Use Perl_deprecate instead */
607 /* */
608 /* It is here to maintain backward compatibility with the pre-5.8 */
609 /* warnings category hierarchy. The "deprecated" category used to */
610 /* live under the "syntax" category. It is now a top-level category */
611 /* in its own right. */
612
7918f24d
NC
613 PERL_ARGS_ASSERT_DEPRECATE_OLD;
614
12bcd1a6 615 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
bfed75c6 616 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
12bcd1a6
PM
617 "Use of %s is deprecated", s);
618}
619
ffb4593c 620/*
9cbb5ea2
GS
621 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
622 * utf16-to-utf8-reversed.
ffb4593c
NT
623 */
624
c39cd008
GS
625#ifdef PERL_CR_FILTER
626static void
627strip_return(SV *sv)
628{
95a20fc0 629 register const char *s = SvPVX_const(sv);
9d4ba2ae 630 register const char * const e = s + SvCUR(sv);
7918f24d
NC
631
632 PERL_ARGS_ASSERT_STRIP_RETURN;
633
c39cd008
GS
634 /* outer loop optimized to do nothing if there are no CR-LFs */
635 while (s < e) {
636 if (*s++ == '\r' && *s == '\n') {
637 /* hit a CR-LF, need to copy the rest */
638 register char *d = s - 1;
639 *d++ = *s++;
640 while (s < e) {
641 if (*s == '\r' && s[1] == '\n')
642 s++;
643 *d++ = *s++;
644 }
645 SvCUR(sv) -= s - d;
646 return;
647 }
648 }
649}
a868473f 650
76e3520e 651STATIC I32
c39cd008 652S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
a868473f 653{
f54cb97a 654 const I32 count = FILTER_READ(idx+1, sv, maxlen);
c39cd008
GS
655 if (count > 0 && !maxlen)
656 strip_return(sv);
657 return count;
a868473f
NIS
658}
659#endif
660
199e78b7
DM
661
662
ffb4593c
NT
663/*
664 * Perl_lex_start
5486870f 665 *
e3abe207 666 * Create a parser object and initialise its parser and lexer fields
5486870f
DM
667 *
668 * rsfp is the opened file handle to read from (if any),
669 *
670 * line holds any initial content already read from the file (or in
671 * the case of no file, such as an eval, the whole contents);
672 *
673 * new_filter indicates that this is a new file and it shouldn't inherit
674 * the filters from the current parser (ie require).
ffb4593c
NT
675 */
676
a0d0e21e 677void
5486870f 678Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp, bool new_filter)
79072805 679{
97aff369 680 dVAR;
6ef55633 681 const char *s = NULL;
8990e307 682 STRLEN len;
5486870f 683 yy_parser *parser, *oparser;
acdf0a21
DM
684
685 /* create and initialise a parser */
686
199e78b7 687 Newxz(parser, 1, yy_parser);
5486870f 688 parser->old_parser = oparser = PL_parser;
acdf0a21
DM
689 PL_parser = parser;
690
691 Newx(parser->stack, YYINITDEPTH, yy_stack_frame);
692 parser->ps = parser->stack;
693 parser->stack_size = YYINITDEPTH;
694
695 parser->stack->state = 0;
696 parser->yyerrstatus = 0;
697 parser->yychar = YYEMPTY; /* Cause a token to be read. */
698
e3abe207
DM
699 /* on scope exit, free this parser and restore any outer one */
700 SAVEPARSER(parser);
7c4baf47 701 parser->saved_curcop = PL_curcop;
e3abe207 702
acdf0a21 703 /* initialise lexer state */
8990e307 704
fb205e7a
DM
705#ifdef PERL_MAD
706 parser->curforce = -1;
707#else
708 parser->nexttoke = 0;
709#endif
ca4cfd28 710 parser->error_count = oparser ? oparser->error_count : 0;
c2598295 711 parser->copline = NOLINE;
5afb0a62 712 parser->lex_state = LEX_NORMAL;
c2598295 713 parser->expect = XSTATE;
2f9285f8 714 parser->rsfp = rsfp;
56b27c9a 715 parser->rsfp_filters = (new_filter || !oparser) ? newAV()
502c6561 716 : MUTABLE_AV(SvREFCNT_inc(oparser->rsfp_filters));
2f9285f8 717
199e78b7
DM
718 Newx(parser->lex_brackstack, 120, char);
719 Newx(parser->lex_casestack, 12, char);
720 *parser->lex_casestack = '\0';
02b34bbe 721
10efb74f
NC
722 if (line) {
723 s = SvPV_const(line, len);
724 } else {
725 len = 0;
726 }
bdc0bf6f 727
10efb74f 728 if (!len) {
bdc0bf6f 729 parser->linestr = newSVpvs("\n;");
10efb74f 730 } else if (SvREADONLY(line) || s[len-1] != ';') {
bdc0bf6f 731 parser->linestr = newSVsv(line);
10efb74f 732 if (s[len-1] != ';')
bdc0bf6f 733 sv_catpvs(parser->linestr, "\n;");
6c5ce11d
NC
734 } else {
735 SvTEMP_off(line);
736 SvREFCNT_inc_simple_void_NN(line);
bdc0bf6f 737 parser->linestr = line;
8990e307 738 }
f06b5848
DM
739 parser->oldoldbufptr =
740 parser->oldbufptr =
741 parser->bufptr =
742 parser->linestart = SvPVX(parser->linestr);
743 parser->bufend = parser->bufptr + SvCUR(parser->linestr);
744 parser->last_lop = parser->last_uni = NULL;
79072805 745}
a687059c 746
e3abe207
DM
747
748/* delete a parser object */
749
750void
751Perl_parser_free(pTHX_ const yy_parser *parser)
752{
7918f24d
NC
753 PERL_ARGS_ASSERT_PARSER_FREE;
754
7c4baf47 755 PL_curcop = parser->saved_curcop;
bdc0bf6f
DM
756 SvREFCNT_dec(parser->linestr);
757
2f9285f8
DM
758 if (parser->rsfp == PerlIO_stdin())
759 PerlIO_clearerr(parser->rsfp);
799361c3
SH
760 else if (parser->rsfp && (!parser->old_parser ||
761 (parser->old_parser && parser->rsfp != parser->old_parser->rsfp)))
2f9285f8 762 PerlIO_close(parser->rsfp);
5486870f 763 SvREFCNT_dec(parser->rsfp_filters);
2f9285f8 764
e3abe207
DM
765 Safefree(parser->stack);
766 Safefree(parser->lex_brackstack);
767 Safefree(parser->lex_casestack);
768 PL_parser = parser->old_parser;
769 Safefree(parser);
770}
771
772
ffb4593c
NT
773/*
774 * Perl_lex_end
9cbb5ea2
GS
775 * Finalizer for lexing operations. Must be called when the parser is
776 * done with the lexer.
ffb4593c
NT
777 */
778
463ee0b2 779void
864dbfa3 780Perl_lex_end(pTHX)
463ee0b2 781{
97aff369 782 dVAR;
3280af22 783 PL_doextract = FALSE;
463ee0b2
LW
784}
785
ffb4593c
NT
786/*
787 * S_incline
788 * This subroutine has nothing to do with tilting, whether at windmills
789 * or pinball tables. Its name is short for "increment line". It
57843af0 790 * increments the current line number in CopLINE(PL_curcop) and checks
ffb4593c 791 * to see whether the line starts with a comment of the form
9cbb5ea2
GS
792 * # line 500 "foo.pm"
793 * If so, it sets the current line number and file to the values in the comment.
ffb4593c
NT
794 */
795
76e3520e 796STATIC void
d9095cec 797S_incline(pTHX_ const char *s)
463ee0b2 798{
97aff369 799 dVAR;
d9095cec
NC
800 const char *t;
801 const char *n;
802 const char *e;
463ee0b2 803
7918f24d
NC
804 PERL_ARGS_ASSERT_INCLINE;
805
57843af0 806 CopLINE_inc(PL_curcop);
463ee0b2
LW
807 if (*s++ != '#')
808 return;
d4c19fe8
AL
809 while (SPACE_OR_TAB(*s))
810 s++;
73659bf1
GS
811 if (strnEQ(s, "line", 4))
812 s += 4;
813 else
814 return;
084592ab 815 if (SPACE_OR_TAB(*s))
73659bf1 816 s++;
4e553d73 817 else
73659bf1 818 return;
d4c19fe8
AL
819 while (SPACE_OR_TAB(*s))
820 s++;
463ee0b2
LW
821 if (!isDIGIT(*s))
822 return;
d4c19fe8 823
463ee0b2
LW
824 n = s;
825 while (isDIGIT(*s))
826 s++;
26b6dc3f
RGS
827 if (!SPACE_OR_TAB(*s) && *s != '\n' && *s != '\0')
828 return;
bf4acbe4 829 while (SPACE_OR_TAB(*s))
463ee0b2 830 s++;
73659bf1 831 if (*s == '"' && (t = strchr(s+1, '"'))) {
463ee0b2 832 s++;
73659bf1
GS
833 e = t + 1;
834 }
463ee0b2 835 else {
c35e046a
AL
836 t = s;
837 while (!isSPACE(*t))
838 t++;
73659bf1 839 e = t;
463ee0b2 840 }
bf4acbe4 841 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
73659bf1
GS
842 e++;
843 if (*e != '\n' && *e != '\0')
844 return; /* false alarm */
845
f4dd75d9 846 if (t - s > 0) {
d9095cec 847 const STRLEN len = t - s;
8a5ee598 848#ifndef USE_ITHREADS
19bad673
NC
849 SV *const temp_sv = CopFILESV(PL_curcop);
850 const char *cf;
851 STRLEN tmplen;
852
853 if (temp_sv) {
854 cf = SvPVX(temp_sv);
855 tmplen = SvCUR(temp_sv);
856 } else {
857 cf = NULL;
858 tmplen = 0;
859 }
860
42d9b98d 861 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
e66cf94c
RGS
862 /* must copy *{"::_<(eval N)[oldfilename:L]"}
863 * to *{"::_<newfilename"} */
44867030
NC
864 /* However, the long form of evals is only turned on by the
865 debugger - usually they're "(eval %lu)" */
866 char smallbuf[128];
867 char *tmpbuf;
868 GV **gvp;
d9095cec 869 STRLEN tmplen2 = len;
798b63bc 870 if (tmplen + 2 <= sizeof smallbuf)
e66cf94c
RGS
871 tmpbuf = smallbuf;
872 else
2ae0db35 873 Newx(tmpbuf, tmplen + 2, char);
44867030
NC
874 tmpbuf[0] = '_';
875 tmpbuf[1] = '<';
2ae0db35 876 memcpy(tmpbuf + 2, cf, tmplen);
44867030 877 tmplen += 2;
8a5ee598
RGS
878 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
879 if (gvp) {
44867030
NC
880 char *tmpbuf2;
881 GV *gv2;
882
883 if (tmplen2 + 2 <= sizeof smallbuf)
884 tmpbuf2 = smallbuf;
885 else
886 Newx(tmpbuf2, tmplen2 + 2, char);
887
888 if (tmpbuf2 != smallbuf || tmpbuf != smallbuf) {
889 /* Either they malloc'd it, or we malloc'd it,
890 so no prefix is present in ours. */
891 tmpbuf2[0] = '_';
892 tmpbuf2[1] = '<';
893 }
894
895 memcpy(tmpbuf2 + 2, s, tmplen2);
896 tmplen2 += 2;
897
8a5ee598 898 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
e5527e4b 899 if (!isGV(gv2)) {
8a5ee598 900 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
e5527e4b
RGS
901 /* adjust ${"::_<newfilename"} to store the new file name */
902 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
3cb1dbc6
NC
903 GvHV(gv2) = MUTABLE_HV(SvREFCNT_inc(GvHV(*gvp)));
904 GvAV(gv2) = MUTABLE_AV(SvREFCNT_inc(GvAV(*gvp)));
e5527e4b 905 }
44867030
NC
906
907 if (tmpbuf2 != smallbuf) Safefree(tmpbuf2);
8a5ee598 908 }
e66cf94c 909 if (tmpbuf != smallbuf) Safefree(tmpbuf);
e66cf94c 910 }
8a5ee598 911#endif
05ec9bb3 912 CopFILE_free(PL_curcop);
d9095cec 913 CopFILE_setn(PL_curcop, s, len);
f4dd75d9 914 }
57843af0 915 CopLINE_set(PL_curcop, atoi(n)-1);
463ee0b2
LW
916}
917
29595ff2 918#ifdef PERL_MAD
cd81e915 919/* skip space before PL_thistoken */
29595ff2
NC
920
921STATIC char *
922S_skipspace0(pTHX_ register char *s)
923{
7918f24d
NC
924 PERL_ARGS_ASSERT_SKIPSPACE0;
925
29595ff2
NC
926 s = skipspace(s);
927 if (!PL_madskills)
928 return s;
cd81e915
NC
929 if (PL_skipwhite) {
930 if (!PL_thiswhite)
6b29d1f5 931 PL_thiswhite = newSVpvs("");
cd81e915
NC
932 sv_catsv(PL_thiswhite, PL_skipwhite);
933 sv_free(PL_skipwhite);
934 PL_skipwhite = 0;
935 }
936 PL_realtokenstart = s - SvPVX(PL_linestr);
29595ff2
NC
937 return s;
938}
939
cd81e915 940/* skip space after PL_thistoken */
29595ff2
NC
941
942STATIC char *
943S_skipspace1(pTHX_ register char *s)
944{
d4c19fe8 945 const char *start = s;
29595ff2
NC
946 I32 startoff = start - SvPVX(PL_linestr);
947
7918f24d
NC
948 PERL_ARGS_ASSERT_SKIPSPACE1;
949
29595ff2
NC
950 s = skipspace(s);
951 if (!PL_madskills)
952 return s;
953 start = SvPVX(PL_linestr) + startoff;
cd81e915 954 if (!PL_thistoken && PL_realtokenstart >= 0) {
d4c19fe8 955 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
cd81e915
NC
956 PL_thistoken = newSVpvn(tstart, start - tstart);
957 }
958 PL_realtokenstart = -1;
959 if (PL_skipwhite) {
960 if (!PL_nextwhite)
6b29d1f5 961 PL_nextwhite = newSVpvs("");
cd81e915
NC
962 sv_catsv(PL_nextwhite, PL_skipwhite);
963 sv_free(PL_skipwhite);
964 PL_skipwhite = 0;
29595ff2
NC
965 }
966 return s;
967}
968
969STATIC char *
970S_skipspace2(pTHX_ register char *s, SV **svp)
971{
c35e046a
AL
972 char *start;
973 const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
974 const I32 startoff = s - SvPVX(PL_linestr);
975
7918f24d
NC
976 PERL_ARGS_ASSERT_SKIPSPACE2;
977
29595ff2
NC
978 s = skipspace(s);
979 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
980 if (!PL_madskills || !svp)
981 return s;
982 start = SvPVX(PL_linestr) + startoff;
cd81e915 983 if (!PL_thistoken && PL_realtokenstart >= 0) {
d4c19fe8 984 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
cd81e915
NC
985 PL_thistoken = newSVpvn(tstart, start - tstart);
986 PL_realtokenstart = -1;
29595ff2 987 }
cd81e915 988 if (PL_skipwhite) {
29595ff2 989 if (!*svp)
6b29d1f5 990 *svp = newSVpvs("");
cd81e915
NC
991 sv_setsv(*svp, PL_skipwhite);
992 sv_free(PL_skipwhite);
993 PL_skipwhite = 0;
29595ff2
NC
994 }
995
996 return s;
997}
998#endif
999
80a702cd 1000STATIC void
15f169a1 1001S_update_debugger_info(pTHX_ SV *orig_sv, const char *const buf, STRLEN len)
80a702cd
RGS
1002{
1003 AV *av = CopFILEAVx(PL_curcop);
1004 if (av) {
b9f83d2f 1005 SV * const sv = newSV_type(SVt_PVMG);
5fa550fb
NC
1006 if (orig_sv)
1007 sv_setsv(sv, orig_sv);
1008 else
1009 sv_setpvn(sv, buf, len);
80a702cd
RGS
1010 (void)SvIOK_on(sv);
1011 SvIV_set(sv, 0);
1012 av_store(av, (I32)CopLINE(PL_curcop), sv);
1013 }
1014}
1015
ffb4593c
NT
1016/*
1017 * S_skipspace
1018 * Called to gobble the appropriate amount and type of whitespace.
1019 * Skips comments as well.
1020 */
1021
76e3520e 1022STATIC char *
cea2e8a9 1023S_skipspace(pTHX_ register char *s)
a687059c 1024{
97aff369 1025 dVAR;
5db06880
NC
1026#ifdef PERL_MAD
1027 int curoff;
1028 int startoff = s - SvPVX(PL_linestr);
1029
7918f24d
NC
1030 PERL_ARGS_ASSERT_SKIPSPACE;
1031
cd81e915
NC
1032 if (PL_skipwhite) {
1033 sv_free(PL_skipwhite);
1034 PL_skipwhite = 0;
5db06880
NC
1035 }
1036#endif
7918f24d 1037 PERL_ARGS_ASSERT_SKIPSPACE;
5db06880 1038
3280af22 1039 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
bf4acbe4 1040 while (s < PL_bufend && SPACE_OR_TAB(*s))
463ee0b2 1041 s++;
5db06880
NC
1042#ifdef PERL_MAD
1043 goto done;
1044#else
463ee0b2 1045 return s;
5db06880 1046#endif
463ee0b2
LW
1047 }
1048 for (;;) {
fd049845 1049 STRLEN prevlen;
09bef843 1050 SSize_t oldprevlen, oldoldprevlen;
9c5ffd7c 1051 SSize_t oldloplen = 0, oldunilen = 0;
60e6418e
GS
1052 while (s < PL_bufend && isSPACE(*s)) {
1053 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
1054 incline(s);
1055 }
ffb4593c
NT
1056
1057 /* comment */
3280af22
NIS
1058 if (s < PL_bufend && *s == '#') {
1059 while (s < PL_bufend && *s != '\n')
463ee0b2 1060 s++;
60e6418e 1061 if (s < PL_bufend) {
463ee0b2 1062 s++;
60e6418e
GS
1063 if (PL_in_eval && !PL_rsfp) {
1064 incline(s);
1065 continue;
1066 }
1067 }
463ee0b2 1068 }
ffb4593c
NT
1069
1070 /* only continue to recharge the buffer if we're at the end
1071 * of the buffer, we're not reading from a source filter, and
1072 * we're in normal lexing mode
1073 */
09bef843
SB
1074 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
1075 PL_lex_state == LEX_FORMLINE)
5db06880
NC
1076#ifdef PERL_MAD
1077 goto done;
1078#else
463ee0b2 1079 return s;
5db06880 1080#endif
ffb4593c
NT
1081
1082 /* try to recharge the buffer */
5db06880
NC
1083#ifdef PERL_MAD
1084 curoff = s - SvPVX(PL_linestr);
1085#endif
1086
9cbb5ea2 1087 if ((s = filter_gets(PL_linestr, PL_rsfp,
bd61b366 1088 (prevlen = SvCUR(PL_linestr)))) == NULL)
9cbb5ea2 1089 {
5db06880
NC
1090#ifdef PERL_MAD
1091 if (PL_madskills && curoff != startoff) {
cd81e915 1092 if (!PL_skipwhite)
6b29d1f5 1093 PL_skipwhite = newSVpvs("");
cd81e915 1094 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
5db06880
NC
1095 curoff - startoff);
1096 }
1097
1098 /* mustn't throw out old stuff yet if madpropping */
1099 SvCUR(PL_linestr) = curoff;
1100 s = SvPVX(PL_linestr) + curoff;
1101 *s = 0;
1102 if (curoff && s[-1] == '\n')
1103 s[-1] = ' ';
1104#endif
1105
9cbb5ea2 1106 /* end of file. Add on the -p or -n magic */
cd81e915 1107 /* XXX these shouldn't really be added here, can't set PL_faketokens */
01a19ab0 1108 if (PL_minus_p) {
5db06880 1109#ifdef PERL_MAD
6502358f 1110 sv_catpvs(PL_linestr,
5db06880
NC
1111 ";}continue{print or die qq(-p destination: $!\\n);}");
1112#else
6502358f 1113 sv_setpvs(PL_linestr,
01a19ab0 1114 ";}continue{print or die qq(-p destination: $!\\n);}");
5db06880 1115#endif
3280af22 1116 PL_minus_n = PL_minus_p = 0;
a0d0e21e 1117 }
01a19ab0 1118 else if (PL_minus_n) {
5db06880 1119#ifdef PERL_MAD
76f68e9b 1120 sv_catpvs(PL_linestr, ";}");
5db06880 1121#else
76f68e9b 1122 sv_setpvs(PL_linestr, ";}");
5db06880 1123#endif
01a19ab0
NC
1124 PL_minus_n = 0;
1125 }
a0d0e21e 1126 else
5db06880 1127#ifdef PERL_MAD
76f68e9b 1128 sv_catpvs(PL_linestr,";");
5db06880 1129#else
76f68e9b 1130 sv_setpvs(PL_linestr,";");
5db06880 1131#endif
ffb4593c
NT
1132
1133 /* reset variables for next time we lex */
9cbb5ea2 1134 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
89122651
NC
1135 = SvPVX(PL_linestr)
1136#ifdef PERL_MAD
1137 + curoff
1138#endif
1139 ;
3280af22 1140 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 1141 PL_last_lop = PL_last_uni = NULL;
ffb4593c 1142
4c84d7f2 1143 /* Close the filehandle. Could be from
ffb4593c
NT
1144 * STDIN, or a regular file. If we were reading code from
1145 * STDIN (because the commandline held no -e or filename)
1146 * then we don't close it, we reset it so the code can
1147 * read from STDIN too.
1148 */
1149
4c84d7f2 1150 if ((PerlIO*)PL_rsfp == PerlIO_stdin())
3280af22 1151 PerlIO_clearerr(PL_rsfp);
8990e307 1152 else
3280af22 1153 (void)PerlIO_close(PL_rsfp);
4608196e 1154 PL_rsfp = NULL;
463ee0b2
LW
1155 return s;
1156 }
ffb4593c
NT
1157
1158 /* not at end of file, so we only read another line */
09bef843
SB
1159 /* make corresponding updates to old pointers, for yyerror() */
1160 oldprevlen = PL_oldbufptr - PL_bufend;
1161 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1162 if (PL_last_uni)
1163 oldunilen = PL_last_uni - PL_bufend;
1164 if (PL_last_lop)
1165 oldloplen = PL_last_lop - PL_bufend;
3280af22
NIS
1166 PL_linestart = PL_bufptr = s + prevlen;
1167 PL_bufend = s + SvCUR(PL_linestr);
1168 s = PL_bufptr;
09bef843
SB
1169 PL_oldbufptr = s + oldprevlen;
1170 PL_oldoldbufptr = s + oldoldprevlen;
1171 if (PL_last_uni)
1172 PL_last_uni = s + oldunilen;
1173 if (PL_last_lop)
1174 PL_last_lop = s + oldloplen;
a0d0e21e 1175 incline(s);
ffb4593c
NT
1176
1177 /* debugger active and we're not compiling the debugger code,
1178 * so store the line into the debugger's array of lines
1179 */
65269a95 1180 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
5fa550fb 1181 update_debugger_info(NULL, PL_bufptr, PL_bufend - PL_bufptr);
463ee0b2 1182 }
5db06880
NC
1183
1184#ifdef PERL_MAD
1185 done:
1186 if (PL_madskills) {
cd81e915 1187 if (!PL_skipwhite)
6b29d1f5 1188 PL_skipwhite = newSVpvs("");
5db06880
NC
1189 curoff = s - SvPVX(PL_linestr);
1190 if (curoff - startoff)
cd81e915 1191 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
5db06880
NC
1192 curoff - startoff);
1193 }
1194 return s;
1195#endif
a687059c 1196}
378cc40b 1197
ffb4593c
NT
1198/*
1199 * S_check_uni
1200 * Check the unary operators to ensure there's no ambiguity in how they're
1201 * used. An ambiguous piece of code would be:
1202 * rand + 5
1203 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1204 * the +5 is its argument.
1205 */
1206
76e3520e 1207STATIC void
cea2e8a9 1208S_check_uni(pTHX)
ba106d47 1209{
97aff369 1210 dVAR;
d4c19fe8
AL
1211 const char *s;
1212 const char *t;
2f3197b3 1213
3280af22 1214 if (PL_oldoldbufptr != PL_last_uni)
2f3197b3 1215 return;
3280af22
NIS
1216 while (isSPACE(*PL_last_uni))
1217 PL_last_uni++;
c35e046a
AL
1218 s = PL_last_uni;
1219 while (isALNUM_lazy_if(s,UTF) || *s == '-')
1220 s++;
3280af22 1221 if ((t = strchr(s, '(')) && t < PL_bufptr)
a0d0e21e 1222 return;
6136c704 1223
0453d815 1224 if (ckWARN_d(WARN_AMBIGUOUS)){
9014280d 1225 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
32d45c1d
NC
1226 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1227 (int)(s - PL_last_uni), PL_last_uni);
0453d815 1228 }
2f3197b3
LW
1229}
1230
ffb4593c
NT
1231/*
1232 * LOP : macro to build a list operator. Its behaviour has been replaced
1233 * with a subroutine, S_lop() for which LOP is just another name.
1234 */
1235
a0d0e21e
LW
1236#define LOP(f,x) return lop(f,x,s)
1237
ffb4593c
NT
1238/*
1239 * S_lop
1240 * Build a list operator (or something that might be one). The rules:
1241 * - if we have a next token, then it's a list operator [why?]
1242 * - if the next thing is an opening paren, then it's a function
1243 * - else it's a list operator
1244 */
1245
76e3520e 1246STATIC I32
a0be28da 1247S_lop(pTHX_ I32 f, int x, char *s)
ffed7fef 1248{
97aff369 1249 dVAR;
7918f24d
NC
1250
1251 PERL_ARGS_ASSERT_LOP;
1252
6154021b 1253 pl_yylval.ival = f;
35c8bce7 1254 CLINE;
3280af22
NIS
1255 PL_expect = x;
1256 PL_bufptr = s;
1257 PL_last_lop = PL_oldbufptr;
eb160463 1258 PL_last_lop_op = (OPCODE)f;
5db06880
NC
1259#ifdef PERL_MAD
1260 if (PL_lasttoke)
1261 return REPORT(LSTOP);
1262#else
3280af22 1263 if (PL_nexttoke)
bbf60fe6 1264 return REPORT(LSTOP);
5db06880 1265#endif
79072805 1266 if (*s == '(')
bbf60fe6 1267 return REPORT(FUNC);
29595ff2 1268 s = PEEKSPACE(s);
79072805 1269 if (*s == '(')
bbf60fe6 1270 return REPORT(FUNC);
79072805 1271 else
bbf60fe6 1272 return REPORT(LSTOP);
79072805
LW
1273}
1274
5db06880
NC
1275#ifdef PERL_MAD
1276 /*
1277 * S_start_force
1278 * Sets up for an eventual force_next(). start_force(0) basically does
1279 * an unshift, while start_force(-1) does a push. yylex removes items
1280 * on the "pop" end.
1281 */
1282
1283STATIC void
1284S_start_force(pTHX_ int where)
1285{
1286 int i;
1287
cd81e915 1288 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
5db06880 1289 where = PL_lasttoke;
cd81e915
NC
1290 assert(PL_curforce < 0 || PL_curforce == where);
1291 if (PL_curforce != where) {
5db06880
NC
1292 for (i = PL_lasttoke; i > where; --i) {
1293 PL_nexttoke[i] = PL_nexttoke[i-1];
1294 }
1295 PL_lasttoke++;
1296 }
cd81e915 1297 if (PL_curforce < 0) /* in case of duplicate start_force() */
5db06880 1298 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
cd81e915
NC
1299 PL_curforce = where;
1300 if (PL_nextwhite) {
5db06880 1301 if (PL_madskills)
6b29d1f5 1302 curmad('^', newSVpvs(""));
cd81e915 1303 CURMAD('_', PL_nextwhite);
5db06880
NC
1304 }
1305}
1306
1307STATIC void
1308S_curmad(pTHX_ char slot, SV *sv)
1309{
1310 MADPROP **where;
1311
1312 if (!sv)
1313 return;
cd81e915
NC
1314 if (PL_curforce < 0)
1315 where = &PL_thismad;
5db06880 1316 else
cd81e915 1317 where = &PL_nexttoke[PL_curforce].next_mad;
5db06880 1318
cd81e915 1319 if (PL_faketokens)
76f68e9b 1320 sv_setpvs(sv, "");
5db06880
NC
1321 else {
1322 if (!IN_BYTES) {
1323 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1324 SvUTF8_on(sv);
1325 else if (PL_encoding) {
1326 sv_recode_to_utf8(sv, PL_encoding);
1327 }
1328 }
1329 }
1330
1331 /* keep a slot open for the head of the list? */
1332 if (slot != '_' && *where && (*where)->mad_key == '^') {
1333 (*where)->mad_key = slot;
daba3364 1334 sv_free(MUTABLE_SV(((*where)->mad_val)));
5db06880
NC
1335 (*where)->mad_val = (void*)sv;
1336 }
1337 else
1338 addmad(newMADsv(slot, sv), where, 0);
1339}
1340#else
b3f24c00
MHM
1341# define start_force(where) NOOP
1342# define curmad(slot, sv) NOOP
5db06880
NC
1343#endif
1344
ffb4593c
NT
1345/*
1346 * S_force_next
9cbb5ea2 1347 * When the lexer realizes it knows the next token (for instance,
ffb4593c 1348 * it is reordering tokens for the parser) then it can call S_force_next
9cbb5ea2 1349 * to know what token to return the next time the lexer is called. Caller
5db06880
NC
1350 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1351 * and possibly PL_expect to ensure the lexer handles the token correctly.
ffb4593c
NT
1352 */
1353
4e553d73 1354STATIC void
cea2e8a9 1355S_force_next(pTHX_ I32 type)
79072805 1356{
97aff369 1357 dVAR;
704d4215
GG
1358#ifdef DEBUGGING
1359 if (DEBUG_T_TEST) {
1360 PerlIO_printf(Perl_debug_log, "### forced token:\n");
f05d7009 1361 tokereport(type, &NEXTVAL_NEXTTOKE);
704d4215
GG
1362 }
1363#endif
5db06880 1364#ifdef PERL_MAD
cd81e915 1365 if (PL_curforce < 0)
5db06880 1366 start_force(PL_lasttoke);
cd81e915 1367 PL_nexttoke[PL_curforce].next_type = type;
5db06880
NC
1368 if (PL_lex_state != LEX_KNOWNEXT)
1369 PL_lex_defer = PL_lex_state;
1370 PL_lex_state = LEX_KNOWNEXT;
1371 PL_lex_expect = PL_expect;
cd81e915 1372 PL_curforce = -1;
5db06880 1373#else
3280af22
NIS
1374 PL_nexttype[PL_nexttoke] = type;
1375 PL_nexttoke++;
1376 if (PL_lex_state != LEX_KNOWNEXT) {
1377 PL_lex_defer = PL_lex_state;
1378 PL_lex_expect = PL_expect;
1379 PL_lex_state = LEX_KNOWNEXT;
79072805 1380 }
5db06880 1381#endif
79072805
LW
1382}
1383
d0a148a6 1384STATIC SV *
15f169a1 1385S_newSV_maybe_utf8(pTHX_ const char *const start, STRLEN len)
d0a148a6 1386{
97aff369 1387 dVAR;
740cce10
NC
1388 SV * const sv = newSVpvn_utf8(start, len,
1389 UTF && !IN_BYTES
1390 && is_utf8_string((const U8*)start, len));
d0a148a6
NC
1391 return sv;
1392}
1393
ffb4593c
NT
1394/*
1395 * S_force_word
1396 * When the lexer knows the next thing is a word (for instance, it has
1397 * just seen -> and it knows that the next char is a word char, then
02b34bbe
DM
1398 * it calls S_force_word to stick the next word into the PL_nexttoke/val
1399 * lookahead.
ffb4593c
NT
1400 *
1401 * Arguments:
b1b65b59 1402 * char *start : buffer position (must be within PL_linestr)
02b34bbe 1403 * int token : PL_next* will be this type of bare word (e.g., METHOD,WORD)
ffb4593c
NT
1404 * int check_keyword : if true, Perl checks to make sure the word isn't
1405 * a keyword (do this if the word is a label, e.g. goto FOO)
1406 * int allow_pack : if true, : characters will also be allowed (require,
1407 * use, etc. do this)
9cbb5ea2 1408 * int allow_initial_tick : used by the "sub" lexer only.
ffb4593c
NT
1409 */
1410
76e3520e 1411STATIC char *
cea2e8a9 1412S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
79072805 1413{
97aff369 1414 dVAR;
463ee0b2
LW
1415 register char *s;
1416 STRLEN len;
4e553d73 1417
7918f24d
NC
1418 PERL_ARGS_ASSERT_FORCE_WORD;
1419
29595ff2 1420 start = SKIPSPACE1(start);
463ee0b2 1421 s = start;
7e2040f0 1422 if (isIDFIRST_lazy_if(s,UTF) ||
a0d0e21e 1423 (allow_pack && *s == ':') ||
15f0808c 1424 (allow_initial_tick && *s == '\'') )
a0d0e21e 1425 {
3280af22 1426 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
5458a98a 1427 if (check_keyword && keyword(PL_tokenbuf, len, 0))
463ee0b2 1428 return start;
cd81e915 1429 start_force(PL_curforce);
5db06880
NC
1430 if (PL_madskills)
1431 curmad('X', newSVpvn(start,s-start));
463ee0b2 1432 if (token == METHOD) {
29595ff2 1433 s = SKIPSPACE1(s);
463ee0b2 1434 if (*s == '(')
3280af22 1435 PL_expect = XTERM;
463ee0b2 1436 else {
3280af22 1437 PL_expect = XOPERATOR;
463ee0b2 1438 }
79072805 1439 }
e74e6b3d 1440 if (PL_madskills)
63575281 1441 curmad('g', newSVpvs( "forced" ));
9ded7720 1442 NEXTVAL_NEXTTOKE.opval
d0a148a6
NC
1443 = (OP*)newSVOP(OP_CONST,0,
1444 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
9ded7720 1445 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
79072805
LW
1446 force_next(token);
1447 }
1448 return s;
1449}
1450
ffb4593c
NT
1451/*
1452 * S_force_ident
9cbb5ea2 1453 * Called when the lexer wants $foo *foo &foo etc, but the program
ffb4593c
NT
1454 * text only contains the "foo" portion. The first argument is a pointer
1455 * to the "foo", and the second argument is the type symbol to prefix.
1456 * Forces the next token to be a "WORD".
9cbb5ea2 1457 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
ffb4593c
NT
1458 */
1459
76e3520e 1460STATIC void
bfed75c6 1461S_force_ident(pTHX_ register const char *s, int kind)
79072805 1462{
97aff369 1463 dVAR;
7918f24d
NC
1464
1465 PERL_ARGS_ASSERT_FORCE_IDENT;
1466
c35e046a 1467 if (*s) {
90e5519e
NC
1468 const STRLEN len = strlen(s);
1469 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
cd81e915 1470 start_force(PL_curforce);
9ded7720 1471 NEXTVAL_NEXTTOKE.opval = o;
79072805 1472 force_next(WORD);
748a9306 1473 if (kind) {
11343788 1474 o->op_private = OPpCONST_ENTERED;
55497cff 1475 /* XXX see note in pp_entereval() for why we forgo typo
1476 warnings if the symbol must be introduced in an eval.
1477 GSAR 96-10-12 */
90e5519e
NC
1478 gv_fetchpvn_flags(s, len,
1479 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1480 : GV_ADD,
1481 kind == '$' ? SVt_PV :
1482 kind == '@' ? SVt_PVAV :
1483 kind == '%' ? SVt_PVHV :
a0d0e21e 1484 SVt_PVGV
90e5519e 1485 );
748a9306 1486 }
79072805
LW
1487 }
1488}
1489
1571675a
GS
1490NV
1491Perl_str_to_version(pTHX_ SV *sv)
1492{
1493 NV retval = 0.0;
1494 NV nshift = 1.0;
1495 STRLEN len;
cfd0369c 1496 const char *start = SvPV_const(sv,len);
9d4ba2ae 1497 const char * const end = start + len;
504618e9 1498 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
7918f24d
NC
1499
1500 PERL_ARGS_ASSERT_STR_TO_VERSION;
1501
1571675a 1502 while (start < end) {
ba210ebe 1503 STRLEN skip;
1571675a
GS
1504 UV n;
1505 if (utf)
9041c2e3 1506 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1571675a
GS
1507 else {
1508 n = *(U8*)start;
1509 skip = 1;
1510 }
1511 retval += ((NV)n)/nshift;
1512 start += skip;
1513 nshift *= 1000;
1514 }
1515 return retval;
1516}
1517
4e553d73 1518/*
ffb4593c
NT
1519 * S_force_version
1520 * Forces the next token to be a version number.
e759cc13
RGS
1521 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1522 * and if "guessing" is TRUE, then no new token is created (and the caller
1523 * must use an alternative parsing method).
ffb4593c
NT
1524 */
1525
76e3520e 1526STATIC char *
e759cc13 1527S_force_version(pTHX_ char *s, int guessing)
89bfa8cd 1528{
97aff369 1529 dVAR;
5f66b61c 1530 OP *version = NULL;
44dcb63b 1531 char *d;
5db06880
NC
1532#ifdef PERL_MAD
1533 I32 startoff = s - SvPVX(PL_linestr);
1534#endif
89bfa8cd 1535
7918f24d
NC
1536 PERL_ARGS_ASSERT_FORCE_VERSION;
1537
29595ff2 1538 s = SKIPSPACE1(s);
89bfa8cd 1539
44dcb63b 1540 d = s;
dd629d5b 1541 if (*d == 'v')
44dcb63b 1542 d++;
44dcb63b 1543 if (isDIGIT(*d)) {
e759cc13
RGS
1544 while (isDIGIT(*d) || *d == '_' || *d == '.')
1545 d++;
5db06880
NC
1546#ifdef PERL_MAD
1547 if (PL_madskills) {
cd81e915 1548 start_force(PL_curforce);
5db06880
NC
1549 curmad('X', newSVpvn(s,d-s));
1550 }
1551#endif
9f3d182e 1552 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
dd629d5b 1553 SV *ver;
6154021b
RGS
1554 s = scan_num(s, &pl_yylval);
1555 version = pl_yylval.opval;
dd629d5b
GS
1556 ver = cSVOPx(version)->op_sv;
1557 if (SvPOK(ver) && !SvNIOK(ver)) {
862a34c6 1558 SvUPGRADE(ver, SVt_PVNV);
9d6ce603 1559 SvNV_set(ver, str_to_version(ver));
1571675a 1560 SvNOK_on(ver); /* hint that it is a version */
44dcb63b 1561 }
89bfa8cd 1562 }
5db06880
NC
1563 else if (guessing) {
1564#ifdef PERL_MAD
1565 if (PL_madskills) {
cd81e915
NC
1566 sv_free(PL_nextwhite); /* let next token collect whitespace */
1567 PL_nextwhite = 0;
5db06880
NC
1568 s = SvPVX(PL_linestr) + startoff;
1569 }
1570#endif
e759cc13 1571 return s;
5db06880 1572 }
89bfa8cd 1573 }
1574
5db06880
NC
1575#ifdef PERL_MAD
1576 if (PL_madskills && !version) {
cd81e915
NC
1577 sv_free(PL_nextwhite); /* let next token collect whitespace */
1578 PL_nextwhite = 0;
5db06880
NC
1579 s = SvPVX(PL_linestr) + startoff;
1580 }
1581#endif
89bfa8cd 1582 /* NOTE: The parser sees the package name and the VERSION swapped */
cd81e915 1583 start_force(PL_curforce);
9ded7720 1584 NEXTVAL_NEXTTOKE.opval = version;
4e553d73 1585 force_next(WORD);
89bfa8cd 1586
e759cc13 1587 return s;
89bfa8cd 1588}
1589
ffb4593c
NT
1590/*
1591 * S_tokeq
1592 * Tokenize a quoted string passed in as an SV. It finds the next
1593 * chunk, up to end of string or a backslash. It may make a new
1594 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1595 * turns \\ into \.
1596 */
1597
76e3520e 1598STATIC SV *
cea2e8a9 1599S_tokeq(pTHX_ SV *sv)
79072805 1600{
97aff369 1601 dVAR;
79072805
LW
1602 register char *s;
1603 register char *send;
1604 register char *d;
b3ac6de7
IZ
1605 STRLEN len = 0;
1606 SV *pv = sv;
79072805 1607
7918f24d
NC
1608 PERL_ARGS_ASSERT_TOKEQ;
1609
79072805 1610 if (!SvLEN(sv))
b3ac6de7 1611 goto finish;
79072805 1612
a0d0e21e 1613 s = SvPV_force(sv, len);
21a311ee 1614 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
b3ac6de7 1615 goto finish;
463ee0b2 1616 send = s + len;
79072805
LW
1617 while (s < send && *s != '\\')
1618 s++;
1619 if (s == send)
b3ac6de7 1620 goto finish;
79072805 1621 d = s;
be4731d2 1622 if ( PL_hints & HINT_NEW_STRING ) {
59cd0e26 1623 pv = newSVpvn_flags(SvPVX_const(pv), len, SVs_TEMP | SvUTF8(sv));
be4731d2 1624 }
79072805
LW
1625 while (s < send) {
1626 if (*s == '\\') {
a0d0e21e 1627 if (s + 1 < send && (s[1] == '\\'))
79072805
LW
1628 s++; /* all that, just for this */
1629 }
1630 *d++ = *s++;
1631 }
1632 *d = '\0';
95a20fc0 1633 SvCUR_set(sv, d - SvPVX_const(sv));
b3ac6de7 1634 finish:
3280af22 1635 if ( PL_hints & HINT_NEW_STRING )
eb0d8d16 1636 return new_constant(NULL, 0, "q", sv, pv, "q", 1);
79072805
LW
1637 return sv;
1638}
1639
ffb4593c
NT
1640/*
1641 * Now come three functions related to double-quote context,
1642 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1643 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1644 * interact with PL_lex_state, and create fake ( ... ) argument lists
1645 * to handle functions and concatenation.
1646 * They assume that whoever calls them will be setting up a fake
1647 * join call, because each subthing puts a ',' after it. This lets
1648 * "lower \luPpEr"
1649 * become
1650 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1651 *
1652 * (I'm not sure whether the spurious commas at the end of lcfirst's
1653 * arguments and join's arguments are created or not).
1654 */
1655
1656/*
1657 * S_sublex_start
6154021b 1658 * Assumes that pl_yylval.ival is the op we're creating (e.g. OP_LCFIRST).
ffb4593c
NT
1659 *
1660 * Pattern matching will set PL_lex_op to the pattern-matching op to
6154021b 1661 * make (we return THING if pl_yylval.ival is OP_NULL, PMFUNC otherwise).
ffb4593c
NT
1662 *
1663 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1664 *
1665 * Everything else becomes a FUNC.
1666 *
1667 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1668 * had an OP_CONST or OP_READLINE). This just sets us up for a
1669 * call to S_sublex_push().
1670 */
1671
76e3520e 1672STATIC I32
cea2e8a9 1673S_sublex_start(pTHX)
79072805 1674{
97aff369 1675 dVAR;
6154021b 1676 register const I32 op_type = pl_yylval.ival;
79072805
LW
1677
1678 if (op_type == OP_NULL) {
6154021b 1679 pl_yylval.opval = PL_lex_op;
5f66b61c 1680 PL_lex_op = NULL;
79072805
LW
1681 return THING;
1682 }
1683 if (op_type == OP_CONST || op_type == OP_READLINE) {
3280af22 1684 SV *sv = tokeq(PL_lex_stuff);
b3ac6de7
IZ
1685
1686 if (SvTYPE(sv) == SVt_PVIV) {
1687 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1688 STRLEN len;
96a5add6 1689 const char * const p = SvPV_const(sv, len);
740cce10 1690 SV * const nsv = newSVpvn_flags(p, len, SvUTF8(sv));
b3ac6de7
IZ
1691 SvREFCNT_dec(sv);
1692 sv = nsv;
4e553d73 1693 }
6154021b 1694 pl_yylval.opval = (OP*)newSVOP(op_type, 0, sv);
a0714e2c 1695 PL_lex_stuff = NULL;
6f33ba73
RGS
1696 /* Allow <FH> // "foo" */
1697 if (op_type == OP_READLINE)
1698 PL_expect = XTERMORDORDOR;
79072805
LW
1699 return THING;
1700 }
e3f73d4e
RGS
1701 else if (op_type == OP_BACKTICK && PL_lex_op) {
1702 /* readpipe() vas overriden */
1703 cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff);
6154021b 1704 pl_yylval.opval = PL_lex_op;
9b201d7d 1705 PL_lex_op = NULL;
e3f73d4e
RGS
1706 PL_lex_stuff = NULL;
1707 return THING;
1708 }
79072805 1709
3280af22 1710 PL_sublex_info.super_state = PL_lex_state;
eac04b2e 1711 PL_sublex_info.sub_inwhat = (U16)op_type;
3280af22
NIS
1712 PL_sublex_info.sub_op = PL_lex_op;
1713 PL_lex_state = LEX_INTERPPUSH;
55497cff 1714
3280af22
NIS
1715 PL_expect = XTERM;
1716 if (PL_lex_op) {
6154021b 1717 pl_yylval.opval = PL_lex_op;
5f66b61c 1718 PL_lex_op = NULL;
55497cff 1719 return PMFUNC;
1720 }
1721 else
1722 return FUNC;
1723}
1724
ffb4593c
NT
1725/*
1726 * S_sublex_push
1727 * Create a new scope to save the lexing state. The scope will be
1728 * ended in S_sublex_done. Returns a '(', starting the function arguments
1729 * to the uc, lc, etc. found before.
1730 * Sets PL_lex_state to LEX_INTERPCONCAT.
1731 */
1732
76e3520e 1733STATIC I32
cea2e8a9 1734S_sublex_push(pTHX)
55497cff 1735{
27da23d5 1736 dVAR;
f46d017c 1737 ENTER;
55497cff 1738
3280af22 1739 PL_lex_state = PL_sublex_info.super_state;
651b5b28 1740 SAVEBOOL(PL_lex_dojoin);
3280af22 1741 SAVEI32(PL_lex_brackets);
3280af22
NIS
1742 SAVEI32(PL_lex_casemods);
1743 SAVEI32(PL_lex_starts);
651b5b28 1744 SAVEI8(PL_lex_state);
7766f137 1745 SAVEVPTR(PL_lex_inpat);
98246f1e 1746 SAVEI16(PL_lex_inwhat);
57843af0 1747 SAVECOPLINE(PL_curcop);
3280af22 1748 SAVEPPTR(PL_bufptr);
8452ff4b 1749 SAVEPPTR(PL_bufend);
3280af22
NIS
1750 SAVEPPTR(PL_oldbufptr);
1751 SAVEPPTR(PL_oldoldbufptr);
207e3d1a
JH
1752 SAVEPPTR(PL_last_lop);
1753 SAVEPPTR(PL_last_uni);
3280af22
NIS
1754 SAVEPPTR(PL_linestart);
1755 SAVESPTR(PL_linestr);
8edd5f42
RGS
1756 SAVEGENERICPV(PL_lex_brackstack);
1757 SAVEGENERICPV(PL_lex_casestack);
3280af22
NIS
1758
1759 PL_linestr = PL_lex_stuff;
a0714e2c 1760 PL_lex_stuff = NULL;
3280af22 1761
9cbb5ea2
GS
1762 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1763 = SvPVX(PL_linestr);
3280af22 1764 PL_bufend += SvCUR(PL_linestr);
bd61b366 1765 PL_last_lop = PL_last_uni = NULL;
3280af22
NIS
1766 SAVEFREESV(PL_linestr);
1767
1768 PL_lex_dojoin = FALSE;
1769 PL_lex_brackets = 0;
a02a5408
JC
1770 Newx(PL_lex_brackstack, 120, char);
1771 Newx(PL_lex_casestack, 12, char);
3280af22
NIS
1772 PL_lex_casemods = 0;
1773 *PL_lex_casestack = '\0';
1774 PL_lex_starts = 0;
1775 PL_lex_state = LEX_INTERPCONCAT;
eb160463 1776 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
3280af22
NIS
1777
1778 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1779 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1780 PL_lex_inpat = PL_sublex_info.sub_op;
79072805 1781 else
5f66b61c 1782 PL_lex_inpat = NULL;
79072805 1783
55497cff 1784 return '(';
79072805
LW
1785}
1786
ffb4593c
NT
1787/*
1788 * S_sublex_done
1789 * Restores lexer state after a S_sublex_push.
1790 */
1791
76e3520e 1792STATIC I32
cea2e8a9 1793S_sublex_done(pTHX)
79072805 1794{
27da23d5 1795 dVAR;
3280af22 1796 if (!PL_lex_starts++) {
396482e1 1797 SV * const sv = newSVpvs("");
9aa983d2
JH
1798 if (SvUTF8(PL_linestr))
1799 SvUTF8_on(sv);
3280af22 1800 PL_expect = XOPERATOR;
6154021b 1801 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
79072805
LW
1802 return THING;
1803 }
1804
3280af22
NIS
1805 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1806 PL_lex_state = LEX_INTERPCASEMOD;
cea2e8a9 1807 return yylex();
79072805
LW
1808 }
1809
ffb4593c 1810 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
3280af22
NIS
1811 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1812 PL_linestr = PL_lex_repl;
1813 PL_lex_inpat = 0;
1814 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1815 PL_bufend += SvCUR(PL_linestr);
bd61b366 1816 PL_last_lop = PL_last_uni = NULL;
3280af22
NIS
1817 SAVEFREESV(PL_linestr);
1818 PL_lex_dojoin = FALSE;
1819 PL_lex_brackets = 0;
3280af22
NIS
1820 PL_lex_casemods = 0;
1821 *PL_lex_casestack = '\0';
1822 PL_lex_starts = 0;
25da4f38 1823 if (SvEVALED(PL_lex_repl)) {
3280af22
NIS
1824 PL_lex_state = LEX_INTERPNORMAL;
1825 PL_lex_starts++;
e9fa98b2
HS
1826 /* we don't clear PL_lex_repl here, so that we can check later
1827 whether this is an evalled subst; that means we rely on the
1828 logic to ensure sublex_done() is called again only via the
1829 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
79072805 1830 }
e9fa98b2 1831 else {
3280af22 1832 PL_lex_state = LEX_INTERPCONCAT;
a0714e2c 1833 PL_lex_repl = NULL;
e9fa98b2 1834 }
79072805 1835 return ',';
ffed7fef
LW
1836 }
1837 else {
5db06880
NC
1838#ifdef PERL_MAD
1839 if (PL_madskills) {
cd81e915
NC
1840 if (PL_thiswhite) {
1841 if (!PL_endwhite)
6b29d1f5 1842 PL_endwhite = newSVpvs("");
cd81e915
NC
1843 sv_catsv(PL_endwhite, PL_thiswhite);
1844 PL_thiswhite = 0;
1845 }
1846 if (PL_thistoken)
76f68e9b 1847 sv_setpvs(PL_thistoken,"");
5db06880 1848 else
cd81e915 1849 PL_realtokenstart = -1;
5db06880
NC
1850 }
1851#endif
f46d017c 1852 LEAVE;
3280af22
NIS
1853 PL_bufend = SvPVX(PL_linestr);
1854 PL_bufend += SvCUR(PL_linestr);
1855 PL_expect = XOPERATOR;
09bef843 1856 PL_sublex_info.sub_inwhat = 0;
79072805 1857 return ')';
ffed7fef
LW
1858 }
1859}
1860
02aa26ce
NT
1861/*
1862 scan_const
1863
1864 Extracts a pattern, double-quoted string, or transliteration. This
1865 is terrifying code.
1866
94def140 1867 It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
3280af22 1868 processing a pattern (PL_lex_inpat is true), a transliteration
94def140 1869 (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
02aa26ce 1870
94def140
TS
1871 Returns a pointer to the character scanned up to. If this is
1872 advanced from the start pointer supplied (i.e. if anything was
9b599b2a 1873 successfully parsed), will leave an OP for the substring scanned
6154021b 1874 in pl_yylval. Caller must intuit reason for not parsing further
9b599b2a
GS
1875 by looking at the next characters herself.
1876
02aa26ce
NT
1877 In patterns:
1878 backslashes:
1879 double-quoted style: \r and \n
1880 regexp special ones: \D \s
94def140
TS
1881 constants: \x31
1882 backrefs: \1
02aa26ce
NT
1883 case and quoting: \U \Q \E
1884 stops on @ and $, but not for $ as tail anchor
1885
1886 In transliterations:
1887 characters are VERY literal, except for - not at the start or end
94def140
TS
1888 of the string, which indicates a range. If the range is in bytes,
1889 scan_const expands the range to the full set of intermediate
1890 characters. If the range is in utf8, the hyphen is replaced with
1891 a certain range mark which will be handled by pmtrans() in op.c.
02aa26ce
NT
1892
1893 In double-quoted strings:
1894 backslashes:
1895 double-quoted style: \r and \n
94def140
TS
1896 constants: \x31
1897 deprecated backrefs: \1 (in substitution replacements)
02aa26ce
NT
1898 case and quoting: \U \Q \E
1899 stops on @ and $
1900
1901 scan_const does *not* construct ops to handle interpolated strings.
1902 It stops processing as soon as it finds an embedded $ or @ variable
1903 and leaves it to the caller to work out what's going on.
1904
94def140
TS
1905 embedded arrays (whether in pattern or not) could be:
1906 @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
1907
1908 $ in double-quoted strings must be the symbol of an embedded scalar.
02aa26ce
NT
1909
1910 $ in pattern could be $foo or could be tail anchor. Assumption:
1911 it's a tail anchor if $ is the last thing in the string, or if it's
94def140 1912 followed by one of "()| \r\n\t"
02aa26ce
NT
1913
1914 \1 (backreferences) are turned into $1
1915
1916 The structure of the code is
1917 while (there's a character to process) {
94def140
TS
1918 handle transliteration ranges
1919 skip regexp comments /(?#comment)/ and codes /(?{code})/
1920 skip #-initiated comments in //x patterns
1921 check for embedded arrays
02aa26ce
NT
1922 check for embedded scalars
1923 if (backslash) {
94def140
TS
1924 leave intact backslashes from leaveit (below)
1925 deprecate \1 in substitution replacements
02aa26ce
NT
1926 handle string-changing backslashes \l \U \Q \E, etc.
1927 switch (what was escaped) {
94def140
TS
1928 handle \- in a transliteration (becomes a literal -)
1929 handle \132 (octal characters)
1930 handle \x15 and \x{1234} (hex characters)
1931 handle \N{name} (named characters)
1932 handle \cV (control characters)
1933 handle printf-style backslashes (\f, \r, \n, etc)
02aa26ce
NT
1934 } (end switch)
1935 } (end if backslash)
1936 } (end while character to read)
4e553d73 1937
02aa26ce
NT
1938*/
1939
76e3520e 1940STATIC char *
cea2e8a9 1941S_scan_const(pTHX_ char *start)
79072805 1942{
97aff369 1943 dVAR;
3280af22 1944 register char *send = PL_bufend; /* end of the constant */
561b68a9 1945 SV *sv = newSV(send - start); /* sv for the constant */
02aa26ce
NT
1946 register char *s = start; /* start of the constant */
1947 register char *d = SvPVX(sv); /* destination for copies */
1948 bool dorange = FALSE; /* are we in a translit range? */
c2e66d9e 1949 bool didrange = FALSE; /* did we just finish a range? */
2b9d42f0
NIS
1950 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1951 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
012bcf8d 1952 UV uv;
4c3a8340
TS
1953#ifdef EBCDIC
1954 UV literal_endpoint = 0;
e294cc5d 1955 bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
4c3a8340 1956#endif
012bcf8d 1957
7918f24d
NC
1958 PERL_ARGS_ASSERT_SCAN_CONST;
1959
2b9d42f0
NIS
1960 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1961 /* If we are doing a trans and we know we want UTF8 set expectation */
1962 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1963 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1964 }
1965
1966
79072805 1967 while (s < send || dorange) {
02aa26ce 1968 /* get transliterations out of the way (they're most literal) */
3280af22 1969 if (PL_lex_inwhat == OP_TRANS) {
02aa26ce 1970 /* expand a range A-Z to the full set of characters. AIE! */
79072805 1971 if (dorange) {
1ba5c669
JH
1972 I32 i; /* current expanded character */
1973 I32 min; /* first character in range */
1974 I32 max; /* last character in range */
02aa26ce 1975
e294cc5d
JH
1976#ifdef EBCDIC
1977 UV uvmax = 0;
1978#endif
1979
1980 if (has_utf8
1981#ifdef EBCDIC
1982 && !native_range
1983#endif
1984 ) {
9d4ba2ae 1985 char * const c = (char*)utf8_hop((U8*)d, -1);
8973db79
JH
1986 char *e = d++;
1987 while (e-- > c)
1988 *(e + 1) = *e;
25716404 1989 *c = (char)UTF_TO_NATIVE(0xff);
8973db79
JH
1990 /* mark the range as done, and continue */
1991 dorange = FALSE;
1992 didrange = TRUE;
1993 continue;
1994 }
2b9d42f0 1995
95a20fc0 1996 i = d - SvPVX_const(sv); /* remember current offset */
e294cc5d
JH
1997#ifdef EBCDIC
1998 SvGROW(sv,
1999 SvLEN(sv) + (has_utf8 ?
2000 (512 - UTF_CONTINUATION_MARK +
2001 UNISKIP(0x100))
2002 : 256));
2003 /* How many two-byte within 0..255: 128 in UTF-8,
2004 * 96 in UTF-8-mod. */
2005#else
9cbb5ea2 2006 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
e294cc5d 2007#endif
9cbb5ea2 2008 d = SvPVX(sv) + i; /* refresh d after realloc */
e294cc5d
JH
2009#ifdef EBCDIC
2010 if (has_utf8) {
2011 int j;
2012 for (j = 0; j <= 1; j++) {
2013 char * const c = (char*)utf8_hop((U8*)d, -1);
2014 const UV uv = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
2015 if (j)
2016 min = (U8)uv;
2017 else if (uv < 256)
2018 max = (U8)uv;
2019 else {
2020 max = (U8)0xff; /* only to \xff */
2021 uvmax = uv; /* \x{100} to uvmax */
2022 }
2023 d = c; /* eat endpoint chars */
2024 }
2025 }
2026 else {
2027#endif
2028 d -= 2; /* eat the first char and the - */
2029 min = (U8)*d; /* first char in range */
2030 max = (U8)d[1]; /* last char in range */
2031#ifdef EBCDIC
2032 }
2033#endif
8ada0baa 2034
c2e66d9e 2035 if (min > max) {
01ec43d0 2036 Perl_croak(aTHX_
d1573ac7 2037 "Invalid range \"%c-%c\" in transliteration operator",
1ba5c669 2038 (char)min, (char)max);
c2e66d9e
GS
2039 }
2040
c7f1f016 2041#ifdef EBCDIC
4c3a8340
TS
2042 if (literal_endpoint == 2 &&
2043 ((isLOWER(min) && isLOWER(max)) ||
2044 (isUPPER(min) && isUPPER(max)))) {
8ada0baa
JH
2045 if (isLOWER(min)) {
2046 for (i = min; i <= max; i++)
2047 if (isLOWER(i))
db42d148 2048 *d++ = NATIVE_TO_NEED(has_utf8,i);
8ada0baa
JH
2049 } else {
2050 for (i = min; i <= max; i++)
2051 if (isUPPER(i))
db42d148 2052 *d++ = NATIVE_TO_NEED(has_utf8,i);
8ada0baa
JH
2053 }
2054 }
2055 else
2056#endif
2057 for (i = min; i <= max; i++)
e294cc5d
JH
2058#ifdef EBCDIC
2059 if (has_utf8) {
2060 const U8 ch = (U8)NATIVE_TO_UTF(i);
2061 if (UNI_IS_INVARIANT(ch))
2062 *d++ = (U8)i;
2063 else {
2064 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
2065 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
2066 }
2067 }
2068 else
2069#endif
2070 *d++ = (char)i;
2071
2072#ifdef EBCDIC
2073 if (uvmax) {
2074 d = (char*)uvchr_to_utf8((U8*)d, 0x100);
2075 if (uvmax > 0x101)
2076 *d++ = (char)UTF_TO_NATIVE(0xff);
2077 if (uvmax > 0x100)
2078 d = (char*)uvchr_to_utf8((U8*)d, uvmax);
2079 }
2080#endif
02aa26ce
NT
2081
2082 /* mark the range as done, and continue */
79072805 2083 dorange = FALSE;
01ec43d0 2084 didrange = TRUE;
4c3a8340
TS
2085#ifdef EBCDIC
2086 literal_endpoint = 0;
2087#endif
79072805 2088 continue;
4e553d73 2089 }
02aa26ce
NT
2090
2091 /* range begins (ignore - as first or last char) */
79072805 2092 else if (*s == '-' && s+1 < send && s != start) {
4e553d73 2093 if (didrange) {
1fafa243 2094 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
01ec43d0 2095 }
e294cc5d
JH
2096 if (has_utf8
2097#ifdef EBCDIC
2098 && !native_range
2099#endif
2100 ) {
25716404 2101 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
a0ed51b3
LW
2102 s++;
2103 continue;
2104 }
79072805
LW
2105 dorange = TRUE;
2106 s++;
01ec43d0
GS
2107 }
2108 else {
2109 didrange = FALSE;
4c3a8340
TS
2110#ifdef EBCDIC
2111 literal_endpoint = 0;
e294cc5d 2112 native_range = TRUE;
4c3a8340 2113#endif
01ec43d0 2114 }
79072805 2115 }
02aa26ce
NT
2116
2117 /* if we get here, we're not doing a transliteration */
2118
0f5d15d6
IZ
2119 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
2120 except for the last char, which will be done separately. */
3280af22 2121 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
cc6b7395 2122 if (s[2] == '#') {
e994fd66 2123 while (s+1 < send && *s != ')')
db42d148 2124 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
155aba94
GS
2125 }
2126 else if (s[2] == '{' /* This should match regcomp.c */
67edc0c9 2127 || (s[2] == '?' && s[3] == '{'))
155aba94 2128 {
cc6b7395 2129 I32 count = 1;
0f5d15d6 2130 char *regparse = s + (s[2] == '{' ? 3 : 4);
cc6b7395
IZ
2131 char c;
2132
d9f97599
GS
2133 while (count && (c = *regparse)) {
2134 if (c == '\\' && regparse[1])
2135 regparse++;
4e553d73 2136 else if (c == '{')
cc6b7395 2137 count++;
4e553d73 2138 else if (c == '}')
cc6b7395 2139 count--;
d9f97599 2140 regparse++;
cc6b7395 2141 }
e994fd66 2142 if (*regparse != ')')
5bdf89e7 2143 regparse--; /* Leave one char for continuation. */
0f5d15d6 2144 while (s < regparse)
db42d148 2145 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
cc6b7395 2146 }
748a9306 2147 }
02aa26ce
NT
2148
2149 /* likewise skip #-initiated comments in //x patterns */
3280af22
NIS
2150 else if (*s == '#' && PL_lex_inpat &&
2151 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
748a9306 2152 while (s+1 < send && *s != '\n')
db42d148 2153 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
748a9306 2154 }
02aa26ce 2155
5d1d4326 2156 /* check for embedded arrays
da6eedaa 2157 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
5d1d4326 2158 */
1749ea0d
TS
2159 else if (*s == '@' && s[1]) {
2160 if (isALNUM_lazy_if(s+1,UTF))
2161 break;
2162 if (strchr(":'{$", s[1]))
2163 break;
2164 if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
2165 break; /* in regexp, neither @+ nor @- are interpolated */
2166 }
02aa26ce
NT
2167
2168 /* check for embedded scalars. only stop if we're sure it's a
2169 variable.
2170 */
79072805 2171 else if (*s == '$') {
3280af22 2172 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
79072805 2173 break;
77772344
B
2174 if (s + 1 < send && !strchr("()| \r\n\t", s[1])) {
2175 if (s[1] == '\\' && ckWARN(WARN_AMBIGUOUS)) {
2176 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
2177 "Possible unintended interpolation of $\\ in regex");
2178 }
79072805 2179 break; /* in regexp, $ might be tail anchor */
77772344 2180 }
79072805 2181 }
02aa26ce 2182
2b9d42f0
NIS
2183 /* End of else if chain - OP_TRANS rejoin rest */
2184
02aa26ce 2185 /* backslashes */
79072805
LW
2186 if (*s == '\\' && s+1 < send) {
2187 s++;
02aa26ce 2188
02aa26ce 2189 /* deprecate \1 in strings and substitution replacements */
3280af22 2190 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
a0d0e21e 2191 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
79072805 2192 {
599cee73 2193 if (ckWARN(WARN_SYNTAX))
9014280d 2194 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
79072805
LW
2195 *--s = '$';
2196 break;
2197 }
02aa26ce
NT
2198
2199 /* string-change backslash escapes */
3280af22 2200 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
79072805
LW
2201 --s;
2202 break;
2203 }
cc74c5bd
TS
2204 /* skip any other backslash escapes in a pattern */
2205 else if (PL_lex_inpat) {
2206 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2207 goto default_action;
2208 }
02aa26ce
NT
2209
2210 /* if we get here, it's either a quoted -, or a digit */
79072805 2211 switch (*s) {
02aa26ce
NT
2212
2213 /* quoted - in transliterations */
79072805 2214 case '-':
3280af22 2215 if (PL_lex_inwhat == OP_TRANS) {
79072805
LW
2216 *d++ = *s++;
2217 continue;
2218 }
2219 /* FALL THROUGH */
2220 default:
11b8faa4 2221 {
86f97054 2222 if ((isALPHA(*s) || isDIGIT(*s)) &&
041457d9 2223 ckWARN(WARN_MISC))
9014280d 2224 Perl_warner(aTHX_ packWARN(WARN_MISC),
e294cc5d
JH
2225 "Unrecognized escape \\%c passed through",
2226 *s);
11b8faa4 2227 /* default action is to copy the quoted character */
f9a63242 2228 goto default_action;
11b8faa4 2229 }
02aa26ce
NT
2230
2231 /* \132 indicates an octal constant */
79072805
LW
2232 case '0': case '1': case '2': case '3':
2233 case '4': case '5': case '6': case '7':
ba210ebe 2234 {
53305cf1
NC
2235 I32 flags = 0;
2236 STRLEN len = 3;
2237 uv = grok_oct(s, &len, &flags, NULL);
ba210ebe
JH
2238 s += len;
2239 }
012bcf8d 2240 goto NUM_ESCAPE_INSERT;
02aa26ce
NT
2241
2242 /* \x24 indicates a hex constant */
79072805 2243 case 'x':
a0ed51b3
LW
2244 ++s;
2245 if (*s == '{') {
9d4ba2ae 2246 char* const e = strchr(s, '}');
a4c04bdc
NC
2247 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2248 PERL_SCAN_DISALLOW_PREFIX;
53305cf1 2249 STRLEN len;
355860ce 2250
53305cf1 2251 ++s;
adaeee49 2252 if (!e) {
a0ed51b3 2253 yyerror("Missing right brace on \\x{}");
355860ce 2254 continue;
ba210ebe 2255 }
53305cf1
NC
2256 len = e - s;
2257 uv = grok_hex(s, &len, &flags, NULL);
ba210ebe 2258 s = e + 1;
a0ed51b3
LW
2259 }
2260 else {
ba210ebe 2261 {
53305cf1 2262 STRLEN len = 2;
a4c04bdc 2263 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
53305cf1 2264 uv = grok_hex(s, &len, &flags, NULL);
ba210ebe
JH
2265 s += len;
2266 }
012bcf8d
GS
2267 }
2268
2269 NUM_ESCAPE_INSERT:
2270 /* Insert oct or hex escaped character.
301d3d20 2271 * There will always enough room in sv since such
db42d148 2272 * escapes will be longer than any UTF-8 sequence
301d3d20 2273 * they can end up as. */
ba7cea30 2274
c7f1f016
NIS
2275 /* We need to map to chars to ASCII before doing the tests
2276 to cover EBCDIC
2277 */
c4d5f83a 2278 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
9aa983d2 2279 if (!has_utf8 && uv > 255) {
301d3d20
JH
2280 /* Might need to recode whatever we have
2281 * accumulated so far if it contains any
2282 * hibit chars.
2283 *
2284 * (Can't we keep track of that and avoid
2285 * this rescan? --jhi)
012bcf8d 2286 */
c7f1f016 2287 int hicount = 0;
63cd0674
NIS
2288 U8 *c;
2289 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
c4d5f83a 2290 if (!NATIVE_IS_INVARIANT(*c)) {
012bcf8d 2291 hicount++;
db42d148 2292 }
012bcf8d 2293 }
63cd0674 2294 if (hicount) {
9d4ba2ae 2295 const STRLEN offset = d - SvPVX_const(sv);
db42d148
NIS
2296 U8 *src, *dst;
2297 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
2298 src = (U8 *)d - 1;
2299 dst = src+hicount;
2300 d += hicount;
cfd0369c 2301 while (src >= (const U8 *)SvPVX_const(sv)) {
c4d5f83a 2302 if (!NATIVE_IS_INVARIANT(*src)) {
9d4ba2ae 2303 const U8 ch = NATIVE_TO_ASCII(*src);
eb160463
GS
2304 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
2305 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
012bcf8d
GS
2306 }
2307 else {
63cd0674 2308 *dst-- = *src;
012bcf8d 2309 }
c7f1f016 2310 src--;
012bcf8d
GS
2311 }
2312 }
2313 }
2314
9aa983d2 2315 if (has_utf8 || uv > 255) {
9041c2e3 2316 d = (char*)uvchr_to_utf8((U8*)d, uv);
4e553d73 2317 has_utf8 = TRUE;
f9a63242
JH
2318 if (PL_lex_inwhat == OP_TRANS &&
2319 PL_sublex_info.sub_op) {
2320 PL_sublex_info.sub_op->op_private |=
2321 (PL_lex_repl ? OPpTRANS_FROM_UTF
2322 : OPpTRANS_TO_UTF);
f9a63242 2323 }
e294cc5d
JH
2324#ifdef EBCDIC
2325 if (uv > 255 && !dorange)
2326 native_range = FALSE;
2327#endif
012bcf8d 2328 }
a0ed51b3 2329 else {
012bcf8d 2330 *d++ = (char)uv;
a0ed51b3 2331 }
012bcf8d
GS
2332 }
2333 else {
c4d5f83a 2334 *d++ = (char) uv;
a0ed51b3 2335 }
79072805 2336 continue;
02aa26ce 2337
b239daa5 2338 /* \N{LATIN SMALL LETTER A} is a named character */
4a2d328f 2339 case 'N':
55eda711 2340 ++s;
423cee85
JH
2341 if (*s == '{') {
2342 char* e = strchr(s, '}');
155aba94 2343 SV *res;
423cee85 2344 STRLEN len;
cfd0369c 2345 const char *str;
4e553d73 2346
423cee85 2347 if (!e) {
5777a3f7 2348 yyerror("Missing right brace on \\N{}");
423cee85
JH
2349 e = s - 1;
2350 goto cont_scan;
2351 }
dbc0d4f2
JH
2352 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2353 /* \N{U+...} */
2354 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2355 PERL_SCAN_DISALLOW_PREFIX;
2356 s += 3;
2357 len = e - s;
2358 uv = grok_hex(s, &len, &flags, NULL);
b57a0404
JH
2359 if ( e > s && len != (STRLEN)(e - s) ) {
2360 uv = 0xFFFD;
fc8cd66c 2361 }
dbc0d4f2
JH
2362 s = e + 1;
2363 goto NUM_ESCAPE_INSERT;
2364 }
55eda711 2365 res = newSVpvn(s + 1, e - s - 1);
bd61b366 2366 res = new_constant( NULL, 0, "charnames",
eb0d8d16 2367 res, NULL, s - 2, e - s + 3 );
f9a63242
JH
2368 if (has_utf8)
2369 sv_utf8_upgrade(res);
cfd0369c 2370 str = SvPV_const(res,len);
1c47067b
JH
2371#ifdef EBCDIC_NEVER_MIND
2372 /* charnames uses pack U and that has been
2373 * recently changed to do the below uni->native
2374 * mapping, so this would be redundant (and wrong,
2375 * the code point would be doubly converted).
2376 * But leave this in just in case the pack U change
2377 * gets revoked, but the semantics is still
2378 * desireable for charnames. --jhi */
cddc7ef4 2379 {
cfd0369c 2380 UV uv = utf8_to_uvchr((const U8*)str, 0);
cddc7ef4
JH
2381
2382 if (uv < 0x100) {
89ebb4a3 2383 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
cddc7ef4
JH
2384
2385 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2386 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
cfd0369c 2387 str = SvPV_const(res, len);
cddc7ef4
JH
2388 }
2389 }
2390#endif
89491803 2391 if (!has_utf8 && SvUTF8(res)) {
9d4ba2ae 2392 const char * const ostart = SvPVX_const(sv);
f08d6ad9
GS
2393 SvCUR_set(sv, d - ostart);
2394 SvPOK_on(sv);
e4f3eed8 2395 *d = '\0';
f08d6ad9 2396 sv_utf8_upgrade(sv);
d2f449dd 2397 /* this just broke our allocation above... */
eb160463 2398 SvGROW(sv, (STRLEN)(send - start));
f08d6ad9 2399 d = SvPVX(sv) + SvCUR(sv);
89491803 2400 has_utf8 = TRUE;
f08d6ad9 2401 }
eb160463 2402 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
9d4ba2ae 2403 const char * const odest = SvPVX_const(sv);
423cee85 2404
8973db79 2405 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
423cee85
JH
2406 d = SvPVX(sv) + (d - odest);
2407 }
e294cc5d
JH
2408#ifdef EBCDIC
2409 if (!dorange)
2410 native_range = FALSE; /* \N{} is guessed to be Unicode */
2411#endif
423cee85
JH
2412 Copy(str, d, len, char);
2413 d += len;
2414 SvREFCNT_dec(res);
2415 cont_scan:
2416 s = e + 1;
2417 }
2418 else
5777a3f7 2419 yyerror("Missing braces on \\N{}");
423cee85
JH
2420 continue;
2421
02aa26ce 2422 /* \c is a control character */
79072805
LW
2423 case 'c':
2424 s++;
961ce445 2425 if (s < send) {
ba210ebe 2426 U8 c = *s++;
c7f1f016
NIS
2427#ifdef EBCDIC
2428 if (isLOWER(c))
2429 c = toUPPER(c);
2430#endif
db42d148 2431 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
ba210ebe 2432 }
961ce445
RGS
2433 else {
2434 yyerror("Missing control char name in \\c");
2435 }
79072805 2436 continue;
02aa26ce
NT
2437
2438 /* printf-style backslashes, formfeeds, newlines, etc */
79072805 2439 case 'b':
db42d148 2440 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
79072805
LW
2441 break;
2442 case 'n':
db42d148 2443 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
79072805
LW
2444 break;
2445 case 'r':
db42d148 2446 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
79072805
LW
2447 break;
2448 case 'f':
db42d148 2449 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
79072805
LW
2450 break;
2451 case 't':
db42d148 2452 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
79072805 2453 break;
34a3fe2a 2454 case 'e':
db42d148 2455 *d++ = ASCII_TO_NEED(has_utf8,'\033');
34a3fe2a
PP
2456 break;
2457 case 'a':
db42d148 2458 *d++ = ASCII_TO_NEED(has_utf8,'\007');
79072805 2459 break;
02aa26ce
NT
2460 } /* end switch */
2461
79072805
LW
2462 s++;
2463 continue;
02aa26ce 2464 } /* end if (backslash) */
4c3a8340
TS
2465#ifdef EBCDIC
2466 else
2467 literal_endpoint++;
2468#endif
02aa26ce 2469
f9a63242 2470 default_action:
2b9d42f0
NIS
2471 /* If we started with encoded form, or already know we want it
2472 and then encode the next character */
2473 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
2474 STRLEN len = 1;
5f66b61c
AL
2475 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2476 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2b9d42f0
NIS
2477 s += len;
2478 if (need > len) {
2479 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
9d4ba2ae 2480 const STRLEN off = d - SvPVX_const(sv);
2b9d42f0
NIS
2481 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
2482 }
5f66b61c 2483 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2b9d42f0 2484 has_utf8 = TRUE;
e294cc5d
JH
2485#ifdef EBCDIC
2486 if (uv > 255 && !dorange)
2487 native_range = FALSE;
2488#endif
2b9d42f0
NIS
2489 }
2490 else {
2491 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2492 }
02aa26ce
NT
2493 } /* while loop to process each character */
2494
2495 /* terminate the string and set up the sv */
79072805 2496 *d = '\0';
95a20fc0 2497 SvCUR_set(sv, d - SvPVX_const(sv));
2b9d42f0 2498 if (SvCUR(sv) >= SvLEN(sv))
d0063567 2499 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2b9d42f0 2500
79072805 2501 SvPOK_on(sv);
9f4817db 2502 if (PL_encoding && !has_utf8) {
d0063567
DK
2503 sv_recode_to_utf8(sv, PL_encoding);
2504 if (SvUTF8(sv))
2505 has_utf8 = TRUE;
9f4817db 2506 }
2b9d42f0 2507 if (has_utf8) {
7e2040f0 2508 SvUTF8_on(sv);
2b9d42f0 2509 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
d0063567 2510 PL_sublex_info.sub_op->op_private |=
2b9d42f0
NIS
2511 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2512 }
2513 }
79072805 2514
02aa26ce 2515 /* shrink the sv if we allocated more than we used */
79072805 2516 if (SvCUR(sv) + 5 < SvLEN(sv)) {
1da4ca5f 2517 SvPV_shrink_to_cur(sv);
79072805 2518 }
02aa26ce 2519
6154021b 2520 /* return the substring (via pl_yylval) only if we parsed anything */
3280af22 2521 if (s > PL_bufptr) {
eb0d8d16
NC
2522 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) ) {
2523 const char *const key = PL_lex_inpat ? "qr" : "q";
2524 const STRLEN keylen = PL_lex_inpat ? 2 : 1;
2525 const char *type;
2526 STRLEN typelen;
2527
2528 if (PL_lex_inwhat == OP_TRANS) {
2529 type = "tr";
2530 typelen = 2;
2531 } else if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat) {
2532 type = "s";
2533 typelen = 1;
2534 } else {
2535 type = "qq";
2536 typelen = 2;
2537 }
2538
2539 sv = S_new_constant(aTHX_ start, s - start, key, keylen, sv, NULL,
2540 type, typelen);
2541 }
6154021b 2542 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
b3ac6de7 2543 } else
8990e307 2544 SvREFCNT_dec(sv);
79072805
LW
2545 return s;
2546}
2547
ffb4593c
NT
2548/* S_intuit_more
2549 * Returns TRUE if there's more to the expression (e.g., a subscript),
2550 * FALSE otherwise.
ffb4593c
NT
2551 *
2552 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2553 *
2554 * ->[ and ->{ return TRUE
2555 * { and [ outside a pattern are always subscripts, so return TRUE
2556 * if we're outside a pattern and it's not { or [, then return FALSE
2557 * if we're in a pattern and the first char is a {
2558 * {4,5} (any digits around the comma) returns FALSE
2559 * if we're in a pattern and the first char is a [
2560 * [] returns FALSE
2561 * [SOMETHING] has a funky algorithm to decide whether it's a
2562 * character class or not. It has to deal with things like
2563 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2564 * anything else returns TRUE
2565 */
2566
9cbb5ea2
GS
2567/* This is the one truly awful dwimmer necessary to conflate C and sed. */
2568
76e3520e 2569STATIC int
cea2e8a9 2570S_intuit_more(pTHX_ register char *s)
79072805 2571{
97aff369 2572 dVAR;
7918f24d
NC
2573
2574 PERL_ARGS_ASSERT_INTUIT_MORE;
2575
3280af22 2576 if (PL_lex_brackets)
79072805
LW
2577 return TRUE;
2578 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2579 return TRUE;
2580 if (*s != '{' && *s != '[')
2581 return FALSE;
3280af22 2582 if (!PL_lex_inpat)
79072805
LW
2583 return TRUE;
2584
2585 /* In a pattern, so maybe we have {n,m}. */
2586 if (*s == '{') {
2587 s++;
2588 if (!isDIGIT(*s))
2589 return TRUE;
2590 while (isDIGIT(*s))
2591 s++;
2592 if (*s == ',')
2593 s++;
2594 while (isDIGIT(*s))
2595 s++;
2596 if (*s == '}')
2597 return FALSE;
2598 return TRUE;
2599
2600 }
2601
2602 /* On the other hand, maybe we have a character class */
2603
2604 s++;
2605 if (*s == ']' || *s == '^')
2606 return FALSE;
2607 else {
ffb4593c 2608 /* this is terrifying, and it works */
79072805
LW
2609 int weight = 2; /* let's weigh the evidence */
2610 char seen[256];
f27ffc4a 2611 unsigned char un_char = 255, last_un_char;
9d4ba2ae 2612 const char * const send = strchr(s,']');
3280af22 2613 char tmpbuf[sizeof PL_tokenbuf * 4];
79072805
LW
2614
2615 if (!send) /* has to be an expression */
2616 return TRUE;
2617
2618 Zero(seen,256,char);
2619 if (*s == '$')
2620 weight -= 3;
2621 else if (isDIGIT(*s)) {
2622 if (s[1] != ']') {
2623 if (isDIGIT(s[1]) && s[2] == ']')
2624 weight -= 10;
2625 }
2626 else
2627 weight -= 100;
2628 }
2629 for (; s < send; s++) {
2630 last_un_char = un_char;
2631 un_char = (unsigned char)*s;
2632 switch (*s) {
2633 case '@':
2634 case '&':
2635 case '$':
2636 weight -= seen[un_char] * 10;
7e2040f0 2637 if (isALNUM_lazy_if(s+1,UTF)) {
90e5519e 2638 int len;
8903cb82 2639 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
90e5519e
NC
2640 len = (int)strlen(tmpbuf);
2641 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
79072805
LW
2642 weight -= 100;
2643 else
2644 weight -= 10;
2645 }
2646 else if (*s == '$' && s[1] &&
93a17b20
LW
2647 strchr("[#!%*<>()-=",s[1])) {
2648 if (/*{*/ strchr("])} =",s[2]))
79072805
LW
2649 weight -= 10;
2650 else
2651 weight -= 1;
2652 }
2653 break;
2654 case '\\':
2655 un_char = 254;
2656 if (s[1]) {
93a17b20 2657 if (strchr("wds]",s[1]))
79072805 2658 weight += 100;
10edeb5d 2659 else if (seen[(U8)'\''] || seen[(U8)'"'])
79072805 2660 weight += 1;
93a17b20 2661 else if (strchr("rnftbxcav",s[1]))
79072805
LW
2662 weight += 40;
2663 else if (isDIGIT(s[1])) {
2664 weight += 40;
2665 while (s[1] && isDIGIT(s[1]))
2666 s++;
2667 }
2668 }
2669 else
2670 weight += 100;
2671 break;
2672 case '-':
2673 if (s[1] == '\\')
2674 weight += 50;
93a17b20 2675 if (strchr("aA01! ",last_un_char))
79072805 2676 weight += 30;
93a17b20 2677 if (strchr("zZ79~",s[1]))
79072805 2678 weight += 30;
f27ffc4a
GS
2679 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2680 weight -= 5; /* cope with negative subscript */
79072805
LW
2681 break;
2682 default:
3792a11b
NC
2683 if (!isALNUM(last_un_char)
2684 && !(last_un_char == '$' || last_un_char == '@'
2685 || last_un_char == '&')
2686 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
79072805
LW
2687 char *d = tmpbuf;
2688 while (isALPHA(*s))
2689 *d++ = *s++;
2690 *d = '\0';
5458a98a 2691 if (keyword(tmpbuf, d - tmpbuf, 0))
79072805
LW
2692 weight -= 150;
2693 }
2694 if (un_char == last_un_char + 1)
2695 weight += 5;
2696 weight -= seen[un_char];
2697 break;
2698 }
2699 seen[un_char]++;
2700 }
2701 if (weight >= 0) /* probably a character class */
2702 return FALSE;
2703 }
2704
2705 return TRUE;
2706}
ffed7fef 2707
ffb4593c
NT
2708/*
2709 * S_intuit_method
2710 *
2711 * Does all the checking to disambiguate
2712 * foo bar
2713 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2714 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2715 *
2716 * First argument is the stuff after the first token, e.g. "bar".
2717 *
2718 * Not a method if bar is a filehandle.
2719 * Not a method if foo is a subroutine prototyped to take a filehandle.
2720 * Not a method if it's really "Foo $bar"
2721 * Method if it's "foo $bar"
2722 * Not a method if it's really "print foo $bar"
2723 * Method if it's really "foo package::" (interpreted as package->foo)
8f8cf39c 2724 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
3cb0bbe5 2725 * Not a method if bar is a filehandle or package, but is quoted with
ffb4593c
NT
2726 * =>
2727 */
2728
76e3520e 2729STATIC int
62d55b22 2730S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
a0d0e21e 2731{
97aff369 2732 dVAR;
a0d0e21e 2733 char *s = start + (*start == '$');
3280af22 2734 char tmpbuf[sizeof PL_tokenbuf];
a0d0e21e
LW
2735 STRLEN len;
2736 GV* indirgv;
5db06880
NC
2737#ifdef PERL_MAD
2738 int soff;
2739#endif
a0d0e21e 2740
7918f24d
NC
2741 PERL_ARGS_ASSERT_INTUIT_METHOD;
2742
a0d0e21e 2743 if (gv) {
62d55b22 2744 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
a0d0e21e 2745 return 0;
62d55b22
NC
2746 if (cv) {
2747 if (SvPOK(cv)) {
2748 const char *proto = SvPVX_const(cv);
2749 if (proto) {
2750 if (*proto == ';')
2751 proto++;
2752 if (*proto == '*')
2753 return 0;
2754 }
b6c543e3
IZ
2755 }
2756 } else
c35e046a 2757 gv = NULL;
a0d0e21e 2758 }
8903cb82 2759 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
ffb4593c
NT
2760 /* start is the beginning of the possible filehandle/object,
2761 * and s is the end of it
2762 * tmpbuf is a copy of it
2763 */
2764
a0d0e21e 2765 if (*start == '$') {
3ef1310e
RGS
2766 if (gv || PL_last_lop_op == OP_PRINT || PL_last_lop_op == OP_SAY ||
2767 isUPPER(*PL_tokenbuf))
a0d0e21e 2768 return 0;
5db06880
NC
2769#ifdef PERL_MAD
2770 len = start - SvPVX(PL_linestr);
2771#endif
29595ff2 2772 s = PEEKSPACE(s);
f0092767 2773#ifdef PERL_MAD
5db06880
NC
2774 start = SvPVX(PL_linestr) + len;
2775#endif
3280af22
NIS
2776 PL_bufptr = start;
2777 PL_expect = XREF;
a0d0e21e
LW
2778 return *s == '(' ? FUNCMETH : METHOD;
2779 }
5458a98a 2780 if (!keyword(tmpbuf, len, 0)) {
c3e0f903
GS
2781 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2782 len -= 2;
2783 tmpbuf[len] = '\0';
5db06880
NC
2784#ifdef PERL_MAD
2785 soff = s - SvPVX(PL_linestr);
2786#endif
c3e0f903
GS
2787 goto bare_package;
2788 }
90e5519e 2789 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
8ebc5c01 2790 if (indirgv && GvCVu(indirgv))
a0d0e21e
LW
2791 return 0;
2792 /* filehandle or package name makes it a method */
da51bb9b 2793 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, 0)) {
5db06880
NC
2794#ifdef PERL_MAD
2795 soff = s - SvPVX(PL_linestr);
2796#endif
29595ff2 2797 s = PEEKSPACE(s);
3280af22 2798 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
55497cff 2799 return 0; /* no assumptions -- "=>" quotes bearword */
c3e0f903 2800 bare_package:
cd81e915 2801 start_force(PL_curforce);
9ded7720 2802 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
79cb57f6 2803 newSVpvn(tmpbuf,len));
9ded7720 2804 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
5db06880
NC
2805 if (PL_madskills)
2806 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
3280af22 2807 PL_expect = XTERM;
a0d0e21e 2808 force_next(WORD);
3280af22 2809 PL_bufptr = s;
5db06880
NC
2810#ifdef PERL_MAD
2811 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2812#endif
a0d0e21e
LW
2813 return *s == '(' ? FUNCMETH : METHOD;
2814 }
2815 }
2816 return 0;
2817}
2818
16d20bd9 2819/* Encoded script support. filter_add() effectively inserts a
4e553d73 2820 * 'pre-processing' function into the current source input stream.
16d20bd9
AD
2821 * Note that the filter function only applies to the current source file
2822 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2823 *
2824 * The datasv parameter (which may be NULL) can be used to pass
2825 * private data to this instance of the filter. The filter function
2826 * can recover the SV using the FILTER_DATA macro and use it to
2827 * store private buffers and state information.
2828 *
2829 * The supplied datasv parameter is upgraded to a PVIO type
4755096e 2830 * and the IoDIRP/IoANY field is used to store the function pointer,
e0c19803 2831 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
16d20bd9
AD
2832 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2833 * private use must be set using malloc'd pointers.
2834 */
16d20bd9
AD
2835
2836SV *
864dbfa3 2837Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
16d20bd9 2838{
97aff369 2839 dVAR;
f4c556ac 2840 if (!funcp)
a0714e2c 2841 return NULL;
f4c556ac 2842
5486870f
DM
2843 if (!PL_parser)
2844 return NULL;
2845
3280af22
NIS
2846 if (!PL_rsfp_filters)
2847 PL_rsfp_filters = newAV();
16d20bd9 2848 if (!datasv)
561b68a9 2849 datasv = newSV(0);
862a34c6 2850 SvUPGRADE(datasv, SVt_PVIO);
8141890a 2851 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
e0c19803 2852 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
f4c556ac 2853 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
55662e27
JH
2854 FPTR2DPTR(void *, IoANY(datasv)),
2855 SvPV_nolen(datasv)));
3280af22
NIS
2856 av_unshift(PL_rsfp_filters, 1);
2857 av_store(PL_rsfp_filters, 0, datasv) ;
16d20bd9
AD
2858 return(datasv);
2859}
4e553d73 2860
16d20bd9
AD
2861
2862/* Delete most recently added instance of this filter function. */
a0d0e21e 2863void
864dbfa3 2864Perl_filter_del(pTHX_ filter_t funcp)
16d20bd9 2865{
97aff369 2866 dVAR;
e0c19803 2867 SV *datasv;
24801a4b 2868
7918f24d
NC
2869 PERL_ARGS_ASSERT_FILTER_DEL;
2870
33073adb 2871#ifdef DEBUGGING
55662e27
JH
2872 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2873 FPTR2DPTR(void*, funcp)));
33073adb 2874#endif
5486870f 2875 if (!PL_parser || !PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
16d20bd9
AD
2876 return;
2877 /* if filter is on top of stack (usual case) just pop it off */
e0c19803 2878 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
8141890a 2879 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
e0c19803 2880 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
4755096e 2881 IoANY(datasv) = (void *)NULL;
3280af22 2882 sv_free(av_pop(PL_rsfp_filters));
e50aee73 2883
16d20bd9
AD
2884 return;
2885 }
2886 /* we need to search for the correct entry and clear it */
cea2e8a9 2887 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
16d20bd9
AD
2888}
2889
2890
1de9afcd
RGS
2891/* Invoke the idxth filter function for the current rsfp. */
2892/* maxlen 0 = read one text line */
16d20bd9 2893I32
864dbfa3 2894Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
a0d0e21e 2895{
97aff369 2896 dVAR;
16d20bd9
AD
2897 filter_t funcp;
2898 SV *datasv = NULL;
f482118e
NC
2899 /* This API is bad. It should have been using unsigned int for maxlen.
2900 Not sure if we want to change the API, but if not we should sanity
2901 check the value here. */
39cd7a59
NC
2902 const unsigned int correct_length
2903 = maxlen < 0 ?
2904#ifdef PERL_MICRO
2905 0x7FFFFFFF
2906#else
2907 INT_MAX
2908#endif
2909 : maxlen;
e50aee73 2910
7918f24d
NC
2911 PERL_ARGS_ASSERT_FILTER_READ;
2912
5486870f 2913 if (!PL_parser || !PL_rsfp_filters)
16d20bd9 2914 return -1;
1de9afcd 2915 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
16d20bd9
AD
2916 /* Provide a default input filter to make life easy. */
2917 /* Note that we append to the line. This is handy. */
f4c556ac
GS
2918 DEBUG_P(PerlIO_printf(Perl_debug_log,
2919 "filter_read %d: from rsfp\n", idx));
f482118e 2920 if (correct_length) {
16d20bd9
AD
2921 /* Want a block */
2922 int len ;
f54cb97a 2923 const int old_len = SvCUR(buf_sv);
16d20bd9
AD
2924
2925 /* ensure buf_sv is large enough */
f482118e
NC
2926 SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2927 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2928 correct_length)) <= 0) {
3280af22 2929 if (PerlIO_error(PL_rsfp))
37120919
AD
2930 return -1; /* error */
2931 else
2932 return 0 ; /* end of file */
2933 }
16d20bd9
AD
2934 SvCUR_set(buf_sv, old_len + len) ;
2935 } else {
2936 /* Want a line */
3280af22
NIS
2937 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2938 if (PerlIO_error(PL_rsfp))
37120919
AD
2939 return -1; /* error */
2940 else
2941 return 0 ; /* end of file */
2942 }
16d20bd9
AD
2943 }
2944 return SvCUR(buf_sv);
2945 }
2946 /* Skip this filter slot if filter has been deleted */
1de9afcd 2947 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
f4c556ac
GS
2948 DEBUG_P(PerlIO_printf(Perl_debug_log,
2949 "filter_read %d: skipped (filter deleted)\n",
2950 idx));
f482118e 2951 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
16d20bd9
AD
2952 }
2953 /* Get function pointer hidden within datasv */
8141890a 2954 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
f4c556ac
GS
2955 DEBUG_P(PerlIO_printf(Perl_debug_log,
2956 "filter_read %d: via function %p (%s)\n",
ca0270c4 2957 idx, (void*)datasv, SvPV_nolen_const(datasv)));
16d20bd9
AD
2958 /* Call function. The function is expected to */
2959 /* call "FILTER_READ(idx+1, buf_sv)" first. */
37120919 2960 /* Return: <0:error, =0:eof, >0:not eof */
f482118e 2961 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
16d20bd9
AD
2962}
2963
76e3520e 2964STATIC char *
cea2e8a9 2965S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
16d20bd9 2966{
97aff369 2967 dVAR;
7918f24d
NC
2968
2969 PERL_ARGS_ASSERT_FILTER_GETS;
2970
c39cd008 2971#ifdef PERL_CR_FILTER
3280af22 2972 if (!PL_rsfp_filters) {
c39cd008 2973 filter_add(S_cr_textfilter,NULL);
a868473f
NIS
2974 }
2975#endif
3280af22 2976 if (PL_rsfp_filters) {
55497cff 2977 if (!append)
2978 SvCUR_set(sv, 0); /* start with empty line */
16d20bd9
AD
2979 if (FILTER_READ(0, sv, 0) > 0)
2980 return ( SvPVX(sv) ) ;
2981 else
bd61b366 2982 return NULL ;
16d20bd9 2983 }
9d116dd7 2984 else
fd049845 2985 return (sv_gets(sv, fp, append));
a0d0e21e
LW
2986}
2987
01ec43d0 2988STATIC HV *
9bde8eb0 2989S_find_in_my_stash(pTHX_ const char *pkgname, STRLEN len)
def3634b 2990{
97aff369 2991 dVAR;
def3634b
GS
2992 GV *gv;
2993
7918f24d
NC
2994 PERL_ARGS_ASSERT_FIND_IN_MY_STASH;
2995
01ec43d0 2996 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
def3634b
GS
2997 return PL_curstash;
2998
2999 if (len > 2 &&
3000 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
90e5519e 3001 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
01ec43d0
GS
3002 {
3003 return GvHV(gv); /* Foo:: */
def3634b
GS
3004 }
3005
3006 /* use constant CLASS => 'MyClass' */
c35e046a
AL
3007 gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
3008 if (gv && GvCV(gv)) {
3009 SV * const sv = cv_const_sv(GvCV(gv));
3010 if (sv)
9bde8eb0 3011 pkgname = SvPV_const(sv, len);
def3634b
GS
3012 }
3013
9bde8eb0 3014 return gv_stashpvn(pkgname, len, 0);
def3634b 3015}
a0d0e21e 3016
e3f73d4e
RGS
3017/*
3018 * S_readpipe_override
3019 * Check whether readpipe() is overriden, and generates the appropriate
3020 * optree, provided sublex_start() is called afterwards.
3021 */
3022STATIC void
1d51329b 3023S_readpipe_override(pTHX)
e3f73d4e
RGS
3024{
3025 GV **gvp;
3026 GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
6154021b 3027 pl_yylval.ival = OP_BACKTICK;
e3f73d4e
RGS
3028 if ((gv_readpipe
3029 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
3030 ||
3031 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
d5e716f5 3032 && (gv_readpipe = *gvp) && isGV_with_GP(gv_readpipe)
e3f73d4e
RGS
3033 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
3034 {
3035 PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
3036 append_elem(OP_LIST,
3037 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
3038 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
3039 }
e3f73d4e
RGS
3040}
3041
5db06880
NC
3042#ifdef PERL_MAD
3043 /*
3044 * Perl_madlex
3045 * The intent of this yylex wrapper is to minimize the changes to the
3046 * tokener when we aren't interested in collecting madprops. It remains
3047 * to be seen how successful this strategy will be...
3048 */
3049
3050int
3051Perl_madlex(pTHX)
3052{
3053 int optype;
3054 char *s = PL_bufptr;
3055
cd81e915
NC
3056 /* make sure PL_thiswhite is initialized */
3057 PL_thiswhite = 0;
3058 PL_thismad = 0;
5db06880 3059
cd81e915 3060 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
5db06880
NC
3061 if (PL_pending_ident)
3062 return S_pending_ident(aTHX);
3063
3064 /* previous token ate up our whitespace? */
cd81e915
NC
3065 if (!PL_lasttoke && PL_nextwhite) {
3066 PL_thiswhite = PL_nextwhite;
3067 PL_nextwhite = 0;
5db06880
NC
3068 }
3069
3070 /* isolate the token, and figure out where it is without whitespace */
cd81e915
NC
3071 PL_realtokenstart = -1;
3072 PL_thistoken = 0;
5db06880
NC
3073 optype = yylex();
3074 s = PL_bufptr;
cd81e915 3075 assert(PL_curforce < 0);
5db06880 3076
cd81e915
NC
3077 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
3078 if (!PL_thistoken) {
3079 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
6b29d1f5 3080 PL_thistoken = newSVpvs("");
5db06880 3081 else {
c35e046a 3082 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
cd81e915 3083 PL_thistoken = newSVpvn(tstart, s - tstart);
5db06880
NC
3084 }
3085 }
cd81e915
NC
3086 if (PL_thismad) /* install head */
3087 CURMAD('X', PL_thistoken);
5db06880
NC
3088 }
3089
3090 /* last whitespace of a sublex? */
cd81e915
NC
3091 if (optype == ')' && PL_endwhite) {
3092 CURMAD('X', PL_endwhite);
5db06880
NC
3093 }
3094
cd81e915 3095 if (!PL_thismad) {
5db06880
NC
3096
3097 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
cd81e915
NC
3098 if (!PL_thiswhite && !PL_endwhite && !optype) {
3099 sv_free(PL_thistoken);
3100 PL_thistoken = 0;
5db06880
NC
3101 return 0;
3102 }
3103
3104 /* put off final whitespace till peg */
3105 if (optype == ';' && !PL_rsfp) {
cd81e915
NC
3106 PL_nextwhite = PL_thiswhite;
3107 PL_thiswhite = 0;
5db06880 3108 }
cd81e915
NC
3109 else if (PL_thisopen) {
3110 CURMAD('q', PL_thisopen);
3111 if (PL_thistoken)
3112 sv_free(PL_thistoken);
3113 PL_thistoken = 0;
5db06880
NC
3114 }
3115 else {
3116 /* Store actual token text as madprop X */
cd81e915 3117 CURMAD('X', PL_thistoken);
5db06880
NC
3118 }
3119
cd81e915 3120 if (PL_thiswhite) {
5db06880 3121 /* add preceding whitespace as madprop _ */
cd81e915 3122 CURMAD('_', PL_thiswhite);
5db06880
NC
3123 }
3124
cd81e915 3125 if (PL_thisstuff) {
5db06880 3126 /* add quoted material as madprop = */
cd81e915 3127 CURMAD('=', PL_thisstuff);
5db06880
NC
3128 }
3129
cd81e915 3130 if (PL_thisclose) {
5db06880 3131 /* add terminating quote as madprop Q */
cd81e915 3132 CURMAD('Q', PL_thisclose);
5db06880
NC
3133 }
3134 }
3135
3136 /* special processing based on optype */
3137
3138 switch (optype) {
3139
3140 /* opval doesn't need a TOKEN since it can already store mp */
3141 case WORD:
3142 case METHOD:
3143 case FUNCMETH:
3144 case THING:
3145 case PMFUNC:
3146 case PRIVATEREF:
3147 case FUNC0SUB:
3148 case UNIOPSUB:
3149 case LSTOPSUB:
6154021b
RGS
3150 if (pl_yylval.opval)
3151 append_madprops(PL_thismad, pl_yylval.opval, 0);
cd81e915 3152 PL_thismad = 0;
5db06880
NC
3153 return optype;
3154
3155 /* fake EOF */
3156 case 0:
3157 optype = PEG;
cd81e915
NC
3158 if (PL_endwhite) {
3159 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
3160 PL_endwhite = 0;
5db06880
NC
3161 }
3162 break;
3163
3164 case ']':
3165 case '}':
cd81e915 3166 if (PL_faketokens)
5db06880
NC
3167 break;
3168 /* remember any fake bracket that lexer is about to discard */
3169 if (PL_lex_brackets == 1 &&
3170 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
3171 {
3172 s = PL_bufptr;
3173 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3174 s++;
3175 if (*s == '}') {
cd81e915
NC
3176 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
3177 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3178 PL_thiswhite = 0;
5db06880
NC
3179 PL_bufptr = s - 1;
3180 break; /* don't bother looking for trailing comment */
3181 }
3182 else
3183 s = PL_bufptr;
3184 }
3185 if (optype == ']')
3186 break;
3187 /* FALLTHROUGH */
3188
3189 /* attach a trailing comment to its statement instead of next token */
3190 case ';':
cd81e915 3191 if (PL_faketokens)
5db06880
NC
3192 break;
3193 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
3194 s = PL_bufptr;
3195 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3196 s++;
3197 if (*s == '\n' || *s == '#') {
3198 while (s < PL_bufend && *s != '\n')
3199 s++;
3200 if (s < PL_bufend)
3201 s++;
cd81e915
NC
3202 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
3203 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3204 PL_thiswhite = 0;
5db06880
NC
3205 PL_bufptr = s;
3206 }
3207 }
3208 break;
3209
3210 /* pval */
3211 case LABEL:
3212 break;
3213
3214 /* ival */
3215 default:
3216 break;
3217
3218 }
3219
3220 /* Create new token struct. Note: opvals return early above. */
6154021b 3221 pl_yylval.tkval = newTOKEN(optype, pl_yylval, PL_thismad);
cd81e915 3222 PL_thismad = 0;
5db06880
NC
3223 return optype;
3224}
3225#endif
3226
468aa647 3227STATIC char *
cc6ed77d 3228S_tokenize_use(pTHX_ int is_use, char *s) {
97aff369 3229 dVAR;
7918f24d
NC
3230
3231 PERL_ARGS_ASSERT_TOKENIZE_USE;
3232
468aa647
RGS
3233 if (PL_expect != XSTATE)
3234 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
3235 is_use ? "use" : "no"));
29595ff2 3236 s = SKIPSPACE1(s);
468aa647
RGS
3237 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
3238 s = force_version(s, TRUE);
29595ff2 3239 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
cd81e915 3240 start_force(PL_curforce);
9ded7720 3241 NEXTVAL_NEXTTOKE.opval = NULL;
468aa647
RGS
3242 force_next(WORD);
3243 }
3244 else if (*s == 'v') {
3245 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3246 s = force_version(s, FALSE);
3247 }
3248 }
3249 else {
3250 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3251 s = force_version(s, FALSE);
3252 }
6154021b 3253 pl_yylval.ival = is_use;
468aa647
RGS
3254 return s;
3255}
748a9306 3256#ifdef DEBUGGING
27da23d5 3257 static const char* const exp_name[] =
09bef843 3258 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
27308ded 3259 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
09bef843 3260 };
748a9306 3261#endif
463ee0b2 3262
02aa26ce
NT
3263/*
3264 yylex
3265
3266 Works out what to call the token just pulled out of the input
3267 stream. The yacc parser takes care of taking the ops we return and
3268 stitching them into a tree.
3269
3270 Returns:
3271 PRIVATEREF
3272
3273 Structure:
3274 if read an identifier
3275 if we're in a my declaration
3276 croak if they tried to say my($foo::bar)
3277 build the ops for a my() declaration
3278 if it's an access to a my() variable
3279 are we in a sort block?
3280 croak if my($a); $a <=> $b
3281 build ops for access to a my() variable
3282 if in a dq string, and they've said @foo and we can't find @foo
3283 croak
3284 build ops for a bareword
3285 if we already built the token before, use it.
3286*/
3287
20141f0e 3288
dba4d153
JH
3289#ifdef __SC__
3290#pragma segment Perl_yylex
3291#endif
dba4d153 3292int
dba4d153 3293Perl_yylex(pTHX)
20141f0e 3294{
97aff369 3295 dVAR;
3afc138a 3296 register char *s = PL_bufptr;
378cc40b 3297 register char *d;
463ee0b2 3298 STRLEN len;
aa7440fb 3299 bool bof = FALSE;
a687059c 3300
10edeb5d
JH
3301 /* orig_keyword, gvp, and gv are initialized here because
3302 * jump to the label just_a_word_zero can bypass their
3303 * initialization later. */
3304 I32 orig_keyword = 0;
3305 GV *gv = NULL;
3306 GV **gvp = NULL;
3307
bbf60fe6 3308 DEBUG_T( {
396482e1 3309 SV* tmp = newSVpvs("");
b6007c36
DM
3310 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3311 (IV)CopLINE(PL_curcop),
3312 lex_state_names[PL_lex_state],
3313 exp_name[PL_expect],
3314 pv_display(tmp, s, strlen(s), 0, 60));
3315 SvREFCNT_dec(tmp);
bbf60fe6 3316 } );
02aa26ce 3317 /* check if there's an identifier for us to look at */
ba979b31 3318 if (PL_pending_ident)
bbf60fe6 3319 return REPORT(S_pending_ident(aTHX));
bbce6d69 3320
02aa26ce
NT
3321 /* no identifier pending identification */
3322
3280af22 3323 switch (PL_lex_state) {
79072805
LW
3324#ifdef COMMENTARY
3325 case LEX_NORMAL: /* Some compilers will produce faster */
3326 case LEX_INTERPNORMAL: /* code if we comment these out. */
3327 break;
3328#endif
3329
09bef843 3330 /* when we've already built the next token, just pull it out of the queue */
79072805 3331 case LEX_KNOWNEXT:
5db06880
NC
3332#ifdef PERL_MAD
3333 PL_lasttoke--;
6154021b 3334 pl_yylval = PL_nexttoke[PL_lasttoke].next_val;
5db06880 3335 if (PL_madskills) {
cd81e915 3336 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
5db06880 3337 PL_nexttoke[PL_lasttoke].next_mad = 0;
cd81e915 3338 if (PL_thismad && PL_thismad->mad_key == '_') {
daba3364 3339 PL_thiswhite = MUTABLE_SV(PL_thismad->mad_val);
cd81e915
NC
3340 PL_thismad->mad_val = 0;
3341 mad_free(PL_thismad);
3342 PL_thismad = 0;
5db06880
NC
3343 }
3344 }
3345 if (!PL_lasttoke) {
3346 PL_lex_state = PL_lex_defer;
3347 PL_expect = PL_lex_expect;
3348 PL_lex_defer = LEX_NORMAL;
3349 if (!PL_nexttoke[PL_lasttoke].next_type)
3350 return yylex();
3351 }
3352#else
3280af22 3353 PL_nexttoke--;
6154021b 3354 pl_yylval = PL_nextval[PL_nexttoke];
3280af22
NIS
3355 if (!PL_nexttoke) {
3356 PL_lex_state = PL_lex_defer;
3357 PL_expect = PL_lex_expect;
3358 PL_lex_defer = LEX_NORMAL;
463ee0b2 3359 }
5db06880
NC
3360#endif
3361#ifdef PERL_MAD
3362 /* FIXME - can these be merged? */
3363 return(PL_nexttoke[PL_lasttoke].next_type);
3364#else
bbf60fe6 3365 return REPORT(PL_nexttype[PL_nexttoke]);
5db06880 3366#endif
79072805 3367
02aa26ce 3368 /* interpolated case modifiers like \L \U, including \Q and \E.
3280af22 3369 when we get here, PL_bufptr is at the \
02aa26ce 3370 */
79072805
LW
3371 case LEX_INTERPCASEMOD:
3372#ifdef DEBUGGING
3280af22 3373 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
cea2e8a9 3374 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
79072805 3375#endif
02aa26ce 3376 /* handle \E or end of string */
3280af22 3377 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
02aa26ce 3378 /* if at a \E */
3280af22 3379 if (PL_lex_casemods) {
f54cb97a 3380 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3280af22 3381 PL_lex_casestack[PL_lex_casemods] = '\0';
02aa26ce 3382
3792a11b
NC
3383 if (PL_bufptr != PL_bufend
3384 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3280af22
NIS
3385 PL_bufptr += 2;
3386 PL_lex_state = LEX_INTERPCONCAT;
5db06880
NC
3387#ifdef PERL_MAD
3388 if (PL_madskills)
6b29d1f5 3389 PL_thistoken = newSVpvs("\\E");
5db06880 3390#endif
a0d0e21e 3391 }
bbf60fe6 3392 return REPORT(')');
79072805 3393 }
5db06880
NC
3394#ifdef PERL_MAD
3395 while (PL_bufptr != PL_bufend &&
3396 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
cd81e915 3397 if (!PL_thiswhite)
6b29d1f5 3398 PL_thiswhite = newSVpvs("");
cd81e915 3399 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
5db06880
NC
3400 PL_bufptr += 2;
3401 }
3402#else
3280af22
NIS
3403 if (PL_bufptr != PL_bufend)
3404 PL_bufptr += 2;
5db06880 3405#endif
3280af22 3406 PL_lex_state = LEX_INTERPCONCAT;
cea2e8a9 3407 return yylex();
79072805
LW
3408 }
3409 else {
607df283 3410 DEBUG_T({ PerlIO_printf(Perl_debug_log,
b6007c36 3411 "### Saw case modifier\n"); });
3280af22 3412 s = PL_bufptr + 1;
6e909404 3413 if (s[1] == '\\' && s[2] == 'E') {
5db06880 3414#ifdef PERL_MAD
cd81e915 3415 if (!PL_thiswhite)
6b29d1f5 3416 PL_thiswhite = newSVpvs("");
cd81e915 3417 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
5db06880 3418#endif
89122651 3419 PL_bufptr = s + 3;
6e909404
JH
3420 PL_lex_state = LEX_INTERPCONCAT;
3421 return yylex();
a0d0e21e 3422 }
6e909404 3423 else {
90771dc0 3424 I32 tmp;
5db06880
NC
3425 if (!PL_madskills) /* when just compiling don't need correct */
3426 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3427 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3792a11b 3428 if ((*s == 'L' || *s == 'U') &&
6e909404
JH
3429 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3430 PL_lex_casestack[--PL_lex_casemods] = '\0';
bbf60fe6 3431 return REPORT(')');
6e909404
JH
3432 }
3433 if (PL_lex_casemods > 10)
3434 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3435 PL_lex_casestack[PL_lex_casemods++] = *s;
3436 PL_lex_casestack[PL_lex_casemods] = '\0';
3437 PL_lex_state = LEX_INTERPCONCAT;
cd81e915 3438 start_force(PL_curforce);
9ded7720 3439 NEXTVAL_NEXTTOKE.ival = 0;
6e909404 3440 force_next('(');
cd81e915 3441 start_force(PL_curforce);
6e909404 3442 if (*s == 'l')
9ded7720 3443 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
6e909404 3444 else if (*s == 'u')
9ded7720 3445 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
6e909404 3446 else if (*s == 'L')
9ded7720 3447 NEXTVAL_NEXTTOKE.ival = OP_LC;
6e909404 3448 else if (*s == 'U')
9ded7720 3449 NEXTVAL_NEXTTOKE.ival = OP_UC;
6e909404 3450 else if (*s == 'Q')
9ded7720 3451 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
6e909404
JH
3452 else
3453 Perl_croak(aTHX_ "panic: yylex");
5db06880 3454 if (PL_madskills) {
a5849ce5
NC
3455 SV* const tmpsv = newSVpvs("\\ ");
3456 /* replace the space with the character we want to escape
3457 */
3458 SvPVX(tmpsv)[1] = *s;
5db06880
NC
3459 curmad('_', tmpsv);
3460 }
6e909404 3461 PL_bufptr = s + 1;
a0d0e21e 3462 }
79072805 3463 force_next(FUNC);
3280af22
NIS
3464 if (PL_lex_starts) {
3465 s = PL_bufptr;
3466 PL_lex_starts = 0;
5db06880
NC
3467#ifdef PERL_MAD
3468 if (PL_madskills) {
cd81e915
NC
3469 if (PL_thistoken)
3470 sv_free(PL_thistoken);
6b29d1f5 3471 PL_thistoken = newSVpvs("");
5db06880
NC
3472 }
3473#endif
131b3ad0
DM
3474 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3475 if (PL_lex_casemods == 1 && PL_lex_inpat)
3476 OPERATOR(',');
3477 else
3478 Aop(OP_CONCAT);
79072805
LW
3479 }
3480 else
cea2e8a9 3481 return yylex();
79072805
LW
3482 }
3483
55497cff 3484 case LEX_INTERPPUSH:
bbf60fe6 3485 return REPORT(sublex_push());
55497cff 3486
79072805 3487 case LEX_INTERPSTART:
3280af22 3488 if (PL_bufptr == PL_bufend)
bbf60fe6 3489 return REPORT(sublex_done());
607df283 3490 DEBUG_T({ PerlIO_printf(Perl_debug_log,
b6007c36 3491 "### Interpolated variable\n"); });
3280af22
NIS
3492 PL_expect = XTERM;
3493 PL_lex_dojoin = (*PL_bufptr == '@');
3494 PL_lex_state = LEX_INTERPNORMAL;
3495 if (PL_lex_dojoin) {
cd81e915 3496 start_force(PL_curforce);
9ded7720 3497 NEXTVAL_NEXTTOKE.ival = 0;
79072805 3498 force_next(',');
cd81e915 3499 start_force(PL_curforce);
a0d0e21e 3500 force_ident("\"", '$');
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 = 0;
79072805 3506 force_next('(');
cd81e915 3507 start_force(PL_curforce);
9ded7720 3508 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
79072805
LW
3509 force_next(FUNC);
3510 }
3280af22
NIS
3511 if (PL_lex_starts++) {
3512 s = PL_bufptr;
5db06880
NC
3513#ifdef PERL_MAD
3514 if (PL_madskills) {
cd81e915
NC
3515 if (PL_thistoken)
3516 sv_free(PL_thistoken);
6b29d1f5 3517 PL_thistoken = newSVpvs("");
5db06880
NC
3518 }
3519#endif
131b3ad0
DM
3520 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3521 if (!PL_lex_casemods && PL_lex_inpat)
3522 OPERATOR(',');
3523 else
3524 Aop(OP_CONCAT);
79072805 3525 }
cea2e8a9 3526 return yylex();
79072805
LW
3527
3528 case LEX_INTERPENDMAYBE:
3280af22
NIS
3529 if (intuit_more(PL_bufptr)) {
3530 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
79072805
LW
3531 break;
3532 }
3533 /* FALL THROUGH */
3534
3535 case LEX_INTERPEND:
3280af22
NIS
3536 if (PL_lex_dojoin) {
3537 PL_lex_dojoin = FALSE;
3538 PL_lex_state = LEX_INTERPCONCAT;
5db06880
NC
3539#ifdef PERL_MAD
3540 if (PL_madskills) {
cd81e915
NC
3541 if (PL_thistoken)
3542 sv_free(PL_thistoken);
6b29d1f5 3543 PL_thistoken = newSVpvs("");
5db06880
NC
3544 }
3545#endif
bbf60fe6 3546 return REPORT(')');
79072805 3547 }
43a16006 3548 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
25da4f38 3549 && SvEVALED(PL_lex_repl))
43a16006 3550 {
e9fa98b2 3551 if (PL_bufptr != PL_bufend)
cea2e8a9 3552 Perl_croak(aTHX_ "Bad evalled substitution pattern");
a0714e2c 3553 PL_lex_repl = NULL;
e9fa98b2 3554 }
79072805
LW
3555 /* FALLTHROUGH */
3556 case LEX_INTERPCONCAT:
3557#ifdef DEBUGGING
3280af22 3558 if (PL_lex_brackets)
cea2e8a9 3559 Perl_croak(aTHX_ "panic: INTERPCONCAT");
79072805 3560#endif
3280af22 3561 if (PL_bufptr == PL_bufend)
bbf60fe6 3562 return REPORT(sublex_done());
79072805 3563
3280af22
NIS
3564 if (SvIVX(PL_linestr) == '\'') {
3565 SV *sv = newSVsv(PL_linestr);
3566 if (!PL_lex_inpat)
76e3520e 3567 sv = tokeq(sv);
3280af22 3568 else if ( PL_hints & HINT_NEW_RE )
eb0d8d16 3569 sv = new_constant(NULL, 0, "qr", sv, sv, "q", 1);
6154021b 3570 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3280af22 3571 s = PL_bufend;
79072805
LW
3572 }
3573 else {
3280af22 3574 s = scan_const(PL_bufptr);
79072805 3575 if (*s == '\\')
3280af22 3576 PL_lex_state = LEX_INTERPCASEMOD;
79072805 3577 else
3280af22 3578 PL_lex_state = LEX_INTERPSTART;
79072805
LW
3579 }
3580
3280af22 3581 if (s != PL_bufptr) {
cd81e915 3582 start_force(PL_curforce);
5db06880
NC
3583 if (PL_madskills) {
3584 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3585 }
6154021b 3586 NEXTVAL_NEXTTOKE = pl_yylval;
3280af22 3587 PL_expect = XTERM;
79072805 3588 force_next(THING);
131b3ad0 3589 if (PL_lex_starts++) {
5db06880
NC
3590#ifdef PERL_MAD
3591 if (PL_madskills) {
cd81e915
NC
3592 if (PL_thistoken)
3593 sv_free(PL_thistoken);
6b29d1f5 3594 PL_thistoken = newSVpvs("");
5db06880
NC
3595 }
3596#endif
131b3ad0
DM
3597 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3598 if (!PL_lex_casemods && PL_lex_inpat)
3599 OPERATOR(',');
3600 else
3601 Aop(OP_CONCAT);
3602 }
79072805 3603 else {
3280af22 3604 PL_bufptr = s;
cea2e8a9 3605 return yylex();
79072805
LW
3606 }
3607 }
3608
cea2e8a9 3609 return yylex();
a0d0e21e 3610 case LEX_FORMLINE:
3280af22
NIS
3611 PL_lex_state = LEX_NORMAL;
3612 s = scan_formline(PL_bufptr);
3613 if (!PL_lex_formbrack)
a0d0e21e
LW
3614 goto rightbracket;
3615 OPERATOR(';');
79072805
LW
3616 }
3617
3280af22
NIS
3618 s = PL_bufptr;
3619 PL_oldoldbufptr = PL_oldbufptr;
3620 PL_oldbufptr = s;
463ee0b2
LW
3621
3622 retry:
5db06880 3623#ifdef PERL_MAD
cd81e915
NC
3624 if (PL_thistoken) {
3625 sv_free(PL_thistoken);
3626 PL_thistoken = 0;
5db06880 3627 }
cd81e915 3628 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
5db06880 3629#endif
378cc40b
LW
3630 switch (*s) {
3631 default:
7e2040f0 3632 if (isIDFIRST_lazy_if(s,UTF))
834a4ddd 3633 goto keylookup;
987a03fc 3634 len = UTF ? Perl_utf8_length(aTHX_ (U8 *) PL_linestart, (U8 *) s) : (STRLEN) (s - PL_linestart);
356c7adf 3635 Perl_croak(aTHX_ "Unrecognized character \\x%02X in column %d", *s & 255, (int) len + 1);
e929a76b
LW
3636 case 4:
3637 case 26:
3638 goto fake_eof; /* emulate EOF on ^D or ^Z */
378cc40b 3639 case 0:
5db06880
NC
3640#ifdef PERL_MAD
3641 if (PL_madskills)
cd81e915 3642 PL_faketokens = 0;
5db06880 3643#endif
3280af22
NIS
3644 if (!PL_rsfp) {
3645 PL_last_uni = 0;
3646 PL_last_lop = 0;
c5ee2135 3647 if (PL_lex_brackets) {
10edeb5d
JH
3648 yyerror((const char *)
3649 (PL_lex_formbrack
3650 ? "Format not terminated"
3651 : "Missing right curly or square bracket"));
c5ee2135 3652 }
4e553d73 3653 DEBUG_T( { PerlIO_printf(Perl_debug_log,
607df283 3654 "### Tokener got EOF\n");
5f80b19c 3655 } );
79072805 3656 TOKEN(0);
463ee0b2 3657 }
3280af22 3658 if (s++ < PL_bufend)
a687059c 3659 goto retry; /* ignore stray nulls */
3280af22
NIS
3660 PL_last_uni = 0;
3661 PL_last_lop = 0;
3662 if (!PL_in_eval && !PL_preambled) {
3663 PL_preambled = TRUE;
5db06880
NC
3664#ifdef PERL_MAD
3665 if (PL_madskills)
cd81e915 3666 PL_faketokens = 1;
5db06880 3667#endif
5ab7ff98
NC
3668 if (PL_perldb) {
3669 /* Generate a string of Perl code to load the debugger.
3670 * If PERL5DB is set, it will return the contents of that,
3671 * otherwise a compile-time require of perl5db.pl. */
3672
3673 const char * const pdb = PerlEnv_getenv("PERL5DB");
3674
3675 if (pdb) {
3676 sv_setpv(PL_linestr, pdb);
3677 sv_catpvs(PL_linestr,";");
3678 } else {
3679 SETERRNO(0,SS_NORMAL);
3680 sv_setpvs(PL_linestr, "BEGIN { require 'perl5db.pl' };");
3681 }
3682 } else
3683 sv_setpvs(PL_linestr,"");
c62eb204
NC
3684 if (PL_preambleav) {
3685 SV **svp = AvARRAY(PL_preambleav);
3686 SV **const end = svp + AvFILLp(PL_preambleav);
3687 while(svp <= end) {
3688 sv_catsv(PL_linestr, *svp);
3689 ++svp;
396482e1 3690 sv_catpvs(PL_linestr, ";");
91b7def8 3691 }
daba3364 3692 sv_free(MUTABLE_SV(PL_preambleav));
3280af22 3693 PL_preambleav = NULL;
91b7def8 3694 }
9f639728
FR
3695 if (PL_minus_E)
3696 sv_catpvs(PL_linestr,
3697 "use feature ':5." STRINGIFY(PERL_VERSION) "';");
3280af22 3698 if (PL_minus_n || PL_minus_p) {
396482e1 3699 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3280af22 3700 if (PL_minus_l)
396482e1 3701 sv_catpvs(PL_linestr,"chomp;");
3280af22 3702 if (PL_minus_a) {
3280af22 3703 if (PL_minus_F) {
3792a11b
NC
3704 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3705 || *PL_splitstr == '"')
3280af22 3706 && strchr(PL_splitstr + 1, *PL_splitstr))
3db68c4c 3707 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
54310121 3708 else {
c8ef6a4b
NC
3709 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3710 bytes can be used as quoting characters. :-) */
dd374669 3711 const char *splits = PL_splitstr;
91d456ae 3712 sv_catpvs(PL_linestr, "our @F=split(q\0");
48c4c863
NC
3713 do {
3714 /* Need to \ \s */
dd374669
AL
3715 if (*splits == '\\')
3716 sv_catpvn(PL_linestr, splits, 1);
3717 sv_catpvn(PL_linestr, splits, 1);
3718 } while (*splits++);
48c4c863
NC
3719 /* This loop will embed the trailing NUL of
3720 PL_linestr as the last thing it does before
3721 terminating. */
396482e1 3722 sv_catpvs(PL_linestr, ");");
54310121 3723 }
2304df62
AD
3724 }
3725 else
396482e1 3726 sv_catpvs(PL_linestr,"our @F=split(' ');");
2304df62 3727 }
79072805 3728 }
396482e1 3729 sv_catpvs(PL_linestr, "\n");
3280af22
NIS
3730 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3731 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3732 PL_last_lop = PL_last_uni = NULL;
65269a95 3733 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
5fa550fb 3734 update_debugger_info(PL_linestr, NULL, 0);
79072805 3735 goto retry;
a687059c 3736 }
e929a76b 3737 do {
aa7440fb 3738 bof = PL_rsfp ? TRUE : FALSE;
bd61b366 3739 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
7e28d3af 3740 fake_eof:
5db06880 3741#ifdef PERL_MAD
cd81e915 3742 PL_realtokenstart = -1;
5db06880 3743#endif
7e28d3af 3744 if (PL_rsfp) {
4c84d7f2 3745 if ((PerlIO *)PL_rsfp == PerlIO_stdin())
7e28d3af
JH
3746 PerlIO_clearerr(PL_rsfp);
3747 else
3748 (void)PerlIO_close(PL_rsfp);
4608196e 3749 PL_rsfp = NULL;
7e28d3af
JH
3750 PL_doextract = FALSE;
3751 }
3752 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
5db06880
NC
3753#ifdef PERL_MAD
3754 if (PL_madskills)
cd81e915 3755 PL_faketokens = 1;
5db06880 3756#endif
49a54bbe
NC
3757 if (PL_minus_p)
3758 sv_setpvs(PL_linestr, ";}continue{print;}");
3759 else
3760 sv_setpvs(PL_linestr, ";}");
7e28d3af
JH
3761 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3762 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3763 PL_last_lop = PL_last_uni = NULL;
7e28d3af
JH
3764 PL_minus_n = PL_minus_p = 0;
3765 goto retry;
3766 }
3767 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
bd61b366 3768 PL_last_lop = PL_last_uni = NULL;
76f68e9b 3769 sv_setpvs(PL_linestr,"");
7e28d3af
JH
3770 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3771 }
7aa207d6
JH
3772 /* If it looks like the start of a BOM or raw UTF-16,
3773 * check if it in fact is. */
3774 else if (bof &&
3775 (*s == 0 ||
3776 *(U8*)s == 0xEF ||
3777 *(U8*)s >= 0xFE ||
3778 s[1] == 0)) {
226017aa 3779#ifdef PERLIO_IS_STDIO
e3f494f1
JH
3780# ifdef __GNU_LIBRARY__
3781# if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
226017aa
DD
3782# define FTELL_FOR_PIPE_IS_BROKEN
3783# endif
e3f494f1
JH
3784# else
3785# ifdef __GLIBC__
3786# if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3787# define FTELL_FOR_PIPE_IS_BROKEN
3788# endif
3789# endif
226017aa
DD
3790# endif
3791#endif
eb160463 3792 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
7e28d3af 3793 if (bof) {
3280af22 3794 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
7e28d3af 3795 s = swallow_bom((U8*)s);
e929a76b 3796 }
378cc40b 3797 }
3280af22 3798 if (PL_doextract) {
a0d0e21e 3799 /* Incest with pod. */
5db06880
NC
3800#ifdef PERL_MAD
3801 if (PL_madskills)
cd81e915 3802 sv_catsv(PL_thiswhite, PL_linestr);
5db06880 3803#endif
01a57ef7 3804 if (*s == '=' && strnEQ(s, "=cut", 4) && !isALPHA(s[4])) {
76f68e9b 3805 sv_setpvs(PL_linestr, "");
3280af22
NIS
3806 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3807 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3808 PL_last_lop = PL_last_uni = NULL;
3280af22 3809 PL_doextract = FALSE;
a0d0e21e 3810 }
4e553d73 3811 }
463ee0b2 3812 incline(s);
3280af22
NIS
3813 } while (PL_doextract);
3814 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
65269a95 3815 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
5fa550fb 3816 update_debugger_info(PL_linestr, NULL, 0);
3280af22 3817 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3818 PL_last_lop = PL_last_uni = NULL;
57843af0 3819 if (CopLINE(PL_curcop) == 1) {
3280af22 3820 while (s < PL_bufend && isSPACE(*s))
79072805 3821 s++;
a0d0e21e 3822 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
79072805 3823 s++;
5db06880
NC
3824#ifdef PERL_MAD
3825 if (PL_madskills)
cd81e915 3826 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
5db06880 3827#endif
bd61b366 3828 d = NULL;
3280af22 3829 if (!PL_in_eval) {
44a8e56a 3830 if (*s == '#' && *(s+1) == '!')
3831 d = s + 2;
3832#ifdef ALTERNATE_SHEBANG
3833 else {
bfed75c6 3834 static char const as[] = ALTERNATE_SHEBANG;
44a8e56a 3835 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3836 d = s + (sizeof(as) - 1);
3837 }
3838#endif /* ALTERNATE_SHEBANG */
3839 }
3840 if (d) {
b8378b72 3841 char *ipath;
774d564b 3842 char *ipathend;
b8378b72 3843
774d564b 3844 while (isSPACE(*d))
b8378b72
CS
3845 d++;
3846 ipath = d;
774d564b 3847 while (*d && !isSPACE(*d))
3848 d++;
3849 ipathend = d;
3850
3851#ifdef ARG_ZERO_IS_SCRIPT
3852 if (ipathend > ipath) {
3853 /*
3854 * HP-UX (at least) sets argv[0] to the script name,
3855 * which makes $^X incorrect. And Digital UNIX and Linux,
3856 * at least, set argv[0] to the basename of the Perl
3857 * interpreter. So, having found "#!", we'll set it right.
3858 */
fafc274c
NC
3859 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3860 SVt_PV)); /* $^X */
774d564b 3861 assert(SvPOK(x) || SvGMAGICAL(x));
cc49e20b 3862 if (sv_eq(x, CopFILESV(PL_curcop))) {
774d564b 3863 sv_setpvn(x, ipath, ipathend - ipath);
9607fc9c 3864 SvSETMAGIC(x);
3865 }
556c1dec
JH
3866 else {
3867 STRLEN blen;
3868 STRLEN llen;
cfd0369c 3869 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
9d4ba2ae 3870 const char * const lstart = SvPV_const(x,llen);
556c1dec
JH
3871 if (llen < blen) {
3872 bstart += blen - llen;
3873 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3874 sv_setpvn(x, ipath, ipathend - ipath);
3875 SvSETMAGIC(x);
3876 }
3877 }
3878 }
774d564b 3879 TAINT_NOT; /* $^X is always tainted, but that's OK */
8ebc5c01 3880 }
774d564b 3881#endif /* ARG_ZERO_IS_SCRIPT */
b8378b72
CS
3882
3883 /*
3884 * Look for options.
3885 */
748a9306 3886 d = instr(s,"perl -");
84e30d1a 3887 if (!d) {
748a9306 3888 d = instr(s,"perl");
84e30d1a
GS
3889#if defined(DOSISH)
3890 /* avoid getting into infinite loops when shebang
3891 * line contains "Perl" rather than "perl" */
3892 if (!d) {
3893 for (d = ipathend-4; d >= ipath; --d) {
3894 if ((*d == 'p' || *d == 'P')
3895 && !ibcmp(d, "perl", 4))
3896 {
3897 break;
3898 }
3899 }
3900 if (d < ipath)
bd61b366 3901 d = NULL;
84e30d1a
GS
3902 }
3903#endif
3904 }
44a8e56a 3905#ifdef ALTERNATE_SHEBANG
3906 /*
3907 * If the ALTERNATE_SHEBANG on this system starts with a
3908 * character that can be part of a Perl expression, then if
3909 * we see it but not "perl", we're probably looking at the
3910 * start of Perl code, not a request to hand off to some
3911 * other interpreter. Similarly, if "perl" is there, but
3912 * not in the first 'word' of the line, we assume the line
3913 * contains the start of the Perl program.
44a8e56a 3914 */
3915 if (d && *s != '#') {
f54cb97a 3916 const char *c = ipath;
44a8e56a 3917 while (*c && !strchr("; \t\r\n\f\v#", *c))
3918 c++;
3919 if (c < d)
bd61b366 3920 d = NULL; /* "perl" not in first word; ignore */
44a8e56a 3921 else
3922 *s = '#'; /* Don't try to parse shebang line */
3923 }
774d564b 3924#endif /* ALTERNATE_SHEBANG */
bf4acbe4 3925#ifndef MACOS_TRADITIONAL
748a9306 3926 if (!d &&
44a8e56a 3927 *s == '#' &&
774d564b 3928 ipathend > ipath &&
3280af22 3929 !PL_minus_c &&
748a9306 3930 !instr(s,"indir") &&
3280af22 3931 instr(PL_origargv[0],"perl"))
748a9306 3932 {
27da23d5 3933 dVAR;
9f68db38 3934 char **newargv;
9f68db38 3935
774d564b 3936 *ipathend = '\0';
3937 s = ipathend + 1;
3280af22 3938 while (s < PL_bufend && isSPACE(*s))
9f68db38 3939 s++;
3280af22 3940 if (s < PL_bufend) {
a02a5408 3941 Newxz(newargv,PL_origargc+3,char*);
9f68db38 3942 newargv[1] = s;
3280af22 3943 while (s < PL_bufend && !isSPACE(*s))
9f68db38
LW
3944 s++;
3945 *s = '\0';
3280af22 3946 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
9f68db38
LW
3947 }
3948 else
3280af22 3949 newargv = PL_origargv;
774d564b 3950 newargv[0] = ipath;
b35112e7 3951 PERL_FPU_PRE_EXEC
b4748376 3952 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
b35112e7 3953 PERL_FPU_POST_EXEC
cea2e8a9 3954 Perl_croak(aTHX_ "Can't exec %s", ipath);
9f68db38 3955 }
bf4acbe4 3956#endif
748a9306 3957 if (d) {
c35e046a
AL
3958 while (*d && !isSPACE(*d))
3959 d++;
3960 while (SPACE_OR_TAB(*d))
3961 d++;
748a9306
LW
3962
3963 if (*d++ == '-') {
f54cb97a 3964 const bool switches_done = PL_doswitches;
fb993905
GA
3965 const U32 oldpdb = PL_perldb;
3966 const bool oldn = PL_minus_n;
3967 const bool oldp = PL_minus_p;
c7030b81 3968 const char *d1 = d;
fb993905 3969
8cc95fdb 3970 do {
c7030b81
NC
3971 if (*d1 == 'M' || *d1 == 'm' || *d1 == 'C') {
3972 const char * const m = d1;
3973 while (*d1 && !isSPACE(*d1))
3974 d1++;
cea2e8a9 3975 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
c7030b81 3976 (int)(d1 - m), m);
8cc95fdb 3977 }
c7030b81
NC
3978 d1 = moreswitches(d1);
3979 } while (d1);
f0b2cf55
YST
3980 if (PL_doswitches && !switches_done) {
3981 int argc = PL_origargc;
3982 char **argv = PL_origargv;
3983 do {
3984 argc--,argv++;
3985 } while (argc && argv[0][0] == '-' && argv[0][1]);
3986 init_argv_symbols(argc,argv);
3987 }
65269a95 3988 if (((PERLDB_LINE || PERLDB_SAVESRC) && !oldpdb) ||
155aba94 3989 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
b084f20b 3990 /* if we have already added "LINE: while (<>) {",
3991 we must not do it again */
748a9306 3992 {
76f68e9b 3993 sv_setpvs(PL_linestr, "");
3280af22
NIS
3994 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3995 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3996 PL_last_lop = PL_last_uni = NULL;
3280af22 3997 PL_preambled = FALSE;
65269a95 3998 if (PERLDB_LINE || PERLDB_SAVESRC)
3280af22 3999 (void)gv_fetchfile(PL_origfilename);
748a9306
LW
4000 goto retry;
4001 }
a0d0e21e 4002 }
79072805 4003 }
9f68db38 4004 }
79072805 4005 }
3280af22
NIS
4006 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
4007 PL_bufptr = s;
4008 PL_lex_state = LEX_FORMLINE;
cea2e8a9 4009 return yylex();
ae986130 4010 }
378cc40b 4011 goto retry;
4fdae800 4012 case '\r':
6a27c188 4013#ifdef PERL_STRICT_CR
cea2e8a9 4014 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
4e553d73 4015 Perl_croak(aTHX_
cc507455 4016 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
a868473f 4017#endif
4fdae800 4018 case ' ': case '\t': case '\f': case 013:
bf4acbe4
GS
4019#ifdef MACOS_TRADITIONAL
4020 case '\312':
4021#endif
5db06880 4022#ifdef PERL_MAD
cd81e915 4023 PL_realtokenstart = -1;
ac372eb8
RD
4024 if (!PL_thiswhite)
4025 PL_thiswhite = newSVpvs("");
4026 sv_catpvn(PL_thiswhite, s, 1);
5db06880 4027#endif
ac372eb8 4028 s++;
378cc40b 4029 goto retry;
378cc40b 4030 case '#':
e929a76b 4031 case '\n':
5db06880 4032#ifdef PERL_MAD
cd81e915 4033 PL_realtokenstart = -1;
5db06880 4034 if (PL_madskills)
cd81e915 4035 PL_faketokens = 0;
5db06880 4036#endif
3280af22 4037 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
df0deb90
GS
4038 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
4039 /* handle eval qq[#line 1 "foo"\n ...] */
4040 CopLINE_dec(PL_curcop);
4041 incline(s);
4042 }
5db06880
NC
4043 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
4044 s = SKIPSPACE0(s);
4045 if (!PL_in_eval || PL_rsfp)
4046 incline(s);
4047 }
4048 else {
4049 d = s;
4050 while (d < PL_bufend && *d != '\n')
4051 d++;
4052 if (d < PL_bufend)
4053 d++;
4054 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
4055 Perl_croak(aTHX_ "panic: input overflow");
4056#ifdef PERL_MAD
4057 if (PL_madskills)
cd81e915 4058 PL_thiswhite = newSVpvn(s, d - s);
5db06880
NC
4059#endif
4060 s = d;
4061 incline(s);
4062 }
3280af22
NIS
4063 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
4064 PL_bufptr = s;
4065 PL_lex_state = LEX_FORMLINE;
cea2e8a9 4066 return yylex();
a687059c 4067 }
378cc40b 4068 }
a687059c 4069 else {
5db06880
NC
4070#ifdef PERL_MAD
4071 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
4072 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
cd81e915 4073 PL_faketokens = 0;
5db06880
NC
4074 s = SKIPSPACE0(s);
4075 TOKEN(PEG); /* make sure any #! line is accessible */
4076 }
4077 s = SKIPSPACE0(s);
4078 }
4079 else {
4080/* if (PL_madskills && PL_lex_formbrack) { */
4081 d = s;
4082 while (d < PL_bufend && *d != '\n')
4083 d++;
4084 if (d < PL_bufend)
4085 d++;
4086 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
4087 Perl_croak(aTHX_ "panic: input overflow");
4088 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
cd81e915 4089 if (!PL_thiswhite)
6b29d1f5 4090 PL_thiswhite = newSVpvs("");
5db06880 4091 if (CopLINE(PL_curcop) == 1) {
76f68e9b 4092 sv_setpvs(PL_thiswhite, "");
cd81e915 4093 PL_faketokens = 0;
5db06880 4094 }
cd81e915 4095 sv_catpvn(PL_thiswhite, s, d - s);
5db06880
NC
4096 }
4097 s = d;
4098/* }
4099 *s = '\0';
4100 PL_bufend = s; */
4101 }
4102#else
378cc40b 4103 *s = '\0';
3280af22 4104 PL_bufend = s;
5db06880 4105#endif
a687059c 4106 }
378cc40b
LW
4107 goto retry;
4108 case '-':
79072805 4109 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
e5edeb50 4110 I32 ftst = 0;
90771dc0 4111 char tmp;
e5edeb50 4112
378cc40b 4113 s++;
3280af22 4114 PL_bufptr = s;
748a9306
LW
4115 tmp = *s++;
4116
bf4acbe4 4117 while (s < PL_bufend && SPACE_OR_TAB(*s))
748a9306
LW
4118 s++;
4119
4120 if (strnEQ(s,"=>",2)) {
3280af22 4121 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
931e0695 4122 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
748a9306
LW
4123 OPERATOR('-'); /* unary minus */
4124 }
3280af22 4125 PL_last_uni = PL_oldbufptr;
748a9306 4126 switch (tmp) {
e5edeb50
JH
4127 case 'r': ftst = OP_FTEREAD; break;
4128 case 'w': ftst = OP_FTEWRITE; break;
4129 case 'x': ftst = OP_FTEEXEC; break;
4130 case 'o': ftst = OP_FTEOWNED; break;
4131 case 'R': ftst = OP_FTRREAD; break;
4132 case 'W': ftst = OP_FTRWRITE; break;
4133 case 'X': ftst = OP_FTREXEC; break;
4134 case 'O': ftst = OP_FTROWNED; break;
4135 case 'e': ftst = OP_FTIS; break;
4136 case 'z': ftst = OP_FTZERO; break;
4137 case 's': ftst = OP_FTSIZE; break;
4138 case 'f': ftst = OP_FTFILE; break;
4139 case 'd': ftst = OP_FTDIR; break;
4140 case 'l': ftst = OP_FTLINK; break;
4141 case 'p': ftst = OP_FTPIPE; break;
4142 case 'S': ftst = OP_FTSOCK; break;
4143 case 'u': ftst = OP_FTSUID; break;
4144 case 'g': ftst = OP_FTSGID; break;
4145 case 'k': ftst = OP_FTSVTX; break;
4146 case 'b': ftst = OP_FTBLK; break;
4147 case 'c': ftst = OP_FTCHR; break;
4148 case 't': ftst = OP_FTTTY; break;
4149 case 'T': ftst = OP_FTTEXT; break;
4150 case 'B': ftst = OP_FTBINARY; break;
4151 case 'M': case 'A': case 'C':
fafc274c 4152 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
e5edeb50
JH
4153 switch (tmp) {
4154 case 'M': ftst = OP_FTMTIME; break;
4155 case 'A': ftst = OP_FTATIME; break;
4156 case 'C': ftst = OP_FTCTIME; break;
4157 default: break;
4158 }
4159 break;
378cc40b 4160 default:
378cc40b
LW
4161 break;
4162 }
e5edeb50 4163 if (ftst) {
eb160463 4164 PL_last_lop_op = (OPCODE)ftst;
4e553d73 4165 DEBUG_T( { PerlIO_printf(Perl_debug_log,
a18d764d 4166 "### Saw file test %c\n", (int)tmp);
5f80b19c 4167 } );
e5edeb50
JH
4168 FTST(ftst);
4169 }
4170 else {
4171 /* Assume it was a minus followed by a one-letter named
4172 * subroutine call (or a -bareword), then. */
95c31fe3 4173 DEBUG_T( { PerlIO_printf(Perl_debug_log,
17ad61e0 4174 "### '-%c' looked like a file test but was not\n",
4fccd7c6 4175 (int) tmp);
5f80b19c 4176 } );
3cf7b4c4 4177 s = --PL_bufptr;
e5edeb50 4178 }
378cc40b 4179 }
90771dc0
NC
4180 {
4181 const char tmp = *s++;
4182 if (*s == tmp) {
4183 s++;
4184 if (PL_expect == XOPERATOR)
4185 TERM(POSTDEC);
4186 else
4187 OPERATOR(PREDEC);
4188 }
4189 else if (*s == '>') {
4190 s++;
29595ff2 4191 s = SKIPSPACE1(s);
90771dc0
NC
4192 if (isIDFIRST_lazy_if(s,UTF)) {
4193 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
4194 TOKEN(ARROW);
4195 }
4196 else if (*s == '$')
4197 OPERATOR(ARROW);
4198 else
4199 TERM(ARROW);
4200 }
3280af22 4201 if (PL_expect == XOPERATOR)
90771dc0
NC
4202 Aop(OP_SUBTRACT);
4203 else {
4204 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4205 check_uni();
4206 OPERATOR('-'); /* unary minus */
79072805 4207 }
2f3197b3 4208 }
79072805 4209
378cc40b 4210 case '+':
90771dc0
NC
4211 {
4212 const char tmp = *s++;
4213 if (*s == tmp) {
4214 s++;
4215 if (PL_expect == XOPERATOR)
4216 TERM(POSTINC);
4217 else
4218 OPERATOR(PREINC);
4219 }
3280af22 4220 if (PL_expect == XOPERATOR)
90771dc0
NC
4221 Aop(OP_ADD);
4222 else {
4223 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4224 check_uni();
4225 OPERATOR('+');
4226 }
2f3197b3 4227 }
a687059c 4228
378cc40b 4229 case '*':
3280af22
NIS
4230 if (PL_expect != XOPERATOR) {
4231 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4232 PL_expect = XOPERATOR;
4233 force_ident(PL_tokenbuf, '*');
4234 if (!*PL_tokenbuf)
a0d0e21e 4235 PREREF('*');
79072805 4236 TERM('*');
a687059c 4237 }
79072805
LW
4238 s++;
4239 if (*s == '*') {
a687059c 4240 s++;
79072805 4241 PWop(OP_POW);
a687059c 4242 }
79072805
LW
4243 Mop(OP_MULTIPLY);
4244
378cc40b 4245 case '%':
3280af22 4246 if (PL_expect == XOPERATOR) {
bbce6d69 4247 ++s;
4248 Mop(OP_MODULO);
a687059c 4249 }
3280af22 4250 PL_tokenbuf[0] = '%';
e8ae98db
RGS
4251 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4252 sizeof PL_tokenbuf - 1, FALSE);
3280af22 4253 if (!PL_tokenbuf[1]) {
bbce6d69 4254 PREREF('%');
a687059c 4255 }
3280af22 4256 PL_pending_ident = '%';
bbce6d69 4257 TERM('%');
a687059c 4258
378cc40b 4259 case '^':
79072805 4260 s++;
a0d0e21e 4261 BOop(OP_BIT_XOR);
79072805 4262 case '[':
3280af22 4263 PL_lex_brackets++;
79072805 4264 /* FALL THROUGH */
378cc40b 4265 case '~':
0d863452 4266 if (s[1] == '~'
3e7dd34d 4267 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR))
0d863452
RH
4268 {
4269 s += 2;
4270 Eop(OP_SMARTMATCH);
4271 }
378cc40b 4272 case ',':
90771dc0
NC
4273 {
4274 const char tmp = *s++;
4275 OPERATOR(tmp);
4276 }
a0d0e21e
LW
4277 case ':':
4278 if (s[1] == ':') {
4279 len = 0;
0bfa2a8a 4280 goto just_a_word_zero_gv;
a0d0e21e
LW
4281 }
4282 s++;
09bef843
SB
4283 switch (PL_expect) {
4284 OP *attrs;
5db06880
NC
4285#ifdef PERL_MAD
4286 I32 stuffstart;
4287#endif
09bef843
SB
4288 case XOPERATOR:
4289 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
4290 break;
4291 PL_bufptr = s; /* update in case we back off */
4292 goto grabattrs;
4293 case XATTRBLOCK:
4294 PL_expect = XBLOCK;
4295 goto grabattrs;
4296 case XATTRTERM:
4297 PL_expect = XTERMBLOCK;
4298 grabattrs:
5db06880
NC
4299#ifdef PERL_MAD
4300 stuffstart = s - SvPVX(PL_linestr) - 1;
4301#endif
29595ff2 4302 s = PEEKSPACE(s);
5f66b61c 4303 attrs = NULL;
7e2040f0 4304 while (isIDFIRST_lazy_if(s,UTF)) {
90771dc0 4305 I32 tmp;
5cc237b8 4306 SV *sv;
09bef843 4307 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5458a98a 4308 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
f9829d6b
GS
4309 if (tmp < 0) tmp = -tmp;
4310 switch (tmp) {
4311 case KEY_or:
4312 case KEY_and:
4313 case KEY_for:
4314 case KEY_unless:
4315 case KEY_if:
4316 case KEY_while:
4317 case KEY_until:
4318 goto got_attrs;
4319 default:
4320 break;
4321 }
4322 }
5cc237b8 4323 sv = newSVpvn(s, len);
09bef843
SB
4324 if (*d == '(') {
4325 d = scan_str(d,TRUE,TRUE);
4326 if (!d) {
09bef843
SB
4327 /* MUST advance bufptr here to avoid bogus
4328 "at end of line" context messages from yyerror().
4329 */
4330 PL_bufptr = s + len;
4331 yyerror("Unterminated attribute parameter in attribute list");
4332 if (attrs)
4333 op_free(attrs);
5cc237b8 4334 sv_free(sv);
bbf60fe6 4335 return REPORT(0); /* EOF indicator */
09bef843
SB
4336 }
4337 }
4338 if (PL_lex_stuff) {
09bef843
SB
4339 sv_catsv(sv, PL_lex_stuff);
4340 attrs = append_elem(OP_LIST, attrs,
4341 newSVOP(OP_CONST, 0, sv));
4342 SvREFCNT_dec(PL_lex_stuff);
a0714e2c 4343 PL_lex_stuff = NULL;
09bef843
SB
4344 }
4345 else {
5cc237b8
BS
4346 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4347 sv_free(sv);
1108974d 4348 if (PL_in_my == KEY_our) {
371fce9b 4349#ifdef USE_ITHREADS
6154021b 4350 GvUNIQUE_on(cGVOPx_gv(pl_yylval.opval));
371fce9b 4351#else
1108974d 4352 /* skip to avoid loading attributes.pm */
371fce9b 4353#endif
df9a6019 4354 deprecate(":unique");
1108974d 4355 }
bfed75c6 4356 else
371fce9b
DM
4357 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4358 }
4359
d3cea301
SB
4360 /* NOTE: any CV attrs applied here need to be part of
4361 the CVf_BUILTIN_ATTRS define in cv.h! */
5cc237b8
BS
4362 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4363 sv_free(sv);
78f9721b 4364 CvLVALUE_on(PL_compcv);
5cc237b8
BS
4365 }
4366 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4367 sv_free(sv);
78f9721b 4368 CvLOCKED_on(PL_compcv);
5cc237b8
BS
4369 }
4370 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4371 sv_free(sv);
78f9721b 4372 CvMETHOD_on(PL_compcv);
5cc237b8 4373 }
78f9721b
SM
4374 /* After we've set the flags, it could be argued that
4375 we don't need to do the attributes.pm-based setting
4376 process, and shouldn't bother appending recognized
d3cea301
SB
4377 flags. To experiment with that, uncomment the
4378 following "else". (Note that's already been
4379 uncommented. That keeps the above-applied built-in
4380 attributes from being intercepted (and possibly
4381 rejected) by a package's attribute routines, but is
4382 justified by the performance win for the common case
4383 of applying only built-in attributes.) */
0256094b 4384 else
78f9721b
SM
4385 attrs = append_elem(OP_LIST, attrs,
4386 newSVOP(OP_CONST, 0,
5cc237b8 4387 sv));
09bef843 4388 }
29595ff2 4389 s = PEEKSPACE(d);
0120eecf 4390 if (*s == ':' && s[1] != ':')
29595ff2 4391 s = PEEKSPACE(s+1);
0120eecf
GS
4392 else if (s == d)
4393 break; /* require real whitespace or :'s */
29595ff2 4394 /* XXX losing whitespace on sequential attributes here */
09bef843 4395 }
90771dc0
NC
4396 {
4397 const char tmp
4398 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4399 if (*s != ';' && *s != '}' && *s != tmp
4400 && (tmp != '=' || *s != ')')) {
4401 const char q = ((*s == '\'') ? '"' : '\'');
4402 /* If here for an expression, and parsed no attrs, back
4403 off. */
4404 if (tmp == '=' && !attrs) {
4405 s = PL_bufptr;
4406 break;
4407 }
4408 /* MUST advance bufptr here to avoid bogus "at end of line"
4409 context messages from yyerror().
4410 */
4411 PL_bufptr = s;
10edeb5d
JH
4412 yyerror( (const char *)
4413 (*s
4414 ? Perl_form(aTHX_ "Invalid separator character "
4415 "%c%c%c in attribute list", q, *s, q)
4416 : "Unterminated attribute list" ) );
90771dc0
NC
4417 if (attrs)
4418 op_free(attrs);
4419 OPERATOR(':');
09bef843 4420 }
09bef843 4421 }
f9829d6b 4422 got_attrs:
09bef843 4423 if (attrs) {
cd81e915 4424 start_force(PL_curforce);
9ded7720 4425 NEXTVAL_NEXTTOKE.opval = attrs;
cd81e915 4426 CURMAD('_', PL_nextwhite);
89122651 4427 force_next(THING);
5db06880
NC
4428 }
4429#ifdef PERL_MAD
4430 if (PL_madskills) {
cd81e915 4431 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
5db06880 4432 (s - SvPVX(PL_linestr)) - stuffstart);
09bef843 4433 }
5db06880 4434#endif
09bef843
SB
4435 TOKEN(COLONATTR);
4436 }
a0d0e21e 4437 OPERATOR(':');
8990e307
LW
4438 case '(':
4439 s++;
3280af22
NIS
4440 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4441 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
a0d0e21e 4442 else
3280af22 4443 PL_expect = XTERM;
29595ff2 4444 s = SKIPSPACE1(s);
a0d0e21e 4445 TOKEN('(');
378cc40b 4446 case ';':
f4dd75d9 4447 CLINE;
90771dc0
NC
4448 {
4449 const char tmp = *s++;
4450 OPERATOR(tmp);
4451 }
378cc40b 4452 case ')':
90771dc0
NC
4453 {
4454 const char tmp = *s++;
29595ff2 4455 s = SKIPSPACE1(s);
90771dc0
NC
4456 if (*s == '{')
4457 PREBLOCK(tmp);
4458 TERM(tmp);
4459 }
79072805
LW
4460 case ']':
4461 s++;
3280af22 4462 if (PL_lex_brackets <= 0)
d98d5fff 4463 yyerror("Unmatched right square bracket");
463ee0b2 4464 else
3280af22
NIS
4465 --PL_lex_brackets;
4466 if (PL_lex_state == LEX_INTERPNORMAL) {
4467 if (PL_lex_brackets == 0) {
02255c60
FC
4468 if (*s == '-' && s[1] == '>')
4469 PL_lex_state = LEX_INTERPENDMAYBE;
4470 else if (*s != '[' && *s != '{')
3280af22 4471 PL_lex_state = LEX_INTERPEND;
79072805
LW
4472 }
4473 }
4633a7c4 4474 TERM(']');
79072805
LW
4475 case '{':
4476 leftbracket:
79072805 4477 s++;
3280af22 4478 if (PL_lex_brackets > 100) {
8edd5f42 4479 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
8990e307 4480 }
3280af22 4481 switch (PL_expect) {
a0d0e21e 4482 case XTERM:
3280af22 4483 if (PL_lex_formbrack) {
a0d0e21e
LW
4484 s--;
4485 PRETERMBLOCK(DO);
4486 }
3280af22
NIS
4487 if (PL_oldoldbufptr == PL_last_lop)
4488 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
a0d0e21e 4489 else
3280af22 4490 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
79072805 4491 OPERATOR(HASHBRACK);
a0d0e21e 4492 case XOPERATOR:
bf4acbe4 4493 while (s < PL_bufend && SPACE_OR_TAB(*s))
748a9306 4494 s++;
44a8e56a 4495 d = s;
3280af22
NIS
4496 PL_tokenbuf[0] = '\0';
4497 if (d < PL_bufend && *d == '-') {
4498 PL_tokenbuf[0] = '-';
44a8e56a 4499 d++;
bf4acbe4 4500 while (d < PL_bufend && SPACE_OR_TAB(*d))
44a8e56a 4501 d++;
4502 }
7e2040f0 4503 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
3280af22 4504 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
8903cb82 4505 FALSE, &len);
bf4acbe4 4506 while (d < PL_bufend && SPACE_OR_TAB(*d))
748a9306
LW
4507 d++;
4508 if (*d == '}') {
f54cb97a 4509 const char minus = (PL_tokenbuf[0] == '-');
44a8e56a 4510 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4511 if (minus)
4512 force_next('-');
748a9306
LW
4513 }
4514 }
4515 /* FALL THROUGH */
09bef843 4516 case XATTRBLOCK:
748a9306 4517 case XBLOCK:
3280af22
NIS
4518 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4519 PL_expect = XSTATE;
a0d0e21e 4520 break;
09bef843 4521 case XATTRTERM:
a0d0e21e 4522 case XTERMBLOCK:
3280af22
NIS
4523 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4524 PL_expect = XSTATE;
a0d0e21e
LW
4525 break;
4526 default: {
f54cb97a 4527 const char *t;
3280af22
NIS
4528 if (PL_oldoldbufptr == PL_last_lop)
4529 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
a0d0e21e 4530 else
3280af22 4531 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
29595ff2 4532 s = SKIPSPACE1(s);
8452ff4b
SB
4533 if (*s == '}') {
4534 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4535 PL_expect = XTERM;
4536 /* This hack is to get the ${} in the message. */
4537 PL_bufptr = s+1;
4538 yyerror("syntax error");
4539 break;
4540 }
a0d0e21e 4541 OPERATOR(HASHBRACK);
8452ff4b 4542 }
b8a4b1be
GS
4543 /* This hack serves to disambiguate a pair of curlies
4544 * as being a block or an anon hash. Normally, expectation
4545 * determines that, but in cases where we're not in a
4546 * position to expect anything in particular (like inside
4547 * eval"") we have to resolve the ambiguity. This code
4548 * covers the case where the first term in the curlies is a
4549 * quoted string. Most other cases need to be explicitly
a0288114 4550 * disambiguated by prepending a "+" before the opening
b8a4b1be
GS
4551 * curly in order to force resolution as an anon hash.
4552 *
4553 * XXX should probably propagate the outer expectation
4554 * into eval"" to rely less on this hack, but that could
4555 * potentially break current behavior of eval"".
4556 * GSAR 97-07-21
4557 */
4558 t = s;
4559 if (*s == '\'' || *s == '"' || *s == '`') {
4560 /* common case: get past first string, handling escapes */
3280af22 4561 for (t++; t < PL_bufend && *t != *s;)
b8a4b1be
GS
4562 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4563 t++;
4564 t++;
a0d0e21e 4565 }
b8a4b1be 4566 else if (*s == 'q') {
3280af22 4567 if (++t < PL_bufend
b8a4b1be 4568 && (!isALNUM(*t)
3280af22 4569 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
0505442f
GS
4570 && !isALNUM(*t))))
4571 {
abc667d1 4572 /* skip q//-like construct */
f54cb97a 4573 const char *tmps;
b8a4b1be
GS
4574 char open, close, term;
4575 I32 brackets = 1;
4576
3280af22 4577 while (t < PL_bufend && isSPACE(*t))
b8a4b1be 4578 t++;
abc667d1
DM
4579 /* check for q => */
4580 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4581 OPERATOR(HASHBRACK);
4582 }
b8a4b1be
GS
4583 term = *t;
4584 open = term;
4585 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4586 term = tmps[5];
4587 close = term;
4588 if (open == close)
3280af22
NIS
4589 for (t++; t < PL_bufend; t++) {
4590 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
b8a4b1be 4591 t++;
6d07e5e9 4592 else if (*t == open)
b8a4b1be
GS
4593 break;
4594 }
abc667d1 4595 else {
3280af22
NIS
4596 for (t++; t < PL_bufend; t++) {
4597 if (*t == '\\' && t+1 < PL_bufend)
b8a4b1be 4598 t++;
6d07e5e9 4599 else if (*t == close && --brackets <= 0)
b8a4b1be
GS
4600 break;
4601 else if (*t == open)
4602 brackets++;
4603 }
abc667d1
DM
4604 }
4605 t++;
b8a4b1be 4606 }
abc667d1
DM
4607 else
4608 /* skip plain q word */
4609 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4610 t += UTF8SKIP(t);
a0d0e21e 4611 }
7e2040f0 4612 else if (isALNUM_lazy_if(t,UTF)) {
0505442f 4613 t += UTF8SKIP(t);
7e2040f0 4614 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
0505442f 4615 t += UTF8SKIP(t);
a0d0e21e 4616 }
3280af22 4617 while (t < PL_bufend && isSPACE(*t))
a0d0e21e 4618 t++;
b8a4b1be
GS
4619 /* if comma follows first term, call it an anon hash */
4620 /* XXX it could be a comma expression with loop modifiers */
3280af22 4621 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
b8a4b1be 4622 || (*t == '=' && t[1] == '>')))
a0d0e21e 4623 OPERATOR(HASHBRACK);
3280af22 4624 if (PL_expect == XREF)
4e4e412b 4625 PL_expect = XTERM;
a0d0e21e 4626 else {
3280af22
NIS
4627 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4628 PL_expect = XSTATE;
a0d0e21e 4629 }
8990e307 4630 }
a0d0e21e 4631 break;
463ee0b2 4632 }
6154021b 4633 pl_yylval.ival = CopLINE(PL_curcop);
79072805 4634 if (isSPACE(*s) || *s == '#')
3280af22 4635 PL_copline = NOLINE; /* invalidate current command line number */
79072805 4636 TOKEN('{');
378cc40b 4637 case '}':
79072805
LW
4638 rightbracket:
4639 s++;
3280af22 4640 if (PL_lex_brackets <= 0)
d98d5fff 4641 yyerror("Unmatched right curly bracket");
463ee0b2 4642 else
3280af22 4643 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
c2e66d9e 4644 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
3280af22
NIS
4645 PL_lex_formbrack = 0;
4646 if (PL_lex_state == LEX_INTERPNORMAL) {
4647 if (PL_lex_brackets == 0) {
9059aa12
LW
4648 if (PL_expect & XFAKEBRACK) {
4649 PL_expect &= XENUMMASK;
3280af22
NIS
4650 PL_lex_state = LEX_INTERPEND;
4651 PL_bufptr = s;
5db06880
NC
4652#if 0
4653 if (PL_madskills) {
cd81e915 4654 if (!PL_thiswhite)
6b29d1f5 4655 PL_thiswhite = newSVpvs("");
76f68e9b 4656 sv_catpvs(PL_thiswhite,"}");
5db06880
NC
4657 }
4658#endif
cea2e8a9 4659 return yylex(); /* ignore fake brackets */
79072805 4660 }
fa83b5b6 4661 if (*s == '-' && s[1] == '>')
3280af22 4662 PL_lex_state = LEX_INTERPENDMAYBE;
fa83b5b6 4663 else if (*s != '[' && *s != '{')
3280af22 4664 PL_lex_state = LEX_INTERPEND;
79072805
LW
4665 }
4666 }
9059aa12
LW
4667 if (PL_expect & XFAKEBRACK) {
4668 PL_expect &= XENUMMASK;
3280af22 4669 PL_bufptr = s;
cea2e8a9 4670 return yylex(); /* ignore fake brackets */
748a9306 4671 }
cd81e915 4672 start_force(PL_curforce);
5db06880
NC
4673 if (PL_madskills) {
4674 curmad('X', newSVpvn(s-1,1));
cd81e915 4675 CURMAD('_', PL_thiswhite);
5db06880 4676 }
79072805 4677 force_next('}');
5db06880 4678#ifdef PERL_MAD
cd81e915 4679 if (!PL_thistoken)
6b29d1f5 4680 PL_thistoken = newSVpvs("");
5db06880 4681#endif
79072805 4682 TOKEN(';');
378cc40b
LW
4683 case '&':
4684 s++;
90771dc0 4685 if (*s++ == '&')
a0d0e21e 4686 AOPERATOR(ANDAND);
378cc40b 4687 s--;
3280af22 4688 if (PL_expect == XOPERATOR) {
041457d9
DM
4689 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4690 && isIDFIRST_lazy_if(s,UTF))
7e2040f0 4691 {
57843af0 4692 CopLINE_dec(PL_curcop);
f1f66076 4693 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
57843af0 4694 CopLINE_inc(PL_curcop);
463ee0b2 4695 }
79072805 4696 BAop(OP_BIT_AND);
463ee0b2 4697 }
79072805 4698
3280af22
NIS
4699 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4700 if (*PL_tokenbuf) {
4701 PL_expect = XOPERATOR;
4702 force_ident(PL_tokenbuf, '&');
463ee0b2 4703 }
79072805
LW
4704 else
4705 PREREF('&');
6154021b 4706 pl_yylval.ival = (OPpENTERSUB_AMPER<<8);
79072805
LW
4707 TERM('&');
4708
378cc40b
LW
4709 case '|':
4710 s++;
90771dc0 4711 if (*s++ == '|')
a0d0e21e 4712 AOPERATOR(OROR);
378cc40b 4713 s--;
79072805 4714 BOop(OP_BIT_OR);
378cc40b
LW
4715 case '=':
4716 s++;
748a9306 4717 {
90771dc0
NC
4718 const char tmp = *s++;
4719 if (tmp == '=')
4720 Eop(OP_EQ);
4721 if (tmp == '>')
4722 OPERATOR(',');
4723 if (tmp == '~')
4724 PMop(OP_MATCH);
4725 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4726 && strchr("+-*/%.^&|<",tmp))
4727 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4728 "Reversed %c= operator",(int)tmp);
4729 s--;
4730 if (PL_expect == XSTATE && isALPHA(tmp) &&
4731 (s == PL_linestart+1 || s[-2] == '\n') )
4732 {
4733 if (PL_in_eval && !PL_rsfp) {
4734 d = PL_bufend;
4735 while (s < d) {
4736 if (*s++ == '\n') {
4737 incline(s);
4738 if (strnEQ(s,"=cut",4)) {
4739 s = strchr(s,'\n');
4740 if (s)
4741 s++;
4742 else
4743 s = d;
4744 incline(s);
4745 goto retry;
4746 }
4747 }
a5f75d66 4748 }
90771dc0 4749 goto retry;
a5f75d66 4750 }
5db06880
NC
4751#ifdef PERL_MAD
4752 if (PL_madskills) {
cd81e915 4753 if (!PL_thiswhite)
6b29d1f5 4754 PL_thiswhite = newSVpvs("");
cd81e915 4755 sv_catpvn(PL_thiswhite, PL_linestart,
5db06880
NC
4756 PL_bufend - PL_linestart);
4757 }
4758#endif
90771dc0
NC
4759 s = PL_bufend;
4760 PL_doextract = TRUE;
4761 goto retry;
a5f75d66 4762 }
a0d0e21e 4763 }
3280af22 4764 if (PL_lex_brackets < PL_lex_formbrack) {
c35e046a 4765 const char *t = s;
51882d45 4766#ifdef PERL_STRICT_CR
c35e046a 4767 while (SPACE_OR_TAB(*t))
51882d45 4768#else
c35e046a 4769 while (SPACE_OR_TAB(*t) || *t == '\r')
51882d45 4770#endif
c35e046a 4771 t++;
a0d0e21e
LW
4772 if (*t == '\n' || *t == '#') {
4773 s--;
3280af22 4774 PL_expect = XBLOCK;
a0d0e21e
LW
4775 goto leftbracket;
4776 }
79072805 4777 }
6154021b 4778 pl_yylval.ival = 0;
a0d0e21e 4779 OPERATOR(ASSIGNOP);
378cc40b 4780 case '!':
be25f609 4781 if (PL_expect == XSTATE && s[1] == '!' && s[2] == '!') {
4782 s += 3;
4783 LOP(OP_DIE,XTERM);
4784 }
378cc40b 4785 s++;
90771dc0
NC
4786 {
4787 const char tmp = *s++;
4788 if (tmp == '=') {
4789 /* was this !=~ where !~ was meant?
4790 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4791
4792 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4793 const char *t = s+1;
4794
4795 while (t < PL_bufend && isSPACE(*t))
4796 ++t;
4797
4798 if (*t == '/' || *t == '?' ||
4799 ((*t == 'm' || *t == 's' || *t == 'y')
4800 && !isALNUM(t[1])) ||
4801 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4802 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4803 "!=~ should be !~");
4804 }
4805 Eop(OP_NE);
4806 }
4807 if (tmp == '~')
4808 PMop(OP_NOT);
4809 }
378cc40b
LW
4810 s--;
4811 OPERATOR('!');
4812 case '<':
3280af22 4813 if (PL_expect != XOPERATOR) {
93a17b20 4814 if (s[1] != '<' && !strchr(s,'>'))
2f3197b3 4815 check_uni();
79072805
LW
4816 if (s[1] == '<')
4817 s = scan_heredoc(s);
4818 else
4819 s = scan_inputsymbol(s);
4820 TERM(sublex_start());
378cc40b
LW
4821 }
4822 s++;
90771dc0
NC
4823 {
4824 char tmp = *s++;
4825 if (tmp == '<')
4826 SHop(OP_LEFT_SHIFT);
4827 if (tmp == '=') {
4828 tmp = *s++;
4829 if (tmp == '>')
4830 Eop(OP_NCMP);
4831 s--;
4832 Rop(OP_LE);
4833 }
395c3793 4834 }
378cc40b 4835 s--;
79072805 4836 Rop(OP_LT);
378cc40b
LW
4837 case '>':
4838 s++;
90771dc0
NC
4839 {
4840 const char tmp = *s++;
4841 if (tmp == '>')
4842 SHop(OP_RIGHT_SHIFT);
d4c19fe8 4843 else if (tmp == '=')
90771dc0
NC
4844 Rop(OP_GE);
4845 }
378cc40b 4846 s--;
79072805 4847 Rop(OP_GT);
378cc40b
LW
4848
4849 case '$':
bbce6d69 4850 CLINE;
4851
3280af22
NIS
4852 if (PL_expect == XOPERATOR) {
4853 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4854 PL_expect = XTERM;
c445ea15 4855 deprecate_old(commaless_variable_list);
bbf60fe6 4856 return REPORT(','); /* grandfather non-comma-format format */
a0d0e21e 4857 }
8990e307 4858 }
a0d0e21e 4859
7e2040f0 4860 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
3280af22 4861 PL_tokenbuf[0] = '@';
376b8730
SM
4862 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4863 sizeof PL_tokenbuf - 1, FALSE);
4864 if (PL_expect == XOPERATOR)
4865 no_op("Array length", s);
3280af22 4866 if (!PL_tokenbuf[1])
a0d0e21e 4867 PREREF(DOLSHARP);
3280af22
NIS
4868 PL_expect = XOPERATOR;
4869 PL_pending_ident = '#';
463ee0b2 4870 TOKEN(DOLSHARP);
79072805 4871 }
bbce6d69 4872
3280af22 4873 PL_tokenbuf[0] = '$';
376b8730
SM
4874 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4875 sizeof PL_tokenbuf - 1, FALSE);
4876 if (PL_expect == XOPERATOR)
4877 no_op("Scalar", s);
3280af22
NIS
4878 if (!PL_tokenbuf[1]) {
4879 if (s == PL_bufend)
bbce6d69 4880 yyerror("Final $ should be \\$ or $name");
4881 PREREF('$');
8990e307 4882 }
a0d0e21e 4883
bbce6d69 4884 /* This kludge not intended to be bulletproof. */
3280af22 4885 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
6154021b 4886 pl_yylval.opval = newSVOP(OP_CONST, 0,
fc15ae8f 4887 newSViv(CopARYBASE_get(&PL_compiling)));
6154021b 4888 pl_yylval.opval->op_private = OPpCONST_ARYBASE;
bbce6d69 4889 TERM(THING);
4890 }
4891
ff68c719 4892 d = s;
90771dc0
NC
4893 {
4894 const char tmp = *s;
4895 if (PL_lex_state == LEX_NORMAL)
29595ff2 4896 s = SKIPSPACE1(s);
ff68c719 4897
90771dc0
NC
4898 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4899 && intuit_more(s)) {
4900 if (*s == '[') {
4901 PL_tokenbuf[0] = '@';
4902 if (ckWARN(WARN_SYNTAX)) {
c35e046a
AL
4903 char *t = s+1;
4904
4905 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4906 t++;
90771dc0 4907 if (*t++ == ',') {
29595ff2 4908 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
90771dc0
NC
4909 while (t < PL_bufend && *t != ']')
4910 t++;
9014280d 4911 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
90771dc0 4912 "Multidimensional syntax %.*s not supported",
36c7798d 4913 (int)((t - PL_bufptr) + 1), PL_bufptr);
90771dc0 4914 }
748a9306 4915 }
93a17b20 4916 }
90771dc0
NC
4917 else if (*s == '{') {
4918 char *t;
4919 PL_tokenbuf[0] = '%';
4920 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4921 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4922 {
4923 char tmpbuf[sizeof PL_tokenbuf];
c35e046a
AL
4924 do {
4925 t++;
4926 } while (isSPACE(*t));
90771dc0 4927 if (isIDFIRST_lazy_if(t,UTF)) {
780a5241 4928 STRLEN len;
90771dc0 4929 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
780a5241 4930 &len);
c35e046a
AL
4931 while (isSPACE(*t))
4932 t++;
780a5241 4933 if (*t == ';' && get_cvn_flags(tmpbuf, len, 0))
90771dc0
NC
4934 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4935 "You need to quote \"%s\"",
4936 tmpbuf);
4937 }
4938 }
4939 }
93a17b20 4940 }
bbce6d69 4941
90771dc0
NC
4942 PL_expect = XOPERATOR;
4943 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4944 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4945 if (!islop || PL_last_lop_op == OP_GREPSTART)
4946 PL_expect = XOPERATOR;
4947 else if (strchr("$@\"'`q", *s))
4948 PL_expect = XTERM; /* e.g. print $fh "foo" */
4949 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4950 PL_expect = XTERM; /* e.g. print $fh &sub */
4951 else if (isIDFIRST_lazy_if(s,UTF)) {
4952 char tmpbuf[sizeof PL_tokenbuf];
4953 int t2;
4954 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5458a98a 4955 if ((t2 = keyword(tmpbuf, len, 0))) {
90771dc0
NC
4956 /* binary operators exclude handle interpretations */
4957 switch (t2) {
4958 case -KEY_x:
4959 case -KEY_eq:
4960 case -KEY_ne:
4961 case -KEY_gt:
4962 case -KEY_lt:
4963 case -KEY_ge:
4964 case -KEY_le:
4965 case -KEY_cmp:
4966 break;
4967 default:
4968 PL_expect = XTERM; /* e.g. print $fh length() */
4969 break;
4970 }
4971 }
4972 else {
4973 PL_expect = XTERM; /* e.g. print $fh subr() */
84902520
TB
4974 }
4975 }
90771dc0
NC
4976 else if (isDIGIT(*s))
4977 PL_expect = XTERM; /* e.g. print $fh 3 */
4978 else if (*s == '.' && isDIGIT(s[1]))
4979 PL_expect = XTERM; /* e.g. print $fh .3 */
4980 else if ((*s == '?' || *s == '-' || *s == '+')
4981 && !isSPACE(s[1]) && s[1] != '=')
4982 PL_expect = XTERM; /* e.g. print $fh -1 */
4983 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4984 && s[1] != '/')
4985 PL_expect = XTERM; /* e.g. print $fh /.../
4986 XXX except DORDOR operator
4987 */
4988 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4989 && s[2] != '=')
4990 PL_expect = XTERM; /* print $fh <<"EOF" */
93a17b20 4991 }
bbce6d69 4992 }
3280af22 4993 PL_pending_ident = '$';
79072805 4994 TOKEN('$');
378cc40b
LW
4995
4996 case '@':
3280af22 4997 if (PL_expect == XOPERATOR)
bbce6d69 4998 no_op("Array", s);
3280af22
NIS
4999 PL_tokenbuf[0] = '@';
5000 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
5001 if (!PL_tokenbuf[1]) {
bbce6d69 5002 PREREF('@');
5003 }
3280af22 5004 if (PL_lex_state == LEX_NORMAL)
29595ff2 5005 s = SKIPSPACE1(s);
3280af22 5006 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
bbce6d69 5007 if (*s == '{')
3280af22 5008 PL_tokenbuf[0] = '%';
a0d0e21e
LW
5009
5010 /* Warn about @ where they meant $. */
041457d9
DM
5011 if (*s == '[' || *s == '{') {
5012 if (ckWARN(WARN_SYNTAX)) {
f54cb97a 5013 const char *t = s + 1;
7e2040f0 5014 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
a0d0e21e
LW
5015 t++;
5016 if (*t == '}' || *t == ']') {
5017 t++;
29595ff2 5018 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
9014280d 5019 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
599cee73 5020 "Scalar value %.*s better written as $%.*s",
36c7798d
DM
5021 (int)(t-PL_bufptr), PL_bufptr,
5022 (int)(t-PL_bufptr-1), PL_bufptr+1);
a0d0e21e 5023 }
93a17b20
LW
5024 }
5025 }
463ee0b2 5026 }
3280af22 5027 PL_pending_ident = '@';
79072805 5028 TERM('@');
378cc40b 5029
c963b151 5030 case '/': /* may be division, defined-or, or pattern */
6f33ba73
RGS
5031 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
5032 s += 2;
5033 AOPERATOR(DORDOR);
5034 }
c963b151 5035 case '?': /* may either be conditional or pattern */
be25f609 5036 if (PL_expect == XSTATE && s[1] == '?' && s[2] == '?') {
5037 s += 3;
5038 LOP(OP_WARN,XTERM);
5039 }
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) {
5116 PL_expect = XTERM;
c445ea15 5117 deprecate_old(commaless_variable_list);
bbf60fe6 5118 return REPORT(','); /* grandfather non-comma-format format */
a0d0e21e 5119 }
463ee0b2 5120 else
8990e307 5121 no_op("String",s);
463ee0b2 5122 }
79072805 5123 if (!s)
d4c19fe8 5124 missingterm(NULL);
6154021b 5125 pl_yylval.ival = OP_CONST;
79072805
LW
5126 TERM(sublex_start());
5127
5128 case '"':
5db06880 5129 s = scan_str(s,!!PL_madskills,FALSE);
931e0695 5130 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
3280af22
NIS
5131 if (PL_expect == XOPERATOR) {
5132 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5133 PL_expect = XTERM;
c445ea15 5134 deprecate_old(commaless_variable_list);
bbf60fe6 5135 return REPORT(','); /* grandfather non-comma-format format */
a0d0e21e 5136 }
463ee0b2 5137 else
8990e307 5138 no_op("String",s);
463ee0b2 5139 }
79072805 5140 if (!s)
d4c19fe8 5141 missingterm(NULL);
6154021b 5142 pl_yylval.ival = OP_CONST;
cfd0369c
NC
5143 /* FIXME. I think that this can be const if char *d is replaced by
5144 more localised variables. */
3280af22 5145 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
63cd0674 5146 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
6154021b 5147 pl_yylval.ival = OP_STRINGIFY;
4633a7c4
LW
5148 break;
5149 }
5150 }
79072805
LW
5151 TERM(sublex_start());
5152
5153 case '`':
5db06880 5154 s = scan_str(s,!!PL_madskills,FALSE);
931e0695 5155 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
3280af22 5156 if (PL_expect == XOPERATOR)
8990e307 5157 no_op("Backticks",s);
79072805 5158 if (!s)
d4c19fe8 5159 missingterm(NULL);
9b201d7d 5160 readpipe_override();
79072805
LW
5161 TERM(sublex_start());
5162
5163 case '\\':
5164 s++;
041457d9 5165 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
9014280d 5166 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
599cee73 5167 *s, *s);
3280af22 5168 if (PL_expect == XOPERATOR)
8990e307 5169 no_op("Backslash",s);
79072805
LW
5170 OPERATOR(REFGEN);
5171
a7cb1f99 5172 case 'v':
e526c9e6 5173 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
f54cb97a 5174 char *start = s + 2;
dd629d5b 5175 while (isDIGIT(*start) || *start == '_')
a7cb1f99
GS
5176 start++;
5177 if (*start == '.' && isDIGIT(start[1])) {
6154021b 5178 s = scan_num(s, &pl_yylval);
a7cb1f99
GS
5179 TERM(THING);
5180 }
e526c9e6 5181 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
6f33ba73
RGS
5182 else if (!isALPHA(*start) && (PL_expect == XTERM
5183 || PL_expect == XREF || PL_expect == XSTATE
5184 || PL_expect == XTERMORDORDOR)) {
9bde8eb0 5185 GV *const gv = gv_fetchpvn_flags(s, start - s, 0, SVt_PVCV);
e526c9e6 5186 if (!gv) {
6154021b 5187 s = scan_num(s, &pl_yylval);
e526c9e6
GS
5188 TERM(THING);
5189 }
5190 }
a7cb1f99
GS
5191 }
5192 goto keylookup;
79072805 5193 case 'x':
3280af22 5194 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
79072805
LW
5195 s++;
5196 Mop(OP_REPEAT);
2f3197b3 5197 }
79072805
LW
5198 goto keylookup;
5199
378cc40b 5200 case '_':
79072805
LW
5201 case 'a': case 'A':
5202 case 'b': case 'B':
5203 case 'c': case 'C':
5204 case 'd': case 'D':
5205 case 'e': case 'E':
5206 case 'f': case 'F':
5207 case 'g': case 'G':
5208 case 'h': case 'H':
5209 case 'i': case 'I':
5210 case 'j': case 'J':
5211 case 'k': case 'K':
5212 case 'l': case 'L':
5213 case 'm': case 'M':
5214 case 'n': case 'N':
5215 case 'o': case 'O':
5216 case 'p': case 'P':
5217 case 'q': case 'Q':
5218 case 'r': case 'R':
5219 case 's': case 'S':
5220 case 't': case 'T':
5221 case 'u': case 'U':
a7cb1f99 5222 case 'V':
79072805
LW
5223 case 'w': case 'W':
5224 case 'X':
5225 case 'y': case 'Y':
5226 case 'z': case 'Z':
5227
49dc05e3 5228 keylookup: {
90771dc0 5229 I32 tmp;
10edeb5d
JH
5230
5231 orig_keyword = 0;
5232 gv = NULL;
5233 gvp = NULL;
49dc05e3 5234
3280af22
NIS
5235 PL_bufptr = s;
5236 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
8ebc5c01 5237
5238 /* Some keywords can be followed by any delimiter, including ':' */
155aba94
GS
5239 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
5240 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
5241 (PL_tokenbuf[0] == 'q' &&
5242 strchr("qwxr", PL_tokenbuf[1])))));
8ebc5c01 5243
5244 /* x::* is just a word, unless x is "CORE" */
3280af22 5245 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
4633a7c4
LW
5246 goto just_a_word;
5247
3643fb5f 5248 d = s;
3280af22 5249 while (d < PL_bufend && isSPACE(*d))
3643fb5f
CS
5250 d++; /* no comments skipped here, or s### is misparsed */
5251
5252 /* Is this a label? */
3280af22
NIS
5253 if (!tmp && PL_expect == XSTATE
5254 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
8ebc5c01 5255 s = d + 1;
6154021b 5256 pl_yylval.pval = CopLABEL_alloc(PL_tokenbuf);
8ebc5c01 5257 CLINE;
5258 TOKEN(LABEL);
3643fb5f
CS
5259 }
5260
5261 /* Check for keywords */
5458a98a 5262 tmp = keyword(PL_tokenbuf, len, 0);
748a9306
LW
5263
5264 /* Is this a word before a => operator? */
1c3923b3 5265 if (*d == '=' && d[1] == '>') {
748a9306 5266 CLINE;
6154021b 5267 pl_yylval.opval
d0a148a6
NC
5268 = (OP*)newSVOP(OP_CONST, 0,
5269 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
6154021b 5270 pl_yylval.opval->op_private = OPpCONST_BARE;
748a9306
LW
5271 TERM(WORD);
5272 }
5273
a0d0e21e 5274 if (tmp < 0) { /* second-class keyword? */
cbbf8932
AL
5275 GV *ogv = NULL; /* override (winner) */
5276 GV *hgv = NULL; /* hidden (loser) */
3280af22 5277 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
56f7f34b 5278 CV *cv;
90e5519e 5279 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
56f7f34b
CS
5280 (cv = GvCVu(gv)))
5281 {
5282 if (GvIMPORTED_CV(gv))
5283 ogv = gv;
5284 else if (! CvMETHOD(cv))
5285 hgv = gv;
5286 }
5287 if (!ogv &&
3280af22 5288 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
9e0d86f8 5289 (gv = *gvp) && isGV_with_GP(gv) &&
56f7f34b
CS
5290 GvCVu(gv) && GvIMPORTED_CV(gv))
5291 {
5292 ogv = gv;
5293 }
5294 }
5295 if (ogv) {
30fe34ed 5296 orig_keyword = tmp;
56f7f34b 5297 tmp = 0; /* overridden by import or by GLOBAL */
6e7b2336
GS
5298 }
5299 else if (gv && !gvp
5300 && -tmp==KEY_lock /* XXX generalizable kludge */
47f9f84c 5301 && GvCVu(gv))
6e7b2336
GS
5302 {
5303 tmp = 0; /* any sub overrides "weak" keyword */
a0d0e21e 5304 }
56f7f34b
CS
5305 else { /* no override */
5306 tmp = -tmp;
ac206dc8 5307 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
9014280d 5308 Perl_warner(aTHX_ packWARN(WARN_MISC),
ac206dc8
RGS
5309 "dump() better written as CORE::dump()");
5310 }
a0714e2c 5311 gv = NULL;
56f7f34b 5312 gvp = 0;
041457d9
DM
5313 if (hgv && tmp != KEY_x && tmp != KEY_CORE
5314 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
9014280d 5315 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
599cee73 5316 "Ambiguous call resolved as CORE::%s(), %s",
2f3ca594 5317 GvENAME(hgv), "qualify as such or use &");
49dc05e3 5318 }
a0d0e21e
LW
5319 }
5320
5321 reserved_word:
5322 switch (tmp) {
79072805
LW
5323
5324 default: /* not a keyword */
0bfa2a8a
NC
5325 /* Trade off - by using this evil construction we can pull the
5326 variable gv into the block labelled keylookup. If not, then
5327 we have to give it function scope so that the goto from the
5328 earlier ':' case doesn't bypass the initialisation. */
5329 if (0) {
5330 just_a_word_zero_gv:
5331 gv = NULL;
5332 gvp = NULL;
8bee0991 5333 orig_keyword = 0;
0bfa2a8a 5334 }
93a17b20 5335 just_a_word: {
96e4d5b1 5336 SV *sv;
ce29ac45 5337 int pkgname = 0;
f54cb97a 5338 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5069cc75 5339 CV *cv;
5db06880 5340#ifdef PERL_MAD
cd81e915 5341 SV *nextPL_nextwhite = 0;
5db06880
NC
5342#endif
5343
8990e307
LW
5344
5345 /* Get the rest if it looks like a package qualifier */
5346
155aba94 5347 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
c3e0f903 5348 STRLEN morelen;
3280af22 5349 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
c3e0f903
GS
5350 TRUE, &morelen);
5351 if (!morelen)
cea2e8a9 5352 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
ec2ab091 5353 *s == '\'' ? "'" : "::");
c3e0f903 5354 len += morelen;
ce29ac45 5355 pkgname = 1;
a0d0e21e 5356 }
8990e307 5357
3280af22
NIS
5358 if (PL_expect == XOPERATOR) {
5359 if (PL_bufptr == PL_linestart) {
57843af0 5360 CopLINE_dec(PL_curcop);
f1f66076 5361 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
57843af0 5362 CopLINE_inc(PL_curcop);
463ee0b2
LW
5363 }
5364 else
54310121 5365 no_op("Bareword",s);
463ee0b2 5366 }
8990e307 5367
c3e0f903
GS
5368 /* Look for a subroutine with this name in current package,
5369 unless name is "Foo::", in which case Foo is a bearword
5370 (and a package name). */
5371
5db06880 5372 if (len > 2 && !PL_madskills &&
3280af22 5373 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
c3e0f903 5374 {
f776e3cd 5375 if (ckWARN(WARN_BAREWORD)
90e5519e 5376 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
9014280d 5377 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
599cee73 5378 "Bareword \"%s\" refers to nonexistent package",
3280af22 5379 PL_tokenbuf);
c3e0f903 5380 len -= 2;
3280af22 5381 PL_tokenbuf[len] = '\0';
a0714e2c 5382 gv = NULL;
c3e0f903
GS
5383 gvp = 0;
5384 }
5385 else {
62d55b22
NC
5386 if (!gv) {
5387 /* Mustn't actually add anything to a symbol table.
5388 But also don't want to "initialise" any placeholder
5389 constants that might already be there into full
5390 blown PVGVs with attached PVCV. */
90e5519e
NC
5391 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5392 GV_NOADD_NOINIT, SVt_PVCV);
62d55b22 5393 }
b3d904f3 5394 len = 0;
c3e0f903
GS
5395 }
5396
5397 /* if we saw a global override before, get the right name */
8990e307 5398
49dc05e3 5399 if (gvp) {
396482e1 5400 sv = newSVpvs("CORE::GLOBAL::");
3280af22 5401 sv_catpv(sv,PL_tokenbuf);
49dc05e3 5402 }
8a7a129d
NC
5403 else {
5404 /* If len is 0, newSVpv does strlen(), which is correct.
5405 If len is non-zero, then it will be the true length,
5406 and so the scalar will be created correctly. */
5407 sv = newSVpv(PL_tokenbuf,len);
5408 }
5db06880 5409#ifdef PERL_MAD
cd81e915
NC
5410 if (PL_madskills && !PL_thistoken) {
5411 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
9ff8e806 5412 PL_thistoken = newSVpvn(start,s - start);
cd81e915 5413 PL_realtokenstart = s - SvPVX(PL_linestr);
5db06880
NC
5414 }
5415#endif
8990e307 5416
a0d0e21e
LW
5417 /* Presume this is going to be a bareword of some sort. */
5418
5419 CLINE;
6154021b
RGS
5420 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5421 pl_yylval.opval->op_private = OPpCONST_BARE;
8f8cf39c
JH
5422 /* UTF-8 package name? */
5423 if (UTF && !IN_BYTES &&
95a20fc0 5424 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
8f8cf39c 5425 SvUTF8_on(sv);
a0d0e21e 5426
c3e0f903
GS
5427 /* And if "Foo::", then that's what it certainly is. */
5428
5429 if (len)
5430 goto safe_bareword;
5431
5069cc75
NC
5432 /* Do the explicit type check so that we don't need to force
5433 the initialisation of the symbol table to have a real GV.
5434 Beware - gv may not really be a PVGV, cv may not really be
5435 a PVCV, (because of the space optimisations that gv_init
5436 understands) But they're true if for this symbol there is
5437 respectively a typeglob and a subroutine.
5438 */
5439 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5440 /* Real typeglob, so get the real subroutine: */
5441 ? GvCVu(gv)
5442 /* A proxy for a subroutine in this package? */
ea726b52 5443 : SvOK(gv) ? MUTABLE_CV(gv) : NULL)
5069cc75
NC
5444 : NULL;
5445
8990e307
LW
5446 /* See if it's the indirect object for a list operator. */
5447
3280af22
NIS
5448 if (PL_oldoldbufptr &&
5449 PL_oldoldbufptr < PL_bufptr &&
65cec589
GS
5450 (PL_oldoldbufptr == PL_last_lop
5451 || PL_oldoldbufptr == PL_last_uni) &&
a0d0e21e 5452 /* NO SKIPSPACE BEFORE HERE! */
a9ef352a
GS
5453 (PL_expect == XREF ||
5454 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
a0d0e21e 5455 {
748a9306
LW
5456 bool immediate_paren = *s == '(';
5457
a0d0e21e 5458 /* (Now we can afford to cross potential line boundary.) */
cd81e915 5459 s = SKIPSPACE2(s,nextPL_nextwhite);
5db06880 5460#ifdef PERL_MAD
cd81e915 5461 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5db06880 5462#endif
a0d0e21e
LW
5463
5464 /* Two barewords in a row may indicate method call. */
5465
62d55b22
NC
5466 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5467 (tmp = intuit_method(s, gv, cv)))
bbf60fe6 5468 return REPORT(tmp);
a0d0e21e
LW
5469
5470 /* If not a declared subroutine, it's an indirect object. */
5471 /* (But it's an indir obj regardless for sort.) */
7294df96 5472 /* Also, if "_" follows a filetest operator, it's a bareword */
a0d0e21e 5473
7294df96
RGS
5474 if (
5475 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5069cc75 5476 ((!gv || !cv) &&
a9ef352a 5477 (PL_last_lop_op != OP_MAPSTART &&
f0670693 5478 PL_last_lop_op != OP_GREPSTART))))
7294df96
RGS
5479 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5480 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5481 )
a9ef352a 5482 {
3280af22 5483 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
748a9306 5484 goto bareword;
93a17b20
LW
5485 }
5486 }
8990e307 5487
3280af22 5488 PL_expect = XOPERATOR;
5db06880
NC
5489#ifdef PERL_MAD
5490 if (isSPACE(*s))
cd81e915
NC
5491 s = SKIPSPACE2(s,nextPL_nextwhite);
5492 PL_nextwhite = nextPL_nextwhite;
5db06880 5493#else
8990e307 5494 s = skipspace(s);
5db06880 5495#endif
1c3923b3
GS
5496
5497 /* Is this a word before a => operator? */
ce29ac45 5498 if (*s == '=' && s[1] == '>' && !pkgname) {
1c3923b3 5499 CLINE;
6154021b 5500 sv_setpv(((SVOP*)pl_yylval.opval)->op_sv, PL_tokenbuf);
0064a8a9 5501 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
6154021b 5502 SvUTF8_on(((SVOP*)pl_yylval.opval)->op_sv);
1c3923b3
GS
5503 TERM(WORD);
5504 }
5505
5506 /* If followed by a paren, it's certainly a subroutine. */
93a17b20 5507 if (*s == '(') {
79072805 5508 CLINE;
5069cc75 5509 if (cv) {
c35e046a
AL
5510 d = s + 1;
5511 while (SPACE_OR_TAB(*d))
5512 d++;
62d55b22 5513 if (*d == ')' && (sv = gv_const_sv(gv))) {
96e4d5b1 5514 s = d + 1;
c631f32b 5515 goto its_constant;
96e4d5b1 5516 }
5517 }
5db06880
NC
5518#ifdef PERL_MAD
5519 if (PL_madskills) {
cd81e915
NC
5520 PL_nextwhite = PL_thiswhite;
5521 PL_thiswhite = 0;
5db06880 5522 }
cd81e915 5523 start_force(PL_curforce);
5db06880 5524#endif
6154021b 5525 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
3280af22 5526 PL_expect = XOPERATOR;
5db06880
NC
5527#ifdef PERL_MAD
5528 if (PL_madskills) {
cd81e915
NC
5529 PL_nextwhite = nextPL_nextwhite;
5530 curmad('X', PL_thistoken);
6b29d1f5 5531 PL_thistoken = newSVpvs("");
5db06880
NC
5532 }
5533#endif
93a17b20 5534 force_next(WORD);
6154021b 5535 pl_yylval.ival = 0;
463ee0b2 5536 TOKEN('&');
79072805 5537 }
93a17b20 5538
a0d0e21e 5539 /* If followed by var or block, call it a method (unless sub) */
8990e307 5540
62d55b22 5541 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
3280af22
NIS
5542 PL_last_lop = PL_oldbufptr;
5543 PL_last_lop_op = OP_METHOD;
93a17b20 5544 PREBLOCK(METHOD);
463ee0b2
LW
5545 }
5546
8990e307
LW
5547 /* If followed by a bareword, see if it looks like indir obj. */
5548
30fe34ed
RGS
5549 if (!orig_keyword
5550 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
62d55b22 5551 && (tmp = intuit_method(s, gv, cv)))
bbf60fe6 5552 return REPORT(tmp);
93a17b20 5553
8990e307
LW
5554 /* Not a method, so call it a subroutine (if defined) */
5555
5069cc75 5556 if (cv) {
0453d815 5557 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
9014280d 5558 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
0453d815 5559 "Ambiguous use of -%s resolved as -&%s()",
3280af22 5560 PL_tokenbuf, PL_tokenbuf);
89bfa8cd 5561 /* Check for a constant sub */
c631f32b 5562 if ((sv = gv_const_sv(gv))) {
96e4d5b1 5563 its_constant:
6154021b
RGS
5564 SvREFCNT_dec(((SVOP*)pl_yylval.opval)->op_sv);
5565 ((SVOP*)pl_yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5566 pl_yylval.opval->op_private = 0;
96e4d5b1 5567 TOKEN(WORD);
89bfa8cd 5568 }
5569
a5f75d66 5570 /* Resolve to GV now. */
62d55b22 5571 if (SvTYPE(gv) != SVt_PVGV) {
b3d904f3 5572 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
62d55b22
NC
5573 assert (SvTYPE(gv) == SVt_PVGV);
5574 /* cv must have been some sort of placeholder, so
5575 now needs replacing with a real code reference. */
5576 cv = GvCV(gv);
5577 }
5578
6154021b
RGS
5579 op_free(pl_yylval.opval);
5580 pl_yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5581 pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
7a52d87a 5582 PL_last_lop = PL_oldbufptr;
bf848113 5583 PL_last_lop_op = OP_ENTERSUB;
4633a7c4 5584 /* Is there a prototype? */
5db06880
NC
5585 if (
5586#ifdef PERL_MAD
5587 cv &&
5588#endif
d9f2850e
RGS
5589 SvPOK(cv))
5590 {
5f66b61c 5591 STRLEN protolen;
daba3364 5592 const char *proto = SvPV_const(MUTABLE_SV(cv), protolen);
5f66b61c 5593 if (!protolen)
4633a7c4 5594 TERM(FUNC0SUB);
8c28b960 5595 if ((*proto == '$' || *proto == '_') && proto[1] == '\0')
4633a7c4 5596 OPERATOR(UNIOPSUB);
0f5d0394
AE
5597 while (*proto == ';')
5598 proto++;
7a52d87a 5599 if (*proto == '&' && *s == '{') {
49a54bbe
NC
5600 if (PL_curstash)
5601 sv_setpvs(PL_subname, "__ANON__");
5602 else
5603 sv_setpvs(PL_subname, "__ANON__::__ANON__");
4633a7c4
LW
5604 PREBLOCK(LSTOPSUB);
5605 }
a9ef352a 5606 }
5db06880
NC
5607#ifdef PERL_MAD
5608 {
5609 if (PL_madskills) {
cd81e915
NC
5610 PL_nextwhite = PL_thiswhite;
5611 PL_thiswhite = 0;
5db06880 5612 }
cd81e915 5613 start_force(PL_curforce);
6154021b 5614 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
5db06880
NC
5615 PL_expect = XTERM;
5616 if (PL_madskills) {
cd81e915
NC
5617 PL_nextwhite = nextPL_nextwhite;
5618 curmad('X', PL_thistoken);
6b29d1f5 5619 PL_thistoken = newSVpvs("");
5db06880
NC
5620 }
5621 force_next(WORD);
5622 TOKEN(NOAMP);
5623 }
5624 }
5625
5626 /* Guess harder when madskills require "best effort". */
5627 if (PL_madskills && (!gv || !GvCVu(gv))) {
5628 int probable_sub = 0;
5629 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5630 probable_sub = 1;
5631 else if (isALPHA(*s)) {
5632 char tmpbuf[1024];
5633 STRLEN tmplen;
5634 d = s;
5635 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5458a98a 5636 if (!keyword(tmpbuf, tmplen, 0))
5db06880
NC
5637 probable_sub = 1;
5638 else {
5639 while (d < PL_bufend && isSPACE(*d))
5640 d++;
5641 if (*d == '=' && d[1] == '>')
5642 probable_sub = 1;
5643 }
5644 }
5645 if (probable_sub) {
7a6d04f4 5646 gv = gv_fetchpv(PL_tokenbuf, GV_ADD, SVt_PVCV);
6154021b
RGS
5647 op_free(pl_yylval.opval);
5648 pl_yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5649 pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5db06880
NC
5650 PL_last_lop = PL_oldbufptr;
5651 PL_last_lop_op = OP_ENTERSUB;
cd81e915
NC
5652 PL_nextwhite = PL_thiswhite;
5653 PL_thiswhite = 0;
5654 start_force(PL_curforce);
6154021b 5655 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
5db06880 5656 PL_expect = XTERM;
cd81e915
NC
5657 PL_nextwhite = nextPL_nextwhite;
5658 curmad('X', PL_thistoken);
6b29d1f5 5659 PL_thistoken = newSVpvs("");
5db06880
NC
5660 force_next(WORD);
5661 TOKEN(NOAMP);
5662 }
5663#else
6154021b 5664 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
3280af22 5665 PL_expect = XTERM;
8990e307
LW
5666 force_next(WORD);
5667 TOKEN(NOAMP);
5db06880 5668#endif
8990e307 5669 }
748a9306 5670
8990e307
LW
5671 /* Call it a bare word */
5672
984f9f66 5673 bareword:
5603f27d 5674 if (PL_hints & HINT_STRICT_SUBS)
6154021b 5675 pl_yylval.opval->op_private |= OPpCONST_STRICT;
5603f27d 5676 else {
041457d9
DM
5677 if (lastchar != '-') {
5678 if (ckWARN(WARN_RESERVED)) {
c35e046a
AL
5679 d = PL_tokenbuf;
5680 while (isLOWER(*d))
5681 d++;
da51bb9b 5682 if (!*d && !gv_stashpv(PL_tokenbuf, 0))
9014280d 5683 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5603f27d
GS
5684 PL_tokenbuf);
5685 }
748a9306
LW
5686 }
5687 }
c3e0f903
GS
5688
5689 safe_bareword:
3792a11b
NC
5690 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5691 && ckWARN_d(WARN_AMBIGUOUS)) {
9014280d 5692 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
0453d815 5693 "Operator or semicolon missing before %c%s",
3280af22 5694 lastchar, PL_tokenbuf);
9014280d 5695 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
0453d815 5696 "Ambiguous use of %c resolved as operator %c",
748a9306
LW
5697 lastchar, lastchar);
5698 }
93a17b20 5699 TOKEN(WORD);
79072805 5700 }
79072805 5701
68dc0745 5702 case KEY___FILE__:
6154021b 5703 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
ed094faf 5704 newSVpv(CopFILE(PL_curcop),0));
46fc3d4c 5705 TERM(THING);
5706
79072805 5707 case KEY___LINE__:
6154021b 5708 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
57843af0 5709 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
79072805 5710 TERM(THING);
68dc0745 5711
5712 case KEY___PACKAGE__:
6154021b 5713 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
3280af22 5714 (PL_curstash
5aaec2b4 5715 ? newSVhek(HvNAME_HEK(PL_curstash))
3280af22 5716 : &PL_sv_undef));
79072805 5717 TERM(THING);
79072805 5718
e50aee73 5719 case KEY___DATA__:
79072805
LW
5720 case KEY___END__: {
5721 GV *gv;
3280af22 5722 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
bfed75c6 5723 const char *pname = "main";
3280af22 5724 if (PL_tokenbuf[2] == 'D')
bfcb3514 5725 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
f776e3cd
NC
5726 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5727 SVt_PVIO);
a5f75d66 5728 GvMULTI_on(gv);
79072805 5729 if (!GvIO(gv))
a0d0e21e 5730 GvIOp(gv) = newIO();
3280af22 5731 IoIFP(GvIOp(gv)) = PL_rsfp;
a0d0e21e
LW
5732#if defined(HAS_FCNTL) && defined(F_SETFD)
5733 {
f54cb97a 5734 const int fd = PerlIO_fileno(PL_rsfp);
a0d0e21e
LW
5735 fcntl(fd,F_SETFD,fd >= 3);
5736 }
79072805 5737#endif
fd049845 5738 /* Mark this internal pseudo-handle as clean */
5739 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
4c84d7f2 5740 if ((PerlIO*)PL_rsfp == PerlIO_stdin())
50952442 5741 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
79072805 5742 else
50952442 5743 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
c39cd008
GS
5744#if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5745 /* if the script was opened in binmode, we need to revert
53129d29 5746 * it to text mode for compatibility; but only iff it has CRs
c39cd008 5747 * XXX this is a questionable hack at best. */
53129d29
GS
5748 if (PL_bufend-PL_bufptr > 2
5749 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
c39cd008
GS
5750 {
5751 Off_t loc = 0;
50952442 5752 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
c39cd008
GS
5753 loc = PerlIO_tell(PL_rsfp);
5754 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5755 }
2986a63f
JH
5756#ifdef NETWARE
5757 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5758#else
c39cd008 5759 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
2986a63f 5760#endif /* NETWARE */
1143fce0
JH
5761#ifdef PERLIO_IS_STDIO /* really? */
5762# if defined(__BORLANDC__)
cb359b41
JH
5763 /* XXX see note in do_binmode() */
5764 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
1143fce0
JH
5765# endif
5766#endif
c39cd008
GS
5767 if (loc > 0)
5768 PerlIO_seek(PL_rsfp, loc, 0);
5769 }
5770 }
5771#endif
7948272d 5772#ifdef PERLIO_LAYERS
52d2e0f4
JH
5773 if (!IN_BYTES) {
5774 if (UTF)
5775 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5776 else if (PL_encoding) {
5777 SV *name;
5778 dSP;
5779 ENTER;
5780 SAVETMPS;
5781 PUSHMARK(sp);
5782 EXTEND(SP, 1);
5783 XPUSHs(PL_encoding);
5784 PUTBACK;
5785 call_method("name", G_SCALAR);
5786 SPAGAIN;
5787 name = POPs;
5788 PUTBACK;
bfed75c6 5789 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
52d2e0f4 5790 Perl_form(aTHX_ ":encoding(%"SVf")",
be2597df 5791 SVfARG(name)));
52d2e0f4
JH
5792 FREETMPS;
5793 LEAVE;
5794 }
5795 }
7948272d 5796#endif
5db06880
NC
5797#ifdef PERL_MAD
5798 if (PL_madskills) {
cd81e915
NC
5799 if (PL_realtokenstart >= 0) {
5800 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5801 if (!PL_endwhite)
6b29d1f5 5802 PL_endwhite = newSVpvs("");
cd81e915
NC
5803 sv_catsv(PL_endwhite, PL_thiswhite);
5804 PL_thiswhite = 0;
5805 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5806 PL_realtokenstart = -1;
5db06880 5807 }
cd81e915 5808 while ((s = filter_gets(PL_endwhite, PL_rsfp,
1a9a51d4 5809 SvCUR(PL_endwhite))) != NULL) ;
5db06880
NC
5810 }
5811#endif
4608196e 5812 PL_rsfp = NULL;
79072805
LW
5813 }
5814 goto fake_eof;
e929a76b 5815 }
de3bb511 5816
8990e307 5817 case KEY_AUTOLOAD:
ed6116ce 5818 case KEY_DESTROY:
79072805 5819 case KEY_BEGIN:
3c10abe3 5820 case KEY_UNITCHECK:
7d30b5c4 5821 case KEY_CHECK:
7d07dbc2 5822 case KEY_INIT:
7d30b5c4 5823 case KEY_END:
3280af22
NIS
5824 if (PL_expect == XSTATE) {
5825 s = PL_bufptr;
93a17b20 5826 goto really_sub;
79072805
LW
5827 }
5828 goto just_a_word;
5829
a0d0e21e
LW
5830 case KEY_CORE:
5831 if (*s == ':' && s[1] == ':') {
5832 s += 2;
748a9306 5833 d = s;
3280af22 5834 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5458a98a 5835 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
6798c92b 5836 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
a0d0e21e
LW
5837 if (tmp < 0)
5838 tmp = -tmp;
850e8516 5839 else if (tmp == KEY_require || tmp == KEY_do)
a72a1c8b 5840 /* that's a way to remember we saw "CORE::" */
850e8516 5841 orig_keyword = tmp;
a0d0e21e
LW
5842 goto reserved_word;
5843 }
5844 goto just_a_word;
5845
463ee0b2
LW
5846 case KEY_abs:
5847 UNI(OP_ABS);
5848
79072805
LW
5849 case KEY_alarm:
5850 UNI(OP_ALARM);
5851
5852 case KEY_accept:
a0d0e21e 5853 LOP(OP_ACCEPT,XTERM);
79072805 5854
463ee0b2
LW
5855 case KEY_and:
5856 OPERATOR(ANDOP);
5857
79072805 5858 case KEY_atan2:
a0d0e21e 5859 LOP(OP_ATAN2,XTERM);
85e6fe83 5860
79072805 5861 case KEY_bind:
a0d0e21e 5862 LOP(OP_BIND,XTERM);
79072805
LW
5863
5864 case KEY_binmode:
1c1fc3ea 5865 LOP(OP_BINMODE,XTERM);
79072805
LW
5866
5867 case KEY_bless:
a0d0e21e 5868 LOP(OP_BLESS,XTERM);
79072805 5869
0d863452
RH
5870 case KEY_break:
5871 FUN0(OP_BREAK);
5872
79072805
LW
5873 case KEY_chop:
5874 UNI(OP_CHOP);
5875
5876 case KEY_continue:
0d863452
RH
5877 /* When 'use switch' is in effect, continue has a dual
5878 life as a control operator. */
5879 {
ef89dcc3 5880 if (!FEATURE_IS_ENABLED("switch"))
0d863452
RH
5881 PREBLOCK(CONTINUE);
5882 else {
5883 /* We have to disambiguate the two senses of
5884 "continue". If the next token is a '{' then
5885 treat it as the start of a continue block;
5886 otherwise treat it as a control operator.
5887 */
5888 s = skipspace(s);
5889 if (*s == '{')
79072805 5890 PREBLOCK(CONTINUE);
0d863452
RH
5891 else
5892 FUN0(OP_CONTINUE);
5893 }
5894 }
79072805
LW
5895
5896 case KEY_chdir:
fafc274c
NC
5897 /* may use HOME */
5898 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
79072805
LW
5899 UNI(OP_CHDIR);
5900
5901 case KEY_close:
5902 UNI(OP_CLOSE);
5903
5904 case KEY_closedir:
5905 UNI(OP_CLOSEDIR);
5906
5907 case KEY_cmp:
5908 Eop(OP_SCMP);
5909
5910 case KEY_caller:
5911 UNI(OP_CALLER);
5912
5913 case KEY_crypt:
5914#ifdef FCRYPT
f4c556ac
GS
5915 if (!PL_cryptseen) {
5916 PL_cryptseen = TRUE;
de3bb511 5917 init_des();
f4c556ac 5918 }
a687059c 5919#endif
a0d0e21e 5920 LOP(OP_CRYPT,XTERM);
79072805
LW
5921
5922 case KEY_chmod:
a0d0e21e 5923 LOP(OP_CHMOD,XTERM);
79072805
LW
5924
5925 case KEY_chown:
a0d0e21e 5926 LOP(OP_CHOWN,XTERM);
79072805
LW
5927
5928 case KEY_connect:
a0d0e21e 5929 LOP(OP_CONNECT,XTERM);
79072805 5930
463ee0b2
LW
5931 case KEY_chr:
5932 UNI(OP_CHR);
5933
79072805
LW
5934 case KEY_cos:
5935 UNI(OP_COS);
5936
5937 case KEY_chroot:
5938 UNI(OP_CHROOT);
5939
0d863452
RH
5940 case KEY_default:
5941 PREBLOCK(DEFAULT);
5942
79072805 5943 case KEY_do:
29595ff2 5944 s = SKIPSPACE1(s);
79072805 5945 if (*s == '{')
a0d0e21e 5946 PRETERMBLOCK(DO);
79072805 5947 if (*s != '\'')
89c5585f 5948 s = force_word(s,WORD,TRUE,TRUE,FALSE);
850e8516
RGS
5949 if (orig_keyword == KEY_do) {
5950 orig_keyword = 0;
6154021b 5951 pl_yylval.ival = 1;
850e8516
RGS
5952 }
5953 else
6154021b 5954 pl_yylval.ival = 0;
378cc40b 5955 OPERATOR(DO);
79072805
LW
5956
5957 case KEY_die:
3280af22 5958 PL_hints |= HINT_BLOCK_SCOPE;
a0d0e21e 5959 LOP(OP_DIE,XTERM);
79072805
LW
5960
5961 case KEY_defined:
5962 UNI(OP_DEFINED);
5963
5964 case KEY_delete:
a0d0e21e 5965 UNI(OP_DELETE);
79072805
LW
5966
5967 case KEY_dbmopen:
5c1737d1 5968 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
a0d0e21e 5969 LOP(OP_DBMOPEN,XTERM);
79072805
LW
5970
5971 case KEY_dbmclose:
5972 UNI(OP_DBMCLOSE);
5973
5974 case KEY_dump:
a0d0e21e 5975 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
5976 LOOPX(OP_DUMP);
5977
5978 case KEY_else:
5979 PREBLOCK(ELSE);
5980
5981 case KEY_elsif:
6154021b 5982 pl_yylval.ival = CopLINE(PL_curcop);
79072805
LW
5983 OPERATOR(ELSIF);
5984
5985 case KEY_eq:
5986 Eop(OP_SEQ);
5987
a0d0e21e
LW
5988 case KEY_exists:
5989 UNI(OP_EXISTS);
4e553d73 5990
79072805 5991 case KEY_exit:
5db06880
NC
5992 if (PL_madskills)
5993 UNI(OP_INT);
79072805
LW
5994 UNI(OP_EXIT);
5995
5996 case KEY_eval:
29595ff2 5997 s = SKIPSPACE1(s);
3280af22 5998 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
463ee0b2 5999 UNIBRACK(OP_ENTEREVAL);
79072805
LW
6000
6001 case KEY_eof:
6002 UNI(OP_EOF);
6003
6004 case KEY_exp:
6005 UNI(OP_EXP);
6006
6007 case KEY_each:
6008 UNI(OP_EACH);
6009
6010 case KEY_exec:
a0d0e21e 6011 LOP(OP_EXEC,XREF);
79072805
LW
6012
6013 case KEY_endhostent:
6014 FUN0(OP_EHOSTENT);
6015
6016 case KEY_endnetent:
6017 FUN0(OP_ENETENT);
6018
6019 case KEY_endservent:
6020 FUN0(OP_ESERVENT);
6021
6022 case KEY_endprotoent:
6023 FUN0(OP_EPROTOENT);
6024
6025 case KEY_endpwent:
6026 FUN0(OP_EPWENT);
6027
6028 case KEY_endgrent:
6029 FUN0(OP_EGRENT);
6030
6031 case KEY_for:
6032 case KEY_foreach:
6154021b 6033 pl_yylval.ival = CopLINE(PL_curcop);
29595ff2 6034 s = SKIPSPACE1(s);
7e2040f0 6035 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
55497cff 6036 char *p = s;
5db06880
NC
6037#ifdef PERL_MAD
6038 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
6039#endif
6040
3280af22 6041 if ((PL_bufend - p) >= 3 &&
55497cff 6042 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
6043 p += 2;
77ca0c92
LW
6044 else if ((PL_bufend - p) >= 4 &&
6045 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
6046 p += 3;
29595ff2 6047 p = PEEKSPACE(p);
7e2040f0 6048 if (isIDFIRST_lazy_if(p,UTF)) {
77ca0c92
LW
6049 p = scan_ident(p, PL_bufend,
6050 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
29595ff2 6051 p = PEEKSPACE(p);
77ca0c92
LW
6052 }
6053 if (*p != '$')
cea2e8a9 6054 Perl_croak(aTHX_ "Missing $ on loop variable");
5db06880
NC
6055#ifdef PERL_MAD
6056 s = SvPVX(PL_linestr) + soff;
6057#endif
55497cff 6058 }
79072805
LW
6059 OPERATOR(FOR);
6060
6061 case KEY_formline:
a0d0e21e 6062 LOP(OP_FORMLINE,XTERM);
79072805
LW
6063
6064 case KEY_fork:
6065 FUN0(OP_FORK);
6066
6067 case KEY_fcntl:
a0d0e21e 6068 LOP(OP_FCNTL,XTERM);
79072805
LW
6069
6070 case KEY_fileno:
6071 UNI(OP_FILENO);
6072
6073 case KEY_flock:
a0d0e21e 6074 LOP(OP_FLOCK,XTERM);
79072805
LW
6075
6076 case KEY_gt:
6077 Rop(OP_SGT);
6078
6079 case KEY_ge:
6080 Rop(OP_SGE);
6081
6082 case KEY_grep:
2c38e13d 6083 LOP(OP_GREPSTART, XREF);
79072805
LW
6084
6085 case KEY_goto:
a0d0e21e 6086 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
6087 LOOPX(OP_GOTO);
6088
6089 case KEY_gmtime:
6090 UNI(OP_GMTIME);
6091
6092 case KEY_getc:
6f33ba73 6093 UNIDOR(OP_GETC);
79072805
LW
6094
6095 case KEY_getppid:
6096 FUN0(OP_GETPPID);
6097
6098 case KEY_getpgrp:
6099 UNI(OP_GETPGRP);
6100
6101 case KEY_getpriority:
a0d0e21e 6102 LOP(OP_GETPRIORITY,XTERM);
79072805
LW
6103
6104 case KEY_getprotobyname:
6105 UNI(OP_GPBYNAME);
6106
6107 case KEY_getprotobynumber:
a0d0e21e 6108 LOP(OP_GPBYNUMBER,XTERM);
79072805
LW
6109
6110 case KEY_getprotoent:
6111 FUN0(OP_GPROTOENT);
6112
6113 case KEY_getpwent:
6114 FUN0(OP_GPWENT);
6115
6116 case KEY_getpwnam:
ff68c719 6117 UNI(OP_GPWNAM);
79072805
LW
6118
6119 case KEY_getpwuid:
ff68c719 6120 UNI(OP_GPWUID);
79072805
LW
6121
6122 case KEY_getpeername:
6123 UNI(OP_GETPEERNAME);
6124
6125 case KEY_gethostbyname:
6126 UNI(OP_GHBYNAME);
6127
6128 case KEY_gethostbyaddr:
a0d0e21e 6129 LOP(OP_GHBYADDR,XTERM);
79072805
LW
6130
6131 case KEY_gethostent:
6132 FUN0(OP_GHOSTENT);
6133
6134 case KEY_getnetbyname:
6135 UNI(OP_GNBYNAME);
6136
6137 case KEY_getnetbyaddr:
a0d0e21e 6138 LOP(OP_GNBYADDR,XTERM);
79072805
LW
6139
6140 case KEY_getnetent:
6141 FUN0(OP_GNETENT);
6142
6143 case KEY_getservbyname:
a0d0e21e 6144 LOP(OP_GSBYNAME,XTERM);
79072805
LW
6145
6146 case KEY_getservbyport:
a0d0e21e 6147 LOP(OP_GSBYPORT,XTERM);
79072805
LW
6148
6149 case KEY_getservent:
6150 FUN0(OP_GSERVENT);
6151
6152 case KEY_getsockname:
6153 UNI(OP_GETSOCKNAME);
6154
6155 case KEY_getsockopt:
a0d0e21e 6156 LOP(OP_GSOCKOPT,XTERM);
79072805
LW
6157
6158 case KEY_getgrent:
6159 FUN0(OP_GGRENT);
6160
6161 case KEY_getgrnam:
ff68c719 6162 UNI(OP_GGRNAM);
79072805
LW
6163
6164 case KEY_getgrgid:
ff68c719 6165 UNI(OP_GGRGID);
79072805
LW
6166
6167 case KEY_getlogin:
6168 FUN0(OP_GETLOGIN);
6169
0d863452 6170 case KEY_given:
6154021b 6171 pl_yylval.ival = CopLINE(PL_curcop);
0d863452
RH
6172 OPERATOR(GIVEN);
6173
93a17b20 6174 case KEY_glob:
a0d0e21e 6175 LOP(OP_GLOB,XTERM);
93a17b20 6176
79072805
LW
6177 case KEY_hex:
6178 UNI(OP_HEX);
6179
6180 case KEY_if:
6154021b 6181 pl_yylval.ival = CopLINE(PL_curcop);
79072805
LW
6182 OPERATOR(IF);
6183
6184 case KEY_index:
a0d0e21e 6185 LOP(OP_INDEX,XTERM);
79072805
LW
6186
6187 case KEY_int:
6188 UNI(OP_INT);
6189
6190 case KEY_ioctl:
a0d0e21e 6191 LOP(OP_IOCTL,XTERM);
79072805
LW
6192
6193 case KEY_join:
a0d0e21e 6194 LOP(OP_JOIN,XTERM);
79072805
LW
6195
6196 case KEY_keys:
6197 UNI(OP_KEYS);
6198
6199 case KEY_kill:
a0d0e21e 6200 LOP(OP_KILL,XTERM);
79072805
LW
6201
6202 case KEY_last:
a0d0e21e 6203 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805 6204 LOOPX(OP_LAST);
4e553d73 6205
79072805
LW
6206 case KEY_lc:
6207 UNI(OP_LC);
6208
6209 case KEY_lcfirst:
6210 UNI(OP_LCFIRST);
6211
6212 case KEY_local:
6154021b 6213 pl_yylval.ival = 0;
79072805
LW
6214 OPERATOR(LOCAL);
6215
6216 case KEY_length:
6217 UNI(OP_LENGTH);
6218
6219 case KEY_lt:
6220 Rop(OP_SLT);
6221
6222 case KEY_le:
6223 Rop(OP_SLE);
6224
6225 case KEY_localtime:
6226 UNI(OP_LOCALTIME);
6227
6228 case KEY_log:
6229 UNI(OP_LOG);
6230
6231 case KEY_link:
a0d0e21e 6232 LOP(OP_LINK,XTERM);
79072805
LW
6233
6234 case KEY_listen:
a0d0e21e 6235 LOP(OP_LISTEN,XTERM);
79072805 6236
c0329465
MB
6237 case KEY_lock:
6238 UNI(OP_LOCK);
6239
79072805
LW
6240 case KEY_lstat:
6241 UNI(OP_LSTAT);
6242
6243 case KEY_m:
8782bef2 6244 s = scan_pat(s,OP_MATCH);
79072805
LW
6245 TERM(sublex_start());
6246
a0d0e21e 6247 case KEY_map:
2c38e13d 6248 LOP(OP_MAPSTART, XREF);
4e4e412b 6249
79072805 6250 case KEY_mkdir:
a0d0e21e 6251 LOP(OP_MKDIR,XTERM);
79072805
LW
6252
6253 case KEY_msgctl:
a0d0e21e 6254 LOP(OP_MSGCTL,XTERM);
79072805
LW
6255
6256 case KEY_msgget:
a0d0e21e 6257 LOP(OP_MSGGET,XTERM);
79072805
LW
6258
6259 case KEY_msgrcv:
a0d0e21e 6260 LOP(OP_MSGRCV,XTERM);
79072805
LW
6261
6262 case KEY_msgsnd:
a0d0e21e 6263 LOP(OP_MSGSND,XTERM);
79072805 6264
77ca0c92 6265 case KEY_our:
93a17b20 6266 case KEY_my:
952306ac 6267 case KEY_state:
eac04b2e 6268 PL_in_my = (U16)tmp;
29595ff2 6269 s = SKIPSPACE1(s);
7e2040f0 6270 if (isIDFIRST_lazy_if(s,UTF)) {
5db06880
NC
6271#ifdef PERL_MAD
6272 char* start = s;
6273#endif
3280af22 6274 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
09bef843
SB
6275 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
6276 goto really_sub;
def3634b 6277 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
3280af22 6278 if (!PL_in_my_stash) {
c750a3ec 6279 char tmpbuf[1024];
3280af22 6280 PL_bufptr = s;
d9fad198 6281 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
c750a3ec
MB
6282 yyerror(tmpbuf);
6283 }
5db06880
NC
6284#ifdef PERL_MAD
6285 if (PL_madskills) { /* just add type to declarator token */
cd81e915
NC
6286 sv_catsv(PL_thistoken, PL_nextwhite);
6287 PL_nextwhite = 0;
6288 sv_catpvn(PL_thistoken, start, s - start);
5db06880
NC
6289 }
6290#endif
c750a3ec 6291 }
6154021b 6292 pl_yylval.ival = 1;
55497cff 6293 OPERATOR(MY);
93a17b20 6294
79072805 6295 case KEY_next:
a0d0e21e 6296 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
6297 LOOPX(OP_NEXT);
6298
6299 case KEY_ne:
6300 Eop(OP_SNE);
6301
a0d0e21e 6302 case KEY_no:
468aa647 6303 s = tokenize_use(0, s);
a0d0e21e
LW
6304 OPERATOR(USE);
6305
6306 case KEY_not:
29595ff2 6307 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
2d2e263d
LW
6308 FUN1(OP_NOT);
6309 else
6310 OPERATOR(NOTOP);
a0d0e21e 6311
79072805 6312 case KEY_open:
29595ff2 6313 s = SKIPSPACE1(s);
7e2040f0 6314 if (isIDFIRST_lazy_if(s,UTF)) {
f54cb97a 6315 const char *t;
c35e046a
AL
6316 for (d = s; isALNUM_lazy_if(d,UTF);)
6317 d++;
6318 for (t=d; isSPACE(*t);)
6319 t++;
e2ab214b 6320 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
66fbe8fb
HS
6321 /* [perl #16184] */
6322 && !(t[0] == '=' && t[1] == '>')
6323 ) {
5f66b61c 6324 int parms_len = (int)(d-s);
9014280d 6325 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
0453d815 6326 "Precedence problem: open %.*s should be open(%.*s)",
5f66b61c 6327 parms_len, s, parms_len, s);
66fbe8fb 6328 }
93a17b20 6329 }
a0d0e21e 6330 LOP(OP_OPEN,XTERM);
79072805 6331
463ee0b2 6332 case KEY_or:
6154021b 6333 pl_yylval.ival = OP_OR;
463ee0b2
LW
6334 OPERATOR(OROP);
6335
79072805
LW
6336 case KEY_ord:
6337 UNI(OP_ORD);
6338
6339 case KEY_oct:
6340 UNI(OP_OCT);
6341
6342 case KEY_opendir:
a0d0e21e 6343 LOP(OP_OPEN_DIR,XTERM);
79072805
LW
6344
6345 case KEY_print:
3280af22 6346 checkcomma(s,PL_tokenbuf,"filehandle");
a0d0e21e 6347 LOP(OP_PRINT,XREF);
79072805
LW
6348
6349 case KEY_printf:
3280af22 6350 checkcomma(s,PL_tokenbuf,"filehandle");
a0d0e21e 6351 LOP(OP_PRTF,XREF);
79072805 6352
c07a80fd 6353 case KEY_prototype:
6354 UNI(OP_PROTOTYPE);
6355
79072805 6356 case KEY_push:
a0d0e21e 6357 LOP(OP_PUSH,XTERM);
79072805
LW
6358
6359 case KEY_pop:
6f33ba73 6360 UNIDOR(OP_POP);
79072805 6361
a0d0e21e 6362 case KEY_pos:
6f33ba73 6363 UNIDOR(OP_POS);
4e553d73 6364
79072805 6365 case KEY_pack:
a0d0e21e 6366 LOP(OP_PACK,XTERM);
79072805
LW
6367
6368 case KEY_package:
a0d0e21e 6369 s = force_word(s,WORD,FALSE,TRUE,FALSE);
79072805
LW
6370 OPERATOR(PACKAGE);
6371
6372 case KEY_pipe:
a0d0e21e 6373 LOP(OP_PIPE_OP,XTERM);
79072805
LW
6374
6375 case KEY_q:
5db06880 6376 s = scan_str(s,!!PL_madskills,FALSE);
79072805 6377 if (!s)
d4c19fe8 6378 missingterm(NULL);
6154021b 6379 pl_yylval.ival = OP_CONST;
79072805
LW
6380 TERM(sublex_start());
6381
a0d0e21e
LW
6382 case KEY_quotemeta:
6383 UNI(OP_QUOTEMETA);
6384
8990e307 6385 case KEY_qw:
5db06880 6386 s = scan_str(s,!!PL_madskills,FALSE);
8990e307 6387 if (!s)
d4c19fe8 6388 missingterm(NULL);
3480a8d2 6389 PL_expect = XOPERATOR;
8127e0e3
GS
6390 force_next(')');
6391 if (SvCUR(PL_lex_stuff)) {
5f66b61c 6392 OP *words = NULL;
8127e0e3 6393 int warned = 0;
3280af22 6394 d = SvPV_force(PL_lex_stuff, len);
8127e0e3 6395 while (len) {
d4c19fe8
AL
6396 for (; isSPACE(*d) && len; --len, ++d)
6397 /**/;
8127e0e3 6398 if (len) {
d4c19fe8 6399 SV *sv;
f54cb97a 6400 const char *b = d;
e476b1b5 6401 if (!warned && ckWARN(WARN_QW)) {
8127e0e3
GS
6402 for (; !isSPACE(*d) && len; --len, ++d) {
6403 if (*d == ',') {
9014280d 6404 Perl_warner(aTHX_ packWARN(WARN_QW),
8127e0e3
GS
6405 "Possible attempt to separate words with commas");
6406 ++warned;
6407 }
6408 else if (*d == '#') {
9014280d 6409 Perl_warner(aTHX_ packWARN(WARN_QW),
8127e0e3
GS
6410 "Possible attempt to put comments in qw() list");
6411 ++warned;
6412 }
6413 }
6414 }
6415 else {
d4c19fe8
AL
6416 for (; !isSPACE(*d) && len; --len, ++d)
6417 /**/;
8127e0e3 6418 }
740cce10 6419 sv = newSVpvn_utf8(b, d-b, DO_UTF8(PL_lex_stuff));
8127e0e3 6420 words = append_elem(OP_LIST, words,
7948272d 6421 newSVOP(OP_CONST, 0, tokeq(sv)));
55497cff 6422 }
6423 }
8127e0e3 6424 if (words) {
cd81e915 6425 start_force(PL_curforce);
9ded7720 6426 NEXTVAL_NEXTTOKE.opval = words;
8127e0e3
GS
6427 force_next(THING);
6428 }
55497cff 6429 }
37fd879b 6430 if (PL_lex_stuff) {
8127e0e3 6431 SvREFCNT_dec(PL_lex_stuff);
a0714e2c 6432 PL_lex_stuff = NULL;
37fd879b 6433 }
3280af22 6434 PL_expect = XTERM;
8127e0e3 6435 TOKEN('(');
8990e307 6436
79072805 6437 case KEY_qq:
5db06880 6438 s = scan_str(s,!!PL_madskills,FALSE);
79072805 6439 if (!s)
d4c19fe8 6440 missingterm(NULL);
6154021b 6441 pl_yylval.ival = OP_STRINGIFY;
3280af22 6442 if (SvIVX(PL_lex_stuff) == '\'')
45977657 6443 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
79072805
LW
6444 TERM(sublex_start());
6445
8782bef2
GB
6446 case KEY_qr:
6447 s = scan_pat(s,OP_QR);
6448 TERM(sublex_start());
6449
79072805 6450 case KEY_qx:
5db06880 6451 s = scan_str(s,!!PL_madskills,FALSE);
79072805 6452 if (!s)
d4c19fe8 6453 missingterm(NULL);
9b201d7d 6454 readpipe_override();
79072805
LW
6455 TERM(sublex_start());
6456
6457 case KEY_return:
6458 OLDLOP(OP_RETURN);
6459
6460 case KEY_require:
29595ff2 6461 s = SKIPSPACE1(s);
e759cc13
RGS
6462 if (isDIGIT(*s)) {
6463 s = force_version(s, FALSE);
a7cb1f99 6464 }
e759cc13
RGS
6465 else if (*s != 'v' || !isDIGIT(s[1])
6466 || (s = force_version(s, TRUE), *s == 'v'))
6467 {
a7cb1f99
GS
6468 *PL_tokenbuf = '\0';
6469 s = force_word(s,WORD,TRUE,TRUE,FALSE);
7e2040f0 6470 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
da51bb9b 6471 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), GV_ADD);
a7cb1f99
GS
6472 else if (*s == '<')
6473 yyerror("<> should be quotes");
6474 }
a72a1c8b
RGS
6475 if (orig_keyword == KEY_require) {
6476 orig_keyword = 0;
6154021b 6477 pl_yylval.ival = 1;
a72a1c8b
RGS
6478 }
6479 else
6154021b 6480 pl_yylval.ival = 0;
a72a1c8b
RGS
6481 PL_expect = XTERM;
6482 PL_bufptr = s;
6483 PL_last_uni = PL_oldbufptr;
6484 PL_last_lop_op = OP_REQUIRE;
6485 s = skipspace(s);
6486 return REPORT( (int)REQUIRE );
79072805
LW
6487
6488 case KEY_reset:
6489 UNI(OP_RESET);
6490
6491 case KEY_redo:
a0d0e21e 6492 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
6493 LOOPX(OP_REDO);
6494
6495 case KEY_rename:
a0d0e21e 6496 LOP(OP_RENAME,XTERM);
79072805
LW
6497
6498 case KEY_rand:
6499 UNI(OP_RAND);
6500
6501 case KEY_rmdir:
6502 UNI(OP_RMDIR);
6503
6504 case KEY_rindex:
a0d0e21e 6505 LOP(OP_RINDEX,XTERM);
79072805
LW
6506
6507 case KEY_read:
a0d0e21e 6508 LOP(OP_READ,XTERM);
79072805
LW
6509
6510 case KEY_readdir:
6511 UNI(OP_READDIR);
6512
93a17b20 6513 case KEY_readline:
6f33ba73 6514 UNIDOR(OP_READLINE);
93a17b20
LW
6515
6516 case KEY_readpipe:
0858480c 6517 UNIDOR(OP_BACKTICK);
93a17b20 6518
79072805
LW
6519 case KEY_rewinddir:
6520 UNI(OP_REWINDDIR);
6521
6522 case KEY_recv:
a0d0e21e 6523 LOP(OP_RECV,XTERM);
79072805
LW
6524
6525 case KEY_reverse:
a0d0e21e 6526 LOP(OP_REVERSE,XTERM);
79072805
LW
6527
6528 case KEY_readlink:
6f33ba73 6529 UNIDOR(OP_READLINK);
79072805
LW
6530
6531 case KEY_ref:
6532 UNI(OP_REF);
6533
6534 case KEY_s:
6535 s = scan_subst(s);
6154021b 6536 if (pl_yylval.opval)
79072805
LW
6537 TERM(sublex_start());
6538 else
6539 TOKEN(1); /* force error */
6540
0d863452
RH
6541 case KEY_say:
6542 checkcomma(s,PL_tokenbuf,"filehandle");
6543 LOP(OP_SAY,XREF);
6544
a0d0e21e
LW
6545 case KEY_chomp:
6546 UNI(OP_CHOMP);
4e553d73 6547
79072805
LW
6548 case KEY_scalar:
6549 UNI(OP_SCALAR);
6550
6551 case KEY_select:
a0d0e21e 6552 LOP(OP_SELECT,XTERM);
79072805
LW
6553
6554 case KEY_seek:
a0d0e21e 6555 LOP(OP_SEEK,XTERM);
79072805
LW
6556
6557 case KEY_semctl:
a0d0e21e 6558 LOP(OP_SEMCTL,XTERM);
79072805
LW
6559
6560 case KEY_semget:
a0d0e21e 6561 LOP(OP_SEMGET,XTERM);
79072805
LW
6562
6563 case KEY_semop:
a0d0e21e 6564 LOP(OP_SEMOP,XTERM);
79072805
LW
6565
6566 case KEY_send:
a0d0e21e 6567 LOP(OP_SEND,XTERM);
79072805
LW
6568
6569 case KEY_setpgrp:
a0d0e21e 6570 LOP(OP_SETPGRP,XTERM);
79072805
LW
6571
6572 case KEY_setpriority:
a0d0e21e 6573 LOP(OP_SETPRIORITY,XTERM);
79072805
LW
6574
6575 case KEY_sethostent:
ff68c719 6576 UNI(OP_SHOSTENT);
79072805
LW
6577
6578 case KEY_setnetent:
ff68c719 6579 UNI(OP_SNETENT);
79072805
LW
6580
6581 case KEY_setservent:
ff68c719 6582 UNI(OP_SSERVENT);
79072805
LW
6583
6584 case KEY_setprotoent:
ff68c719 6585 UNI(OP_SPROTOENT);
79072805
LW
6586
6587 case KEY_setpwent:
6588 FUN0(OP_SPWENT);
6589
6590 case KEY_setgrent:
6591 FUN0(OP_SGRENT);
6592
6593 case KEY_seekdir:
a0d0e21e 6594 LOP(OP_SEEKDIR,XTERM);
79072805
LW
6595
6596 case KEY_setsockopt:
a0d0e21e 6597 LOP(OP_SSOCKOPT,XTERM);
79072805
LW
6598
6599 case KEY_shift:
6f33ba73 6600 UNIDOR(OP_SHIFT);
79072805
LW
6601
6602 case KEY_shmctl:
a0d0e21e 6603 LOP(OP_SHMCTL,XTERM);
79072805
LW
6604
6605 case KEY_shmget:
a0d0e21e 6606 LOP(OP_SHMGET,XTERM);
79072805
LW
6607
6608 case KEY_shmread:
a0d0e21e 6609 LOP(OP_SHMREAD,XTERM);
79072805
LW
6610
6611 case KEY_shmwrite:
a0d0e21e 6612 LOP(OP_SHMWRITE,XTERM);
79072805
LW
6613
6614 case KEY_shutdown:
a0d0e21e 6615 LOP(OP_SHUTDOWN,XTERM);
79072805
LW
6616
6617 case KEY_sin:
6618 UNI(OP_SIN);
6619
6620 case KEY_sleep:
6621 UNI(OP_SLEEP);
6622
6623 case KEY_socket:
a0d0e21e 6624 LOP(OP_SOCKET,XTERM);
79072805
LW
6625
6626 case KEY_socketpair:
a0d0e21e 6627 LOP(OP_SOCKPAIR,XTERM);
79072805
LW
6628
6629 case KEY_sort:
3280af22 6630 checkcomma(s,PL_tokenbuf,"subroutine name");
29595ff2 6631 s = SKIPSPACE1(s);
79072805 6632 if (*s == ';' || *s == ')') /* probably a close */
cea2e8a9 6633 Perl_croak(aTHX_ "sort is now a reserved word");
3280af22 6634 PL_expect = XTERM;
15f0808c 6635 s = force_word(s,WORD,TRUE,TRUE,FALSE);
a0d0e21e 6636 LOP(OP_SORT,XREF);
79072805
LW
6637
6638 case KEY_split:
a0d0e21e 6639 LOP(OP_SPLIT,XTERM);
79072805
LW
6640
6641 case KEY_sprintf:
a0d0e21e 6642 LOP(OP_SPRINTF,XTERM);
79072805
LW
6643
6644 case KEY_splice:
a0d0e21e 6645 LOP(OP_SPLICE,XTERM);
79072805
LW
6646
6647 case KEY_sqrt:
6648 UNI(OP_SQRT);
6649
6650 case KEY_srand:
6651 UNI(OP_SRAND);
6652
6653 case KEY_stat:
6654 UNI(OP_STAT);
6655
6656 case KEY_study:
79072805
LW
6657 UNI(OP_STUDY);
6658
6659 case KEY_substr:
a0d0e21e 6660 LOP(OP_SUBSTR,XTERM);
79072805
LW
6661
6662 case KEY_format:
6663 case KEY_sub:
93a17b20 6664 really_sub:
09bef843 6665 {
3280af22 6666 char tmpbuf[sizeof PL_tokenbuf];
9c5ffd7c 6667 SSize_t tboffset = 0;
09bef843 6668 expectation attrful;
28cc6278 6669 bool have_name, have_proto;
f54cb97a 6670 const int key = tmp;
09bef843 6671
5db06880
NC
6672#ifdef PERL_MAD
6673 SV *tmpwhite = 0;
6674
cd81e915 6675 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5db06880 6676 SV *subtoken = newSVpvn(tstart, s - tstart);
cd81e915 6677 PL_thistoken = 0;
5db06880
NC
6678
6679 d = s;
6680 s = SKIPSPACE2(s,tmpwhite);
6681#else
09bef843 6682 s = skipspace(s);
5db06880 6683#endif
09bef843 6684
7e2040f0 6685 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
09bef843
SB
6686 (*s == ':' && s[1] == ':'))
6687 {
5db06880 6688#ifdef PERL_MAD
4f61fd4b 6689 SV *nametoke = NULL;
5db06880
NC
6690#endif
6691
09bef843
SB
6692 PL_expect = XBLOCK;
6693 attrful = XATTRBLOCK;
b1b65b59
JH
6694 /* remember buffer pos'n for later force_word */
6695 tboffset = s - PL_oldbufptr;
09bef843 6696 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5db06880
NC
6697#ifdef PERL_MAD
6698 if (PL_madskills)
6699 nametoke = newSVpvn(s, d - s);
6700#endif
6502358f
NC
6701 if (memchr(tmpbuf, ':', len))
6702 sv_setpvn(PL_subname, tmpbuf, len);
09bef843
SB
6703 else {
6704 sv_setsv(PL_subname,PL_curstname);
396482e1 6705 sv_catpvs(PL_subname,"::");
09bef843
SB
6706 sv_catpvn(PL_subname,tmpbuf,len);
6707 }
09bef843 6708 have_name = TRUE;
5db06880
NC
6709
6710#ifdef PERL_MAD
6711
6712 start_force(0);
6713 CURMAD('X', nametoke);
6714 CURMAD('_', tmpwhite);
6715 (void) force_word(PL_oldbufptr + tboffset, WORD,
6716 FALSE, TRUE, TRUE);
6717
6718 s = SKIPSPACE2(d,tmpwhite);
6719#else
6720 s = skipspace(d);
6721#endif
09bef843 6722 }
463ee0b2 6723 else {
09bef843
SB
6724 if (key == KEY_my)
6725 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6726 PL_expect = XTERMBLOCK;
6727 attrful = XATTRTERM;
76f68e9b 6728 sv_setpvs(PL_subname,"?");
09bef843 6729 have_name = FALSE;
463ee0b2 6730 }
4633a7c4 6731
09bef843
SB
6732 if (key == KEY_format) {
6733 if (*s == '=')
6734 PL_lex_formbrack = PL_lex_brackets + 1;
5db06880 6735#ifdef PERL_MAD
cd81e915 6736 PL_thistoken = subtoken;
5db06880
NC
6737 s = d;
6738#else
09bef843 6739 if (have_name)
b1b65b59
JH
6740 (void) force_word(PL_oldbufptr + tboffset, WORD,
6741 FALSE, TRUE, TRUE);
5db06880 6742#endif
09bef843
SB
6743 OPERATOR(FORMAT);
6744 }
79072805 6745
09bef843
SB
6746 /* Look for a prototype */
6747 if (*s == '(') {
d9f2850e
RGS
6748 char *p;
6749 bool bad_proto = FALSE;
9e8d7757
RB
6750 bool in_brackets = FALSE;
6751 char greedy_proto = ' ';
6752 bool proto_after_greedy_proto = FALSE;
6753 bool must_be_last = FALSE;
6754 bool underscore = FALSE;
aef2a98a 6755 bool seen_underscore = FALSE;
d9f2850e 6756 const bool warnsyntax = ckWARN(WARN_SYNTAX);
09bef843 6757
5db06880 6758 s = scan_str(s,!!PL_madskills,FALSE);
37fd879b 6759 if (!s)
09bef843 6760 Perl_croak(aTHX_ "Prototype not terminated");
2f758a16 6761 /* strip spaces and check for bad characters */
09bef843
SB
6762 d = SvPVX(PL_lex_stuff);
6763 tmp = 0;
d9f2850e
RGS
6764 for (p = d; *p; ++p) {
6765 if (!isSPACE(*p)) {
6766 d[tmp++] = *p;
9e8d7757
RB
6767
6768 if (warnsyntax) {
6769 if (must_be_last)
6770 proto_after_greedy_proto = TRUE;
6771 if (!strchr("$@%*;[]&\\_", *p)) {
6772 bad_proto = TRUE;
6773 }
6774 else {
6775 if ( underscore ) {
6776 if ( *p != ';' )
6777 bad_proto = TRUE;
6778 underscore = FALSE;
6779 }
6780 if ( *p == '[' ) {
6781 in_brackets = TRUE;
6782 }
6783 else if ( *p == ']' ) {
6784 in_brackets = FALSE;
6785 }
6786 else if ( (*p == '@' || *p == '%') &&
6787 ( tmp < 2 || d[tmp-2] != '\\' ) &&
6788 !in_brackets ) {
6789 must_be_last = TRUE;
6790 greedy_proto = *p;
6791 }
6792 else if ( *p == '_' ) {
aef2a98a 6793 underscore = seen_underscore = TRUE;
9e8d7757
RB
6794 }
6795 }
6796 }
d37a9538 6797 }
09bef843 6798 }
d9f2850e 6799 d[tmp] = '\0';
9e8d7757
RB
6800 if (proto_after_greedy_proto)
6801 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6802 "Prototype after '%c' for %"SVf" : %s",
6803 greedy_proto, SVfARG(PL_subname), d);
d9f2850e
RGS
6804 if (bad_proto)
6805 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
aef2a98a
RGS
6806 "Illegal character %sin prototype for %"SVf" : %s",
6807 seen_underscore ? "after '_' " : "",
be2597df 6808 SVfARG(PL_subname), d);
b162af07 6809 SvCUR_set(PL_lex_stuff, tmp);
09bef843 6810 have_proto = TRUE;
68dc0745 6811
5db06880
NC
6812#ifdef PERL_MAD
6813 start_force(0);
cd81e915 6814 CURMAD('q', PL_thisopen);
5db06880 6815 CURMAD('_', tmpwhite);
cd81e915
NC
6816 CURMAD('=', PL_thisstuff);
6817 CURMAD('Q', PL_thisclose);
5db06880
NC
6818 NEXTVAL_NEXTTOKE.opval =
6819 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
1a9a51d4 6820 PL_lex_stuff = NULL;
5db06880
NC
6821 force_next(THING);
6822
6823 s = SKIPSPACE2(s,tmpwhite);
6824#else
09bef843 6825 s = skipspace(s);
5db06880 6826#endif
4633a7c4 6827 }
09bef843
SB
6828 else
6829 have_proto = FALSE;
6830
6831 if (*s == ':' && s[1] != ':')
6832 PL_expect = attrful;
8e742a20
MHM
6833 else if (*s != '{' && key == KEY_sub) {
6834 if (!have_name)
6835 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6836 else if (*s != ';')
be2597df 6837 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, SVfARG(PL_subname));
8e742a20 6838 }
09bef843 6839
5db06880
NC
6840#ifdef PERL_MAD
6841 start_force(0);
6842 if (tmpwhite) {
6843 if (PL_madskills)
6b29d1f5 6844 curmad('^', newSVpvs(""));
5db06880
NC
6845 CURMAD('_', tmpwhite);
6846 }
6847 force_next(0);
6848
cd81e915 6849 PL_thistoken = subtoken;
5db06880 6850#else
09bef843 6851 if (have_proto) {
9ded7720 6852 NEXTVAL_NEXTTOKE.opval =
b1b65b59 6853 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
a0714e2c 6854 PL_lex_stuff = NULL;
09bef843 6855 force_next(THING);
68dc0745 6856 }
5db06880 6857#endif
09bef843 6858 if (!have_name) {
49a54bbe
NC
6859 if (PL_curstash)
6860 sv_setpvs(PL_subname, "__ANON__");
6861 else
6862 sv_setpvs(PL_subname, "__ANON__::__ANON__");
09bef843 6863 TOKEN(ANONSUB);
4633a7c4 6864 }
5db06880 6865#ifndef PERL_MAD
b1b65b59
JH
6866 (void) force_word(PL_oldbufptr + tboffset, WORD,
6867 FALSE, TRUE, TRUE);
5db06880 6868#endif
09bef843
SB
6869 if (key == KEY_my)
6870 TOKEN(MYSUB);
6871 TOKEN(SUB);
4633a7c4 6872 }
79072805
LW
6873
6874 case KEY_system:
a0d0e21e 6875 LOP(OP_SYSTEM,XREF);
79072805
LW
6876
6877 case KEY_symlink:
a0d0e21e 6878 LOP(OP_SYMLINK,XTERM);
79072805
LW
6879
6880 case KEY_syscall:
a0d0e21e 6881 LOP(OP_SYSCALL,XTERM);
79072805 6882
c07a80fd 6883 case KEY_sysopen:
6884 LOP(OP_SYSOPEN,XTERM);
6885
137443ea 6886 case KEY_sysseek:
6887 LOP(OP_SYSSEEK,XTERM);
6888
79072805 6889 case KEY_sysread:
a0d0e21e 6890 LOP(OP_SYSREAD,XTERM);
79072805
LW
6891
6892 case KEY_syswrite:
a0d0e21e 6893 LOP(OP_SYSWRITE,XTERM);
79072805
LW
6894
6895 case KEY_tr:
6896 s = scan_trans(s);
6897 TERM(sublex_start());
6898
6899 case KEY_tell:
6900 UNI(OP_TELL);
6901
6902 case KEY_telldir:
6903 UNI(OP_TELLDIR);
6904
463ee0b2 6905 case KEY_tie:
a0d0e21e 6906 LOP(OP_TIE,XTERM);
463ee0b2 6907
c07a80fd 6908 case KEY_tied:
6909 UNI(OP_TIED);
6910
79072805
LW
6911 case KEY_time:
6912 FUN0(OP_TIME);
6913
6914 case KEY_times:
6915 FUN0(OP_TMS);
6916
6917 case KEY_truncate:
a0d0e21e 6918 LOP(OP_TRUNCATE,XTERM);
79072805
LW
6919
6920 case KEY_uc:
6921 UNI(OP_UC);
6922
6923 case KEY_ucfirst:
6924 UNI(OP_UCFIRST);
6925
463ee0b2
LW
6926 case KEY_untie:
6927 UNI(OP_UNTIE);
6928
79072805 6929 case KEY_until:
6154021b 6930 pl_yylval.ival = CopLINE(PL_curcop);
79072805
LW
6931 OPERATOR(UNTIL);
6932
6933 case KEY_unless:
6154021b 6934 pl_yylval.ival = CopLINE(PL_curcop);
79072805
LW
6935 OPERATOR(UNLESS);
6936
6937 case KEY_unlink:
a0d0e21e 6938 LOP(OP_UNLINK,XTERM);
79072805
LW
6939
6940 case KEY_undef:
6f33ba73 6941 UNIDOR(OP_UNDEF);
79072805
LW
6942
6943 case KEY_unpack:
a0d0e21e 6944 LOP(OP_UNPACK,XTERM);
79072805
LW
6945
6946 case KEY_utime:
a0d0e21e 6947 LOP(OP_UTIME,XTERM);
79072805
LW
6948
6949 case KEY_umask:
6f33ba73 6950 UNIDOR(OP_UMASK);
79072805
LW
6951
6952 case KEY_unshift:
a0d0e21e
LW
6953 LOP(OP_UNSHIFT,XTERM);
6954
6955 case KEY_use:
468aa647 6956 s = tokenize_use(1, s);
a0d0e21e 6957 OPERATOR(USE);
79072805
LW
6958
6959 case KEY_values:
6960 UNI(OP_VALUES);
6961
6962 case KEY_vec:
a0d0e21e 6963 LOP(OP_VEC,XTERM);
79072805 6964
0d863452 6965 case KEY_when:
6154021b 6966 pl_yylval.ival = CopLINE(PL_curcop);
0d863452
RH
6967 OPERATOR(WHEN);
6968
79072805 6969 case KEY_while:
6154021b 6970 pl_yylval.ival = CopLINE(PL_curcop);
79072805
LW
6971 OPERATOR(WHILE);
6972
6973 case KEY_warn:
3280af22 6974 PL_hints |= HINT_BLOCK_SCOPE;
a0d0e21e 6975 LOP(OP_WARN,XTERM);
79072805
LW
6976
6977 case KEY_wait:
6978 FUN0(OP_WAIT);
6979
6980 case KEY_waitpid:
a0d0e21e 6981 LOP(OP_WAITPID,XTERM);
79072805
LW
6982
6983 case KEY_wantarray:
6984 FUN0(OP_WANTARRAY);
6985
6986 case KEY_write:
9d116dd7
JH
6987#ifdef EBCDIC
6988 {
df3728a2
JH
6989 char ctl_l[2];
6990 ctl_l[0] = toCTRL('L');
6991 ctl_l[1] = '\0';
fafc274c 6992 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
9d116dd7
JH
6993 }
6994#else
fafc274c
NC
6995 /* Make sure $^L is defined */
6996 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
9d116dd7 6997#endif
79072805
LW
6998 UNI(OP_ENTERWRITE);
6999
7000 case KEY_x:
3280af22 7001 if (PL_expect == XOPERATOR)
79072805
LW
7002 Mop(OP_REPEAT);
7003 check_uni();
7004 goto just_a_word;
7005
a0d0e21e 7006 case KEY_xor:
6154021b 7007 pl_yylval.ival = OP_XOR;
a0d0e21e
LW
7008 OPERATOR(OROP);
7009
79072805
LW
7010 case KEY_y:
7011 s = scan_trans(s);
7012 TERM(sublex_start());
7013 }
49dc05e3 7014 }}
79072805 7015}
bf4acbe4
GS
7016#ifdef __SC__
7017#pragma segment Main
7018#endif
79072805 7019
e930465f
JH
7020static int
7021S_pending_ident(pTHX)
8eceec63 7022{
97aff369 7023 dVAR;
8eceec63 7024 register char *d;
bbd11bfc 7025 PADOFFSET tmp = 0;
8eceec63
SC
7026 /* pit holds the identifier we read and pending_ident is reset */
7027 char pit = PL_pending_ident;
9bde8eb0
NC
7028 const STRLEN tokenbuf_len = strlen(PL_tokenbuf);
7029 /* All routes through this function want to know if there is a colon. */
c099d646 7030 const char *const has_colon = (const char*) memchr (PL_tokenbuf, ':', tokenbuf_len);
8eceec63
SC
7031 PL_pending_ident = 0;
7032
cd81e915 7033 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
8eceec63 7034 DEBUG_T({ PerlIO_printf(Perl_debug_log,
b6007c36 7035 "### Pending identifier '%s'\n", PL_tokenbuf); });
8eceec63
SC
7036
7037 /* if we're in a my(), we can't allow dynamics here.
7038 $foo'bar has already been turned into $foo::bar, so
7039 just check for colons.
7040
7041 if it's a legal name, the OP is a PADANY.
7042 */
7043 if (PL_in_my) {
7044 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
9bde8eb0 7045 if (has_colon)
8eceec63
SC
7046 yyerror(Perl_form(aTHX_ "No package name allowed for "
7047 "variable %s in \"our\"",
7048 PL_tokenbuf));
dd2155a4 7049 tmp = allocmy(PL_tokenbuf);
8eceec63
SC
7050 }
7051 else {
9bde8eb0 7052 if (has_colon)
952306ac
RGS
7053 yyerror(Perl_form(aTHX_ PL_no_myglob,
7054 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
8eceec63 7055
6154021b
RGS
7056 pl_yylval.opval = newOP(OP_PADANY, 0);
7057 pl_yylval.opval->op_targ = allocmy(PL_tokenbuf);
8eceec63
SC
7058 return PRIVATEREF;
7059 }
7060 }
7061
7062 /*
7063 build the ops for accesses to a my() variable.
7064
7065 Deny my($a) or my($b) in a sort block, *if* $a or $b is
7066 then used in a comparison. This catches most, but not
7067 all cases. For instance, it catches
7068 sort { my($a); $a <=> $b }
7069 but not
7070 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
7071 (although why you'd do that is anyone's guess).
7072 */
7073
9bde8eb0 7074 if (!has_colon) {
8716503d
DM
7075 if (!PL_in_my)
7076 tmp = pad_findmy(PL_tokenbuf);
7077 if (tmp != NOT_IN_PAD) {
8eceec63 7078 /* might be an "our" variable" */
00b1698f 7079 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
8eceec63 7080 /* build ops for a bareword */
b64e5050
AL
7081 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
7082 HEK * const stashname = HvNAME_HEK(stash);
7083 SV * const sym = newSVhek(stashname);
396482e1 7084 sv_catpvs(sym, "::");
9bde8eb0 7085 sv_catpvn(sym, PL_tokenbuf+1, tokenbuf_len - 1);
6154021b
RGS
7086 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
7087 pl_yylval.opval->op_private = OPpCONST_ENTERED;
7a5fd60d 7088 gv_fetchsv(sym,
8eceec63
SC
7089 (PL_in_eval
7090 ? (GV_ADDMULTI | GV_ADDINEVAL)
700078d2 7091 : GV_ADDMULTI
8eceec63
SC
7092 ),
7093 ((PL_tokenbuf[0] == '$') ? SVt_PV
7094 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
7095 : SVt_PVHV));
7096 return WORD;
7097 }
7098
7099 /* if it's a sort block and they're naming $a or $b */
7100 if (PL_last_lop_op == OP_SORT &&
7101 PL_tokenbuf[0] == '$' &&
7102 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
7103 && !PL_tokenbuf[2])
7104 {
7105 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
7106 d < PL_bufend && *d != '\n';
7107 d++)
7108 {
7109 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
7110 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
7111 PL_tokenbuf);
7112 }
7113 }
7114 }
7115
6154021b
RGS
7116 pl_yylval.opval = newOP(OP_PADANY, 0);
7117 pl_yylval.opval->op_targ = tmp;
8eceec63
SC
7118 return PRIVATEREF;
7119 }
7120 }
7121
7122 /*
7123 Whine if they've said @foo in a doublequoted string,
7124 and @foo isn't a variable we can find in the symbol
7125 table.
7126 */
7127 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
9bde8eb0
NC
7128 GV *const gv = gv_fetchpvn_flags(PL_tokenbuf + 1, tokenbuf_len - 1, 0,
7129 SVt_PVAV);
8eceec63 7130 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
e879d94f
RGS
7131 && ckWARN(WARN_AMBIGUOUS)
7132 /* DO NOT warn for @- and @+ */
7133 && !( PL_tokenbuf[2] == '\0' &&
7134 ( PL_tokenbuf[1] == '-' || PL_tokenbuf[1] == '+' ))
7135 )
8eceec63
SC
7136 {
7137 /* Downgraded from fatal to warning 20000522 mjd */
9014280d 7138 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
8eceec63
SC
7139 "Possible unintended interpolation of %s in string",
7140 PL_tokenbuf);
7141 }
7142 }
7143
7144 /* build ops for a bareword */
6154021b 7145 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpvn(PL_tokenbuf + 1,
9bde8eb0 7146 tokenbuf_len - 1));
6154021b 7147 pl_yylval.opval->op_private = OPpCONST_ENTERED;
9bde8eb0
NC
7148 gv_fetchpvn_flags(
7149 PL_tokenbuf + 1, tokenbuf_len - 1,
d6069db2
RGS
7150 /* If the identifier refers to a stash, don't autovivify it.
7151 * Change 24660 had the side effect of causing symbol table
7152 * hashes to always be defined, even if they were freshly
7153 * created and the only reference in the entire program was
7154 * the single statement with the defined %foo::bar:: test.
7155 * It appears that all code in the wild doing this actually
7156 * wants to know whether sub-packages have been loaded, so
7157 * by avoiding auto-vivifying symbol tables, we ensure that
7158 * defined %foo::bar:: continues to be false, and the existing
7159 * tests still give the expected answers, even though what
7160 * they're actually testing has now changed subtly.
7161 */
9bde8eb0
NC
7162 (*PL_tokenbuf == '%'
7163 && *(d = PL_tokenbuf + tokenbuf_len - 1) == ':'
7164 && d[-1] == ':'
d6069db2
RGS
7165 ? 0
7166 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
adc51b97
RGS
7167 ((PL_tokenbuf[0] == '$') ? SVt_PV
7168 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
7169 : SVt_PVHV));
8eceec63
SC
7170 return WORD;
7171}
7172
4c3bbe0f
MHM
7173/*
7174 * The following code was generated by perl_keyword.pl.
7175 */
e2e1dd5a 7176
79072805 7177I32
5458a98a 7178Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
4c3bbe0f 7179{
952306ac 7180 dVAR;
7918f24d
NC
7181
7182 PERL_ARGS_ASSERT_KEYWORD;
7183
4c3bbe0f
MHM
7184 switch (len)
7185 {
7186 case 1: /* 5 tokens of length 1 */
7187 switch (name[0])
e2e1dd5a 7188 {
4c3bbe0f
MHM
7189 case 'm':
7190 { /* m */
7191 return KEY_m;
7192 }
7193
4c3bbe0f
MHM
7194 case 'q':
7195 { /* q */
7196 return KEY_q;
7197 }
7198
4c3bbe0f
MHM
7199 case 's':
7200 { /* s */
7201 return KEY_s;
7202 }
7203
4c3bbe0f
MHM
7204 case 'x':
7205 { /* x */
7206 return -KEY_x;
7207 }
7208
4c3bbe0f
MHM
7209 case 'y':
7210 { /* y */
7211 return KEY_y;
7212 }
7213
4c3bbe0f
MHM
7214 default:
7215 goto unknown;
e2e1dd5a 7216 }
4c3bbe0f
MHM
7217
7218 case 2: /* 18 tokens of length 2 */
7219 switch (name[0])
e2e1dd5a 7220 {
4c3bbe0f
MHM
7221 case 'd':
7222 if (name[1] == 'o')
7223 { /* do */
7224 return KEY_do;
7225 }
7226
7227 goto unknown;
7228
7229 case 'e':
7230 if (name[1] == 'q')
7231 { /* eq */
7232 return -KEY_eq;
7233 }
7234
7235 goto unknown;
7236
7237 case 'g':
7238 switch (name[1])
7239 {
7240 case 'e':
7241 { /* ge */
7242 return -KEY_ge;
7243 }
7244
4c3bbe0f
MHM
7245 case 't':
7246 { /* gt */
7247 return -KEY_gt;
7248 }
7249
4c3bbe0f
MHM
7250 default:
7251 goto unknown;
7252 }
7253
7254 case 'i':
7255 if (name[1] == 'f')
7256 { /* if */
7257 return KEY_if;
7258 }
7259
7260 goto unknown;
7261
7262 case 'l':
7263 switch (name[1])
7264 {
7265 case 'c':
7266 { /* lc */
7267 return -KEY_lc;
7268 }
7269
4c3bbe0f
MHM
7270 case 'e':
7271 { /* le */
7272 return -KEY_le;
7273 }
7274
4c3bbe0f
MHM
7275 case 't':
7276 { /* lt */
7277 return -KEY_lt;
7278 }
7279
4c3bbe0f
MHM
7280 default:
7281 goto unknown;
7282 }
7283
7284 case 'm':
7285 if (name[1] == 'y')
7286 { /* my */
7287 return KEY_my;
7288 }
7289
7290 goto unknown;
7291
7292 case 'n':
7293 switch (name[1])
7294 {
7295 case 'e':
7296 { /* ne */
7297 return -KEY_ne;
7298 }
7299
4c3bbe0f
MHM
7300 case 'o':
7301 { /* no */
7302 return KEY_no;
7303 }
7304
4c3bbe0f
MHM
7305 default:
7306 goto unknown;
7307 }
7308
7309 case 'o':
7310 if (name[1] == 'r')
7311 { /* or */
7312 return -KEY_or;
7313 }
7314
7315 goto unknown;
7316
7317 case 'q':
7318 switch (name[1])
7319 {
7320 case 'q':
7321 { /* qq */
7322 return KEY_qq;
7323 }
7324
4c3bbe0f
MHM
7325 case 'r':
7326 { /* qr */
7327 return KEY_qr;
7328 }
7329
4c3bbe0f
MHM
7330 case 'w':
7331 { /* qw */
7332 return KEY_qw;
7333 }
7334
4c3bbe0f
MHM
7335 case 'x':
7336 { /* qx */
7337 return KEY_qx;
7338 }
7339
4c3bbe0f
MHM
7340 default:
7341 goto unknown;
7342 }
7343
7344 case 't':
7345 if (name[1] == 'r')
7346 { /* tr */
7347 return KEY_tr;
7348 }
7349
7350 goto unknown;
7351
7352 case 'u':
7353 if (name[1] == 'c')
7354 { /* uc */
7355 return -KEY_uc;
7356 }
7357
7358 goto unknown;
7359
7360 default:
7361 goto unknown;
e2e1dd5a 7362 }
4c3bbe0f 7363
0d863452 7364 case 3: /* 29 tokens of length 3 */
4c3bbe0f 7365 switch (name[0])
e2e1dd5a 7366 {
4c3bbe0f
MHM
7367 case 'E':
7368 if (name[1] == 'N' &&
7369 name[2] == 'D')
7370 { /* END */
7371 return KEY_END;
7372 }
7373
7374 goto unknown;
7375
7376 case 'a':
7377 switch (name[1])
7378 {
7379 case 'b':
7380 if (name[2] == 's')
7381 { /* abs */
7382 return -KEY_abs;
7383 }
7384
7385 goto unknown;
7386
7387 case 'n':
7388 if (name[2] == 'd')
7389 { /* and */
7390 return -KEY_and;
7391 }
7392
7393 goto unknown;
7394
7395 default:
7396 goto unknown;
7397 }
7398
7399 case 'c':
7400 switch (name[1])
7401 {
7402 case 'h':
7403 if (name[2] == 'r')
7404 { /* chr */
7405 return -KEY_chr;
7406 }
7407
7408 goto unknown;
7409
7410 case 'm':
7411 if (name[2] == 'p')
7412 { /* cmp */
7413 return -KEY_cmp;
7414 }
7415
7416 goto unknown;
7417
7418 case 'o':
7419 if (name[2] == 's')
7420 { /* cos */
7421 return -KEY_cos;
7422 }
7423
7424 goto unknown;
7425
7426 default:
7427 goto unknown;
7428 }
7429
7430 case 'd':
7431 if (name[1] == 'i' &&
7432 name[2] == 'e')
7433 { /* die */
7434 return -KEY_die;
7435 }
7436
7437 goto unknown;
7438
7439 case 'e':
7440 switch (name[1])
7441 {
7442 case 'o':
7443 if (name[2] == 'f')
7444 { /* eof */
7445 return -KEY_eof;
7446 }
7447
7448 goto unknown;
7449
4c3bbe0f
MHM
7450 case 'x':
7451 if (name[2] == 'p')
7452 { /* exp */
7453 return -KEY_exp;
7454 }
7455
7456 goto unknown;
7457
7458 default:
7459 goto unknown;
7460 }
7461
7462 case 'f':
7463 if (name[1] == 'o' &&
7464 name[2] == 'r')
7465 { /* for */
7466 return KEY_for;
7467 }
7468
7469 goto unknown;
7470
7471 case 'h':
7472 if (name[1] == 'e' &&
7473 name[2] == 'x')
7474 { /* hex */
7475 return -KEY_hex;
7476 }
7477
7478 goto unknown;
7479
7480 case 'i':
7481 if (name[1] == 'n' &&
7482 name[2] == 't')
7483 { /* int */
7484 return -KEY_int;
7485 }
7486
7487 goto unknown;
7488
7489 case 'l':
7490 if (name[1] == 'o' &&
7491 name[2] == 'g')
7492 { /* log */
7493 return -KEY_log;
7494 }
7495
7496 goto unknown;
7497
7498 case 'm':
7499 if (name[1] == 'a' &&
7500 name[2] == 'p')
7501 { /* map */
7502 return KEY_map;
7503 }
7504
7505 goto unknown;
7506
7507 case 'n':
7508 if (name[1] == 'o' &&
7509 name[2] == 't')
7510 { /* not */
7511 return -KEY_not;
7512 }
7513
7514 goto unknown;
7515
7516 case 'o':
7517 switch (name[1])
7518 {
7519 case 'c':
7520 if (name[2] == 't')
7521 { /* oct */
7522 return -KEY_oct;
7523 }
7524
7525 goto unknown;
7526
7527 case 'r':
7528 if (name[2] == 'd')
7529 { /* ord */
7530 return -KEY_ord;
7531 }
7532
7533 goto unknown;
7534
7535 case 'u':
7536 if (name[2] == 'r')
7537 { /* our */
7538 return KEY_our;
7539 }
7540
7541 goto unknown;
7542
7543 default:
7544 goto unknown;
7545 }
7546
7547 case 'p':
7548 if (name[1] == 'o')
7549 {
7550 switch (name[2])
7551 {
7552 case 'p':
7553 { /* pop */
7554 return -KEY_pop;
7555 }
7556
4c3bbe0f
MHM
7557 case 's':
7558 { /* pos */
7559 return KEY_pos;
7560 }
7561
4c3bbe0f
MHM
7562 default:
7563 goto unknown;
7564 }
7565 }
7566
7567 goto unknown;
7568
7569 case 'r':
7570 if (name[1] == 'e' &&
7571 name[2] == 'f')
7572 { /* ref */
7573 return -KEY_ref;
7574 }
7575
7576 goto unknown;
7577
7578 case 's':
7579 switch (name[1])
7580 {
0d863452
RH
7581 case 'a':
7582 if (name[2] == 'y')
7583 { /* say */
e3e804c9 7584 return (all_keywords || FEATURE_IS_ENABLED("say") ? KEY_say : 0);
0d863452
RH
7585 }
7586
7587 goto unknown;
7588
4c3bbe0f
MHM
7589 case 'i':
7590 if (name[2] == 'n')
7591 { /* sin */
7592 return -KEY_sin;
7593 }
7594
7595 goto unknown;
7596
7597 case 'u':
7598 if (name[2] == 'b')
7599 { /* sub */
7600 return KEY_sub;
7601 }
7602
7603 goto unknown;
7604
7605 default:
7606 goto unknown;
7607 }
7608
7609 case 't':
7610 if (name[1] == 'i' &&
7611 name[2] == 'e')
7612 { /* tie */
7613 return KEY_tie;
7614 }
7615
7616 goto unknown;
7617
7618 case 'u':
7619 if (name[1] == 's' &&
7620 name[2] == 'e')
7621 { /* use */
7622 return KEY_use;
7623 }
7624
7625 goto unknown;
7626
7627 case 'v':
7628 if (name[1] == 'e' &&
7629 name[2] == 'c')
7630 { /* vec */
7631 return -KEY_vec;
7632 }
7633
7634 goto unknown;
7635
7636 case 'x':
7637 if (name[1] == 'o' &&
7638 name[2] == 'r')
7639 { /* xor */
7640 return -KEY_xor;
7641 }
7642
7643 goto unknown;
7644
7645 default:
7646 goto unknown;
e2e1dd5a 7647 }
4c3bbe0f 7648
0d863452 7649 case 4: /* 41 tokens of length 4 */
4c3bbe0f 7650 switch (name[0])
e2e1dd5a 7651 {
4c3bbe0f
MHM
7652 case 'C':
7653 if (name[1] == 'O' &&
7654 name[2] == 'R' &&
7655 name[3] == 'E')
7656 { /* CORE */
7657 return -KEY_CORE;
7658 }
7659
7660 goto unknown;
7661
7662 case 'I':
7663 if (name[1] == 'N' &&
7664 name[2] == 'I' &&
7665 name[3] == 'T')
7666 { /* INIT */
7667 return KEY_INIT;
7668 }
7669
7670 goto unknown;
7671
7672 case 'b':
7673 if (name[1] == 'i' &&
7674 name[2] == 'n' &&
7675 name[3] == 'd')
7676 { /* bind */
7677 return -KEY_bind;
7678 }
7679
7680 goto unknown;
7681
7682 case 'c':
7683 if (name[1] == 'h' &&
7684 name[2] == 'o' &&
7685 name[3] == 'p')
7686 { /* chop */
7687 return -KEY_chop;
7688 }
7689
7690 goto unknown;
7691
7692 case 'd':
7693 if (name[1] == 'u' &&
7694 name[2] == 'm' &&
7695 name[3] == 'p')
7696 { /* dump */
7697 return -KEY_dump;
7698 }
7699
7700 goto unknown;
7701
7702 case 'e':
7703 switch (name[1])
7704 {
7705 case 'a':
7706 if (name[2] == 'c' &&
7707 name[3] == 'h')
7708 { /* each */
7709 return -KEY_each;
7710 }
7711
7712 goto unknown;
7713
7714 case 'l':
7715 if (name[2] == 's' &&
7716 name[3] == 'e')
7717 { /* else */
7718 return KEY_else;
7719 }
7720
7721 goto unknown;
7722
7723 case 'v':
7724 if (name[2] == 'a' &&
7725 name[3] == 'l')
7726 { /* eval */
7727 return KEY_eval;
7728 }
7729
7730 goto unknown;
7731
7732 case 'x':
7733 switch (name[2])
7734 {
7735 case 'e':
7736 if (name[3] == 'c')
7737 { /* exec */
7738 return -KEY_exec;
7739 }
7740
7741 goto unknown;
7742
7743 case 'i':
7744 if (name[3] == 't')
7745 { /* exit */
7746 return -KEY_exit;
7747 }
7748
7749 goto unknown;
7750
7751 default:
7752 goto unknown;
7753 }
7754
7755 default:
7756 goto unknown;
7757 }
7758
7759 case 'f':
7760 if (name[1] == 'o' &&
7761 name[2] == 'r' &&
7762 name[3] == 'k')
7763 { /* fork */
7764 return -KEY_fork;
7765 }
7766
7767 goto unknown;
7768
7769 case 'g':
7770 switch (name[1])
7771 {
7772 case 'e':
7773 if (name[2] == 't' &&
7774 name[3] == 'c')
7775 { /* getc */
7776 return -KEY_getc;
7777 }
7778
7779 goto unknown;
7780
7781 case 'l':
7782 if (name[2] == 'o' &&
7783 name[3] == 'b')
7784 { /* glob */
7785 return KEY_glob;
7786 }
7787
7788 goto unknown;
7789
7790 case 'o':
7791 if (name[2] == 't' &&
7792 name[3] == 'o')
7793 { /* goto */
7794 return KEY_goto;
7795 }
7796
7797 goto unknown;
7798
7799 case 'r':
7800 if (name[2] == 'e' &&
7801 name[3] == 'p')
7802 { /* grep */
7803 return KEY_grep;
7804 }
7805
7806 goto unknown;
7807
7808 default:
7809 goto unknown;
7810 }
7811
7812 case 'j':
7813 if (name[1] == 'o' &&
7814 name[2] == 'i' &&
7815 name[3] == 'n')
7816 { /* join */
7817 return -KEY_join;
7818 }
7819
7820 goto unknown;
7821
7822 case 'k':
7823 switch (name[1])
7824 {
7825 case 'e':
7826 if (name[2] == 'y' &&
7827 name[3] == 's')
7828 { /* keys */
7829 return -KEY_keys;
7830 }
7831
7832 goto unknown;
7833
7834 case 'i':
7835 if (name[2] == 'l' &&
7836 name[3] == 'l')
7837 { /* kill */
7838 return -KEY_kill;
7839 }
7840
7841 goto unknown;
7842
7843 default:
7844 goto unknown;
7845 }
7846
7847 case 'l':
7848 switch (name[1])
7849 {
7850 case 'a':
7851 if (name[2] == 's' &&
7852 name[3] == 't')
7853 { /* last */
7854 return KEY_last;
7855 }
7856
7857 goto unknown;
7858
7859 case 'i':
7860 if (name[2] == 'n' &&
7861 name[3] == 'k')
7862 { /* link */
7863 return -KEY_link;
7864 }
7865
7866 goto unknown;
7867
7868 case 'o':
7869 if (name[2] == 'c' &&
7870 name[3] == 'k')
7871 { /* lock */
7872 return -KEY_lock;
7873 }
7874
7875 goto unknown;
7876
7877 default:
7878 goto unknown;
7879 }
7880
7881 case 'n':
7882 if (name[1] == 'e' &&
7883 name[2] == 'x' &&
7884 name[3] == 't')
7885 { /* next */
7886 return KEY_next;
7887 }
7888
7889 goto unknown;
7890
7891 case 'o':
7892 if (name[1] == 'p' &&
7893 name[2] == 'e' &&
7894 name[3] == 'n')
7895 { /* open */
7896 return -KEY_open;
7897 }
7898
7899 goto unknown;
7900
7901 case 'p':
7902 switch (name[1])
7903 {
7904 case 'a':
7905 if (name[2] == 'c' &&
7906 name[3] == 'k')
7907 { /* pack */
7908 return -KEY_pack;
7909 }
7910
7911 goto unknown;
7912
7913 case 'i':
7914 if (name[2] == 'p' &&
7915 name[3] == 'e')
7916 { /* pipe */
7917 return -KEY_pipe;
7918 }
7919
7920 goto unknown;
7921
7922 case 'u':
7923 if (name[2] == 's' &&
7924 name[3] == 'h')
7925 { /* push */
7926 return -KEY_push;
7927 }
7928
7929 goto unknown;
7930
7931 default:
7932 goto unknown;
7933 }
7934
7935 case 'r':
7936 switch (name[1])
7937 {
7938 case 'a':
7939 if (name[2] == 'n' &&
7940 name[3] == 'd')
7941 { /* rand */
7942 return -KEY_rand;
7943 }
7944
7945 goto unknown;
7946
7947 case 'e':
7948 switch (name[2])
7949 {
7950 case 'a':
7951 if (name[3] == 'd')
7952 { /* read */
7953 return -KEY_read;
7954 }
7955
7956 goto unknown;
7957
7958 case 'c':
7959 if (name[3] == 'v')
7960 { /* recv */
7961 return -KEY_recv;
7962 }
7963
7964 goto unknown;
7965
7966 case 'd':
7967 if (name[3] == 'o')
7968 { /* redo */
7969 return KEY_redo;
7970 }
7971
7972 goto unknown;
7973
7974 default:
7975 goto unknown;
7976 }
7977
7978 default:
7979 goto unknown;
7980 }
7981
7982 case 's':
7983 switch (name[1])
7984 {
7985 case 'e':
7986 switch (name[2])
7987 {
7988 case 'e':
7989 if (name[3] == 'k')
7990 { /* seek */
7991 return -KEY_seek;
7992 }
7993
7994 goto unknown;
7995
7996 case 'n':
7997 if (name[3] == 'd')
7998 { /* send */
7999 return -KEY_send;
8000 }
8001
8002 goto unknown;
8003
8004 default:
8005 goto unknown;
8006 }
8007
8008 case 'o':
8009 if (name[2] == 'r' &&
8010 name[3] == 't')
8011 { /* sort */
8012 return KEY_sort;
8013 }
8014
8015 goto unknown;
8016
8017 case 'q':
8018 if (name[2] == 'r' &&
8019 name[3] == 't')
8020 { /* sqrt */
8021 return -KEY_sqrt;
8022 }
8023
8024 goto unknown;
8025
8026 case 't':
8027 if (name[2] == 'a' &&
8028 name[3] == 't')
8029 { /* stat */
8030 return -KEY_stat;
8031 }
8032
8033 goto unknown;
8034
8035 default:
8036 goto unknown;
8037 }
8038
8039 case 't':
8040 switch (name[1])
8041 {
8042 case 'e':
8043 if (name[2] == 'l' &&
8044 name[3] == 'l')
8045 { /* tell */
8046 return -KEY_tell;
8047 }
8048
8049 goto unknown;
8050
8051 case 'i':
8052 switch (name[2])
8053 {
8054 case 'e':
8055 if (name[3] == 'd')
8056 { /* tied */
8057 return KEY_tied;
8058 }
8059
8060 goto unknown;
8061
8062 case 'm':
8063 if (name[3] == 'e')
8064 { /* time */
8065 return -KEY_time;
8066 }
8067
8068 goto unknown;
8069
8070 default:
8071 goto unknown;
8072 }
8073
8074 default:
8075 goto unknown;
8076 }
8077
8078 case 'w':
0d863452 8079 switch (name[1])
4c3bbe0f 8080 {
0d863452 8081 case 'a':
952306ac
RGS
8082 switch (name[2])
8083 {
8084 case 'i':
8085 if (name[3] == 't')
8086 { /* wait */
8087 return -KEY_wait;
8088 }
4c3bbe0f 8089
952306ac 8090 goto unknown;
4c3bbe0f 8091
952306ac
RGS
8092 case 'r':
8093 if (name[3] == 'n')
8094 { /* warn */
8095 return -KEY_warn;
8096 }
4c3bbe0f 8097
952306ac 8098 goto unknown;
4c3bbe0f 8099
952306ac
RGS
8100 default:
8101 goto unknown;
8102 }
0d863452
RH
8103
8104 case 'h':
8105 if (name[2] == 'e' &&
8106 name[3] == 'n')
8107 { /* when */
5458a98a 8108 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
952306ac 8109 }
4c3bbe0f 8110
952306ac 8111 goto unknown;
4c3bbe0f 8112
952306ac
RGS
8113 default:
8114 goto unknown;
8115 }
4c3bbe0f 8116
0d863452
RH
8117 default:
8118 goto unknown;
8119 }
8120
952306ac 8121 case 5: /* 39 tokens of length 5 */
4c3bbe0f 8122 switch (name[0])
e2e1dd5a 8123 {
4c3bbe0f
MHM
8124 case 'B':
8125 if (name[1] == 'E' &&
8126 name[2] == 'G' &&
8127 name[3] == 'I' &&
8128 name[4] == 'N')
8129 { /* BEGIN */
8130 return KEY_BEGIN;
8131 }
8132
8133 goto unknown;
8134
8135 case 'C':
8136 if (name[1] == 'H' &&
8137 name[2] == 'E' &&
8138 name[3] == 'C' &&
8139 name[4] == 'K')
8140 { /* CHECK */
8141 return KEY_CHECK;
8142 }
8143
8144 goto unknown;
8145
8146 case 'a':
8147 switch (name[1])
8148 {
8149 case 'l':
8150 if (name[2] == 'a' &&
8151 name[3] == 'r' &&
8152 name[4] == 'm')
8153 { /* alarm */
8154 return -KEY_alarm;
8155 }
8156
8157 goto unknown;
8158
8159 case 't':
8160 if (name[2] == 'a' &&
8161 name[3] == 'n' &&
8162 name[4] == '2')
8163 { /* atan2 */
8164 return -KEY_atan2;
8165 }
8166
8167 goto unknown;
8168
8169 default:
8170 goto unknown;
8171 }
8172
8173 case 'b':
0d863452
RH
8174 switch (name[1])
8175 {
8176 case 'l':
8177 if (name[2] == 'e' &&
952306ac
RGS
8178 name[3] == 's' &&
8179 name[4] == 's')
8180 { /* bless */
8181 return -KEY_bless;
8182 }
4c3bbe0f 8183
952306ac 8184 goto unknown;
4c3bbe0f 8185
0d863452
RH
8186 case 'r':
8187 if (name[2] == 'e' &&
8188 name[3] == 'a' &&
8189 name[4] == 'k')
8190 { /* break */
5458a98a 8191 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
0d863452
RH
8192 }
8193
8194 goto unknown;
8195
8196 default:
8197 goto unknown;
8198 }
8199
4c3bbe0f
MHM
8200 case 'c':
8201 switch (name[1])
8202 {
8203 case 'h':
8204 switch (name[2])
8205 {
8206 case 'd':
8207 if (name[3] == 'i' &&
8208 name[4] == 'r')
8209 { /* chdir */
8210 return -KEY_chdir;
8211 }
8212
8213 goto unknown;
8214
8215 case 'm':
8216 if (name[3] == 'o' &&
8217 name[4] == 'd')
8218 { /* chmod */
8219 return -KEY_chmod;
8220 }
8221
8222 goto unknown;
8223
8224 case 'o':
8225 switch (name[3])
8226 {
8227 case 'm':
8228 if (name[4] == 'p')
8229 { /* chomp */
8230 return -KEY_chomp;
8231 }
8232
8233 goto unknown;
8234
8235 case 'w':
8236 if (name[4] == 'n')
8237 { /* chown */
8238 return -KEY_chown;
8239 }
8240
8241 goto unknown;
8242
8243 default:
8244 goto unknown;
8245 }
8246
8247 default:
8248 goto unknown;
8249 }
8250
8251 case 'l':
8252 if (name[2] == 'o' &&
8253 name[3] == 's' &&
8254 name[4] == 'e')
8255 { /* close */
8256 return -KEY_close;
8257 }
8258
8259 goto unknown;
8260
8261 case 'r':
8262 if (name[2] == 'y' &&
8263 name[3] == 'p' &&
8264 name[4] == 't')
8265 { /* crypt */
8266 return -KEY_crypt;
8267 }
8268
8269 goto unknown;
8270
8271 default:
8272 goto unknown;
8273 }
8274
8275 case 'e':
8276 if (name[1] == 'l' &&
8277 name[2] == 's' &&
8278 name[3] == 'i' &&
8279 name[4] == 'f')
8280 { /* elsif */
8281 return KEY_elsif;
8282 }
8283
8284 goto unknown;
8285
8286 case 'f':
8287 switch (name[1])
8288 {
8289 case 'c':
8290 if (name[2] == 'n' &&
8291 name[3] == 't' &&
8292 name[4] == 'l')
8293 { /* fcntl */
8294 return -KEY_fcntl;
8295 }
8296
8297 goto unknown;
8298
8299 case 'l':
8300 if (name[2] == 'o' &&
8301 name[3] == 'c' &&
8302 name[4] == 'k')
8303 { /* flock */
8304 return -KEY_flock;
8305 }
8306
8307 goto unknown;
8308
8309 default:
8310 goto unknown;
8311 }
8312
0d863452
RH
8313 case 'g':
8314 if (name[1] == 'i' &&
8315 name[2] == 'v' &&
8316 name[3] == 'e' &&
8317 name[4] == 'n')
8318 { /* given */
5458a98a 8319 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
0d863452
RH
8320 }
8321
8322 goto unknown;
8323
4c3bbe0f
MHM
8324 case 'i':
8325 switch (name[1])
8326 {
8327 case 'n':
8328 if (name[2] == 'd' &&
8329 name[3] == 'e' &&
8330 name[4] == 'x')
8331 { /* index */
8332 return -KEY_index;
8333 }
8334
8335 goto unknown;
8336
8337 case 'o':
8338 if (name[2] == 'c' &&
8339 name[3] == 't' &&
8340 name[4] == 'l')
8341 { /* ioctl */
8342 return -KEY_ioctl;
8343 }
8344
8345 goto unknown;
8346
8347 default:
8348 goto unknown;
8349 }
8350
8351 case 'l':
8352 switch (name[1])
8353 {
8354 case 'o':
8355 if (name[2] == 'c' &&
8356 name[3] == 'a' &&
8357 name[4] == 'l')
8358 { /* local */
8359 return KEY_local;
8360 }
8361
8362 goto unknown;
8363
8364 case 's':
8365 if (name[2] == 't' &&
8366 name[3] == 'a' &&
8367 name[4] == 't')
8368 { /* lstat */
8369 return -KEY_lstat;
8370 }
8371
8372 goto unknown;
8373
8374 default:
8375 goto unknown;
8376 }
8377
8378 case 'm':
8379 if (name[1] == 'k' &&
8380 name[2] == 'd' &&
8381 name[3] == 'i' &&
8382 name[4] == 'r')
8383 { /* mkdir */
8384 return -KEY_mkdir;
8385 }
8386
8387 goto unknown;
8388
8389 case 'p':
8390 if (name[1] == 'r' &&
8391 name[2] == 'i' &&
8392 name[3] == 'n' &&
8393 name[4] == 't')
8394 { /* print */
8395 return KEY_print;
8396 }
8397
8398 goto unknown;
8399
8400 case 'r':
8401 switch (name[1])
8402 {
8403 case 'e':
8404 if (name[2] == 's' &&
8405 name[3] == 'e' &&
8406 name[4] == 't')
8407 { /* reset */
8408 return -KEY_reset;
8409 }
8410
8411 goto unknown;
8412
8413 case 'm':
8414 if (name[2] == 'd' &&
8415 name[3] == 'i' &&
8416 name[4] == 'r')
8417 { /* rmdir */
8418 return -KEY_rmdir;
8419 }
8420
8421 goto unknown;
8422
8423 default:
8424 goto unknown;
8425 }
8426
8427 case 's':
8428 switch (name[1])
8429 {
8430 case 'e':
8431 if (name[2] == 'm' &&
8432 name[3] == 'o' &&
8433 name[4] == 'p')
8434 { /* semop */
8435 return -KEY_semop;
8436 }
8437
8438 goto unknown;
8439
8440 case 'h':
8441 if (name[2] == 'i' &&
8442 name[3] == 'f' &&
8443 name[4] == 't')
8444 { /* shift */
8445 return -KEY_shift;
8446 }
8447
8448 goto unknown;
8449
8450 case 'l':
8451 if (name[2] == 'e' &&
8452 name[3] == 'e' &&
8453 name[4] == 'p')
8454 { /* sleep */
8455 return -KEY_sleep;
8456 }
8457
8458 goto unknown;
8459
8460 case 'p':
8461 if (name[2] == 'l' &&
8462 name[3] == 'i' &&
8463 name[4] == 't')
8464 { /* split */
8465 return KEY_split;
8466 }
8467
8468 goto unknown;
8469
8470 case 'r':
8471 if (name[2] == 'a' &&
8472 name[3] == 'n' &&
8473 name[4] == 'd')
8474 { /* srand */
8475 return -KEY_srand;
8476 }
8477
8478 goto unknown;
8479
8480 case 't':
952306ac
RGS
8481 switch (name[2])
8482 {
8483 case 'a':
8484 if (name[3] == 't' &&
8485 name[4] == 'e')
8486 { /* state */
5458a98a 8487 return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
952306ac 8488 }
4c3bbe0f 8489
952306ac
RGS
8490 goto unknown;
8491
8492 case 'u':
8493 if (name[3] == 'd' &&
8494 name[4] == 'y')
8495 { /* study */
8496 return KEY_study;
8497 }
8498
8499 goto unknown;
8500
8501 default:
8502 goto unknown;
8503 }
4c3bbe0f
MHM
8504
8505 default:
8506 goto unknown;
8507 }
8508
8509 case 't':
8510 if (name[1] == 'i' &&
8511 name[2] == 'm' &&
8512 name[3] == 'e' &&
8513 name[4] == 's')
8514 { /* times */
8515 return -KEY_times;
8516 }
8517
8518 goto unknown;
8519
8520 case 'u':
8521 switch (name[1])
8522 {
8523 case 'm':
8524 if (name[2] == 'a' &&
8525 name[3] == 's' &&
8526 name[4] == 'k')
8527 { /* umask */
8528 return -KEY_umask;
8529 }
8530
8531 goto unknown;
8532
8533 case 'n':
8534 switch (name[2])
8535 {
8536 case 'd':
8537 if (name[3] == 'e' &&
8538 name[4] == 'f')
8539 { /* undef */
8540 return KEY_undef;
8541 }
8542
8543 goto unknown;
8544
8545 case 't':
8546 if (name[3] == 'i')
8547 {
8548 switch (name[4])
8549 {
8550 case 'e':
8551 { /* untie */
8552 return KEY_untie;
8553 }
8554
4c3bbe0f
MHM
8555 case 'l':
8556 { /* until */
8557 return KEY_until;
8558 }
8559
4c3bbe0f
MHM
8560 default:
8561 goto unknown;
8562 }
8563 }
8564
8565 goto unknown;
8566
8567 default:
8568 goto unknown;
8569 }
8570
8571 case 't':
8572 if (name[2] == 'i' &&
8573 name[3] == 'm' &&
8574 name[4] == 'e')
8575 { /* utime */
8576 return -KEY_utime;
8577 }
8578
8579 goto unknown;
8580
8581 default:
8582 goto unknown;
8583 }
8584
8585 case 'w':
8586 switch (name[1])
8587 {
8588 case 'h':
8589 if (name[2] == 'i' &&
8590 name[3] == 'l' &&
8591 name[4] == 'e')
8592 { /* while */
8593 return KEY_while;
8594 }
8595
8596 goto unknown;
8597
8598 case 'r':
8599 if (name[2] == 'i' &&
8600 name[3] == 't' &&
8601 name[4] == 'e')
8602 { /* write */
8603 return -KEY_write;
8604 }
8605
8606 goto unknown;
8607
8608 default:
8609 goto unknown;
8610 }
8611
8612 default:
8613 goto unknown;
e2e1dd5a 8614 }
4c3bbe0f
MHM
8615
8616 case 6: /* 33 tokens of length 6 */
8617 switch (name[0])
8618 {
8619 case 'a':
8620 if (name[1] == 'c' &&
8621 name[2] == 'c' &&
8622 name[3] == 'e' &&
8623 name[4] == 'p' &&
8624 name[5] == 't')
8625 { /* accept */
8626 return -KEY_accept;
8627 }
8628
8629 goto unknown;
8630
8631 case 'c':
8632 switch (name[1])
8633 {
8634 case 'a':
8635 if (name[2] == 'l' &&
8636 name[3] == 'l' &&
8637 name[4] == 'e' &&
8638 name[5] == 'r')
8639 { /* caller */
8640 return -KEY_caller;
8641 }
8642
8643 goto unknown;
8644
8645 case 'h':
8646 if (name[2] == 'r' &&
8647 name[3] == 'o' &&
8648 name[4] == 'o' &&
8649 name[5] == 't')
8650 { /* chroot */
8651 return -KEY_chroot;
8652 }
8653
8654 goto unknown;
8655
8656 default:
8657 goto unknown;
8658 }
8659
8660 case 'd':
8661 if (name[1] == 'e' &&
8662 name[2] == 'l' &&
8663 name[3] == 'e' &&
8664 name[4] == 't' &&
8665 name[5] == 'e')
8666 { /* delete */
8667 return KEY_delete;
8668 }
8669
8670 goto unknown;
8671
8672 case 'e':
8673 switch (name[1])
8674 {
8675 case 'l':
8676 if (name[2] == 's' &&
8677 name[3] == 'e' &&
8678 name[4] == 'i' &&
8679 name[5] == 'f')
8680 { /* elseif */
8681 if(ckWARN_d(WARN_SYNTAX))
8682 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8683 }
8684
8685 goto unknown;
8686
8687 case 'x':
8688 if (name[2] == 'i' &&
8689 name[3] == 's' &&
8690 name[4] == 't' &&
8691 name[5] == 's')
8692 { /* exists */
8693 return KEY_exists;
8694 }
8695
8696 goto unknown;
8697
8698 default:
8699 goto unknown;
8700 }
8701
8702 case 'f':
8703 switch (name[1])
8704 {
8705 case 'i':
8706 if (name[2] == 'l' &&
8707 name[3] == 'e' &&
8708 name[4] == 'n' &&
8709 name[5] == 'o')
8710 { /* fileno */
8711 return -KEY_fileno;
8712 }
8713
8714 goto unknown;
8715
8716 case 'o':
8717 if (name[2] == 'r' &&
8718 name[3] == 'm' &&
8719 name[4] == 'a' &&
8720 name[5] == 't')
8721 { /* format */
8722 return KEY_format;
8723 }
8724
8725 goto unknown;
8726
8727 default:
8728 goto unknown;
8729 }
8730
8731 case 'g':
8732 if (name[1] == 'm' &&
8733 name[2] == 't' &&
8734 name[3] == 'i' &&
8735 name[4] == 'm' &&
8736 name[5] == 'e')
8737 { /* gmtime */
8738 return -KEY_gmtime;
8739 }
8740
8741 goto unknown;
8742
8743 case 'l':
8744 switch (name[1])
8745 {
8746 case 'e':
8747 if (name[2] == 'n' &&
8748 name[3] == 'g' &&
8749 name[4] == 't' &&
8750 name[5] == 'h')
8751 { /* length */
8752 return -KEY_length;
8753 }
8754
8755 goto unknown;
8756
8757 case 'i':
8758 if (name[2] == 's' &&
8759 name[3] == 't' &&
8760 name[4] == 'e' &&
8761 name[5] == 'n')
8762 { /* listen */
8763 return -KEY_listen;
8764 }
8765
8766 goto unknown;
8767
8768 default:
8769 goto unknown;
8770 }
8771
8772 case 'm':
8773 if (name[1] == 's' &&
8774 name[2] == 'g')
8775 {
8776 switch (name[3])
8777 {
8778 case 'c':
8779 if (name[4] == 't' &&
8780 name[5] == 'l')
8781 { /* msgctl */
8782 return -KEY_msgctl;
8783 }
8784
8785 goto unknown;
8786
8787 case 'g':
8788 if (name[4] == 'e' &&
8789 name[5] == 't')
8790 { /* msgget */
8791 return -KEY_msgget;
8792 }
8793
8794 goto unknown;
8795
8796 case 'r':
8797 if (name[4] == 'c' &&
8798 name[5] == 'v')
8799 { /* msgrcv */
8800 return -KEY_msgrcv;
8801 }
8802
8803 goto unknown;
8804
8805 case 's':
8806 if (name[4] == 'n' &&
8807 name[5] == 'd')
8808 { /* msgsnd */
8809 return -KEY_msgsnd;
8810 }
8811
8812 goto unknown;
8813
8814 default:
8815 goto unknown;
8816 }
8817 }
8818
8819 goto unknown;
8820
8821 case 'p':
8822 if (name[1] == 'r' &&
8823 name[2] == 'i' &&
8824 name[3] == 'n' &&
8825 name[4] == 't' &&
8826 name[5] == 'f')
8827 { /* printf */
8828 return KEY_printf;
8829 }
8830
8831 goto unknown;
8832
8833 case 'r':
8834 switch (name[1])
8835 {
8836 case 'e':
8837 switch (name[2])
8838 {
8839 case 'n':
8840 if (name[3] == 'a' &&
8841 name[4] == 'm' &&
8842 name[5] == 'e')
8843 { /* rename */
8844 return -KEY_rename;
8845 }
8846
8847 goto unknown;
8848
8849 case 't':
8850 if (name[3] == 'u' &&
8851 name[4] == 'r' &&
8852 name[5] == 'n')
8853 { /* return */
8854 return KEY_return;
8855 }
8856
8857 goto unknown;
8858
8859 default:
8860 goto unknown;
8861 }
8862
8863 case 'i':
8864 if (name[2] == 'n' &&
8865 name[3] == 'd' &&
8866 name[4] == 'e' &&
8867 name[5] == 'x')
8868 { /* rindex */
8869 return -KEY_rindex;
8870 }
8871
8872 goto unknown;
8873
8874 default:
8875 goto unknown;
8876 }
8877
8878 case 's':
8879 switch (name[1])
8880 {
8881 case 'c':
8882 if (name[2] == 'a' &&
8883 name[3] == 'l' &&
8884 name[4] == 'a' &&
8885 name[5] == 'r')
8886 { /* scalar */
8887 return KEY_scalar;
8888 }
8889
8890 goto unknown;
8891
8892 case 'e':
8893 switch (name[2])
8894 {
8895 case 'l':
8896 if (name[3] == 'e' &&
8897 name[4] == 'c' &&
8898 name[5] == 't')
8899 { /* select */
8900 return -KEY_select;
8901 }
8902
8903 goto unknown;
8904
8905 case 'm':
8906 switch (name[3])
8907 {
8908 case 'c':
8909 if (name[4] == 't' &&
8910 name[5] == 'l')
8911 { /* semctl */
8912 return -KEY_semctl;
8913 }
8914
8915 goto unknown;
8916
8917 case 'g':
8918 if (name[4] == 'e' &&
8919 name[5] == 't')
8920 { /* semget */
8921 return -KEY_semget;
8922 }
8923
8924 goto unknown;
8925
8926 default:
8927 goto unknown;
8928 }
8929
8930 default:
8931 goto unknown;
8932 }
8933
8934 case 'h':
8935 if (name[2] == 'm')
8936 {
8937 switch (name[3])
8938 {
8939 case 'c':
8940 if (name[4] == 't' &&
8941 name[5] == 'l')
8942 { /* shmctl */
8943 return -KEY_shmctl;
8944 }
8945
8946 goto unknown;
8947
8948 case 'g':
8949 if (name[4] == 'e' &&
8950 name[5] == 't')
8951 { /* shmget */
8952 return -KEY_shmget;
8953 }
8954
8955 goto unknown;
8956
8957 default:
8958 goto unknown;
8959 }
8960 }
8961
8962 goto unknown;
8963
8964 case 'o':
8965 if (name[2] == 'c' &&
8966 name[3] == 'k' &&
8967 name[4] == 'e' &&
8968 name[5] == 't')
8969 { /* socket */
8970 return -KEY_socket;
8971 }
8972
8973 goto unknown;
8974
8975 case 'p':
8976 if (name[2] == 'l' &&
8977 name[3] == 'i' &&
8978 name[4] == 'c' &&
8979 name[5] == 'e')
8980 { /* splice */
8981 return -KEY_splice;
8982 }
8983
8984 goto unknown;
8985
8986 case 'u':
8987 if (name[2] == 'b' &&
8988 name[3] == 's' &&
8989 name[4] == 't' &&
8990 name[5] == 'r')
8991 { /* substr */
8992 return -KEY_substr;
8993 }
8994
8995 goto unknown;
8996
8997 case 'y':
8998 if (name[2] == 's' &&
8999 name[3] == 't' &&
9000 name[4] == 'e' &&
9001 name[5] == 'm')
9002 { /* system */
9003 return -KEY_system;
9004 }
9005
9006 goto unknown;
9007
9008 default:
9009 goto unknown;
9010 }
9011
9012 case 'u':
9013 if (name[1] == 'n')
9014 {
9015 switch (name[2])
9016 {
9017 case 'l':
9018 switch (name[3])
9019 {
9020 case 'e':
9021 if (name[4] == 's' &&
9022 name[5] == 's')
9023 { /* unless */
9024 return KEY_unless;
9025 }
9026
9027 goto unknown;
9028
9029 case 'i':
9030 if (name[4] == 'n' &&
9031 name[5] == 'k')
9032 { /* unlink */
9033 return -KEY_unlink;
9034 }
9035
9036 goto unknown;
9037
9038 default:
9039 goto unknown;
9040 }
9041
9042 case 'p':
9043 if (name[3] == 'a' &&
9044 name[4] == 'c' &&
9045 name[5] == 'k')
9046 { /* unpack */
9047 return -KEY_unpack;
9048 }
9049
9050 goto unknown;
9051
9052 default:
9053 goto unknown;
9054 }
9055 }
9056
9057 goto unknown;
9058
9059 case 'v':
9060 if (name[1] == 'a' &&
9061 name[2] == 'l' &&
9062 name[3] == 'u' &&
9063 name[4] == 'e' &&
9064 name[5] == 's')
9065 { /* values */
9066 return -KEY_values;
9067 }
9068
9069 goto unknown;
9070
9071 default:
9072 goto unknown;
e2e1dd5a 9073 }
4c3bbe0f 9074
0d863452 9075 case 7: /* 29 tokens of length 7 */
4c3bbe0f
MHM
9076 switch (name[0])
9077 {
9078 case 'D':
9079 if (name[1] == 'E' &&
9080 name[2] == 'S' &&
9081 name[3] == 'T' &&
9082 name[4] == 'R' &&
9083 name[5] == 'O' &&
9084 name[6] == 'Y')
9085 { /* DESTROY */
9086 return KEY_DESTROY;
9087 }
9088
9089 goto unknown;
9090
9091 case '_':
9092 if (name[1] == '_' &&
9093 name[2] == 'E' &&
9094 name[3] == 'N' &&
9095 name[4] == 'D' &&
9096 name[5] == '_' &&
9097 name[6] == '_')
9098 { /* __END__ */
9099 return KEY___END__;
9100 }
9101
9102 goto unknown;
9103
9104 case 'b':
9105 if (name[1] == 'i' &&
9106 name[2] == 'n' &&
9107 name[3] == 'm' &&
9108 name[4] == 'o' &&
9109 name[5] == 'd' &&
9110 name[6] == 'e')
9111 { /* binmode */
9112 return -KEY_binmode;
9113 }
9114
9115 goto unknown;
9116
9117 case 'c':
9118 if (name[1] == 'o' &&
9119 name[2] == 'n' &&
9120 name[3] == 'n' &&
9121 name[4] == 'e' &&
9122 name[5] == 'c' &&
9123 name[6] == 't')
9124 { /* connect */
9125 return -KEY_connect;
9126 }
9127
9128 goto unknown;
9129
9130 case 'd':
9131 switch (name[1])
9132 {
9133 case 'b':
9134 if (name[2] == 'm' &&
9135 name[3] == 'o' &&
9136 name[4] == 'p' &&
9137 name[5] == 'e' &&
9138 name[6] == 'n')
9139 { /* dbmopen */
9140 return -KEY_dbmopen;
9141 }
9142
9143 goto unknown;
9144
9145 case 'e':
0d863452
RH
9146 if (name[2] == 'f')
9147 {
9148 switch (name[3])
9149 {
9150 case 'a':
9151 if (name[4] == 'u' &&
9152 name[5] == 'l' &&
9153 name[6] == 't')
9154 { /* default */
5458a98a 9155 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
0d863452
RH
9156 }
9157
9158 goto unknown;
9159
9160 case 'i':
9161 if (name[4] == 'n' &&
952306ac
RGS
9162 name[5] == 'e' &&
9163 name[6] == 'd')
9164 { /* defined */
9165 return KEY_defined;
9166 }
4c3bbe0f 9167
952306ac 9168 goto unknown;
4c3bbe0f 9169
952306ac
RGS
9170 default:
9171 goto unknown;
9172 }
0d863452
RH
9173 }
9174
9175 goto unknown;
9176
9177 default:
9178 goto unknown;
9179 }
4c3bbe0f
MHM
9180
9181 case 'f':
9182 if (name[1] == 'o' &&
9183 name[2] == 'r' &&
9184 name[3] == 'e' &&
9185 name[4] == 'a' &&
9186 name[5] == 'c' &&
9187 name[6] == 'h')
9188 { /* foreach */
9189 return KEY_foreach;
9190 }
9191
9192 goto unknown;
9193
9194 case 'g':
9195 if (name[1] == 'e' &&
9196 name[2] == 't' &&
9197 name[3] == 'p')
9198 {
9199 switch (name[4])
9200 {
9201 case 'g':
9202 if (name[5] == 'r' &&
9203 name[6] == 'p')
9204 { /* getpgrp */
9205 return -KEY_getpgrp;
9206 }
9207
9208 goto unknown;
9209
9210 case 'p':
9211 if (name[5] == 'i' &&
9212 name[6] == 'd')
9213 { /* getppid */
9214 return -KEY_getppid;
9215 }
9216
9217 goto unknown;
9218
9219 default:
9220 goto unknown;
9221 }
9222 }
9223
9224 goto unknown;
9225
9226 case 'l':
9227 if (name[1] == 'c' &&
9228 name[2] == 'f' &&
9229 name[3] == 'i' &&
9230 name[4] == 'r' &&
9231 name[5] == 's' &&
9232 name[6] == 't')
9233 { /* lcfirst */
9234 return -KEY_lcfirst;
9235 }
9236
9237 goto unknown;
9238
9239 case 'o':
9240 if (name[1] == 'p' &&
9241 name[2] == 'e' &&
9242 name[3] == 'n' &&
9243 name[4] == 'd' &&
9244 name[5] == 'i' &&
9245 name[6] == 'r')
9246 { /* opendir */
9247 return -KEY_opendir;
9248 }
9249
9250 goto unknown;
9251
9252 case 'p':
9253 if (name[1] == 'a' &&
9254 name[2] == 'c' &&
9255 name[3] == 'k' &&
9256 name[4] == 'a' &&
9257 name[5] == 'g' &&
9258 name[6] == 'e')
9259 { /* package */
9260 return KEY_package;
9261 }
9262
9263 goto unknown;
9264
9265 case 'r':
9266 if (name[1] == 'e')
9267 {
9268 switch (name[2])
9269 {
9270 case 'a':
9271 if (name[3] == 'd' &&
9272 name[4] == 'd' &&
9273 name[5] == 'i' &&
9274 name[6] == 'r')
9275 { /* readdir */
9276 return -KEY_readdir;
9277 }
9278
9279 goto unknown;
9280
9281 case 'q':
9282 if (name[3] == 'u' &&
9283 name[4] == 'i' &&
9284 name[5] == 'r' &&
9285 name[6] == 'e')
9286 { /* require */
9287 return KEY_require;
9288 }
9289
9290 goto unknown;
9291
9292 case 'v':
9293 if (name[3] == 'e' &&
9294 name[4] == 'r' &&
9295 name[5] == 's' &&
9296 name[6] == 'e')
9297 { /* reverse */
9298 return -KEY_reverse;
9299 }
9300
9301 goto unknown;
9302
9303 default:
9304 goto unknown;
9305 }
9306 }
9307
9308 goto unknown;
9309
9310 case 's':
9311 switch (name[1])
9312 {
9313 case 'e':
9314 switch (name[2])
9315 {
9316 case 'e':
9317 if (name[3] == 'k' &&
9318 name[4] == 'd' &&
9319 name[5] == 'i' &&
9320 name[6] == 'r')
9321 { /* seekdir */
9322 return -KEY_seekdir;
9323 }
9324
9325 goto unknown;
9326
9327 case 't':
9328 if (name[3] == 'p' &&
9329 name[4] == 'g' &&
9330 name[5] == 'r' &&
9331 name[6] == 'p')
9332 { /* setpgrp */
9333 return -KEY_setpgrp;
9334 }
9335
9336 goto unknown;
9337
9338 default:
9339 goto unknown;
9340 }
9341
9342 case 'h':
9343 if (name[2] == 'm' &&
9344 name[3] == 'r' &&
9345 name[4] == 'e' &&
9346 name[5] == 'a' &&
9347 name[6] == 'd')
9348 { /* shmread */
9349 return -KEY_shmread;
9350 }
9351
9352 goto unknown;
9353
9354 case 'p':
9355 if (name[2] == 'r' &&
9356 name[3] == 'i' &&
9357 name[4] == 'n' &&
9358 name[5] == 't' &&
9359 name[6] == 'f')
9360 { /* sprintf */
9361 return -KEY_sprintf;
9362 }
9363
9364 goto unknown;
9365
9366 case 'y':
9367 switch (name[2])
9368 {
9369 case 'm':
9370 if (name[3] == 'l' &&
9371 name[4] == 'i' &&
9372 name[5] == 'n' &&
9373 name[6] == 'k')
9374 { /* symlink */
9375 return -KEY_symlink;
9376 }
9377
9378 goto unknown;
9379
9380 case 's':
9381 switch (name[3])
9382 {
9383 case 'c':
9384 if (name[4] == 'a' &&
9385 name[5] == 'l' &&
9386 name[6] == 'l')
9387 { /* syscall */
9388 return -KEY_syscall;
9389 }
9390
9391 goto unknown;
9392
9393 case 'o':
9394 if (name[4] == 'p' &&
9395 name[5] == 'e' &&
9396 name[6] == 'n')
9397 { /* sysopen */
9398 return -KEY_sysopen;
9399 }
9400
9401 goto unknown;
9402
9403 case 'r':
9404 if (name[4] == 'e' &&
9405 name[5] == 'a' &&
9406 name[6] == 'd')
9407 { /* sysread */
9408 return -KEY_sysread;
9409 }
9410
9411 goto unknown;
9412
9413 case 's':
9414 if (name[4] == 'e' &&
9415 name[5] == 'e' &&
9416 name[6] == 'k')
9417 { /* sysseek */
9418 return -KEY_sysseek;
9419 }
9420
9421 goto unknown;
9422
9423 default:
9424 goto unknown;
9425 }
9426
9427 default:
9428 goto unknown;
9429 }
9430
9431 default:
9432 goto unknown;
9433 }
9434
9435 case 't':
9436 if (name[1] == 'e' &&
9437 name[2] == 'l' &&
9438 name[3] == 'l' &&
9439 name[4] == 'd' &&
9440 name[5] == 'i' &&
9441 name[6] == 'r')
9442 { /* telldir */
9443 return -KEY_telldir;
9444 }
9445
9446 goto unknown;
9447
9448 case 'u':
9449 switch (name[1])
9450 {
9451 case 'c':
9452 if (name[2] == 'f' &&
9453 name[3] == 'i' &&
9454 name[4] == 'r' &&
9455 name[5] == 's' &&
9456 name[6] == 't')
9457 { /* ucfirst */
9458 return -KEY_ucfirst;
9459 }
9460
9461 goto unknown;
9462
9463 case 'n':
9464 if (name[2] == 's' &&
9465 name[3] == 'h' &&
9466 name[4] == 'i' &&
9467 name[5] == 'f' &&
9468 name[6] == 't')
9469 { /* unshift */
9470 return -KEY_unshift;
9471 }
9472
9473 goto unknown;
9474
9475 default:
9476 goto unknown;
9477 }
9478
9479 case 'w':
9480 if (name[1] == 'a' &&
9481 name[2] == 'i' &&
9482 name[3] == 't' &&
9483 name[4] == 'p' &&
9484 name[5] == 'i' &&
9485 name[6] == 'd')
9486 { /* waitpid */
9487 return -KEY_waitpid;
9488 }
9489
9490 goto unknown;
9491
9492 default:
9493 goto unknown;
9494 }
9495
9496 case 8: /* 26 tokens of length 8 */
9497 switch (name[0])
9498 {
9499 case 'A':
9500 if (name[1] == 'U' &&
9501 name[2] == 'T' &&
9502 name[3] == 'O' &&
9503 name[4] == 'L' &&
9504 name[5] == 'O' &&
9505 name[6] == 'A' &&
9506 name[7] == 'D')
9507 { /* AUTOLOAD */
9508 return KEY_AUTOLOAD;
9509 }
9510
9511 goto unknown;
9512
9513 case '_':
9514 if (name[1] == '_')
9515 {
9516 switch (name[2])
9517 {
9518 case 'D':
9519 if (name[3] == 'A' &&
9520 name[4] == 'T' &&
9521 name[5] == 'A' &&
9522 name[6] == '_' &&
9523 name[7] == '_')
9524 { /* __DATA__ */
9525 return KEY___DATA__;
9526 }
9527
9528 goto unknown;
9529
9530 case 'F':
9531 if (name[3] == 'I' &&
9532 name[4] == 'L' &&
9533 name[5] == 'E' &&
9534 name[6] == '_' &&
9535 name[7] == '_')
9536 { /* __FILE__ */
9537 return -KEY___FILE__;
9538 }
9539
9540 goto unknown;
9541
9542 case 'L':
9543 if (name[3] == 'I' &&
9544 name[4] == 'N' &&
9545 name[5] == 'E' &&
9546 name[6] == '_' &&
9547 name[7] == '_')
9548 { /* __LINE__ */
9549 return -KEY___LINE__;
9550 }
9551
9552 goto unknown;
9553
9554 default:
9555 goto unknown;
9556 }
9557 }
9558
9559 goto unknown;
9560
9561 case 'c':
9562 switch (name[1])
9563 {
9564 case 'l':
9565 if (name[2] == 'o' &&
9566 name[3] == 's' &&
9567 name[4] == 'e' &&
9568 name[5] == 'd' &&
9569 name[6] == 'i' &&
9570 name[7] == 'r')
9571 { /* closedir */
9572 return -KEY_closedir;
9573 }
9574
9575 goto unknown;
9576
9577 case 'o':
9578 if (name[2] == 'n' &&
9579 name[3] == 't' &&
9580 name[4] == 'i' &&
9581 name[5] == 'n' &&
9582 name[6] == 'u' &&
9583 name[7] == 'e')
9584 { /* continue */
9585 return -KEY_continue;
9586 }
9587
9588 goto unknown;
9589
9590 default:
9591 goto unknown;
9592 }
9593
9594 case 'd':
9595 if (name[1] == 'b' &&
9596 name[2] == 'm' &&
9597 name[3] == 'c' &&
9598 name[4] == 'l' &&
9599 name[5] == 'o' &&
9600 name[6] == 's' &&
9601 name[7] == 'e')
9602 { /* dbmclose */
9603 return -KEY_dbmclose;
9604 }
9605
9606 goto unknown;
9607
9608 case 'e':
9609 if (name[1] == 'n' &&
9610 name[2] == 'd')
9611 {
9612 switch (name[3])
9613 {
9614 case 'g':
9615 if (name[4] == 'r' &&
9616 name[5] == 'e' &&
9617 name[6] == 'n' &&
9618 name[7] == 't')
9619 { /* endgrent */
9620 return -KEY_endgrent;
9621 }
9622
9623 goto unknown;
9624
9625 case 'p':
9626 if (name[4] == 'w' &&
9627 name[5] == 'e' &&
9628 name[6] == 'n' &&
9629 name[7] == 't')
9630 { /* endpwent */
9631 return -KEY_endpwent;
9632 }
9633
9634 goto unknown;
9635
9636 default:
9637 goto unknown;
9638 }
9639 }
9640
9641 goto unknown;
9642
9643 case 'f':
9644 if (name[1] == 'o' &&
9645 name[2] == 'r' &&
9646 name[3] == 'm' &&
9647 name[4] == 'l' &&
9648 name[5] == 'i' &&
9649 name[6] == 'n' &&
9650 name[7] == 'e')
9651 { /* formline */
9652 return -KEY_formline;
9653 }
9654
9655 goto unknown;
9656
9657 case 'g':
9658 if (name[1] == 'e' &&
9659 name[2] == 't')
9660 {
9661 switch (name[3])
9662 {
9663 case 'g':
9664 if (name[4] == 'r')
9665 {
9666 switch (name[5])
9667 {
9668 case 'e':
9669 if (name[6] == 'n' &&
9670 name[7] == 't')
9671 { /* getgrent */
9672 return -KEY_getgrent;
9673 }
9674
9675 goto unknown;
9676
9677 case 'g':
9678 if (name[6] == 'i' &&
9679 name[7] == 'd')
9680 { /* getgrgid */
9681 return -KEY_getgrgid;
9682 }
9683
9684 goto unknown;
9685
9686 case 'n':
9687 if (name[6] == 'a' &&
9688 name[7] == 'm')
9689 { /* getgrnam */
9690 return -KEY_getgrnam;
9691 }
9692
9693 goto unknown;
9694
9695 default:
9696 goto unknown;
9697 }
9698 }
9699
9700 goto unknown;
9701
9702 case 'l':
9703 if (name[4] == 'o' &&
9704 name[5] == 'g' &&
9705 name[6] == 'i' &&
9706 name[7] == 'n')
9707 { /* getlogin */
9708 return -KEY_getlogin;
9709 }
9710
9711 goto unknown;
9712
9713 case 'p':
9714 if (name[4] == 'w')
9715 {
9716 switch (name[5])
9717 {
9718 case 'e':
9719 if (name[6] == 'n' &&
9720 name[7] == 't')
9721 { /* getpwent */
9722 return -KEY_getpwent;
9723 }
9724
9725 goto unknown;
9726
9727 case 'n':
9728 if (name[6] == 'a' &&
9729 name[7] == 'm')
9730 { /* getpwnam */
9731 return -KEY_getpwnam;
9732 }
9733
9734 goto unknown;
9735
9736 case 'u':
9737 if (name[6] == 'i' &&
9738 name[7] == 'd')
9739 { /* getpwuid */
9740 return -KEY_getpwuid;
9741 }
9742
9743 goto unknown;
9744
9745 default:
9746 goto unknown;
9747 }
9748 }
9749
9750 goto unknown;
9751
9752 default:
9753 goto unknown;
9754 }
9755 }
9756
9757 goto unknown;
9758
9759 case 'r':
9760 if (name[1] == 'e' &&
9761 name[2] == 'a' &&
9762 name[3] == 'd')
9763 {
9764 switch (name[4])
9765 {
9766 case 'l':
9767 if (name[5] == 'i' &&
9768 name[6] == 'n')
9769 {
9770 switch (name[7])
9771 {
9772 case 'e':
9773 { /* readline */
9774 return -KEY_readline;
9775 }
9776
4c3bbe0f
MHM
9777 case 'k':
9778 { /* readlink */
9779 return -KEY_readlink;
9780 }
9781
4c3bbe0f
MHM
9782 default:
9783 goto unknown;
9784 }
9785 }
9786
9787 goto unknown;
9788
9789 case 'p':
9790 if (name[5] == 'i' &&
9791 name[6] == 'p' &&
9792 name[7] == 'e')
9793 { /* readpipe */
9794 return -KEY_readpipe;
9795 }
9796
9797 goto unknown;
9798
9799 default:
9800 goto unknown;
9801 }
9802 }
9803
9804 goto unknown;
9805
9806 case 's':
9807 switch (name[1])
9808 {
9809 case 'e':
9810 if (name[2] == 't')
9811 {
9812 switch (name[3])
9813 {
9814 case 'g':
9815 if (name[4] == 'r' &&
9816 name[5] == 'e' &&
9817 name[6] == 'n' &&
9818 name[7] == 't')
9819 { /* setgrent */
9820 return -KEY_setgrent;
9821 }
9822
9823 goto unknown;
9824
9825 case 'p':
9826 if (name[4] == 'w' &&
9827 name[5] == 'e' &&
9828 name[6] == 'n' &&
9829 name[7] == 't')
9830 { /* setpwent */
9831 return -KEY_setpwent;
9832 }
9833
9834 goto unknown;
9835
9836 default:
9837 goto unknown;
9838 }
9839 }
9840
9841 goto unknown;
9842
9843 case 'h':
9844 switch (name[2])
9845 {
9846 case 'm':
9847 if (name[3] == 'w' &&
9848 name[4] == 'r' &&
9849 name[5] == 'i' &&
9850 name[6] == 't' &&
9851 name[7] == 'e')
9852 { /* shmwrite */
9853 return -KEY_shmwrite;
9854 }
9855
9856 goto unknown;
9857
9858 case 'u':
9859 if (name[3] == 't' &&
9860 name[4] == 'd' &&
9861 name[5] == 'o' &&
9862 name[6] == 'w' &&
9863 name[7] == 'n')
9864 { /* shutdown */
9865 return -KEY_shutdown;
9866 }
9867
9868 goto unknown;
9869
9870 default:
9871 goto unknown;
9872 }
9873
9874 case 'y':
9875 if (name[2] == 's' &&
9876 name[3] == 'w' &&
9877 name[4] == 'r' &&
9878 name[5] == 'i' &&
9879 name[6] == 't' &&
9880 name[7] == 'e')
9881 { /* syswrite */
9882 return -KEY_syswrite;
9883 }
9884
9885 goto unknown;
9886
9887 default:
9888 goto unknown;
9889 }
9890
9891 case 't':
9892 if (name[1] == 'r' &&
9893 name[2] == 'u' &&
9894 name[3] == 'n' &&
9895 name[4] == 'c' &&
9896 name[5] == 'a' &&
9897 name[6] == 't' &&
9898 name[7] == 'e')
9899 { /* truncate */
9900 return -KEY_truncate;
9901 }
9902
9903 goto unknown;
9904
9905 default:
9906 goto unknown;
9907 }
9908
3c10abe3 9909 case 9: /* 9 tokens of length 9 */
4c3bbe0f
MHM
9910 switch (name[0])
9911 {
3c10abe3
AG
9912 case 'U':
9913 if (name[1] == 'N' &&
9914 name[2] == 'I' &&
9915 name[3] == 'T' &&
9916 name[4] == 'C' &&
9917 name[5] == 'H' &&
9918 name[6] == 'E' &&
9919 name[7] == 'C' &&
9920 name[8] == 'K')
9921 { /* UNITCHECK */
9922 return KEY_UNITCHECK;
9923 }
9924
9925 goto unknown;
9926
4c3bbe0f
MHM
9927 case 'e':
9928 if (name[1] == 'n' &&
9929 name[2] == 'd' &&
9930 name[3] == 'n' &&
9931 name[4] == 'e' &&
9932 name[5] == 't' &&
9933 name[6] == 'e' &&
9934 name[7] == 'n' &&
9935 name[8] == 't')
9936 { /* endnetent */
9937 return -KEY_endnetent;
9938 }
9939
9940 goto unknown;
9941
9942 case 'g':
9943 if (name[1] == 'e' &&
9944 name[2] == 't' &&
9945 name[3] == 'n' &&
9946 name[4] == 'e' &&
9947 name[5] == 't' &&
9948 name[6] == 'e' &&
9949 name[7] == 'n' &&
9950 name[8] == 't')
9951 { /* getnetent */
9952 return -KEY_getnetent;
9953 }
9954
9955 goto unknown;
9956
9957 case 'l':
9958 if (name[1] == 'o' &&
9959 name[2] == 'c' &&
9960 name[3] == 'a' &&
9961 name[4] == 'l' &&
9962 name[5] == 't' &&
9963 name[6] == 'i' &&
9964 name[7] == 'm' &&
9965 name[8] == 'e')
9966 { /* localtime */
9967 return -KEY_localtime;
9968 }
9969
9970 goto unknown;
9971
9972 case 'p':
9973 if (name[1] == 'r' &&
9974 name[2] == 'o' &&
9975 name[3] == 't' &&
9976 name[4] == 'o' &&
9977 name[5] == 't' &&
9978 name[6] == 'y' &&
9979 name[7] == 'p' &&
9980 name[8] == 'e')
9981 { /* prototype */
9982 return KEY_prototype;
9983 }
9984
9985 goto unknown;
9986
9987 case 'q':
9988 if (name[1] == 'u' &&
9989 name[2] == 'o' &&
9990 name[3] == 't' &&
9991 name[4] == 'e' &&
9992 name[5] == 'm' &&
9993 name[6] == 'e' &&
9994 name[7] == 't' &&
9995 name[8] == 'a')
9996 { /* quotemeta */
9997 return -KEY_quotemeta;
9998 }
9999
10000 goto unknown;
10001
10002 case 'r':
10003 if (name[1] == 'e' &&
10004 name[2] == 'w' &&
10005 name[3] == 'i' &&
10006 name[4] == 'n' &&
10007 name[5] == 'd' &&
10008 name[6] == 'd' &&
10009 name[7] == 'i' &&
10010 name[8] == 'r')
10011 { /* rewinddir */
10012 return -KEY_rewinddir;
10013 }
10014
10015 goto unknown;
10016
10017 case 's':
10018 if (name[1] == 'e' &&
10019 name[2] == 't' &&
10020 name[3] == 'n' &&
10021 name[4] == 'e' &&
10022 name[5] == 't' &&
10023 name[6] == 'e' &&
10024 name[7] == 'n' &&
10025 name[8] == 't')
10026 { /* setnetent */
10027 return -KEY_setnetent;
10028 }
10029
10030 goto unknown;
10031
10032 case 'w':
10033 if (name[1] == 'a' &&
10034 name[2] == 'n' &&
10035 name[3] == 't' &&
10036 name[4] == 'a' &&
10037 name[5] == 'r' &&
10038 name[6] == 'r' &&
10039 name[7] == 'a' &&
10040 name[8] == 'y')
10041 { /* wantarray */
10042 return -KEY_wantarray;
10043 }
10044
10045 goto unknown;
10046
10047 default:
10048 goto unknown;
10049 }
10050
10051 case 10: /* 9 tokens of length 10 */
10052 switch (name[0])
10053 {
10054 case 'e':
10055 if (name[1] == 'n' &&
10056 name[2] == 'd')
10057 {
10058 switch (name[3])
10059 {
10060 case 'h':
10061 if (name[4] == 'o' &&
10062 name[5] == 's' &&
10063 name[6] == 't' &&
10064 name[7] == 'e' &&
10065 name[8] == 'n' &&
10066 name[9] == 't')
10067 { /* endhostent */
10068 return -KEY_endhostent;
10069 }
10070
10071 goto unknown;
10072
10073 case 's':
10074 if (name[4] == 'e' &&
10075 name[5] == 'r' &&
10076 name[6] == 'v' &&
10077 name[7] == 'e' &&
10078 name[8] == 'n' &&
10079 name[9] == 't')
10080 { /* endservent */
10081 return -KEY_endservent;
10082 }
10083
10084 goto unknown;
10085
10086 default:
10087 goto unknown;
10088 }
10089 }
10090
10091 goto unknown;
10092
10093 case 'g':
10094 if (name[1] == 'e' &&
10095 name[2] == 't')
10096 {
10097 switch (name[3])
10098 {
10099 case 'h':
10100 if (name[4] == 'o' &&
10101 name[5] == 's' &&
10102 name[6] == 't' &&
10103 name[7] == 'e' &&
10104 name[8] == 'n' &&
10105 name[9] == 't')
10106 { /* gethostent */
10107 return -KEY_gethostent;
10108 }
10109
10110 goto unknown;
10111
10112 case 's':
10113 switch (name[4])
10114 {
10115 case 'e':
10116 if (name[5] == 'r' &&
10117 name[6] == 'v' &&
10118 name[7] == 'e' &&
10119 name[8] == 'n' &&
10120 name[9] == 't')
10121 { /* getservent */
10122 return -KEY_getservent;
10123 }
10124
10125 goto unknown;
10126
10127 case 'o':
10128 if (name[5] == 'c' &&
10129 name[6] == 'k' &&
10130 name[7] == 'o' &&
10131 name[8] == 'p' &&
10132 name[9] == 't')
10133 { /* getsockopt */
10134 return -KEY_getsockopt;
10135 }
10136
10137 goto unknown;
10138
10139 default:
10140 goto unknown;
10141 }
10142
10143 default:
10144 goto unknown;
10145 }
10146 }
10147
10148 goto unknown;
10149
10150 case 's':
10151 switch (name[1])
10152 {
10153 case 'e':
10154 if (name[2] == 't')
10155 {
10156 switch (name[3])
10157 {
10158 case 'h':
10159 if (name[4] == 'o' &&
10160 name[5] == 's' &&
10161 name[6] == 't' &&
10162 name[7] == 'e' &&
10163 name[8] == 'n' &&
10164 name[9] == 't')
10165 { /* sethostent */
10166 return -KEY_sethostent;
10167 }
10168
10169 goto unknown;
10170
10171 case 's':
10172 switch (name[4])
10173 {
10174 case 'e':
10175 if (name[5] == 'r' &&
10176 name[6] == 'v' &&
10177 name[7] == 'e' &&
10178 name[8] == 'n' &&
10179 name[9] == 't')
10180 { /* setservent */
10181 return -KEY_setservent;
10182 }
10183
10184 goto unknown;
10185
10186 case 'o':
10187 if (name[5] == 'c' &&
10188 name[6] == 'k' &&
10189 name[7] == 'o' &&
10190 name[8] == 'p' &&
10191 name[9] == 't')
10192 { /* setsockopt */
10193 return -KEY_setsockopt;
10194 }
10195
10196 goto unknown;
10197
10198 default:
10199 goto unknown;
10200 }
10201
10202 default:
10203 goto unknown;
10204 }
10205 }
10206
10207 goto unknown;
10208
10209 case 'o':
10210 if (name[2] == 'c' &&
10211 name[3] == 'k' &&
10212 name[4] == 'e' &&
10213 name[5] == 't' &&
10214 name[6] == 'p' &&
10215 name[7] == 'a' &&
10216 name[8] == 'i' &&
10217 name[9] == 'r')
10218 { /* socketpair */
10219 return -KEY_socketpair;
10220 }
10221
10222 goto unknown;
10223
10224 default:
10225 goto unknown;
10226 }
10227
10228 default:
10229 goto unknown;
e2e1dd5a 10230 }
4c3bbe0f
MHM
10231
10232 case 11: /* 8 tokens of length 11 */
10233 switch (name[0])
10234 {
10235 case '_':
10236 if (name[1] == '_' &&
10237 name[2] == 'P' &&
10238 name[3] == 'A' &&
10239 name[4] == 'C' &&
10240 name[5] == 'K' &&
10241 name[6] == 'A' &&
10242 name[7] == 'G' &&
10243 name[8] == 'E' &&
10244 name[9] == '_' &&
10245 name[10] == '_')
10246 { /* __PACKAGE__ */
10247 return -KEY___PACKAGE__;
10248 }
10249
10250 goto unknown;
10251
10252 case 'e':
10253 if (name[1] == 'n' &&
10254 name[2] == 'd' &&
10255 name[3] == 'p' &&
10256 name[4] == 'r' &&
10257 name[5] == 'o' &&
10258 name[6] == 't' &&
10259 name[7] == 'o' &&
10260 name[8] == 'e' &&
10261 name[9] == 'n' &&
10262 name[10] == 't')
10263 { /* endprotoent */
10264 return -KEY_endprotoent;
10265 }
10266
10267 goto unknown;
10268
10269 case 'g':
10270 if (name[1] == 'e' &&
10271 name[2] == 't')
10272 {
10273 switch (name[3])
10274 {
10275 case 'p':
10276 switch (name[4])
10277 {
10278 case 'e':
10279 if (name[5] == 'e' &&
10280 name[6] == 'r' &&
10281 name[7] == 'n' &&
10282 name[8] == 'a' &&
10283 name[9] == 'm' &&
10284 name[10] == 'e')
10285 { /* getpeername */
10286 return -KEY_getpeername;
10287 }
10288
10289 goto unknown;
10290
10291 case 'r':
10292 switch (name[5])
10293 {
10294 case 'i':
10295 if (name[6] == 'o' &&
10296 name[7] == 'r' &&
10297 name[8] == 'i' &&
10298 name[9] == 't' &&
10299 name[10] == 'y')
10300 { /* getpriority */
10301 return -KEY_getpriority;
10302 }
10303
10304 goto unknown;
10305
10306 case 'o':
10307 if (name[6] == 't' &&
10308 name[7] == 'o' &&
10309 name[8] == 'e' &&
10310 name[9] == 'n' &&
10311 name[10] == 't')
10312 { /* getprotoent */
10313 return -KEY_getprotoent;
10314 }
10315
10316 goto unknown;
10317
10318 default:
10319 goto unknown;
10320 }
10321
10322 default:
10323 goto unknown;
10324 }
10325
10326 case 's':
10327 if (name[4] == 'o' &&
10328 name[5] == 'c' &&
10329 name[6] == 'k' &&
10330 name[7] == 'n' &&
10331 name[8] == 'a' &&
10332 name[9] == 'm' &&
10333 name[10] == 'e')
10334 { /* getsockname */
10335 return -KEY_getsockname;
10336 }
10337
10338 goto unknown;
10339
10340 default:
10341 goto unknown;
10342 }
10343 }
10344
10345 goto unknown;
10346
10347 case 's':
10348 if (name[1] == 'e' &&
10349 name[2] == 't' &&
10350 name[3] == 'p' &&
10351 name[4] == 'r')
10352 {
10353 switch (name[5])
10354 {
10355 case 'i':
10356 if (name[6] == 'o' &&
10357 name[7] == 'r' &&
10358 name[8] == 'i' &&
10359 name[9] == 't' &&
10360 name[10] == 'y')
10361 { /* setpriority */
10362 return -KEY_setpriority;
10363 }
10364
10365 goto unknown;
10366
10367 case 'o':
10368 if (name[6] == 't' &&
10369 name[7] == 'o' &&
10370 name[8] == 'e' &&
10371 name[9] == 'n' &&
10372 name[10] == 't')
10373 { /* setprotoent */
10374 return -KEY_setprotoent;
10375 }
10376
10377 goto unknown;
10378
10379 default:
10380 goto unknown;
10381 }
10382 }
10383
10384 goto unknown;
10385
10386 default:
10387 goto unknown;
e2e1dd5a 10388 }
4c3bbe0f
MHM
10389
10390 case 12: /* 2 tokens of length 12 */
10391 if (name[0] == 'g' &&
10392 name[1] == 'e' &&
10393 name[2] == 't' &&
10394 name[3] == 'n' &&
10395 name[4] == 'e' &&
10396 name[5] == 't' &&
10397 name[6] == 'b' &&
10398 name[7] == 'y')
10399 {
10400 switch (name[8])
10401 {
10402 case 'a':
10403 if (name[9] == 'd' &&
10404 name[10] == 'd' &&
10405 name[11] == 'r')
10406 { /* getnetbyaddr */
10407 return -KEY_getnetbyaddr;
10408 }
10409
10410 goto unknown;
10411
10412 case 'n':
10413 if (name[9] == 'a' &&
10414 name[10] == 'm' &&
10415 name[11] == 'e')
10416 { /* getnetbyname */
10417 return -KEY_getnetbyname;
10418 }
10419
10420 goto unknown;
10421
10422 default:
10423 goto unknown;
10424 }
e2e1dd5a 10425 }
4c3bbe0f
MHM
10426
10427 goto unknown;
10428
10429 case 13: /* 4 tokens of length 13 */
10430 if (name[0] == 'g' &&
10431 name[1] == 'e' &&
10432 name[2] == 't')
10433 {
10434 switch (name[3])
10435 {
10436 case 'h':
10437 if (name[4] == 'o' &&
10438 name[5] == 's' &&
10439 name[6] == 't' &&
10440 name[7] == 'b' &&
10441 name[8] == 'y')
10442 {
10443 switch (name[9])
10444 {
10445 case 'a':
10446 if (name[10] == 'd' &&
10447 name[11] == 'd' &&
10448 name[12] == 'r')
10449 { /* gethostbyaddr */
10450 return -KEY_gethostbyaddr;
10451 }
10452
10453 goto unknown;
10454
10455 case 'n':
10456 if (name[10] == 'a' &&
10457 name[11] == 'm' &&
10458 name[12] == 'e')
10459 { /* gethostbyname */
10460 return -KEY_gethostbyname;
10461 }
10462
10463 goto unknown;
10464
10465 default:
10466 goto unknown;
10467 }
10468 }
10469
10470 goto unknown;
10471
10472 case 's':
10473 if (name[4] == 'e' &&
10474 name[5] == 'r' &&
10475 name[6] == 'v' &&
10476 name[7] == 'b' &&
10477 name[8] == 'y')
10478 {
10479 switch (name[9])
10480 {
10481 case 'n':
10482 if (name[10] == 'a' &&
10483 name[11] == 'm' &&
10484 name[12] == 'e')
10485 { /* getservbyname */
10486 return -KEY_getservbyname;
10487 }
10488
10489 goto unknown;
10490
10491 case 'p':
10492 if (name[10] == 'o' &&
10493 name[11] == 'r' &&
10494 name[12] == 't')
10495 { /* getservbyport */
10496 return -KEY_getservbyport;
10497 }
10498
10499 goto unknown;
10500
10501 default:
10502 goto unknown;
10503 }
10504 }
10505
10506 goto unknown;
10507
10508 default:
10509 goto unknown;
10510 }
e2e1dd5a 10511 }
4c3bbe0f
MHM
10512
10513 goto unknown;
10514
10515 case 14: /* 1 tokens of length 14 */
10516 if (name[0] == 'g' &&
10517 name[1] == 'e' &&
10518 name[2] == 't' &&
10519 name[3] == 'p' &&
10520 name[4] == 'r' &&
10521 name[5] == 'o' &&
10522 name[6] == 't' &&
10523 name[7] == 'o' &&
10524 name[8] == 'b' &&
10525 name[9] == 'y' &&
10526 name[10] == 'n' &&
10527 name[11] == 'a' &&
10528 name[12] == 'm' &&
10529 name[13] == 'e')
10530 { /* getprotobyname */
10531 return -KEY_getprotobyname;
10532 }
10533
10534 goto unknown;
10535
10536 case 16: /* 1 tokens of length 16 */
10537 if (name[0] == 'g' &&
10538 name[1] == 'e' &&
10539 name[2] == 't' &&
10540 name[3] == 'p' &&
10541 name[4] == 'r' &&
10542 name[5] == 'o' &&
10543 name[6] == 't' &&
10544 name[7] == 'o' &&
10545 name[8] == 'b' &&
10546 name[9] == 'y' &&
10547 name[10] == 'n' &&
10548 name[11] == 'u' &&
10549 name[12] == 'm' &&
10550 name[13] == 'b' &&
10551 name[14] == 'e' &&
10552 name[15] == 'r')
10553 { /* getprotobynumber */
10554 return -KEY_getprotobynumber;
10555 }
10556
10557 goto unknown;
10558
10559 default:
10560 goto unknown;
e2e1dd5a 10561 }
4c3bbe0f
MHM
10562
10563unknown:
e2e1dd5a 10564 return 0;
a687059c
LW
10565}
10566
76e3520e 10567STATIC void
c94115d8 10568S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
a687059c 10569{
97aff369 10570 dVAR;
2f3197b3 10571
7918f24d
NC
10572 PERL_ARGS_ASSERT_CHECKCOMMA;
10573
d008e5eb 10574 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
d008e5eb
GS
10575 if (ckWARN(WARN_SYNTAX)) {
10576 int level = 1;
26ff0806 10577 const char *w;
d008e5eb
GS
10578 for (w = s+2; *w && level; w++) {
10579 if (*w == '(')
10580 ++level;
10581 else if (*w == ')')
10582 --level;
10583 }
888fea98
NC
10584 while (isSPACE(*w))
10585 ++w;
b1439985
RGS
10586 /* the list of chars below is for end of statements or
10587 * block / parens, boolean operators (&&, ||, //) and branch
10588 * constructs (or, and, if, until, unless, while, err, for).
10589 * Not a very solid hack... */
10590 if (!*w || !strchr(";&/|})]oaiuwef!=", *w))
9014280d 10591 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
65cec589 10592 "%s (...) interpreted as function",name);
d008e5eb 10593 }
2f3197b3 10594 }
3280af22 10595 while (s < PL_bufend && isSPACE(*s))
2f3197b3 10596 s++;
a687059c
LW
10597 if (*s == '(')
10598 s++;
3280af22 10599 while (s < PL_bufend && isSPACE(*s))
a687059c 10600 s++;
7e2040f0 10601 if (isIDFIRST_lazy_if(s,UTF)) {
26ff0806 10602 const char * const w = s++;
7e2040f0 10603 while (isALNUM_lazy_if(s,UTF))
a687059c 10604 s++;
3280af22 10605 while (s < PL_bufend && isSPACE(*s))
a687059c 10606 s++;
e929a76b 10607 if (*s == ',') {
c94115d8 10608 GV* gv;
5458a98a 10609 if (keyword(w, s - w, 0))
e929a76b 10610 return;
c94115d8
NC
10611
10612 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10613 if (gv && GvCVu(gv))
abbb3198 10614 return;
cea2e8a9 10615 Perl_croak(aTHX_ "No comma allowed after %s", what);
463ee0b2
LW
10616 }
10617 }
10618}
10619
423cee85
JH
10620/* Either returns sv, or mortalizes sv and returns a new SV*.
10621 Best used as sv=new_constant(..., sv, ...).
10622 If s, pv are NULL, calls subroutine with one argument,
10623 and type is used with error messages only. */
10624
b3ac6de7 10625STATIC SV *
eb0d8d16
NC
10626S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, STRLEN keylen,
10627 SV *sv, SV *pv, const char *type, STRLEN typelen)
b3ac6de7 10628{
27da23d5 10629 dVAR; dSP;
890ce7af 10630 HV * const table = GvHV(PL_hintgv); /* ^H */
b3ac6de7 10631 SV *res;
b3ac6de7
IZ
10632 SV **cvp;
10633 SV *cv, *typesv;
89e33a05 10634 const char *why1 = "", *why2 = "", *why3 = "";
4e553d73 10635
7918f24d
NC
10636 PERL_ARGS_ASSERT_NEW_CONSTANT;
10637
f0af216f 10638 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
423cee85
JH
10639 SV *msg;
10640
10edeb5d
JH
10641 why2 = (const char *)
10642 (strEQ(key,"charnames")
10643 ? "(possibly a missing \"use charnames ...\")"
10644 : "");
4e553d73 10645 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
41ab332f
JH
10646 (type ? type: "undef"), why2);
10647
10648 /* This is convoluted and evil ("goto considered harmful")
10649 * but I do not understand the intricacies of all the different
10650 * failure modes of %^H in here. The goal here is to make
10651 * the most probable error message user-friendly. --jhi */
10652
10653 goto msgdone;
10654
423cee85 10655 report:
4e553d73 10656 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
f0af216f 10657 (type ? type: "undef"), why1, why2, why3);
41ab332f 10658 msgdone:
95a20fc0 10659 yyerror(SvPVX_const(msg));
423cee85
JH
10660 SvREFCNT_dec(msg);
10661 return sv;
10662 }
eb0d8d16 10663 cvp = hv_fetch(table, key, keylen, FALSE);
b3ac6de7 10664 if (!cvp || !SvOK(*cvp)) {
423cee85
JH
10665 why1 = "$^H{";
10666 why2 = key;
f0af216f 10667 why3 = "} is not defined";
423cee85 10668 goto report;
b3ac6de7
IZ
10669 }
10670 sv_2mortal(sv); /* Parent created it permanently */
10671 cv = *cvp;
423cee85 10672 if (!pv && s)
59cd0e26 10673 pv = newSVpvn_flags(s, len, SVs_TEMP);
423cee85 10674 if (type && pv)
59cd0e26 10675 typesv = newSVpvn_flags(type, typelen, SVs_TEMP);
b3ac6de7 10676 else
423cee85 10677 typesv = &PL_sv_undef;
4e553d73 10678
e788e7d3 10679 PUSHSTACKi(PERLSI_OVERLOAD);
423cee85
JH
10680 ENTER ;
10681 SAVETMPS;
4e553d73 10682
423cee85 10683 PUSHMARK(SP) ;
a5845cb7 10684 EXTEND(sp, 3);
423cee85
JH
10685 if (pv)
10686 PUSHs(pv);
b3ac6de7 10687 PUSHs(sv);
423cee85
JH
10688 if (pv)
10689 PUSHs(typesv);
b3ac6de7 10690 PUTBACK;
423cee85 10691 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
4e553d73 10692
423cee85 10693 SPAGAIN ;
4e553d73 10694
423cee85 10695 /* Check the eval first */
9b0e499b 10696 if (!PL_in_eval && SvTRUE(ERRSV)) {
396482e1 10697 sv_catpvs(ERRSV, "Propagated");
8b6b16e7 10698 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
e1f15930 10699 (void)POPs;
b37c2d43 10700 res = SvREFCNT_inc_simple(sv);
423cee85
JH
10701 }
10702 else {
10703 res = POPs;
b37c2d43 10704 SvREFCNT_inc_simple_void(res);
423cee85 10705 }
4e553d73 10706
423cee85
JH
10707 PUTBACK ;
10708 FREETMPS ;
10709 LEAVE ;
b3ac6de7 10710 POPSTACK;
4e553d73 10711
b3ac6de7 10712 if (!SvOK(res)) {
423cee85
JH
10713 why1 = "Call to &{$^H{";
10714 why2 = key;
f0af216f 10715 why3 = "}} did not return a defined value";
423cee85
JH
10716 sv = res;
10717 goto report;
9b0e499b 10718 }
423cee85 10719
9b0e499b 10720 return res;
b3ac6de7 10721}
4e553d73 10722
d0a148a6
NC
10723/* Returns a NUL terminated string, with the length of the string written to
10724 *slp
10725 */
76e3520e 10726STATIC char *
cea2e8a9 10727S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
463ee0b2 10728{
97aff369 10729 dVAR;
463ee0b2 10730 register char *d = dest;
890ce7af 10731 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
7918f24d
NC
10732
10733 PERL_ARGS_ASSERT_SCAN_WORD;
10734
463ee0b2 10735 for (;;) {
8903cb82 10736 if (d >= e)
cea2e8a9 10737 Perl_croak(aTHX_ ident_too_long);
834a4ddd 10738 if (isALNUM(*s)) /* UTF handled below */
463ee0b2 10739 *d++ = *s++;
c35e046a 10740 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
463ee0b2
LW
10741 *d++ = ':';
10742 *d++ = ':';
10743 s++;
10744 }
c35e046a 10745 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
463ee0b2
LW
10746 *d++ = *s++;
10747 *d++ = *s++;
10748 }
fd400ab9 10749 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
a0ed51b3 10750 char *t = s + UTF8SKIP(s);
c35e046a 10751 size_t len;
fd400ab9 10752 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
a0ed51b3 10753 t += UTF8SKIP(t);
c35e046a
AL
10754 len = t - s;
10755 if (d + len > e)
cea2e8a9 10756 Perl_croak(aTHX_ ident_too_long);
c35e046a
AL
10757 Copy(s, d, len, char);
10758 d += len;
a0ed51b3
LW
10759 s = t;
10760 }
463ee0b2
LW
10761 else {
10762 *d = '\0';
10763 *slp = d - dest;
10764 return s;
e929a76b 10765 }
378cc40b
LW
10766 }
10767}
10768
76e3520e 10769STATIC char *
f54cb97a 10770S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
378cc40b 10771{
97aff369 10772 dVAR;
6136c704 10773 char *bracket = NULL;
748a9306 10774 char funny = *s++;
6136c704
AL
10775 register char *d = dest;
10776 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
378cc40b 10777
7918f24d
NC
10778 PERL_ARGS_ASSERT_SCAN_IDENT;
10779
a0d0e21e 10780 if (isSPACE(*s))
29595ff2 10781 s = PEEKSPACE(s);
de3bb511 10782 if (isDIGIT(*s)) {
8903cb82 10783 while (isDIGIT(*s)) {
10784 if (d >= e)
cea2e8a9 10785 Perl_croak(aTHX_ ident_too_long);
378cc40b 10786 *d++ = *s++;
8903cb82 10787 }
378cc40b
LW
10788 }
10789 else {
463ee0b2 10790 for (;;) {
8903cb82 10791 if (d >= e)
cea2e8a9 10792 Perl_croak(aTHX_ ident_too_long);
834a4ddd 10793 if (isALNUM(*s)) /* UTF handled below */
463ee0b2 10794 *d++ = *s++;
7e2040f0 10795 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
463ee0b2
LW
10796 *d++ = ':';
10797 *d++ = ':';
10798 s++;
10799 }
a0d0e21e 10800 else if (*s == ':' && s[1] == ':') {
463ee0b2
LW
10801 *d++ = *s++;
10802 *d++ = *s++;
10803 }
fd400ab9 10804 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
a0ed51b3 10805 char *t = s + UTF8SKIP(s);
fd400ab9 10806 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
a0ed51b3
LW
10807 t += UTF8SKIP(t);
10808 if (d + (t - s) > e)
cea2e8a9 10809 Perl_croak(aTHX_ ident_too_long);
a0ed51b3
LW
10810 Copy(s, d, t - s, char);
10811 d += t - s;
10812 s = t;
10813 }
463ee0b2
LW
10814 else
10815 break;
10816 }
378cc40b
LW
10817 }
10818 *d = '\0';
10819 d = dest;
79072805 10820 if (*d) {
3280af22
NIS
10821 if (PL_lex_state != LEX_NORMAL)
10822 PL_lex_state = LEX_INTERPENDMAYBE;
79072805 10823 return s;
378cc40b 10824 }
748a9306 10825 if (*s == '$' && s[1] &&
3792a11b 10826 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
5cd24f17 10827 {
4810e5ec 10828 return s;
5cd24f17 10829 }
79072805
LW
10830 if (*s == '{') {
10831 bracket = s;
10832 s++;
10833 }
10834 else if (ck_uni)
10835 check_uni();
93a17b20 10836 if (s < send)
79072805
LW
10837 *d = *s++;
10838 d[1] = '\0';
2b92dfce 10839 if (*d == '^' && *s && isCONTROLVAR(*s)) {
bbce6d69 10840 *d = toCTRL(*s);
10841 s++;
de3bb511 10842 }
79072805 10843 if (bracket) {
748a9306 10844 if (isSPACE(s[-1])) {
fa83b5b6 10845 while (s < send) {
f54cb97a 10846 const char ch = *s++;
bf4acbe4 10847 if (!SPACE_OR_TAB(ch)) {
fa83b5b6 10848 *d = ch;
10849 break;
10850 }
10851 }
748a9306 10852 }
7e2040f0 10853 if (isIDFIRST_lazy_if(d,UTF)) {
79072805 10854 d++;
a0ed51b3 10855 if (UTF) {
6136c704
AL
10856 char *end = s;
10857 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10858 end += UTF8SKIP(end);
10859 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10860 end += UTF8SKIP(end);
a0ed51b3 10861 }
6136c704
AL
10862 Copy(s, d, end - s, char);
10863 d += end - s;
10864 s = end;
a0ed51b3
LW
10865 }
10866 else {
2b92dfce 10867 while ((isALNUM(*s) || *s == ':') && d < e)
a0ed51b3 10868 *d++ = *s++;
2b92dfce 10869 if (d >= e)
cea2e8a9 10870 Perl_croak(aTHX_ ident_too_long);
a0ed51b3 10871 }
79072805 10872 *d = '\0';
c35e046a
AL
10873 while (s < send && SPACE_OR_TAB(*s))
10874 s++;
ff68c719 10875 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
5458a98a 10876 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
10edeb5d
JH
10877 const char * const brack =
10878 (const char *)
10879 ((*s == '[') ? "[...]" : "{...}");
9014280d 10880 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
599cee73 10881 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
748a9306
LW
10882 funny, dest, brack, funny, dest, brack);
10883 }
79072805 10884 bracket++;
a0be28da 10885 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
79072805
LW
10886 return s;
10887 }
4e553d73
NIS
10888 }
10889 /* Handle extended ${^Foo} variables
2b92dfce
GS
10890 * 1999-02-27 mjd-perl-patch@plover.com */
10891 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10892 && isALNUM(*s))
10893 {
10894 d++;
10895 while (isALNUM(*s) && d < e) {
10896 *d++ = *s++;
10897 }
10898 if (d >= e)
cea2e8a9 10899 Perl_croak(aTHX_ ident_too_long);
2b92dfce 10900 *d = '\0';
79072805
LW
10901 }
10902 if (*s == '}') {
10903 s++;
7df0d042 10904 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
3280af22 10905 PL_lex_state = LEX_INTERPEND;
7df0d042
AE
10906 PL_expect = XREF;
10907 }
d008e5eb 10908 if (PL_lex_state == LEX_NORMAL) {
d008e5eb 10909 if (ckWARN(WARN_AMBIGUOUS) &&
780a5241
NC
10910 (keyword(dest, d - dest, 0)
10911 || get_cvn_flags(dest, d - dest, 0)))
d008e5eb 10912 {
c35e046a
AL
10913 if (funny == '#')
10914 funny = '@';
9014280d 10915 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
d008e5eb
GS
10916 "Ambiguous use of %c{%s} resolved to %c%s",
10917 funny, dest, funny, dest);
10918 }
10919 }
79072805
LW
10920 }
10921 else {
10922 s = bracket; /* let the parser handle it */
93a17b20 10923 *dest = '\0';
79072805
LW
10924 }
10925 }
3280af22
NIS
10926 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10927 PL_lex_state = LEX_INTERPEND;
378cc40b
LW
10928 return s;
10929}
10930
cea2e8a9 10931void
2b36a5a0 10932Perl_pmflag(pTHX_ U32* pmfl, int ch)
a0d0e21e 10933{
7918f24d
NC
10934 PERL_ARGS_ASSERT_PMFLAG;
10935
96a5add6 10936 PERL_UNUSED_CONTEXT;
cde0cee5 10937 if (ch<256) {
15f169a1 10938 const char c = (char)ch;
cde0cee5
YO
10939 switch (c) {
10940 CASE_STD_PMMOD_FLAGS_PARSE_SET(pmfl);
a20207d7
YO
10941 case GLOBAL_PAT_MOD: *pmfl |= PMf_GLOBAL; break;
10942 case CONTINUE_PAT_MOD: *pmfl |= PMf_CONTINUE; break;
10943 case ONCE_PAT_MOD: *pmfl |= PMf_KEEP; break;
10944 case KEEPCOPY_PAT_MOD: *pmfl |= PMf_KEEPCOPY; break;
cde0cee5
YO
10945 }
10946 }
a0d0e21e 10947}
378cc40b 10948
76e3520e 10949STATIC char *
cea2e8a9 10950S_scan_pat(pTHX_ char *start, I32 type)
378cc40b 10951{
97aff369 10952 dVAR;
79072805 10953 PMOP *pm;
5db06880 10954 char *s = scan_str(start,!!PL_madskills,FALSE);
10edeb5d 10955 const char * const valid_flags =
a20207d7 10956 (const char *)((type == OP_QR) ? QR_PAT_MODS : M_PAT_MODS);
5db06880
NC
10957#ifdef PERL_MAD
10958 char *modstart;
10959#endif
10960
7918f24d 10961 PERL_ARGS_ASSERT_SCAN_PAT;
378cc40b 10962
25c09cbf 10963 if (!s) {
6136c704 10964 const char * const delimiter = skipspace(start);
10edeb5d
JH
10965 Perl_croak(aTHX_
10966 (const char *)
10967 (*delimiter == '?'
10968 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10969 : "Search pattern not terminated" ));
25c09cbf 10970 }
bbce6d69 10971
8782bef2 10972 pm = (PMOP*)newPMOP(type, 0);
ad639bfb
NC
10973 if (PL_multi_open == '?') {
10974 /* This is the only point in the code that sets PMf_ONCE: */
79072805 10975 pm->op_pmflags |= PMf_ONCE;
ad639bfb
NC
10976
10977 /* Hence it's safe to do this bit of PMOP book-keeping here, which
10978 allows us to restrict the list needed by reset to just the ??
10979 matches. */
10980 assert(type != OP_TRANS);
10981 if (PL_curstash) {
daba3364 10982 MAGIC *mg = mg_find((const SV *)PL_curstash, PERL_MAGIC_symtab);
ad639bfb
NC
10983 U32 elements;
10984 if (!mg) {
daba3364 10985 mg = sv_magicext(MUTABLE_SV(PL_curstash), 0, PERL_MAGIC_symtab, 0, 0,
ad639bfb
NC
10986 0);
10987 }
10988 elements = mg->mg_len / sizeof(PMOP**);
10989 Renewc(mg->mg_ptr, elements + 1, PMOP*, char);
10990 ((PMOP**)mg->mg_ptr) [elements++] = pm;
10991 mg->mg_len = elements * sizeof(PMOP**);
10992 PmopSTASH_set(pm,PL_curstash);
10993 }
10994 }
5db06880
NC
10995#ifdef PERL_MAD
10996 modstart = s;
10997#endif
6136c704
AL
10998 while (*s && strchr(valid_flags, *s))
10999 pmflag(&pm->op_pmflags,*s++);
5db06880
NC
11000#ifdef PERL_MAD
11001 if (PL_madskills && modstart != s) {
11002 SV* tmptoken = newSVpvn(modstart, s - modstart);
11003 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
11004 }
11005#endif
4ac733c9 11006 /* issue a warning if /c is specified,but /g is not */
041457d9
DM
11007 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
11008 && ckWARN(WARN_REGEXP))
4ac733c9 11009 {
a20207d7
YO
11010 Perl_warner(aTHX_ packWARN(WARN_REGEXP),
11011 "Use of /c modifier is meaningless without /g" );
4ac733c9
MJD
11012 }
11013
3280af22 11014 PL_lex_op = (OP*)pm;
6154021b 11015 pl_yylval.ival = OP_MATCH;
378cc40b
LW
11016 return s;
11017}
11018
76e3520e 11019STATIC char *
cea2e8a9 11020S_scan_subst(pTHX_ char *start)
79072805 11021{
27da23d5 11022 dVAR;
a0d0e21e 11023 register char *s;
79072805 11024 register PMOP *pm;
4fdae800 11025 I32 first_start;
79072805 11026 I32 es = 0;
5db06880
NC
11027#ifdef PERL_MAD
11028 char *modstart;
11029#endif
79072805 11030
7918f24d
NC
11031 PERL_ARGS_ASSERT_SCAN_SUBST;
11032
6154021b 11033 pl_yylval.ival = OP_NULL;
79072805 11034
5db06880 11035 s = scan_str(start,!!PL_madskills,FALSE);
79072805 11036
37fd879b 11037 if (!s)
cea2e8a9 11038 Perl_croak(aTHX_ "Substitution pattern not terminated");
79072805 11039
3280af22 11040 if (s[-1] == PL_multi_open)
79072805 11041 s--;
5db06880
NC
11042#ifdef PERL_MAD
11043 if (PL_madskills) {
cd81e915
NC
11044 CURMAD('q', PL_thisopen);
11045 CURMAD('_', PL_thiswhite);
11046 CURMAD('E', PL_thisstuff);
11047 CURMAD('Q', PL_thisclose);
11048 PL_realtokenstart = s - SvPVX(PL_linestr);
5db06880
NC
11049 }
11050#endif
79072805 11051
3280af22 11052 first_start = PL_multi_start;
5db06880 11053 s = scan_str(s,!!PL_madskills,FALSE);
79072805 11054 if (!s) {
37fd879b 11055 if (PL_lex_stuff) {
3280af22 11056 SvREFCNT_dec(PL_lex_stuff);
a0714e2c 11057 PL_lex_stuff = NULL;
37fd879b 11058 }
cea2e8a9 11059 Perl_croak(aTHX_ "Substitution replacement not terminated");
a687059c 11060 }
3280af22 11061 PL_multi_start = first_start; /* so whole substitution is taken together */
2f3197b3 11062
79072805 11063 pm = (PMOP*)newPMOP(OP_SUBST, 0);
5db06880
NC
11064
11065#ifdef PERL_MAD
11066 if (PL_madskills) {
cd81e915
NC
11067 CURMAD('z', PL_thisopen);
11068 CURMAD('R', PL_thisstuff);
11069 CURMAD('Z', PL_thisclose);
5db06880
NC
11070 }
11071 modstart = s;
11072#endif
11073
48c036b1 11074 while (*s) {
a20207d7 11075 if (*s == EXEC_PAT_MOD) {
a687059c 11076 s++;
2f3197b3 11077 es++;
a687059c 11078 }
a20207d7 11079 else if (strchr(S_PAT_MODS, *s))
a0d0e21e 11080 pmflag(&pm->op_pmflags,*s++);
48c036b1
GS
11081 else
11082 break;
378cc40b 11083 }
79072805 11084
5db06880
NC
11085#ifdef PERL_MAD
11086 if (PL_madskills) {
11087 if (modstart != s)
11088 curmad('m', newSVpvn(modstart, s - modstart));
cd81e915
NC
11089 append_madprops(PL_thismad, (OP*)pm, 0);
11090 PL_thismad = 0;
5db06880
NC
11091 }
11092#endif
0bd48802
AL
11093 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
11094 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
4ac733c9
MJD
11095 }
11096
79072805 11097 if (es) {
6136c704
AL
11098 SV * const repl = newSVpvs("");
11099
0244c3a4
GS
11100 PL_sublex_info.super_bufptr = s;
11101 PL_sublex_info.super_bufend = PL_bufend;
11102 PL_multi_end = 0;
79072805 11103 pm->op_pmflags |= PMf_EVAL;
a5849ce5
NC
11104 while (es-- > 0) {
11105 if (es)
11106 sv_catpvs(repl, "eval ");
11107 else
11108 sv_catpvs(repl, "do ");
11109 }
6f43d98f 11110 sv_catpvs(repl, "{");
3280af22 11111 sv_catsv(repl, PL_lex_repl);
9badc361
RGS
11112 if (strchr(SvPVX(PL_lex_repl), '#'))
11113 sv_catpvs(repl, "\n");
11114 sv_catpvs(repl, "}");
25da4f38 11115 SvEVALED_on(repl);
3280af22
NIS
11116 SvREFCNT_dec(PL_lex_repl);
11117 PL_lex_repl = repl;
378cc40b 11118 }
79072805 11119
3280af22 11120 PL_lex_op = (OP*)pm;
6154021b 11121 pl_yylval.ival = OP_SUBST;
378cc40b
LW
11122 return s;
11123}
11124
76e3520e 11125STATIC char *
cea2e8a9 11126S_scan_trans(pTHX_ char *start)
378cc40b 11127{
97aff369 11128 dVAR;
a0d0e21e 11129 register char* s;
11343788 11130 OP *o;
79072805 11131 short *tbl;
b84c11c8
NC
11132 U8 squash;
11133 U8 del;
11134 U8 complement;
5db06880
NC
11135#ifdef PERL_MAD
11136 char *modstart;
11137#endif
79072805 11138
7918f24d
NC
11139 PERL_ARGS_ASSERT_SCAN_TRANS;
11140
6154021b 11141 pl_yylval.ival = OP_NULL;
79072805 11142
5db06880 11143 s = scan_str(start,!!PL_madskills,FALSE);
37fd879b 11144 if (!s)
cea2e8a9 11145 Perl_croak(aTHX_ "Transliteration pattern not terminated");
5db06880 11146
3280af22 11147 if (s[-1] == PL_multi_open)
2f3197b3 11148 s--;
5db06880
NC
11149#ifdef PERL_MAD
11150 if (PL_madskills) {
cd81e915
NC
11151 CURMAD('q', PL_thisopen);
11152 CURMAD('_', PL_thiswhite);
11153 CURMAD('E', PL_thisstuff);
11154 CURMAD('Q', PL_thisclose);
11155 PL_realtokenstart = s - SvPVX(PL_linestr);
5db06880
NC
11156 }
11157#endif
2f3197b3 11158
5db06880 11159 s = scan_str(s,!!PL_madskills,FALSE);
79072805 11160 if (!s) {
37fd879b 11161 if (PL_lex_stuff) {
3280af22 11162 SvREFCNT_dec(PL_lex_stuff);
a0714e2c 11163 PL_lex_stuff = NULL;
37fd879b 11164 }
cea2e8a9 11165 Perl_croak(aTHX_ "Transliteration replacement not terminated");
a687059c 11166 }
5db06880 11167 if (PL_madskills) {
cd81e915
NC
11168 CURMAD('z', PL_thisopen);
11169 CURMAD('R', PL_thisstuff);
11170 CURMAD('Z', PL_thisclose);
5db06880 11171 }
79072805 11172
a0ed51b3 11173 complement = del = squash = 0;
5db06880
NC
11174#ifdef PERL_MAD
11175 modstart = s;
11176#endif
7a1e2023
NC
11177 while (1) {
11178 switch (*s) {
11179 case 'c':
79072805 11180 complement = OPpTRANS_COMPLEMENT;
7a1e2023
NC
11181 break;
11182 case 'd':
a0ed51b3 11183 del = OPpTRANS_DELETE;
7a1e2023
NC
11184 break;
11185 case 's':
79072805 11186 squash = OPpTRANS_SQUASH;
7a1e2023
NC
11187 break;
11188 default:
11189 goto no_more;
11190 }
395c3793
LW
11191 s++;
11192 }
7a1e2023 11193 no_more:
8973db79 11194
aa1f7c5b 11195 tbl = (short *)PerlMemShared_calloc(complement&&!del?258:256, sizeof(short));
8973db79 11196 o = newPVOP(OP_TRANS, 0, (char*)tbl);
59f00321
RGS
11197 o->op_private &= ~OPpTRANS_ALL;
11198 o->op_private |= del|squash|complement|
7948272d
NIS
11199 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
11200 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
79072805 11201
3280af22 11202 PL_lex_op = o;
6154021b 11203 pl_yylval.ival = OP_TRANS;
5db06880
NC
11204
11205#ifdef PERL_MAD
11206 if (PL_madskills) {
11207 if (modstart != s)
11208 curmad('m', newSVpvn(modstart, s - modstart));
cd81e915
NC
11209 append_madprops(PL_thismad, o, 0);
11210 PL_thismad = 0;
5db06880
NC
11211 }
11212#endif
11213
79072805
LW
11214 return s;
11215}
11216
76e3520e 11217STATIC char *
cea2e8a9 11218S_scan_heredoc(pTHX_ register char *s)
79072805 11219{
97aff369 11220 dVAR;
79072805
LW
11221 SV *herewas;
11222 I32 op_type = OP_SCALAR;
11223 I32 len;
11224 SV *tmpstr;
11225 char term;
73d840c0 11226 const char *found_newline;
79072805 11227 register char *d;
fc36a67e 11228 register char *e;
4633a7c4 11229 char *peek;
f54cb97a 11230 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
5db06880
NC
11231#ifdef PERL_MAD
11232 I32 stuffstart = s - SvPVX(PL_linestr);
11233 char *tstart;
11234
cd81e915 11235 PL_realtokenstart = -1;
5db06880 11236#endif
79072805 11237
7918f24d
NC
11238 PERL_ARGS_ASSERT_SCAN_HEREDOC;
11239
79072805 11240 s += 2;
3280af22
NIS
11241 d = PL_tokenbuf;
11242 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
fd2d0953 11243 if (!outer)
79072805 11244 *d++ = '\n';
c35e046a
AL
11245 peek = s;
11246 while (SPACE_OR_TAB(*peek))
11247 peek++;
3792a11b 11248 if (*peek == '`' || *peek == '\'' || *peek =='"') {
4633a7c4 11249 s = peek;
79072805 11250 term = *s++;
3280af22 11251 s = delimcpy(d, e, s, PL_bufend, term, &len);
fc36a67e 11252 d += len;
3280af22 11253 if (s < PL_bufend)
79072805 11254 s++;
79072805
LW
11255 }
11256 else {
11257 if (*s == '\\')
11258 s++, term = '\'';
11259 else
11260 term = '"';
7e2040f0 11261 if (!isALNUM_lazy_if(s,UTF))
12bcd1a6 11262 deprecate_old("bare << to mean <<\"\"");
7e2040f0 11263 for (; isALNUM_lazy_if(s,UTF); s++) {
fc36a67e 11264 if (d < e)
11265 *d++ = *s;
11266 }
11267 }
3280af22 11268 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
cea2e8a9 11269 Perl_croak(aTHX_ "Delimiter for here document is too long");
79072805
LW
11270 *d++ = '\n';
11271 *d = '\0';
3280af22 11272 len = d - PL_tokenbuf;
5db06880
NC
11273
11274#ifdef PERL_MAD
11275 if (PL_madskills) {
11276 tstart = PL_tokenbuf + !outer;
cd81e915 11277 PL_thisclose = newSVpvn(tstart, len - !outer);
5db06880 11278 tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915 11279 PL_thisopen = newSVpvn(tstart, s - tstart);
5db06880
NC
11280 stuffstart = s - SvPVX(PL_linestr);
11281 }
11282#endif
6a27c188 11283#ifndef PERL_STRICT_CR
f63a84b2
LW
11284 d = strchr(s, '\r');
11285 if (d) {
b464bac0 11286 char * const olds = s;
f63a84b2 11287 s = d;
3280af22 11288 while (s < PL_bufend) {
f63a84b2
LW
11289 if (*s == '\r') {
11290 *d++ = '\n';
11291 if (*++s == '\n')
11292 s++;
11293 }
11294 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
11295 *d++ = *s++;
11296 s++;
11297 }
11298 else
11299 *d++ = *s++;
11300 }
11301 *d = '\0';
3280af22 11302 PL_bufend = d;
95a20fc0 11303 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
f63a84b2
LW
11304 s = olds;
11305 }
11306#endif
5db06880
NC
11307#ifdef PERL_MAD
11308 found_newline = 0;
11309#endif
10edeb5d 11310 if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
73d840c0
AL
11311 herewas = newSVpvn(s,PL_bufend-s);
11312 }
11313 else {
5db06880
NC
11314#ifdef PERL_MAD
11315 herewas = newSVpvn(s-1,found_newline-s+1);
11316#else
73d840c0
AL
11317 s--;
11318 herewas = newSVpvn(s,found_newline-s);
5db06880 11319#endif
73d840c0 11320 }
5db06880
NC
11321#ifdef PERL_MAD
11322 if (PL_madskills) {
11323 tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915
NC
11324 if (PL_thisstuff)
11325 sv_catpvn(PL_thisstuff, tstart, s - tstart);
5db06880 11326 else
cd81e915 11327 PL_thisstuff = newSVpvn(tstart, s - tstart);
5db06880
NC
11328 }
11329#endif
79072805 11330 s += SvCUR(herewas);
748a9306 11331
5db06880
NC
11332#ifdef PERL_MAD
11333 stuffstart = s - SvPVX(PL_linestr);
11334
11335 if (found_newline)
11336 s--;
11337#endif
11338
7d0a29fe
NC
11339 tmpstr = newSV_type(SVt_PVIV);
11340 SvGROW(tmpstr, 80);
748a9306 11341 if (term == '\'') {
79072805 11342 op_type = OP_CONST;
45977657 11343 SvIV_set(tmpstr, -1);
748a9306
LW
11344 }
11345 else if (term == '`') {
79072805 11346 op_type = OP_BACKTICK;
45977657 11347 SvIV_set(tmpstr, '\\');
748a9306 11348 }
79072805
LW
11349
11350 CLINE;
57843af0 11351 PL_multi_start = CopLINE(PL_curcop);
3280af22
NIS
11352 PL_multi_open = PL_multi_close = '<';
11353 term = *PL_tokenbuf;
0244c3a4 11354 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
6136c704
AL
11355 char * const bufptr = PL_sublex_info.super_bufptr;
11356 char * const bufend = PL_sublex_info.super_bufend;
b464bac0 11357 char * const olds = s - SvCUR(herewas);
0244c3a4
GS
11358 s = strchr(bufptr, '\n');
11359 if (!s)
11360 s = bufend;
11361 d = s;
11362 while (s < bufend &&
11363 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11364 if (*s++ == '\n')
57843af0 11365 CopLINE_inc(PL_curcop);
0244c3a4
GS
11366 }
11367 if (s >= bufend) {
eb160463 11368 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
0244c3a4
GS
11369 missingterm(PL_tokenbuf);
11370 }
11371 sv_setpvn(herewas,bufptr,d-bufptr+1);
11372 sv_setpvn(tmpstr,d+1,s-d);
11373 s += len - 1;
11374 sv_catpvn(herewas,s,bufend-s);
95a20fc0 11375 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
0244c3a4
GS
11376
11377 s = olds;
11378 goto retval;
11379 }
11380 else if (!outer) {
79072805 11381 d = s;
3280af22
NIS
11382 while (s < PL_bufend &&
11383 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
79072805 11384 if (*s++ == '\n')
57843af0 11385 CopLINE_inc(PL_curcop);
79072805 11386 }
3280af22 11387 if (s >= PL_bufend) {
eb160463 11388 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
3280af22 11389 missingterm(PL_tokenbuf);
79072805
LW
11390 }
11391 sv_setpvn(tmpstr,d+1,s-d);
5db06880
NC
11392#ifdef PERL_MAD
11393 if (PL_madskills) {
cd81e915
NC
11394 if (PL_thisstuff)
11395 sv_catpvn(PL_thisstuff, d + 1, s - d);
5db06880 11396 else
cd81e915 11397 PL_thisstuff = newSVpvn(d + 1, s - d);
5db06880
NC
11398 stuffstart = s - SvPVX(PL_linestr);
11399 }
11400#endif
79072805 11401 s += len - 1;
57843af0 11402 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
49d8d3a1 11403
3280af22
NIS
11404 sv_catpvn(herewas,s,PL_bufend-s);
11405 sv_setsv(PL_linestr,herewas);
11406 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11407 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 11408 PL_last_lop = PL_last_uni = NULL;
79072805
LW
11409 }
11410 else
76f68e9b 11411 sv_setpvs(tmpstr,""); /* avoid "uninitialized" warning */
3280af22 11412 while (s >= PL_bufend) { /* multiple line string? */
5db06880
NC
11413#ifdef PERL_MAD
11414 if (PL_madskills) {
11415 tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915
NC
11416 if (PL_thisstuff)
11417 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
5db06880 11418 else
cd81e915 11419 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
5db06880
NC
11420 }
11421#endif
fd2d0953 11422 if (!outer ||
3280af22 11423 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
eb160463 11424 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
3280af22 11425 missingterm(PL_tokenbuf);
79072805 11426 }
5db06880
NC
11427#ifdef PERL_MAD
11428 stuffstart = s - SvPVX(PL_linestr);
11429#endif
57843af0 11430 CopLINE_inc(PL_curcop);
3280af22 11431 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 11432 PL_last_lop = PL_last_uni = NULL;
6a27c188 11433#ifndef PERL_STRICT_CR
3280af22 11434 if (PL_bufend - PL_linestart >= 2) {
a1529941
NIS
11435 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11436 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
c6f14548 11437 {
3280af22
NIS
11438 PL_bufend[-2] = '\n';
11439 PL_bufend--;
95a20fc0 11440 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
f63a84b2 11441 }
3280af22
NIS
11442 else if (PL_bufend[-1] == '\r')
11443 PL_bufend[-1] = '\n';
f63a84b2 11444 }
3280af22
NIS
11445 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11446 PL_bufend[-1] = '\n';
f63a84b2 11447#endif
65269a95 11448 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
5fa550fb 11449 update_debugger_info(PL_linestr, NULL, 0);
3280af22 11450 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
95a20fc0 11451 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
1de9afcd 11452 *(SvPVX(PL_linestr) + off ) = ' ';
3280af22
NIS
11453 sv_catsv(PL_linestr,herewas);
11454 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1de9afcd 11455 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
79072805
LW
11456 }
11457 else {
3280af22
NIS
11458 s = PL_bufend;
11459 sv_catsv(tmpstr,PL_linestr);
395c3793
LW
11460 }
11461 }
79072805 11462 s++;
0244c3a4 11463retval:
57843af0 11464 PL_multi_end = CopLINE(PL_curcop);
79072805 11465 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
1da4ca5f 11466 SvPV_shrink_to_cur(tmpstr);
79072805 11467 }
8990e307 11468 SvREFCNT_dec(herewas);
2f31ce75 11469 if (!IN_BYTES) {
95a20fc0 11470 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
2f31ce75
JH
11471 SvUTF8_on(tmpstr);
11472 else if (PL_encoding)
11473 sv_recode_to_utf8(tmpstr, PL_encoding);
11474 }
3280af22 11475 PL_lex_stuff = tmpstr;
6154021b 11476 pl_yylval.ival = op_type;
79072805
LW
11477 return s;
11478}
11479
02aa26ce
NT
11480/* scan_inputsymbol
11481 takes: current position in input buffer
11482 returns: new position in input buffer
6154021b 11483 side-effects: pl_yylval and lex_op are set.
02aa26ce
NT
11484
11485 This code handles:
11486
11487 <> read from ARGV
11488 <FH> read from filehandle
11489 <pkg::FH> read from package qualified filehandle
11490 <pkg'FH> read from package qualified filehandle
11491 <$fh> read from filehandle in $fh
11492 <*.h> filename glob
11493
11494*/
11495
76e3520e 11496STATIC char *
cea2e8a9 11497S_scan_inputsymbol(pTHX_ char *start)
79072805 11498{
97aff369 11499 dVAR;
02aa26ce 11500 register char *s = start; /* current position in buffer */
1b420867 11501 char *end;
79072805 11502 I32 len;
6136c704
AL
11503 char *d = PL_tokenbuf; /* start of temp holding space */
11504 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11505
7918f24d
NC
11506 PERL_ARGS_ASSERT_SCAN_INPUTSYMBOL;
11507
1b420867
GS
11508 end = strchr(s, '\n');
11509 if (!end)
11510 end = PL_bufend;
11511 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
02aa26ce
NT
11512
11513 /* die if we didn't have space for the contents of the <>,
1b420867 11514 or if it didn't end, or if we see a newline
02aa26ce
NT
11515 */
11516
bb7a0f54 11517 if (len >= (I32)sizeof PL_tokenbuf)
cea2e8a9 11518 Perl_croak(aTHX_ "Excessively long <> operator");
1b420867 11519 if (s >= end)
cea2e8a9 11520 Perl_croak(aTHX_ "Unterminated <> operator");
02aa26ce 11521
fc36a67e 11522 s++;
02aa26ce
NT
11523
11524 /* check for <$fh>
11525 Remember, only scalar variables are interpreted as filehandles by
11526 this code. Anything more complex (e.g., <$fh{$num}>) will be
11527 treated as a glob() call.
11528 This code makes use of the fact that except for the $ at the front,
11529 a scalar variable and a filehandle look the same.
11530 */
4633a7c4 11531 if (*d == '$' && d[1]) d++;
02aa26ce
NT
11532
11533 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
7e2040f0 11534 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
79072805 11535 d++;
02aa26ce
NT
11536
11537 /* If we've tried to read what we allow filehandles to look like, and
11538 there's still text left, then it must be a glob() and not a getline.
11539 Use scan_str to pull out the stuff between the <> and treat it
11540 as nothing more than a string.
11541 */
11542
3280af22 11543 if (d - PL_tokenbuf != len) {
6154021b 11544 pl_yylval.ival = OP_GLOB;
5db06880 11545 s = scan_str(start,!!PL_madskills,FALSE);
79072805 11546 if (!s)
cea2e8a9 11547 Perl_croak(aTHX_ "Glob not terminated");
79072805
LW
11548 return s;
11549 }
395c3793 11550 else {
9b3023bc 11551 bool readline_overriden = FALSE;
6136c704 11552 GV *gv_readline;
9b3023bc 11553 GV **gvp;
02aa26ce 11554 /* we're in a filehandle read situation */
3280af22 11555 d = PL_tokenbuf;
02aa26ce
NT
11556
11557 /* turn <> into <ARGV> */
79072805 11558 if (!len)
689badd5 11559 Copy("ARGV",d,5,char);
02aa26ce 11560
9b3023bc 11561 /* Check whether readline() is overriden */
fafc274c 11562 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
6136c704 11563 if ((gv_readline
ba979b31 11564 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
9b3023bc 11565 ||
017a3ce5 11566 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
9e0d86f8 11567 && (gv_readline = *gvp) && isGV_with_GP(gv_readline)
ba979b31 11568 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
9b3023bc
RGS
11569 readline_overriden = TRUE;
11570
02aa26ce
NT
11571 /* if <$fh>, create the ops to turn the variable into a
11572 filehandle
11573 */
79072805 11574 if (*d == '$') {
02aa26ce
NT
11575 /* try to find it in the pad for this block, otherwise find
11576 add symbol table ops
11577 */
bbd11bfc
AL
11578 const PADOFFSET tmp = pad_findmy(d);
11579 if (tmp != NOT_IN_PAD) {
00b1698f 11580 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6136c704
AL
11581 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11582 HEK * const stashname = HvNAME_HEK(stash);
11583 SV * const sym = sv_2mortal(newSVhek(stashname));
396482e1 11584 sv_catpvs(sym, "::");
f558d5af
JH
11585 sv_catpv(sym, d+1);
11586 d = SvPVX(sym);
11587 goto intro_sym;
11588 }
11589 else {
6136c704 11590 OP * const o = newOP(OP_PADSV, 0);
f558d5af 11591 o->op_targ = tmp;
9b3023bc
RGS
11592 PL_lex_op = readline_overriden
11593 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11594 append_elem(OP_LIST, o,
11595 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11596 : (OP*)newUNOP(OP_READLINE, 0, o);
f558d5af 11597 }
a0d0e21e
LW
11598 }
11599 else {
f558d5af
JH
11600 GV *gv;
11601 ++d;
11602intro_sym:
11603 gv = gv_fetchpv(d,
11604 (PL_in_eval
11605 ? (GV_ADDMULTI | GV_ADDINEVAL)
bea70d1e 11606 : GV_ADDMULTI),
f558d5af 11607 SVt_PV);
9b3023bc
RGS
11608 PL_lex_op = readline_overriden
11609 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11610 append_elem(OP_LIST,
11611 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11612 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11613 : (OP*)newUNOP(OP_READLINE, 0,
11614 newUNOP(OP_RV2SV, 0,
11615 newGVOP(OP_GV, 0, gv)));
a0d0e21e 11616 }
7c6fadd6
RGS
11617 if (!readline_overriden)
11618 PL_lex_op->op_flags |= OPf_SPECIAL;
6154021b
RGS
11619 /* we created the ops in PL_lex_op, so make pl_yylval.ival a null op */
11620 pl_yylval.ival = OP_NULL;
79072805 11621 }
02aa26ce
NT
11622
11623 /* If it's none of the above, it must be a literal filehandle
11624 (<Foo::BAR> or <FOO>) so build a simple readline OP */
79072805 11625 else {
6136c704 11626 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
9b3023bc
RGS
11627 PL_lex_op = readline_overriden
11628 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11629 append_elem(OP_LIST,
11630 newGVOP(OP_GV, 0, gv),
11631 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11632 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
6154021b 11633 pl_yylval.ival = OP_NULL;
79072805
LW
11634 }
11635 }
02aa26ce 11636
79072805
LW
11637 return s;
11638}
11639
02aa26ce
NT
11640
11641/* scan_str
11642 takes: start position in buffer
09bef843
SB
11643 keep_quoted preserve \ on the embedded delimiter(s)
11644 keep_delims preserve the delimiters around the string
02aa26ce
NT
11645 returns: position to continue reading from buffer
11646 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11647 updates the read buffer.
11648
11649 This subroutine pulls a string out of the input. It is called for:
11650 q single quotes q(literal text)
11651 ' single quotes 'literal text'
11652 qq double quotes qq(interpolate $here please)
11653 " double quotes "interpolate $here please"
11654 qx backticks qx(/bin/ls -l)
11655 ` backticks `/bin/ls -l`
11656 qw quote words @EXPORT_OK = qw( func() $spam )
11657 m// regexp match m/this/
11658 s/// regexp substitute s/this/that/
11659 tr/// string transliterate tr/this/that/
11660 y/// string transliterate y/this/that/
11661 ($*@) sub prototypes sub foo ($)
09bef843 11662 (stuff) sub attr parameters sub foo : attr(stuff)
02aa26ce
NT
11663 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11664
11665 In most of these cases (all but <>, patterns and transliterate)
11666 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11667 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11668 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11669 calls scan_str().
4e553d73 11670
02aa26ce
NT
11671 It skips whitespace before the string starts, and treats the first
11672 character as the delimiter. If the delimiter is one of ([{< then
11673 the corresponding "close" character )]}> is used as the closing
11674 delimiter. It allows quoting of delimiters, and if the string has
11675 balanced delimiters ([{<>}]) it allows nesting.
11676
37fd879b
HS
11677 On success, the SV with the resulting string is put into lex_stuff or,
11678 if that is already non-NULL, into lex_repl. The second case occurs only
11679 when parsing the RHS of the special constructs s/// and tr/// (y///).
11680 For convenience, the terminating delimiter character is stuffed into
11681 SvIVX of the SV.
02aa26ce
NT
11682*/
11683
76e3520e 11684STATIC char *
09bef843 11685S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
79072805 11686{
97aff369 11687 dVAR;
02aa26ce 11688 SV *sv; /* scalar value: string */
d3fcec1f 11689 const char *tmps; /* temp string, used for delimiter matching */
02aa26ce
NT
11690 register char *s = start; /* current position in the buffer */
11691 register char term; /* terminating character */
11692 register char *to; /* current position in the sv's data */
11693 I32 brackets = 1; /* bracket nesting level */
89491803 11694 bool has_utf8 = FALSE; /* is there any utf8 content? */
220e2d4e 11695 I32 termcode; /* terminating char. code */
89ebb4a3 11696 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
220e2d4e 11697 STRLEN termlen; /* length of terminating string */
0331ef07 11698 int last_off = 0; /* last position for nesting bracket */
5db06880
NC
11699#ifdef PERL_MAD
11700 int stuffstart;
11701 char *tstart;
11702#endif
02aa26ce 11703
7918f24d
NC
11704 PERL_ARGS_ASSERT_SCAN_STR;
11705
02aa26ce 11706 /* skip space before the delimiter */
29595ff2
NC
11707 if (isSPACE(*s)) {
11708 s = PEEKSPACE(s);
11709 }
02aa26ce 11710
5db06880 11711#ifdef PERL_MAD
cd81e915
NC
11712 if (PL_realtokenstart >= 0) {
11713 stuffstart = PL_realtokenstart;
11714 PL_realtokenstart = -1;
5db06880
NC
11715 }
11716 else
11717 stuffstart = start - SvPVX(PL_linestr);
11718#endif
02aa26ce 11719 /* mark where we are, in case we need to report errors */
79072805 11720 CLINE;
02aa26ce
NT
11721
11722 /* after skipping whitespace, the next character is the terminator */
a0d0e21e 11723 term = *s;
220e2d4e
IH
11724 if (!UTF) {
11725 termcode = termstr[0] = term;
11726 termlen = 1;
11727 }
11728 else {
f3b9ce0f 11729 termcode = utf8_to_uvchr((U8*)s, &termlen);
220e2d4e
IH
11730 Copy(s, termstr, termlen, U8);
11731 if (!UTF8_IS_INVARIANT(term))
11732 has_utf8 = TRUE;
11733 }
b1c7b182 11734
02aa26ce 11735 /* mark where we are */
57843af0 11736 PL_multi_start = CopLINE(PL_curcop);
3280af22 11737 PL_multi_open = term;
02aa26ce
NT
11738
11739 /* find corresponding closing delimiter */
93a17b20 11740 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
220e2d4e
IH
11741 termcode = termstr[0] = term = tmps[5];
11742
3280af22 11743 PL_multi_close = term;
79072805 11744
561b68a9
SH
11745 /* create a new SV to hold the contents. 79 is the SV's initial length.
11746 What a random number. */
7d0a29fe
NC
11747 sv = newSV_type(SVt_PVIV);
11748 SvGROW(sv, 80);
45977657 11749 SvIV_set(sv, termcode);
a0d0e21e 11750 (void)SvPOK_only(sv); /* validate pointer */
02aa26ce
NT
11751
11752 /* move past delimiter and try to read a complete string */
09bef843 11753 if (keep_delims)
220e2d4e
IH
11754 sv_catpvn(sv, s, termlen);
11755 s += termlen;
5db06880
NC
11756#ifdef PERL_MAD
11757 tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915
NC
11758 if (!PL_thisopen && !keep_delims) {
11759 PL_thisopen = newSVpvn(tstart, s - tstart);
5db06880
NC
11760 stuffstart = s - SvPVX(PL_linestr);
11761 }
11762#endif
93a17b20 11763 for (;;) {
220e2d4e
IH
11764 if (PL_encoding && !UTF) {
11765 bool cont = TRUE;
11766
11767 while (cont) {
95a20fc0 11768 int offset = s - SvPVX_const(PL_linestr);
66a1b24b 11769 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
f3b9ce0f 11770 &offset, (char*)termstr, termlen);
6136c704
AL
11771 const char * const ns = SvPVX_const(PL_linestr) + offset;
11772 char * const svlast = SvEND(sv) - 1;
220e2d4e
IH
11773
11774 for (; s < ns; s++) {
11775 if (*s == '\n' && !PL_rsfp)
11776 CopLINE_inc(PL_curcop);
11777 }
11778 if (!found)
11779 goto read_more_line;
11780 else {
11781 /* handle quoted delimiters */
52327caf 11782 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
f54cb97a 11783 const char *t;
95a20fc0 11784 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
220e2d4e
IH
11785 t--;
11786 if ((svlast-1 - t) % 2) {
11787 if (!keep_quoted) {
11788 *(svlast-1) = term;
11789 *svlast = '\0';
11790 SvCUR_set(sv, SvCUR(sv) - 1);
11791 }
11792 continue;
11793 }
11794 }
11795 if (PL_multi_open == PL_multi_close) {
11796 cont = FALSE;
11797 }
11798 else {
f54cb97a
AL
11799 const char *t;
11800 char *w;
0331ef07 11801 for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
220e2d4e
IH
11802 /* At here, all closes are "was quoted" one,
11803 so we don't check PL_multi_close. */
11804 if (*t == '\\') {
11805 if (!keep_quoted && *(t+1) == PL_multi_open)
11806 t++;
11807 else
11808 *w++ = *t++;
11809 }
11810 else if (*t == PL_multi_open)
11811 brackets++;
11812
11813 *w = *t;
11814 }
11815 if (w < t) {
11816 *w++ = term;
11817 *w = '\0';
95a20fc0 11818 SvCUR_set(sv, w - SvPVX_const(sv));
220e2d4e 11819 }
0331ef07 11820 last_off = w - SvPVX(sv);
220e2d4e
IH
11821 if (--brackets <= 0)
11822 cont = FALSE;
11823 }
11824 }
11825 }
11826 if (!keep_delims) {
11827 SvCUR_set(sv, SvCUR(sv) - 1);
11828 *SvEND(sv) = '\0';
11829 }
11830 break;
11831 }
11832
02aa26ce 11833 /* extend sv if need be */
3280af22 11834 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
02aa26ce 11835 /* set 'to' to the next character in the sv's string */
463ee0b2 11836 to = SvPVX(sv)+SvCUR(sv);
09bef843 11837
02aa26ce 11838 /* if open delimiter is the close delimiter read unbridle */
3280af22
NIS
11839 if (PL_multi_open == PL_multi_close) {
11840 for (; s < PL_bufend; s++,to++) {
02aa26ce 11841 /* embedded newlines increment the current line number */
3280af22 11842 if (*s == '\n' && !PL_rsfp)
57843af0 11843 CopLINE_inc(PL_curcop);
02aa26ce 11844 /* handle quoted delimiters */
3280af22 11845 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
09bef843 11846 if (!keep_quoted && s[1] == term)
a0d0e21e 11847 s++;
02aa26ce 11848 /* any other quotes are simply copied straight through */
a0d0e21e
LW
11849 else
11850 *to++ = *s++;
11851 }
02aa26ce
NT
11852 /* terminate when run out of buffer (the for() condition), or
11853 have found the terminator */
220e2d4e
IH
11854 else if (*s == term) {
11855 if (termlen == 1)
11856 break;
f3b9ce0f 11857 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
220e2d4e
IH
11858 break;
11859 }
63cd0674 11860 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
89491803 11861 has_utf8 = TRUE;
93a17b20
LW
11862 *to = *s;
11863 }
11864 }
02aa26ce
NT
11865
11866 /* if the terminator isn't the same as the start character (e.g.,
11867 matched brackets), we have to allow more in the quoting, and
11868 be prepared for nested brackets.
11869 */
93a17b20 11870 else {
02aa26ce 11871 /* read until we run out of string, or we find the terminator */
3280af22 11872 for (; s < PL_bufend; s++,to++) {
02aa26ce 11873 /* embedded newlines increment the line count */
3280af22 11874 if (*s == '\n' && !PL_rsfp)
57843af0 11875 CopLINE_inc(PL_curcop);
02aa26ce 11876 /* backslashes can escape the open or closing characters */
3280af22 11877 if (*s == '\\' && s+1 < PL_bufend) {
09bef843
SB
11878 if (!keep_quoted &&
11879 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
a0d0e21e
LW
11880 s++;
11881 else
11882 *to++ = *s++;
11883 }
02aa26ce 11884 /* allow nested opens and closes */
3280af22 11885 else if (*s == PL_multi_close && --brackets <= 0)
93a17b20 11886 break;
3280af22 11887 else if (*s == PL_multi_open)
93a17b20 11888 brackets++;
63cd0674 11889 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
89491803 11890 has_utf8 = TRUE;
93a17b20
LW
11891 *to = *s;
11892 }
11893 }
02aa26ce 11894 /* terminate the copied string and update the sv's end-of-string */
93a17b20 11895 *to = '\0';
95a20fc0 11896 SvCUR_set(sv, to - SvPVX_const(sv));
93a17b20 11897
02aa26ce
NT
11898 /*
11899 * this next chunk reads more into the buffer if we're not done yet
11900 */
11901
b1c7b182
GS
11902 if (s < PL_bufend)
11903 break; /* handle case where we are done yet :-) */
79072805 11904
6a27c188 11905#ifndef PERL_STRICT_CR
95a20fc0 11906 if (to - SvPVX_const(sv) >= 2) {
c6f14548
GS
11907 if ((to[-2] == '\r' && to[-1] == '\n') ||
11908 (to[-2] == '\n' && to[-1] == '\r'))
11909 {
f63a84b2
LW
11910 to[-2] = '\n';
11911 to--;
95a20fc0 11912 SvCUR_set(sv, to - SvPVX_const(sv));
f63a84b2
LW
11913 }
11914 else if (to[-1] == '\r')
11915 to[-1] = '\n';
11916 }
95a20fc0 11917 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
f63a84b2
LW
11918 to[-1] = '\n';
11919#endif
11920
220e2d4e 11921 read_more_line:
02aa26ce
NT
11922 /* if we're out of file, or a read fails, bail and reset the current
11923 line marker so we can report where the unterminated string began
11924 */
5db06880
NC
11925#ifdef PERL_MAD
11926 if (PL_madskills) {
c35e046a 11927 char * const tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915
NC
11928 if (PL_thisstuff)
11929 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
5db06880 11930 else
cd81e915 11931 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
5db06880
NC
11932 }
11933#endif
3280af22
NIS
11934 if (!PL_rsfp ||
11935 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
c07a80fd 11936 sv_free(sv);
eb160463 11937 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
bd61b366 11938 return NULL;
79072805 11939 }
5db06880
NC
11940#ifdef PERL_MAD
11941 stuffstart = 0;
11942#endif
02aa26ce 11943 /* we read a line, so increment our line counter */
57843af0 11944 CopLINE_inc(PL_curcop);
a0ed51b3 11945
02aa26ce 11946 /* update debugger info */
65269a95 11947 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
5fa550fb 11948 update_debugger_info(PL_linestr, NULL, 0);
a0ed51b3 11949
3280af22
NIS
11950 /* having changed the buffer, we must update PL_bufend */
11951 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 11952 PL_last_lop = PL_last_uni = NULL;
378cc40b 11953 }
4e553d73 11954
02aa26ce
NT
11955 /* at this point, we have successfully read the delimited string */
11956
220e2d4e 11957 if (!PL_encoding || UTF) {
5db06880
NC
11958#ifdef PERL_MAD
11959 if (PL_madskills) {
c35e046a 11960 char * const tstart = SvPVX(PL_linestr) + stuffstart;
29522234 11961 const int len = s - tstart;
cd81e915 11962 if (PL_thisstuff)
c35e046a 11963 sv_catpvn(PL_thisstuff, tstart, len);
5db06880 11964 else
c35e046a 11965 PL_thisstuff = newSVpvn(tstart, len);
cd81e915
NC
11966 if (!PL_thisclose && !keep_delims)
11967 PL_thisclose = newSVpvn(s,termlen);
5db06880
NC
11968 }
11969#endif
11970
220e2d4e
IH
11971 if (keep_delims)
11972 sv_catpvn(sv, s, termlen);
11973 s += termlen;
11974 }
5db06880
NC
11975#ifdef PERL_MAD
11976 else {
11977 if (PL_madskills) {
c35e046a
AL
11978 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11979 const int len = s - tstart - termlen;
cd81e915 11980 if (PL_thisstuff)
c35e046a 11981 sv_catpvn(PL_thisstuff, tstart, len);
5db06880 11982 else
c35e046a 11983 PL_thisstuff = newSVpvn(tstart, len);
cd81e915
NC
11984 if (!PL_thisclose && !keep_delims)
11985 PL_thisclose = newSVpvn(s - termlen,termlen);
5db06880
NC
11986 }
11987 }
11988#endif
220e2d4e 11989 if (has_utf8 || PL_encoding)
b1c7b182 11990 SvUTF8_on(sv);
d0063567 11991
57843af0 11992 PL_multi_end = CopLINE(PL_curcop);
02aa26ce
NT
11993
11994 /* if we allocated too much space, give some back */
93a17b20
LW
11995 if (SvCUR(sv) + 5 < SvLEN(sv)) {
11996 SvLEN_set(sv, SvCUR(sv) + 1);
b7e9a5c2 11997 SvPV_renew(sv, SvLEN(sv));
79072805 11998 }
02aa26ce
NT
11999
12000 /* decide whether this is the first or second quoted string we've read
12001 for this op
12002 */
4e553d73 12003
3280af22
NIS
12004 if (PL_lex_stuff)
12005 PL_lex_repl = sv;
79072805 12006 else
3280af22 12007 PL_lex_stuff = sv;
378cc40b
LW
12008 return s;
12009}
12010
02aa26ce
NT
12011/*
12012 scan_num
12013 takes: pointer to position in buffer
12014 returns: pointer to new position in buffer
6154021b 12015 side-effects: builds ops for the constant in pl_yylval.op
02aa26ce
NT
12016
12017 Read a number in any of the formats that Perl accepts:
12018
7fd134d9
JH
12019 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
12020 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
24138b49
JH
12021 0b[01](_?[01])*
12022 0[0-7](_?[0-7])*
12023 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
02aa26ce 12024
3280af22 12025 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
02aa26ce
NT
12026 thing it reads.
12027
12028 If it reads a number without a decimal point or an exponent, it will
12029 try converting the number to an integer and see if it can do so
12030 without loss of precision.
12031*/
4e553d73 12032
378cc40b 12033char *
bfed75c6 12034Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
378cc40b 12035{
97aff369 12036 dVAR;
bfed75c6 12037 register const char *s = start; /* current position in buffer */
02aa26ce
NT
12038 register char *d; /* destination in temp buffer */
12039 register char *e; /* end of temp buffer */
86554af2 12040 NV nv; /* number read, as a double */
a0714e2c 12041 SV *sv = NULL; /* place to put the converted number */
a86a20aa 12042 bool floatit; /* boolean: int or float? */
cbbf8932 12043 const char *lastub = NULL; /* position of last underbar */
bfed75c6 12044 static char const number_too_long[] = "Number too long";
378cc40b 12045
7918f24d
NC
12046 PERL_ARGS_ASSERT_SCAN_NUM;
12047
02aa26ce
NT
12048 /* We use the first character to decide what type of number this is */
12049
378cc40b 12050 switch (*s) {
79072805 12051 default:
cea2e8a9 12052 Perl_croak(aTHX_ "panic: scan_num");
4e553d73 12053
02aa26ce 12054 /* if it starts with a 0, it could be an octal number, a decimal in
a7cb1f99 12055 0.13 disguise, or a hexadecimal number, or a binary number. */
378cc40b
LW
12056 case '0':
12057 {
02aa26ce
NT
12058 /* variables:
12059 u holds the "number so far"
4f19785b
WSI
12060 shift the power of 2 of the base
12061 (hex == 4, octal == 3, binary == 1)
02aa26ce
NT
12062 overflowed was the number more than we can hold?
12063
12064 Shift is used when we add a digit. It also serves as an "are
4f19785b
WSI
12065 we in octal/hex/binary?" indicator to disallow hex characters
12066 when in octal mode.
02aa26ce 12067 */
9e24b6e2
JH
12068 NV n = 0.0;
12069 UV u = 0;
79072805 12070 I32 shift;
9e24b6e2 12071 bool overflowed = FALSE;
61f33854 12072 bool just_zero = TRUE; /* just plain 0 or binary number? */
27da23d5
JH
12073 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
12074 static const char* const bases[5] =
12075 { "", "binary", "", "octal", "hexadecimal" };
12076 static const char* const Bases[5] =
12077 { "", "Binary", "", "Octal", "Hexadecimal" };
12078 static const char* const maxima[5] =
12079 { "",
12080 "0b11111111111111111111111111111111",
12081 "",
12082 "037777777777",
12083 "0xffffffff" };
bfed75c6 12084 const char *base, *Base, *max;
378cc40b 12085
02aa26ce 12086 /* check for hex */
378cc40b
LW
12087 if (s[1] == 'x') {
12088 shift = 4;
12089 s += 2;
61f33854 12090 just_zero = FALSE;
4f19785b
WSI
12091 } else if (s[1] == 'b') {
12092 shift = 1;
12093 s += 2;
61f33854 12094 just_zero = FALSE;
378cc40b 12095 }
02aa26ce 12096 /* check for a decimal in disguise */
b78218b7 12097 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
378cc40b 12098 goto decimal;
02aa26ce 12099 /* so it must be octal */
928753ea 12100 else {
378cc40b 12101 shift = 3;
928753ea
JH
12102 s++;
12103 }
12104
12105 if (*s == '_') {
12106 if (ckWARN(WARN_SYNTAX))
9014280d 12107 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
928753ea
JH
12108 "Misplaced _ in number");
12109 lastub = s++;
12110 }
9e24b6e2
JH
12111
12112 base = bases[shift];
12113 Base = Bases[shift];
12114 max = maxima[shift];
02aa26ce 12115
4f19785b 12116 /* read the rest of the number */
378cc40b 12117 for (;;) {
9e24b6e2 12118 /* x is used in the overflow test,
893fe2c2 12119 b is the digit we're adding on. */
9e24b6e2 12120 UV x, b;
55497cff 12121
378cc40b 12122 switch (*s) {
02aa26ce
NT
12123
12124 /* if we don't mention it, we're done */
378cc40b
LW
12125 default:
12126 goto out;
02aa26ce 12127
928753ea 12128 /* _ are ignored -- but warned about if consecutive */
de3bb511 12129 case '_':
041457d9 12130 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
9014280d 12131 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
928753ea
JH
12132 "Misplaced _ in number");
12133 lastub = s++;
de3bb511 12134 break;
02aa26ce
NT
12135
12136 /* 8 and 9 are not octal */
378cc40b 12137 case '8': case '9':
4f19785b 12138 if (shift == 3)
cea2e8a9 12139 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
378cc40b 12140 /* FALL THROUGH */
02aa26ce
NT
12141
12142 /* octal digits */
4f19785b 12143 case '2': case '3': case '4':
378cc40b 12144 case '5': case '6': case '7':
4f19785b 12145 if (shift == 1)
cea2e8a9 12146 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
4f19785b
WSI
12147 /* FALL THROUGH */
12148
12149 case '0': case '1':
02aa26ce 12150 b = *s++ & 15; /* ASCII digit -> value of digit */
55497cff 12151 goto digit;
02aa26ce
NT
12152
12153 /* hex digits */
378cc40b
LW
12154 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
12155 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
02aa26ce 12156 /* make sure they said 0x */
378cc40b
LW
12157 if (shift != 4)
12158 goto out;
55497cff 12159 b = (*s++ & 7) + 9;
02aa26ce
NT
12160
12161 /* Prepare to put the digit we have onto the end
12162 of the number so far. We check for overflows.
12163 */
12164
55497cff 12165 digit:
61f33854 12166 just_zero = FALSE;
9e24b6e2
JH
12167 if (!overflowed) {
12168 x = u << shift; /* make room for the digit */
12169
12170 if ((x >> shift) != u
12171 && !(PL_hints & HINT_NEW_BINARY)) {
9e24b6e2
JH
12172 overflowed = TRUE;
12173 n = (NV) u;
767a6a26 12174 if (ckWARN_d(WARN_OVERFLOW))
9014280d 12175 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
9e24b6e2
JH
12176 "Integer overflow in %s number",
12177 base);
12178 } else
12179 u = x | b; /* add the digit to the end */
12180 }
12181 if (overflowed) {
12182 n *= nvshift[shift];
12183 /* If an NV has not enough bits in its
12184 * mantissa to represent an UV this summing of
12185 * small low-order numbers is a waste of time
12186 * (because the NV cannot preserve the
12187 * low-order bits anyway): we could just
12188 * remember when did we overflow and in the
12189 * end just multiply n by the right
12190 * amount. */
12191 n += (NV) b;
55497cff 12192 }
378cc40b
LW
12193 break;
12194 }
12195 }
02aa26ce
NT
12196
12197 /* if we get here, we had success: make a scalar value from
12198 the number.
12199 */
378cc40b 12200 out:
928753ea
JH
12201
12202 /* final misplaced underbar check */
12203 if (s[-1] == '_') {
12204 if (ckWARN(WARN_SYNTAX))
9014280d 12205 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
928753ea
JH
12206 }
12207
561b68a9 12208 sv = newSV(0);
9e24b6e2 12209 if (overflowed) {
041457d9 12210 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
9014280d 12211 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
9e24b6e2
JH
12212 "%s number > %s non-portable",
12213 Base, max);
12214 sv_setnv(sv, n);
12215 }
12216 else {
15041a67 12217#if UVSIZE > 4
041457d9 12218 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
9014280d 12219 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
9e24b6e2
JH
12220 "%s number > %s non-portable",
12221 Base, max);
2cc4c2dc 12222#endif
9e24b6e2
JH
12223 sv_setuv(sv, u);
12224 }
61f33854 12225 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
bfed75c6 12226 sv = new_constant(start, s - start, "integer",
eb0d8d16 12227 sv, NULL, NULL, 0);
61f33854 12228 else if (PL_hints & HINT_NEW_BINARY)
eb0d8d16 12229 sv = new_constant(start, s - start, "binary", sv, NULL, NULL, 0);
378cc40b
LW
12230 }
12231 break;
02aa26ce
NT
12232
12233 /*
12234 handle decimal numbers.
12235 we're also sent here when we read a 0 as the first digit
12236 */
378cc40b
LW
12237 case '1': case '2': case '3': case '4': case '5':
12238 case '6': case '7': case '8': case '9': case '.':
12239 decimal:
3280af22
NIS
12240 d = PL_tokenbuf;
12241 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
79072805 12242 floatit = FALSE;
02aa26ce
NT
12243
12244 /* read next group of digits and _ and copy into d */
de3bb511 12245 while (isDIGIT(*s) || *s == '_') {
4e553d73 12246 /* skip underscores, checking for misplaced ones
02aa26ce
NT
12247 if -w is on
12248 */
93a17b20 12249 if (*s == '_') {
041457d9 12250 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
9014280d 12251 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
928753ea
JH
12252 "Misplaced _ in number");
12253 lastub = s++;
93a17b20 12254 }
fc36a67e 12255 else {
02aa26ce 12256 /* check for end of fixed-length buffer */
fc36a67e 12257 if (d >= e)
cea2e8a9 12258 Perl_croak(aTHX_ number_too_long);
02aa26ce 12259 /* if we're ok, copy the character */
378cc40b 12260 *d++ = *s++;
fc36a67e 12261 }
378cc40b 12262 }
02aa26ce
NT
12263
12264 /* final misplaced underbar check */
928753ea 12265 if (lastub && s == lastub + 1) {
d008e5eb 12266 if (ckWARN(WARN_SYNTAX))
9014280d 12267 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
d008e5eb 12268 }
02aa26ce
NT
12269
12270 /* read a decimal portion if there is one. avoid
12271 3..5 being interpreted as the number 3. followed
12272 by .5
12273 */
2f3197b3 12274 if (*s == '.' && s[1] != '.') {
79072805 12275 floatit = TRUE;
378cc40b 12276 *d++ = *s++;
02aa26ce 12277
928753ea
JH
12278 if (*s == '_') {
12279 if (ckWARN(WARN_SYNTAX))
9014280d 12280 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
928753ea
JH
12281 "Misplaced _ in number");
12282 lastub = s;
12283 }
12284
12285 /* copy, ignoring underbars, until we run out of digits.
02aa26ce 12286 */
fc36a67e 12287 for (; isDIGIT(*s) || *s == '_'; s++) {
02aa26ce 12288 /* fixed length buffer check */
fc36a67e 12289 if (d >= e)
cea2e8a9 12290 Perl_croak(aTHX_ number_too_long);
928753ea 12291 if (*s == '_') {
041457d9 12292 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
9014280d 12293 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
928753ea
JH
12294 "Misplaced _ in number");
12295 lastub = s;
12296 }
12297 else
fc36a67e 12298 *d++ = *s;
378cc40b 12299 }
928753ea
JH
12300 /* fractional part ending in underbar? */
12301 if (s[-1] == '_') {
12302 if (ckWARN(WARN_SYNTAX))
9014280d 12303 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
928753ea
JH
12304 "Misplaced _ in number");
12305 }
dd629d5b
GS
12306 if (*s == '.' && isDIGIT(s[1])) {
12307 /* oops, it's really a v-string, but without the "v" */
f4758303 12308 s = start;
dd629d5b
GS
12309 goto vstring;
12310 }
378cc40b 12311 }
02aa26ce
NT
12312
12313 /* read exponent part, if present */
3792a11b 12314 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
79072805
LW
12315 floatit = TRUE;
12316 s++;
02aa26ce
NT
12317
12318 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
79072805 12319 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
02aa26ce 12320
7fd134d9
JH
12321 /* stray preinitial _ */
12322 if (*s == '_') {
12323 if (ckWARN(WARN_SYNTAX))
9014280d 12324 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
7fd134d9
JH
12325 "Misplaced _ in number");
12326 lastub = s++;
12327 }
12328
02aa26ce 12329 /* allow positive or negative exponent */
378cc40b
LW
12330 if (*s == '+' || *s == '-')
12331 *d++ = *s++;
02aa26ce 12332
7fd134d9
JH
12333 /* stray initial _ */
12334 if (*s == '_') {
12335 if (ckWARN(WARN_SYNTAX))
9014280d 12336 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
7fd134d9
JH
12337 "Misplaced _ in number");
12338 lastub = s++;
12339 }
12340
7fd134d9
JH
12341 /* read digits of exponent */
12342 while (isDIGIT(*s) || *s == '_') {
12343 if (isDIGIT(*s)) {
12344 if (d >= e)
12345 Perl_croak(aTHX_ number_too_long);
b3b48e3e 12346 *d++ = *s++;
7fd134d9
JH
12347 }
12348 else {
041457d9
DM
12349 if (((lastub && s == lastub + 1) ||
12350 (!isDIGIT(s[1]) && s[1] != '_'))
12351 && ckWARN(WARN_SYNTAX))
9014280d 12352 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
7fd134d9 12353 "Misplaced _ in number");
b3b48e3e 12354 lastub = s++;
7fd134d9 12355 }
7fd134d9 12356 }
378cc40b 12357 }
02aa26ce 12358
02aa26ce
NT
12359
12360 /* make an sv from the string */
561b68a9 12361 sv = newSV(0);
097ee67d 12362
0b7fceb9 12363 /*
58bb9ec3
NC
12364 We try to do an integer conversion first if no characters
12365 indicating "float" have been found.
0b7fceb9
MU
12366 */
12367
12368 if (!floatit) {
58bb9ec3 12369 UV uv;
6136c704 12370 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
58bb9ec3
NC
12371
12372 if (flags == IS_NUMBER_IN_UV) {
12373 if (uv <= IV_MAX)
86554af2 12374 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
58bb9ec3 12375 else
c239479b 12376 sv_setuv(sv, uv);
58bb9ec3
NC
12377 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
12378 if (uv <= (UV) IV_MIN)
12379 sv_setiv(sv, -(IV)uv);
12380 else
12381 floatit = TRUE;
12382 } else
12383 floatit = TRUE;
12384 }
0b7fceb9 12385 if (floatit) {
58bb9ec3
NC
12386 /* terminate the string */
12387 *d = '\0';
86554af2
JH
12388 nv = Atof(PL_tokenbuf);
12389 sv_setnv(sv, nv);
12390 }
86554af2 12391
eb0d8d16
NC
12392 if ( floatit
12393 ? (PL_hints & HINT_NEW_FLOAT) : (PL_hints & HINT_NEW_INTEGER) ) {
12394 const char *const key = floatit ? "float" : "integer";
12395 const STRLEN keylen = floatit ? 5 : 7;
12396 sv = S_new_constant(aTHX_ PL_tokenbuf, d - PL_tokenbuf,
12397 key, keylen, sv, NULL, NULL, 0);
12398 }
378cc40b 12399 break;
0b7fceb9 12400
e312add1 12401 /* if it starts with a v, it could be a v-string */
a7cb1f99 12402 case 'v':
dd629d5b 12403vstring:
561b68a9 12404 sv = newSV(5); /* preallocate storage space */
65b06e02 12405 s = scan_vstring(s, PL_bufend, sv);
a7cb1f99 12406 break;
79072805 12407 }
a687059c 12408
02aa26ce
NT
12409 /* make the op for the constant and return */
12410
a86a20aa 12411 if (sv)
b73d6f50 12412 lvalp->opval = newSVOP(OP_CONST, 0, sv);
a7cb1f99 12413 else
5f66b61c 12414 lvalp->opval = NULL;
a687059c 12415
73d840c0 12416 return (char *)s;
378cc40b
LW
12417}
12418
76e3520e 12419STATIC char *
cea2e8a9 12420S_scan_formline(pTHX_ register char *s)
378cc40b 12421{
97aff369 12422 dVAR;
79072805 12423 register char *eol;
378cc40b 12424 register char *t;
6136c704 12425 SV * const stuff = newSVpvs("");
79072805 12426 bool needargs = FALSE;
c5ee2135 12427 bool eofmt = FALSE;
5db06880
NC
12428#ifdef PERL_MAD
12429 char *tokenstart = s;
4f61fd4b
JC
12430 SV* savewhite = NULL;
12431
5db06880 12432 if (PL_madskills) {
cd81e915
NC
12433 savewhite = PL_thiswhite;
12434 PL_thiswhite = 0;
5db06880
NC
12435 }
12436#endif
378cc40b 12437
7918f24d
NC
12438 PERL_ARGS_ASSERT_SCAN_FORMLINE;
12439
79072805 12440 while (!needargs) {
a1b95068 12441 if (*s == '.') {
c35e046a 12442 t = s+1;
51882d45 12443#ifdef PERL_STRICT_CR
c35e046a
AL
12444 while (SPACE_OR_TAB(*t))
12445 t++;
51882d45 12446#else
c35e046a
AL
12447 while (SPACE_OR_TAB(*t) || *t == '\r')
12448 t++;
51882d45 12449#endif
c5ee2135
WL
12450 if (*t == '\n' || t == PL_bufend) {
12451 eofmt = TRUE;
79072805 12452 break;
c5ee2135 12453 }
79072805 12454 }
3280af22 12455 if (PL_in_eval && !PL_rsfp) {
07409e01 12456 eol = (char *) memchr(s,'\n',PL_bufend-s);
0f85fab0 12457 if (!eol++)
3280af22 12458 eol = PL_bufend;
0f85fab0
LW
12459 }
12460 else
3280af22 12461 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
79072805 12462 if (*s != '#') {
a0d0e21e
LW
12463 for (t = s; t < eol; t++) {
12464 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12465 needargs = FALSE;
12466 goto enough; /* ~~ must be first line in formline */
378cc40b 12467 }
a0d0e21e
LW
12468 if (*t == '@' || *t == '^')
12469 needargs = TRUE;
378cc40b 12470 }
7121b347
MG
12471 if (eol > s) {
12472 sv_catpvn(stuff, s, eol-s);
2dc4c65b 12473#ifndef PERL_STRICT_CR
7121b347
MG
12474 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12475 char *end = SvPVX(stuff) + SvCUR(stuff);
12476 end[-2] = '\n';
12477 end[-1] = '\0';
b162af07 12478 SvCUR_set(stuff, SvCUR(stuff) - 1);
7121b347 12479 }
2dc4c65b 12480#endif
7121b347
MG
12481 }
12482 else
12483 break;
79072805 12484 }
95a20fc0 12485 s = (char*)eol;
3280af22 12486 if (PL_rsfp) {
5db06880
NC
12487#ifdef PERL_MAD
12488 if (PL_madskills) {
cd81e915
NC
12489 if (PL_thistoken)
12490 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
5db06880 12491 else
cd81e915 12492 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
5db06880
NC
12493 }
12494#endif
3280af22 12495 s = filter_gets(PL_linestr, PL_rsfp, 0);
5db06880
NC
12496#ifdef PERL_MAD
12497 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12498#else
3280af22 12499 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
5db06880 12500#endif
3280af22 12501 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
bd61b366 12502 PL_last_lop = PL_last_uni = NULL;
79072805 12503 if (!s) {
3280af22 12504 s = PL_bufptr;
378cc40b
LW
12505 break;
12506 }
378cc40b 12507 }
463ee0b2 12508 incline(s);
79072805 12509 }
a0d0e21e
LW
12510 enough:
12511 if (SvCUR(stuff)) {
3280af22 12512 PL_expect = XTERM;
79072805 12513 if (needargs) {
3280af22 12514 PL_lex_state = LEX_NORMAL;
cd81e915 12515 start_force(PL_curforce);
9ded7720 12516 NEXTVAL_NEXTTOKE.ival = 0;
79072805
LW
12517 force_next(',');
12518 }
a0d0e21e 12519 else
3280af22 12520 PL_lex_state = LEX_FORMLINE;
1bd51a4c 12521 if (!IN_BYTES) {
95a20fc0 12522 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
1bd51a4c
IH
12523 SvUTF8_on(stuff);
12524 else if (PL_encoding)
12525 sv_recode_to_utf8(stuff, PL_encoding);
12526 }
cd81e915 12527 start_force(PL_curforce);
9ded7720 12528 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
79072805 12529 force_next(THING);
cd81e915 12530 start_force(PL_curforce);
9ded7720 12531 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
79072805 12532 force_next(LSTOP);
378cc40b 12533 }
79072805 12534 else {
8990e307 12535 SvREFCNT_dec(stuff);
c5ee2135
WL
12536 if (eofmt)
12537 PL_lex_formbrack = 0;
3280af22 12538 PL_bufptr = s;
79072805 12539 }
5db06880
NC
12540#ifdef PERL_MAD
12541 if (PL_madskills) {
cd81e915
NC
12542 if (PL_thistoken)
12543 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
5db06880 12544 else
cd81e915
NC
12545 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12546 PL_thiswhite = savewhite;
5db06880
NC
12547 }
12548#endif
79072805 12549 return s;
378cc40b 12550}
a687059c 12551
ba6d6ac9 12552I32
864dbfa3 12553Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
8990e307 12554{
97aff369 12555 dVAR;
a3b680e6 12556 const I32 oldsavestack_ix = PL_savestack_ix;
6136c704 12557 CV* const outsidecv = PL_compcv;
8990e307 12558
3280af22
NIS
12559 if (PL_compcv) {
12560 assert(SvTYPE(PL_compcv) == SVt_PVCV);
e9a444f0 12561 }
7766f137 12562 SAVEI32(PL_subline);
3280af22 12563 save_item(PL_subname);
3280af22 12564 SAVESPTR(PL_compcv);
3280af22 12565
ea726b52 12566 PL_compcv = MUTABLE_CV(newSV_type(is_format ? SVt_PVFM : SVt_PVCV));
3280af22
NIS
12567 CvFLAGS(PL_compcv) |= flags;
12568
57843af0 12569 PL_subline = CopLINE(PL_curcop);
dd2155a4 12570 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
ea726b52 12571 CvOUTSIDE(PL_compcv) = MUTABLE_CV(SvREFCNT_inc_simple(outsidecv));
a3985cdc 12572 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
748a9306 12573
8990e307
LW
12574 return oldsavestack_ix;
12575}
12576
084592ab
CN
12577#ifdef __SC__
12578#pragma segment Perl_yylex
12579#endif
af41e527
NC
12580static int
12581S_yywarn(pTHX_ const char *const s)
8990e307 12582{
97aff369 12583 dVAR;
7918f24d
NC
12584
12585 PERL_ARGS_ASSERT_YYWARN;
12586
faef0170 12587 PL_in_eval |= EVAL_WARNONLY;
748a9306 12588 yyerror(s);
faef0170 12589 PL_in_eval &= ~EVAL_WARNONLY;
748a9306 12590 return 0;
8990e307
LW
12591}
12592
12593int
15f169a1 12594Perl_yyerror(pTHX_ const char *const s)
463ee0b2 12595{
97aff369 12596 dVAR;
bfed75c6
AL
12597 const char *where = NULL;
12598 const char *context = NULL;
68dc0745 12599 int contlen = -1;
46fc3d4c 12600 SV *msg;
5912531f 12601 int yychar = PL_parser->yychar;
463ee0b2 12602
7918f24d
NC
12603 PERL_ARGS_ASSERT_YYERROR;
12604
3280af22 12605 if (!yychar || (yychar == ';' && !PL_rsfp))
54310121 12606 where = "at EOF";
8bcfe651
TM
12607 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12608 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12609 PL_oldbufptr != PL_bufptr) {
f355267c
JH
12610 /*
12611 Only for NetWare:
12612 The code below is removed for NetWare because it abends/crashes on NetWare
12613 when the script has error such as not having the closing quotes like:
12614 if ($var eq "value)
12615 Checking of white spaces is anyway done in NetWare code.
12616 */
12617#ifndef NETWARE
3280af22
NIS
12618 while (isSPACE(*PL_oldoldbufptr))
12619 PL_oldoldbufptr++;
f355267c 12620#endif
3280af22
NIS
12621 context = PL_oldoldbufptr;
12622 contlen = PL_bufptr - PL_oldoldbufptr;
463ee0b2 12623 }
8bcfe651
TM
12624 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12625 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
f355267c
JH
12626 /*
12627 Only for NetWare:
12628 The code below is removed for NetWare because it abends/crashes on NetWare
12629 when the script has error such as not having the closing quotes like:
12630 if ($var eq "value)
12631 Checking of white spaces is anyway done in NetWare code.
12632 */
12633#ifndef NETWARE
3280af22
NIS
12634 while (isSPACE(*PL_oldbufptr))
12635 PL_oldbufptr++;
f355267c 12636#endif
3280af22
NIS
12637 context = PL_oldbufptr;
12638 contlen = PL_bufptr - PL_oldbufptr;
463ee0b2
LW
12639 }
12640 else if (yychar > 255)
68dc0745 12641 where = "next token ???";
12fbd33b 12642 else if (yychar == -2) { /* YYEMPTY */
3280af22
NIS
12643 if (PL_lex_state == LEX_NORMAL ||
12644 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
68dc0745 12645 where = "at end of line";
3280af22 12646 else if (PL_lex_inpat)
68dc0745 12647 where = "within pattern";
463ee0b2 12648 else
68dc0745 12649 where = "within string";
463ee0b2 12650 }
46fc3d4c 12651 else {
84bafc02 12652 SV * const where_sv = newSVpvs_flags("next char ", SVs_TEMP);
46fc3d4c 12653 if (yychar < 32)
cea2e8a9 12654 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
5e7aa789 12655 else if (isPRINT_LC(yychar)) {
88c9ea1e 12656 const char string = yychar;
5e7aa789
NC
12657 sv_catpvn(where_sv, &string, 1);
12658 }
463ee0b2 12659 else
cea2e8a9 12660 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
95a20fc0 12661 where = SvPVX_const(where_sv);
463ee0b2 12662 }
46fc3d4c 12663 msg = sv_2mortal(newSVpv(s, 0));
ed094faf 12664 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
248c2a4d 12665 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
68dc0745 12666 if (context)
cea2e8a9 12667 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
463ee0b2 12668 else
cea2e8a9 12669 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
57843af0 12670 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
cf2093f6 12671 Perl_sv_catpvf(aTHX_ msg,
57def98f 12672 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
cf2093f6 12673 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
3280af22 12674 PL_multi_end = 0;
a0d0e21e 12675 }
500960a6
RD
12676 if (PL_in_eval & EVAL_WARNONLY) {
12677 if (ckWARN_d(WARN_SYNTAX))
12678 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, SVfARG(msg));
12679 }
463ee0b2 12680 else
5a844595 12681 qerror(msg);
c7d6bfb2
GS
12682 if (PL_error_count >= 10) {
12683 if (PL_in_eval && SvCUR(ERRSV))
d2560b70 12684 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
be2597df 12685 SVfARG(ERRSV), OutCopFILE(PL_curcop));
c7d6bfb2
GS
12686 else
12687 Perl_croak(aTHX_ "%s has too many errors.\n",
248c2a4d 12688 OutCopFILE(PL_curcop));
c7d6bfb2 12689 }
3280af22 12690 PL_in_my = 0;
5c284bb0 12691 PL_in_my_stash = NULL;
463ee0b2
LW
12692 return 0;
12693}
084592ab
CN
12694#ifdef __SC__
12695#pragma segment Main
12696#endif
4e35701f 12697
b250498f 12698STATIC char*
3ae08724 12699S_swallow_bom(pTHX_ U8 *s)
01ec43d0 12700{
97aff369 12701 dVAR;
f54cb97a 12702 const STRLEN slen = SvCUR(PL_linestr);
7918f24d
NC
12703
12704 PERL_ARGS_ASSERT_SWALLOW_BOM;
12705
7aa207d6 12706 switch (s[0]) {
4e553d73
NIS
12707 case 0xFF:
12708 if (s[1] == 0xFE) {
7aa207d6 12709 /* UTF-16 little-endian? (or UTF32-LE?) */
3ae08724 12710 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
7aa207d6 12711 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
01ec43d0 12712#ifndef PERL_NO_UTF16_FILTER
7aa207d6 12713 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
3ae08724 12714 s += 2;
7aa207d6 12715 utf16le:
dea0fc0b
JH
12716 if (PL_bufend > (char*)s) {
12717 U8 *news;
12718 I32 newlen;
12719
12720 filter_add(utf16rev_textfilter, NULL);
a02a5408 12721 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
1de9afcd 12722 utf16_to_utf8_reversed(s, news,
aed58286 12723 PL_bufend - (char*)s - 1,
1de9afcd 12724 &newlen);
7aa207d6 12725 sv_setpvn(PL_linestr, (const char*)news, newlen);
5db06880
NC
12726#ifdef PERL_MAD
12727 s = (U8*)SvPVX(PL_linestr);
12728 Copy(news, s, newlen, U8);
12729 s[newlen] = '\0';
12730#endif
dea0fc0b 12731 Safefree(news);
7aa207d6
JH
12732 SvUTF8_on(PL_linestr);
12733 s = (U8*)SvPVX(PL_linestr);
5db06880
NC
12734#ifdef PERL_MAD
12735 /* FIXME - is this a general bug fix? */
12736 s[newlen] = '\0';
12737#endif
7aa207d6 12738 PL_bufend = SvPVX(PL_linestr) + newlen;
dea0fc0b 12739 }
b250498f 12740#else
7aa207d6 12741 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
b250498f 12742#endif
01ec43d0
GS
12743 }
12744 break;
78ae23f5 12745 case 0xFE:
7aa207d6 12746 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
01ec43d0 12747#ifndef PERL_NO_UTF16_FILTER
7aa207d6 12748 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
dea0fc0b 12749 s += 2;
7aa207d6 12750 utf16be:
dea0fc0b
JH
12751 if (PL_bufend > (char *)s) {
12752 U8 *news;
12753 I32 newlen;
12754
12755 filter_add(utf16_textfilter, NULL);
a02a5408 12756 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
1de9afcd
RGS
12757 utf16_to_utf8(s, news,
12758 PL_bufend - (char*)s,
12759 &newlen);
7aa207d6 12760 sv_setpvn(PL_linestr, (const char*)news, newlen);
dea0fc0b 12761 Safefree(news);
7aa207d6
JH
12762 SvUTF8_on(PL_linestr);
12763 s = (U8*)SvPVX(PL_linestr);
12764 PL_bufend = SvPVX(PL_linestr) + newlen;
dea0fc0b 12765 }
b250498f 12766#else
7aa207d6 12767 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
b250498f 12768#endif
01ec43d0
GS
12769 }
12770 break;
3ae08724
GS
12771 case 0xEF:
12772 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
7aa207d6 12773 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
01ec43d0
GS
12774 s += 3; /* UTF-8 */
12775 }
12776 break;
12777 case 0:
7aa207d6
JH
12778 if (slen > 3) {
12779 if (s[1] == 0) {
12780 if (s[2] == 0xFE && s[3] == 0xFF) {
12781 /* UTF-32 big-endian */
12782 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12783 }
12784 }
12785 else if (s[2] == 0 && s[3] != 0) {
12786 /* Leading bytes
12787 * 00 xx 00 xx
12788 * are a good indicator of UTF-16BE. */
12789 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12790 goto utf16be;
12791 }
01ec43d0 12792 }
e294cc5d
JH
12793#ifdef EBCDIC
12794 case 0xDD:
12795 if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
12796 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12797 s += 4; /* UTF-8 */
12798 }
12799 break;
12800#endif
12801
7aa207d6
JH
12802 default:
12803 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12804 /* Leading bytes
12805 * xx 00 xx 00
12806 * are a good indicator of UTF-16LE. */
12807 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12808 goto utf16le;
12809 }
01ec43d0 12810 }
b8f84bb2 12811 return (char*)s;
b250498f 12812}
4755096e 12813
6e3aabd6
GS
12814
12815#ifndef PERL_NO_UTF16_FILTER
12816static I32
acfe0abc 12817utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
6e3aabd6 12818{
97aff369 12819 dVAR;
f54cb97a
AL
12820 const STRLEN old = SvCUR(sv);
12821 const I32 count = FILTER_READ(idx+1, sv, maxlen);
1de9afcd
RGS
12822 DEBUG_P(PerlIO_printf(Perl_debug_log,
12823 "utf16_textfilter(%p): %d %d (%d)\n",
55662e27
JH
12824 FPTR2DPTR(void *, utf16_textfilter),
12825 idx, maxlen, (int) count));
6e3aabd6
GS
12826 if (count) {
12827 U8* tmps;
dea0fc0b 12828 I32 newlen;
a02a5408 12829 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
95a20fc0
SP
12830 Copy(SvPVX_const(sv), tmps, old, char);
12831 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
1de9afcd
RGS
12832 SvCUR(sv) - old, &newlen);
12833 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
6e3aabd6 12834 }
1de9afcd
RGS
12835 DEBUG_P({sv_dump(sv);});
12836 return SvCUR(sv);
6e3aabd6
GS
12837}
12838
12839static I32
acfe0abc 12840utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
6e3aabd6 12841{
97aff369 12842 dVAR;
f54cb97a
AL
12843 const STRLEN old = SvCUR(sv);
12844 const I32 count = FILTER_READ(idx+1, sv, maxlen);
1de9afcd
RGS
12845 DEBUG_P(PerlIO_printf(Perl_debug_log,
12846 "utf16rev_textfilter(%p): %d %d (%d)\n",
55662e27
JH
12847 FPTR2DPTR(void *, utf16rev_textfilter),
12848 idx, maxlen, (int) count));
6e3aabd6
GS
12849 if (count) {
12850 U8* tmps;
dea0fc0b 12851 I32 newlen;
a02a5408 12852 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
95a20fc0
SP
12853 Copy(SvPVX_const(sv), tmps, old, char);
12854 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
1de9afcd
RGS
12855 SvCUR(sv) - old, &newlen);
12856 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
6e3aabd6 12857 }
1de9afcd 12858 DEBUG_P({ sv_dump(sv); });
6e3aabd6
GS
12859 return count;
12860}
12861#endif
9f4817db 12862
f333445c
JP
12863/*
12864Returns a pointer to the next character after the parsed
12865vstring, as well as updating the passed in sv.
12866
12867Function must be called like
12868
561b68a9 12869 sv = newSV(5);
65b06e02 12870 s = scan_vstring(s,e,sv);
f333445c 12871
65b06e02 12872where s and e are the start and end of the string.
f333445c
JP
12873The sv should already be large enough to store the vstring
12874passed in, for performance reasons.
12875
12876*/
12877
12878char *
15f169a1 12879Perl_scan_vstring(pTHX_ const char *s, const char *const e, SV *sv)
f333445c 12880{
97aff369 12881 dVAR;
bfed75c6
AL
12882 const char *pos = s;
12883 const char *start = s;
7918f24d
NC
12884
12885 PERL_ARGS_ASSERT_SCAN_VSTRING;
12886
f333445c 12887 if (*pos == 'v') pos++; /* get past 'v' */
65b06e02 12888 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
3e884cbf 12889 pos++;
f333445c
JP
12890 if ( *pos != '.') {
12891 /* this may not be a v-string if followed by => */
bfed75c6 12892 const char *next = pos;
65b06e02 12893 while (next < e && isSPACE(*next))
8fc7bb1c 12894 ++next;
65b06e02 12895 if ((e - next) >= 2 && *next == '=' && next[1] == '>' ) {
f333445c
JP
12896 /* return string not v-string */
12897 sv_setpvn(sv,(char *)s,pos-s);
73d840c0 12898 return (char *)pos;
f333445c
JP
12899 }
12900 }
12901
12902 if (!isALPHA(*pos)) {
89ebb4a3 12903 U8 tmpbuf[UTF8_MAXBYTES+1];
f333445c 12904
d4c19fe8
AL
12905 if (*s == 'v')
12906 s++; /* get past 'v' */
f333445c 12907
76f68e9b 12908 sv_setpvs(sv, "");
f333445c
JP
12909
12910 for (;;) {
d4c19fe8 12911 /* this is atoi() that tolerates underscores */
0bd48802
AL
12912 U8 *tmpend;
12913 UV rev = 0;
d4c19fe8
AL
12914 const char *end = pos;
12915 UV mult = 1;
12916 while (--end >= s) {
12917 if (*end != '_') {
12918 const UV orev = rev;
f333445c
JP
12919 rev += (*end - '0') * mult;
12920 mult *= 10;
12921 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12922 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12923 "Integer overflow in decimal number");
12924 }
12925 }
12926#ifdef EBCDIC
12927 if (rev > 0x7FFFFFFF)
12928 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12929#endif
12930 /* Append native character for the rev point */
12931 tmpend = uvchr_to_utf8(tmpbuf, rev);
12932 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12933 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12934 SvUTF8_on(sv);
65b06e02 12935 if (pos + 1 < e && *pos == '.' && isDIGIT(pos[1]))
f333445c
JP
12936 s = ++pos;
12937 else {
12938 s = pos;
12939 break;
12940 }
65b06e02 12941 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
f333445c
JP
12942 pos++;
12943 }
12944 SvPOK_on(sv);
12945 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12946 SvRMAGICAL_on(sv);
12947 }
73d840c0 12948 return (char *)s;
f333445c
JP
12949}
12950
1da4ca5f
NC
12951/*
12952 * Local variables:
12953 * c-indentation-style: bsd
12954 * c-basic-offset: 4
12955 * indent-tabs-mode: t
12956 * End:
12957 *
37442d52
RGS
12958 * ex: set ts=8 sts=4 sw=4 noet:
12959 */