This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove category 'syntax' from 5 warnings that should just be in 'deprecated'.
[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
b1fc3636
CJ
127/* The maximum number of characters preceding the unrecognized one to display */
128#define UNRECOGNIZED_PRECEDE_COUNT 10
129
61f0cdd9 130/* In variables named $^X, these are the legal values for X.
2b92dfce
GS
131 * 1999-02-27 mjd-perl-patch@plover.com */
132#define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
133
bf4acbe4 134#define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
bf4acbe4 135
ffb4593c
NT
136/* LEX_* are values for PL_lex_state, the state of the lexer.
137 * They are arranged oddly so that the guard on the switch statement
79072805
LW
138 * can get by with a single comparison (if the compiler is smart enough).
139 */
140
fb73857a 141/* #define LEX_NOTPARSING 11 is done in perl.h. */
142
b6007c36
DM
143#define LEX_NORMAL 10 /* normal code (ie not within "...") */
144#define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
145#define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
146#define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
147#define LEX_INTERPSTART 6 /* expecting the start of a $var */
148
149 /* at end of code, eg "$x" followed by: */
150#define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
151#define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
152
153#define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
154 string or after \E, $foo, etc */
155#define LEX_INTERPCONST 2 /* NOT USED */
156#define LEX_FORMLINE 1 /* expecting a format line */
157#define LEX_KNOWNEXT 0 /* next token known; just return it */
158
79072805 159
bbf60fe6 160#ifdef DEBUGGING
27da23d5 161static const char* const lex_state_names[] = {
bbf60fe6
DM
162 "KNOWNEXT",
163 "FORMLINE",
164 "INTERPCONST",
165 "INTERPCONCAT",
166 "INTERPENDMAYBE",
167 "INTERPEND",
168 "INTERPSTART",
169 "INTERPPUSH",
170 "INTERPCASEMOD",
171 "INTERPNORMAL",
172 "NORMAL"
173};
174#endif
175
79072805
LW
176#ifdef ff_next
177#undef ff_next
d48672a2
LW
178#endif
179
79072805 180#include "keywords.h"
fe14fcc3 181
ffb4593c
NT
182/* CLINE is a macro that ensures PL_copline has a sane value */
183
ae986130
LW
184#ifdef CLINE
185#undef CLINE
186#endif
57843af0 187#define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
3280af22 188
5db06880 189#ifdef PERL_MAD
29595ff2
NC
190# define SKIPSPACE0(s) skipspace0(s)
191# define SKIPSPACE1(s) skipspace1(s)
192# define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
193# define PEEKSPACE(s) skipspace2(s,0)
194#else
195# define SKIPSPACE0(s) skipspace(s)
196# define SKIPSPACE1(s) skipspace(s)
197# define SKIPSPACE2(s,tsv) skipspace(s)
198# define PEEKSPACE(s) skipspace(s)
199#endif
200
ffb4593c
NT
201/*
202 * Convenience functions to return different tokens and prime the
9cbb5ea2 203 * lexer for the next token. They all take an argument.
ffb4593c
NT
204 *
205 * TOKEN : generic token (used for '(', DOLSHARP, etc)
206 * OPERATOR : generic operator
207 * AOPERATOR : assignment operator
208 * PREBLOCK : beginning the block after an if, while, foreach, ...
209 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
210 * PREREF : *EXPR where EXPR is not a simple identifier
211 * TERM : expression term
212 * LOOPX : loop exiting command (goto, last, dump, etc)
213 * FTST : file test operator
214 * FUN0 : zero-argument function
2d2e263d 215 * FUN1 : not used, except for not, which isn't a UNIOP
ffb4593c
NT
216 * BOop : bitwise or or xor
217 * BAop : bitwise and
218 * SHop : shift operator
219 * PWop : power operator
9cbb5ea2 220 * PMop : pattern-matching operator
ffb4593c
NT
221 * Aop : addition-level operator
222 * Mop : multiplication-level operator
223 * Eop : equality-testing operator
e5edeb50 224 * Rop : relational operator <= != gt
ffb4593c
NT
225 *
226 * Also see LOP and lop() below.
227 */
228
998054bd 229#ifdef DEBUGGING /* Serve -DT. */
704d4215 230# define REPORT(retval) tokereport((I32)retval, &pl_yylval)
998054bd 231#else
bbf60fe6 232# define REPORT(retval) (retval)
998054bd
SC
233#endif
234
bbf60fe6
DM
235#define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
236#define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
237#define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
238#define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
239#define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
240#define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
241#define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
6154021b
RGS
242#define LOOPX(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
243#define FTST(f) return (pl_yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
244#define FUN0(f) return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
245#define FUN1(f) return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
246#define BOop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
247#define BAop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
248#define SHop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
249#define PWop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
250#define PMop(f) return(pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
251#define Aop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
252#define Mop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
253#define Eop(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
254#define Rop(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
2f3197b3 255
a687059c
LW
256/* This bit of chicanery makes a unary function followed by
257 * a parenthesis into a function with one argument, highest precedence.
6f33ba73
RGS
258 * The UNIDOR macro is for unary functions that can be followed by the //
259 * operator (such as C<shift // 0>).
a687059c 260 */
376fcdbf 261#define UNI2(f,x) { \
6154021b 262 pl_yylval.ival = f; \
376fcdbf
AL
263 PL_expect = x; \
264 PL_bufptr = s; \
265 PL_last_uni = PL_oldbufptr; \
266 PL_last_lop_op = f; \
267 if (*s == '(') \
268 return REPORT( (int)FUNC1 ); \
29595ff2 269 s = PEEKSPACE(s); \
376fcdbf
AL
270 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
271 }
6f33ba73
RGS
272#define UNI(f) UNI2(f,XTERM)
273#define UNIDOR(f) UNI2(f,XTERMORDORDOR)
a687059c 274
376fcdbf 275#define UNIBRACK(f) { \
6154021b 276 pl_yylval.ival = f; \
376fcdbf
AL
277 PL_bufptr = s; \
278 PL_last_uni = PL_oldbufptr; \
279 if (*s == '(') \
280 return REPORT( (int)FUNC1 ); \
29595ff2 281 s = PEEKSPACE(s); \
376fcdbf
AL
282 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
283 }
79072805 284
9f68db38 285/* grandfather return to old style */
6154021b 286#define OLDLOP(f) return(pl_yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
79072805 287
8fa7f367
JH
288#ifdef DEBUGGING
289
6154021b 290/* how to interpret the pl_yylval associated with the token */
bbf60fe6
DM
291enum token_type {
292 TOKENTYPE_NONE,
293 TOKENTYPE_IVAL,
6154021b 294 TOKENTYPE_OPNUM, /* pl_yylval.ival contains an opcode number */
bbf60fe6
DM
295 TOKENTYPE_PVAL,
296 TOKENTYPE_OPVAL,
297 TOKENTYPE_GVVAL
298};
299
6d4a66ac
NC
300static struct debug_tokens {
301 const int token;
302 enum token_type type;
303 const char *name;
304} const debug_tokens[] =
9041c2e3 305{
bbf60fe6
DM
306 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
307 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
308 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
309 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
310 { ARROW, TOKENTYPE_NONE, "ARROW" },
311 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
312 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
313 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
314 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
315 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
0d863452 316 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
bbf60fe6
DM
317 { DO, TOKENTYPE_NONE, "DO" },
318 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
319 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
320 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
321 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
322 { ELSE, TOKENTYPE_NONE, "ELSE" },
323 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
324 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
325 { FOR, TOKENTYPE_IVAL, "FOR" },
326 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
327 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
328 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
329 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
330 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
331 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
0d863452 332 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
bbf60fe6
DM
333 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
334 { IF, TOKENTYPE_IVAL, "IF" },
335 { LABEL, TOKENTYPE_PVAL, "LABEL" },
336 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
337 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
338 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
339 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
340 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
341 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
342 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
343 { MY, TOKENTYPE_IVAL, "MY" },
344 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
345 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
346 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
347 { OROP, TOKENTYPE_IVAL, "OROP" },
348 { OROR, TOKENTYPE_NONE, "OROR" },
349 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
350 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
351 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
352 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
353 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
354 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
355 { PREINC, TOKENTYPE_NONE, "PREINC" },
356 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
357 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
358 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
359 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
360 { SUB, TOKENTYPE_NONE, "SUB" },
361 { THING, TOKENTYPE_OPVAL, "THING" },
362 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
363 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
364 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
365 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
366 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
367 { USE, TOKENTYPE_IVAL, "USE" },
0d863452 368 { WHEN, TOKENTYPE_IVAL, "WHEN" },
bbf60fe6
DM
369 { WHILE, TOKENTYPE_IVAL, "WHILE" },
370 { WORD, TOKENTYPE_OPVAL, "WORD" },
be25f609 371 { YADAYADA, TOKENTYPE_IVAL, "YADAYADA" },
c35e046a 372 { 0, TOKENTYPE_NONE, NULL }
bbf60fe6
DM
373};
374
6154021b 375/* dump the returned token in rv, plus any optional arg in pl_yylval */
998054bd 376
bbf60fe6 377STATIC int
704d4215 378S_tokereport(pTHX_ I32 rv, const YYSTYPE* lvalp)
bbf60fe6 379{
97aff369 380 dVAR;
7918f24d
NC
381
382 PERL_ARGS_ASSERT_TOKEREPORT;
383
bbf60fe6 384 if (DEBUG_T_TEST) {
bd61b366 385 const char *name = NULL;
bbf60fe6 386 enum token_type type = TOKENTYPE_NONE;
f54cb97a 387 const struct debug_tokens *p;
396482e1 388 SV* const report = newSVpvs("<== ");
bbf60fe6 389
f54cb97a 390 for (p = debug_tokens; p->token; p++) {
bbf60fe6
DM
391 if (p->token == (int)rv) {
392 name = p->name;
393 type = p->type;
394 break;
395 }
396 }
397 if (name)
54667de8 398 Perl_sv_catpv(aTHX_ report, name);
bbf60fe6
DM
399 else if ((char)rv > ' ' && (char)rv < '~')
400 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
401 else if (!rv)
396482e1 402 sv_catpvs(report, "EOF");
bbf60fe6
DM
403 else
404 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
405 switch (type) {
406 case TOKENTYPE_NONE:
407 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
408 break;
409 case TOKENTYPE_IVAL:
704d4215 410 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)lvalp->ival);
bbf60fe6
DM
411 break;
412 case TOKENTYPE_OPNUM:
413 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
704d4215 414 PL_op_name[lvalp->ival]);
bbf60fe6
DM
415 break;
416 case TOKENTYPE_PVAL:
704d4215 417 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", lvalp->pval);
bbf60fe6
DM
418 break;
419 case TOKENTYPE_OPVAL:
704d4215 420 if (lvalp->opval) {
401441c0 421 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
704d4215
GG
422 PL_op_name[lvalp->opval->op_type]);
423 if (lvalp->opval->op_type == OP_CONST) {
b6007c36 424 Perl_sv_catpvf(aTHX_ report, " %s",
704d4215 425 SvPEEK(cSVOPx_sv(lvalp->opval)));
b6007c36
DM
426 }
427
428 }
401441c0 429 else
396482e1 430 sv_catpvs(report, "(opval=null)");
bbf60fe6
DM
431 break;
432 }
b6007c36 433 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
bbf60fe6
DM
434 };
435 return (int)rv;
998054bd
SC
436}
437
b6007c36
DM
438
439/* print the buffer with suitable escapes */
440
441STATIC void
15f169a1 442S_printbuf(pTHX_ const char *const fmt, const char *const s)
b6007c36 443{
396482e1 444 SV* const tmp = newSVpvs("");
7918f24d
NC
445
446 PERL_ARGS_ASSERT_PRINTBUF;
447
b6007c36
DM
448 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
449 SvREFCNT_dec(tmp);
450}
451
8fa7f367
JH
452#endif
453
ffb4593c
NT
454/*
455 * S_ao
456 *
c963b151
BD
457 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
458 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
ffb4593c
NT
459 */
460
76e3520e 461STATIC int
cea2e8a9 462S_ao(pTHX_ int toketype)
a0d0e21e 463{
97aff369 464 dVAR;
3280af22
NIS
465 if (*PL_bufptr == '=') {
466 PL_bufptr++;
a0d0e21e 467 if (toketype == ANDAND)
6154021b 468 pl_yylval.ival = OP_ANDASSIGN;
a0d0e21e 469 else if (toketype == OROR)
6154021b 470 pl_yylval.ival = OP_ORASSIGN;
c963b151 471 else if (toketype == DORDOR)
6154021b 472 pl_yylval.ival = OP_DORASSIGN;
a0d0e21e
LW
473 toketype = ASSIGNOP;
474 }
475 return toketype;
476}
477
ffb4593c
NT
478/*
479 * S_no_op
480 * When Perl expects an operator and finds something else, no_op
481 * prints the warning. It always prints "<something> found where
482 * operator expected. It prints "Missing semicolon on previous line?"
483 * if the surprise occurs at the start of the line. "do you need to
484 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
485 * where the compiler doesn't know if foo is a method call or a function.
486 * It prints "Missing operator before end of line" if there's nothing
487 * after the missing operator, or "... before <...>" if there is something
488 * after the missing operator.
489 */
490
76e3520e 491STATIC void
15f169a1 492S_no_op(pTHX_ const char *const what, char *s)
463ee0b2 493{
97aff369 494 dVAR;
9d4ba2ae
AL
495 char * const oldbp = PL_bufptr;
496 const bool is_first = (PL_oldbufptr == PL_linestart);
68dc0745 497
7918f24d
NC
498 PERL_ARGS_ASSERT_NO_OP;
499
1189a94a
GS
500 if (!s)
501 s = oldbp;
07c798fb 502 else
1189a94a 503 PL_bufptr = s;
cea2e8a9 504 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
56da5a46
RGS
505 if (ckWARN_d(WARN_SYNTAX)) {
506 if (is_first)
507 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
508 "\t(Missing semicolon on previous line?)\n");
509 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
f54cb97a 510 const char *t;
c35e046a
AL
511 for (t = PL_oldoldbufptr; (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
512 NOOP;
56da5a46
RGS
513 if (t < PL_bufptr && isSPACE(*t))
514 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
515 "\t(Do you need to predeclare %.*s?)\n",
551405c4 516 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
56da5a46
RGS
517 }
518 else {
519 assert(s >= oldbp);
520 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
551405c4 521 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
56da5a46 522 }
07c798fb 523 }
3280af22 524 PL_bufptr = oldbp;
8990e307
LW
525}
526
ffb4593c
NT
527/*
528 * S_missingterm
529 * Complain about missing quote/regexp/heredoc terminator.
d4c19fe8 530 * If it's called with NULL then it cauterizes the line buffer.
ffb4593c
NT
531 * If we're in a delimited string and the delimiter is a control
532 * character, it's reformatted into a two-char sequence like ^C.
533 * This is fatal.
534 */
535
76e3520e 536STATIC void
cea2e8a9 537S_missingterm(pTHX_ char *s)
8990e307 538{
97aff369 539 dVAR;
8990e307
LW
540 char tmpbuf[3];
541 char q;
542 if (s) {
9d4ba2ae 543 char * const nl = strrchr(s,'\n');
d2719217 544 if (nl)
8990e307
LW
545 *nl = '\0';
546 }
463559e7 547 else if (isCNTRL(PL_multi_close)) {
8990e307 548 *tmpbuf = '^';
585ec06d 549 tmpbuf[1] = (char)toCTRL(PL_multi_close);
8990e307
LW
550 tmpbuf[2] = '\0';
551 s = tmpbuf;
552 }
553 else {
eb160463 554 *tmpbuf = (char)PL_multi_close;
8990e307
LW
555 tmpbuf[1] = '\0';
556 s = tmpbuf;
557 }
558 q = strchr(s,'"') ? '\'' : '"';
cea2e8a9 559 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
463ee0b2 560}
79072805 561
ef89dcc3 562#define FEATURE_IS_ENABLED(name) \
0d863452 563 ((0 != (PL_hints & HINT_LOCALIZE_HH)) \
89529cee 564 && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
4a731d7b
NC
565/* The longest string we pass in. */
566#define MAX_FEATURE_LEN (sizeof("switch")-1)
567
0d863452
RH
568/*
569 * S_feature_is_enabled
570 * Check whether the named feature is enabled.
571 */
572STATIC bool
15f169a1 573S_feature_is_enabled(pTHX_ const char *const name, STRLEN namelen)
0d863452 574{
97aff369 575 dVAR;
0d863452 576 HV * const hinthv = GvHV(PL_hintgv);
4a731d7b 577 char he_name[8 + MAX_FEATURE_LEN] = "feature_";
7918f24d
NC
578
579 PERL_ARGS_ASSERT_FEATURE_IS_ENABLED;
580
4a731d7b
NC
581 assert(namelen <= MAX_FEATURE_LEN);
582 memcpy(&he_name[8], name, namelen);
d4c19fe8 583
7b9ef140 584 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
0d863452
RH
585}
586
ffb4593c
NT
587/*
588 * Perl_deprecate
ffb4593c
NT
589 */
590
79072805 591void
15f169a1 592Perl_deprecate(pTHX_ const char *const s)
a0d0e21e 593{
7918f24d
NC
594 PERL_ARGS_ASSERT_DEPRECATE;
595
a2a5de95 596 Perl_ck_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
a0d0e21e
LW
597}
598
ffb4593c 599/*
9cbb5ea2
GS
600 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
601 * utf16-to-utf8-reversed.
ffb4593c
NT
602 */
603
c39cd008
GS
604#ifdef PERL_CR_FILTER
605static void
606strip_return(SV *sv)
607{
95a20fc0 608 register const char *s = SvPVX_const(sv);
9d4ba2ae 609 register const char * const e = s + SvCUR(sv);
7918f24d
NC
610
611 PERL_ARGS_ASSERT_STRIP_RETURN;
612
c39cd008
GS
613 /* outer loop optimized to do nothing if there are no CR-LFs */
614 while (s < e) {
615 if (*s++ == '\r' && *s == '\n') {
616 /* hit a CR-LF, need to copy the rest */
617 register char *d = s - 1;
618 *d++ = *s++;
619 while (s < e) {
620 if (*s == '\r' && s[1] == '\n')
621 s++;
622 *d++ = *s++;
623 }
624 SvCUR(sv) -= s - d;
625 return;
626 }
627 }
628}
a868473f 629
76e3520e 630STATIC I32
c39cd008 631S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
a868473f 632{
f54cb97a 633 const I32 count = FILTER_READ(idx+1, sv, maxlen);
c39cd008
GS
634 if (count > 0 && !maxlen)
635 strip_return(sv);
636 return count;
a868473f
NIS
637}
638#endif
639
199e78b7
DM
640
641
ffb4593c
NT
642/*
643 * Perl_lex_start
5486870f 644 *
e3abe207 645 * Create a parser object and initialise its parser and lexer fields
5486870f
DM
646 *
647 * rsfp is the opened file handle to read from (if any),
648 *
649 * line holds any initial content already read from the file (or in
650 * the case of no file, such as an eval, the whole contents);
651 *
652 * new_filter indicates that this is a new file and it shouldn't inherit
653 * the filters from the current parser (ie require).
ffb4593c
NT
654 */
655
a0d0e21e 656void
5486870f 657Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp, bool new_filter)
79072805 658{
97aff369 659 dVAR;
6ef55633 660 const char *s = NULL;
8990e307 661 STRLEN len;
5486870f 662 yy_parser *parser, *oparser;
acdf0a21
DM
663
664 /* create and initialise a parser */
665
199e78b7 666 Newxz(parser, 1, yy_parser);
5486870f 667 parser->old_parser = oparser = PL_parser;
acdf0a21
DM
668 PL_parser = parser;
669
670 Newx(parser->stack, YYINITDEPTH, yy_stack_frame);
671 parser->ps = parser->stack;
672 parser->stack_size = YYINITDEPTH;
673
674 parser->stack->state = 0;
675 parser->yyerrstatus = 0;
676 parser->yychar = YYEMPTY; /* Cause a token to be read. */
677
e3abe207
DM
678 /* on scope exit, free this parser and restore any outer one */
679 SAVEPARSER(parser);
7c4baf47 680 parser->saved_curcop = PL_curcop;
e3abe207 681
acdf0a21 682 /* initialise lexer state */
8990e307 683
fb205e7a
DM
684#ifdef PERL_MAD
685 parser->curforce = -1;
686#else
687 parser->nexttoke = 0;
688#endif
ca4cfd28 689 parser->error_count = oparser ? oparser->error_count : 0;
c2598295 690 parser->copline = NOLINE;
5afb0a62 691 parser->lex_state = LEX_NORMAL;
c2598295 692 parser->expect = XSTATE;
2f9285f8 693 parser->rsfp = rsfp;
56b27c9a 694 parser->rsfp_filters = (new_filter || !oparser) ? newAV()
502c6561 695 : MUTABLE_AV(SvREFCNT_inc(oparser->rsfp_filters));
2f9285f8 696
199e78b7
DM
697 Newx(parser->lex_brackstack, 120, char);
698 Newx(parser->lex_casestack, 12, char);
699 *parser->lex_casestack = '\0';
02b34bbe 700
10efb74f
NC
701 if (line) {
702 s = SvPV_const(line, len);
703 } else {
704 len = 0;
705 }
bdc0bf6f 706
10efb74f 707 if (!len) {
bdc0bf6f 708 parser->linestr = newSVpvs("\n;");
10efb74f 709 } else if (SvREADONLY(line) || s[len-1] != ';') {
bdc0bf6f 710 parser->linestr = newSVsv(line);
10efb74f 711 if (s[len-1] != ';')
bdc0bf6f 712 sv_catpvs(parser->linestr, "\n;");
6c5ce11d
NC
713 } else {
714 SvTEMP_off(line);
715 SvREFCNT_inc_simple_void_NN(line);
bdc0bf6f 716 parser->linestr = line;
8990e307 717 }
f06b5848
DM
718 parser->oldoldbufptr =
719 parser->oldbufptr =
720 parser->bufptr =
721 parser->linestart = SvPVX(parser->linestr);
722 parser->bufend = parser->bufptr + SvCUR(parser->linestr);
723 parser->last_lop = parser->last_uni = NULL;
79072805 724}
a687059c 725
e3abe207
DM
726
727/* delete a parser object */
728
729void
730Perl_parser_free(pTHX_ const yy_parser *parser)
731{
7918f24d
NC
732 PERL_ARGS_ASSERT_PARSER_FREE;
733
7c4baf47 734 PL_curcop = parser->saved_curcop;
bdc0bf6f
DM
735 SvREFCNT_dec(parser->linestr);
736
2f9285f8
DM
737 if (parser->rsfp == PerlIO_stdin())
738 PerlIO_clearerr(parser->rsfp);
799361c3
SH
739 else if (parser->rsfp && (!parser->old_parser ||
740 (parser->old_parser && parser->rsfp != parser->old_parser->rsfp)))
2f9285f8 741 PerlIO_close(parser->rsfp);
5486870f 742 SvREFCNT_dec(parser->rsfp_filters);
2f9285f8 743
e3abe207
DM
744 Safefree(parser->stack);
745 Safefree(parser->lex_brackstack);
746 Safefree(parser->lex_casestack);
747 PL_parser = parser->old_parser;
748 Safefree(parser);
749}
750
751
ffb4593c
NT
752/*
753 * Perl_lex_end
9cbb5ea2
GS
754 * Finalizer for lexing operations. Must be called when the parser is
755 * done with the lexer.
ffb4593c
NT
756 */
757
463ee0b2 758void
864dbfa3 759Perl_lex_end(pTHX)
463ee0b2 760{
97aff369 761 dVAR;
3280af22 762 PL_doextract = FALSE;
463ee0b2
LW
763}
764
ffb4593c
NT
765/*
766 * S_incline
767 * This subroutine has nothing to do with tilting, whether at windmills
768 * or pinball tables. Its name is short for "increment line". It
57843af0 769 * increments the current line number in CopLINE(PL_curcop) and checks
ffb4593c 770 * to see whether the line starts with a comment of the form
9cbb5ea2
GS
771 * # line 500 "foo.pm"
772 * If so, it sets the current line number and file to the values in the comment.
ffb4593c
NT
773 */
774
76e3520e 775STATIC void
d9095cec 776S_incline(pTHX_ const char *s)
463ee0b2 777{
97aff369 778 dVAR;
d9095cec
NC
779 const char *t;
780 const char *n;
781 const char *e;
463ee0b2 782
7918f24d
NC
783 PERL_ARGS_ASSERT_INCLINE;
784
57843af0 785 CopLINE_inc(PL_curcop);
463ee0b2
LW
786 if (*s++ != '#')
787 return;
d4c19fe8
AL
788 while (SPACE_OR_TAB(*s))
789 s++;
73659bf1
GS
790 if (strnEQ(s, "line", 4))
791 s += 4;
792 else
793 return;
084592ab 794 if (SPACE_OR_TAB(*s))
73659bf1 795 s++;
4e553d73 796 else
73659bf1 797 return;
d4c19fe8
AL
798 while (SPACE_OR_TAB(*s))
799 s++;
463ee0b2
LW
800 if (!isDIGIT(*s))
801 return;
d4c19fe8 802
463ee0b2
LW
803 n = s;
804 while (isDIGIT(*s))
805 s++;
07714eb4 806 if (!SPACE_OR_TAB(*s) && *s != '\r' && *s != '\n' && *s != '\0')
26b6dc3f 807 return;
bf4acbe4 808 while (SPACE_OR_TAB(*s))
463ee0b2 809 s++;
73659bf1 810 if (*s == '"' && (t = strchr(s+1, '"'))) {
463ee0b2 811 s++;
73659bf1
GS
812 e = t + 1;
813 }
463ee0b2 814 else {
c35e046a
AL
815 t = s;
816 while (!isSPACE(*t))
817 t++;
73659bf1 818 e = t;
463ee0b2 819 }
bf4acbe4 820 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
73659bf1
GS
821 e++;
822 if (*e != '\n' && *e != '\0')
823 return; /* false alarm */
824
f4dd75d9 825 if (t - s > 0) {
d9095cec 826 const STRLEN len = t - s;
8a5ee598 827#ifndef USE_ITHREADS
19bad673
NC
828 SV *const temp_sv = CopFILESV(PL_curcop);
829 const char *cf;
830 STRLEN tmplen;
831
832 if (temp_sv) {
833 cf = SvPVX(temp_sv);
834 tmplen = SvCUR(temp_sv);
835 } else {
836 cf = NULL;
837 tmplen = 0;
838 }
839
42d9b98d 840 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
e66cf94c
RGS
841 /* must copy *{"::_<(eval N)[oldfilename:L]"}
842 * to *{"::_<newfilename"} */
44867030
NC
843 /* However, the long form of evals is only turned on by the
844 debugger - usually they're "(eval %lu)" */
845 char smallbuf[128];
846 char *tmpbuf;
847 GV **gvp;
d9095cec 848 STRLEN tmplen2 = len;
798b63bc 849 if (tmplen + 2 <= sizeof smallbuf)
e66cf94c
RGS
850 tmpbuf = smallbuf;
851 else
2ae0db35 852 Newx(tmpbuf, tmplen + 2, char);
44867030
NC
853 tmpbuf[0] = '_';
854 tmpbuf[1] = '<';
2ae0db35 855 memcpy(tmpbuf + 2, cf, tmplen);
44867030 856 tmplen += 2;
8a5ee598
RGS
857 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
858 if (gvp) {
44867030
NC
859 char *tmpbuf2;
860 GV *gv2;
861
862 if (tmplen2 + 2 <= sizeof smallbuf)
863 tmpbuf2 = smallbuf;
864 else
865 Newx(tmpbuf2, tmplen2 + 2, char);
866
867 if (tmpbuf2 != smallbuf || tmpbuf != smallbuf) {
868 /* Either they malloc'd it, or we malloc'd it,
869 so no prefix is present in ours. */
870 tmpbuf2[0] = '_';
871 tmpbuf2[1] = '<';
872 }
873
874 memcpy(tmpbuf2 + 2, s, tmplen2);
875 tmplen2 += 2;
876
8a5ee598 877 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
e5527e4b 878 if (!isGV(gv2)) {
8a5ee598 879 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
e5527e4b
RGS
880 /* adjust ${"::_<newfilename"} to store the new file name */
881 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
3cb1dbc6
NC
882 GvHV(gv2) = MUTABLE_HV(SvREFCNT_inc(GvHV(*gvp)));
883 GvAV(gv2) = MUTABLE_AV(SvREFCNT_inc(GvAV(*gvp)));
e5527e4b 884 }
44867030
NC
885
886 if (tmpbuf2 != smallbuf) Safefree(tmpbuf2);
8a5ee598 887 }
e66cf94c 888 if (tmpbuf != smallbuf) Safefree(tmpbuf);
e66cf94c 889 }
8a5ee598 890#endif
05ec9bb3 891 CopFILE_free(PL_curcop);
d9095cec 892 CopFILE_setn(PL_curcop, s, len);
f4dd75d9 893 }
57843af0 894 CopLINE_set(PL_curcop, atoi(n)-1);
463ee0b2
LW
895}
896
29595ff2 897#ifdef PERL_MAD
cd81e915 898/* skip space before PL_thistoken */
29595ff2
NC
899
900STATIC char *
901S_skipspace0(pTHX_ register char *s)
902{
7918f24d
NC
903 PERL_ARGS_ASSERT_SKIPSPACE0;
904
29595ff2
NC
905 s = skipspace(s);
906 if (!PL_madskills)
907 return s;
cd81e915
NC
908 if (PL_skipwhite) {
909 if (!PL_thiswhite)
6b29d1f5 910 PL_thiswhite = newSVpvs("");
cd81e915
NC
911 sv_catsv(PL_thiswhite, PL_skipwhite);
912 sv_free(PL_skipwhite);
913 PL_skipwhite = 0;
914 }
915 PL_realtokenstart = s - SvPVX(PL_linestr);
29595ff2
NC
916 return s;
917}
918
cd81e915 919/* skip space after PL_thistoken */
29595ff2
NC
920
921STATIC char *
922S_skipspace1(pTHX_ register char *s)
923{
d4c19fe8 924 const char *start = s;
29595ff2
NC
925 I32 startoff = start - SvPVX(PL_linestr);
926
7918f24d
NC
927 PERL_ARGS_ASSERT_SKIPSPACE1;
928
29595ff2
NC
929 s = skipspace(s);
930 if (!PL_madskills)
931 return s;
932 start = SvPVX(PL_linestr) + startoff;
cd81e915 933 if (!PL_thistoken && PL_realtokenstart >= 0) {
d4c19fe8 934 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
cd81e915
NC
935 PL_thistoken = newSVpvn(tstart, start - tstart);
936 }
937 PL_realtokenstart = -1;
938 if (PL_skipwhite) {
939 if (!PL_nextwhite)
6b29d1f5 940 PL_nextwhite = newSVpvs("");
cd81e915
NC
941 sv_catsv(PL_nextwhite, PL_skipwhite);
942 sv_free(PL_skipwhite);
943 PL_skipwhite = 0;
29595ff2
NC
944 }
945 return s;
946}
947
948STATIC char *
949S_skipspace2(pTHX_ register char *s, SV **svp)
950{
c35e046a
AL
951 char *start;
952 const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
953 const I32 startoff = s - SvPVX(PL_linestr);
954
7918f24d
NC
955 PERL_ARGS_ASSERT_SKIPSPACE2;
956
29595ff2
NC
957 s = skipspace(s);
958 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
959 if (!PL_madskills || !svp)
960 return s;
961 start = SvPVX(PL_linestr) + startoff;
cd81e915 962 if (!PL_thistoken && PL_realtokenstart >= 0) {
d4c19fe8 963 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
cd81e915
NC
964 PL_thistoken = newSVpvn(tstart, start - tstart);
965 PL_realtokenstart = -1;
29595ff2 966 }
cd81e915 967 if (PL_skipwhite) {
29595ff2 968 if (!*svp)
6b29d1f5 969 *svp = newSVpvs("");
cd81e915
NC
970 sv_setsv(*svp, PL_skipwhite);
971 sv_free(PL_skipwhite);
972 PL_skipwhite = 0;
29595ff2
NC
973 }
974
975 return s;
976}
977#endif
978
80a702cd 979STATIC void
15f169a1 980S_update_debugger_info(pTHX_ SV *orig_sv, const char *const buf, STRLEN len)
80a702cd
RGS
981{
982 AV *av = CopFILEAVx(PL_curcop);
983 if (av) {
b9f83d2f 984 SV * const sv = newSV_type(SVt_PVMG);
5fa550fb
NC
985 if (orig_sv)
986 sv_setsv(sv, orig_sv);
987 else
988 sv_setpvn(sv, buf, len);
80a702cd
RGS
989 (void)SvIOK_on(sv);
990 SvIV_set(sv, 0);
991 av_store(av, (I32)CopLINE(PL_curcop), sv);
992 }
993}
994
ffb4593c
NT
995/*
996 * S_skipspace
997 * Called to gobble the appropriate amount and type of whitespace.
998 * Skips comments as well.
999 */
1000
76e3520e 1001STATIC char *
cea2e8a9 1002S_skipspace(pTHX_ register char *s)
a687059c 1003{
97aff369 1004 dVAR;
5db06880
NC
1005#ifdef PERL_MAD
1006 int curoff;
1007 int startoff = s - SvPVX(PL_linestr);
1008
7918f24d
NC
1009 PERL_ARGS_ASSERT_SKIPSPACE;
1010
cd81e915
NC
1011 if (PL_skipwhite) {
1012 sv_free(PL_skipwhite);
1013 PL_skipwhite = 0;
5db06880
NC
1014 }
1015#endif
7918f24d 1016 PERL_ARGS_ASSERT_SKIPSPACE;
5db06880 1017
3280af22 1018 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
bf4acbe4 1019 while (s < PL_bufend && SPACE_OR_TAB(*s))
463ee0b2 1020 s++;
5db06880
NC
1021#ifdef PERL_MAD
1022 goto done;
1023#else
463ee0b2 1024 return s;
5db06880 1025#endif
463ee0b2
LW
1026 }
1027 for (;;) {
fd049845 1028 STRLEN prevlen;
09bef843 1029 SSize_t oldprevlen, oldoldprevlen;
9c5ffd7c 1030 SSize_t oldloplen = 0, oldunilen = 0;
60e6418e
GS
1031 while (s < PL_bufend && isSPACE(*s)) {
1032 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
1033 incline(s);
1034 }
ffb4593c
NT
1035
1036 /* comment */
3280af22
NIS
1037 if (s < PL_bufend && *s == '#') {
1038 while (s < PL_bufend && *s != '\n')
463ee0b2 1039 s++;
60e6418e 1040 if (s < PL_bufend) {
463ee0b2 1041 s++;
60e6418e
GS
1042 if (PL_in_eval && !PL_rsfp) {
1043 incline(s);
1044 continue;
1045 }
1046 }
463ee0b2 1047 }
ffb4593c
NT
1048
1049 /* only continue to recharge the buffer if we're at the end
1050 * of the buffer, we're not reading from a source filter, and
1051 * we're in normal lexing mode
1052 */
09bef843
SB
1053 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
1054 PL_lex_state == LEX_FORMLINE)
5db06880
NC
1055#ifdef PERL_MAD
1056 goto done;
1057#else
463ee0b2 1058 return s;
5db06880 1059#endif
ffb4593c
NT
1060
1061 /* try to recharge the buffer */
5db06880
NC
1062#ifdef PERL_MAD
1063 curoff = s - SvPVX(PL_linestr);
1064#endif
1065
9cbb5ea2 1066 if ((s = filter_gets(PL_linestr, PL_rsfp,
bd61b366 1067 (prevlen = SvCUR(PL_linestr)))) == NULL)
9cbb5ea2 1068 {
5db06880
NC
1069#ifdef PERL_MAD
1070 if (PL_madskills && curoff != startoff) {
cd81e915 1071 if (!PL_skipwhite)
6b29d1f5 1072 PL_skipwhite = newSVpvs("");
cd81e915 1073 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
5db06880
NC
1074 curoff - startoff);
1075 }
1076
1077 /* mustn't throw out old stuff yet if madpropping */
1078 SvCUR(PL_linestr) = curoff;
1079 s = SvPVX(PL_linestr) + curoff;
1080 *s = 0;
1081 if (curoff && s[-1] == '\n')
1082 s[-1] = ' ';
1083#endif
1084
9cbb5ea2 1085 /* end of file. Add on the -p or -n magic */
cd81e915 1086 /* XXX these shouldn't really be added here, can't set PL_faketokens */
01a19ab0 1087 if (PL_minus_p) {
5db06880 1088#ifdef PERL_MAD
6502358f 1089 sv_catpvs(PL_linestr,
5db06880
NC
1090 ";}continue{print or die qq(-p destination: $!\\n);}");
1091#else
6502358f 1092 sv_setpvs(PL_linestr,
01a19ab0 1093 ";}continue{print or die qq(-p destination: $!\\n);}");
5db06880 1094#endif
3280af22 1095 PL_minus_n = PL_minus_p = 0;
a0d0e21e 1096 }
01a19ab0 1097 else if (PL_minus_n) {
5db06880 1098#ifdef PERL_MAD
76f68e9b 1099 sv_catpvs(PL_linestr, ";}");
5db06880 1100#else
76f68e9b 1101 sv_setpvs(PL_linestr, ";}");
5db06880 1102#endif
01a19ab0
NC
1103 PL_minus_n = 0;
1104 }
a0d0e21e 1105 else
5db06880 1106#ifdef PERL_MAD
76f68e9b 1107 sv_catpvs(PL_linestr,";");
5db06880 1108#else
76f68e9b 1109 sv_setpvs(PL_linestr,";");
5db06880 1110#endif
ffb4593c
NT
1111
1112 /* reset variables for next time we lex */
9cbb5ea2 1113 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
89122651
NC
1114 = SvPVX(PL_linestr)
1115#ifdef PERL_MAD
1116 + curoff
1117#endif
1118 ;
3280af22 1119 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 1120 PL_last_lop = PL_last_uni = NULL;
ffb4593c 1121
4c84d7f2 1122 /* Close the filehandle. Could be from
ffb4593c
NT
1123 * STDIN, or a regular file. If we were reading code from
1124 * STDIN (because the commandline held no -e or filename)
1125 * then we don't close it, we reset it so the code can
1126 * read from STDIN too.
1127 */
1128
4c84d7f2 1129 if ((PerlIO*)PL_rsfp == PerlIO_stdin())
3280af22 1130 PerlIO_clearerr(PL_rsfp);
8990e307 1131 else
3280af22 1132 (void)PerlIO_close(PL_rsfp);
4608196e 1133 PL_rsfp = NULL;
463ee0b2
LW
1134 return s;
1135 }
ffb4593c
NT
1136
1137 /* not at end of file, so we only read another line */
09bef843
SB
1138 /* make corresponding updates to old pointers, for yyerror() */
1139 oldprevlen = PL_oldbufptr - PL_bufend;
1140 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1141 if (PL_last_uni)
1142 oldunilen = PL_last_uni - PL_bufend;
1143 if (PL_last_lop)
1144 oldloplen = PL_last_lop - PL_bufend;
3280af22
NIS
1145 PL_linestart = PL_bufptr = s + prevlen;
1146 PL_bufend = s + SvCUR(PL_linestr);
1147 s = PL_bufptr;
09bef843
SB
1148 PL_oldbufptr = s + oldprevlen;
1149 PL_oldoldbufptr = s + oldoldprevlen;
1150 if (PL_last_uni)
1151 PL_last_uni = s + oldunilen;
1152 if (PL_last_lop)
1153 PL_last_lop = s + oldloplen;
a0d0e21e 1154 incline(s);
ffb4593c
NT
1155
1156 /* debugger active and we're not compiling the debugger code,
1157 * so store the line into the debugger's array of lines
1158 */
65269a95 1159 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
5fa550fb 1160 update_debugger_info(NULL, PL_bufptr, PL_bufend - PL_bufptr);
463ee0b2 1161 }
5db06880
NC
1162
1163#ifdef PERL_MAD
1164 done:
1165 if (PL_madskills) {
cd81e915 1166 if (!PL_skipwhite)
6b29d1f5 1167 PL_skipwhite = newSVpvs("");
5db06880
NC
1168 curoff = s - SvPVX(PL_linestr);
1169 if (curoff - startoff)
cd81e915 1170 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
5db06880
NC
1171 curoff - startoff);
1172 }
1173 return s;
1174#endif
a687059c 1175}
378cc40b 1176
ffb4593c
NT
1177/*
1178 * S_check_uni
1179 * Check the unary operators to ensure there's no ambiguity in how they're
1180 * used. An ambiguous piece of code would be:
1181 * rand + 5
1182 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1183 * the +5 is its argument.
1184 */
1185
76e3520e 1186STATIC void
cea2e8a9 1187S_check_uni(pTHX)
ba106d47 1188{
97aff369 1189 dVAR;
d4c19fe8
AL
1190 const char *s;
1191 const char *t;
2f3197b3 1192
3280af22 1193 if (PL_oldoldbufptr != PL_last_uni)
2f3197b3 1194 return;
3280af22
NIS
1195 while (isSPACE(*PL_last_uni))
1196 PL_last_uni++;
c35e046a
AL
1197 s = PL_last_uni;
1198 while (isALNUM_lazy_if(s,UTF) || *s == '-')
1199 s++;
3280af22 1200 if ((t = strchr(s, '(')) && t < PL_bufptr)
a0d0e21e 1201 return;
6136c704 1202
9b387841
NC
1203 Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
1204 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1205 (int)(s - PL_last_uni), PL_last_uni);
2f3197b3
LW
1206}
1207
ffb4593c
NT
1208/*
1209 * LOP : macro to build a list operator. Its behaviour has been replaced
1210 * with a subroutine, S_lop() for which LOP is just another name.
1211 */
1212
a0d0e21e
LW
1213#define LOP(f,x) return lop(f,x,s)
1214
ffb4593c
NT
1215/*
1216 * S_lop
1217 * Build a list operator (or something that might be one). The rules:
1218 * - if we have a next token, then it's a list operator [why?]
1219 * - if the next thing is an opening paren, then it's a function
1220 * - else it's a list operator
1221 */
1222
76e3520e 1223STATIC I32
a0be28da 1224S_lop(pTHX_ I32 f, int x, char *s)
ffed7fef 1225{
97aff369 1226 dVAR;
7918f24d
NC
1227
1228 PERL_ARGS_ASSERT_LOP;
1229
6154021b 1230 pl_yylval.ival = f;
35c8bce7 1231 CLINE;
3280af22
NIS
1232 PL_expect = x;
1233 PL_bufptr = s;
1234 PL_last_lop = PL_oldbufptr;
eb160463 1235 PL_last_lop_op = (OPCODE)f;
5db06880
NC
1236#ifdef PERL_MAD
1237 if (PL_lasttoke)
1238 return REPORT(LSTOP);
1239#else
3280af22 1240 if (PL_nexttoke)
bbf60fe6 1241 return REPORT(LSTOP);
5db06880 1242#endif
79072805 1243 if (*s == '(')
bbf60fe6 1244 return REPORT(FUNC);
29595ff2 1245 s = PEEKSPACE(s);
79072805 1246 if (*s == '(')
bbf60fe6 1247 return REPORT(FUNC);
79072805 1248 else
bbf60fe6 1249 return REPORT(LSTOP);
79072805
LW
1250}
1251
5db06880
NC
1252#ifdef PERL_MAD
1253 /*
1254 * S_start_force
1255 * Sets up for an eventual force_next(). start_force(0) basically does
1256 * an unshift, while start_force(-1) does a push. yylex removes items
1257 * on the "pop" end.
1258 */
1259
1260STATIC void
1261S_start_force(pTHX_ int where)
1262{
1263 int i;
1264
cd81e915 1265 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
5db06880 1266 where = PL_lasttoke;
cd81e915
NC
1267 assert(PL_curforce < 0 || PL_curforce == where);
1268 if (PL_curforce != where) {
5db06880
NC
1269 for (i = PL_lasttoke; i > where; --i) {
1270 PL_nexttoke[i] = PL_nexttoke[i-1];
1271 }
1272 PL_lasttoke++;
1273 }
cd81e915 1274 if (PL_curforce < 0) /* in case of duplicate start_force() */
5db06880 1275 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
cd81e915
NC
1276 PL_curforce = where;
1277 if (PL_nextwhite) {
5db06880 1278 if (PL_madskills)
6b29d1f5 1279 curmad('^', newSVpvs(""));
cd81e915 1280 CURMAD('_', PL_nextwhite);
5db06880
NC
1281 }
1282}
1283
1284STATIC void
1285S_curmad(pTHX_ char slot, SV *sv)
1286{
1287 MADPROP **where;
1288
1289 if (!sv)
1290 return;
cd81e915
NC
1291 if (PL_curforce < 0)
1292 where = &PL_thismad;
5db06880 1293 else
cd81e915 1294 where = &PL_nexttoke[PL_curforce].next_mad;
5db06880 1295
cd81e915 1296 if (PL_faketokens)
76f68e9b 1297 sv_setpvs(sv, "");
5db06880
NC
1298 else {
1299 if (!IN_BYTES) {
1300 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1301 SvUTF8_on(sv);
1302 else if (PL_encoding) {
1303 sv_recode_to_utf8(sv, PL_encoding);
1304 }
1305 }
1306 }
1307
1308 /* keep a slot open for the head of the list? */
1309 if (slot != '_' && *where && (*where)->mad_key == '^') {
1310 (*where)->mad_key = slot;
daba3364 1311 sv_free(MUTABLE_SV(((*where)->mad_val)));
5db06880
NC
1312 (*where)->mad_val = (void*)sv;
1313 }
1314 else
1315 addmad(newMADsv(slot, sv), where, 0);
1316}
1317#else
b3f24c00
MHM
1318# define start_force(where) NOOP
1319# define curmad(slot, sv) NOOP
5db06880
NC
1320#endif
1321
ffb4593c
NT
1322/*
1323 * S_force_next
9cbb5ea2 1324 * When the lexer realizes it knows the next token (for instance,
ffb4593c 1325 * it is reordering tokens for the parser) then it can call S_force_next
9cbb5ea2 1326 * to know what token to return the next time the lexer is called. Caller
5db06880
NC
1327 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1328 * and possibly PL_expect to ensure the lexer handles the token correctly.
ffb4593c
NT
1329 */
1330
4e553d73 1331STATIC void
cea2e8a9 1332S_force_next(pTHX_ I32 type)
79072805 1333{
97aff369 1334 dVAR;
704d4215
GG
1335#ifdef DEBUGGING
1336 if (DEBUG_T_TEST) {
1337 PerlIO_printf(Perl_debug_log, "### forced token:\n");
f05d7009 1338 tokereport(type, &NEXTVAL_NEXTTOKE);
704d4215
GG
1339 }
1340#endif
5db06880 1341#ifdef PERL_MAD
cd81e915 1342 if (PL_curforce < 0)
5db06880 1343 start_force(PL_lasttoke);
cd81e915 1344 PL_nexttoke[PL_curforce].next_type = type;
5db06880
NC
1345 if (PL_lex_state != LEX_KNOWNEXT)
1346 PL_lex_defer = PL_lex_state;
1347 PL_lex_state = LEX_KNOWNEXT;
1348 PL_lex_expect = PL_expect;
cd81e915 1349 PL_curforce = -1;
5db06880 1350#else
3280af22
NIS
1351 PL_nexttype[PL_nexttoke] = type;
1352 PL_nexttoke++;
1353 if (PL_lex_state != LEX_KNOWNEXT) {
1354 PL_lex_defer = PL_lex_state;
1355 PL_lex_expect = PL_expect;
1356 PL_lex_state = LEX_KNOWNEXT;
79072805 1357 }
5db06880 1358#endif
79072805
LW
1359}
1360
d0a148a6 1361STATIC SV *
15f169a1 1362S_newSV_maybe_utf8(pTHX_ const char *const start, STRLEN len)
d0a148a6 1363{
97aff369 1364 dVAR;
740cce10 1365 SV * const sv = newSVpvn_utf8(start, len,
eaf7a4d2
CS
1366 !IN_BYTES
1367 && UTF
1368 && !is_ascii_string((const U8*)start, len)
740cce10 1369 && is_utf8_string((const U8*)start, len));
d0a148a6
NC
1370 return sv;
1371}
1372
ffb4593c
NT
1373/*
1374 * S_force_word
1375 * When the lexer knows the next thing is a word (for instance, it has
1376 * just seen -> and it knows that the next char is a word char, then
02b34bbe
DM
1377 * it calls S_force_word to stick the next word into the PL_nexttoke/val
1378 * lookahead.
ffb4593c
NT
1379 *
1380 * Arguments:
b1b65b59 1381 * char *start : buffer position (must be within PL_linestr)
02b34bbe 1382 * int token : PL_next* will be this type of bare word (e.g., METHOD,WORD)
ffb4593c
NT
1383 * int check_keyword : if true, Perl checks to make sure the word isn't
1384 * a keyword (do this if the word is a label, e.g. goto FOO)
1385 * int allow_pack : if true, : characters will also be allowed (require,
1386 * use, etc. do this)
9cbb5ea2 1387 * int allow_initial_tick : used by the "sub" lexer only.
ffb4593c
NT
1388 */
1389
76e3520e 1390STATIC char *
cea2e8a9 1391S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
79072805 1392{
97aff369 1393 dVAR;
463ee0b2
LW
1394 register char *s;
1395 STRLEN len;
4e553d73 1396
7918f24d
NC
1397 PERL_ARGS_ASSERT_FORCE_WORD;
1398
29595ff2 1399 start = SKIPSPACE1(start);
463ee0b2 1400 s = start;
7e2040f0 1401 if (isIDFIRST_lazy_if(s,UTF) ||
a0d0e21e 1402 (allow_pack && *s == ':') ||
15f0808c 1403 (allow_initial_tick && *s == '\'') )
a0d0e21e 1404 {
3280af22 1405 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
5458a98a 1406 if (check_keyword && keyword(PL_tokenbuf, len, 0))
463ee0b2 1407 return start;
cd81e915 1408 start_force(PL_curforce);
5db06880
NC
1409 if (PL_madskills)
1410 curmad('X', newSVpvn(start,s-start));
463ee0b2 1411 if (token == METHOD) {
29595ff2 1412 s = SKIPSPACE1(s);
463ee0b2 1413 if (*s == '(')
3280af22 1414 PL_expect = XTERM;
463ee0b2 1415 else {
3280af22 1416 PL_expect = XOPERATOR;
463ee0b2 1417 }
79072805 1418 }
e74e6b3d 1419 if (PL_madskills)
63575281 1420 curmad('g', newSVpvs( "forced" ));
9ded7720 1421 NEXTVAL_NEXTTOKE.opval
d0a148a6
NC
1422 = (OP*)newSVOP(OP_CONST,0,
1423 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
9ded7720 1424 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
79072805
LW
1425 force_next(token);
1426 }
1427 return s;
1428}
1429
ffb4593c
NT
1430/*
1431 * S_force_ident
9cbb5ea2 1432 * Called when the lexer wants $foo *foo &foo etc, but the program
ffb4593c
NT
1433 * text only contains the "foo" portion. The first argument is a pointer
1434 * to the "foo", and the second argument is the type symbol to prefix.
1435 * Forces the next token to be a "WORD".
9cbb5ea2 1436 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
ffb4593c
NT
1437 */
1438
76e3520e 1439STATIC void
bfed75c6 1440S_force_ident(pTHX_ register const char *s, int kind)
79072805 1441{
97aff369 1442 dVAR;
7918f24d
NC
1443
1444 PERL_ARGS_ASSERT_FORCE_IDENT;
1445
c35e046a 1446 if (*s) {
90e5519e
NC
1447 const STRLEN len = strlen(s);
1448 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
cd81e915 1449 start_force(PL_curforce);
9ded7720 1450 NEXTVAL_NEXTTOKE.opval = o;
79072805 1451 force_next(WORD);
748a9306 1452 if (kind) {
11343788 1453 o->op_private = OPpCONST_ENTERED;
55497cff 1454 /* XXX see note in pp_entereval() for why we forgo typo
1455 warnings if the symbol must be introduced in an eval.
1456 GSAR 96-10-12 */
90e5519e
NC
1457 gv_fetchpvn_flags(s, len,
1458 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1459 : GV_ADD,
1460 kind == '$' ? SVt_PV :
1461 kind == '@' ? SVt_PVAV :
1462 kind == '%' ? SVt_PVHV :
a0d0e21e 1463 SVt_PVGV
90e5519e 1464 );
748a9306 1465 }
79072805
LW
1466 }
1467}
1468
1571675a
GS
1469NV
1470Perl_str_to_version(pTHX_ SV *sv)
1471{
1472 NV retval = 0.0;
1473 NV nshift = 1.0;
1474 STRLEN len;
cfd0369c 1475 const char *start = SvPV_const(sv,len);
9d4ba2ae 1476 const char * const end = start + len;
504618e9 1477 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
7918f24d
NC
1478
1479 PERL_ARGS_ASSERT_STR_TO_VERSION;
1480
1571675a 1481 while (start < end) {
ba210ebe 1482 STRLEN skip;
1571675a
GS
1483 UV n;
1484 if (utf)
9041c2e3 1485 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1571675a
GS
1486 else {
1487 n = *(U8*)start;
1488 skip = 1;
1489 }
1490 retval += ((NV)n)/nshift;
1491 start += skip;
1492 nshift *= 1000;
1493 }
1494 return retval;
1495}
1496
4e553d73 1497/*
ffb4593c
NT
1498 * S_force_version
1499 * Forces the next token to be a version number.
e759cc13
RGS
1500 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1501 * and if "guessing" is TRUE, then no new token is created (and the caller
1502 * must use an alternative parsing method).
ffb4593c
NT
1503 */
1504
76e3520e 1505STATIC char *
e759cc13 1506S_force_version(pTHX_ char *s, int guessing)
89bfa8cd 1507{
97aff369 1508 dVAR;
5f66b61c 1509 OP *version = NULL;
44dcb63b 1510 char *d;
5db06880
NC
1511#ifdef PERL_MAD
1512 I32 startoff = s - SvPVX(PL_linestr);
1513#endif
89bfa8cd 1514
7918f24d
NC
1515 PERL_ARGS_ASSERT_FORCE_VERSION;
1516
29595ff2 1517 s = SKIPSPACE1(s);
89bfa8cd 1518
44dcb63b 1519 d = s;
dd629d5b 1520 if (*d == 'v')
44dcb63b 1521 d++;
44dcb63b 1522 if (isDIGIT(*d)) {
e759cc13
RGS
1523 while (isDIGIT(*d) || *d == '_' || *d == '.')
1524 d++;
5db06880
NC
1525#ifdef PERL_MAD
1526 if (PL_madskills) {
cd81e915 1527 start_force(PL_curforce);
5db06880
NC
1528 curmad('X', newSVpvn(s,d-s));
1529 }
1530#endif
9f3d182e 1531 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
dd629d5b 1532 SV *ver;
6154021b
RGS
1533 s = scan_num(s, &pl_yylval);
1534 version = pl_yylval.opval;
dd629d5b
GS
1535 ver = cSVOPx(version)->op_sv;
1536 if (SvPOK(ver) && !SvNIOK(ver)) {
862a34c6 1537 SvUPGRADE(ver, SVt_PVNV);
9d6ce603 1538 SvNV_set(ver, str_to_version(ver));
1571675a 1539 SvNOK_on(ver); /* hint that it is a version */
44dcb63b 1540 }
89bfa8cd 1541 }
5db06880
NC
1542 else if (guessing) {
1543#ifdef PERL_MAD
1544 if (PL_madskills) {
cd81e915
NC
1545 sv_free(PL_nextwhite); /* let next token collect whitespace */
1546 PL_nextwhite = 0;
5db06880
NC
1547 s = SvPVX(PL_linestr) + startoff;
1548 }
1549#endif
e759cc13 1550 return s;
5db06880 1551 }
89bfa8cd 1552 }
1553
5db06880
NC
1554#ifdef PERL_MAD
1555 if (PL_madskills && !version) {
cd81e915
NC
1556 sv_free(PL_nextwhite); /* let next token collect whitespace */
1557 PL_nextwhite = 0;
5db06880
NC
1558 s = SvPVX(PL_linestr) + startoff;
1559 }
1560#endif
89bfa8cd 1561 /* NOTE: The parser sees the package name and the VERSION swapped */
cd81e915 1562 start_force(PL_curforce);
9ded7720 1563 NEXTVAL_NEXTTOKE.opval = version;
4e553d73 1564 force_next(WORD);
89bfa8cd 1565
e759cc13 1566 return s;
89bfa8cd 1567}
1568
ffb4593c
NT
1569/*
1570 * S_tokeq
1571 * Tokenize a quoted string passed in as an SV. It finds the next
1572 * chunk, up to end of string or a backslash. It may make a new
1573 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1574 * turns \\ into \.
1575 */
1576
76e3520e 1577STATIC SV *
cea2e8a9 1578S_tokeq(pTHX_ SV *sv)
79072805 1579{
97aff369 1580 dVAR;
79072805
LW
1581 register char *s;
1582 register char *send;
1583 register char *d;
b3ac6de7
IZ
1584 STRLEN len = 0;
1585 SV *pv = sv;
79072805 1586
7918f24d
NC
1587 PERL_ARGS_ASSERT_TOKEQ;
1588
79072805 1589 if (!SvLEN(sv))
b3ac6de7 1590 goto finish;
79072805 1591
a0d0e21e 1592 s = SvPV_force(sv, len);
21a311ee 1593 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
b3ac6de7 1594 goto finish;
463ee0b2 1595 send = s + len;
79072805
LW
1596 while (s < send && *s != '\\')
1597 s++;
1598 if (s == send)
b3ac6de7 1599 goto finish;
79072805 1600 d = s;
be4731d2 1601 if ( PL_hints & HINT_NEW_STRING ) {
59cd0e26 1602 pv = newSVpvn_flags(SvPVX_const(pv), len, SVs_TEMP | SvUTF8(sv));
be4731d2 1603 }
79072805
LW
1604 while (s < send) {
1605 if (*s == '\\') {
a0d0e21e 1606 if (s + 1 < send && (s[1] == '\\'))
79072805
LW
1607 s++; /* all that, just for this */
1608 }
1609 *d++ = *s++;
1610 }
1611 *d = '\0';
95a20fc0 1612 SvCUR_set(sv, d - SvPVX_const(sv));
b3ac6de7 1613 finish:
3280af22 1614 if ( PL_hints & HINT_NEW_STRING )
eb0d8d16 1615 return new_constant(NULL, 0, "q", sv, pv, "q", 1);
79072805
LW
1616 return sv;
1617}
1618
ffb4593c
NT
1619/*
1620 * Now come three functions related to double-quote context,
1621 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1622 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1623 * interact with PL_lex_state, and create fake ( ... ) argument lists
1624 * to handle functions and concatenation.
1625 * They assume that whoever calls them will be setting up a fake
1626 * join call, because each subthing puts a ',' after it. This lets
1627 * "lower \luPpEr"
1628 * become
1629 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1630 *
1631 * (I'm not sure whether the spurious commas at the end of lcfirst's
1632 * arguments and join's arguments are created or not).
1633 */
1634
1635/*
1636 * S_sublex_start
6154021b 1637 * Assumes that pl_yylval.ival is the op we're creating (e.g. OP_LCFIRST).
ffb4593c
NT
1638 *
1639 * Pattern matching will set PL_lex_op to the pattern-matching op to
6154021b 1640 * make (we return THING if pl_yylval.ival is OP_NULL, PMFUNC otherwise).
ffb4593c
NT
1641 *
1642 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1643 *
1644 * Everything else becomes a FUNC.
1645 *
1646 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1647 * had an OP_CONST or OP_READLINE). This just sets us up for a
1648 * call to S_sublex_push().
1649 */
1650
76e3520e 1651STATIC I32
cea2e8a9 1652S_sublex_start(pTHX)
79072805 1653{
97aff369 1654 dVAR;
6154021b 1655 register const I32 op_type = pl_yylval.ival;
79072805
LW
1656
1657 if (op_type == OP_NULL) {
6154021b 1658 pl_yylval.opval = PL_lex_op;
5f66b61c 1659 PL_lex_op = NULL;
79072805
LW
1660 return THING;
1661 }
1662 if (op_type == OP_CONST || op_type == OP_READLINE) {
3280af22 1663 SV *sv = tokeq(PL_lex_stuff);
b3ac6de7
IZ
1664
1665 if (SvTYPE(sv) == SVt_PVIV) {
1666 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1667 STRLEN len;
96a5add6 1668 const char * const p = SvPV_const(sv, len);
740cce10 1669 SV * const nsv = newSVpvn_flags(p, len, SvUTF8(sv));
b3ac6de7
IZ
1670 SvREFCNT_dec(sv);
1671 sv = nsv;
4e553d73 1672 }
6154021b 1673 pl_yylval.opval = (OP*)newSVOP(op_type, 0, sv);
a0714e2c 1674 PL_lex_stuff = NULL;
6f33ba73
RGS
1675 /* Allow <FH> // "foo" */
1676 if (op_type == OP_READLINE)
1677 PL_expect = XTERMORDORDOR;
79072805
LW
1678 return THING;
1679 }
e3f73d4e
RGS
1680 else if (op_type == OP_BACKTICK && PL_lex_op) {
1681 /* readpipe() vas overriden */
1682 cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff);
6154021b 1683 pl_yylval.opval = PL_lex_op;
9b201d7d 1684 PL_lex_op = NULL;
e3f73d4e
RGS
1685 PL_lex_stuff = NULL;
1686 return THING;
1687 }
79072805 1688
3280af22 1689 PL_sublex_info.super_state = PL_lex_state;
eac04b2e 1690 PL_sublex_info.sub_inwhat = (U16)op_type;
3280af22
NIS
1691 PL_sublex_info.sub_op = PL_lex_op;
1692 PL_lex_state = LEX_INTERPPUSH;
55497cff 1693
3280af22
NIS
1694 PL_expect = XTERM;
1695 if (PL_lex_op) {
6154021b 1696 pl_yylval.opval = PL_lex_op;
5f66b61c 1697 PL_lex_op = NULL;
55497cff 1698 return PMFUNC;
1699 }
1700 else
1701 return FUNC;
1702}
1703
ffb4593c
NT
1704/*
1705 * S_sublex_push
1706 * Create a new scope to save the lexing state. The scope will be
1707 * ended in S_sublex_done. Returns a '(', starting the function arguments
1708 * to the uc, lc, etc. found before.
1709 * Sets PL_lex_state to LEX_INTERPCONCAT.
1710 */
1711
76e3520e 1712STATIC I32
cea2e8a9 1713S_sublex_push(pTHX)
55497cff 1714{
27da23d5 1715 dVAR;
f46d017c 1716 ENTER;
55497cff 1717
3280af22 1718 PL_lex_state = PL_sublex_info.super_state;
651b5b28 1719 SAVEBOOL(PL_lex_dojoin);
3280af22 1720 SAVEI32(PL_lex_brackets);
3280af22
NIS
1721 SAVEI32(PL_lex_casemods);
1722 SAVEI32(PL_lex_starts);
651b5b28 1723 SAVEI8(PL_lex_state);
7766f137 1724 SAVEVPTR(PL_lex_inpat);
98246f1e 1725 SAVEI16(PL_lex_inwhat);
57843af0 1726 SAVECOPLINE(PL_curcop);
3280af22 1727 SAVEPPTR(PL_bufptr);
8452ff4b 1728 SAVEPPTR(PL_bufend);
3280af22
NIS
1729 SAVEPPTR(PL_oldbufptr);
1730 SAVEPPTR(PL_oldoldbufptr);
207e3d1a
JH
1731 SAVEPPTR(PL_last_lop);
1732 SAVEPPTR(PL_last_uni);
3280af22
NIS
1733 SAVEPPTR(PL_linestart);
1734 SAVESPTR(PL_linestr);
8edd5f42
RGS
1735 SAVEGENERICPV(PL_lex_brackstack);
1736 SAVEGENERICPV(PL_lex_casestack);
3280af22
NIS
1737
1738 PL_linestr = PL_lex_stuff;
a0714e2c 1739 PL_lex_stuff = NULL;
3280af22 1740
9cbb5ea2
GS
1741 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1742 = SvPVX(PL_linestr);
3280af22 1743 PL_bufend += SvCUR(PL_linestr);
bd61b366 1744 PL_last_lop = PL_last_uni = NULL;
3280af22
NIS
1745 SAVEFREESV(PL_linestr);
1746
1747 PL_lex_dojoin = FALSE;
1748 PL_lex_brackets = 0;
a02a5408
JC
1749 Newx(PL_lex_brackstack, 120, char);
1750 Newx(PL_lex_casestack, 12, char);
3280af22
NIS
1751 PL_lex_casemods = 0;
1752 *PL_lex_casestack = '\0';
1753 PL_lex_starts = 0;
1754 PL_lex_state = LEX_INTERPCONCAT;
eb160463 1755 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
3280af22
NIS
1756
1757 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1758 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1759 PL_lex_inpat = PL_sublex_info.sub_op;
79072805 1760 else
5f66b61c 1761 PL_lex_inpat = NULL;
79072805 1762
55497cff 1763 return '(';
79072805
LW
1764}
1765
ffb4593c
NT
1766/*
1767 * S_sublex_done
1768 * Restores lexer state after a S_sublex_push.
1769 */
1770
76e3520e 1771STATIC I32
cea2e8a9 1772S_sublex_done(pTHX)
79072805 1773{
27da23d5 1774 dVAR;
3280af22 1775 if (!PL_lex_starts++) {
396482e1 1776 SV * const sv = newSVpvs("");
9aa983d2
JH
1777 if (SvUTF8(PL_linestr))
1778 SvUTF8_on(sv);
3280af22 1779 PL_expect = XOPERATOR;
6154021b 1780 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
79072805
LW
1781 return THING;
1782 }
1783
3280af22
NIS
1784 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1785 PL_lex_state = LEX_INTERPCASEMOD;
cea2e8a9 1786 return yylex();
79072805
LW
1787 }
1788
ffb4593c 1789 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
3280af22
NIS
1790 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1791 PL_linestr = PL_lex_repl;
1792 PL_lex_inpat = 0;
1793 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1794 PL_bufend += SvCUR(PL_linestr);
bd61b366 1795 PL_last_lop = PL_last_uni = NULL;
3280af22
NIS
1796 SAVEFREESV(PL_linestr);
1797 PL_lex_dojoin = FALSE;
1798 PL_lex_brackets = 0;
3280af22
NIS
1799 PL_lex_casemods = 0;
1800 *PL_lex_casestack = '\0';
1801 PL_lex_starts = 0;
25da4f38 1802 if (SvEVALED(PL_lex_repl)) {
3280af22
NIS
1803 PL_lex_state = LEX_INTERPNORMAL;
1804 PL_lex_starts++;
e9fa98b2
HS
1805 /* we don't clear PL_lex_repl here, so that we can check later
1806 whether this is an evalled subst; that means we rely on the
1807 logic to ensure sublex_done() is called again only via the
1808 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
79072805 1809 }
e9fa98b2 1810 else {
3280af22 1811 PL_lex_state = LEX_INTERPCONCAT;
a0714e2c 1812 PL_lex_repl = NULL;
e9fa98b2 1813 }
79072805 1814 return ',';
ffed7fef
LW
1815 }
1816 else {
5db06880
NC
1817#ifdef PERL_MAD
1818 if (PL_madskills) {
cd81e915
NC
1819 if (PL_thiswhite) {
1820 if (!PL_endwhite)
6b29d1f5 1821 PL_endwhite = newSVpvs("");
cd81e915
NC
1822 sv_catsv(PL_endwhite, PL_thiswhite);
1823 PL_thiswhite = 0;
1824 }
1825 if (PL_thistoken)
76f68e9b 1826 sv_setpvs(PL_thistoken,"");
5db06880 1827 else
cd81e915 1828 PL_realtokenstart = -1;
5db06880
NC
1829 }
1830#endif
f46d017c 1831 LEAVE;
3280af22
NIS
1832 PL_bufend = SvPVX(PL_linestr);
1833 PL_bufend += SvCUR(PL_linestr);
1834 PL_expect = XOPERATOR;
09bef843 1835 PL_sublex_info.sub_inwhat = 0;
79072805 1836 return ')';
ffed7fef
LW
1837 }
1838}
1839
02aa26ce
NT
1840/*
1841 scan_const
1842
1843 Extracts a pattern, double-quoted string, or transliteration. This
1844 is terrifying code.
1845
94def140 1846 It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
3280af22 1847 processing a pattern (PL_lex_inpat is true), a transliteration
94def140 1848 (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
02aa26ce 1849
94def140
TS
1850 Returns a pointer to the character scanned up to. If this is
1851 advanced from the start pointer supplied (i.e. if anything was
9b599b2a 1852 successfully parsed), will leave an OP for the substring scanned
6154021b 1853 in pl_yylval. Caller must intuit reason for not parsing further
9b599b2a
GS
1854 by looking at the next characters herself.
1855
02aa26ce
NT
1856 In patterns:
1857 backslashes:
1858 double-quoted style: \r and \n
1859 regexp special ones: \D \s
94def140
TS
1860 constants: \x31
1861 backrefs: \1
02aa26ce
NT
1862 case and quoting: \U \Q \E
1863 stops on @ and $, but not for $ as tail anchor
1864
1865 In transliterations:
1866 characters are VERY literal, except for - not at the start or end
94def140
TS
1867 of the string, which indicates a range. If the range is in bytes,
1868 scan_const expands the range to the full set of intermediate
1869 characters. If the range is in utf8, the hyphen is replaced with
1870 a certain range mark which will be handled by pmtrans() in op.c.
02aa26ce
NT
1871
1872 In double-quoted strings:
1873 backslashes:
1874 double-quoted style: \r and \n
94def140
TS
1875 constants: \x31
1876 deprecated backrefs: \1 (in substitution replacements)
02aa26ce
NT
1877 case and quoting: \U \Q \E
1878 stops on @ and $
1879
1880 scan_const does *not* construct ops to handle interpolated strings.
1881 It stops processing as soon as it finds an embedded $ or @ variable
1882 and leaves it to the caller to work out what's going on.
1883
94def140
TS
1884 embedded arrays (whether in pattern or not) could be:
1885 @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
1886
1887 $ in double-quoted strings must be the symbol of an embedded scalar.
02aa26ce
NT
1888
1889 $ in pattern could be $foo or could be tail anchor. Assumption:
1890 it's a tail anchor if $ is the last thing in the string, or if it's
94def140 1891 followed by one of "()| \r\n\t"
02aa26ce
NT
1892
1893 \1 (backreferences) are turned into $1
1894
1895 The structure of the code is
1896 while (there's a character to process) {
94def140
TS
1897 handle transliteration ranges
1898 skip regexp comments /(?#comment)/ and codes /(?{code})/
1899 skip #-initiated comments in //x patterns
1900 check for embedded arrays
02aa26ce
NT
1901 check for embedded scalars
1902 if (backslash) {
94def140
TS
1903 leave intact backslashes from leaveit (below)
1904 deprecate \1 in substitution replacements
02aa26ce
NT
1905 handle string-changing backslashes \l \U \Q \E, etc.
1906 switch (what was escaped) {
94def140
TS
1907 handle \- in a transliteration (becomes a literal -)
1908 handle \132 (octal characters)
1909 handle \x15 and \x{1234} (hex characters)
1910 handle \N{name} (named characters)
1911 handle \cV (control characters)
1912 handle printf-style backslashes (\f, \r, \n, etc)
02aa26ce 1913 } (end switch)
77a135fe 1914 continue
02aa26ce 1915 } (end if backslash)
77a135fe 1916 handle regular character
02aa26ce 1917 } (end while character to read)
4e553d73 1918
02aa26ce
NT
1919*/
1920
76e3520e 1921STATIC char *
cea2e8a9 1922S_scan_const(pTHX_ char *start)
79072805 1923{
97aff369 1924 dVAR;
3280af22 1925 register char *send = PL_bufend; /* end of the constant */
77a135fe
KW
1926 SV *sv = newSV(send - start); /* sv for the constant. See
1927 note below on sizing. */
02aa26ce
NT
1928 register char *s = start; /* start of the constant */
1929 register char *d = SvPVX(sv); /* destination for copies */
1930 bool dorange = FALSE; /* are we in a translit range? */
c2e66d9e 1931 bool didrange = FALSE; /* did we just finish a range? */
2b9d42f0 1932 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
77a135fe
KW
1933 I32 this_utf8 = UTF; /* Is the source string assumed
1934 to be UTF8? But, this can
1935 show as true when the source
1936 isn't utf8, as for example
1937 when it is entirely composed
1938 of hex constants */
1939
1940 /* Note on sizing: The scanned constant is placed into sv, which is
1941 * initialized by newSV() assuming one byte of output for every byte of
1942 * input. This routine expects newSV() to allocate an extra byte for a
1943 * trailing NUL, which this routine will append if it gets to the end of
1944 * the input. There may be more bytes of input than output (eg., \N{LATIN
1945 * CAPITAL LETTER A}), or more output than input if the constant ends up
1946 * recoded to utf8, but each time a construct is found that might increase
1947 * the needed size, SvGROW() is called. Its size parameter each time is
1948 * based on the best guess estimate at the time, namely the length used so
1949 * far, plus the length the current construct will occupy, plus room for
1950 * the trailing NUL, plus one byte for every input byte still unscanned */
1951
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 2174 if (s + 1 < send && !strchr("()| \r\n\t", s[1])) {
a2a5de95
NC
2175 if (s[1] == '\\') {
2176 Perl_ck_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
2177 "Possible unintended interpolation of $\\ in regex");
77772344 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 {
a2a5de95 2193 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
79072805
LW
2194 *--s = '$';
2195 break;
2196 }
02aa26ce
NT
2197
2198 /* string-change backslash escapes */
3280af22 2199 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
79072805
LW
2200 --s;
2201 break;
2202 }
cc74c5bd
TS
2203 /* skip any other backslash escapes in a pattern */
2204 else if (PL_lex_inpat) {
2205 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2206 goto default_action;
2207 }
02aa26ce
NT
2208
2209 /* if we get here, it's either a quoted -, or a digit */
79072805 2210 switch (*s) {
02aa26ce
NT
2211
2212 /* quoted - in transliterations */
79072805 2213 case '-':
3280af22 2214 if (PL_lex_inwhat == OP_TRANS) {
79072805
LW
2215 *d++ = *s++;
2216 continue;
2217 }
2218 /* FALL THROUGH */
2219 default:
11b8faa4 2220 {
a2a5de95
NC
2221 if ((isALPHA(*s) || isDIGIT(*s)))
2222 Perl_ck_warner(aTHX_ packWARN(WARN_MISC),
2223 "Unrecognized escape \\%c passed through",
2224 *s);
11b8faa4 2225 /* default action is to copy the quoted character */
f9a63242 2226 goto default_action;
11b8faa4 2227 }
02aa26ce 2228
77a135fe 2229 /* eg. \132 indicates the octal constant 0x132 */
79072805
LW
2230 case '0': case '1': case '2': case '3':
2231 case '4': case '5': case '6': case '7':
ba210ebe 2232 {
53305cf1
NC
2233 I32 flags = 0;
2234 STRLEN len = 3;
77a135fe 2235 uv = NATIVE_TO_UNI(grok_oct(s, &len, &flags, NULL));
ba210ebe
JH
2236 s += len;
2237 }
012bcf8d 2238 goto NUM_ESCAPE_INSERT;
02aa26ce 2239
77a135fe 2240 /* eg. \x24 indicates the hex constant 0x24 */
79072805 2241 case 'x':
a0ed51b3
LW
2242 ++s;
2243 if (*s == '{') {
9d4ba2ae 2244 char* const e = strchr(s, '}');
a4c04bdc
NC
2245 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2246 PERL_SCAN_DISALLOW_PREFIX;
53305cf1 2247 STRLEN len;
355860ce 2248
53305cf1 2249 ++s;
adaeee49 2250 if (!e) {
a0ed51b3 2251 yyerror("Missing right brace on \\x{}");
355860ce 2252 continue;
ba210ebe 2253 }
53305cf1 2254 len = e - s;
77a135fe 2255 uv = NATIVE_TO_UNI(grok_hex(s, &len, &flags, NULL));
ba210ebe 2256 s = e + 1;
a0ed51b3
LW
2257 }
2258 else {
ba210ebe 2259 {
53305cf1 2260 STRLEN len = 2;
a4c04bdc 2261 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
77a135fe 2262 uv = NATIVE_TO_UNI(grok_hex(s, &len, &flags, NULL));
ba210ebe
JH
2263 s += len;
2264 }
012bcf8d
GS
2265 }
2266
2267 NUM_ESCAPE_INSERT:
77a135fe
KW
2268 /* Insert oct, hex, or \N{U+...} escaped character. There will
2269 * always be enough room in sv since such escapes will be
2270 * longer than any UTF-8 sequence they can end up as, except if
2271 * they force us to recode the rest of the string into utf8 */
ba7cea30 2272
77a135fe
KW
2273 /* Here uv is the ordinal of the next character being added in
2274 * unicode (converted from native). (It has to be done before
2275 * here because \N is interpreted as unicode, and oct and hex
2276 * as native.) */
2277 if (!UNI_IS_INVARIANT(uv)) {
9aa983d2 2278 if (!has_utf8 && uv > 255) {
77a135fe
KW
2279 /* Might need to recode whatever we have accumulated so
2280 * far if it contains any chars variant in utf8 or
2281 * utf-ebcdic. */
2282
2283 SvCUR_set(sv, d - SvPVX_const(sv));
2284 SvPOK_on(sv);
2285 *d = '\0';
77a135fe 2286 /* See Note on sizing above. */
7bf79863
KW
2287 sv_utf8_upgrade_flags_grow(sv,
2288 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
2289 UNISKIP(uv) + (STRLEN)(send - s) + 1);
77a135fe
KW
2290 d = SvPVX(sv) + SvCUR(sv);
2291 has_utf8 = TRUE;
012bcf8d
GS
2292 }
2293
77a135fe
KW
2294 if (has_utf8) {
2295 d = (char*)uvuni_to_utf8((U8*)d, uv);
f9a63242
JH
2296 if (PL_lex_inwhat == OP_TRANS &&
2297 PL_sublex_info.sub_op) {
2298 PL_sublex_info.sub_op->op_private |=
2299 (PL_lex_repl ? OPpTRANS_FROM_UTF
2300 : OPpTRANS_TO_UTF);
f9a63242 2301 }
e294cc5d
JH
2302#ifdef EBCDIC
2303 if (uv > 255 && !dorange)
2304 native_range = FALSE;
2305#endif
012bcf8d 2306 }
a0ed51b3 2307 else {
012bcf8d 2308 *d++ = (char)uv;
a0ed51b3 2309 }
012bcf8d
GS
2310 }
2311 else {
c4d5f83a 2312 *d++ = (char) uv;
a0ed51b3 2313 }
79072805 2314 continue;
02aa26ce 2315
77a135fe
KW
2316 /* \N{LATIN SMALL LETTER A} is a named character, and so is
2317 * \N{U+0041} */
4a2d328f 2318 case 'N':
55eda711 2319 ++s;
423cee85
JH
2320 if (*s == '{') {
2321 char* e = strchr(s, '}');
155aba94 2322 SV *res;
423cee85 2323 STRLEN len;
cfd0369c 2324 const char *str;
4e553d73 2325
423cee85 2326 if (!e) {
5777a3f7 2327 yyerror("Missing right brace on \\N{}");
423cee85
JH
2328 e = s - 1;
2329 goto cont_scan;
2330 }
dbc0d4f2 2331 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
77a135fe
KW
2332 /* \N{U+...} The ... is a unicode value even on EBCDIC
2333 * machines */
dbc0d4f2
JH
2334 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2335 PERL_SCAN_DISALLOW_PREFIX;
2336 s += 3;
2337 len = e - s;
2338 uv = grok_hex(s, &len, &flags, NULL);
b57a0404
JH
2339 if ( e > s && len != (STRLEN)(e - s) ) {
2340 uv = 0xFFFD;
fc8cd66c 2341 }
dbc0d4f2
JH
2342 s = e + 1;
2343 goto NUM_ESCAPE_INSERT;
2344 }
55eda711 2345 res = newSVpvn(s + 1, e - s - 1);
bd61b366 2346 res = new_constant( NULL, 0, "charnames",
eb0d8d16 2347 res, NULL, s - 2, e - s + 3 );
f9a63242
JH
2348 if (has_utf8)
2349 sv_utf8_upgrade(res);
cfd0369c 2350 str = SvPV_const(res,len);
1c47067b
JH
2351#ifdef EBCDIC_NEVER_MIND
2352 /* charnames uses pack U and that has been
2353 * recently changed to do the below uni->native
2354 * mapping, so this would be redundant (and wrong,
2355 * the code point would be doubly converted).
2356 * But leave this in just in case the pack U change
2357 * gets revoked, but the semantics is still
2358 * desireable for charnames. --jhi */
cddc7ef4 2359 {
cfd0369c 2360 UV uv = utf8_to_uvchr((const U8*)str, 0);
cddc7ef4
JH
2361
2362 if (uv < 0x100) {
89ebb4a3 2363 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
cddc7ef4
JH
2364
2365 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2366 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
cfd0369c 2367 str = SvPV_const(res, len);
cddc7ef4
JH
2368 }
2369 }
2370#endif
77a135fe
KW
2371 /* If destination is not in utf8 but this new character is,
2372 * recode the dest to utf8 */
89491803 2373 if (!has_utf8 && SvUTF8(res)) {
77a135fe 2374 SvCUR_set(sv, d - SvPVX_const(sv));
f08d6ad9 2375 SvPOK_on(sv);
e4f3eed8 2376 *d = '\0';
77a135fe 2377 /* See Note on sizing above. */
7bf79863
KW
2378 sv_utf8_upgrade_flags_grow(sv,
2379 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
2380 len + (STRLEN)(send - s) + 1);
f08d6ad9 2381 d = SvPVX(sv) + SvCUR(sv);
89491803 2382 has_utf8 = TRUE;
77a135fe 2383 } else if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
423cee85 2384
77a135fe
KW
2385 /* See Note on sizing above. (NOTE: SvCUR() is not set
2386 * correctly here). */
2387 const STRLEN off = d - SvPVX_const(sv);
2388 d = SvGROW(sv, off + len + (STRLEN)(send - s) + 1) + off;
423cee85 2389 }
e294cc5d
JH
2390#ifdef EBCDIC
2391 if (!dorange)
2392 native_range = FALSE; /* \N{} is guessed to be Unicode */
2393#endif
423cee85
JH
2394 Copy(str, d, len, char);
2395 d += len;
2396 SvREFCNT_dec(res);
2397 cont_scan:
2398 s = e + 1;
2399 }
2400 else
5777a3f7 2401 yyerror("Missing braces on \\N{}");
423cee85
JH
2402 continue;
2403
02aa26ce 2404 /* \c is a control character */
79072805
LW
2405 case 'c':
2406 s++;
961ce445 2407 if (s < send) {
ba210ebe 2408 U8 c = *s++;
c7f1f016
NIS
2409#ifdef EBCDIC
2410 if (isLOWER(c))
2411 c = toUPPER(c);
2412#endif
db42d148 2413 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
ba210ebe 2414 }
961ce445
RGS
2415 else {
2416 yyerror("Missing control char name in \\c");
2417 }
79072805 2418 continue;
02aa26ce
NT
2419
2420 /* printf-style backslashes, formfeeds, newlines, etc */
79072805 2421 case 'b':
db42d148 2422 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
79072805
LW
2423 break;
2424 case 'n':
db42d148 2425 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
79072805
LW
2426 break;
2427 case 'r':
db42d148 2428 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
79072805
LW
2429 break;
2430 case 'f':
db42d148 2431 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
79072805
LW
2432 break;
2433 case 't':
db42d148 2434 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
79072805 2435 break;
34a3fe2a 2436 case 'e':
db42d148 2437 *d++ = ASCII_TO_NEED(has_utf8,'\033');
34a3fe2a
PP
2438 break;
2439 case 'a':
db42d148 2440 *d++ = ASCII_TO_NEED(has_utf8,'\007');
79072805 2441 break;
02aa26ce
NT
2442 } /* end switch */
2443
79072805
LW
2444 s++;
2445 continue;
02aa26ce 2446 } /* end if (backslash) */
4c3a8340
TS
2447#ifdef EBCDIC
2448 else
2449 literal_endpoint++;
2450#endif
02aa26ce 2451
f9a63242 2452 default_action:
77a135fe
KW
2453 /* If we started with encoded form, or already know we want it,
2454 then encode the next character */
2455 if (! NATIVE_IS_INVARIANT((U8)(*s)) && (this_utf8 || has_utf8)) {
2b9d42f0 2456 STRLEN len = 1;
77a135fe
KW
2457
2458
2459 /* One might think that it is wasted effort in the case of the
2460 * source being utf8 (this_utf8 == TRUE) to take the next character
2461 * in the source, convert it to an unsigned value, and then convert
2462 * it back again. But the source has not been validated here. The
2463 * routine that does the conversion checks for errors like
2464 * malformed utf8 */
2465
5f66b61c
AL
2466 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2467 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
77a135fe
KW
2468 if (!has_utf8) {
2469 SvCUR_set(sv, d - SvPVX_const(sv));
2470 SvPOK_on(sv);
2471 *d = '\0';
77a135fe 2472 /* See Note on sizing above. */
7bf79863
KW
2473 sv_utf8_upgrade_flags_grow(sv,
2474 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
2475 need + (STRLEN)(send - s) + 1);
77a135fe
KW
2476 d = SvPVX(sv) + SvCUR(sv);
2477 has_utf8 = TRUE;
2478 } else if (need > len) {
2479 /* encoded value larger than old, may need extra space (NOTE:
2480 * SvCUR() is not set correctly here). See Note on sizing
2481 * above. */
9d4ba2ae 2482 const STRLEN off = d - SvPVX_const(sv);
77a135fe 2483 d = SvGROW(sv, off + need + (STRLEN)(send - s) + 1) + off;
2b9d42f0 2484 }
77a135fe
KW
2485 s += len;
2486
5f66b61c 2487 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
e294cc5d
JH
2488#ifdef EBCDIC
2489 if (uv > 255 && !dorange)
2490 native_range = FALSE;
2491#endif
2b9d42f0
NIS
2492 }
2493 else {
2494 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2495 }
02aa26ce
NT
2496 } /* while loop to process each character */
2497
2498 /* terminate the string and set up the sv */
79072805 2499 *d = '\0';
95a20fc0 2500 SvCUR_set(sv, d - SvPVX_const(sv));
2b9d42f0 2501 if (SvCUR(sv) >= SvLEN(sv))
d0063567 2502 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2b9d42f0 2503
79072805 2504 SvPOK_on(sv);
9f4817db 2505 if (PL_encoding && !has_utf8) {
d0063567
DK
2506 sv_recode_to_utf8(sv, PL_encoding);
2507 if (SvUTF8(sv))
2508 has_utf8 = TRUE;
9f4817db 2509 }
2b9d42f0 2510 if (has_utf8) {
7e2040f0 2511 SvUTF8_on(sv);
2b9d42f0 2512 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
d0063567 2513 PL_sublex_info.sub_op->op_private |=
2b9d42f0
NIS
2514 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2515 }
2516 }
79072805 2517
02aa26ce 2518 /* shrink the sv if we allocated more than we used */
79072805 2519 if (SvCUR(sv) + 5 < SvLEN(sv)) {
1da4ca5f 2520 SvPV_shrink_to_cur(sv);
79072805 2521 }
02aa26ce 2522
6154021b 2523 /* return the substring (via pl_yylval) only if we parsed anything */
3280af22 2524 if (s > PL_bufptr) {
eb0d8d16
NC
2525 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) ) {
2526 const char *const key = PL_lex_inpat ? "qr" : "q";
2527 const STRLEN keylen = PL_lex_inpat ? 2 : 1;
2528 const char *type;
2529 STRLEN typelen;
2530
2531 if (PL_lex_inwhat == OP_TRANS) {
2532 type = "tr";
2533 typelen = 2;
2534 } else if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat) {
2535 type = "s";
2536 typelen = 1;
2537 } else {
2538 type = "qq";
2539 typelen = 2;
2540 }
2541
2542 sv = S_new_constant(aTHX_ start, s - start, key, keylen, sv, NULL,
2543 type, typelen);
2544 }
6154021b 2545 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
b3ac6de7 2546 } else
8990e307 2547 SvREFCNT_dec(sv);
79072805
LW
2548 return s;
2549}
2550
ffb4593c
NT
2551/* S_intuit_more
2552 * Returns TRUE if there's more to the expression (e.g., a subscript),
2553 * FALSE otherwise.
ffb4593c
NT
2554 *
2555 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2556 *
2557 * ->[ and ->{ return TRUE
2558 * { and [ outside a pattern are always subscripts, so return TRUE
2559 * if we're outside a pattern and it's not { or [, then return FALSE
2560 * if we're in a pattern and the first char is a {
2561 * {4,5} (any digits around the comma) returns FALSE
2562 * if we're in a pattern and the first char is a [
2563 * [] returns FALSE
2564 * [SOMETHING] has a funky algorithm to decide whether it's a
2565 * character class or not. It has to deal with things like
2566 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2567 * anything else returns TRUE
2568 */
2569
9cbb5ea2
GS
2570/* This is the one truly awful dwimmer necessary to conflate C and sed. */
2571
76e3520e 2572STATIC int
cea2e8a9 2573S_intuit_more(pTHX_ register char *s)
79072805 2574{
97aff369 2575 dVAR;
7918f24d
NC
2576
2577 PERL_ARGS_ASSERT_INTUIT_MORE;
2578
3280af22 2579 if (PL_lex_brackets)
79072805
LW
2580 return TRUE;
2581 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2582 return TRUE;
2583 if (*s != '{' && *s != '[')
2584 return FALSE;
3280af22 2585 if (!PL_lex_inpat)
79072805
LW
2586 return TRUE;
2587
2588 /* In a pattern, so maybe we have {n,m}. */
2589 if (*s == '{') {
2590 s++;
2591 if (!isDIGIT(*s))
2592 return TRUE;
2593 while (isDIGIT(*s))
2594 s++;
2595 if (*s == ',')
2596 s++;
2597 while (isDIGIT(*s))
2598 s++;
2599 if (*s == '}')
2600 return FALSE;
2601 return TRUE;
2602
2603 }
2604
2605 /* On the other hand, maybe we have a character class */
2606
2607 s++;
2608 if (*s == ']' || *s == '^')
2609 return FALSE;
2610 else {
ffb4593c 2611 /* this is terrifying, and it works */
79072805
LW
2612 int weight = 2; /* let's weigh the evidence */
2613 char seen[256];
f27ffc4a 2614 unsigned char un_char = 255, last_un_char;
9d4ba2ae 2615 const char * const send = strchr(s,']');
3280af22 2616 char tmpbuf[sizeof PL_tokenbuf * 4];
79072805
LW
2617
2618 if (!send) /* has to be an expression */
2619 return TRUE;
2620
2621 Zero(seen,256,char);
2622 if (*s == '$')
2623 weight -= 3;
2624 else if (isDIGIT(*s)) {
2625 if (s[1] != ']') {
2626 if (isDIGIT(s[1]) && s[2] == ']')
2627 weight -= 10;
2628 }
2629 else
2630 weight -= 100;
2631 }
2632 for (; s < send; s++) {
2633 last_un_char = un_char;
2634 un_char = (unsigned char)*s;
2635 switch (*s) {
2636 case '@':
2637 case '&':
2638 case '$':
2639 weight -= seen[un_char] * 10;
7e2040f0 2640 if (isALNUM_lazy_if(s+1,UTF)) {
90e5519e 2641 int len;
8903cb82 2642 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
90e5519e
NC
2643 len = (int)strlen(tmpbuf);
2644 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
79072805
LW
2645 weight -= 100;
2646 else
2647 weight -= 10;
2648 }
2649 else if (*s == '$' && s[1] &&
93a17b20
LW
2650 strchr("[#!%*<>()-=",s[1])) {
2651 if (/*{*/ strchr("])} =",s[2]))
79072805
LW
2652 weight -= 10;
2653 else
2654 weight -= 1;
2655 }
2656 break;
2657 case '\\':
2658 un_char = 254;
2659 if (s[1]) {
93a17b20 2660 if (strchr("wds]",s[1]))
79072805 2661 weight += 100;
10edeb5d 2662 else if (seen[(U8)'\''] || seen[(U8)'"'])
79072805 2663 weight += 1;
93a17b20 2664 else if (strchr("rnftbxcav",s[1]))
79072805
LW
2665 weight += 40;
2666 else if (isDIGIT(s[1])) {
2667 weight += 40;
2668 while (s[1] && isDIGIT(s[1]))
2669 s++;
2670 }
2671 }
2672 else
2673 weight += 100;
2674 break;
2675 case '-':
2676 if (s[1] == '\\')
2677 weight += 50;
93a17b20 2678 if (strchr("aA01! ",last_un_char))
79072805 2679 weight += 30;
93a17b20 2680 if (strchr("zZ79~",s[1]))
79072805 2681 weight += 30;
f27ffc4a
GS
2682 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2683 weight -= 5; /* cope with negative subscript */
79072805
LW
2684 break;
2685 default:
3792a11b
NC
2686 if (!isALNUM(last_un_char)
2687 && !(last_un_char == '$' || last_un_char == '@'
2688 || last_un_char == '&')
2689 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
79072805
LW
2690 char *d = tmpbuf;
2691 while (isALPHA(*s))
2692 *d++ = *s++;
2693 *d = '\0';
5458a98a 2694 if (keyword(tmpbuf, d - tmpbuf, 0))
79072805
LW
2695 weight -= 150;
2696 }
2697 if (un_char == last_un_char + 1)
2698 weight += 5;
2699 weight -= seen[un_char];
2700 break;
2701 }
2702 seen[un_char]++;
2703 }
2704 if (weight >= 0) /* probably a character class */
2705 return FALSE;
2706 }
2707
2708 return TRUE;
2709}
ffed7fef 2710
ffb4593c
NT
2711/*
2712 * S_intuit_method
2713 *
2714 * Does all the checking to disambiguate
2715 * foo bar
2716 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2717 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2718 *
2719 * First argument is the stuff after the first token, e.g. "bar".
2720 *
2721 * Not a method if bar is a filehandle.
2722 * Not a method if foo is a subroutine prototyped to take a filehandle.
2723 * Not a method if it's really "Foo $bar"
2724 * Method if it's "foo $bar"
2725 * Not a method if it's really "print foo $bar"
2726 * Method if it's really "foo package::" (interpreted as package->foo)
8f8cf39c 2727 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
3cb0bbe5 2728 * Not a method if bar is a filehandle or package, but is quoted with
ffb4593c
NT
2729 * =>
2730 */
2731
76e3520e 2732STATIC int
62d55b22 2733S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
a0d0e21e 2734{
97aff369 2735 dVAR;
a0d0e21e 2736 char *s = start + (*start == '$');
3280af22 2737 char tmpbuf[sizeof PL_tokenbuf];
a0d0e21e
LW
2738 STRLEN len;
2739 GV* indirgv;
5db06880
NC
2740#ifdef PERL_MAD
2741 int soff;
2742#endif
a0d0e21e 2743
7918f24d
NC
2744 PERL_ARGS_ASSERT_INTUIT_METHOD;
2745
a0d0e21e 2746 if (gv) {
62d55b22 2747 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
a0d0e21e 2748 return 0;
62d55b22
NC
2749 if (cv) {
2750 if (SvPOK(cv)) {
2751 const char *proto = SvPVX_const(cv);
2752 if (proto) {
2753 if (*proto == ';')
2754 proto++;
2755 if (*proto == '*')
2756 return 0;
2757 }
b6c543e3
IZ
2758 }
2759 } else
c35e046a 2760 gv = NULL;
a0d0e21e 2761 }
8903cb82 2762 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
ffb4593c
NT
2763 /* start is the beginning of the possible filehandle/object,
2764 * and s is the end of it
2765 * tmpbuf is a copy of it
2766 */
2767
a0d0e21e 2768 if (*start == '$') {
3ef1310e
RGS
2769 if (gv || PL_last_lop_op == OP_PRINT || PL_last_lop_op == OP_SAY ||
2770 isUPPER(*PL_tokenbuf))
a0d0e21e 2771 return 0;
5db06880
NC
2772#ifdef PERL_MAD
2773 len = start - SvPVX(PL_linestr);
2774#endif
29595ff2 2775 s = PEEKSPACE(s);
f0092767 2776#ifdef PERL_MAD
5db06880
NC
2777 start = SvPVX(PL_linestr) + len;
2778#endif
3280af22
NIS
2779 PL_bufptr = start;
2780 PL_expect = XREF;
a0d0e21e
LW
2781 return *s == '(' ? FUNCMETH : METHOD;
2782 }
5458a98a 2783 if (!keyword(tmpbuf, len, 0)) {
c3e0f903
GS
2784 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2785 len -= 2;
2786 tmpbuf[len] = '\0';
5db06880
NC
2787#ifdef PERL_MAD
2788 soff = s - SvPVX(PL_linestr);
2789#endif
c3e0f903
GS
2790 goto bare_package;
2791 }
90e5519e 2792 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
8ebc5c01 2793 if (indirgv && GvCVu(indirgv))
a0d0e21e
LW
2794 return 0;
2795 /* filehandle or package name makes it a method */
da51bb9b 2796 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, 0)) {
5db06880
NC
2797#ifdef PERL_MAD
2798 soff = s - SvPVX(PL_linestr);
2799#endif
29595ff2 2800 s = PEEKSPACE(s);
3280af22 2801 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
55497cff 2802 return 0; /* no assumptions -- "=>" quotes bearword */
c3e0f903 2803 bare_package:
cd81e915 2804 start_force(PL_curforce);
9ded7720 2805 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
64142370 2806 S_newSV_maybe_utf8(aTHX_ tmpbuf, len));
9ded7720 2807 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
5db06880
NC
2808 if (PL_madskills)
2809 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
3280af22 2810 PL_expect = XTERM;
a0d0e21e 2811 force_next(WORD);
3280af22 2812 PL_bufptr = s;
5db06880
NC
2813#ifdef PERL_MAD
2814 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2815#endif
a0d0e21e
LW
2816 return *s == '(' ? FUNCMETH : METHOD;
2817 }
2818 }
2819 return 0;
2820}
2821
16d20bd9 2822/* Encoded script support. filter_add() effectively inserts a
4e553d73 2823 * 'pre-processing' function into the current source input stream.
16d20bd9
AD
2824 * Note that the filter function only applies to the current source file
2825 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2826 *
2827 * The datasv parameter (which may be NULL) can be used to pass
2828 * private data to this instance of the filter. The filter function
2829 * can recover the SV using the FILTER_DATA macro and use it to
2830 * store private buffers and state information.
2831 *
2832 * The supplied datasv parameter is upgraded to a PVIO type
4755096e 2833 * and the IoDIRP/IoANY field is used to store the function pointer,
e0c19803 2834 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
16d20bd9
AD
2835 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2836 * private use must be set using malloc'd pointers.
2837 */
16d20bd9
AD
2838
2839SV *
864dbfa3 2840Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
16d20bd9 2841{
97aff369 2842 dVAR;
f4c556ac 2843 if (!funcp)
a0714e2c 2844 return NULL;
f4c556ac 2845
5486870f
DM
2846 if (!PL_parser)
2847 return NULL;
2848
3280af22
NIS
2849 if (!PL_rsfp_filters)
2850 PL_rsfp_filters = newAV();
16d20bd9 2851 if (!datasv)
561b68a9 2852 datasv = newSV(0);
862a34c6 2853 SvUPGRADE(datasv, SVt_PVIO);
8141890a 2854 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
e0c19803 2855 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
f4c556ac 2856 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
55662e27
JH
2857 FPTR2DPTR(void *, IoANY(datasv)),
2858 SvPV_nolen(datasv)));
3280af22
NIS
2859 av_unshift(PL_rsfp_filters, 1);
2860 av_store(PL_rsfp_filters, 0, datasv) ;
16d20bd9
AD
2861 return(datasv);
2862}
4e553d73 2863
16d20bd9
AD
2864
2865/* Delete most recently added instance of this filter function. */
a0d0e21e 2866void
864dbfa3 2867Perl_filter_del(pTHX_ filter_t funcp)
16d20bd9 2868{
97aff369 2869 dVAR;
e0c19803 2870 SV *datasv;
24801a4b 2871
7918f24d
NC
2872 PERL_ARGS_ASSERT_FILTER_DEL;
2873
33073adb 2874#ifdef DEBUGGING
55662e27
JH
2875 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2876 FPTR2DPTR(void*, funcp)));
33073adb 2877#endif
5486870f 2878 if (!PL_parser || !PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
16d20bd9
AD
2879 return;
2880 /* if filter is on top of stack (usual case) just pop it off */
e0c19803 2881 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
8141890a 2882 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
e0c19803 2883 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
4755096e 2884 IoANY(datasv) = (void *)NULL;
3280af22 2885 sv_free(av_pop(PL_rsfp_filters));
e50aee73 2886
16d20bd9
AD
2887 return;
2888 }
2889 /* we need to search for the correct entry and clear it */
cea2e8a9 2890 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
16d20bd9
AD
2891}
2892
2893
1de9afcd
RGS
2894/* Invoke the idxth filter function for the current rsfp. */
2895/* maxlen 0 = read one text line */
16d20bd9 2896I32
864dbfa3 2897Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
a0d0e21e 2898{
97aff369 2899 dVAR;
16d20bd9
AD
2900 filter_t funcp;
2901 SV *datasv = NULL;
f482118e
NC
2902 /* This API is bad. It should have been using unsigned int for maxlen.
2903 Not sure if we want to change the API, but if not we should sanity
2904 check the value here. */
39cd7a59
NC
2905 const unsigned int correct_length
2906 = maxlen < 0 ?
2907#ifdef PERL_MICRO
2908 0x7FFFFFFF
2909#else
2910 INT_MAX
2911#endif
2912 : maxlen;
e50aee73 2913
7918f24d
NC
2914 PERL_ARGS_ASSERT_FILTER_READ;
2915
5486870f 2916 if (!PL_parser || !PL_rsfp_filters)
16d20bd9 2917 return -1;
1de9afcd 2918 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
16d20bd9
AD
2919 /* Provide a default input filter to make life easy. */
2920 /* Note that we append to the line. This is handy. */
f4c556ac
GS
2921 DEBUG_P(PerlIO_printf(Perl_debug_log,
2922 "filter_read %d: from rsfp\n", idx));
f482118e 2923 if (correct_length) {
16d20bd9
AD
2924 /* Want a block */
2925 int len ;
f54cb97a 2926 const int old_len = SvCUR(buf_sv);
16d20bd9
AD
2927
2928 /* ensure buf_sv is large enough */
f482118e
NC
2929 SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2930 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2931 correct_length)) <= 0) {
3280af22 2932 if (PerlIO_error(PL_rsfp))
37120919
AD
2933 return -1; /* error */
2934 else
2935 return 0 ; /* end of file */
2936 }
16d20bd9
AD
2937 SvCUR_set(buf_sv, old_len + len) ;
2938 } else {
2939 /* Want a line */
3280af22
NIS
2940 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2941 if (PerlIO_error(PL_rsfp))
37120919
AD
2942 return -1; /* error */
2943 else
2944 return 0 ; /* end of file */
2945 }
16d20bd9
AD
2946 }
2947 return SvCUR(buf_sv);
2948 }
2949 /* Skip this filter slot if filter has been deleted */
1de9afcd 2950 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
f4c556ac
GS
2951 DEBUG_P(PerlIO_printf(Perl_debug_log,
2952 "filter_read %d: skipped (filter deleted)\n",
2953 idx));
f482118e 2954 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
16d20bd9
AD
2955 }
2956 /* Get function pointer hidden within datasv */
8141890a 2957 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
f4c556ac
GS
2958 DEBUG_P(PerlIO_printf(Perl_debug_log,
2959 "filter_read %d: via function %p (%s)\n",
ca0270c4 2960 idx, (void*)datasv, SvPV_nolen_const(datasv)));
16d20bd9
AD
2961 /* Call function. The function is expected to */
2962 /* call "FILTER_READ(idx+1, buf_sv)" first. */
37120919 2963 /* Return: <0:error, =0:eof, >0:not eof */
f482118e 2964 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
16d20bd9
AD
2965}
2966
76e3520e 2967STATIC char *
cea2e8a9 2968S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
16d20bd9 2969{
97aff369 2970 dVAR;
7918f24d
NC
2971
2972 PERL_ARGS_ASSERT_FILTER_GETS;
2973
c39cd008 2974#ifdef PERL_CR_FILTER
3280af22 2975 if (!PL_rsfp_filters) {
c39cd008 2976 filter_add(S_cr_textfilter,NULL);
a868473f
NIS
2977 }
2978#endif
3280af22 2979 if (PL_rsfp_filters) {
55497cff 2980 if (!append)
2981 SvCUR_set(sv, 0); /* start with empty line */
16d20bd9
AD
2982 if (FILTER_READ(0, sv, 0) > 0)
2983 return ( SvPVX(sv) ) ;
2984 else
bd61b366 2985 return NULL ;
16d20bd9 2986 }
9d116dd7 2987 else
fd049845 2988 return (sv_gets(sv, fp, append));
a0d0e21e
LW
2989}
2990
01ec43d0 2991STATIC HV *
9bde8eb0 2992S_find_in_my_stash(pTHX_ const char *pkgname, STRLEN len)
def3634b 2993{
97aff369 2994 dVAR;
def3634b
GS
2995 GV *gv;
2996
7918f24d
NC
2997 PERL_ARGS_ASSERT_FIND_IN_MY_STASH;
2998
01ec43d0 2999 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
def3634b
GS
3000 return PL_curstash;
3001
3002 if (len > 2 &&
3003 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
90e5519e 3004 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
01ec43d0
GS
3005 {
3006 return GvHV(gv); /* Foo:: */
def3634b
GS
3007 }
3008
3009 /* use constant CLASS => 'MyClass' */
c35e046a
AL
3010 gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
3011 if (gv && GvCV(gv)) {
3012 SV * const sv = cv_const_sv(GvCV(gv));
3013 if (sv)
9bde8eb0 3014 pkgname = SvPV_const(sv, len);
def3634b
GS
3015 }
3016
9bde8eb0 3017 return gv_stashpvn(pkgname, len, 0);
def3634b 3018}
a0d0e21e 3019
e3f73d4e
RGS
3020/*
3021 * S_readpipe_override
3022 * Check whether readpipe() is overriden, and generates the appropriate
3023 * optree, provided sublex_start() is called afterwards.
3024 */
3025STATIC void
1d51329b 3026S_readpipe_override(pTHX)
e3f73d4e
RGS
3027{
3028 GV **gvp;
3029 GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
6154021b 3030 pl_yylval.ival = OP_BACKTICK;
e3f73d4e
RGS
3031 if ((gv_readpipe
3032 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
3033 ||
3034 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
d5e716f5 3035 && (gv_readpipe = *gvp) && isGV_with_GP(gv_readpipe)
e3f73d4e
RGS
3036 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
3037 {
3038 PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
3039 append_elem(OP_LIST,
3040 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
3041 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
3042 }
e3f73d4e
RGS
3043}
3044
5db06880
NC
3045#ifdef PERL_MAD
3046 /*
3047 * Perl_madlex
3048 * The intent of this yylex wrapper is to minimize the changes to the
3049 * tokener when we aren't interested in collecting madprops. It remains
3050 * to be seen how successful this strategy will be...
3051 */
3052
3053int
3054Perl_madlex(pTHX)
3055{
3056 int optype;
3057 char *s = PL_bufptr;
3058
cd81e915
NC
3059 /* make sure PL_thiswhite is initialized */
3060 PL_thiswhite = 0;
3061 PL_thismad = 0;
5db06880 3062
cd81e915 3063 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
5db06880
NC
3064 if (PL_pending_ident)
3065 return S_pending_ident(aTHX);
3066
3067 /* previous token ate up our whitespace? */
cd81e915
NC
3068 if (!PL_lasttoke && PL_nextwhite) {
3069 PL_thiswhite = PL_nextwhite;
3070 PL_nextwhite = 0;
5db06880
NC
3071 }
3072
3073 /* isolate the token, and figure out where it is without whitespace */
cd81e915
NC
3074 PL_realtokenstart = -1;
3075 PL_thistoken = 0;
5db06880
NC
3076 optype = yylex();
3077 s = PL_bufptr;
cd81e915 3078 assert(PL_curforce < 0);
5db06880 3079
cd81e915
NC
3080 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
3081 if (!PL_thistoken) {
3082 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
6b29d1f5 3083 PL_thistoken = newSVpvs("");
5db06880 3084 else {
c35e046a 3085 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
cd81e915 3086 PL_thistoken = newSVpvn(tstart, s - tstart);
5db06880
NC
3087 }
3088 }
cd81e915
NC
3089 if (PL_thismad) /* install head */
3090 CURMAD('X', PL_thistoken);
5db06880
NC
3091 }
3092
3093 /* last whitespace of a sublex? */
cd81e915
NC
3094 if (optype == ')' && PL_endwhite) {
3095 CURMAD('X', PL_endwhite);
5db06880
NC
3096 }
3097
cd81e915 3098 if (!PL_thismad) {
5db06880
NC
3099
3100 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
cd81e915
NC
3101 if (!PL_thiswhite && !PL_endwhite && !optype) {
3102 sv_free(PL_thistoken);
3103 PL_thistoken = 0;
5db06880
NC
3104 return 0;
3105 }
3106
3107 /* put off final whitespace till peg */
3108 if (optype == ';' && !PL_rsfp) {
cd81e915
NC
3109 PL_nextwhite = PL_thiswhite;
3110 PL_thiswhite = 0;
5db06880 3111 }
cd81e915
NC
3112 else if (PL_thisopen) {
3113 CURMAD('q', PL_thisopen);
3114 if (PL_thistoken)
3115 sv_free(PL_thistoken);
3116 PL_thistoken = 0;
5db06880
NC
3117 }
3118 else {
3119 /* Store actual token text as madprop X */
cd81e915 3120 CURMAD('X', PL_thistoken);
5db06880
NC
3121 }
3122
cd81e915 3123 if (PL_thiswhite) {
5db06880 3124 /* add preceding whitespace as madprop _ */
cd81e915 3125 CURMAD('_', PL_thiswhite);
5db06880
NC
3126 }
3127
cd81e915 3128 if (PL_thisstuff) {
5db06880 3129 /* add quoted material as madprop = */
cd81e915 3130 CURMAD('=', PL_thisstuff);
5db06880
NC
3131 }
3132
cd81e915 3133 if (PL_thisclose) {
5db06880 3134 /* add terminating quote as madprop Q */
cd81e915 3135 CURMAD('Q', PL_thisclose);
5db06880
NC
3136 }
3137 }
3138
3139 /* special processing based on optype */
3140
3141 switch (optype) {
3142
3143 /* opval doesn't need a TOKEN since it can already store mp */
3144 case WORD:
3145 case METHOD:
3146 case FUNCMETH:
3147 case THING:
3148 case PMFUNC:
3149 case PRIVATEREF:
3150 case FUNC0SUB:
3151 case UNIOPSUB:
3152 case LSTOPSUB:
6154021b
RGS
3153 if (pl_yylval.opval)
3154 append_madprops(PL_thismad, pl_yylval.opval, 0);
cd81e915 3155 PL_thismad = 0;
5db06880
NC
3156 return optype;
3157
3158 /* fake EOF */
3159 case 0:
3160 optype = PEG;
cd81e915
NC
3161 if (PL_endwhite) {
3162 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
3163 PL_endwhite = 0;
5db06880
NC
3164 }
3165 break;
3166
3167 case ']':
3168 case '}':
cd81e915 3169 if (PL_faketokens)
5db06880
NC
3170 break;
3171 /* remember any fake bracket that lexer is about to discard */
3172 if (PL_lex_brackets == 1 &&
3173 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
3174 {
3175 s = PL_bufptr;
3176 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3177 s++;
3178 if (*s == '}') {
cd81e915
NC
3179 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
3180 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3181 PL_thiswhite = 0;
5db06880
NC
3182 PL_bufptr = s - 1;
3183 break; /* don't bother looking for trailing comment */
3184 }
3185 else
3186 s = PL_bufptr;
3187 }
3188 if (optype == ']')
3189 break;
3190 /* FALLTHROUGH */
3191
3192 /* attach a trailing comment to its statement instead of next token */
3193 case ';':
cd81e915 3194 if (PL_faketokens)
5db06880
NC
3195 break;
3196 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
3197 s = PL_bufptr;
3198 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3199 s++;
3200 if (*s == '\n' || *s == '#') {
3201 while (s < PL_bufend && *s != '\n')
3202 s++;
3203 if (s < PL_bufend)
3204 s++;
cd81e915
NC
3205 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
3206 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3207 PL_thiswhite = 0;
5db06880
NC
3208 PL_bufptr = s;
3209 }
3210 }
3211 break;
3212
3213 /* pval */
3214 case LABEL:
3215 break;
3216
3217 /* ival */
3218 default:
3219 break;
3220
3221 }
3222
3223 /* Create new token struct. Note: opvals return early above. */
6154021b 3224 pl_yylval.tkval = newTOKEN(optype, pl_yylval, PL_thismad);
cd81e915 3225 PL_thismad = 0;
5db06880
NC
3226 return optype;
3227}
3228#endif
3229
468aa647 3230STATIC char *
cc6ed77d 3231S_tokenize_use(pTHX_ int is_use, char *s) {
97aff369 3232 dVAR;
7918f24d
NC
3233
3234 PERL_ARGS_ASSERT_TOKENIZE_USE;
3235
468aa647
RGS
3236 if (PL_expect != XSTATE)
3237 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
3238 is_use ? "use" : "no"));
29595ff2 3239 s = SKIPSPACE1(s);
468aa647
RGS
3240 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
3241 s = force_version(s, TRUE);
29595ff2 3242 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
cd81e915 3243 start_force(PL_curforce);
9ded7720 3244 NEXTVAL_NEXTTOKE.opval = NULL;
468aa647
RGS
3245 force_next(WORD);
3246 }
3247 else if (*s == 'v') {
3248 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3249 s = force_version(s, FALSE);
3250 }
3251 }
3252 else {
3253 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3254 s = force_version(s, FALSE);
3255 }
6154021b 3256 pl_yylval.ival = is_use;
468aa647
RGS
3257 return s;
3258}
748a9306 3259#ifdef DEBUGGING
27da23d5 3260 static const char* const exp_name[] =
09bef843 3261 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
27308ded 3262 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
09bef843 3263 };
748a9306 3264#endif
463ee0b2 3265
02aa26ce
NT
3266/*
3267 yylex
3268
3269 Works out what to call the token just pulled out of the input
3270 stream. The yacc parser takes care of taking the ops we return and
3271 stitching them into a tree.
3272
3273 Returns:
3274 PRIVATEREF
3275
3276 Structure:
3277 if read an identifier
3278 if we're in a my declaration
3279 croak if they tried to say my($foo::bar)
3280 build the ops for a my() declaration
3281 if it's an access to a my() variable
3282 are we in a sort block?
3283 croak if my($a); $a <=> $b
3284 build ops for access to a my() variable
3285 if in a dq string, and they've said @foo and we can't find @foo
3286 croak
3287 build ops for a bareword
3288 if we already built the token before, use it.
3289*/
3290
20141f0e 3291
dba4d153
JH
3292#ifdef __SC__
3293#pragma segment Perl_yylex
3294#endif
dba4d153 3295int
dba4d153 3296Perl_yylex(pTHX)
20141f0e 3297{
97aff369 3298 dVAR;
3afc138a 3299 register char *s = PL_bufptr;
378cc40b 3300 register char *d;
463ee0b2 3301 STRLEN len;
aa7440fb 3302 bool bof = FALSE;
a687059c 3303
10edeb5d
JH
3304 /* orig_keyword, gvp, and gv are initialized here because
3305 * jump to the label just_a_word_zero can bypass their
3306 * initialization later. */
3307 I32 orig_keyword = 0;
3308 GV *gv = NULL;
3309 GV **gvp = NULL;
3310
bbf60fe6 3311 DEBUG_T( {
396482e1 3312 SV* tmp = newSVpvs("");
b6007c36
DM
3313 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3314 (IV)CopLINE(PL_curcop),
3315 lex_state_names[PL_lex_state],
3316 exp_name[PL_expect],
3317 pv_display(tmp, s, strlen(s), 0, 60));
3318 SvREFCNT_dec(tmp);
bbf60fe6 3319 } );
02aa26ce 3320 /* check if there's an identifier for us to look at */
ba979b31 3321 if (PL_pending_ident)
bbf60fe6 3322 return REPORT(S_pending_ident(aTHX));
bbce6d69 3323
02aa26ce
NT
3324 /* no identifier pending identification */
3325
3280af22 3326 switch (PL_lex_state) {
79072805
LW
3327#ifdef COMMENTARY
3328 case LEX_NORMAL: /* Some compilers will produce faster */
3329 case LEX_INTERPNORMAL: /* code if we comment these out. */
3330 break;
3331#endif
3332
09bef843 3333 /* when we've already built the next token, just pull it out of the queue */
79072805 3334 case LEX_KNOWNEXT:
5db06880
NC
3335#ifdef PERL_MAD
3336 PL_lasttoke--;
6154021b 3337 pl_yylval = PL_nexttoke[PL_lasttoke].next_val;
5db06880 3338 if (PL_madskills) {
cd81e915 3339 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
5db06880 3340 PL_nexttoke[PL_lasttoke].next_mad = 0;
cd81e915 3341 if (PL_thismad && PL_thismad->mad_key == '_') {
daba3364 3342 PL_thiswhite = MUTABLE_SV(PL_thismad->mad_val);
cd81e915
NC
3343 PL_thismad->mad_val = 0;
3344 mad_free(PL_thismad);
3345 PL_thismad = 0;
5db06880
NC
3346 }
3347 }
3348 if (!PL_lasttoke) {
3349 PL_lex_state = PL_lex_defer;
3350 PL_expect = PL_lex_expect;
3351 PL_lex_defer = LEX_NORMAL;
3352 if (!PL_nexttoke[PL_lasttoke].next_type)
3353 return yylex();
3354 }
3355#else
3280af22 3356 PL_nexttoke--;
6154021b 3357 pl_yylval = PL_nextval[PL_nexttoke];
3280af22
NIS
3358 if (!PL_nexttoke) {
3359 PL_lex_state = PL_lex_defer;
3360 PL_expect = PL_lex_expect;
3361 PL_lex_defer = LEX_NORMAL;
463ee0b2 3362 }
5db06880
NC
3363#endif
3364#ifdef PERL_MAD
3365 /* FIXME - can these be merged? */
3366 return(PL_nexttoke[PL_lasttoke].next_type);
3367#else
bbf60fe6 3368 return REPORT(PL_nexttype[PL_nexttoke]);
5db06880 3369#endif
79072805 3370
02aa26ce 3371 /* interpolated case modifiers like \L \U, including \Q and \E.
3280af22 3372 when we get here, PL_bufptr is at the \
02aa26ce 3373 */
79072805
LW
3374 case LEX_INTERPCASEMOD:
3375#ifdef DEBUGGING
3280af22 3376 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
cea2e8a9 3377 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
79072805 3378#endif
02aa26ce 3379 /* handle \E or end of string */
3280af22 3380 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
02aa26ce 3381 /* if at a \E */
3280af22 3382 if (PL_lex_casemods) {
f54cb97a 3383 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3280af22 3384 PL_lex_casestack[PL_lex_casemods] = '\0';
02aa26ce 3385
3792a11b
NC
3386 if (PL_bufptr != PL_bufend
3387 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3280af22
NIS
3388 PL_bufptr += 2;
3389 PL_lex_state = LEX_INTERPCONCAT;
5db06880
NC
3390#ifdef PERL_MAD
3391 if (PL_madskills)
6b29d1f5 3392 PL_thistoken = newSVpvs("\\E");
5db06880 3393#endif
a0d0e21e 3394 }
bbf60fe6 3395 return REPORT(')');
79072805 3396 }
5db06880
NC
3397#ifdef PERL_MAD
3398 while (PL_bufptr != PL_bufend &&
3399 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
cd81e915 3400 if (!PL_thiswhite)
6b29d1f5 3401 PL_thiswhite = newSVpvs("");
cd81e915 3402 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
5db06880
NC
3403 PL_bufptr += 2;
3404 }
3405#else
3280af22
NIS
3406 if (PL_bufptr != PL_bufend)
3407 PL_bufptr += 2;
5db06880 3408#endif
3280af22 3409 PL_lex_state = LEX_INTERPCONCAT;
cea2e8a9 3410 return yylex();
79072805
LW
3411 }
3412 else {
607df283 3413 DEBUG_T({ PerlIO_printf(Perl_debug_log,
b6007c36 3414 "### Saw case modifier\n"); });
3280af22 3415 s = PL_bufptr + 1;
6e909404 3416 if (s[1] == '\\' && s[2] == 'E') {
5db06880 3417#ifdef PERL_MAD
cd81e915 3418 if (!PL_thiswhite)
6b29d1f5 3419 PL_thiswhite = newSVpvs("");
cd81e915 3420 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
5db06880 3421#endif
89122651 3422 PL_bufptr = s + 3;
6e909404
JH
3423 PL_lex_state = LEX_INTERPCONCAT;
3424 return yylex();
a0d0e21e 3425 }
6e909404 3426 else {
90771dc0 3427 I32 tmp;
5db06880
NC
3428 if (!PL_madskills) /* when just compiling don't need correct */
3429 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3430 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3792a11b 3431 if ((*s == 'L' || *s == 'U') &&
6e909404
JH
3432 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3433 PL_lex_casestack[--PL_lex_casemods] = '\0';
bbf60fe6 3434 return REPORT(')');
6e909404
JH
3435 }
3436 if (PL_lex_casemods > 10)
3437 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3438 PL_lex_casestack[PL_lex_casemods++] = *s;
3439 PL_lex_casestack[PL_lex_casemods] = '\0';
3440 PL_lex_state = LEX_INTERPCONCAT;
cd81e915 3441 start_force(PL_curforce);
9ded7720 3442 NEXTVAL_NEXTTOKE.ival = 0;
6e909404 3443 force_next('(');
cd81e915 3444 start_force(PL_curforce);
6e909404 3445 if (*s == 'l')
9ded7720 3446 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
6e909404 3447 else if (*s == 'u')
9ded7720 3448 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
6e909404 3449 else if (*s == 'L')
9ded7720 3450 NEXTVAL_NEXTTOKE.ival = OP_LC;
6e909404 3451 else if (*s == 'U')
9ded7720 3452 NEXTVAL_NEXTTOKE.ival = OP_UC;
6e909404 3453 else if (*s == 'Q')
9ded7720 3454 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
6e909404
JH
3455 else
3456 Perl_croak(aTHX_ "panic: yylex");
5db06880 3457 if (PL_madskills) {
a5849ce5
NC
3458 SV* const tmpsv = newSVpvs("\\ ");
3459 /* replace the space with the character we want to escape
3460 */
3461 SvPVX(tmpsv)[1] = *s;
5db06880
NC
3462 curmad('_', tmpsv);
3463 }
6e909404 3464 PL_bufptr = s + 1;
a0d0e21e 3465 }
79072805 3466 force_next(FUNC);
3280af22
NIS
3467 if (PL_lex_starts) {
3468 s = PL_bufptr;
3469 PL_lex_starts = 0;
5db06880
NC
3470#ifdef PERL_MAD
3471 if (PL_madskills) {
cd81e915
NC
3472 if (PL_thistoken)
3473 sv_free(PL_thistoken);
6b29d1f5 3474 PL_thistoken = newSVpvs("");
5db06880
NC
3475 }
3476#endif
131b3ad0
DM
3477 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3478 if (PL_lex_casemods == 1 && PL_lex_inpat)
3479 OPERATOR(',');
3480 else
3481 Aop(OP_CONCAT);
79072805
LW
3482 }
3483 else
cea2e8a9 3484 return yylex();
79072805
LW
3485 }
3486
55497cff 3487 case LEX_INTERPPUSH:
bbf60fe6 3488 return REPORT(sublex_push());
55497cff 3489
79072805 3490 case LEX_INTERPSTART:
3280af22 3491 if (PL_bufptr == PL_bufend)
bbf60fe6 3492 return REPORT(sublex_done());
607df283 3493 DEBUG_T({ PerlIO_printf(Perl_debug_log,
b6007c36 3494 "### Interpolated variable\n"); });
3280af22
NIS
3495 PL_expect = XTERM;
3496 PL_lex_dojoin = (*PL_bufptr == '@');
3497 PL_lex_state = LEX_INTERPNORMAL;
3498 if (PL_lex_dojoin) {
cd81e915 3499 start_force(PL_curforce);
9ded7720 3500 NEXTVAL_NEXTTOKE.ival = 0;
79072805 3501 force_next(',');
cd81e915 3502 start_force(PL_curforce);
a0d0e21e 3503 force_ident("\"", '$');
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 = 0;
79072805 3509 force_next('(');
cd81e915 3510 start_force(PL_curforce);
9ded7720 3511 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
79072805
LW
3512 force_next(FUNC);
3513 }
3280af22
NIS
3514 if (PL_lex_starts++) {
3515 s = PL_bufptr;
5db06880
NC
3516#ifdef PERL_MAD
3517 if (PL_madskills) {
cd81e915
NC
3518 if (PL_thistoken)
3519 sv_free(PL_thistoken);
6b29d1f5 3520 PL_thistoken = newSVpvs("");
5db06880
NC
3521 }
3522#endif
131b3ad0
DM
3523 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3524 if (!PL_lex_casemods && PL_lex_inpat)
3525 OPERATOR(',');
3526 else
3527 Aop(OP_CONCAT);
79072805 3528 }
cea2e8a9 3529 return yylex();
79072805
LW
3530
3531 case LEX_INTERPENDMAYBE:
3280af22
NIS
3532 if (intuit_more(PL_bufptr)) {
3533 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
79072805
LW
3534 break;
3535 }
3536 /* FALL THROUGH */
3537
3538 case LEX_INTERPEND:
3280af22
NIS
3539 if (PL_lex_dojoin) {
3540 PL_lex_dojoin = FALSE;
3541 PL_lex_state = LEX_INTERPCONCAT;
5db06880
NC
3542#ifdef PERL_MAD
3543 if (PL_madskills) {
cd81e915
NC
3544 if (PL_thistoken)
3545 sv_free(PL_thistoken);
6b29d1f5 3546 PL_thistoken = newSVpvs("");
5db06880
NC
3547 }
3548#endif
bbf60fe6 3549 return REPORT(')');
79072805 3550 }
43a16006 3551 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
25da4f38 3552 && SvEVALED(PL_lex_repl))
43a16006 3553 {
e9fa98b2 3554 if (PL_bufptr != PL_bufend)
cea2e8a9 3555 Perl_croak(aTHX_ "Bad evalled substitution pattern");
a0714e2c 3556 PL_lex_repl = NULL;
e9fa98b2 3557 }
79072805
LW
3558 /* FALLTHROUGH */
3559 case LEX_INTERPCONCAT:
3560#ifdef DEBUGGING
3280af22 3561 if (PL_lex_brackets)
cea2e8a9 3562 Perl_croak(aTHX_ "panic: INTERPCONCAT");
79072805 3563#endif
3280af22 3564 if (PL_bufptr == PL_bufend)
bbf60fe6 3565 return REPORT(sublex_done());
79072805 3566
3280af22
NIS
3567 if (SvIVX(PL_linestr) == '\'') {
3568 SV *sv = newSVsv(PL_linestr);
3569 if (!PL_lex_inpat)
76e3520e 3570 sv = tokeq(sv);
3280af22 3571 else if ( PL_hints & HINT_NEW_RE )
eb0d8d16 3572 sv = new_constant(NULL, 0, "qr", sv, sv, "q", 1);
6154021b 3573 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3280af22 3574 s = PL_bufend;
79072805
LW
3575 }
3576 else {
3280af22 3577 s = scan_const(PL_bufptr);
79072805 3578 if (*s == '\\')
3280af22 3579 PL_lex_state = LEX_INTERPCASEMOD;
79072805 3580 else
3280af22 3581 PL_lex_state = LEX_INTERPSTART;
79072805
LW
3582 }
3583
3280af22 3584 if (s != PL_bufptr) {
cd81e915 3585 start_force(PL_curforce);
5db06880
NC
3586 if (PL_madskills) {
3587 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3588 }
6154021b 3589 NEXTVAL_NEXTTOKE = pl_yylval;
3280af22 3590 PL_expect = XTERM;
79072805 3591 force_next(THING);
131b3ad0 3592 if (PL_lex_starts++) {
5db06880
NC
3593#ifdef PERL_MAD
3594 if (PL_madskills) {
cd81e915
NC
3595 if (PL_thistoken)
3596 sv_free(PL_thistoken);
6b29d1f5 3597 PL_thistoken = newSVpvs("");
5db06880
NC
3598 }
3599#endif
131b3ad0
DM
3600 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3601 if (!PL_lex_casemods && PL_lex_inpat)
3602 OPERATOR(',');
3603 else
3604 Aop(OP_CONCAT);
3605 }
79072805 3606 else {
3280af22 3607 PL_bufptr = s;
cea2e8a9 3608 return yylex();
79072805
LW
3609 }
3610 }
3611
cea2e8a9 3612 return yylex();
a0d0e21e 3613 case LEX_FORMLINE:
3280af22
NIS
3614 PL_lex_state = LEX_NORMAL;
3615 s = scan_formline(PL_bufptr);
3616 if (!PL_lex_formbrack)
a0d0e21e
LW
3617 goto rightbracket;
3618 OPERATOR(';');
79072805
LW
3619 }
3620
3280af22
NIS
3621 s = PL_bufptr;
3622 PL_oldoldbufptr = PL_oldbufptr;
3623 PL_oldbufptr = s;
463ee0b2
LW
3624
3625 retry:
5db06880 3626#ifdef PERL_MAD
cd81e915
NC
3627 if (PL_thistoken) {
3628 sv_free(PL_thistoken);
3629 PL_thistoken = 0;
5db06880 3630 }
cd81e915 3631 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
5db06880 3632#endif
378cc40b
LW
3633 switch (*s) {
3634 default:
7e2040f0 3635 if (isIDFIRST_lazy_if(s,UTF))
834a4ddd 3636 goto keylookup;
b1fc3636
CJ
3637 {
3638 unsigned char c = *s;
3639 len = UTF ? Perl_utf8_length(aTHX_ (U8 *) PL_linestart, (U8 *) s) : (STRLEN) (s - PL_linestart);
3640 if (len > UNRECOGNIZED_PRECEDE_COUNT) {
3641 d = UTF ? (char *) Perl_utf8_hop(aTHX_ (U8 *) s, -UNRECOGNIZED_PRECEDE_COUNT) : s - UNRECOGNIZED_PRECEDE_COUNT;
3642 } else {
3643 d = PL_linestart;
3644 }
3645 *s = '\0';
3646 Perl_croak(aTHX_ "Unrecognized character \\x%02X; marked by <-- HERE after %s<-- HERE near column %d", c, d, (int) len + 1);
3647 }
e929a76b
LW
3648 case 4:
3649 case 26:
3650 goto fake_eof; /* emulate EOF on ^D or ^Z */
378cc40b 3651 case 0:
5db06880
NC
3652#ifdef PERL_MAD
3653 if (PL_madskills)
cd81e915 3654 PL_faketokens = 0;
5db06880 3655#endif
3280af22
NIS
3656 if (!PL_rsfp) {
3657 PL_last_uni = 0;
3658 PL_last_lop = 0;
c5ee2135 3659 if (PL_lex_brackets) {
10edeb5d
JH
3660 yyerror((const char *)
3661 (PL_lex_formbrack
3662 ? "Format not terminated"
3663 : "Missing right curly or square bracket"));
c5ee2135 3664 }
4e553d73 3665 DEBUG_T( { PerlIO_printf(Perl_debug_log,
607df283 3666 "### Tokener got EOF\n");
5f80b19c 3667 } );
79072805 3668 TOKEN(0);
463ee0b2 3669 }
3280af22 3670 if (s++ < PL_bufend)
a687059c 3671 goto retry; /* ignore stray nulls */
3280af22
NIS
3672 PL_last_uni = 0;
3673 PL_last_lop = 0;
3674 if (!PL_in_eval && !PL_preambled) {
3675 PL_preambled = TRUE;
5db06880
NC
3676#ifdef PERL_MAD
3677 if (PL_madskills)
cd81e915 3678 PL_faketokens = 1;
5db06880 3679#endif
5ab7ff98
NC
3680 if (PL_perldb) {
3681 /* Generate a string of Perl code to load the debugger.
3682 * If PERL5DB is set, it will return the contents of that,
3683 * otherwise a compile-time require of perl5db.pl. */
3684
3685 const char * const pdb = PerlEnv_getenv("PERL5DB");
3686
3687 if (pdb) {
3688 sv_setpv(PL_linestr, pdb);
3689 sv_catpvs(PL_linestr,";");
3690 } else {
3691 SETERRNO(0,SS_NORMAL);
3692 sv_setpvs(PL_linestr, "BEGIN { require 'perl5db.pl' };");
3693 }
3694 } else
3695 sv_setpvs(PL_linestr,"");
c62eb204
NC
3696 if (PL_preambleav) {
3697 SV **svp = AvARRAY(PL_preambleav);
3698 SV **const end = svp + AvFILLp(PL_preambleav);
3699 while(svp <= end) {
3700 sv_catsv(PL_linestr, *svp);
3701 ++svp;
396482e1 3702 sv_catpvs(PL_linestr, ";");
91b7def8 3703 }
daba3364 3704 sv_free(MUTABLE_SV(PL_preambleav));
3280af22 3705 PL_preambleav = NULL;
91b7def8 3706 }
9f639728
FR
3707 if (PL_minus_E)
3708 sv_catpvs(PL_linestr,
3709 "use feature ':5." STRINGIFY(PERL_VERSION) "';");
3280af22 3710 if (PL_minus_n || PL_minus_p) {
396482e1 3711 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3280af22 3712 if (PL_minus_l)
396482e1 3713 sv_catpvs(PL_linestr,"chomp;");
3280af22 3714 if (PL_minus_a) {
3280af22 3715 if (PL_minus_F) {
3792a11b
NC
3716 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3717 || *PL_splitstr == '"')
3280af22 3718 && strchr(PL_splitstr + 1, *PL_splitstr))
3db68c4c 3719 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
54310121 3720 else {
c8ef6a4b
NC
3721 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3722 bytes can be used as quoting characters. :-) */
dd374669 3723 const char *splits = PL_splitstr;
91d456ae 3724 sv_catpvs(PL_linestr, "our @F=split(q\0");
48c4c863
NC
3725 do {
3726 /* Need to \ \s */
dd374669
AL
3727 if (*splits == '\\')
3728 sv_catpvn(PL_linestr, splits, 1);
3729 sv_catpvn(PL_linestr, splits, 1);
3730 } while (*splits++);
48c4c863
NC
3731 /* This loop will embed the trailing NUL of
3732 PL_linestr as the last thing it does before
3733 terminating. */
396482e1 3734 sv_catpvs(PL_linestr, ");");
54310121 3735 }
2304df62
AD
3736 }
3737 else
396482e1 3738 sv_catpvs(PL_linestr,"our @F=split(' ');");
2304df62 3739 }
79072805 3740 }
396482e1 3741 sv_catpvs(PL_linestr, "\n");
3280af22
NIS
3742 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3743 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3744 PL_last_lop = PL_last_uni = NULL;
65269a95 3745 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
5fa550fb 3746 update_debugger_info(PL_linestr, NULL, 0);
79072805 3747 goto retry;
a687059c 3748 }
e929a76b 3749 do {
aa7440fb 3750 bof = PL_rsfp ? TRUE : FALSE;
bd61b366 3751 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
7e28d3af 3752 fake_eof:
5db06880 3753#ifdef PERL_MAD
cd81e915 3754 PL_realtokenstart = -1;
5db06880 3755#endif
7e28d3af 3756 if (PL_rsfp) {
4c84d7f2 3757 if ((PerlIO *)PL_rsfp == PerlIO_stdin())
7e28d3af
JH
3758 PerlIO_clearerr(PL_rsfp);
3759 else
3760 (void)PerlIO_close(PL_rsfp);
4608196e 3761 PL_rsfp = NULL;
7e28d3af
JH
3762 PL_doextract = FALSE;
3763 }
3764 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
5db06880
NC
3765#ifdef PERL_MAD
3766 if (PL_madskills)
cd81e915 3767 PL_faketokens = 1;
5db06880 3768#endif
49a54bbe
NC
3769 if (PL_minus_p)
3770 sv_setpvs(PL_linestr, ";}continue{print;}");
3771 else
3772 sv_setpvs(PL_linestr, ";}");
7e28d3af
JH
3773 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3774 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3775 PL_last_lop = PL_last_uni = NULL;
7e28d3af
JH
3776 PL_minus_n = PL_minus_p = 0;
3777 goto retry;
3778 }
3779 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
bd61b366 3780 PL_last_lop = PL_last_uni = NULL;
76f68e9b 3781 sv_setpvs(PL_linestr,"");
7e28d3af
JH
3782 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3783 }
7aa207d6
JH
3784 /* If it looks like the start of a BOM or raw UTF-16,
3785 * check if it in fact is. */
3786 else if (bof &&
3787 (*s == 0 ||
3788 *(U8*)s == 0xEF ||
3789 *(U8*)s >= 0xFE ||
3790 s[1] == 0)) {
226017aa 3791#ifdef PERLIO_IS_STDIO
e3f494f1
JH
3792# ifdef __GNU_LIBRARY__
3793# if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
226017aa
DD
3794# define FTELL_FOR_PIPE_IS_BROKEN
3795# endif
e3f494f1
JH
3796# else
3797# ifdef __GLIBC__
3798# if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3799# define FTELL_FOR_PIPE_IS_BROKEN
3800# endif
3801# endif
226017aa
DD
3802# endif
3803#endif
eb160463 3804 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
7e28d3af 3805 if (bof) {
3280af22 3806 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
7e28d3af 3807 s = swallow_bom((U8*)s);
e929a76b 3808 }
378cc40b 3809 }
3280af22 3810 if (PL_doextract) {
a0d0e21e 3811 /* Incest with pod. */
5db06880
NC
3812#ifdef PERL_MAD
3813 if (PL_madskills)
cd81e915 3814 sv_catsv(PL_thiswhite, PL_linestr);
5db06880 3815#endif
01a57ef7 3816 if (*s == '=' && strnEQ(s, "=cut", 4) && !isALPHA(s[4])) {
76f68e9b 3817 sv_setpvs(PL_linestr, "");
3280af22
NIS
3818 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3819 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3820 PL_last_lop = PL_last_uni = NULL;
3280af22 3821 PL_doextract = FALSE;
a0d0e21e 3822 }
4e553d73 3823 }
463ee0b2 3824 incline(s);
3280af22
NIS
3825 } while (PL_doextract);
3826 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
65269a95 3827 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
5fa550fb 3828 update_debugger_info(PL_linestr, NULL, 0);
3280af22 3829 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3830 PL_last_lop = PL_last_uni = NULL;
57843af0 3831 if (CopLINE(PL_curcop) == 1) {
3280af22 3832 while (s < PL_bufend && isSPACE(*s))
79072805 3833 s++;
a0d0e21e 3834 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
79072805 3835 s++;
5db06880
NC
3836#ifdef PERL_MAD
3837 if (PL_madskills)
cd81e915 3838 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
5db06880 3839#endif
bd61b366 3840 d = NULL;
3280af22 3841 if (!PL_in_eval) {
44a8e56a 3842 if (*s == '#' && *(s+1) == '!')
3843 d = s + 2;
3844#ifdef ALTERNATE_SHEBANG
3845 else {
bfed75c6 3846 static char const as[] = ALTERNATE_SHEBANG;
44a8e56a 3847 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3848 d = s + (sizeof(as) - 1);
3849 }
3850#endif /* ALTERNATE_SHEBANG */
3851 }
3852 if (d) {
b8378b72 3853 char *ipath;
774d564b 3854 char *ipathend;
b8378b72 3855
774d564b 3856 while (isSPACE(*d))
b8378b72
CS
3857 d++;
3858 ipath = d;
774d564b 3859 while (*d && !isSPACE(*d))
3860 d++;
3861 ipathend = d;
3862
3863#ifdef ARG_ZERO_IS_SCRIPT
3864 if (ipathend > ipath) {
3865 /*
3866 * HP-UX (at least) sets argv[0] to the script name,
3867 * which makes $^X incorrect. And Digital UNIX and Linux,
3868 * at least, set argv[0] to the basename of the Perl
3869 * interpreter. So, having found "#!", we'll set it right.
3870 */
fafc274c
NC
3871 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3872 SVt_PV)); /* $^X */
774d564b 3873 assert(SvPOK(x) || SvGMAGICAL(x));
cc49e20b 3874 if (sv_eq(x, CopFILESV(PL_curcop))) {
774d564b 3875 sv_setpvn(x, ipath, ipathend - ipath);
9607fc9c 3876 SvSETMAGIC(x);
3877 }
556c1dec
JH
3878 else {
3879 STRLEN blen;
3880 STRLEN llen;
cfd0369c 3881 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
9d4ba2ae 3882 const char * const lstart = SvPV_const(x,llen);
556c1dec
JH
3883 if (llen < blen) {
3884 bstart += blen - llen;
3885 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3886 sv_setpvn(x, ipath, ipathend - ipath);
3887 SvSETMAGIC(x);
3888 }
3889 }
3890 }
774d564b 3891 TAINT_NOT; /* $^X is always tainted, but that's OK */
8ebc5c01 3892 }
774d564b 3893#endif /* ARG_ZERO_IS_SCRIPT */
b8378b72
CS
3894
3895 /*
3896 * Look for options.
3897 */
748a9306 3898 d = instr(s,"perl -");
84e30d1a 3899 if (!d) {
748a9306 3900 d = instr(s,"perl");
84e30d1a
GS
3901#if defined(DOSISH)
3902 /* avoid getting into infinite loops when shebang
3903 * line contains "Perl" rather than "perl" */
3904 if (!d) {
3905 for (d = ipathend-4; d >= ipath; --d) {
3906 if ((*d == 'p' || *d == 'P')
3907 && !ibcmp(d, "perl", 4))
3908 {
3909 break;
3910 }
3911 }
3912 if (d < ipath)
bd61b366 3913 d = NULL;
84e30d1a
GS
3914 }
3915#endif
3916 }
44a8e56a 3917#ifdef ALTERNATE_SHEBANG
3918 /*
3919 * If the ALTERNATE_SHEBANG on this system starts with a
3920 * character that can be part of a Perl expression, then if
3921 * we see it but not "perl", we're probably looking at the
3922 * start of Perl code, not a request to hand off to some
3923 * other interpreter. Similarly, if "perl" is there, but
3924 * not in the first 'word' of the line, we assume the line
3925 * contains the start of the Perl program.
44a8e56a 3926 */
3927 if (d && *s != '#') {
f54cb97a 3928 const char *c = ipath;
44a8e56a 3929 while (*c && !strchr("; \t\r\n\f\v#", *c))
3930 c++;
3931 if (c < d)
bd61b366 3932 d = NULL; /* "perl" not in first word; ignore */
44a8e56a 3933 else
3934 *s = '#'; /* Don't try to parse shebang line */
3935 }
774d564b 3936#endif /* ALTERNATE_SHEBANG */
748a9306 3937 if (!d &&
44a8e56a 3938 *s == '#' &&
774d564b 3939 ipathend > ipath &&
3280af22 3940 !PL_minus_c &&
748a9306 3941 !instr(s,"indir") &&
3280af22 3942 instr(PL_origargv[0],"perl"))
748a9306 3943 {
27da23d5 3944 dVAR;
9f68db38 3945 char **newargv;
9f68db38 3946
774d564b 3947 *ipathend = '\0';
3948 s = ipathend + 1;
3280af22 3949 while (s < PL_bufend && isSPACE(*s))
9f68db38 3950 s++;
3280af22 3951 if (s < PL_bufend) {
d85f917e 3952 Newx(newargv,PL_origargc+3,char*);
9f68db38 3953 newargv[1] = s;
3280af22 3954 while (s < PL_bufend && !isSPACE(*s))
9f68db38
LW
3955 s++;
3956 *s = '\0';
3280af22 3957 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
9f68db38
LW
3958 }
3959 else
3280af22 3960 newargv = PL_origargv;
774d564b 3961 newargv[0] = ipath;
b35112e7 3962 PERL_FPU_PRE_EXEC
b4748376 3963 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
b35112e7 3964 PERL_FPU_POST_EXEC
cea2e8a9 3965 Perl_croak(aTHX_ "Can't exec %s", ipath);
9f68db38 3966 }
748a9306 3967 if (d) {
c35e046a
AL
3968 while (*d && !isSPACE(*d))
3969 d++;
3970 while (SPACE_OR_TAB(*d))
3971 d++;
748a9306
LW
3972
3973 if (*d++ == '-') {
f54cb97a 3974 const bool switches_done = PL_doswitches;
fb993905
GA
3975 const U32 oldpdb = PL_perldb;
3976 const bool oldn = PL_minus_n;
3977 const bool oldp = PL_minus_p;
c7030b81 3978 const char *d1 = d;
fb993905 3979
8cc95fdb 3980 do {
4ba71d51
FC
3981 bool baduni = FALSE;
3982 if (*d1 == 'C') {
bd0ab00d
NC
3983 const char *d2 = d1 + 1;
3984 if (parse_unicode_opts((const char **)&d2)
3985 != PL_unicode)
3986 baduni = TRUE;
4ba71d51
FC
3987 }
3988 if (baduni || *d1 == 'M' || *d1 == 'm') {
c7030b81
NC
3989 const char * const m = d1;
3990 while (*d1 && !isSPACE(*d1))
3991 d1++;
cea2e8a9 3992 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
c7030b81 3993 (int)(d1 - m), m);
8cc95fdb 3994 }
c7030b81
NC
3995 d1 = moreswitches(d1);
3996 } while (d1);
f0b2cf55
YST
3997 if (PL_doswitches && !switches_done) {
3998 int argc = PL_origargc;
3999 char **argv = PL_origargv;
4000 do {
4001 argc--,argv++;
4002 } while (argc && argv[0][0] == '-' && argv[0][1]);
4003 init_argv_symbols(argc,argv);
4004 }
65269a95 4005 if (((PERLDB_LINE || PERLDB_SAVESRC) && !oldpdb) ||
155aba94 4006 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
b084f20b 4007 /* if we have already added "LINE: while (<>) {",
4008 we must not do it again */
748a9306 4009 {
76f68e9b 4010 sv_setpvs(PL_linestr, "");
3280af22
NIS
4011 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
4012 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 4013 PL_last_lop = PL_last_uni = NULL;
3280af22 4014 PL_preambled = FALSE;
65269a95 4015 if (PERLDB_LINE || PERLDB_SAVESRC)
3280af22 4016 (void)gv_fetchfile(PL_origfilename);
748a9306
LW
4017 goto retry;
4018 }
a0d0e21e 4019 }
79072805 4020 }
9f68db38 4021 }
79072805 4022 }
3280af22
NIS
4023 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
4024 PL_bufptr = s;
4025 PL_lex_state = LEX_FORMLINE;
cea2e8a9 4026 return yylex();
ae986130 4027 }
378cc40b 4028 goto retry;
4fdae800 4029 case '\r':
6a27c188 4030#ifdef PERL_STRICT_CR
cea2e8a9 4031 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
4e553d73 4032 Perl_croak(aTHX_
cc507455 4033 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
a868473f 4034#endif
4fdae800 4035 case ' ': case '\t': case '\f': case 013:
5db06880 4036#ifdef PERL_MAD
cd81e915 4037 PL_realtokenstart = -1;
ac372eb8
RD
4038 if (!PL_thiswhite)
4039 PL_thiswhite = newSVpvs("");
4040 sv_catpvn(PL_thiswhite, s, 1);
5db06880 4041#endif
ac372eb8 4042 s++;
378cc40b 4043 goto retry;
378cc40b 4044 case '#':
e929a76b 4045 case '\n':
5db06880 4046#ifdef PERL_MAD
cd81e915 4047 PL_realtokenstart = -1;
5db06880 4048 if (PL_madskills)
cd81e915 4049 PL_faketokens = 0;
5db06880 4050#endif
3280af22 4051 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
df0deb90
GS
4052 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
4053 /* handle eval qq[#line 1 "foo"\n ...] */
4054 CopLINE_dec(PL_curcop);
4055 incline(s);
4056 }
5db06880
NC
4057 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
4058 s = SKIPSPACE0(s);
4059 if (!PL_in_eval || PL_rsfp)
4060 incline(s);
4061 }
4062 else {
4063 d = s;
4064 while (d < PL_bufend && *d != '\n')
4065 d++;
4066 if (d < PL_bufend)
4067 d++;
4068 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
4069 Perl_croak(aTHX_ "panic: input overflow");
4070#ifdef PERL_MAD
4071 if (PL_madskills)
cd81e915 4072 PL_thiswhite = newSVpvn(s, d - s);
5db06880
NC
4073#endif
4074 s = d;
4075 incline(s);
4076 }
3280af22
NIS
4077 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
4078 PL_bufptr = s;
4079 PL_lex_state = LEX_FORMLINE;
cea2e8a9 4080 return yylex();
a687059c 4081 }
378cc40b 4082 }
a687059c 4083 else {
5db06880
NC
4084#ifdef PERL_MAD
4085 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
4086 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
cd81e915 4087 PL_faketokens = 0;
5db06880
NC
4088 s = SKIPSPACE0(s);
4089 TOKEN(PEG); /* make sure any #! line is accessible */
4090 }
4091 s = SKIPSPACE0(s);
4092 }
4093 else {
4094/* if (PL_madskills && PL_lex_formbrack) { */
4095 d = s;
4096 while (d < PL_bufend && *d != '\n')
4097 d++;
4098 if (d < PL_bufend)
4099 d++;
4100 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
4101 Perl_croak(aTHX_ "panic: input overflow");
4102 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
cd81e915 4103 if (!PL_thiswhite)
6b29d1f5 4104 PL_thiswhite = newSVpvs("");
5db06880 4105 if (CopLINE(PL_curcop) == 1) {
76f68e9b 4106 sv_setpvs(PL_thiswhite, "");
cd81e915 4107 PL_faketokens = 0;
5db06880 4108 }
cd81e915 4109 sv_catpvn(PL_thiswhite, s, d - s);
5db06880
NC
4110 }
4111 s = d;
4112/* }
4113 *s = '\0';
4114 PL_bufend = s; */
4115 }
4116#else
378cc40b 4117 *s = '\0';
3280af22 4118 PL_bufend = s;
5db06880 4119#endif
a687059c 4120 }
378cc40b
LW
4121 goto retry;
4122 case '-':
79072805 4123 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
e5edeb50 4124 I32 ftst = 0;
90771dc0 4125 char tmp;
e5edeb50 4126
378cc40b 4127 s++;
3280af22 4128 PL_bufptr = s;
748a9306
LW
4129 tmp = *s++;
4130
bf4acbe4 4131 while (s < PL_bufend && SPACE_OR_TAB(*s))
748a9306
LW
4132 s++;
4133
4134 if (strnEQ(s,"=>",2)) {
3280af22 4135 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
931e0695 4136 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
748a9306
LW
4137 OPERATOR('-'); /* unary minus */
4138 }
3280af22 4139 PL_last_uni = PL_oldbufptr;
748a9306 4140 switch (tmp) {
e5edeb50
JH
4141 case 'r': ftst = OP_FTEREAD; break;
4142 case 'w': ftst = OP_FTEWRITE; break;
4143 case 'x': ftst = OP_FTEEXEC; break;
4144 case 'o': ftst = OP_FTEOWNED; break;
4145 case 'R': ftst = OP_FTRREAD; break;
4146 case 'W': ftst = OP_FTRWRITE; break;
4147 case 'X': ftst = OP_FTREXEC; break;
4148 case 'O': ftst = OP_FTROWNED; break;
4149 case 'e': ftst = OP_FTIS; break;
4150 case 'z': ftst = OP_FTZERO; break;
4151 case 's': ftst = OP_FTSIZE; break;
4152 case 'f': ftst = OP_FTFILE; break;
4153 case 'd': ftst = OP_FTDIR; break;
4154 case 'l': ftst = OP_FTLINK; break;
4155 case 'p': ftst = OP_FTPIPE; break;
4156 case 'S': ftst = OP_FTSOCK; break;
4157 case 'u': ftst = OP_FTSUID; break;
4158 case 'g': ftst = OP_FTSGID; break;
4159 case 'k': ftst = OP_FTSVTX; break;
4160 case 'b': ftst = OP_FTBLK; break;
4161 case 'c': ftst = OP_FTCHR; break;
4162 case 't': ftst = OP_FTTTY; break;
4163 case 'T': ftst = OP_FTTEXT; break;
4164 case 'B': ftst = OP_FTBINARY; break;
4165 case 'M': case 'A': case 'C':
fafc274c 4166 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
e5edeb50
JH
4167 switch (tmp) {
4168 case 'M': ftst = OP_FTMTIME; break;
4169 case 'A': ftst = OP_FTATIME; break;
4170 case 'C': ftst = OP_FTCTIME; break;
4171 default: break;
4172 }
4173 break;
378cc40b 4174 default:
378cc40b
LW
4175 break;
4176 }
e5edeb50 4177 if (ftst) {
eb160463 4178 PL_last_lop_op = (OPCODE)ftst;
4e553d73 4179 DEBUG_T( { PerlIO_printf(Perl_debug_log,
a18d764d 4180 "### Saw file test %c\n", (int)tmp);
5f80b19c 4181 } );
e5edeb50
JH
4182 FTST(ftst);
4183 }
4184 else {
4185 /* Assume it was a minus followed by a one-letter named
4186 * subroutine call (or a -bareword), then. */
95c31fe3 4187 DEBUG_T( { PerlIO_printf(Perl_debug_log,
17ad61e0 4188 "### '-%c' looked like a file test but was not\n",
4fccd7c6 4189 (int) tmp);
5f80b19c 4190 } );
3cf7b4c4 4191 s = --PL_bufptr;
e5edeb50 4192 }
378cc40b 4193 }
90771dc0
NC
4194 {
4195 const char tmp = *s++;
4196 if (*s == tmp) {
4197 s++;
4198 if (PL_expect == XOPERATOR)
4199 TERM(POSTDEC);
4200 else
4201 OPERATOR(PREDEC);
4202 }
4203 else if (*s == '>') {
4204 s++;
29595ff2 4205 s = SKIPSPACE1(s);
90771dc0
NC
4206 if (isIDFIRST_lazy_if(s,UTF)) {
4207 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
4208 TOKEN(ARROW);
4209 }
4210 else if (*s == '$')
4211 OPERATOR(ARROW);
4212 else
4213 TERM(ARROW);
4214 }
3280af22 4215 if (PL_expect == XOPERATOR)
90771dc0
NC
4216 Aop(OP_SUBTRACT);
4217 else {
4218 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4219 check_uni();
4220 OPERATOR('-'); /* unary minus */
79072805 4221 }
2f3197b3 4222 }
79072805 4223
378cc40b 4224 case '+':
90771dc0
NC
4225 {
4226 const char tmp = *s++;
4227 if (*s == tmp) {
4228 s++;
4229 if (PL_expect == XOPERATOR)
4230 TERM(POSTINC);
4231 else
4232 OPERATOR(PREINC);
4233 }
3280af22 4234 if (PL_expect == XOPERATOR)
90771dc0
NC
4235 Aop(OP_ADD);
4236 else {
4237 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4238 check_uni();
4239 OPERATOR('+');
4240 }
2f3197b3 4241 }
a687059c 4242
378cc40b 4243 case '*':
3280af22
NIS
4244 if (PL_expect != XOPERATOR) {
4245 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4246 PL_expect = XOPERATOR;
4247 force_ident(PL_tokenbuf, '*');
4248 if (!*PL_tokenbuf)
a0d0e21e 4249 PREREF('*');
79072805 4250 TERM('*');
a687059c 4251 }
79072805
LW
4252 s++;
4253 if (*s == '*') {
a687059c 4254 s++;
79072805 4255 PWop(OP_POW);
a687059c 4256 }
79072805
LW
4257 Mop(OP_MULTIPLY);
4258
378cc40b 4259 case '%':
3280af22 4260 if (PL_expect == XOPERATOR) {
bbce6d69 4261 ++s;
4262 Mop(OP_MODULO);
a687059c 4263 }
3280af22 4264 PL_tokenbuf[0] = '%';
e8ae98db
RGS
4265 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4266 sizeof PL_tokenbuf - 1, FALSE);
3280af22 4267 if (!PL_tokenbuf[1]) {
bbce6d69 4268 PREREF('%');
a687059c 4269 }
3280af22 4270 PL_pending_ident = '%';
bbce6d69 4271 TERM('%');
a687059c 4272
378cc40b 4273 case '^':
79072805 4274 s++;
a0d0e21e 4275 BOop(OP_BIT_XOR);
79072805 4276 case '[':
3280af22 4277 PL_lex_brackets++;
df3467db
IG
4278 {
4279 const char tmp = *s++;
4280 OPERATOR(tmp);
4281 }
378cc40b 4282 case '~':
0d863452 4283 if (s[1] == '~'
3e7dd34d 4284 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR))
0d863452
RH
4285 {
4286 s += 2;
4287 Eop(OP_SMARTMATCH);
4288 }
378cc40b 4289 case ',':
90771dc0
NC
4290 {
4291 const char tmp = *s++;
4292 OPERATOR(tmp);
4293 }
a0d0e21e
LW
4294 case ':':
4295 if (s[1] == ':') {
4296 len = 0;
0bfa2a8a 4297 goto just_a_word_zero_gv;
a0d0e21e
LW
4298 }
4299 s++;
09bef843
SB
4300 switch (PL_expect) {
4301 OP *attrs;
5db06880
NC
4302#ifdef PERL_MAD
4303 I32 stuffstart;
4304#endif
09bef843
SB
4305 case XOPERATOR:
4306 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
4307 break;
4308 PL_bufptr = s; /* update in case we back off */
4309 goto grabattrs;
4310 case XATTRBLOCK:
4311 PL_expect = XBLOCK;
4312 goto grabattrs;
4313 case XATTRTERM:
4314 PL_expect = XTERMBLOCK;
4315 grabattrs:
5db06880
NC
4316#ifdef PERL_MAD
4317 stuffstart = s - SvPVX(PL_linestr) - 1;
4318#endif
29595ff2 4319 s = PEEKSPACE(s);
5f66b61c 4320 attrs = NULL;
7e2040f0 4321 while (isIDFIRST_lazy_if(s,UTF)) {
90771dc0 4322 I32 tmp;
5cc237b8 4323 SV *sv;
09bef843 4324 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5458a98a 4325 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
f9829d6b
GS
4326 if (tmp < 0) tmp = -tmp;
4327 switch (tmp) {
4328 case KEY_or:
4329 case KEY_and:
4330 case KEY_for:
11baf631 4331 case KEY_foreach:
f9829d6b
GS
4332 case KEY_unless:
4333 case KEY_if:
4334 case KEY_while:
4335 case KEY_until:
4336 goto got_attrs;
4337 default:
4338 break;
4339 }
4340 }
5cc237b8 4341 sv = newSVpvn(s, len);
09bef843
SB
4342 if (*d == '(') {
4343 d = scan_str(d,TRUE,TRUE);
4344 if (!d) {
09bef843
SB
4345 /* MUST advance bufptr here to avoid bogus
4346 "at end of line" context messages from yyerror().
4347 */
4348 PL_bufptr = s + len;
4349 yyerror("Unterminated attribute parameter in attribute list");
4350 if (attrs)
4351 op_free(attrs);
5cc237b8 4352 sv_free(sv);
bbf60fe6 4353 return REPORT(0); /* EOF indicator */
09bef843
SB
4354 }
4355 }
4356 if (PL_lex_stuff) {
09bef843
SB
4357 sv_catsv(sv, PL_lex_stuff);
4358 attrs = append_elem(OP_LIST, attrs,
4359 newSVOP(OP_CONST, 0, sv));
4360 SvREFCNT_dec(PL_lex_stuff);
a0714e2c 4361 PL_lex_stuff = NULL;
09bef843
SB
4362 }
4363 else {
5cc237b8
BS
4364 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4365 sv_free(sv);
1108974d 4366 if (PL_in_my == KEY_our) {
df9a6019 4367 deprecate(":unique");
1108974d 4368 }
bfed75c6 4369 else
371fce9b
DM
4370 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4371 }
4372
d3cea301
SB
4373 /* NOTE: any CV attrs applied here need to be part of
4374 the CVf_BUILTIN_ATTRS define in cv.h! */
5cc237b8
BS
4375 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4376 sv_free(sv);
78f9721b 4377 CvLVALUE_on(PL_compcv);
5cc237b8
BS
4378 }
4379 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4380 sv_free(sv);
8e5dadda 4381 deprecate(":locked");
5cc237b8
BS
4382 }
4383 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4384 sv_free(sv);
78f9721b 4385 CvMETHOD_on(PL_compcv);
5cc237b8 4386 }
78f9721b
SM
4387 /* After we've set the flags, it could be argued that
4388 we don't need to do the attributes.pm-based setting
4389 process, and shouldn't bother appending recognized
d3cea301
SB
4390 flags. To experiment with that, uncomment the
4391 following "else". (Note that's already been
4392 uncommented. That keeps the above-applied built-in
4393 attributes from being intercepted (and possibly
4394 rejected) by a package's attribute routines, but is
4395 justified by the performance win for the common case
4396 of applying only built-in attributes.) */
0256094b 4397 else
78f9721b
SM
4398 attrs = append_elem(OP_LIST, attrs,
4399 newSVOP(OP_CONST, 0,
5cc237b8 4400 sv));
09bef843 4401 }
29595ff2 4402 s = PEEKSPACE(d);
0120eecf 4403 if (*s == ':' && s[1] != ':')
29595ff2 4404 s = PEEKSPACE(s+1);
0120eecf
GS
4405 else if (s == d)
4406 break; /* require real whitespace or :'s */
29595ff2 4407 /* XXX losing whitespace on sequential attributes here */
09bef843 4408 }
90771dc0
NC
4409 {
4410 const char tmp
4411 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4412 if (*s != ';' && *s != '}' && *s != tmp
4413 && (tmp != '=' || *s != ')')) {
4414 const char q = ((*s == '\'') ? '"' : '\'');
4415 /* If here for an expression, and parsed no attrs, back
4416 off. */
4417 if (tmp == '=' && !attrs) {
4418 s = PL_bufptr;
4419 break;
4420 }
4421 /* MUST advance bufptr here to avoid bogus "at end of line"
4422 context messages from yyerror().
4423 */
4424 PL_bufptr = s;
10edeb5d
JH
4425 yyerror( (const char *)
4426 (*s
4427 ? Perl_form(aTHX_ "Invalid separator character "
4428 "%c%c%c in attribute list", q, *s, q)
4429 : "Unterminated attribute list" ) );
90771dc0
NC
4430 if (attrs)
4431 op_free(attrs);
4432 OPERATOR(':');
09bef843 4433 }
09bef843 4434 }
f9829d6b 4435 got_attrs:
09bef843 4436 if (attrs) {
cd81e915 4437 start_force(PL_curforce);
9ded7720 4438 NEXTVAL_NEXTTOKE.opval = attrs;
cd81e915 4439 CURMAD('_', PL_nextwhite);
89122651 4440 force_next(THING);
5db06880
NC
4441 }
4442#ifdef PERL_MAD
4443 if (PL_madskills) {
cd81e915 4444 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
5db06880 4445 (s - SvPVX(PL_linestr)) - stuffstart);
09bef843 4446 }
5db06880 4447#endif
09bef843
SB
4448 TOKEN(COLONATTR);
4449 }
a0d0e21e 4450 OPERATOR(':');
8990e307
LW
4451 case '(':
4452 s++;
3280af22
NIS
4453 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4454 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
a0d0e21e 4455 else
3280af22 4456 PL_expect = XTERM;
29595ff2 4457 s = SKIPSPACE1(s);
a0d0e21e 4458 TOKEN('(');
378cc40b 4459 case ';':
f4dd75d9 4460 CLINE;
90771dc0
NC
4461 {
4462 const char tmp = *s++;
4463 OPERATOR(tmp);
4464 }
378cc40b 4465 case ')':
90771dc0
NC
4466 {
4467 const char tmp = *s++;
29595ff2 4468 s = SKIPSPACE1(s);
90771dc0
NC
4469 if (*s == '{')
4470 PREBLOCK(tmp);
4471 TERM(tmp);
4472 }
79072805
LW
4473 case ']':
4474 s++;
3280af22 4475 if (PL_lex_brackets <= 0)
d98d5fff 4476 yyerror("Unmatched right square bracket");
463ee0b2 4477 else
3280af22
NIS
4478 --PL_lex_brackets;
4479 if (PL_lex_state == LEX_INTERPNORMAL) {
4480 if (PL_lex_brackets == 0) {
02255c60
FC
4481 if (*s == '-' && s[1] == '>')
4482 PL_lex_state = LEX_INTERPENDMAYBE;
4483 else if (*s != '[' && *s != '{')
3280af22 4484 PL_lex_state = LEX_INTERPEND;
79072805
LW
4485 }
4486 }
4633a7c4 4487 TERM(']');
79072805
LW
4488 case '{':
4489 leftbracket:
79072805 4490 s++;
3280af22 4491 if (PL_lex_brackets > 100) {
8edd5f42 4492 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
8990e307 4493 }
3280af22 4494 switch (PL_expect) {
a0d0e21e 4495 case XTERM:
3280af22 4496 if (PL_lex_formbrack) {
a0d0e21e
LW
4497 s--;
4498 PRETERMBLOCK(DO);
4499 }
3280af22
NIS
4500 if (PL_oldoldbufptr == PL_last_lop)
4501 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
a0d0e21e 4502 else
3280af22 4503 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
79072805 4504 OPERATOR(HASHBRACK);
a0d0e21e 4505 case XOPERATOR:
bf4acbe4 4506 while (s < PL_bufend && SPACE_OR_TAB(*s))
748a9306 4507 s++;
44a8e56a 4508 d = s;
3280af22
NIS
4509 PL_tokenbuf[0] = '\0';
4510 if (d < PL_bufend && *d == '-') {
4511 PL_tokenbuf[0] = '-';
44a8e56a 4512 d++;
bf4acbe4 4513 while (d < PL_bufend && SPACE_OR_TAB(*d))
44a8e56a 4514 d++;
4515 }
7e2040f0 4516 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
3280af22 4517 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
8903cb82 4518 FALSE, &len);
bf4acbe4 4519 while (d < PL_bufend && SPACE_OR_TAB(*d))
748a9306
LW
4520 d++;
4521 if (*d == '}') {
f54cb97a 4522 const char minus = (PL_tokenbuf[0] == '-');
44a8e56a 4523 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4524 if (minus)
4525 force_next('-');
748a9306
LW
4526 }
4527 }
4528 /* FALL THROUGH */
09bef843 4529 case XATTRBLOCK:
748a9306 4530 case XBLOCK:
3280af22
NIS
4531 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4532 PL_expect = XSTATE;
a0d0e21e 4533 break;
09bef843 4534 case XATTRTERM:
a0d0e21e 4535 case XTERMBLOCK:
3280af22
NIS
4536 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4537 PL_expect = XSTATE;
a0d0e21e
LW
4538 break;
4539 default: {
f54cb97a 4540 const char *t;
3280af22
NIS
4541 if (PL_oldoldbufptr == PL_last_lop)
4542 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
a0d0e21e 4543 else
3280af22 4544 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
29595ff2 4545 s = SKIPSPACE1(s);
8452ff4b
SB
4546 if (*s == '}') {
4547 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4548 PL_expect = XTERM;
4549 /* This hack is to get the ${} in the message. */
4550 PL_bufptr = s+1;
4551 yyerror("syntax error");
4552 break;
4553 }
a0d0e21e 4554 OPERATOR(HASHBRACK);
8452ff4b 4555 }
b8a4b1be
GS
4556 /* This hack serves to disambiguate a pair of curlies
4557 * as being a block or an anon hash. Normally, expectation
4558 * determines that, but in cases where we're not in a
4559 * position to expect anything in particular (like inside
4560 * eval"") we have to resolve the ambiguity. This code
4561 * covers the case where the first term in the curlies is a
4562 * quoted string. Most other cases need to be explicitly
a0288114 4563 * disambiguated by prepending a "+" before the opening
b8a4b1be
GS
4564 * curly in order to force resolution as an anon hash.
4565 *
4566 * XXX should probably propagate the outer expectation
4567 * into eval"" to rely less on this hack, but that could
4568 * potentially break current behavior of eval"".
4569 * GSAR 97-07-21
4570 */
4571 t = s;
4572 if (*s == '\'' || *s == '"' || *s == '`') {
4573 /* common case: get past first string, handling escapes */
3280af22 4574 for (t++; t < PL_bufend && *t != *s;)
b8a4b1be
GS
4575 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4576 t++;
4577 t++;
a0d0e21e 4578 }
b8a4b1be 4579 else if (*s == 'q') {
3280af22 4580 if (++t < PL_bufend
b8a4b1be 4581 && (!isALNUM(*t)
3280af22 4582 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
0505442f
GS
4583 && !isALNUM(*t))))
4584 {
abc667d1 4585 /* skip q//-like construct */
f54cb97a 4586 const char *tmps;
b8a4b1be
GS
4587 char open, close, term;
4588 I32 brackets = 1;
4589
3280af22 4590 while (t < PL_bufend && isSPACE(*t))
b8a4b1be 4591 t++;
abc667d1
DM
4592 /* check for q => */
4593 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4594 OPERATOR(HASHBRACK);
4595 }
b8a4b1be
GS
4596 term = *t;
4597 open = term;
4598 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4599 term = tmps[5];
4600 close = term;
4601 if (open == close)
3280af22
NIS
4602 for (t++; t < PL_bufend; t++) {
4603 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
b8a4b1be 4604 t++;
6d07e5e9 4605 else if (*t == open)
b8a4b1be
GS
4606 break;
4607 }
abc667d1 4608 else {
3280af22
NIS
4609 for (t++; t < PL_bufend; t++) {
4610 if (*t == '\\' && t+1 < PL_bufend)
b8a4b1be 4611 t++;
6d07e5e9 4612 else if (*t == close && --brackets <= 0)
b8a4b1be
GS
4613 break;
4614 else if (*t == open)
4615 brackets++;
4616 }
abc667d1
DM
4617 }
4618 t++;
b8a4b1be 4619 }
abc667d1
DM
4620 else
4621 /* skip plain q word */
4622 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4623 t += UTF8SKIP(t);
a0d0e21e 4624 }
7e2040f0 4625 else if (isALNUM_lazy_if(t,UTF)) {
0505442f 4626 t += UTF8SKIP(t);
7e2040f0 4627 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
0505442f 4628 t += UTF8SKIP(t);
a0d0e21e 4629 }
3280af22 4630 while (t < PL_bufend && isSPACE(*t))
a0d0e21e 4631 t++;
b8a4b1be
GS
4632 /* if comma follows first term, call it an anon hash */
4633 /* XXX it could be a comma expression with loop modifiers */
3280af22 4634 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
b8a4b1be 4635 || (*t == '=' && t[1] == '>')))
a0d0e21e 4636 OPERATOR(HASHBRACK);
3280af22 4637 if (PL_expect == XREF)
4e4e412b 4638 PL_expect = XTERM;
a0d0e21e 4639 else {
3280af22
NIS
4640 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4641 PL_expect = XSTATE;
a0d0e21e 4642 }
8990e307 4643 }
a0d0e21e 4644 break;
463ee0b2 4645 }
6154021b 4646 pl_yylval.ival = CopLINE(PL_curcop);
79072805 4647 if (isSPACE(*s) || *s == '#')
3280af22 4648 PL_copline = NOLINE; /* invalidate current command line number */
79072805 4649 TOKEN('{');
378cc40b 4650 case '}':
79072805
LW
4651 rightbracket:
4652 s++;
3280af22 4653 if (PL_lex_brackets <= 0)
d98d5fff 4654 yyerror("Unmatched right curly bracket");
463ee0b2 4655 else
3280af22 4656 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
c2e66d9e 4657 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
3280af22
NIS
4658 PL_lex_formbrack = 0;
4659 if (PL_lex_state == LEX_INTERPNORMAL) {
4660 if (PL_lex_brackets == 0) {
9059aa12
LW
4661 if (PL_expect & XFAKEBRACK) {
4662 PL_expect &= XENUMMASK;
3280af22
NIS
4663 PL_lex_state = LEX_INTERPEND;
4664 PL_bufptr = s;
5db06880
NC
4665#if 0
4666 if (PL_madskills) {
cd81e915 4667 if (!PL_thiswhite)
6b29d1f5 4668 PL_thiswhite = newSVpvs("");
76f68e9b 4669 sv_catpvs(PL_thiswhite,"}");
5db06880
NC
4670 }
4671#endif
cea2e8a9 4672 return yylex(); /* ignore fake brackets */
79072805 4673 }
fa83b5b6 4674 if (*s == '-' && s[1] == '>')
3280af22 4675 PL_lex_state = LEX_INTERPENDMAYBE;
fa83b5b6 4676 else if (*s != '[' && *s != '{')
3280af22 4677 PL_lex_state = LEX_INTERPEND;
79072805
LW
4678 }
4679 }
9059aa12
LW
4680 if (PL_expect & XFAKEBRACK) {
4681 PL_expect &= XENUMMASK;
3280af22 4682 PL_bufptr = s;
cea2e8a9 4683 return yylex(); /* ignore fake brackets */
748a9306 4684 }
cd81e915 4685 start_force(PL_curforce);
5db06880
NC
4686 if (PL_madskills) {
4687 curmad('X', newSVpvn(s-1,1));
cd81e915 4688 CURMAD('_', PL_thiswhite);
5db06880 4689 }
79072805 4690 force_next('}');
5db06880 4691#ifdef PERL_MAD
cd81e915 4692 if (!PL_thistoken)
6b29d1f5 4693 PL_thistoken = newSVpvs("");
5db06880 4694#endif
79072805 4695 TOKEN(';');
378cc40b
LW
4696 case '&':
4697 s++;
90771dc0 4698 if (*s++ == '&')
a0d0e21e 4699 AOPERATOR(ANDAND);
378cc40b 4700 s--;
3280af22 4701 if (PL_expect == XOPERATOR) {
041457d9
DM
4702 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4703 && isIDFIRST_lazy_if(s,UTF))
7e2040f0 4704 {
57843af0 4705 CopLINE_dec(PL_curcop);
f1f66076 4706 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
57843af0 4707 CopLINE_inc(PL_curcop);
463ee0b2 4708 }
79072805 4709 BAop(OP_BIT_AND);
463ee0b2 4710 }
79072805 4711
3280af22
NIS
4712 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4713 if (*PL_tokenbuf) {
4714 PL_expect = XOPERATOR;
4715 force_ident(PL_tokenbuf, '&');
463ee0b2 4716 }
79072805
LW
4717 else
4718 PREREF('&');
6154021b 4719 pl_yylval.ival = (OPpENTERSUB_AMPER<<8);
79072805
LW
4720 TERM('&');
4721
378cc40b
LW
4722 case '|':
4723 s++;
90771dc0 4724 if (*s++ == '|')
a0d0e21e 4725 AOPERATOR(OROR);
378cc40b 4726 s--;
79072805 4727 BOop(OP_BIT_OR);
378cc40b
LW
4728 case '=':
4729 s++;
748a9306 4730 {
90771dc0
NC
4731 const char tmp = *s++;
4732 if (tmp == '=')
4733 Eop(OP_EQ);
4734 if (tmp == '>')
4735 OPERATOR(',');
4736 if (tmp == '~')
4737 PMop(OP_MATCH);
4738 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4739 && strchr("+-*/%.^&|<",tmp))
4740 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4741 "Reversed %c= operator",(int)tmp);
4742 s--;
4743 if (PL_expect == XSTATE && isALPHA(tmp) &&
4744 (s == PL_linestart+1 || s[-2] == '\n') )
4745 {
4746 if (PL_in_eval && !PL_rsfp) {
4747 d = PL_bufend;
4748 while (s < d) {
4749 if (*s++ == '\n') {
4750 incline(s);
4751 if (strnEQ(s,"=cut",4)) {
4752 s = strchr(s,'\n');
4753 if (s)
4754 s++;
4755 else
4756 s = d;
4757 incline(s);
4758 goto retry;
4759 }
4760 }
a5f75d66 4761 }
90771dc0 4762 goto retry;
a5f75d66 4763 }
5db06880
NC
4764#ifdef PERL_MAD
4765 if (PL_madskills) {
cd81e915 4766 if (!PL_thiswhite)
6b29d1f5 4767 PL_thiswhite = newSVpvs("");
cd81e915 4768 sv_catpvn(PL_thiswhite, PL_linestart,
5db06880
NC
4769 PL_bufend - PL_linestart);
4770 }
4771#endif
90771dc0
NC
4772 s = PL_bufend;
4773 PL_doextract = TRUE;
4774 goto retry;
a5f75d66 4775 }
a0d0e21e 4776 }
3280af22 4777 if (PL_lex_brackets < PL_lex_formbrack) {
c35e046a 4778 const char *t = s;
51882d45 4779#ifdef PERL_STRICT_CR
c35e046a 4780 while (SPACE_OR_TAB(*t))
51882d45 4781#else
c35e046a 4782 while (SPACE_OR_TAB(*t) || *t == '\r')
51882d45 4783#endif
c35e046a 4784 t++;
a0d0e21e
LW
4785 if (*t == '\n' || *t == '#') {
4786 s--;
3280af22 4787 PL_expect = XBLOCK;
a0d0e21e
LW
4788 goto leftbracket;
4789 }
79072805 4790 }
6154021b 4791 pl_yylval.ival = 0;
a0d0e21e 4792 OPERATOR(ASSIGNOP);
378cc40b
LW
4793 case '!':
4794 s++;
90771dc0
NC
4795 {
4796 const char tmp = *s++;
4797 if (tmp == '=') {
4798 /* was this !=~ where !~ was meant?
4799 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4800
4801 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4802 const char *t = s+1;
4803
4804 while (t < PL_bufend && isSPACE(*t))
4805 ++t;
4806
4807 if (*t == '/' || *t == '?' ||
4808 ((*t == 'm' || *t == 's' || *t == 'y')
4809 && !isALNUM(t[1])) ||
4810 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4811 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4812 "!=~ should be !~");
4813 }
4814 Eop(OP_NE);
4815 }
4816 if (tmp == '~')
4817 PMop(OP_NOT);
4818 }
378cc40b
LW
4819 s--;
4820 OPERATOR('!');
4821 case '<':
3280af22 4822 if (PL_expect != XOPERATOR) {
93a17b20 4823 if (s[1] != '<' && !strchr(s,'>'))
2f3197b3 4824 check_uni();
79072805
LW
4825 if (s[1] == '<')
4826 s = scan_heredoc(s);
4827 else
4828 s = scan_inputsymbol(s);
4829 TERM(sublex_start());
378cc40b
LW
4830 }
4831 s++;
90771dc0
NC
4832 {
4833 char tmp = *s++;
4834 if (tmp == '<')
4835 SHop(OP_LEFT_SHIFT);
4836 if (tmp == '=') {
4837 tmp = *s++;
4838 if (tmp == '>')
4839 Eop(OP_NCMP);
4840 s--;
4841 Rop(OP_LE);
4842 }
395c3793 4843 }
378cc40b 4844 s--;
79072805 4845 Rop(OP_LT);
378cc40b
LW
4846 case '>':
4847 s++;
90771dc0
NC
4848 {
4849 const char tmp = *s++;
4850 if (tmp == '>')
4851 SHop(OP_RIGHT_SHIFT);
d4c19fe8 4852 else if (tmp == '=')
90771dc0
NC
4853 Rop(OP_GE);
4854 }
378cc40b 4855 s--;
79072805 4856 Rop(OP_GT);
378cc40b
LW
4857
4858 case '$':
bbce6d69 4859 CLINE;
4860
3280af22
NIS
4861 if (PL_expect == XOPERATOR) {
4862 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4863 PL_expect = XTERM;
8ab8f082 4864 deprecate(commaless_variable_list);
bbf60fe6 4865 return REPORT(','); /* grandfather non-comma-format format */
a0d0e21e 4866 }
8990e307 4867 }
a0d0e21e 4868
7e2040f0 4869 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
3280af22 4870 PL_tokenbuf[0] = '@';
376b8730
SM
4871 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4872 sizeof PL_tokenbuf - 1, FALSE);
4873 if (PL_expect == XOPERATOR)
4874 no_op("Array length", s);
3280af22 4875 if (!PL_tokenbuf[1])
a0d0e21e 4876 PREREF(DOLSHARP);
3280af22
NIS
4877 PL_expect = XOPERATOR;
4878 PL_pending_ident = '#';
463ee0b2 4879 TOKEN(DOLSHARP);
79072805 4880 }
bbce6d69 4881
3280af22 4882 PL_tokenbuf[0] = '$';
376b8730
SM
4883 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4884 sizeof PL_tokenbuf - 1, FALSE);
4885 if (PL_expect == XOPERATOR)
4886 no_op("Scalar", s);
3280af22
NIS
4887 if (!PL_tokenbuf[1]) {
4888 if (s == PL_bufend)
bbce6d69 4889 yyerror("Final $ should be \\$ or $name");
4890 PREREF('$');
8990e307 4891 }
a0d0e21e 4892
bbce6d69 4893 /* This kludge not intended to be bulletproof. */
3280af22 4894 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
6154021b 4895 pl_yylval.opval = newSVOP(OP_CONST, 0,
fc15ae8f 4896 newSViv(CopARYBASE_get(&PL_compiling)));
6154021b 4897 pl_yylval.opval->op_private = OPpCONST_ARYBASE;
bbce6d69 4898 TERM(THING);
4899 }
4900
ff68c719 4901 d = s;
90771dc0
NC
4902 {
4903 const char tmp = *s;
4904 if (PL_lex_state == LEX_NORMAL)
29595ff2 4905 s = SKIPSPACE1(s);
ff68c719 4906
90771dc0
NC
4907 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4908 && intuit_more(s)) {
4909 if (*s == '[') {
4910 PL_tokenbuf[0] = '@';
4911 if (ckWARN(WARN_SYNTAX)) {
c35e046a
AL
4912 char *t = s+1;
4913
4914 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4915 t++;
90771dc0 4916 if (*t++ == ',') {
29595ff2 4917 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
90771dc0
NC
4918 while (t < PL_bufend && *t != ']')
4919 t++;
9014280d 4920 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
90771dc0 4921 "Multidimensional syntax %.*s not supported",
36c7798d 4922 (int)((t - PL_bufptr) + 1), PL_bufptr);
90771dc0 4923 }
748a9306 4924 }
93a17b20 4925 }
90771dc0
NC
4926 else if (*s == '{') {
4927 char *t;
4928 PL_tokenbuf[0] = '%';
4929 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4930 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4931 {
4932 char tmpbuf[sizeof PL_tokenbuf];
c35e046a
AL
4933 do {
4934 t++;
4935 } while (isSPACE(*t));
90771dc0 4936 if (isIDFIRST_lazy_if(t,UTF)) {
780a5241 4937 STRLEN len;
90771dc0 4938 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
780a5241 4939 &len);
c35e046a
AL
4940 while (isSPACE(*t))
4941 t++;
780a5241 4942 if (*t == ';' && get_cvn_flags(tmpbuf, len, 0))
90771dc0
NC
4943 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4944 "You need to quote \"%s\"",
4945 tmpbuf);
4946 }
4947 }
4948 }
93a17b20 4949 }
bbce6d69 4950
90771dc0
NC
4951 PL_expect = XOPERATOR;
4952 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4953 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4954 if (!islop || PL_last_lop_op == OP_GREPSTART)
4955 PL_expect = XOPERATOR;
4956 else if (strchr("$@\"'`q", *s))
4957 PL_expect = XTERM; /* e.g. print $fh "foo" */
4958 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4959 PL_expect = XTERM; /* e.g. print $fh &sub */
4960 else if (isIDFIRST_lazy_if(s,UTF)) {
4961 char tmpbuf[sizeof PL_tokenbuf];
4962 int t2;
4963 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5458a98a 4964 if ((t2 = keyword(tmpbuf, len, 0))) {
90771dc0
NC
4965 /* binary operators exclude handle interpretations */
4966 switch (t2) {
4967 case -KEY_x:
4968 case -KEY_eq:
4969 case -KEY_ne:
4970 case -KEY_gt:
4971 case -KEY_lt:
4972 case -KEY_ge:
4973 case -KEY_le:
4974 case -KEY_cmp:
4975 break;
4976 default:
4977 PL_expect = XTERM; /* e.g. print $fh length() */
4978 break;
4979 }
4980 }
4981 else {
4982 PL_expect = XTERM; /* e.g. print $fh subr() */
84902520
TB
4983 }
4984 }
90771dc0
NC
4985 else if (isDIGIT(*s))
4986 PL_expect = XTERM; /* e.g. print $fh 3 */
4987 else if (*s == '.' && isDIGIT(s[1]))
4988 PL_expect = XTERM; /* e.g. print $fh .3 */
4989 else if ((*s == '?' || *s == '-' || *s == '+')
4990 && !isSPACE(s[1]) && s[1] != '=')
4991 PL_expect = XTERM; /* e.g. print $fh -1 */
4992 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4993 && s[1] != '/')
4994 PL_expect = XTERM; /* e.g. print $fh /.../
4995 XXX except DORDOR operator
4996 */
4997 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4998 && s[2] != '=')
4999 PL_expect = XTERM; /* print $fh <<"EOF" */
93a17b20 5000 }
bbce6d69 5001 }
3280af22 5002 PL_pending_ident = '$';
79072805 5003 TOKEN('$');
378cc40b
LW
5004
5005 case '@':
3280af22 5006 if (PL_expect == XOPERATOR)
bbce6d69 5007 no_op("Array", s);
3280af22
NIS
5008 PL_tokenbuf[0] = '@';
5009 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
5010 if (!PL_tokenbuf[1]) {
bbce6d69 5011 PREREF('@');
5012 }
3280af22 5013 if (PL_lex_state == LEX_NORMAL)
29595ff2 5014 s = SKIPSPACE1(s);
3280af22 5015 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
bbce6d69 5016 if (*s == '{')
3280af22 5017 PL_tokenbuf[0] = '%';
a0d0e21e
LW
5018
5019 /* Warn about @ where they meant $. */
041457d9
DM
5020 if (*s == '[' || *s == '{') {
5021 if (ckWARN(WARN_SYNTAX)) {
f54cb97a 5022 const char *t = s + 1;
7e2040f0 5023 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
a0d0e21e
LW
5024 t++;
5025 if (*t == '}' || *t == ']') {
5026 t++;
29595ff2 5027 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
9014280d 5028 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
599cee73 5029 "Scalar value %.*s better written as $%.*s",
36c7798d
DM
5030 (int)(t-PL_bufptr), PL_bufptr,
5031 (int)(t-PL_bufptr-1), PL_bufptr+1);
a0d0e21e 5032 }
93a17b20
LW
5033 }
5034 }
463ee0b2 5035 }
3280af22 5036 PL_pending_ident = '@';
79072805 5037 TERM('@');
378cc40b 5038
c963b151 5039 case '/': /* may be division, defined-or, or pattern */
6f33ba73
RGS
5040 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
5041 s += 2;
5042 AOPERATOR(DORDOR);
5043 }
c963b151 5044 case '?': /* may either be conditional or pattern */
be25f609 5045 if (PL_expect == XOPERATOR) {
90771dc0 5046 char tmp = *s++;
c963b151 5047 if(tmp == '?') {
be25f609 5048 OPERATOR('?');
c963b151
BD
5049 }
5050 else {
5051 tmp = *s++;
5052 if(tmp == '/') {
5053 /* A // operator. */
5054 AOPERATOR(DORDOR);
5055 }
5056 else {
5057 s--;
5058 Mop(OP_DIVIDE);
5059 }
5060 }
5061 }
5062 else {
5063 /* Disable warning on "study /blah/" */
5064 if (PL_oldoldbufptr == PL_last_uni
5065 && (*PL_last_uni != 's' || s - PL_last_uni < 5
5066 || memNE(PL_last_uni, "study", 5)
5067 || isALNUM_lazy_if(PL_last_uni+5,UTF)
5068 ))
5069 check_uni();
5070 s = scan_pat(s,OP_MATCH);
5071 TERM(sublex_start());
5072 }
378cc40b
LW
5073
5074 case '.':
51882d45
GS
5075 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
5076#ifdef PERL_STRICT_CR
5077 && s[1] == '\n'
5078#else
5079 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
5080#endif
5081 && (s == PL_linestart || s[-1] == '\n') )
5082 {
3280af22
NIS
5083 PL_lex_formbrack = 0;
5084 PL_expect = XSTATE;
79072805
LW
5085 goto rightbracket;
5086 }
be25f609 5087 if (PL_expect == XSTATE && s[1] == '.' && s[2] == '.') {
5088 s += 3;
5089 OPERATOR(YADAYADA);
5090 }
3280af22 5091 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
90771dc0 5092 char tmp = *s++;
a687059c
LW
5093 if (*s == tmp) {
5094 s++;
2f3197b3
LW
5095 if (*s == tmp) {
5096 s++;
6154021b 5097 pl_yylval.ival = OPf_SPECIAL;
2f3197b3
LW
5098 }
5099 else
6154021b 5100 pl_yylval.ival = 0;
378cc40b 5101 OPERATOR(DOTDOT);
a687059c 5102 }
3280af22 5103 if (PL_expect != XOPERATOR)
2f3197b3 5104 check_uni();
79072805 5105 Aop(OP_CONCAT);
378cc40b
LW
5106 }
5107 /* FALL THROUGH */
5108 case '0': case '1': case '2': case '3': case '4':
5109 case '5': case '6': case '7': case '8': case '9':
6154021b 5110 s = scan_num(s, &pl_yylval);
931e0695 5111 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
3280af22 5112 if (PL_expect == XOPERATOR)
8990e307 5113 no_op("Number",s);
79072805
LW
5114 TERM(THING);
5115
5116 case '\'':
5db06880 5117 s = scan_str(s,!!PL_madskills,FALSE);
931e0695 5118 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
3280af22
NIS
5119 if (PL_expect == XOPERATOR) {
5120 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5121 PL_expect = XTERM;
8ab8f082 5122 deprecate(commaless_variable_list);
bbf60fe6 5123 return REPORT(','); /* grandfather non-comma-format format */
a0d0e21e 5124 }
463ee0b2 5125 else
8990e307 5126 no_op("String",s);
463ee0b2 5127 }
79072805 5128 if (!s)
d4c19fe8 5129 missingterm(NULL);
6154021b 5130 pl_yylval.ival = OP_CONST;
79072805
LW
5131 TERM(sublex_start());
5132
5133 case '"':
5db06880 5134 s = scan_str(s,!!PL_madskills,FALSE);
931e0695 5135 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
3280af22
NIS
5136 if (PL_expect == XOPERATOR) {
5137 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5138 PL_expect = XTERM;
8ab8f082 5139 deprecate(commaless_variable_list);
bbf60fe6 5140 return REPORT(','); /* grandfather non-comma-format format */
a0d0e21e 5141 }
463ee0b2 5142 else
8990e307 5143 no_op("String",s);
463ee0b2 5144 }
79072805 5145 if (!s)
d4c19fe8 5146 missingterm(NULL);
6154021b 5147 pl_yylval.ival = OP_CONST;
cfd0369c
NC
5148 /* FIXME. I think that this can be const if char *d is replaced by
5149 more localised variables. */
3280af22 5150 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
63cd0674 5151 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
6154021b 5152 pl_yylval.ival = OP_STRINGIFY;
4633a7c4
LW
5153 break;
5154 }
5155 }
79072805
LW
5156 TERM(sublex_start());
5157
5158 case '`':
5db06880 5159 s = scan_str(s,!!PL_madskills,FALSE);
931e0695 5160 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
3280af22 5161 if (PL_expect == XOPERATOR)
8990e307 5162 no_op("Backticks",s);
79072805 5163 if (!s)
d4c19fe8 5164 missingterm(NULL);
9b201d7d 5165 readpipe_override();
79072805
LW
5166 TERM(sublex_start());
5167
5168 case '\\':
5169 s++;
a2a5de95
NC
5170 if (PL_lex_inwhat && isDIGIT(*s))
5171 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
5172 *s, *s);
3280af22 5173 if (PL_expect == XOPERATOR)
8990e307 5174 no_op("Backslash",s);
79072805
LW
5175 OPERATOR(REFGEN);
5176
a7cb1f99 5177 case 'v':
e526c9e6 5178 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
f54cb97a 5179 char *start = s + 2;
dd629d5b 5180 while (isDIGIT(*start) || *start == '_')
a7cb1f99
GS
5181 start++;
5182 if (*start == '.' && isDIGIT(start[1])) {
6154021b 5183 s = scan_num(s, &pl_yylval);
a7cb1f99
GS
5184 TERM(THING);
5185 }
e526c9e6 5186 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
6f33ba73
RGS
5187 else if (!isALPHA(*start) && (PL_expect == XTERM
5188 || PL_expect == XREF || PL_expect == XSTATE
5189 || PL_expect == XTERMORDORDOR)) {
9bde8eb0 5190 GV *const gv = gv_fetchpvn_flags(s, start - s, 0, SVt_PVCV);
e526c9e6 5191 if (!gv) {
6154021b 5192 s = scan_num(s, &pl_yylval);
e526c9e6
GS
5193 TERM(THING);
5194 }
5195 }
a7cb1f99
GS
5196 }
5197 goto keylookup;
79072805 5198 case 'x':
3280af22 5199 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
79072805
LW
5200 s++;
5201 Mop(OP_REPEAT);
2f3197b3 5202 }
79072805
LW
5203 goto keylookup;
5204
378cc40b 5205 case '_':
79072805
LW
5206 case 'a': case 'A':
5207 case 'b': case 'B':
5208 case 'c': case 'C':
5209 case 'd': case 'D':
5210 case 'e': case 'E':
5211 case 'f': case 'F':
5212 case 'g': case 'G':
5213 case 'h': case 'H':
5214 case 'i': case 'I':
5215 case 'j': case 'J':
5216 case 'k': case 'K':
5217 case 'l': case 'L':
5218 case 'm': case 'M':
5219 case 'n': case 'N':
5220 case 'o': case 'O':
5221 case 'p': case 'P':
5222 case 'q': case 'Q':
5223 case 'r': case 'R':
5224 case 's': case 'S':
5225 case 't': case 'T':
5226 case 'u': case 'U':
a7cb1f99 5227 case 'V':
79072805
LW
5228 case 'w': case 'W':
5229 case 'X':
5230 case 'y': case 'Y':
5231 case 'z': case 'Z':
5232
49dc05e3 5233 keylookup: {
90771dc0 5234 I32 tmp;
10edeb5d
JH
5235
5236 orig_keyword = 0;
5237 gv = NULL;
5238 gvp = NULL;
49dc05e3 5239
3280af22
NIS
5240 PL_bufptr = s;
5241 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
8ebc5c01 5242
5243 /* Some keywords can be followed by any delimiter, including ':' */
155aba94
GS
5244 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
5245 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
5246 (PL_tokenbuf[0] == 'q' &&
5247 strchr("qwxr", PL_tokenbuf[1])))));
8ebc5c01 5248
5249 /* x::* is just a word, unless x is "CORE" */
3280af22 5250 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
4633a7c4
LW
5251 goto just_a_word;
5252
3643fb5f 5253 d = s;
3280af22 5254 while (d < PL_bufend && isSPACE(*d))
3643fb5f
CS
5255 d++; /* no comments skipped here, or s### is misparsed */
5256
5257 /* Is this a label? */
3280af22
NIS
5258 if (!tmp && PL_expect == XSTATE
5259 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
28ccebc4
RGS
5260 tmp = keyword(PL_tokenbuf, len, 0);
5261 if (tmp)
5262 Perl_croak(aTHX_ "Can't use keyword '%s' as a label", PL_tokenbuf);
8ebc5c01 5263 s = d + 1;
6154021b 5264 pl_yylval.pval = CopLABEL_alloc(PL_tokenbuf);
8ebc5c01 5265 CLINE;
5266 TOKEN(LABEL);
3643fb5f 5267 }
28ccebc4
RGS
5268 else
5269 /* Check for keywords */
5270 tmp = keyword(PL_tokenbuf, len, 0);
3643fb5f 5271
748a9306 5272 /* Is this a word before a => operator? */
1c3923b3 5273 if (*d == '=' && d[1] == '>') {
748a9306 5274 CLINE;
6154021b 5275 pl_yylval.opval
d0a148a6
NC
5276 = (OP*)newSVOP(OP_CONST, 0,
5277 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
6154021b 5278 pl_yylval.opval->op_private = OPpCONST_BARE;
748a9306
LW
5279 TERM(WORD);
5280 }
5281
a0d0e21e 5282 if (tmp < 0) { /* second-class keyword? */
cbbf8932
AL
5283 GV *ogv = NULL; /* override (winner) */
5284 GV *hgv = NULL; /* hidden (loser) */
3280af22 5285 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
56f7f34b 5286 CV *cv;
90e5519e 5287 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
56f7f34b
CS
5288 (cv = GvCVu(gv)))
5289 {
5290 if (GvIMPORTED_CV(gv))
5291 ogv = gv;
5292 else if (! CvMETHOD(cv))
5293 hgv = gv;
5294 }
5295 if (!ogv &&
3280af22 5296 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
9e0d86f8 5297 (gv = *gvp) && isGV_with_GP(gv) &&
56f7f34b
CS
5298 GvCVu(gv) && GvIMPORTED_CV(gv))
5299 {
5300 ogv = gv;
5301 }
5302 }
5303 if (ogv) {
30fe34ed 5304 orig_keyword = tmp;
56f7f34b 5305 tmp = 0; /* overridden by import or by GLOBAL */
6e7b2336
GS
5306 }
5307 else if (gv && !gvp
5308 && -tmp==KEY_lock /* XXX generalizable kludge */
47f9f84c 5309 && GvCVu(gv))
6e7b2336
GS
5310 {
5311 tmp = 0; /* any sub overrides "weak" keyword */
a0d0e21e 5312 }
56f7f34b
CS
5313 else { /* no override */
5314 tmp = -tmp;
a2a5de95
NC
5315 if (tmp == KEY_dump) {
5316 Perl_ck_warner(aTHX_ packWARN(WARN_MISC),
5317 "dump() better written as CORE::dump()");
ac206dc8 5318 }
a0714e2c 5319 gv = NULL;
56f7f34b 5320 gvp = 0;
a2a5de95
NC
5321 if (hgv && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */
5322 Perl_ck_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5323 "Ambiguous call resolved as CORE::%s(), %s",
5324 GvENAME(hgv), "qualify as such or use &");
49dc05e3 5325 }
a0d0e21e
LW
5326 }
5327
5328 reserved_word:
5329 switch (tmp) {
79072805
LW
5330
5331 default: /* not a keyword */
0bfa2a8a
NC
5332 /* Trade off - by using this evil construction we can pull the
5333 variable gv into the block labelled keylookup. If not, then
5334 we have to give it function scope so that the goto from the
5335 earlier ':' case doesn't bypass the initialisation. */
5336 if (0) {
5337 just_a_word_zero_gv:
5338 gv = NULL;
5339 gvp = NULL;
8bee0991 5340 orig_keyword = 0;
0bfa2a8a 5341 }
93a17b20 5342 just_a_word: {
96e4d5b1 5343 SV *sv;
ce29ac45 5344 int pkgname = 0;
f54cb97a 5345 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5069cc75 5346 CV *cv;
5db06880 5347#ifdef PERL_MAD
cd81e915 5348 SV *nextPL_nextwhite = 0;
5db06880
NC
5349#endif
5350
8990e307
LW
5351
5352 /* Get the rest if it looks like a package qualifier */
5353
155aba94 5354 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
c3e0f903 5355 STRLEN morelen;
3280af22 5356 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
c3e0f903
GS
5357 TRUE, &morelen);
5358 if (!morelen)
cea2e8a9 5359 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
ec2ab091 5360 *s == '\'' ? "'" : "::");
c3e0f903 5361 len += morelen;
ce29ac45 5362 pkgname = 1;
a0d0e21e 5363 }
8990e307 5364
3280af22
NIS
5365 if (PL_expect == XOPERATOR) {
5366 if (PL_bufptr == PL_linestart) {
57843af0 5367 CopLINE_dec(PL_curcop);
f1f66076 5368 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
57843af0 5369 CopLINE_inc(PL_curcop);
463ee0b2
LW
5370 }
5371 else
54310121 5372 no_op("Bareword",s);
463ee0b2 5373 }
8990e307 5374
c3e0f903
GS
5375 /* Look for a subroutine with this name in current package,
5376 unless name is "Foo::", in which case Foo is a bearword
5377 (and a package name). */
5378
5db06880 5379 if (len > 2 && !PL_madskills &&
3280af22 5380 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
c3e0f903 5381 {
f776e3cd 5382 if (ckWARN(WARN_BAREWORD)
90e5519e 5383 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
9014280d 5384 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
599cee73 5385 "Bareword \"%s\" refers to nonexistent package",
3280af22 5386 PL_tokenbuf);
c3e0f903 5387 len -= 2;
3280af22 5388 PL_tokenbuf[len] = '\0';
a0714e2c 5389 gv = NULL;
c3e0f903
GS
5390 gvp = 0;
5391 }
5392 else {
62d55b22
NC
5393 if (!gv) {
5394 /* Mustn't actually add anything to a symbol table.
5395 But also don't want to "initialise" any placeholder
5396 constants that might already be there into full
5397 blown PVGVs with attached PVCV. */
90e5519e
NC
5398 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5399 GV_NOADD_NOINIT, SVt_PVCV);
62d55b22 5400 }
b3d904f3 5401 len = 0;
c3e0f903
GS
5402 }
5403
5404 /* if we saw a global override before, get the right name */
8990e307 5405
49dc05e3 5406 if (gvp) {
396482e1 5407 sv = newSVpvs("CORE::GLOBAL::");
3280af22 5408 sv_catpv(sv,PL_tokenbuf);
49dc05e3 5409 }
8a7a129d
NC
5410 else {
5411 /* If len is 0, newSVpv does strlen(), which is correct.
5412 If len is non-zero, then it will be the true length,
5413 and so the scalar will be created correctly. */
5414 sv = newSVpv(PL_tokenbuf,len);
5415 }
5db06880 5416#ifdef PERL_MAD
cd81e915
NC
5417 if (PL_madskills && !PL_thistoken) {
5418 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
9ff8e806 5419 PL_thistoken = newSVpvn(start,s - start);
cd81e915 5420 PL_realtokenstart = s - SvPVX(PL_linestr);
5db06880
NC
5421 }
5422#endif
8990e307 5423
a0d0e21e
LW
5424 /* Presume this is going to be a bareword of some sort. */
5425
5426 CLINE;
6154021b
RGS
5427 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5428 pl_yylval.opval->op_private = OPpCONST_BARE;
8f8cf39c
JH
5429 /* UTF-8 package name? */
5430 if (UTF && !IN_BYTES &&
95a20fc0 5431 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
8f8cf39c 5432 SvUTF8_on(sv);
a0d0e21e 5433
c3e0f903
GS
5434 /* And if "Foo::", then that's what it certainly is. */
5435
5436 if (len)
5437 goto safe_bareword;
5438
5069cc75
NC
5439 /* Do the explicit type check so that we don't need to force
5440 the initialisation of the symbol table to have a real GV.
5441 Beware - gv may not really be a PVGV, cv may not really be
5442 a PVCV, (because of the space optimisations that gv_init
5443 understands) But they're true if for this symbol there is
5444 respectively a typeglob and a subroutine.
5445 */
5446 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5447 /* Real typeglob, so get the real subroutine: */
5448 ? GvCVu(gv)
5449 /* A proxy for a subroutine in this package? */
ea726b52 5450 : SvOK(gv) ? MUTABLE_CV(gv) : NULL)
5069cc75
NC
5451 : NULL;
5452
8990e307
LW
5453 /* See if it's the indirect object for a list operator. */
5454
3280af22
NIS
5455 if (PL_oldoldbufptr &&
5456 PL_oldoldbufptr < PL_bufptr &&
65cec589
GS
5457 (PL_oldoldbufptr == PL_last_lop
5458 || PL_oldoldbufptr == PL_last_uni) &&
a0d0e21e 5459 /* NO SKIPSPACE BEFORE HERE! */
a9ef352a
GS
5460 (PL_expect == XREF ||
5461 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
a0d0e21e 5462 {
748a9306
LW
5463 bool immediate_paren = *s == '(';
5464
a0d0e21e 5465 /* (Now we can afford to cross potential line boundary.) */
cd81e915 5466 s = SKIPSPACE2(s,nextPL_nextwhite);
5db06880 5467#ifdef PERL_MAD
cd81e915 5468 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5db06880 5469#endif
a0d0e21e
LW
5470
5471 /* Two barewords in a row may indicate method call. */
5472
62d55b22
NC
5473 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5474 (tmp = intuit_method(s, gv, cv)))
bbf60fe6 5475 return REPORT(tmp);
a0d0e21e
LW
5476
5477 /* If not a declared subroutine, it's an indirect object. */
5478 /* (But it's an indir obj regardless for sort.) */
7294df96 5479 /* Also, if "_" follows a filetest operator, it's a bareword */
a0d0e21e 5480
7294df96
RGS
5481 if (
5482 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5069cc75 5483 ((!gv || !cv) &&
a9ef352a 5484 (PL_last_lop_op != OP_MAPSTART &&
f0670693 5485 PL_last_lop_op != OP_GREPSTART))))
7294df96
RGS
5486 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5487 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5488 )
a9ef352a 5489 {
3280af22 5490 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
748a9306 5491 goto bareword;
93a17b20
LW
5492 }
5493 }
8990e307 5494
3280af22 5495 PL_expect = XOPERATOR;
5db06880
NC
5496#ifdef PERL_MAD
5497 if (isSPACE(*s))
cd81e915
NC
5498 s = SKIPSPACE2(s,nextPL_nextwhite);
5499 PL_nextwhite = nextPL_nextwhite;
5db06880 5500#else
8990e307 5501 s = skipspace(s);
5db06880 5502#endif
1c3923b3
GS
5503
5504 /* Is this a word before a => operator? */
ce29ac45 5505 if (*s == '=' && s[1] == '>' && !pkgname) {
1c3923b3 5506 CLINE;
6154021b 5507 sv_setpv(((SVOP*)pl_yylval.opval)->op_sv, PL_tokenbuf);
0064a8a9 5508 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
6154021b 5509 SvUTF8_on(((SVOP*)pl_yylval.opval)->op_sv);
1c3923b3
GS
5510 TERM(WORD);
5511 }
5512
5513 /* If followed by a paren, it's certainly a subroutine. */
93a17b20 5514 if (*s == '(') {
79072805 5515 CLINE;
5069cc75 5516 if (cv) {
c35e046a
AL
5517 d = s + 1;
5518 while (SPACE_OR_TAB(*d))
5519 d++;
62d55b22 5520 if (*d == ')' && (sv = gv_const_sv(gv))) {
96e4d5b1 5521 s = d + 1;
c631f32b 5522 goto its_constant;
96e4d5b1 5523 }
5524 }
5db06880
NC
5525#ifdef PERL_MAD
5526 if (PL_madskills) {
cd81e915
NC
5527 PL_nextwhite = PL_thiswhite;
5528 PL_thiswhite = 0;
5db06880 5529 }
cd81e915 5530 start_force(PL_curforce);
5db06880 5531#endif
6154021b 5532 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
3280af22 5533 PL_expect = XOPERATOR;
5db06880
NC
5534#ifdef PERL_MAD
5535 if (PL_madskills) {
cd81e915
NC
5536 PL_nextwhite = nextPL_nextwhite;
5537 curmad('X', PL_thistoken);
6b29d1f5 5538 PL_thistoken = newSVpvs("");
5db06880
NC
5539 }
5540#endif
93a17b20 5541 force_next(WORD);
6154021b 5542 pl_yylval.ival = 0;
463ee0b2 5543 TOKEN('&');
79072805 5544 }
93a17b20 5545
a0d0e21e 5546 /* If followed by var or block, call it a method (unless sub) */
8990e307 5547
62d55b22 5548 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
3280af22
NIS
5549 PL_last_lop = PL_oldbufptr;
5550 PL_last_lop_op = OP_METHOD;
93a17b20 5551 PREBLOCK(METHOD);
463ee0b2
LW
5552 }
5553
8990e307
LW
5554 /* If followed by a bareword, see if it looks like indir obj. */
5555
30fe34ed
RGS
5556 if (!orig_keyword
5557 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
62d55b22 5558 && (tmp = intuit_method(s, gv, cv)))
bbf60fe6 5559 return REPORT(tmp);
93a17b20 5560
8990e307
LW
5561 /* Not a method, so call it a subroutine (if defined) */
5562
5069cc75 5563 if (cv) {
9b387841
NC
5564 if (lastchar == '-')
5565 Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
5566 "Ambiguous use of -%s resolved as -&%s()",
5567 PL_tokenbuf, PL_tokenbuf);
89bfa8cd 5568 /* Check for a constant sub */
c631f32b 5569 if ((sv = gv_const_sv(gv))) {
96e4d5b1 5570 its_constant:
6154021b
RGS
5571 SvREFCNT_dec(((SVOP*)pl_yylval.opval)->op_sv);
5572 ((SVOP*)pl_yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5573 pl_yylval.opval->op_private = 0;
96e4d5b1 5574 TOKEN(WORD);
89bfa8cd 5575 }
5576
a5f75d66 5577 /* Resolve to GV now. */
62d55b22 5578 if (SvTYPE(gv) != SVt_PVGV) {
b3d904f3 5579 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
62d55b22
NC
5580 assert (SvTYPE(gv) == SVt_PVGV);
5581 /* cv must have been some sort of placeholder, so
5582 now needs replacing with a real code reference. */
5583 cv = GvCV(gv);
5584 }
5585
6154021b
RGS
5586 op_free(pl_yylval.opval);
5587 pl_yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5588 pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
7a52d87a 5589 PL_last_lop = PL_oldbufptr;
bf848113 5590 PL_last_lop_op = OP_ENTERSUB;
4633a7c4 5591 /* Is there a prototype? */
5db06880
NC
5592 if (
5593#ifdef PERL_MAD
5594 cv &&
5595#endif
d9f2850e
RGS
5596 SvPOK(cv))
5597 {
5f66b61c 5598 STRLEN protolen;
daba3364 5599 const char *proto = SvPV_const(MUTABLE_SV(cv), protolen);
5f66b61c 5600 if (!protolen)
4633a7c4 5601 TERM(FUNC0SUB);
8c28b960 5602 if ((*proto == '$' || *proto == '_') && proto[1] == '\0')
4633a7c4 5603 OPERATOR(UNIOPSUB);
0f5d0394
AE
5604 while (*proto == ';')
5605 proto++;
7a52d87a 5606 if (*proto == '&' && *s == '{') {
49a54bbe
NC
5607 if (PL_curstash)
5608 sv_setpvs(PL_subname, "__ANON__");
5609 else
5610 sv_setpvs(PL_subname, "__ANON__::__ANON__");
4633a7c4
LW
5611 PREBLOCK(LSTOPSUB);
5612 }
a9ef352a 5613 }
5db06880
NC
5614#ifdef PERL_MAD
5615 {
5616 if (PL_madskills) {
cd81e915
NC
5617 PL_nextwhite = PL_thiswhite;
5618 PL_thiswhite = 0;
5db06880 5619 }
cd81e915 5620 start_force(PL_curforce);
6154021b 5621 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
5db06880
NC
5622 PL_expect = XTERM;
5623 if (PL_madskills) {
cd81e915
NC
5624 PL_nextwhite = nextPL_nextwhite;
5625 curmad('X', PL_thistoken);
6b29d1f5 5626 PL_thistoken = newSVpvs("");
5db06880
NC
5627 }
5628 force_next(WORD);
5629 TOKEN(NOAMP);
5630 }
5631 }
5632
5633 /* Guess harder when madskills require "best effort". */
5634 if (PL_madskills && (!gv || !GvCVu(gv))) {
5635 int probable_sub = 0;
5636 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5637 probable_sub = 1;
5638 else if (isALPHA(*s)) {
5639 char tmpbuf[1024];
5640 STRLEN tmplen;
5641 d = s;
5642 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5458a98a 5643 if (!keyword(tmpbuf, tmplen, 0))
5db06880
NC
5644 probable_sub = 1;
5645 else {
5646 while (d < PL_bufend && isSPACE(*d))
5647 d++;
5648 if (*d == '=' && d[1] == '>')
5649 probable_sub = 1;
5650 }
5651 }
5652 if (probable_sub) {
7a6d04f4 5653 gv = gv_fetchpv(PL_tokenbuf, GV_ADD, SVt_PVCV);
6154021b
RGS
5654 op_free(pl_yylval.opval);
5655 pl_yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5656 pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5db06880
NC
5657 PL_last_lop = PL_oldbufptr;
5658 PL_last_lop_op = OP_ENTERSUB;
cd81e915
NC
5659 PL_nextwhite = PL_thiswhite;
5660 PL_thiswhite = 0;
5661 start_force(PL_curforce);
6154021b 5662 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
5db06880 5663 PL_expect = XTERM;
cd81e915
NC
5664 PL_nextwhite = nextPL_nextwhite;
5665 curmad('X', PL_thistoken);
6b29d1f5 5666 PL_thistoken = newSVpvs("");
5db06880
NC
5667 force_next(WORD);
5668 TOKEN(NOAMP);
5669 }
5670#else
6154021b 5671 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
3280af22 5672 PL_expect = XTERM;
8990e307
LW
5673 force_next(WORD);
5674 TOKEN(NOAMP);
5db06880 5675#endif
8990e307 5676 }
748a9306 5677
8990e307
LW
5678 /* Call it a bare word */
5679
5603f27d 5680 if (PL_hints & HINT_STRICT_SUBS)
6154021b 5681 pl_yylval.opval->op_private |= OPpCONST_STRICT;
5603f27d 5682 else {
9a073a1d
RGS
5683 bareword:
5684 /* after "print" and similar functions (corresponding to
5685 * "F? L" in opcode.pl), whatever wasn't already parsed as
5686 * a filehandle should be subject to "strict subs".
5687 * Likewise for the optional indirect-object argument to system
5688 * or exec, which can't be a bareword */
5689 if ((PL_last_lop_op == OP_PRINT
5690 || PL_last_lop_op == OP_PRTF
5691 || PL_last_lop_op == OP_SAY
5692 || PL_last_lop_op == OP_SYSTEM
5693 || PL_last_lop_op == OP_EXEC)
5694 && (PL_hints & HINT_STRICT_SUBS))
5695 pl_yylval.opval->op_private |= OPpCONST_STRICT;
041457d9
DM
5696 if (lastchar != '-') {
5697 if (ckWARN(WARN_RESERVED)) {
c35e046a
AL
5698 d = PL_tokenbuf;
5699 while (isLOWER(*d))
5700 d++;
da51bb9b 5701 if (!*d && !gv_stashpv(PL_tokenbuf, 0))
9014280d 5702 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5603f27d
GS
5703 PL_tokenbuf);
5704 }
748a9306
LW
5705 }
5706 }
c3e0f903
GS
5707
5708 safe_bareword:
9b387841
NC
5709 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')) {
5710 Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
5711 "Operator or semicolon missing before %c%s",
5712 lastchar, PL_tokenbuf);
5713 Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
5714 "Ambiguous use of %c resolved as operator %c",
5715 lastchar, lastchar);
748a9306 5716 }
93a17b20 5717 TOKEN(WORD);
79072805 5718 }
79072805 5719
68dc0745 5720 case KEY___FILE__:
6154021b 5721 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
ed094faf 5722 newSVpv(CopFILE(PL_curcop),0));
46fc3d4c 5723 TERM(THING);
5724
79072805 5725 case KEY___LINE__:
6154021b 5726 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
57843af0 5727 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
79072805 5728 TERM(THING);
68dc0745 5729
5730 case KEY___PACKAGE__:
6154021b 5731 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
3280af22 5732 (PL_curstash
5aaec2b4 5733 ? newSVhek(HvNAME_HEK(PL_curstash))
3280af22 5734 : &PL_sv_undef));
79072805 5735 TERM(THING);
79072805 5736
e50aee73 5737 case KEY___DATA__:
79072805
LW
5738 case KEY___END__: {
5739 GV *gv;
3280af22 5740 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
bfed75c6 5741 const char *pname = "main";
3280af22 5742 if (PL_tokenbuf[2] == 'D')
bfcb3514 5743 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
f776e3cd
NC
5744 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5745 SVt_PVIO);
a5f75d66 5746 GvMULTI_on(gv);
79072805 5747 if (!GvIO(gv))
a0d0e21e 5748 GvIOp(gv) = newIO();
3280af22 5749 IoIFP(GvIOp(gv)) = PL_rsfp;
a0d0e21e
LW
5750#if defined(HAS_FCNTL) && defined(F_SETFD)
5751 {
f54cb97a 5752 const int fd = PerlIO_fileno(PL_rsfp);
a0d0e21e
LW
5753 fcntl(fd,F_SETFD,fd >= 3);
5754 }
79072805 5755#endif
fd049845 5756 /* Mark this internal pseudo-handle as clean */
5757 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
4c84d7f2 5758 if ((PerlIO*)PL_rsfp == PerlIO_stdin())
50952442 5759 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
79072805 5760 else
50952442 5761 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
c39cd008
GS
5762#if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5763 /* if the script was opened in binmode, we need to revert
53129d29 5764 * it to text mode for compatibility; but only iff it has CRs
c39cd008 5765 * XXX this is a questionable hack at best. */
53129d29
GS
5766 if (PL_bufend-PL_bufptr > 2
5767 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
c39cd008
GS
5768 {
5769 Off_t loc = 0;
50952442 5770 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
c39cd008
GS
5771 loc = PerlIO_tell(PL_rsfp);
5772 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5773 }
2986a63f
JH
5774#ifdef NETWARE
5775 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5776#else
c39cd008 5777 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
2986a63f 5778#endif /* NETWARE */
1143fce0
JH
5779#ifdef PERLIO_IS_STDIO /* really? */
5780# if defined(__BORLANDC__)
cb359b41
JH
5781 /* XXX see note in do_binmode() */
5782 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
1143fce0
JH
5783# endif
5784#endif
c39cd008
GS
5785 if (loc > 0)
5786 PerlIO_seek(PL_rsfp, loc, 0);
5787 }
5788 }
5789#endif
7948272d 5790#ifdef PERLIO_LAYERS
52d2e0f4
JH
5791 if (!IN_BYTES) {
5792 if (UTF)
5793 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5794 else if (PL_encoding) {
5795 SV *name;
5796 dSP;
5797 ENTER;
5798 SAVETMPS;
5799 PUSHMARK(sp);
5800 EXTEND(SP, 1);
5801 XPUSHs(PL_encoding);
5802 PUTBACK;
5803 call_method("name", G_SCALAR);
5804 SPAGAIN;
5805 name = POPs;
5806 PUTBACK;
bfed75c6 5807 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
52d2e0f4 5808 Perl_form(aTHX_ ":encoding(%"SVf")",
be2597df 5809 SVfARG(name)));
52d2e0f4
JH
5810 FREETMPS;
5811 LEAVE;
5812 }
5813 }
7948272d 5814#endif
5db06880
NC
5815#ifdef PERL_MAD
5816 if (PL_madskills) {
cd81e915
NC
5817 if (PL_realtokenstart >= 0) {
5818 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5819 if (!PL_endwhite)
6b29d1f5 5820 PL_endwhite = newSVpvs("");
cd81e915
NC
5821 sv_catsv(PL_endwhite, PL_thiswhite);
5822 PL_thiswhite = 0;
5823 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5824 PL_realtokenstart = -1;
5db06880 5825 }
cd81e915 5826 while ((s = filter_gets(PL_endwhite, PL_rsfp,
1a9a51d4 5827 SvCUR(PL_endwhite))) != NULL) ;
5db06880
NC
5828 }
5829#endif
4608196e 5830 PL_rsfp = NULL;
79072805
LW
5831 }
5832 goto fake_eof;
e929a76b 5833 }
de3bb511 5834
8990e307 5835 case KEY_AUTOLOAD:
ed6116ce 5836 case KEY_DESTROY:
79072805 5837 case KEY_BEGIN:
3c10abe3 5838 case KEY_UNITCHECK:
7d30b5c4 5839 case KEY_CHECK:
7d07dbc2 5840 case KEY_INIT:
7d30b5c4 5841 case KEY_END:
3280af22
NIS
5842 if (PL_expect == XSTATE) {
5843 s = PL_bufptr;
93a17b20 5844 goto really_sub;
79072805
LW
5845 }
5846 goto just_a_word;
5847
a0d0e21e
LW
5848 case KEY_CORE:
5849 if (*s == ':' && s[1] == ':') {
5850 s += 2;
748a9306 5851 d = s;
3280af22 5852 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5458a98a 5853 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
6798c92b 5854 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
a0d0e21e
LW
5855 if (tmp < 0)
5856 tmp = -tmp;
850e8516 5857 else if (tmp == KEY_require || tmp == KEY_do)
a72a1c8b 5858 /* that's a way to remember we saw "CORE::" */
850e8516 5859 orig_keyword = tmp;
a0d0e21e
LW
5860 goto reserved_word;
5861 }
5862 goto just_a_word;
5863
463ee0b2
LW
5864 case KEY_abs:
5865 UNI(OP_ABS);
5866
79072805
LW
5867 case KEY_alarm:
5868 UNI(OP_ALARM);
5869
5870 case KEY_accept:
a0d0e21e 5871 LOP(OP_ACCEPT,XTERM);
79072805 5872
463ee0b2
LW
5873 case KEY_and:
5874 OPERATOR(ANDOP);
5875
79072805 5876 case KEY_atan2:
a0d0e21e 5877 LOP(OP_ATAN2,XTERM);
85e6fe83 5878
79072805 5879 case KEY_bind:
a0d0e21e 5880 LOP(OP_BIND,XTERM);
79072805
LW
5881
5882 case KEY_binmode:
1c1fc3ea 5883 LOP(OP_BINMODE,XTERM);
79072805
LW
5884
5885 case KEY_bless:
a0d0e21e 5886 LOP(OP_BLESS,XTERM);
79072805 5887
0d863452
RH
5888 case KEY_break:
5889 FUN0(OP_BREAK);
5890
79072805
LW
5891 case KEY_chop:
5892 UNI(OP_CHOP);
5893
5894 case KEY_continue:
0d863452
RH
5895 /* When 'use switch' is in effect, continue has a dual
5896 life as a control operator. */
5897 {
ef89dcc3 5898 if (!FEATURE_IS_ENABLED("switch"))
0d863452
RH
5899 PREBLOCK(CONTINUE);
5900 else {
5901 /* We have to disambiguate the two senses of
5902 "continue". If the next token is a '{' then
5903 treat it as the start of a continue block;
5904 otherwise treat it as a control operator.
5905 */
5906 s = skipspace(s);
5907 if (*s == '{')
79072805 5908 PREBLOCK(CONTINUE);
0d863452
RH
5909 else
5910 FUN0(OP_CONTINUE);
5911 }
5912 }
79072805
LW
5913
5914 case KEY_chdir:
fafc274c
NC
5915 /* may use HOME */
5916 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
79072805
LW
5917 UNI(OP_CHDIR);
5918
5919 case KEY_close:
5920 UNI(OP_CLOSE);
5921
5922 case KEY_closedir:
5923 UNI(OP_CLOSEDIR);
5924
5925 case KEY_cmp:
5926 Eop(OP_SCMP);
5927
5928 case KEY_caller:
5929 UNI(OP_CALLER);
5930
5931 case KEY_crypt:
5932#ifdef FCRYPT
f4c556ac
GS
5933 if (!PL_cryptseen) {
5934 PL_cryptseen = TRUE;
de3bb511 5935 init_des();
f4c556ac 5936 }
a687059c 5937#endif
a0d0e21e 5938 LOP(OP_CRYPT,XTERM);
79072805
LW
5939
5940 case KEY_chmod:
a0d0e21e 5941 LOP(OP_CHMOD,XTERM);
79072805
LW
5942
5943 case KEY_chown:
a0d0e21e 5944 LOP(OP_CHOWN,XTERM);
79072805
LW
5945
5946 case KEY_connect:
a0d0e21e 5947 LOP(OP_CONNECT,XTERM);
79072805 5948
463ee0b2
LW
5949 case KEY_chr:
5950 UNI(OP_CHR);
5951
79072805
LW
5952 case KEY_cos:
5953 UNI(OP_COS);
5954
5955 case KEY_chroot:
5956 UNI(OP_CHROOT);
5957
0d863452
RH
5958 case KEY_default:
5959 PREBLOCK(DEFAULT);
5960
79072805 5961 case KEY_do:
29595ff2 5962 s = SKIPSPACE1(s);
79072805 5963 if (*s == '{')
a0d0e21e 5964 PRETERMBLOCK(DO);
79072805 5965 if (*s != '\'')
89c5585f 5966 s = force_word(s,WORD,TRUE,TRUE,FALSE);
850e8516
RGS
5967 if (orig_keyword == KEY_do) {
5968 orig_keyword = 0;
6154021b 5969 pl_yylval.ival = 1;
850e8516
RGS
5970 }
5971 else
6154021b 5972 pl_yylval.ival = 0;
378cc40b 5973 OPERATOR(DO);
79072805
LW
5974
5975 case KEY_die:
3280af22 5976 PL_hints |= HINT_BLOCK_SCOPE;
a0d0e21e 5977 LOP(OP_DIE,XTERM);
79072805
LW
5978
5979 case KEY_defined:
5980 UNI(OP_DEFINED);
5981
5982 case KEY_delete:
a0d0e21e 5983 UNI(OP_DELETE);
79072805
LW
5984
5985 case KEY_dbmopen:
5c1737d1 5986 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
a0d0e21e 5987 LOP(OP_DBMOPEN,XTERM);
79072805
LW
5988
5989 case KEY_dbmclose:
5990 UNI(OP_DBMCLOSE);
5991
5992 case KEY_dump:
a0d0e21e 5993 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
5994 LOOPX(OP_DUMP);
5995
5996 case KEY_else:
5997 PREBLOCK(ELSE);
5998
5999 case KEY_elsif:
6154021b 6000 pl_yylval.ival = CopLINE(PL_curcop);
79072805
LW
6001 OPERATOR(ELSIF);
6002
6003 case KEY_eq:
6004 Eop(OP_SEQ);
6005
a0d0e21e
LW
6006 case KEY_exists:
6007 UNI(OP_EXISTS);
4e553d73 6008
79072805 6009 case KEY_exit:
5db06880
NC
6010 if (PL_madskills)
6011 UNI(OP_INT);
79072805
LW
6012 UNI(OP_EXIT);
6013
6014 case KEY_eval:
29595ff2 6015 s = SKIPSPACE1(s);
3280af22 6016 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
463ee0b2 6017 UNIBRACK(OP_ENTEREVAL);
79072805
LW
6018
6019 case KEY_eof:
6020 UNI(OP_EOF);
6021
6022 case KEY_exp:
6023 UNI(OP_EXP);
6024
6025 case KEY_each:
6026 UNI(OP_EACH);
6027
6028 case KEY_exec:
a0d0e21e 6029 LOP(OP_EXEC,XREF);
79072805
LW
6030
6031 case KEY_endhostent:
6032 FUN0(OP_EHOSTENT);
6033
6034 case KEY_endnetent:
6035 FUN0(OP_ENETENT);
6036
6037 case KEY_endservent:
6038 FUN0(OP_ESERVENT);
6039
6040 case KEY_endprotoent:
6041 FUN0(OP_EPROTOENT);
6042
6043 case KEY_endpwent:
6044 FUN0(OP_EPWENT);
6045
6046 case KEY_endgrent:
6047 FUN0(OP_EGRENT);
6048
6049 case KEY_for:
6050 case KEY_foreach:
6154021b 6051 pl_yylval.ival = CopLINE(PL_curcop);
29595ff2 6052 s = SKIPSPACE1(s);
7e2040f0 6053 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
55497cff 6054 char *p = s;
5db06880
NC
6055#ifdef PERL_MAD
6056 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
6057#endif
6058
3280af22 6059 if ((PL_bufend - p) >= 3 &&
55497cff 6060 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
6061 p += 2;
77ca0c92
LW
6062 else if ((PL_bufend - p) >= 4 &&
6063 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
6064 p += 3;
29595ff2 6065 p = PEEKSPACE(p);
7e2040f0 6066 if (isIDFIRST_lazy_if(p,UTF)) {
77ca0c92
LW
6067 p = scan_ident(p, PL_bufend,
6068 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
29595ff2 6069 p = PEEKSPACE(p);
77ca0c92
LW
6070 }
6071 if (*p != '$')
cea2e8a9 6072 Perl_croak(aTHX_ "Missing $ on loop variable");
5db06880
NC
6073#ifdef PERL_MAD
6074 s = SvPVX(PL_linestr) + soff;
6075#endif
55497cff 6076 }
79072805
LW
6077 OPERATOR(FOR);
6078
6079 case KEY_formline:
a0d0e21e 6080 LOP(OP_FORMLINE,XTERM);
79072805
LW
6081
6082 case KEY_fork:
6083 FUN0(OP_FORK);
6084
6085 case KEY_fcntl:
a0d0e21e 6086 LOP(OP_FCNTL,XTERM);
79072805
LW
6087
6088 case KEY_fileno:
6089 UNI(OP_FILENO);
6090
6091 case KEY_flock:
a0d0e21e 6092 LOP(OP_FLOCK,XTERM);
79072805
LW
6093
6094 case KEY_gt:
6095 Rop(OP_SGT);
6096
6097 case KEY_ge:
6098 Rop(OP_SGE);
6099
6100 case KEY_grep:
2c38e13d 6101 LOP(OP_GREPSTART, XREF);
79072805
LW
6102
6103 case KEY_goto:
a0d0e21e 6104 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
6105 LOOPX(OP_GOTO);
6106
6107 case KEY_gmtime:
6108 UNI(OP_GMTIME);
6109
6110 case KEY_getc:
6f33ba73 6111 UNIDOR(OP_GETC);
79072805
LW
6112
6113 case KEY_getppid:
6114 FUN0(OP_GETPPID);
6115
6116 case KEY_getpgrp:
6117 UNI(OP_GETPGRP);
6118
6119 case KEY_getpriority:
a0d0e21e 6120 LOP(OP_GETPRIORITY,XTERM);
79072805
LW
6121
6122 case KEY_getprotobyname:
6123 UNI(OP_GPBYNAME);
6124
6125 case KEY_getprotobynumber:
a0d0e21e 6126 LOP(OP_GPBYNUMBER,XTERM);
79072805
LW
6127
6128 case KEY_getprotoent:
6129 FUN0(OP_GPROTOENT);
6130
6131 case KEY_getpwent:
6132 FUN0(OP_GPWENT);
6133
6134 case KEY_getpwnam:
ff68c719 6135 UNI(OP_GPWNAM);
79072805
LW
6136
6137 case KEY_getpwuid:
ff68c719 6138 UNI(OP_GPWUID);
79072805
LW
6139
6140 case KEY_getpeername:
6141 UNI(OP_GETPEERNAME);
6142
6143 case KEY_gethostbyname:
6144 UNI(OP_GHBYNAME);
6145
6146 case KEY_gethostbyaddr:
a0d0e21e 6147 LOP(OP_GHBYADDR,XTERM);
79072805
LW
6148
6149 case KEY_gethostent:
6150 FUN0(OP_GHOSTENT);
6151
6152 case KEY_getnetbyname:
6153 UNI(OP_GNBYNAME);
6154
6155 case KEY_getnetbyaddr:
a0d0e21e 6156 LOP(OP_GNBYADDR,XTERM);
79072805
LW
6157
6158 case KEY_getnetent:
6159 FUN0(OP_GNETENT);
6160
6161 case KEY_getservbyname:
a0d0e21e 6162 LOP(OP_GSBYNAME,XTERM);
79072805
LW
6163
6164 case KEY_getservbyport:
a0d0e21e 6165 LOP(OP_GSBYPORT,XTERM);
79072805
LW
6166
6167 case KEY_getservent:
6168 FUN0(OP_GSERVENT);
6169
6170 case KEY_getsockname:
6171 UNI(OP_GETSOCKNAME);
6172
6173 case KEY_getsockopt:
a0d0e21e 6174 LOP(OP_GSOCKOPT,XTERM);
79072805
LW
6175
6176 case KEY_getgrent:
6177 FUN0(OP_GGRENT);
6178
6179 case KEY_getgrnam:
ff68c719 6180 UNI(OP_GGRNAM);
79072805
LW
6181
6182 case KEY_getgrgid:
ff68c719 6183 UNI(OP_GGRGID);
79072805
LW
6184
6185 case KEY_getlogin:
6186 FUN0(OP_GETLOGIN);
6187
0d863452 6188 case KEY_given:
6154021b 6189 pl_yylval.ival = CopLINE(PL_curcop);
0d863452
RH
6190 OPERATOR(GIVEN);
6191
93a17b20 6192 case KEY_glob:
a0d0e21e 6193 LOP(OP_GLOB,XTERM);
93a17b20 6194
79072805
LW
6195 case KEY_hex:
6196 UNI(OP_HEX);
6197
6198 case KEY_if:
6154021b 6199 pl_yylval.ival = CopLINE(PL_curcop);
79072805
LW
6200 OPERATOR(IF);
6201
6202 case KEY_index:
a0d0e21e 6203 LOP(OP_INDEX,XTERM);
79072805
LW
6204
6205 case KEY_int:
6206 UNI(OP_INT);
6207
6208 case KEY_ioctl:
a0d0e21e 6209 LOP(OP_IOCTL,XTERM);
79072805
LW
6210
6211 case KEY_join:
a0d0e21e 6212 LOP(OP_JOIN,XTERM);
79072805
LW
6213
6214 case KEY_keys:
6215 UNI(OP_KEYS);
6216
6217 case KEY_kill:
a0d0e21e 6218 LOP(OP_KILL,XTERM);
79072805
LW
6219
6220 case KEY_last:
a0d0e21e 6221 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805 6222 LOOPX(OP_LAST);
4e553d73 6223
79072805
LW
6224 case KEY_lc:
6225 UNI(OP_LC);
6226
6227 case KEY_lcfirst:
6228 UNI(OP_LCFIRST);
6229
6230 case KEY_local:
6154021b 6231 pl_yylval.ival = 0;
79072805
LW
6232 OPERATOR(LOCAL);
6233
6234 case KEY_length:
6235 UNI(OP_LENGTH);
6236
6237 case KEY_lt:
6238 Rop(OP_SLT);
6239
6240 case KEY_le:
6241 Rop(OP_SLE);
6242
6243 case KEY_localtime:
6244 UNI(OP_LOCALTIME);
6245
6246 case KEY_log:
6247 UNI(OP_LOG);
6248
6249 case KEY_link:
a0d0e21e 6250 LOP(OP_LINK,XTERM);
79072805
LW
6251
6252 case KEY_listen:
a0d0e21e 6253 LOP(OP_LISTEN,XTERM);
79072805 6254
c0329465
MB
6255 case KEY_lock:
6256 UNI(OP_LOCK);
6257
79072805
LW
6258 case KEY_lstat:
6259 UNI(OP_LSTAT);
6260
6261 case KEY_m:
8782bef2 6262 s = scan_pat(s,OP_MATCH);
79072805
LW
6263 TERM(sublex_start());
6264
a0d0e21e 6265 case KEY_map:
2c38e13d 6266 LOP(OP_MAPSTART, XREF);
4e4e412b 6267
79072805 6268 case KEY_mkdir:
a0d0e21e 6269 LOP(OP_MKDIR,XTERM);
79072805
LW
6270
6271 case KEY_msgctl:
a0d0e21e 6272 LOP(OP_MSGCTL,XTERM);
79072805
LW
6273
6274 case KEY_msgget:
a0d0e21e 6275 LOP(OP_MSGGET,XTERM);
79072805
LW
6276
6277 case KEY_msgrcv:
a0d0e21e 6278 LOP(OP_MSGRCV,XTERM);
79072805
LW
6279
6280 case KEY_msgsnd:
a0d0e21e 6281 LOP(OP_MSGSND,XTERM);
79072805 6282
77ca0c92 6283 case KEY_our:
93a17b20 6284 case KEY_my:
952306ac 6285 case KEY_state:
eac04b2e 6286 PL_in_my = (U16)tmp;
29595ff2 6287 s = SKIPSPACE1(s);
7e2040f0 6288 if (isIDFIRST_lazy_if(s,UTF)) {
5db06880
NC
6289#ifdef PERL_MAD
6290 char* start = s;
6291#endif
3280af22 6292 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
09bef843
SB
6293 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
6294 goto really_sub;
def3634b 6295 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
3280af22 6296 if (!PL_in_my_stash) {
c750a3ec 6297 char tmpbuf[1024];
3280af22 6298 PL_bufptr = s;
d9fad198 6299 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
c750a3ec
MB
6300 yyerror(tmpbuf);
6301 }
5db06880
NC
6302#ifdef PERL_MAD
6303 if (PL_madskills) { /* just add type to declarator token */
cd81e915
NC
6304 sv_catsv(PL_thistoken, PL_nextwhite);
6305 PL_nextwhite = 0;
6306 sv_catpvn(PL_thistoken, start, s - start);
5db06880
NC
6307 }
6308#endif
c750a3ec 6309 }
6154021b 6310 pl_yylval.ival = 1;
55497cff 6311 OPERATOR(MY);
93a17b20 6312
79072805 6313 case KEY_next:
a0d0e21e 6314 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
6315 LOOPX(OP_NEXT);
6316
6317 case KEY_ne:
6318 Eop(OP_SNE);
6319
a0d0e21e 6320 case KEY_no:
468aa647 6321 s = tokenize_use(0, s);
a0d0e21e
LW
6322 OPERATOR(USE);
6323
6324 case KEY_not:
29595ff2 6325 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
2d2e263d
LW
6326 FUN1(OP_NOT);
6327 else
6328 OPERATOR(NOTOP);
a0d0e21e 6329
79072805 6330 case KEY_open:
29595ff2 6331 s = SKIPSPACE1(s);
7e2040f0 6332 if (isIDFIRST_lazy_if(s,UTF)) {
f54cb97a 6333 const char *t;
c35e046a
AL
6334 for (d = s; isALNUM_lazy_if(d,UTF);)
6335 d++;
6336 for (t=d; isSPACE(*t);)
6337 t++;
e2ab214b 6338 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
66fbe8fb
HS
6339 /* [perl #16184] */
6340 && !(t[0] == '=' && t[1] == '>')
6341 ) {
5f66b61c 6342 int parms_len = (int)(d-s);
9014280d 6343 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
0453d815 6344 "Precedence problem: open %.*s should be open(%.*s)",
5f66b61c 6345 parms_len, s, parms_len, s);
66fbe8fb 6346 }
93a17b20 6347 }
a0d0e21e 6348 LOP(OP_OPEN,XTERM);
79072805 6349
463ee0b2 6350 case KEY_or:
6154021b 6351 pl_yylval.ival = OP_OR;
463ee0b2
LW
6352 OPERATOR(OROP);
6353
79072805
LW
6354 case KEY_ord:
6355 UNI(OP_ORD);
6356
6357 case KEY_oct:
6358 UNI(OP_OCT);
6359
6360 case KEY_opendir:
a0d0e21e 6361 LOP(OP_OPEN_DIR,XTERM);
79072805
LW
6362
6363 case KEY_print:
3280af22 6364 checkcomma(s,PL_tokenbuf,"filehandle");
a0d0e21e 6365 LOP(OP_PRINT,XREF);
79072805
LW
6366
6367 case KEY_printf:
3280af22 6368 checkcomma(s,PL_tokenbuf,"filehandle");
a0d0e21e 6369 LOP(OP_PRTF,XREF);
79072805 6370
c07a80fd 6371 case KEY_prototype:
6372 UNI(OP_PROTOTYPE);
6373
79072805 6374 case KEY_push:
a0d0e21e 6375 LOP(OP_PUSH,XTERM);
79072805
LW
6376
6377 case KEY_pop:
6f33ba73 6378 UNIDOR(OP_POP);
79072805 6379
a0d0e21e 6380 case KEY_pos:
6f33ba73 6381 UNIDOR(OP_POS);
4e553d73 6382
79072805 6383 case KEY_pack:
a0d0e21e 6384 LOP(OP_PACK,XTERM);
79072805
LW
6385
6386 case KEY_package:
a0d0e21e 6387 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6fa4d285 6388 s = force_version(s, FALSE);
79072805
LW
6389 OPERATOR(PACKAGE);
6390
6391 case KEY_pipe:
a0d0e21e 6392 LOP(OP_PIPE_OP,XTERM);
79072805
LW
6393
6394 case KEY_q:
5db06880 6395 s = scan_str(s,!!PL_madskills,FALSE);
79072805 6396 if (!s)
d4c19fe8 6397 missingterm(NULL);
6154021b 6398 pl_yylval.ival = OP_CONST;
79072805
LW
6399 TERM(sublex_start());
6400
a0d0e21e
LW
6401 case KEY_quotemeta:
6402 UNI(OP_QUOTEMETA);
6403
8990e307 6404 case KEY_qw:
5db06880 6405 s = scan_str(s,!!PL_madskills,FALSE);
8990e307 6406 if (!s)
d4c19fe8 6407 missingterm(NULL);
3480a8d2 6408 PL_expect = XOPERATOR;
8127e0e3
GS
6409 force_next(')');
6410 if (SvCUR(PL_lex_stuff)) {
5f66b61c 6411 OP *words = NULL;
8127e0e3 6412 int warned = 0;
3280af22 6413 d = SvPV_force(PL_lex_stuff, len);
8127e0e3 6414 while (len) {
d4c19fe8
AL
6415 for (; isSPACE(*d) && len; --len, ++d)
6416 /**/;
8127e0e3 6417 if (len) {
d4c19fe8 6418 SV *sv;
f54cb97a 6419 const char *b = d;
e476b1b5 6420 if (!warned && ckWARN(WARN_QW)) {
8127e0e3
GS
6421 for (; !isSPACE(*d) && len; --len, ++d) {
6422 if (*d == ',') {
9014280d 6423 Perl_warner(aTHX_ packWARN(WARN_QW),
8127e0e3
GS
6424 "Possible attempt to separate words with commas");
6425 ++warned;
6426 }
6427 else if (*d == '#') {
9014280d 6428 Perl_warner(aTHX_ packWARN(WARN_QW),
8127e0e3
GS
6429 "Possible attempt to put comments in qw() list");
6430 ++warned;
6431 }
6432 }
6433 }
6434 else {
d4c19fe8
AL
6435 for (; !isSPACE(*d) && len; --len, ++d)
6436 /**/;
8127e0e3 6437 }
740cce10 6438 sv = newSVpvn_utf8(b, d-b, DO_UTF8(PL_lex_stuff));
8127e0e3 6439 words = append_elem(OP_LIST, words,
7948272d 6440 newSVOP(OP_CONST, 0, tokeq(sv)));
55497cff 6441 }
6442 }
8127e0e3 6443 if (words) {
cd81e915 6444 start_force(PL_curforce);
9ded7720 6445 NEXTVAL_NEXTTOKE.opval = words;
8127e0e3
GS
6446 force_next(THING);
6447 }
55497cff 6448 }
37fd879b 6449 if (PL_lex_stuff) {
8127e0e3 6450 SvREFCNT_dec(PL_lex_stuff);
a0714e2c 6451 PL_lex_stuff = NULL;
37fd879b 6452 }
3280af22 6453 PL_expect = XTERM;
8127e0e3 6454 TOKEN('(');
8990e307 6455
79072805 6456 case KEY_qq:
5db06880 6457 s = scan_str(s,!!PL_madskills,FALSE);
79072805 6458 if (!s)
d4c19fe8 6459 missingterm(NULL);
6154021b 6460 pl_yylval.ival = OP_STRINGIFY;
3280af22 6461 if (SvIVX(PL_lex_stuff) == '\'')
45977657 6462 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
79072805
LW
6463 TERM(sublex_start());
6464
8782bef2
GB
6465 case KEY_qr:
6466 s = scan_pat(s,OP_QR);
6467 TERM(sublex_start());
6468
79072805 6469 case KEY_qx:
5db06880 6470 s = scan_str(s,!!PL_madskills,FALSE);
79072805 6471 if (!s)
d4c19fe8 6472 missingterm(NULL);
9b201d7d 6473 readpipe_override();
79072805
LW
6474 TERM(sublex_start());
6475
6476 case KEY_return:
6477 OLDLOP(OP_RETURN);
6478
6479 case KEY_require:
29595ff2 6480 s = SKIPSPACE1(s);
e759cc13
RGS
6481 if (isDIGIT(*s)) {
6482 s = force_version(s, FALSE);
a7cb1f99 6483 }
e759cc13
RGS
6484 else if (*s != 'v' || !isDIGIT(s[1])
6485 || (s = force_version(s, TRUE), *s == 'v'))
6486 {
a7cb1f99
GS
6487 *PL_tokenbuf = '\0';
6488 s = force_word(s,WORD,TRUE,TRUE,FALSE);
7e2040f0 6489 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
da51bb9b 6490 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), GV_ADD);
a7cb1f99
GS
6491 else if (*s == '<')
6492 yyerror("<> should be quotes");
6493 }
a72a1c8b
RGS
6494 if (orig_keyword == KEY_require) {
6495 orig_keyword = 0;
6154021b 6496 pl_yylval.ival = 1;
a72a1c8b
RGS
6497 }
6498 else
6154021b 6499 pl_yylval.ival = 0;
a72a1c8b
RGS
6500 PL_expect = XTERM;
6501 PL_bufptr = s;
6502 PL_last_uni = PL_oldbufptr;
6503 PL_last_lop_op = OP_REQUIRE;
6504 s = skipspace(s);
6505 return REPORT( (int)REQUIRE );
79072805
LW
6506
6507 case KEY_reset:
6508 UNI(OP_RESET);
6509
6510 case KEY_redo:
a0d0e21e 6511 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
6512 LOOPX(OP_REDO);
6513
6514 case KEY_rename:
a0d0e21e 6515 LOP(OP_RENAME,XTERM);
79072805
LW
6516
6517 case KEY_rand:
6518 UNI(OP_RAND);
6519
6520 case KEY_rmdir:
6521 UNI(OP_RMDIR);
6522
6523 case KEY_rindex:
a0d0e21e 6524 LOP(OP_RINDEX,XTERM);
79072805
LW
6525
6526 case KEY_read:
a0d0e21e 6527 LOP(OP_READ,XTERM);
79072805
LW
6528
6529 case KEY_readdir:
6530 UNI(OP_READDIR);
6531
93a17b20 6532 case KEY_readline:
6f33ba73 6533 UNIDOR(OP_READLINE);
93a17b20
LW
6534
6535 case KEY_readpipe:
0858480c 6536 UNIDOR(OP_BACKTICK);
93a17b20 6537
79072805
LW
6538 case KEY_rewinddir:
6539 UNI(OP_REWINDDIR);
6540
6541 case KEY_recv:
a0d0e21e 6542 LOP(OP_RECV,XTERM);
79072805
LW
6543
6544 case KEY_reverse:
a0d0e21e 6545 LOP(OP_REVERSE,XTERM);
79072805
LW
6546
6547 case KEY_readlink:
6f33ba73 6548 UNIDOR(OP_READLINK);
79072805
LW
6549
6550 case KEY_ref:
6551 UNI(OP_REF);
6552
6553 case KEY_s:
6554 s = scan_subst(s);
6154021b 6555 if (pl_yylval.opval)
79072805
LW
6556 TERM(sublex_start());
6557 else
6558 TOKEN(1); /* force error */
6559
0d863452
RH
6560 case KEY_say:
6561 checkcomma(s,PL_tokenbuf,"filehandle");
6562 LOP(OP_SAY,XREF);
6563
a0d0e21e
LW
6564 case KEY_chomp:
6565 UNI(OP_CHOMP);
4e553d73 6566
79072805
LW
6567 case KEY_scalar:
6568 UNI(OP_SCALAR);
6569
6570 case KEY_select:
a0d0e21e 6571 LOP(OP_SELECT,XTERM);
79072805
LW
6572
6573 case KEY_seek:
a0d0e21e 6574 LOP(OP_SEEK,XTERM);
79072805
LW
6575
6576 case KEY_semctl:
a0d0e21e 6577 LOP(OP_SEMCTL,XTERM);
79072805
LW
6578
6579 case KEY_semget:
a0d0e21e 6580 LOP(OP_SEMGET,XTERM);
79072805
LW
6581
6582 case KEY_semop:
a0d0e21e 6583 LOP(OP_SEMOP,XTERM);
79072805
LW
6584
6585 case KEY_send:
a0d0e21e 6586 LOP(OP_SEND,XTERM);
79072805
LW
6587
6588 case KEY_setpgrp:
a0d0e21e 6589 LOP(OP_SETPGRP,XTERM);
79072805
LW
6590
6591 case KEY_setpriority:
a0d0e21e 6592 LOP(OP_SETPRIORITY,XTERM);
79072805
LW
6593
6594 case KEY_sethostent:
ff68c719 6595 UNI(OP_SHOSTENT);
79072805
LW
6596
6597 case KEY_setnetent:
ff68c719 6598 UNI(OP_SNETENT);
79072805
LW
6599
6600 case KEY_setservent:
ff68c719 6601 UNI(OP_SSERVENT);
79072805
LW
6602
6603 case KEY_setprotoent:
ff68c719 6604 UNI(OP_SPROTOENT);
79072805
LW
6605
6606 case KEY_setpwent:
6607 FUN0(OP_SPWENT);
6608
6609 case KEY_setgrent:
6610 FUN0(OP_SGRENT);
6611
6612 case KEY_seekdir:
a0d0e21e 6613 LOP(OP_SEEKDIR,XTERM);
79072805
LW
6614
6615 case KEY_setsockopt:
a0d0e21e 6616 LOP(OP_SSOCKOPT,XTERM);
79072805
LW
6617
6618 case KEY_shift:
6f33ba73 6619 UNIDOR(OP_SHIFT);
79072805
LW
6620
6621 case KEY_shmctl:
a0d0e21e 6622 LOP(OP_SHMCTL,XTERM);
79072805
LW
6623
6624 case KEY_shmget:
a0d0e21e 6625 LOP(OP_SHMGET,XTERM);
79072805
LW
6626
6627 case KEY_shmread:
a0d0e21e 6628 LOP(OP_SHMREAD,XTERM);
79072805
LW
6629
6630 case KEY_shmwrite:
a0d0e21e 6631 LOP(OP_SHMWRITE,XTERM);
79072805
LW
6632
6633 case KEY_shutdown:
a0d0e21e 6634 LOP(OP_SHUTDOWN,XTERM);
79072805
LW
6635
6636 case KEY_sin:
6637 UNI(OP_SIN);
6638
6639 case KEY_sleep:
6640 UNI(OP_SLEEP);
6641
6642 case KEY_socket:
a0d0e21e 6643 LOP(OP_SOCKET,XTERM);
79072805
LW
6644
6645 case KEY_socketpair:
a0d0e21e 6646 LOP(OP_SOCKPAIR,XTERM);
79072805
LW
6647
6648 case KEY_sort:
3280af22 6649 checkcomma(s,PL_tokenbuf,"subroutine name");
29595ff2 6650 s = SKIPSPACE1(s);
79072805 6651 if (*s == ';' || *s == ')') /* probably a close */
cea2e8a9 6652 Perl_croak(aTHX_ "sort is now a reserved word");
3280af22 6653 PL_expect = XTERM;
15f0808c 6654 s = force_word(s,WORD,TRUE,TRUE,FALSE);
a0d0e21e 6655 LOP(OP_SORT,XREF);
79072805
LW
6656
6657 case KEY_split:
a0d0e21e 6658 LOP(OP_SPLIT,XTERM);
79072805
LW
6659
6660 case KEY_sprintf:
a0d0e21e 6661 LOP(OP_SPRINTF,XTERM);
79072805
LW
6662
6663 case KEY_splice:
a0d0e21e 6664 LOP(OP_SPLICE,XTERM);
79072805
LW
6665
6666 case KEY_sqrt:
6667 UNI(OP_SQRT);
6668
6669 case KEY_srand:
6670 UNI(OP_SRAND);
6671
6672 case KEY_stat:
6673 UNI(OP_STAT);
6674
6675 case KEY_study:
79072805
LW
6676 UNI(OP_STUDY);
6677
6678 case KEY_substr:
a0d0e21e 6679 LOP(OP_SUBSTR,XTERM);
79072805
LW
6680
6681 case KEY_format:
6682 case KEY_sub:
93a17b20 6683 really_sub:
09bef843 6684 {
3280af22 6685 char tmpbuf[sizeof PL_tokenbuf];
9c5ffd7c 6686 SSize_t tboffset = 0;
09bef843 6687 expectation attrful;
28cc6278 6688 bool have_name, have_proto;
f54cb97a 6689 const int key = tmp;
09bef843 6690
5db06880
NC
6691#ifdef PERL_MAD
6692 SV *tmpwhite = 0;
6693
cd81e915 6694 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5db06880 6695 SV *subtoken = newSVpvn(tstart, s - tstart);
cd81e915 6696 PL_thistoken = 0;
5db06880
NC
6697
6698 d = s;
6699 s = SKIPSPACE2(s,tmpwhite);
6700#else
09bef843 6701 s = skipspace(s);
5db06880 6702#endif
09bef843 6703
7e2040f0 6704 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
09bef843
SB
6705 (*s == ':' && s[1] == ':'))
6706 {
5db06880 6707#ifdef PERL_MAD
4f61fd4b 6708 SV *nametoke = NULL;
5db06880
NC
6709#endif
6710
09bef843
SB
6711 PL_expect = XBLOCK;
6712 attrful = XATTRBLOCK;
b1b65b59
JH
6713 /* remember buffer pos'n for later force_word */
6714 tboffset = s - PL_oldbufptr;
09bef843 6715 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5db06880
NC
6716#ifdef PERL_MAD
6717 if (PL_madskills)
6718 nametoke = newSVpvn(s, d - s);
6719#endif
6502358f
NC
6720 if (memchr(tmpbuf, ':', len))
6721 sv_setpvn(PL_subname, tmpbuf, len);
09bef843
SB
6722 else {
6723 sv_setsv(PL_subname,PL_curstname);
396482e1 6724 sv_catpvs(PL_subname,"::");
09bef843
SB
6725 sv_catpvn(PL_subname,tmpbuf,len);
6726 }
09bef843 6727 have_name = TRUE;
5db06880
NC
6728
6729#ifdef PERL_MAD
6730
6731 start_force(0);
6732 CURMAD('X', nametoke);
6733 CURMAD('_', tmpwhite);
6734 (void) force_word(PL_oldbufptr + tboffset, WORD,
6735 FALSE, TRUE, TRUE);
6736
6737 s = SKIPSPACE2(d,tmpwhite);
6738#else
6739 s = skipspace(d);
6740#endif
09bef843 6741 }
463ee0b2 6742 else {
09bef843
SB
6743 if (key == KEY_my)
6744 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6745 PL_expect = XTERMBLOCK;
6746 attrful = XATTRTERM;
76f68e9b 6747 sv_setpvs(PL_subname,"?");
09bef843 6748 have_name = FALSE;
463ee0b2 6749 }
4633a7c4 6750
09bef843
SB
6751 if (key == KEY_format) {
6752 if (*s == '=')
6753 PL_lex_formbrack = PL_lex_brackets + 1;
5db06880 6754#ifdef PERL_MAD
cd81e915 6755 PL_thistoken = subtoken;
5db06880
NC
6756 s = d;
6757#else
09bef843 6758 if (have_name)
b1b65b59
JH
6759 (void) force_word(PL_oldbufptr + tboffset, WORD,
6760 FALSE, TRUE, TRUE);
5db06880 6761#endif
09bef843
SB
6762 OPERATOR(FORMAT);
6763 }
79072805 6764
09bef843
SB
6765 /* Look for a prototype */
6766 if (*s == '(') {
d9f2850e
RGS
6767 char *p;
6768 bool bad_proto = FALSE;
9e8d7757
RB
6769 bool in_brackets = FALSE;
6770 char greedy_proto = ' ';
6771 bool proto_after_greedy_proto = FALSE;
6772 bool must_be_last = FALSE;
6773 bool underscore = FALSE;
aef2a98a 6774 bool seen_underscore = FALSE;
d9f2850e 6775 const bool warnsyntax = ckWARN(WARN_SYNTAX);
09bef843 6776
5db06880 6777 s = scan_str(s,!!PL_madskills,FALSE);
37fd879b 6778 if (!s)
09bef843 6779 Perl_croak(aTHX_ "Prototype not terminated");
2f758a16 6780 /* strip spaces and check for bad characters */
09bef843
SB
6781 d = SvPVX(PL_lex_stuff);
6782 tmp = 0;
d9f2850e
RGS
6783 for (p = d; *p; ++p) {
6784 if (!isSPACE(*p)) {
6785 d[tmp++] = *p;
9e8d7757
RB
6786
6787 if (warnsyntax) {
6788 if (must_be_last)
6789 proto_after_greedy_proto = TRUE;
6790 if (!strchr("$@%*;[]&\\_", *p)) {
6791 bad_proto = TRUE;
6792 }
6793 else {
6794 if ( underscore ) {
6795 if ( *p != ';' )
6796 bad_proto = TRUE;
6797 underscore = FALSE;
6798 }
6799 if ( *p == '[' ) {
6800 in_brackets = TRUE;
6801 }
6802 else if ( *p == ']' ) {
6803 in_brackets = FALSE;
6804 }
6805 else if ( (*p == '@' || *p == '%') &&
6806 ( tmp < 2 || d[tmp-2] != '\\' ) &&
6807 !in_brackets ) {
6808 must_be_last = TRUE;
6809 greedy_proto = *p;
6810 }
6811 else if ( *p == '_' ) {
aef2a98a 6812 underscore = seen_underscore = TRUE;
9e8d7757
RB
6813 }
6814 }
6815 }
d37a9538 6816 }
09bef843 6817 }
d9f2850e 6818 d[tmp] = '\0';
9e8d7757
RB
6819 if (proto_after_greedy_proto)
6820 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6821 "Prototype after '%c' for %"SVf" : %s",
6822 greedy_proto, SVfARG(PL_subname), d);
d9f2850e
RGS
6823 if (bad_proto)
6824 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
aef2a98a
RGS
6825 "Illegal character %sin prototype for %"SVf" : %s",
6826 seen_underscore ? "after '_' " : "",
be2597df 6827 SVfARG(PL_subname), d);
b162af07 6828 SvCUR_set(PL_lex_stuff, tmp);
09bef843 6829 have_proto = TRUE;
68dc0745 6830
5db06880
NC
6831#ifdef PERL_MAD
6832 start_force(0);
cd81e915 6833 CURMAD('q', PL_thisopen);
5db06880 6834 CURMAD('_', tmpwhite);
cd81e915
NC
6835 CURMAD('=', PL_thisstuff);
6836 CURMAD('Q', PL_thisclose);
5db06880
NC
6837 NEXTVAL_NEXTTOKE.opval =
6838 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
1a9a51d4 6839 PL_lex_stuff = NULL;
5db06880
NC
6840 force_next(THING);
6841
6842 s = SKIPSPACE2(s,tmpwhite);
6843#else
09bef843 6844 s = skipspace(s);
5db06880 6845#endif
4633a7c4 6846 }
09bef843
SB
6847 else
6848 have_proto = FALSE;
6849
6850 if (*s == ':' && s[1] != ':')
6851 PL_expect = attrful;
8e742a20
MHM
6852 else if (*s != '{' && key == KEY_sub) {
6853 if (!have_name)
6854 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6855 else if (*s != ';')
be2597df 6856 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, SVfARG(PL_subname));
8e742a20 6857 }
09bef843 6858
5db06880
NC
6859#ifdef PERL_MAD
6860 start_force(0);
6861 if (tmpwhite) {
6862 if (PL_madskills)
6b29d1f5 6863 curmad('^', newSVpvs(""));
5db06880
NC
6864 CURMAD('_', tmpwhite);
6865 }
6866 force_next(0);
6867
cd81e915 6868 PL_thistoken = subtoken;
5db06880 6869#else
09bef843 6870 if (have_proto) {
9ded7720 6871 NEXTVAL_NEXTTOKE.opval =
b1b65b59 6872 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
a0714e2c 6873 PL_lex_stuff = NULL;
09bef843 6874 force_next(THING);
68dc0745 6875 }
5db06880 6876#endif
09bef843 6877 if (!have_name) {
49a54bbe
NC
6878 if (PL_curstash)
6879 sv_setpvs(PL_subname, "__ANON__");
6880 else
6881 sv_setpvs(PL_subname, "__ANON__::__ANON__");
09bef843 6882 TOKEN(ANONSUB);
4633a7c4 6883 }
5db06880 6884#ifndef PERL_MAD
b1b65b59
JH
6885 (void) force_word(PL_oldbufptr + tboffset, WORD,
6886 FALSE, TRUE, TRUE);
5db06880 6887#endif
09bef843
SB
6888 if (key == KEY_my)
6889 TOKEN(MYSUB);
6890 TOKEN(SUB);
4633a7c4 6891 }
79072805
LW
6892
6893 case KEY_system:
a0d0e21e 6894 LOP(OP_SYSTEM,XREF);
79072805
LW
6895
6896 case KEY_symlink:
a0d0e21e 6897 LOP(OP_SYMLINK,XTERM);
79072805
LW
6898
6899 case KEY_syscall:
a0d0e21e 6900 LOP(OP_SYSCALL,XTERM);
79072805 6901
c07a80fd 6902 case KEY_sysopen:
6903 LOP(OP_SYSOPEN,XTERM);
6904
137443ea 6905 case KEY_sysseek:
6906 LOP(OP_SYSSEEK,XTERM);
6907
79072805 6908 case KEY_sysread:
a0d0e21e 6909 LOP(OP_SYSREAD,XTERM);
79072805
LW
6910
6911 case KEY_syswrite:
a0d0e21e 6912 LOP(OP_SYSWRITE,XTERM);
79072805
LW
6913
6914 case KEY_tr:
6915 s = scan_trans(s);
6916 TERM(sublex_start());
6917
6918 case KEY_tell:
6919 UNI(OP_TELL);
6920
6921 case KEY_telldir:
6922 UNI(OP_TELLDIR);
6923
463ee0b2 6924 case KEY_tie:
a0d0e21e 6925 LOP(OP_TIE,XTERM);
463ee0b2 6926
c07a80fd 6927 case KEY_tied:
6928 UNI(OP_TIED);
6929
79072805
LW
6930 case KEY_time:
6931 FUN0(OP_TIME);
6932
6933 case KEY_times:
6934 FUN0(OP_TMS);
6935
6936 case KEY_truncate:
a0d0e21e 6937 LOP(OP_TRUNCATE,XTERM);
79072805
LW
6938
6939 case KEY_uc:
6940 UNI(OP_UC);
6941
6942 case KEY_ucfirst:
6943 UNI(OP_UCFIRST);
6944
463ee0b2
LW
6945 case KEY_untie:
6946 UNI(OP_UNTIE);
6947
79072805 6948 case KEY_until:
6154021b 6949 pl_yylval.ival = CopLINE(PL_curcop);
79072805
LW
6950 OPERATOR(UNTIL);
6951
6952 case KEY_unless:
6154021b 6953 pl_yylval.ival = CopLINE(PL_curcop);
79072805
LW
6954 OPERATOR(UNLESS);
6955
6956 case KEY_unlink:
a0d0e21e 6957 LOP(OP_UNLINK,XTERM);
79072805
LW
6958
6959 case KEY_undef:
6f33ba73 6960 UNIDOR(OP_UNDEF);
79072805
LW
6961
6962 case KEY_unpack:
a0d0e21e 6963 LOP(OP_UNPACK,XTERM);
79072805
LW
6964
6965 case KEY_utime:
a0d0e21e 6966 LOP(OP_UTIME,XTERM);
79072805
LW
6967
6968 case KEY_umask:
6f33ba73 6969 UNIDOR(OP_UMASK);
79072805
LW
6970
6971 case KEY_unshift:
a0d0e21e
LW
6972 LOP(OP_UNSHIFT,XTERM);
6973
6974 case KEY_use:
468aa647 6975 s = tokenize_use(1, s);
a0d0e21e 6976 OPERATOR(USE);
79072805
LW
6977
6978 case KEY_values:
6979 UNI(OP_VALUES);
6980
6981 case KEY_vec:
a0d0e21e 6982 LOP(OP_VEC,XTERM);
79072805 6983
0d863452 6984 case KEY_when:
6154021b 6985 pl_yylval.ival = CopLINE(PL_curcop);
0d863452
RH
6986 OPERATOR(WHEN);
6987
79072805 6988 case KEY_while:
6154021b 6989 pl_yylval.ival = CopLINE(PL_curcop);
79072805
LW
6990 OPERATOR(WHILE);
6991
6992 case KEY_warn:
3280af22 6993 PL_hints |= HINT_BLOCK_SCOPE;
a0d0e21e 6994 LOP(OP_WARN,XTERM);
79072805
LW
6995
6996 case KEY_wait:
6997 FUN0(OP_WAIT);
6998
6999 case KEY_waitpid:
a0d0e21e 7000 LOP(OP_WAITPID,XTERM);
79072805
LW
7001
7002 case KEY_wantarray:
7003 FUN0(OP_WANTARRAY);
7004
7005 case KEY_write:
9d116dd7
JH
7006#ifdef EBCDIC
7007 {
df3728a2
JH
7008 char ctl_l[2];
7009 ctl_l[0] = toCTRL('L');
7010 ctl_l[1] = '\0';
fafc274c 7011 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
9d116dd7
JH
7012 }
7013#else
fafc274c
NC
7014 /* Make sure $^L is defined */
7015 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
9d116dd7 7016#endif
79072805
LW
7017 UNI(OP_ENTERWRITE);
7018
7019 case KEY_x:
3280af22 7020 if (PL_expect == XOPERATOR)
79072805
LW
7021 Mop(OP_REPEAT);
7022 check_uni();
7023 goto just_a_word;
7024
a0d0e21e 7025 case KEY_xor:
6154021b 7026 pl_yylval.ival = OP_XOR;
a0d0e21e
LW
7027 OPERATOR(OROP);
7028
79072805
LW
7029 case KEY_y:
7030 s = scan_trans(s);
7031 TERM(sublex_start());
7032 }
49dc05e3 7033 }}
79072805 7034}
bf4acbe4
GS
7035#ifdef __SC__
7036#pragma segment Main
7037#endif
79072805 7038
e930465f
JH
7039static int
7040S_pending_ident(pTHX)
8eceec63 7041{
97aff369 7042 dVAR;
8eceec63 7043 register char *d;
bbd11bfc 7044 PADOFFSET tmp = 0;
8eceec63
SC
7045 /* pit holds the identifier we read and pending_ident is reset */
7046 char pit = PL_pending_ident;
9bde8eb0
NC
7047 const STRLEN tokenbuf_len = strlen(PL_tokenbuf);
7048 /* All routes through this function want to know if there is a colon. */
c099d646 7049 const char *const has_colon = (const char*) memchr (PL_tokenbuf, ':', tokenbuf_len);
8eceec63
SC
7050 PL_pending_ident = 0;
7051
cd81e915 7052 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
8eceec63 7053 DEBUG_T({ PerlIO_printf(Perl_debug_log,
b6007c36 7054 "### Pending identifier '%s'\n", PL_tokenbuf); });
8eceec63
SC
7055
7056 /* if we're in a my(), we can't allow dynamics here.
7057 $foo'bar has already been turned into $foo::bar, so
7058 just check for colons.
7059
7060 if it's a legal name, the OP is a PADANY.
7061 */
7062 if (PL_in_my) {
7063 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
9bde8eb0 7064 if (has_colon)
8eceec63
SC
7065 yyerror(Perl_form(aTHX_ "No package name allowed for "
7066 "variable %s in \"our\"",
7067 PL_tokenbuf));
dd2155a4 7068 tmp = allocmy(PL_tokenbuf);
8eceec63
SC
7069 }
7070 else {
9bde8eb0 7071 if (has_colon)
952306ac
RGS
7072 yyerror(Perl_form(aTHX_ PL_no_myglob,
7073 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
8eceec63 7074
6154021b
RGS
7075 pl_yylval.opval = newOP(OP_PADANY, 0);
7076 pl_yylval.opval->op_targ = allocmy(PL_tokenbuf);
8eceec63
SC
7077 return PRIVATEREF;
7078 }
7079 }
7080
7081 /*
7082 build the ops for accesses to a my() variable.
7083
7084 Deny my($a) or my($b) in a sort block, *if* $a or $b is
7085 then used in a comparison. This catches most, but not
7086 all cases. For instance, it catches
7087 sort { my($a); $a <=> $b }
7088 but not
7089 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
7090 (although why you'd do that is anyone's guess).
7091 */
7092
9bde8eb0 7093 if (!has_colon) {
8716503d
DM
7094 if (!PL_in_my)
7095 tmp = pad_findmy(PL_tokenbuf);
7096 if (tmp != NOT_IN_PAD) {
8eceec63 7097 /* might be an "our" variable" */
00b1698f 7098 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
8eceec63 7099 /* build ops for a bareword */
b64e5050
AL
7100 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
7101 HEK * const stashname = HvNAME_HEK(stash);
7102 SV * const sym = newSVhek(stashname);
396482e1 7103 sv_catpvs(sym, "::");
9bde8eb0 7104 sv_catpvn(sym, PL_tokenbuf+1, tokenbuf_len - 1);
6154021b
RGS
7105 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
7106 pl_yylval.opval->op_private = OPpCONST_ENTERED;
7a5fd60d 7107 gv_fetchsv(sym,
8eceec63
SC
7108 (PL_in_eval
7109 ? (GV_ADDMULTI | GV_ADDINEVAL)
700078d2 7110 : GV_ADDMULTI
8eceec63
SC
7111 ),
7112 ((PL_tokenbuf[0] == '$') ? SVt_PV
7113 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
7114 : SVt_PVHV));
7115 return WORD;
7116 }
7117
7118 /* if it's a sort block and they're naming $a or $b */
7119 if (PL_last_lop_op == OP_SORT &&
7120 PL_tokenbuf[0] == '$' &&
7121 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
7122 && !PL_tokenbuf[2])
7123 {
7124 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
7125 d < PL_bufend && *d != '\n';
7126 d++)
7127 {
7128 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
7129 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
7130 PL_tokenbuf);
7131 }
7132 }
7133 }
7134
6154021b
RGS
7135 pl_yylval.opval = newOP(OP_PADANY, 0);
7136 pl_yylval.opval->op_targ = tmp;
8eceec63
SC
7137 return PRIVATEREF;
7138 }
7139 }
7140
7141 /*
7142 Whine if they've said @foo in a doublequoted string,
7143 and @foo isn't a variable we can find in the symbol
7144 table.
7145 */
7146 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
9bde8eb0
NC
7147 GV *const gv = gv_fetchpvn_flags(PL_tokenbuf + 1, tokenbuf_len - 1, 0,
7148 SVt_PVAV);
8eceec63 7149 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
e879d94f
RGS
7150 /* DO NOT warn for @- and @+ */
7151 && !( PL_tokenbuf[2] == '\0' &&
7152 ( PL_tokenbuf[1] == '-' || PL_tokenbuf[1] == '+' ))
7153 )
8eceec63
SC
7154 {
7155 /* Downgraded from fatal to warning 20000522 mjd */
a2a5de95
NC
7156 Perl_ck_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
7157 "Possible unintended interpolation of %s in string",
7158 PL_tokenbuf);
8eceec63
SC
7159 }
7160 }
7161
7162 /* build ops for a bareword */
6154021b 7163 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpvn(PL_tokenbuf + 1,
9bde8eb0 7164 tokenbuf_len - 1));
6154021b 7165 pl_yylval.opval->op_private = OPpCONST_ENTERED;
9bde8eb0
NC
7166 gv_fetchpvn_flags(
7167 PL_tokenbuf + 1, tokenbuf_len - 1,
d6069db2
RGS
7168 /* If the identifier refers to a stash, don't autovivify it.
7169 * Change 24660 had the side effect of causing symbol table
7170 * hashes to always be defined, even if they were freshly
7171 * created and the only reference in the entire program was
7172 * the single statement with the defined %foo::bar:: test.
7173 * It appears that all code in the wild doing this actually
7174 * wants to know whether sub-packages have been loaded, so
7175 * by avoiding auto-vivifying symbol tables, we ensure that
7176 * defined %foo::bar:: continues to be false, and the existing
7177 * tests still give the expected answers, even though what
7178 * they're actually testing has now changed subtly.
7179 */
9bde8eb0
NC
7180 (*PL_tokenbuf == '%'
7181 && *(d = PL_tokenbuf + tokenbuf_len - 1) == ':'
7182 && d[-1] == ':'
d6069db2
RGS
7183 ? 0
7184 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
adc51b97
RGS
7185 ((PL_tokenbuf[0] == '$') ? SVt_PV
7186 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
7187 : SVt_PVHV));
8eceec63
SC
7188 return WORD;
7189}
7190
4c3bbe0f
MHM
7191/*
7192 * The following code was generated by perl_keyword.pl.
7193 */
e2e1dd5a 7194
79072805 7195I32
5458a98a 7196Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
4c3bbe0f 7197{
952306ac 7198 dVAR;
7918f24d
NC
7199
7200 PERL_ARGS_ASSERT_KEYWORD;
7201
4c3bbe0f
MHM
7202 switch (len)
7203 {
7204 case 1: /* 5 tokens of length 1 */
7205 switch (name[0])
e2e1dd5a 7206 {
4c3bbe0f
MHM
7207 case 'm':
7208 { /* m */
7209 return KEY_m;
7210 }
7211
4c3bbe0f
MHM
7212 case 'q':
7213 { /* q */
7214 return KEY_q;
7215 }
7216
4c3bbe0f
MHM
7217 case 's':
7218 { /* s */
7219 return KEY_s;
7220 }
7221
4c3bbe0f
MHM
7222 case 'x':
7223 { /* x */
7224 return -KEY_x;
7225 }
7226
4c3bbe0f
MHM
7227 case 'y':
7228 { /* y */
7229 return KEY_y;
7230 }
7231
4c3bbe0f
MHM
7232 default:
7233 goto unknown;
e2e1dd5a 7234 }
4c3bbe0f
MHM
7235
7236 case 2: /* 18 tokens of length 2 */
7237 switch (name[0])
e2e1dd5a 7238 {
4c3bbe0f
MHM
7239 case 'd':
7240 if (name[1] == 'o')
7241 { /* do */
7242 return KEY_do;
7243 }
7244
7245 goto unknown;
7246
7247 case 'e':
7248 if (name[1] == 'q')
7249 { /* eq */
7250 return -KEY_eq;
7251 }
7252
7253 goto unknown;
7254
7255 case 'g':
7256 switch (name[1])
7257 {
7258 case 'e':
7259 { /* ge */
7260 return -KEY_ge;
7261 }
7262
4c3bbe0f
MHM
7263 case 't':
7264 { /* gt */
7265 return -KEY_gt;
7266 }
7267
4c3bbe0f
MHM
7268 default:
7269 goto unknown;
7270 }
7271
7272 case 'i':
7273 if (name[1] == 'f')
7274 { /* if */
7275 return KEY_if;
7276 }
7277
7278 goto unknown;
7279
7280 case 'l':
7281 switch (name[1])
7282 {
7283 case 'c':
7284 { /* lc */
7285 return -KEY_lc;
7286 }
7287
4c3bbe0f
MHM
7288 case 'e':
7289 { /* le */
7290 return -KEY_le;
7291 }
7292
4c3bbe0f
MHM
7293 case 't':
7294 { /* lt */
7295 return -KEY_lt;
7296 }
7297
4c3bbe0f
MHM
7298 default:
7299 goto unknown;
7300 }
7301
7302 case 'm':
7303 if (name[1] == 'y')
7304 { /* my */
7305 return KEY_my;
7306 }
7307
7308 goto unknown;
7309
7310 case 'n':
7311 switch (name[1])
7312 {
7313 case 'e':
7314 { /* ne */
7315 return -KEY_ne;
7316 }
7317
4c3bbe0f
MHM
7318 case 'o':
7319 { /* no */
7320 return KEY_no;
7321 }
7322
4c3bbe0f
MHM
7323 default:
7324 goto unknown;
7325 }
7326
7327 case 'o':
7328 if (name[1] == 'r')
7329 { /* or */
7330 return -KEY_or;
7331 }
7332
7333 goto unknown;
7334
7335 case 'q':
7336 switch (name[1])
7337 {
7338 case 'q':
7339 { /* qq */
7340 return KEY_qq;
7341 }
7342
4c3bbe0f
MHM
7343 case 'r':
7344 { /* qr */
7345 return KEY_qr;
7346 }
7347
4c3bbe0f
MHM
7348 case 'w':
7349 { /* qw */
7350 return KEY_qw;
7351 }
7352
4c3bbe0f
MHM
7353 case 'x':
7354 { /* qx */
7355 return KEY_qx;
7356 }
7357
4c3bbe0f
MHM
7358 default:
7359 goto unknown;
7360 }
7361
7362 case 't':
7363 if (name[1] == 'r')
7364 { /* tr */
7365 return KEY_tr;
7366 }
7367
7368 goto unknown;
7369
7370 case 'u':
7371 if (name[1] == 'c')
7372 { /* uc */
7373 return -KEY_uc;
7374 }
7375
7376 goto unknown;
7377
7378 default:
7379 goto unknown;
e2e1dd5a 7380 }
4c3bbe0f 7381
0d863452 7382 case 3: /* 29 tokens of length 3 */
4c3bbe0f 7383 switch (name[0])
e2e1dd5a 7384 {
4c3bbe0f
MHM
7385 case 'E':
7386 if (name[1] == 'N' &&
7387 name[2] == 'D')
7388 { /* END */
7389 return KEY_END;
7390 }
7391
7392 goto unknown;
7393
7394 case 'a':
7395 switch (name[1])
7396 {
7397 case 'b':
7398 if (name[2] == 's')
7399 { /* abs */
7400 return -KEY_abs;
7401 }
7402
7403 goto unknown;
7404
7405 case 'n':
7406 if (name[2] == 'd')
7407 { /* and */
7408 return -KEY_and;
7409 }
7410
7411 goto unknown;
7412
7413 default:
7414 goto unknown;
7415 }
7416
7417 case 'c':
7418 switch (name[1])
7419 {
7420 case 'h':
7421 if (name[2] == 'r')
7422 { /* chr */
7423 return -KEY_chr;
7424 }
7425
7426 goto unknown;
7427
7428 case 'm':
7429 if (name[2] == 'p')
7430 { /* cmp */
7431 return -KEY_cmp;
7432 }
7433
7434 goto unknown;
7435
7436 case 'o':
7437 if (name[2] == 's')
7438 { /* cos */
7439 return -KEY_cos;
7440 }
7441
7442 goto unknown;
7443
7444 default:
7445 goto unknown;
7446 }
7447
7448 case 'd':
7449 if (name[1] == 'i' &&
7450 name[2] == 'e')
7451 { /* die */
7452 return -KEY_die;
7453 }
7454
7455 goto unknown;
7456
7457 case 'e':
7458 switch (name[1])
7459 {
7460 case 'o':
7461 if (name[2] == 'f')
7462 { /* eof */
7463 return -KEY_eof;
7464 }
7465
7466 goto unknown;
7467
4c3bbe0f
MHM
7468 case 'x':
7469 if (name[2] == 'p')
7470 { /* exp */
7471 return -KEY_exp;
7472 }
7473
7474 goto unknown;
7475
7476 default:
7477 goto unknown;
7478 }
7479
7480 case 'f':
7481 if (name[1] == 'o' &&
7482 name[2] == 'r')
7483 { /* for */
7484 return KEY_for;
7485 }
7486
7487 goto unknown;
7488
7489 case 'h':
7490 if (name[1] == 'e' &&
7491 name[2] == 'x')
7492 { /* hex */
7493 return -KEY_hex;
7494 }
7495
7496 goto unknown;
7497
7498 case 'i':
7499 if (name[1] == 'n' &&
7500 name[2] == 't')
7501 { /* int */
7502 return -KEY_int;
7503 }
7504
7505 goto unknown;
7506
7507 case 'l':
7508 if (name[1] == 'o' &&
7509 name[2] == 'g')
7510 { /* log */
7511 return -KEY_log;
7512 }
7513
7514 goto unknown;
7515
7516 case 'm':
7517 if (name[1] == 'a' &&
7518 name[2] == 'p')
7519 { /* map */
7520 return KEY_map;
7521 }
7522
7523 goto unknown;
7524
7525 case 'n':
7526 if (name[1] == 'o' &&
7527 name[2] == 't')
7528 { /* not */
7529 return -KEY_not;
7530 }
7531
7532 goto unknown;
7533
7534 case 'o':
7535 switch (name[1])
7536 {
7537 case 'c':
7538 if (name[2] == 't')
7539 { /* oct */
7540 return -KEY_oct;
7541 }
7542
7543 goto unknown;
7544
7545 case 'r':
7546 if (name[2] == 'd')
7547 { /* ord */
7548 return -KEY_ord;
7549 }
7550
7551 goto unknown;
7552
7553 case 'u':
7554 if (name[2] == 'r')
7555 { /* our */
7556 return KEY_our;
7557 }
7558
7559 goto unknown;
7560
7561 default:
7562 goto unknown;
7563 }
7564
7565 case 'p':
7566 if (name[1] == 'o')
7567 {
7568 switch (name[2])
7569 {
7570 case 'p':
7571 { /* pop */
7572 return -KEY_pop;
7573 }
7574
4c3bbe0f
MHM
7575 case 's':
7576 { /* pos */
7577 return KEY_pos;
7578 }
7579
4c3bbe0f
MHM
7580 default:
7581 goto unknown;
7582 }
7583 }
7584
7585 goto unknown;
7586
7587 case 'r':
7588 if (name[1] == 'e' &&
7589 name[2] == 'f')
7590 { /* ref */
7591 return -KEY_ref;
7592 }
7593
7594 goto unknown;
7595
7596 case 's':
7597 switch (name[1])
7598 {
0d863452
RH
7599 case 'a':
7600 if (name[2] == 'y')
7601 { /* say */
e3e804c9 7602 return (all_keywords || FEATURE_IS_ENABLED("say") ? KEY_say : 0);
0d863452
RH
7603 }
7604
7605 goto unknown;
7606
4c3bbe0f
MHM
7607 case 'i':
7608 if (name[2] == 'n')
7609 { /* sin */
7610 return -KEY_sin;
7611 }
7612
7613 goto unknown;
7614
7615 case 'u':
7616 if (name[2] == 'b')
7617 { /* sub */
7618 return KEY_sub;
7619 }
7620
7621 goto unknown;
7622
7623 default:
7624 goto unknown;
7625 }
7626
7627 case 't':
7628 if (name[1] == 'i' &&
7629 name[2] == 'e')
7630 { /* tie */
7631 return KEY_tie;
7632 }
7633
7634 goto unknown;
7635
7636 case 'u':
7637 if (name[1] == 's' &&
7638 name[2] == 'e')
7639 { /* use */
7640 return KEY_use;
7641 }
7642
7643 goto unknown;
7644
7645 case 'v':
7646 if (name[1] == 'e' &&
7647 name[2] == 'c')
7648 { /* vec */
7649 return -KEY_vec;
7650 }
7651
7652 goto unknown;
7653
7654 case 'x':
7655 if (name[1] == 'o' &&
7656 name[2] == 'r')
7657 { /* xor */
7658 return -KEY_xor;
7659 }
7660
7661 goto unknown;
7662
7663 default:
7664 goto unknown;
e2e1dd5a 7665 }
4c3bbe0f 7666
0d863452 7667 case 4: /* 41 tokens of length 4 */
4c3bbe0f 7668 switch (name[0])
e2e1dd5a 7669 {
4c3bbe0f
MHM
7670 case 'C':
7671 if (name[1] == 'O' &&
7672 name[2] == 'R' &&
7673 name[3] == 'E')
7674 { /* CORE */
7675 return -KEY_CORE;
7676 }
7677
7678 goto unknown;
7679
7680 case 'I':
7681 if (name[1] == 'N' &&
7682 name[2] == 'I' &&
7683 name[3] == 'T')
7684 { /* INIT */
7685 return KEY_INIT;
7686 }
7687
7688 goto unknown;
7689
7690 case 'b':
7691 if (name[1] == 'i' &&
7692 name[2] == 'n' &&
7693 name[3] == 'd')
7694 { /* bind */
7695 return -KEY_bind;
7696 }
7697
7698 goto unknown;
7699
7700 case 'c':
7701 if (name[1] == 'h' &&
7702 name[2] == 'o' &&
7703 name[3] == 'p')
7704 { /* chop */
7705 return -KEY_chop;
7706 }
7707
7708 goto unknown;
7709
7710 case 'd':
7711 if (name[1] == 'u' &&
7712 name[2] == 'm' &&
7713 name[3] == 'p')
7714 { /* dump */
7715 return -KEY_dump;
7716 }
7717
7718 goto unknown;
7719
7720 case 'e':
7721 switch (name[1])
7722 {
7723 case 'a':
7724 if (name[2] == 'c' &&
7725 name[3] == 'h')
7726 { /* each */
7727 return -KEY_each;
7728 }
7729
7730 goto unknown;
7731
7732 case 'l':
7733 if (name[2] == 's' &&
7734 name[3] == 'e')
7735 { /* else */
7736 return KEY_else;
7737 }
7738
7739 goto unknown;
7740
7741 case 'v':
7742 if (name[2] == 'a' &&
7743 name[3] == 'l')
7744 { /* eval */
7745 return KEY_eval;
7746 }
7747
7748 goto unknown;
7749
7750 case 'x':
7751 switch (name[2])
7752 {
7753 case 'e':
7754 if (name[3] == 'c')
7755 { /* exec */
7756 return -KEY_exec;
7757 }
7758
7759 goto unknown;
7760
7761 case 'i':
7762 if (name[3] == 't')
7763 { /* exit */
7764 return -KEY_exit;
7765 }
7766
7767 goto unknown;
7768
7769 default:
7770 goto unknown;
7771 }
7772
7773 default:
7774 goto unknown;
7775 }
7776
7777 case 'f':
7778 if (name[1] == 'o' &&
7779 name[2] == 'r' &&
7780 name[3] == 'k')
7781 { /* fork */
7782 return -KEY_fork;
7783 }
7784
7785 goto unknown;
7786
7787 case 'g':
7788 switch (name[1])
7789 {
7790 case 'e':
7791 if (name[2] == 't' &&
7792 name[3] == 'c')
7793 { /* getc */
7794 return -KEY_getc;
7795 }
7796
7797 goto unknown;
7798
7799 case 'l':
7800 if (name[2] == 'o' &&
7801 name[3] == 'b')
7802 { /* glob */
7803 return KEY_glob;
7804 }
7805
7806 goto unknown;
7807
7808 case 'o':
7809 if (name[2] == 't' &&
7810 name[3] == 'o')
7811 { /* goto */
7812 return KEY_goto;
7813 }
7814
7815 goto unknown;
7816
7817 case 'r':
7818 if (name[2] == 'e' &&
7819 name[3] == 'p')
7820 { /* grep */
7821 return KEY_grep;
7822 }
7823
7824 goto unknown;
7825
7826 default:
7827 goto unknown;
7828 }
7829
7830 case 'j':
7831 if (name[1] == 'o' &&
7832 name[2] == 'i' &&
7833 name[3] == 'n')
7834 { /* join */
7835 return -KEY_join;
7836 }
7837
7838 goto unknown;
7839
7840 case 'k':
7841 switch (name[1])
7842 {
7843 case 'e':
7844 if (name[2] == 'y' &&
7845 name[3] == 's')
7846 { /* keys */
7847 return -KEY_keys;
7848 }
7849
7850 goto unknown;
7851
7852 case 'i':
7853 if (name[2] == 'l' &&
7854 name[3] == 'l')
7855 { /* kill */
7856 return -KEY_kill;
7857 }
7858
7859 goto unknown;
7860
7861 default:
7862 goto unknown;
7863 }
7864
7865 case 'l':
7866 switch (name[1])
7867 {
7868 case 'a':
7869 if (name[2] == 's' &&
7870 name[3] == 't')
7871 { /* last */
7872 return KEY_last;
7873 }
7874
7875 goto unknown;
7876
7877 case 'i':
7878 if (name[2] == 'n' &&
7879 name[3] == 'k')
7880 { /* link */
7881 return -KEY_link;
7882 }
7883
7884 goto unknown;
7885
7886 case 'o':
7887 if (name[2] == 'c' &&
7888 name[3] == 'k')
7889 { /* lock */
7890 return -KEY_lock;
7891 }
7892
7893 goto unknown;
7894
7895 default:
7896 goto unknown;
7897 }
7898
7899 case 'n':
7900 if (name[1] == 'e' &&
7901 name[2] == 'x' &&
7902 name[3] == 't')
7903 { /* next */
7904 return KEY_next;
7905 }
7906
7907 goto unknown;
7908
7909 case 'o':
7910 if (name[1] == 'p' &&
7911 name[2] == 'e' &&
7912 name[3] == 'n')
7913 { /* open */
7914 return -KEY_open;
7915 }
7916
7917 goto unknown;
7918
7919 case 'p':
7920 switch (name[1])
7921 {
7922 case 'a':
7923 if (name[2] == 'c' &&
7924 name[3] == 'k')
7925 { /* pack */
7926 return -KEY_pack;
7927 }
7928
7929 goto unknown;
7930
7931 case 'i':
7932 if (name[2] == 'p' &&
7933 name[3] == 'e')
7934 { /* pipe */
7935 return -KEY_pipe;
7936 }
7937
7938 goto unknown;
7939
7940 case 'u':
7941 if (name[2] == 's' &&
7942 name[3] == 'h')
7943 { /* push */
7944 return -KEY_push;
7945 }
7946
7947 goto unknown;
7948
7949 default:
7950 goto unknown;
7951 }
7952
7953 case 'r':
7954 switch (name[1])
7955 {
7956 case 'a':
7957 if (name[2] == 'n' &&
7958 name[3] == 'd')
7959 { /* rand */
7960 return -KEY_rand;
7961 }
7962
7963 goto unknown;
7964
7965 case 'e':
7966 switch (name[2])
7967 {
7968 case 'a':
7969 if (name[3] == 'd')
7970 { /* read */
7971 return -KEY_read;
7972 }
7973
7974 goto unknown;
7975
7976 case 'c':
7977 if (name[3] == 'v')
7978 { /* recv */
7979 return -KEY_recv;
7980 }
7981
7982 goto unknown;
7983
7984 case 'd':
7985 if (name[3] == 'o')
7986 { /* redo */
7987 return KEY_redo;
7988 }
7989
7990 goto unknown;
7991
7992 default:
7993 goto unknown;
7994 }
7995
7996 default:
7997 goto unknown;
7998 }
7999
8000 case 's':
8001 switch (name[1])
8002 {
8003 case 'e':
8004 switch (name[2])
8005 {
8006 case 'e':
8007 if (name[3] == 'k')
8008 { /* seek */
8009 return -KEY_seek;
8010 }
8011
8012 goto unknown;
8013
8014 case 'n':
8015 if (name[3] == 'd')
8016 { /* send */
8017 return -KEY_send;
8018 }
8019
8020 goto unknown;
8021
8022 default:
8023 goto unknown;
8024 }
8025
8026 case 'o':
8027 if (name[2] == 'r' &&
8028 name[3] == 't')
8029 { /* sort */
8030 return KEY_sort;
8031 }
8032
8033 goto unknown;
8034
8035 case 'q':
8036 if (name[2] == 'r' &&
8037 name[3] == 't')
8038 { /* sqrt */
8039 return -KEY_sqrt;
8040 }
8041
8042 goto unknown;
8043
8044 case 't':
8045 if (name[2] == 'a' &&
8046 name[3] == 't')
8047 { /* stat */
8048 return -KEY_stat;
8049 }
8050
8051 goto unknown;
8052
8053 default:
8054 goto unknown;
8055 }
8056
8057 case 't':
8058 switch (name[1])
8059 {
8060 case 'e':
8061 if (name[2] == 'l' &&
8062 name[3] == 'l')
8063 { /* tell */
8064 return -KEY_tell;
8065 }
8066
8067 goto unknown;
8068
8069 case 'i':
8070 switch (name[2])
8071 {
8072 case 'e':
8073 if (name[3] == 'd')
8074 { /* tied */
8075 return KEY_tied;
8076 }
8077
8078 goto unknown;
8079
8080 case 'm':
8081 if (name[3] == 'e')
8082 { /* time */
8083 return -KEY_time;
8084 }
8085
8086 goto unknown;
8087
8088 default:
8089 goto unknown;
8090 }
8091
8092 default:
8093 goto unknown;
8094 }
8095
8096 case 'w':
0d863452 8097 switch (name[1])
4c3bbe0f 8098 {
0d863452 8099 case 'a':
952306ac
RGS
8100 switch (name[2])
8101 {
8102 case 'i':
8103 if (name[3] == 't')
8104 { /* wait */
8105 return -KEY_wait;
8106 }
4c3bbe0f 8107
952306ac 8108 goto unknown;
4c3bbe0f 8109
952306ac
RGS
8110 case 'r':
8111 if (name[3] == 'n')
8112 { /* warn */
8113 return -KEY_warn;
8114 }
4c3bbe0f 8115
952306ac 8116 goto unknown;
4c3bbe0f 8117
952306ac
RGS
8118 default:
8119 goto unknown;
8120 }
0d863452
RH
8121
8122 case 'h':
8123 if (name[2] == 'e' &&
8124 name[3] == 'n')
8125 { /* when */
5458a98a 8126 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
952306ac 8127 }
4c3bbe0f 8128
952306ac 8129 goto unknown;
4c3bbe0f 8130
952306ac
RGS
8131 default:
8132 goto unknown;
8133 }
4c3bbe0f 8134
0d863452
RH
8135 default:
8136 goto unknown;
8137 }
8138
952306ac 8139 case 5: /* 39 tokens of length 5 */
4c3bbe0f 8140 switch (name[0])
e2e1dd5a 8141 {
4c3bbe0f
MHM
8142 case 'B':
8143 if (name[1] == 'E' &&
8144 name[2] == 'G' &&
8145 name[3] == 'I' &&
8146 name[4] == 'N')
8147 { /* BEGIN */
8148 return KEY_BEGIN;
8149 }
8150
8151 goto unknown;
8152
8153 case 'C':
8154 if (name[1] == 'H' &&
8155 name[2] == 'E' &&
8156 name[3] == 'C' &&
8157 name[4] == 'K')
8158 { /* CHECK */
8159 return KEY_CHECK;
8160 }
8161
8162 goto unknown;
8163
8164 case 'a':
8165 switch (name[1])
8166 {
8167 case 'l':
8168 if (name[2] == 'a' &&
8169 name[3] == 'r' &&
8170 name[4] == 'm')
8171 { /* alarm */
8172 return -KEY_alarm;
8173 }
8174
8175 goto unknown;
8176
8177 case 't':
8178 if (name[2] == 'a' &&
8179 name[3] == 'n' &&
8180 name[4] == '2')
8181 { /* atan2 */
8182 return -KEY_atan2;
8183 }
8184
8185 goto unknown;
8186
8187 default:
8188 goto unknown;
8189 }
8190
8191 case 'b':
0d863452
RH
8192 switch (name[1])
8193 {
8194 case 'l':
8195 if (name[2] == 'e' &&
952306ac
RGS
8196 name[3] == 's' &&
8197 name[4] == 's')
8198 { /* bless */
8199 return -KEY_bless;
8200 }
4c3bbe0f 8201
952306ac 8202 goto unknown;
4c3bbe0f 8203
0d863452
RH
8204 case 'r':
8205 if (name[2] == 'e' &&
8206 name[3] == 'a' &&
8207 name[4] == 'k')
8208 { /* break */
5458a98a 8209 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
0d863452
RH
8210 }
8211
8212 goto unknown;
8213
8214 default:
8215 goto unknown;
8216 }
8217
4c3bbe0f
MHM
8218 case 'c':
8219 switch (name[1])
8220 {
8221 case 'h':
8222 switch (name[2])
8223 {
8224 case 'd':
8225 if (name[3] == 'i' &&
8226 name[4] == 'r')
8227 { /* chdir */
8228 return -KEY_chdir;
8229 }
8230
8231 goto unknown;
8232
8233 case 'm':
8234 if (name[3] == 'o' &&
8235 name[4] == 'd')
8236 { /* chmod */
8237 return -KEY_chmod;
8238 }
8239
8240 goto unknown;
8241
8242 case 'o':
8243 switch (name[3])
8244 {
8245 case 'm':
8246 if (name[4] == 'p')
8247 { /* chomp */
8248 return -KEY_chomp;
8249 }
8250
8251 goto unknown;
8252
8253 case 'w':
8254 if (name[4] == 'n')
8255 { /* chown */
8256 return -KEY_chown;
8257 }
8258
8259 goto unknown;
8260
8261 default:
8262 goto unknown;
8263 }
8264
8265 default:
8266 goto unknown;
8267 }
8268
8269 case 'l':
8270 if (name[2] == 'o' &&
8271 name[3] == 's' &&
8272 name[4] == 'e')
8273 { /* close */
8274 return -KEY_close;
8275 }
8276
8277 goto unknown;
8278
8279 case 'r':
8280 if (name[2] == 'y' &&
8281 name[3] == 'p' &&
8282 name[4] == 't')
8283 { /* crypt */
8284 return -KEY_crypt;
8285 }
8286
8287 goto unknown;
8288
8289 default:
8290 goto unknown;
8291 }
8292
8293 case 'e':
8294 if (name[1] == 'l' &&
8295 name[2] == 's' &&
8296 name[3] == 'i' &&
8297 name[4] == 'f')
8298 { /* elsif */
8299 return KEY_elsif;
8300 }
8301
8302 goto unknown;
8303
8304 case 'f':
8305 switch (name[1])
8306 {
8307 case 'c':
8308 if (name[2] == 'n' &&
8309 name[3] == 't' &&
8310 name[4] == 'l')
8311 { /* fcntl */
8312 return -KEY_fcntl;
8313 }
8314
8315 goto unknown;
8316
8317 case 'l':
8318 if (name[2] == 'o' &&
8319 name[3] == 'c' &&
8320 name[4] == 'k')
8321 { /* flock */
8322 return -KEY_flock;
8323 }
8324
8325 goto unknown;
8326
8327 default:
8328 goto unknown;
8329 }
8330
0d863452
RH
8331 case 'g':
8332 if (name[1] == 'i' &&
8333 name[2] == 'v' &&
8334 name[3] == 'e' &&
8335 name[4] == 'n')
8336 { /* given */
5458a98a 8337 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
0d863452
RH
8338 }
8339
8340 goto unknown;
8341
4c3bbe0f
MHM
8342 case 'i':
8343 switch (name[1])
8344 {
8345 case 'n':
8346 if (name[2] == 'd' &&
8347 name[3] == 'e' &&
8348 name[4] == 'x')
8349 { /* index */
8350 return -KEY_index;
8351 }
8352
8353 goto unknown;
8354
8355 case 'o':
8356 if (name[2] == 'c' &&
8357 name[3] == 't' &&
8358 name[4] == 'l')
8359 { /* ioctl */
8360 return -KEY_ioctl;
8361 }
8362
8363 goto unknown;
8364
8365 default:
8366 goto unknown;
8367 }
8368
8369 case 'l':
8370 switch (name[1])
8371 {
8372 case 'o':
8373 if (name[2] == 'c' &&
8374 name[3] == 'a' &&
8375 name[4] == 'l')
8376 { /* local */
8377 return KEY_local;
8378 }
8379
8380 goto unknown;
8381
8382 case 's':
8383 if (name[2] == 't' &&
8384 name[3] == 'a' &&
8385 name[4] == 't')
8386 { /* lstat */
8387 return -KEY_lstat;
8388 }
8389
8390 goto unknown;
8391
8392 default:
8393 goto unknown;
8394 }
8395
8396 case 'm':
8397 if (name[1] == 'k' &&
8398 name[2] == 'd' &&
8399 name[3] == 'i' &&
8400 name[4] == 'r')
8401 { /* mkdir */
8402 return -KEY_mkdir;
8403 }
8404
8405 goto unknown;
8406
8407 case 'p':
8408 if (name[1] == 'r' &&
8409 name[2] == 'i' &&
8410 name[3] == 'n' &&
8411 name[4] == 't')
8412 { /* print */
8413 return KEY_print;
8414 }
8415
8416 goto unknown;
8417
8418 case 'r':
8419 switch (name[1])
8420 {
8421 case 'e':
8422 if (name[2] == 's' &&
8423 name[3] == 'e' &&
8424 name[4] == 't')
8425 { /* reset */
8426 return -KEY_reset;
8427 }
8428
8429 goto unknown;
8430
8431 case 'm':
8432 if (name[2] == 'd' &&
8433 name[3] == 'i' &&
8434 name[4] == 'r')
8435 { /* rmdir */
8436 return -KEY_rmdir;
8437 }
8438
8439 goto unknown;
8440
8441 default:
8442 goto unknown;
8443 }
8444
8445 case 's':
8446 switch (name[1])
8447 {
8448 case 'e':
8449 if (name[2] == 'm' &&
8450 name[3] == 'o' &&
8451 name[4] == 'p')
8452 { /* semop */
8453 return -KEY_semop;
8454 }
8455
8456 goto unknown;
8457
8458 case 'h':
8459 if (name[2] == 'i' &&
8460 name[3] == 'f' &&
8461 name[4] == 't')
8462 { /* shift */
8463 return -KEY_shift;
8464 }
8465
8466 goto unknown;
8467
8468 case 'l':
8469 if (name[2] == 'e' &&
8470 name[3] == 'e' &&
8471 name[4] == 'p')
8472 { /* sleep */
8473 return -KEY_sleep;
8474 }
8475
8476 goto unknown;
8477
8478 case 'p':
8479 if (name[2] == 'l' &&
8480 name[3] == 'i' &&
8481 name[4] == 't')
8482 { /* split */
8483 return KEY_split;
8484 }
8485
8486 goto unknown;
8487
8488 case 'r':
8489 if (name[2] == 'a' &&
8490 name[3] == 'n' &&
8491 name[4] == 'd')
8492 { /* srand */
8493 return -KEY_srand;
8494 }
8495
8496 goto unknown;
8497
8498 case 't':
952306ac
RGS
8499 switch (name[2])
8500 {
8501 case 'a':
8502 if (name[3] == 't' &&
8503 name[4] == 'e')
8504 { /* state */
5458a98a 8505 return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
952306ac 8506 }
4c3bbe0f 8507
952306ac
RGS
8508 goto unknown;
8509
8510 case 'u':
8511 if (name[3] == 'd' &&
8512 name[4] == 'y')
8513 { /* study */
8514 return KEY_study;
8515 }
8516
8517 goto unknown;
8518
8519 default:
8520 goto unknown;
8521 }
4c3bbe0f
MHM
8522
8523 default:
8524 goto unknown;
8525 }
8526
8527 case 't':
8528 if (name[1] == 'i' &&
8529 name[2] == 'm' &&
8530 name[3] == 'e' &&
8531 name[4] == 's')
8532 { /* times */
8533 return -KEY_times;
8534 }
8535
8536 goto unknown;
8537
8538 case 'u':
8539 switch (name[1])
8540 {
8541 case 'm':
8542 if (name[2] == 'a' &&
8543 name[3] == 's' &&
8544 name[4] == 'k')
8545 { /* umask */
8546 return -KEY_umask;
8547 }
8548
8549 goto unknown;
8550
8551 case 'n':
8552 switch (name[2])
8553 {
8554 case 'd':
8555 if (name[3] == 'e' &&
8556 name[4] == 'f')
8557 { /* undef */
8558 return KEY_undef;
8559 }
8560
8561 goto unknown;
8562
8563 case 't':
8564 if (name[3] == 'i')
8565 {
8566 switch (name[4])
8567 {
8568 case 'e':
8569 { /* untie */
8570 return KEY_untie;
8571 }
8572
4c3bbe0f
MHM
8573 case 'l':
8574 { /* until */
8575 return KEY_until;
8576 }
8577
4c3bbe0f
MHM
8578 default:
8579 goto unknown;
8580 }
8581 }
8582
8583 goto unknown;
8584
8585 default:
8586 goto unknown;
8587 }
8588
8589 case 't':
8590 if (name[2] == 'i' &&
8591 name[3] == 'm' &&
8592 name[4] == 'e')
8593 { /* utime */
8594 return -KEY_utime;
8595 }
8596
8597 goto unknown;
8598
8599 default:
8600 goto unknown;
8601 }
8602
8603 case 'w':
8604 switch (name[1])
8605 {
8606 case 'h':
8607 if (name[2] == 'i' &&
8608 name[3] == 'l' &&
8609 name[4] == 'e')
8610 { /* while */
8611 return KEY_while;
8612 }
8613
8614 goto unknown;
8615
8616 case 'r':
8617 if (name[2] == 'i' &&
8618 name[3] == 't' &&
8619 name[4] == 'e')
8620 { /* write */
8621 return -KEY_write;
8622 }
8623
8624 goto unknown;
8625
8626 default:
8627 goto unknown;
8628 }
8629
8630 default:
8631 goto unknown;
e2e1dd5a 8632 }
4c3bbe0f
MHM
8633
8634 case 6: /* 33 tokens of length 6 */
8635 switch (name[0])
8636 {
8637 case 'a':
8638 if (name[1] == 'c' &&
8639 name[2] == 'c' &&
8640 name[3] == 'e' &&
8641 name[4] == 'p' &&
8642 name[5] == 't')
8643 { /* accept */
8644 return -KEY_accept;
8645 }
8646
8647 goto unknown;
8648
8649 case 'c':
8650 switch (name[1])
8651 {
8652 case 'a':
8653 if (name[2] == 'l' &&
8654 name[3] == 'l' &&
8655 name[4] == 'e' &&
8656 name[5] == 'r')
8657 { /* caller */
8658 return -KEY_caller;
8659 }
8660
8661 goto unknown;
8662
8663 case 'h':
8664 if (name[2] == 'r' &&
8665 name[3] == 'o' &&
8666 name[4] == 'o' &&
8667 name[5] == 't')
8668 { /* chroot */
8669 return -KEY_chroot;
8670 }
8671
8672 goto unknown;
8673
8674 default:
8675 goto unknown;
8676 }
8677
8678 case 'd':
8679 if (name[1] == 'e' &&
8680 name[2] == 'l' &&
8681 name[3] == 'e' &&
8682 name[4] == 't' &&
8683 name[5] == 'e')
8684 { /* delete */
8685 return KEY_delete;
8686 }
8687
8688 goto unknown;
8689
8690 case 'e':
8691 switch (name[1])
8692 {
8693 case 'l':
8694 if (name[2] == 's' &&
8695 name[3] == 'e' &&
8696 name[4] == 'i' &&
8697 name[5] == 'f')
8698 { /* elseif */
9b387841 8699 Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
4c3bbe0f
MHM
8700 }
8701
8702 goto unknown;
8703
8704 case 'x':
8705 if (name[2] == 'i' &&
8706 name[3] == 's' &&
8707 name[4] == 't' &&
8708 name[5] == 's')
8709 { /* exists */
8710 return KEY_exists;
8711 }
8712
8713 goto unknown;
8714
8715 default:
8716 goto unknown;
8717 }
8718
8719 case 'f':
8720 switch (name[1])
8721 {
8722 case 'i':
8723 if (name[2] == 'l' &&
8724 name[3] == 'e' &&
8725 name[4] == 'n' &&
8726 name[5] == 'o')
8727 { /* fileno */
8728 return -KEY_fileno;
8729 }
8730
8731 goto unknown;
8732
8733 case 'o':
8734 if (name[2] == 'r' &&
8735 name[3] == 'm' &&
8736 name[4] == 'a' &&
8737 name[5] == 't')
8738 { /* format */
8739 return KEY_format;
8740 }
8741
8742 goto unknown;
8743
8744 default:
8745 goto unknown;
8746 }
8747
8748 case 'g':
8749 if (name[1] == 'm' &&
8750 name[2] == 't' &&
8751 name[3] == 'i' &&
8752 name[4] == 'm' &&
8753 name[5] == 'e')
8754 { /* gmtime */
8755 return -KEY_gmtime;
8756 }
8757
8758 goto unknown;
8759
8760 case 'l':
8761 switch (name[1])
8762 {
8763 case 'e':
8764 if (name[2] == 'n' &&
8765 name[3] == 'g' &&
8766 name[4] == 't' &&
8767 name[5] == 'h')
8768 { /* length */
8769 return -KEY_length;
8770 }
8771
8772 goto unknown;
8773
8774 case 'i':
8775 if (name[2] == 's' &&
8776 name[3] == 't' &&
8777 name[4] == 'e' &&
8778 name[5] == 'n')
8779 { /* listen */
8780 return -KEY_listen;
8781 }
8782
8783 goto unknown;
8784
8785 default:
8786 goto unknown;
8787 }
8788
8789 case 'm':
8790 if (name[1] == 's' &&
8791 name[2] == 'g')
8792 {
8793 switch (name[3])
8794 {
8795 case 'c':
8796 if (name[4] == 't' &&
8797 name[5] == 'l')
8798 { /* msgctl */
8799 return -KEY_msgctl;
8800 }
8801
8802 goto unknown;
8803
8804 case 'g':
8805 if (name[4] == 'e' &&
8806 name[5] == 't')
8807 { /* msgget */
8808 return -KEY_msgget;
8809 }
8810
8811 goto unknown;
8812
8813 case 'r':
8814 if (name[4] == 'c' &&
8815 name[5] == 'v')
8816 { /* msgrcv */
8817 return -KEY_msgrcv;
8818 }
8819
8820 goto unknown;
8821
8822 case 's':
8823 if (name[4] == 'n' &&
8824 name[5] == 'd')
8825 { /* msgsnd */
8826 return -KEY_msgsnd;
8827 }
8828
8829 goto unknown;
8830
8831 default:
8832 goto unknown;
8833 }
8834 }
8835
8836 goto unknown;
8837
8838 case 'p':
8839 if (name[1] == 'r' &&
8840 name[2] == 'i' &&
8841 name[3] == 'n' &&
8842 name[4] == 't' &&
8843 name[5] == 'f')
8844 { /* printf */
8845 return KEY_printf;
8846 }
8847
8848 goto unknown;
8849
8850 case 'r':
8851 switch (name[1])
8852 {
8853 case 'e':
8854 switch (name[2])
8855 {
8856 case 'n':
8857 if (name[3] == 'a' &&
8858 name[4] == 'm' &&
8859 name[5] == 'e')
8860 { /* rename */
8861 return -KEY_rename;
8862 }
8863
8864 goto unknown;
8865
8866 case 't':
8867 if (name[3] == 'u' &&
8868 name[4] == 'r' &&
8869 name[5] == 'n')
8870 { /* return */
8871 return KEY_return;
8872 }
8873
8874 goto unknown;
8875
8876 default:
8877 goto unknown;
8878 }
8879
8880 case 'i':
8881 if (name[2] == 'n' &&
8882 name[3] == 'd' &&
8883 name[4] == 'e' &&
8884 name[5] == 'x')
8885 { /* rindex */
8886 return -KEY_rindex;
8887 }
8888
8889 goto unknown;
8890
8891 default:
8892 goto unknown;
8893 }
8894
8895 case 's':
8896 switch (name[1])
8897 {
8898 case 'c':
8899 if (name[2] == 'a' &&
8900 name[3] == 'l' &&
8901 name[4] == 'a' &&
8902 name[5] == 'r')
8903 { /* scalar */
8904 return KEY_scalar;
8905 }
8906
8907 goto unknown;
8908
8909 case 'e':
8910 switch (name[2])
8911 {
8912 case 'l':
8913 if (name[3] == 'e' &&
8914 name[4] == 'c' &&
8915 name[5] == 't')
8916 { /* select */
8917 return -KEY_select;
8918 }
8919
8920 goto unknown;
8921
8922 case 'm':
8923 switch (name[3])
8924 {
8925 case 'c':
8926 if (name[4] == 't' &&
8927 name[5] == 'l')
8928 { /* semctl */
8929 return -KEY_semctl;
8930 }
8931
8932 goto unknown;
8933
8934 case 'g':
8935 if (name[4] == 'e' &&
8936 name[5] == 't')
8937 { /* semget */
8938 return -KEY_semget;
8939 }
8940
8941 goto unknown;
8942
8943 default:
8944 goto unknown;
8945 }
8946
8947 default:
8948 goto unknown;
8949 }
8950
8951 case 'h':
8952 if (name[2] == 'm')
8953 {
8954 switch (name[3])
8955 {
8956 case 'c':
8957 if (name[4] == 't' &&
8958 name[5] == 'l')
8959 { /* shmctl */
8960 return -KEY_shmctl;
8961 }
8962
8963 goto unknown;
8964
8965 case 'g':
8966 if (name[4] == 'e' &&
8967 name[5] == 't')
8968 { /* shmget */
8969 return -KEY_shmget;
8970 }
8971
8972 goto unknown;
8973
8974 default:
8975 goto unknown;
8976 }
8977 }
8978
8979 goto unknown;
8980
8981 case 'o':
8982 if (name[2] == 'c' &&
8983 name[3] == 'k' &&
8984 name[4] == 'e' &&
8985 name[5] == 't')
8986 { /* socket */
8987 return -KEY_socket;
8988 }
8989
8990 goto unknown;
8991
8992 case 'p':
8993 if (name[2] == 'l' &&
8994 name[3] == 'i' &&
8995 name[4] == 'c' &&
8996 name[5] == 'e')
8997 { /* splice */
8998 return -KEY_splice;
8999 }
9000
9001 goto unknown;
9002
9003 case 'u':
9004 if (name[2] == 'b' &&
9005 name[3] == 's' &&
9006 name[4] == 't' &&
9007 name[5] == 'r')
9008 { /* substr */
9009 return -KEY_substr;
9010 }
9011
9012 goto unknown;
9013
9014 case 'y':
9015 if (name[2] == 's' &&
9016 name[3] == 't' &&
9017 name[4] == 'e' &&
9018 name[5] == 'm')
9019 { /* system */
9020 return -KEY_system;
9021 }
9022
9023 goto unknown;
9024
9025 default:
9026 goto unknown;
9027 }
9028
9029 case 'u':
9030 if (name[1] == 'n')
9031 {
9032 switch (name[2])
9033 {
9034 case 'l':
9035 switch (name[3])
9036 {
9037 case 'e':
9038 if (name[4] == 's' &&
9039 name[5] == 's')
9040 { /* unless */
9041 return KEY_unless;
9042 }
9043
9044 goto unknown;
9045
9046 case 'i':
9047 if (name[4] == 'n' &&
9048 name[5] == 'k')
9049 { /* unlink */
9050 return -KEY_unlink;
9051 }
9052
9053 goto unknown;
9054
9055 default:
9056 goto unknown;
9057 }
9058
9059 case 'p':
9060 if (name[3] == 'a' &&
9061 name[4] == 'c' &&
9062 name[5] == 'k')
9063 { /* unpack */
9064 return -KEY_unpack;
9065 }
9066
9067 goto unknown;
9068
9069 default:
9070 goto unknown;
9071 }
9072 }
9073
9074 goto unknown;
9075
9076 case 'v':
9077 if (name[1] == 'a' &&
9078 name[2] == 'l' &&
9079 name[3] == 'u' &&
9080 name[4] == 'e' &&
9081 name[5] == 's')
9082 { /* values */
9083 return -KEY_values;
9084 }
9085
9086 goto unknown;
9087
9088 default:
9089 goto unknown;
e2e1dd5a 9090 }
4c3bbe0f 9091
0d863452 9092 case 7: /* 29 tokens of length 7 */
4c3bbe0f
MHM
9093 switch (name[0])
9094 {
9095 case 'D':
9096 if (name[1] == 'E' &&
9097 name[2] == 'S' &&
9098 name[3] == 'T' &&
9099 name[4] == 'R' &&
9100 name[5] == 'O' &&
9101 name[6] == 'Y')
9102 { /* DESTROY */
9103 return KEY_DESTROY;
9104 }
9105
9106 goto unknown;
9107
9108 case '_':
9109 if (name[1] == '_' &&
9110 name[2] == 'E' &&
9111 name[3] == 'N' &&
9112 name[4] == 'D' &&
9113 name[5] == '_' &&
9114 name[6] == '_')
9115 { /* __END__ */
9116 return KEY___END__;
9117 }
9118
9119 goto unknown;
9120
9121 case 'b':
9122 if (name[1] == 'i' &&
9123 name[2] == 'n' &&
9124 name[3] == 'm' &&
9125 name[4] == 'o' &&
9126 name[5] == 'd' &&
9127 name[6] == 'e')
9128 { /* binmode */
9129 return -KEY_binmode;
9130 }
9131
9132 goto unknown;
9133
9134 case 'c':
9135 if (name[1] == 'o' &&
9136 name[2] == 'n' &&
9137 name[3] == 'n' &&
9138 name[4] == 'e' &&
9139 name[5] == 'c' &&
9140 name[6] == 't')
9141 { /* connect */
9142 return -KEY_connect;
9143 }
9144
9145 goto unknown;
9146
9147 case 'd':
9148 switch (name[1])
9149 {
9150 case 'b':
9151 if (name[2] == 'm' &&
9152 name[3] == 'o' &&
9153 name[4] == 'p' &&
9154 name[5] == 'e' &&
9155 name[6] == 'n')
9156 { /* dbmopen */
9157 return -KEY_dbmopen;
9158 }
9159
9160 goto unknown;
9161
9162 case 'e':
0d863452
RH
9163 if (name[2] == 'f')
9164 {
9165 switch (name[3])
9166 {
9167 case 'a':
9168 if (name[4] == 'u' &&
9169 name[5] == 'l' &&
9170 name[6] == 't')
9171 { /* default */
5458a98a 9172 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
0d863452
RH
9173 }
9174
9175 goto unknown;
9176
9177 case 'i':
9178 if (name[4] == 'n' &&
952306ac
RGS
9179 name[5] == 'e' &&
9180 name[6] == 'd')
9181 { /* defined */
9182 return KEY_defined;
9183 }
4c3bbe0f 9184
952306ac 9185 goto unknown;
4c3bbe0f 9186
952306ac
RGS
9187 default:
9188 goto unknown;
9189 }
0d863452
RH
9190 }
9191
9192 goto unknown;
9193
9194 default:
9195 goto unknown;
9196 }
4c3bbe0f
MHM
9197
9198 case 'f':
9199 if (name[1] == 'o' &&
9200 name[2] == 'r' &&
9201 name[3] == 'e' &&
9202 name[4] == 'a' &&
9203 name[5] == 'c' &&
9204 name[6] == 'h')
9205 { /* foreach */
9206 return KEY_foreach;
9207 }
9208
9209 goto unknown;
9210
9211 case 'g':
9212 if (name[1] == 'e' &&
9213 name[2] == 't' &&
9214 name[3] == 'p')
9215 {
9216 switch (name[4])
9217 {
9218 case 'g':
9219 if (name[5] == 'r' &&
9220 name[6] == 'p')
9221 { /* getpgrp */
9222 return -KEY_getpgrp;
9223 }
9224
9225 goto unknown;
9226
9227 case 'p':
9228 if (name[5] == 'i' &&
9229 name[6] == 'd')
9230 { /* getppid */
9231 return -KEY_getppid;
9232 }
9233
9234 goto unknown;
9235
9236 default:
9237 goto unknown;
9238 }
9239 }
9240
9241 goto unknown;
9242
9243 case 'l':
9244 if (name[1] == 'c' &&
9245 name[2] == 'f' &&
9246 name[3] == 'i' &&
9247 name[4] == 'r' &&
9248 name[5] == 's' &&
9249 name[6] == 't')
9250 { /* lcfirst */
9251 return -KEY_lcfirst;
9252 }
9253
9254 goto unknown;
9255
9256 case 'o':
9257 if (name[1] == 'p' &&
9258 name[2] == 'e' &&
9259 name[3] == 'n' &&
9260 name[4] == 'd' &&
9261 name[5] == 'i' &&
9262 name[6] == 'r')
9263 { /* opendir */
9264 return -KEY_opendir;
9265 }
9266
9267 goto unknown;
9268
9269 case 'p':
9270 if (name[1] == 'a' &&
9271 name[2] == 'c' &&
9272 name[3] == 'k' &&
9273 name[4] == 'a' &&
9274 name[5] == 'g' &&
9275 name[6] == 'e')
9276 { /* package */
9277 return KEY_package;
9278 }
9279
9280 goto unknown;
9281
9282 case 'r':
9283 if (name[1] == 'e')
9284 {
9285 switch (name[2])
9286 {
9287 case 'a':
9288 if (name[3] == 'd' &&
9289 name[4] == 'd' &&
9290 name[5] == 'i' &&
9291 name[6] == 'r')
9292 { /* readdir */
9293 return -KEY_readdir;
9294 }
9295
9296 goto unknown;
9297
9298 case 'q':
9299 if (name[3] == 'u' &&
9300 name[4] == 'i' &&
9301 name[5] == 'r' &&
9302 name[6] == 'e')
9303 { /* require */
9304 return KEY_require;
9305 }
9306
9307 goto unknown;
9308
9309 case 'v':
9310 if (name[3] == 'e' &&
9311 name[4] == 'r' &&
9312 name[5] == 's' &&
9313 name[6] == 'e')
9314 { /* reverse */
9315 return -KEY_reverse;
9316 }
9317
9318 goto unknown;
9319
9320 default:
9321 goto unknown;
9322 }
9323 }
9324
9325 goto unknown;
9326
9327 case 's':
9328 switch (name[1])
9329 {
9330 case 'e':
9331 switch (name[2])
9332 {
9333 case 'e':
9334 if (name[3] == 'k' &&
9335 name[4] == 'd' &&
9336 name[5] == 'i' &&
9337 name[6] == 'r')
9338 { /* seekdir */
9339 return -KEY_seekdir;
9340 }
9341
9342 goto unknown;
9343
9344 case 't':
9345 if (name[3] == 'p' &&
9346 name[4] == 'g' &&
9347 name[5] == 'r' &&
9348 name[6] == 'p')
9349 { /* setpgrp */
9350 return -KEY_setpgrp;
9351 }
9352
9353 goto unknown;
9354
9355 default:
9356 goto unknown;
9357 }
9358
9359 case 'h':
9360 if (name[2] == 'm' &&
9361 name[3] == 'r' &&
9362 name[4] == 'e' &&
9363 name[5] == 'a' &&
9364 name[6] == 'd')
9365 { /* shmread */
9366 return -KEY_shmread;
9367 }
9368
9369 goto unknown;
9370
9371 case 'p':
9372 if (name[2] == 'r' &&
9373 name[3] == 'i' &&
9374 name[4] == 'n' &&
9375 name[5] == 't' &&
9376 name[6] == 'f')
9377 { /* sprintf */
9378 return -KEY_sprintf;
9379 }
9380
9381 goto unknown;
9382
9383 case 'y':
9384 switch (name[2])
9385 {
9386 case 'm':
9387 if (name[3] == 'l' &&
9388 name[4] == 'i' &&
9389 name[5] == 'n' &&
9390 name[6] == 'k')
9391 { /* symlink */
9392 return -KEY_symlink;
9393 }
9394
9395 goto unknown;
9396
9397 case 's':
9398 switch (name[3])
9399 {
9400 case 'c':
9401 if (name[4] == 'a' &&
9402 name[5] == 'l' &&
9403 name[6] == 'l')
9404 { /* syscall */
9405 return -KEY_syscall;
9406 }
9407
9408 goto unknown;
9409
9410 case 'o':
9411 if (name[4] == 'p' &&
9412 name[5] == 'e' &&
9413 name[6] == 'n')
9414 { /* sysopen */
9415 return -KEY_sysopen;
9416 }
9417
9418 goto unknown;
9419
9420 case 'r':
9421 if (name[4] == 'e' &&
9422 name[5] == 'a' &&
9423 name[6] == 'd')
9424 { /* sysread */
9425 return -KEY_sysread;
9426 }
9427
9428 goto unknown;
9429
9430 case 's':
9431 if (name[4] == 'e' &&
9432 name[5] == 'e' &&
9433 name[6] == 'k')
9434 { /* sysseek */
9435 return -KEY_sysseek;
9436 }
9437
9438 goto unknown;
9439
9440 default:
9441 goto unknown;
9442 }
9443
9444 default:
9445 goto unknown;
9446 }
9447
9448 default:
9449 goto unknown;
9450 }
9451
9452 case 't':
9453 if (name[1] == 'e' &&
9454 name[2] == 'l' &&
9455 name[3] == 'l' &&
9456 name[4] == 'd' &&
9457 name[5] == 'i' &&
9458 name[6] == 'r')
9459 { /* telldir */
9460 return -KEY_telldir;
9461 }
9462
9463 goto unknown;
9464
9465 case 'u':
9466 switch (name[1])
9467 {
9468 case 'c':
9469 if (name[2] == 'f' &&
9470 name[3] == 'i' &&
9471 name[4] == 'r' &&
9472 name[5] == 's' &&
9473 name[6] == 't')
9474 { /* ucfirst */
9475 return -KEY_ucfirst;
9476 }
9477
9478 goto unknown;
9479
9480 case 'n':
9481 if (name[2] == 's' &&
9482 name[3] == 'h' &&
9483 name[4] == 'i' &&
9484 name[5] == 'f' &&
9485 name[6] == 't')
9486 { /* unshift */
9487 return -KEY_unshift;
9488 }
9489
9490 goto unknown;
9491
9492 default:
9493 goto unknown;
9494 }
9495
9496 case 'w':
9497 if (name[1] == 'a' &&
9498 name[2] == 'i' &&
9499 name[3] == 't' &&
9500 name[4] == 'p' &&
9501 name[5] == 'i' &&
9502 name[6] == 'd')
9503 { /* waitpid */
9504 return -KEY_waitpid;
9505 }
9506
9507 goto unknown;
9508
9509 default:
9510 goto unknown;
9511 }
9512
9513 case 8: /* 26 tokens of length 8 */
9514 switch (name[0])
9515 {
9516 case 'A':
9517 if (name[1] == 'U' &&
9518 name[2] == 'T' &&
9519 name[3] == 'O' &&
9520 name[4] == 'L' &&
9521 name[5] == 'O' &&
9522 name[6] == 'A' &&
9523 name[7] == 'D')
9524 { /* AUTOLOAD */
9525 return KEY_AUTOLOAD;
9526 }
9527
9528 goto unknown;
9529
9530 case '_':
9531 if (name[1] == '_')
9532 {
9533 switch (name[2])
9534 {
9535 case 'D':
9536 if (name[3] == 'A' &&
9537 name[4] == 'T' &&
9538 name[5] == 'A' &&
9539 name[6] == '_' &&
9540 name[7] == '_')
9541 { /* __DATA__ */
9542 return KEY___DATA__;
9543 }
9544
9545 goto unknown;
9546
9547 case 'F':
9548 if (name[3] == 'I' &&
9549 name[4] == 'L' &&
9550 name[5] == 'E' &&
9551 name[6] == '_' &&
9552 name[7] == '_')
9553 { /* __FILE__ */
9554 return -KEY___FILE__;
9555 }
9556
9557 goto unknown;
9558
9559 case 'L':
9560 if (name[3] == 'I' &&
9561 name[4] == 'N' &&
9562 name[5] == 'E' &&
9563 name[6] == '_' &&
9564 name[7] == '_')
9565 { /* __LINE__ */
9566 return -KEY___LINE__;
9567 }
9568
9569 goto unknown;
9570
9571 default:
9572 goto unknown;
9573 }
9574 }
9575
9576 goto unknown;
9577
9578 case 'c':
9579 switch (name[1])
9580 {
9581 case 'l':
9582 if (name[2] == 'o' &&
9583 name[3] == 's' &&
9584 name[4] == 'e' &&
9585 name[5] == 'd' &&
9586 name[6] == 'i' &&
9587 name[7] == 'r')
9588 { /* closedir */
9589 return -KEY_closedir;
9590 }
9591
9592 goto unknown;
9593
9594 case 'o':
9595 if (name[2] == 'n' &&
9596 name[3] == 't' &&
9597 name[4] == 'i' &&
9598 name[5] == 'n' &&
9599 name[6] == 'u' &&
9600 name[7] == 'e')
9601 { /* continue */
9602 return -KEY_continue;
9603 }
9604
9605 goto unknown;
9606
9607 default:
9608 goto unknown;
9609 }
9610
9611 case 'd':
9612 if (name[1] == 'b' &&
9613 name[2] == 'm' &&
9614 name[3] == 'c' &&
9615 name[4] == 'l' &&
9616 name[5] == 'o' &&
9617 name[6] == 's' &&
9618 name[7] == 'e')
9619 { /* dbmclose */
9620 return -KEY_dbmclose;
9621 }
9622
9623 goto unknown;
9624
9625 case 'e':
9626 if (name[1] == 'n' &&
9627 name[2] == 'd')
9628 {
9629 switch (name[3])
9630 {
9631 case 'g':
9632 if (name[4] == 'r' &&
9633 name[5] == 'e' &&
9634 name[6] == 'n' &&
9635 name[7] == 't')
9636 { /* endgrent */
9637 return -KEY_endgrent;
9638 }
9639
9640 goto unknown;
9641
9642 case 'p':
9643 if (name[4] == 'w' &&
9644 name[5] == 'e' &&
9645 name[6] == 'n' &&
9646 name[7] == 't')
9647 { /* endpwent */
9648 return -KEY_endpwent;
9649 }
9650
9651 goto unknown;
9652
9653 default:
9654 goto unknown;
9655 }
9656 }
9657
9658 goto unknown;
9659
9660 case 'f':
9661 if (name[1] == 'o' &&
9662 name[2] == 'r' &&
9663 name[3] == 'm' &&
9664 name[4] == 'l' &&
9665 name[5] == 'i' &&
9666 name[6] == 'n' &&
9667 name[7] == 'e')
9668 { /* formline */
9669 return -KEY_formline;
9670 }
9671
9672 goto unknown;
9673
9674 case 'g':
9675 if (name[1] == 'e' &&
9676 name[2] == 't')
9677 {
9678 switch (name[3])
9679 {
9680 case 'g':
9681 if (name[4] == 'r')
9682 {
9683 switch (name[5])
9684 {
9685 case 'e':
9686 if (name[6] == 'n' &&
9687 name[7] == 't')
9688 { /* getgrent */
9689 return -KEY_getgrent;
9690 }
9691
9692 goto unknown;
9693
9694 case 'g':
9695 if (name[6] == 'i' &&
9696 name[7] == 'd')
9697 { /* getgrgid */
9698 return -KEY_getgrgid;
9699 }
9700
9701 goto unknown;
9702
9703 case 'n':
9704 if (name[6] == 'a' &&
9705 name[7] == 'm')
9706 { /* getgrnam */
9707 return -KEY_getgrnam;
9708 }
9709
9710 goto unknown;
9711
9712 default:
9713 goto unknown;
9714 }
9715 }
9716
9717 goto unknown;
9718
9719 case 'l':
9720 if (name[4] == 'o' &&
9721 name[5] == 'g' &&
9722 name[6] == 'i' &&
9723 name[7] == 'n')
9724 { /* getlogin */
9725 return -KEY_getlogin;
9726 }
9727
9728 goto unknown;
9729
9730 case 'p':
9731 if (name[4] == 'w')
9732 {
9733 switch (name[5])
9734 {
9735 case 'e':
9736 if (name[6] == 'n' &&
9737 name[7] == 't')
9738 { /* getpwent */
9739 return -KEY_getpwent;
9740 }
9741
9742 goto unknown;
9743
9744 case 'n':
9745 if (name[6] == 'a' &&
9746 name[7] == 'm')
9747 { /* getpwnam */
9748 return -KEY_getpwnam;
9749 }
9750
9751 goto unknown;
9752
9753 case 'u':
9754 if (name[6] == 'i' &&
9755 name[7] == 'd')
9756 { /* getpwuid */
9757 return -KEY_getpwuid;
9758 }
9759
9760 goto unknown;
9761
9762 default:
9763 goto unknown;
9764 }
9765 }
9766
9767 goto unknown;
9768
9769 default:
9770 goto unknown;
9771 }
9772 }
9773
9774 goto unknown;
9775
9776 case 'r':
9777 if (name[1] == 'e' &&
9778 name[2] == 'a' &&
9779 name[3] == 'd')
9780 {
9781 switch (name[4])
9782 {
9783 case 'l':
9784 if (name[5] == 'i' &&
9785 name[6] == 'n')
9786 {
9787 switch (name[7])
9788 {
9789 case 'e':
9790 { /* readline */
9791 return -KEY_readline;
9792 }
9793
4c3bbe0f
MHM
9794 case 'k':
9795 { /* readlink */
9796 return -KEY_readlink;
9797 }
9798
4c3bbe0f
MHM
9799 default:
9800 goto unknown;
9801 }
9802 }
9803
9804 goto unknown;
9805
9806 case 'p':
9807 if (name[5] == 'i' &&
9808 name[6] == 'p' &&
9809 name[7] == 'e')
9810 { /* readpipe */
9811 return -KEY_readpipe;
9812 }
9813
9814 goto unknown;
9815
9816 default:
9817 goto unknown;
9818 }
9819 }
9820
9821 goto unknown;
9822
9823 case 's':
9824 switch (name[1])
9825 {
9826 case 'e':
9827 if (name[2] == 't')
9828 {
9829 switch (name[3])
9830 {
9831 case 'g':
9832 if (name[4] == 'r' &&
9833 name[5] == 'e' &&
9834 name[6] == 'n' &&
9835 name[7] == 't')
9836 { /* setgrent */
9837 return -KEY_setgrent;
9838 }
9839
9840 goto unknown;
9841
9842 case 'p':
9843 if (name[4] == 'w' &&
9844 name[5] == 'e' &&
9845 name[6] == 'n' &&
9846 name[7] == 't')
9847 { /* setpwent */
9848 return -KEY_setpwent;
9849 }
9850
9851 goto unknown;
9852
9853 default:
9854 goto unknown;
9855 }
9856 }
9857
9858 goto unknown;
9859
9860 case 'h':
9861 switch (name[2])
9862 {
9863 case 'm':
9864 if (name[3] == 'w' &&
9865 name[4] == 'r' &&
9866 name[5] == 'i' &&
9867 name[6] == 't' &&
9868 name[7] == 'e')
9869 { /* shmwrite */
9870 return -KEY_shmwrite;
9871 }
9872
9873 goto unknown;
9874
9875 case 'u':
9876 if (name[3] == 't' &&
9877 name[4] == 'd' &&
9878 name[5] == 'o' &&
9879 name[6] == 'w' &&
9880 name[7] == 'n')
9881 { /* shutdown */
9882 return -KEY_shutdown;
9883 }
9884
9885 goto unknown;
9886
9887 default:
9888 goto unknown;
9889 }
9890
9891 case 'y':
9892 if (name[2] == 's' &&
9893 name[3] == 'w' &&
9894 name[4] == 'r' &&
9895 name[5] == 'i' &&
9896 name[6] == 't' &&
9897 name[7] == 'e')
9898 { /* syswrite */
9899 return -KEY_syswrite;
9900 }
9901
9902 goto unknown;
9903
9904 default:
9905 goto unknown;
9906 }
9907
9908 case 't':
9909 if (name[1] == 'r' &&
9910 name[2] == 'u' &&
9911 name[3] == 'n' &&
9912 name[4] == 'c' &&
9913 name[5] == 'a' &&
9914 name[6] == 't' &&
9915 name[7] == 'e')
9916 { /* truncate */
9917 return -KEY_truncate;
9918 }
9919
9920 goto unknown;
9921
9922 default:
9923 goto unknown;
9924 }
9925
3c10abe3 9926 case 9: /* 9 tokens of length 9 */
4c3bbe0f
MHM
9927 switch (name[0])
9928 {
3c10abe3
AG
9929 case 'U':
9930 if (name[1] == 'N' &&
9931 name[2] == 'I' &&
9932 name[3] == 'T' &&
9933 name[4] == 'C' &&
9934 name[5] == 'H' &&
9935 name[6] == 'E' &&
9936 name[7] == 'C' &&
9937 name[8] == 'K')
9938 { /* UNITCHECK */
9939 return KEY_UNITCHECK;
9940 }
9941
9942 goto unknown;
9943
4c3bbe0f
MHM
9944 case 'e':
9945 if (name[1] == 'n' &&
9946 name[2] == 'd' &&
9947 name[3] == 'n' &&
9948 name[4] == 'e' &&
9949 name[5] == 't' &&
9950 name[6] == 'e' &&
9951 name[7] == 'n' &&
9952 name[8] == 't')
9953 { /* endnetent */
9954 return -KEY_endnetent;
9955 }
9956
9957 goto unknown;
9958
9959 case 'g':
9960 if (name[1] == 'e' &&
9961 name[2] == 't' &&
9962 name[3] == 'n' &&
9963 name[4] == 'e' &&
9964 name[5] == 't' &&
9965 name[6] == 'e' &&
9966 name[7] == 'n' &&
9967 name[8] == 't')
9968 { /* getnetent */
9969 return -KEY_getnetent;
9970 }
9971
9972 goto unknown;
9973
9974 case 'l':
9975 if (name[1] == 'o' &&
9976 name[2] == 'c' &&
9977 name[3] == 'a' &&
9978 name[4] == 'l' &&
9979 name[5] == 't' &&
9980 name[6] == 'i' &&
9981 name[7] == 'm' &&
9982 name[8] == 'e')
9983 { /* localtime */
9984 return -KEY_localtime;
9985 }
9986
9987 goto unknown;
9988
9989 case 'p':
9990 if (name[1] == 'r' &&
9991 name[2] == 'o' &&
9992 name[3] == 't' &&
9993 name[4] == 'o' &&
9994 name[5] == 't' &&
9995 name[6] == 'y' &&
9996 name[7] == 'p' &&
9997 name[8] == 'e')
9998 { /* prototype */
9999 return KEY_prototype;
10000 }
10001
10002 goto unknown;
10003
10004 case 'q':
10005 if (name[1] == 'u' &&
10006 name[2] == 'o' &&
10007 name[3] == 't' &&
10008 name[4] == 'e' &&
10009 name[5] == 'm' &&
10010 name[6] == 'e' &&
10011 name[7] == 't' &&
10012 name[8] == 'a')
10013 { /* quotemeta */
10014 return -KEY_quotemeta;
10015 }
10016
10017 goto unknown;
10018
10019 case 'r':
10020 if (name[1] == 'e' &&
10021 name[2] == 'w' &&
10022 name[3] == 'i' &&
10023 name[4] == 'n' &&
10024 name[5] == 'd' &&
10025 name[6] == 'd' &&
10026 name[7] == 'i' &&
10027 name[8] == 'r')
10028 { /* rewinddir */
10029 return -KEY_rewinddir;
10030 }
10031
10032 goto unknown;
10033
10034 case 's':
10035 if (name[1] == 'e' &&
10036 name[2] == 't' &&
10037 name[3] == 'n' &&
10038 name[4] == 'e' &&
10039 name[5] == 't' &&
10040 name[6] == 'e' &&
10041 name[7] == 'n' &&
10042 name[8] == 't')
10043 { /* setnetent */
10044 return -KEY_setnetent;
10045 }
10046
10047 goto unknown;
10048
10049 case 'w':
10050 if (name[1] == 'a' &&
10051 name[2] == 'n' &&
10052 name[3] == 't' &&
10053 name[4] == 'a' &&
10054 name[5] == 'r' &&
10055 name[6] == 'r' &&
10056 name[7] == 'a' &&
10057 name[8] == 'y')
10058 { /* wantarray */
10059 return -KEY_wantarray;
10060 }
10061
10062 goto unknown;
10063
10064 default:
10065 goto unknown;
10066 }
10067
10068 case 10: /* 9 tokens of length 10 */
10069 switch (name[0])
10070 {
10071 case 'e':
10072 if (name[1] == 'n' &&
10073 name[2] == 'd')
10074 {
10075 switch (name[3])
10076 {
10077 case 'h':
10078 if (name[4] == 'o' &&
10079 name[5] == 's' &&
10080 name[6] == 't' &&
10081 name[7] == 'e' &&
10082 name[8] == 'n' &&
10083 name[9] == 't')
10084 { /* endhostent */
10085 return -KEY_endhostent;
10086 }
10087
10088 goto unknown;
10089
10090 case 's':
10091 if (name[4] == 'e' &&
10092 name[5] == 'r' &&
10093 name[6] == 'v' &&
10094 name[7] == 'e' &&
10095 name[8] == 'n' &&
10096 name[9] == 't')
10097 { /* endservent */
10098 return -KEY_endservent;
10099 }
10100
10101 goto unknown;
10102
10103 default:
10104 goto unknown;
10105 }
10106 }
10107
10108 goto unknown;
10109
10110 case 'g':
10111 if (name[1] == 'e' &&
10112 name[2] == 't')
10113 {
10114 switch (name[3])
10115 {
10116 case 'h':
10117 if (name[4] == 'o' &&
10118 name[5] == 's' &&
10119 name[6] == 't' &&
10120 name[7] == 'e' &&
10121 name[8] == 'n' &&
10122 name[9] == 't')
10123 { /* gethostent */
10124 return -KEY_gethostent;
10125 }
10126
10127 goto unknown;
10128
10129 case 's':
10130 switch (name[4])
10131 {
10132 case 'e':
10133 if (name[5] == 'r' &&
10134 name[6] == 'v' &&
10135 name[7] == 'e' &&
10136 name[8] == 'n' &&
10137 name[9] == 't')
10138 { /* getservent */
10139 return -KEY_getservent;
10140 }
10141
10142 goto unknown;
10143
10144 case 'o':
10145 if (name[5] == 'c' &&
10146 name[6] == 'k' &&
10147 name[7] == 'o' &&
10148 name[8] == 'p' &&
10149 name[9] == 't')
10150 { /* getsockopt */
10151 return -KEY_getsockopt;
10152 }
10153
10154 goto unknown;
10155
10156 default:
10157 goto unknown;
10158 }
10159
10160 default:
10161 goto unknown;
10162 }
10163 }
10164
10165 goto unknown;
10166
10167 case 's':
10168 switch (name[1])
10169 {
10170 case 'e':
10171 if (name[2] == 't')
10172 {
10173 switch (name[3])
10174 {
10175 case 'h':
10176 if (name[4] == 'o' &&
10177 name[5] == 's' &&
10178 name[6] == 't' &&
10179 name[7] == 'e' &&
10180 name[8] == 'n' &&
10181 name[9] == 't')
10182 { /* sethostent */
10183 return -KEY_sethostent;
10184 }
10185
10186 goto unknown;
10187
10188 case 's':
10189 switch (name[4])
10190 {
10191 case 'e':
10192 if (name[5] == 'r' &&
10193 name[6] == 'v' &&
10194 name[7] == 'e' &&
10195 name[8] == 'n' &&
10196 name[9] == 't')
10197 { /* setservent */
10198 return -KEY_setservent;
10199 }
10200
10201 goto unknown;
10202
10203 case 'o':
10204 if (name[5] == 'c' &&
10205 name[6] == 'k' &&
10206 name[7] == 'o' &&
10207 name[8] == 'p' &&
10208 name[9] == 't')
10209 { /* setsockopt */
10210 return -KEY_setsockopt;
10211 }
10212
10213 goto unknown;
10214
10215 default:
10216 goto unknown;
10217 }
10218
10219 default:
10220 goto unknown;
10221 }
10222 }
10223
10224 goto unknown;
10225
10226 case 'o':
10227 if (name[2] == 'c' &&
10228 name[3] == 'k' &&
10229 name[4] == 'e' &&
10230 name[5] == 't' &&
10231 name[6] == 'p' &&
10232 name[7] == 'a' &&
10233 name[8] == 'i' &&
10234 name[9] == 'r')
10235 { /* socketpair */
10236 return -KEY_socketpair;
10237 }
10238
10239 goto unknown;
10240
10241 default:
10242 goto unknown;
10243 }
10244
10245 default:
10246 goto unknown;
e2e1dd5a 10247 }
4c3bbe0f
MHM
10248
10249 case 11: /* 8 tokens of length 11 */
10250 switch (name[0])
10251 {
10252 case '_':
10253 if (name[1] == '_' &&
10254 name[2] == 'P' &&
10255 name[3] == 'A' &&
10256 name[4] == 'C' &&
10257 name[5] == 'K' &&
10258 name[6] == 'A' &&
10259 name[7] == 'G' &&
10260 name[8] == 'E' &&
10261 name[9] == '_' &&
10262 name[10] == '_')
10263 { /* __PACKAGE__ */
10264 return -KEY___PACKAGE__;
10265 }
10266
10267 goto unknown;
10268
10269 case 'e':
10270 if (name[1] == 'n' &&
10271 name[2] == 'd' &&
10272 name[3] == 'p' &&
10273 name[4] == 'r' &&
10274 name[5] == 'o' &&
10275 name[6] == 't' &&
10276 name[7] == 'o' &&
10277 name[8] == 'e' &&
10278 name[9] == 'n' &&
10279 name[10] == 't')
10280 { /* endprotoent */
10281 return -KEY_endprotoent;
10282 }
10283
10284 goto unknown;
10285
10286 case 'g':
10287 if (name[1] == 'e' &&
10288 name[2] == 't')
10289 {
10290 switch (name[3])
10291 {
10292 case 'p':
10293 switch (name[4])
10294 {
10295 case 'e':
10296 if (name[5] == 'e' &&
10297 name[6] == 'r' &&
10298 name[7] == 'n' &&
10299 name[8] == 'a' &&
10300 name[9] == 'm' &&
10301 name[10] == 'e')
10302 { /* getpeername */
10303 return -KEY_getpeername;
10304 }
10305
10306 goto unknown;
10307
10308 case 'r':
10309 switch (name[5])
10310 {
10311 case 'i':
10312 if (name[6] == 'o' &&
10313 name[7] == 'r' &&
10314 name[8] == 'i' &&
10315 name[9] == 't' &&
10316 name[10] == 'y')
10317 { /* getpriority */
10318 return -KEY_getpriority;
10319 }
10320
10321 goto unknown;
10322
10323 case 'o':
10324 if (name[6] == 't' &&
10325 name[7] == 'o' &&
10326 name[8] == 'e' &&
10327 name[9] == 'n' &&
10328 name[10] == 't')
10329 { /* getprotoent */
10330 return -KEY_getprotoent;
10331 }
10332
10333 goto unknown;
10334
10335 default:
10336 goto unknown;
10337 }
10338
10339 default:
10340 goto unknown;
10341 }
10342
10343 case 's':
10344 if (name[4] == 'o' &&
10345 name[5] == 'c' &&
10346 name[6] == 'k' &&
10347 name[7] == 'n' &&
10348 name[8] == 'a' &&
10349 name[9] == 'm' &&
10350 name[10] == 'e')
10351 { /* getsockname */
10352 return -KEY_getsockname;
10353 }
10354
10355 goto unknown;
10356
10357 default:
10358 goto unknown;
10359 }
10360 }
10361
10362 goto unknown;
10363
10364 case 's':
10365 if (name[1] == 'e' &&
10366 name[2] == 't' &&
10367 name[3] == 'p' &&
10368 name[4] == 'r')
10369 {
10370 switch (name[5])
10371 {
10372 case 'i':
10373 if (name[6] == 'o' &&
10374 name[7] == 'r' &&
10375 name[8] == 'i' &&
10376 name[9] == 't' &&
10377 name[10] == 'y')
10378 { /* setpriority */
10379 return -KEY_setpriority;
10380 }
10381
10382 goto unknown;
10383
10384 case 'o':
10385 if (name[6] == 't' &&
10386 name[7] == 'o' &&
10387 name[8] == 'e' &&
10388 name[9] == 'n' &&
10389 name[10] == 't')
10390 { /* setprotoent */
10391 return -KEY_setprotoent;
10392 }
10393
10394 goto unknown;
10395
10396 default:
10397 goto unknown;
10398 }
10399 }
10400
10401 goto unknown;
10402
10403 default:
10404 goto unknown;
e2e1dd5a 10405 }
4c3bbe0f
MHM
10406
10407 case 12: /* 2 tokens of length 12 */
10408 if (name[0] == 'g' &&
10409 name[1] == 'e' &&
10410 name[2] == 't' &&
10411 name[3] == 'n' &&
10412 name[4] == 'e' &&
10413 name[5] == 't' &&
10414 name[6] == 'b' &&
10415 name[7] == 'y')
10416 {
10417 switch (name[8])
10418 {
10419 case 'a':
10420 if (name[9] == 'd' &&
10421 name[10] == 'd' &&
10422 name[11] == 'r')
10423 { /* getnetbyaddr */
10424 return -KEY_getnetbyaddr;
10425 }
10426
10427 goto unknown;
10428
10429 case 'n':
10430 if (name[9] == 'a' &&
10431 name[10] == 'm' &&
10432 name[11] == 'e')
10433 { /* getnetbyname */
10434 return -KEY_getnetbyname;
10435 }
10436
10437 goto unknown;
10438
10439 default:
10440 goto unknown;
10441 }
e2e1dd5a 10442 }
4c3bbe0f
MHM
10443
10444 goto unknown;
10445
10446 case 13: /* 4 tokens of length 13 */
10447 if (name[0] == 'g' &&
10448 name[1] == 'e' &&
10449 name[2] == 't')
10450 {
10451 switch (name[3])
10452 {
10453 case 'h':
10454 if (name[4] == 'o' &&
10455 name[5] == 's' &&
10456 name[6] == 't' &&
10457 name[7] == 'b' &&
10458 name[8] == 'y')
10459 {
10460 switch (name[9])
10461 {
10462 case 'a':
10463 if (name[10] == 'd' &&
10464 name[11] == 'd' &&
10465 name[12] == 'r')
10466 { /* gethostbyaddr */
10467 return -KEY_gethostbyaddr;
10468 }
10469
10470 goto unknown;
10471
10472 case 'n':
10473 if (name[10] == 'a' &&
10474 name[11] == 'm' &&
10475 name[12] == 'e')
10476 { /* gethostbyname */
10477 return -KEY_gethostbyname;
10478 }
10479
10480 goto unknown;
10481
10482 default:
10483 goto unknown;
10484 }
10485 }
10486
10487 goto unknown;
10488
10489 case 's':
10490 if (name[4] == 'e' &&
10491 name[5] == 'r' &&
10492 name[6] == 'v' &&
10493 name[7] == 'b' &&
10494 name[8] == 'y')
10495 {
10496 switch (name[9])
10497 {
10498 case 'n':
10499 if (name[10] == 'a' &&
10500 name[11] == 'm' &&
10501 name[12] == 'e')
10502 { /* getservbyname */
10503 return -KEY_getservbyname;
10504 }
10505
10506 goto unknown;
10507
10508 case 'p':
10509 if (name[10] == 'o' &&
10510 name[11] == 'r' &&
10511 name[12] == 't')
10512 { /* getservbyport */
10513 return -KEY_getservbyport;
10514 }
10515
10516 goto unknown;
10517
10518 default:
10519 goto unknown;
10520 }
10521 }
10522
10523 goto unknown;
10524
10525 default:
10526 goto unknown;
10527 }
e2e1dd5a 10528 }
4c3bbe0f
MHM
10529
10530 goto unknown;
10531
10532 case 14: /* 1 tokens of length 14 */
10533 if (name[0] == 'g' &&
10534 name[1] == 'e' &&
10535 name[2] == 't' &&
10536 name[3] == 'p' &&
10537 name[4] == 'r' &&
10538 name[5] == 'o' &&
10539 name[6] == 't' &&
10540 name[7] == 'o' &&
10541 name[8] == 'b' &&
10542 name[9] == 'y' &&
10543 name[10] == 'n' &&
10544 name[11] == 'a' &&
10545 name[12] == 'm' &&
10546 name[13] == 'e')
10547 { /* getprotobyname */
10548 return -KEY_getprotobyname;
10549 }
10550
10551 goto unknown;
10552
10553 case 16: /* 1 tokens of length 16 */
10554 if (name[0] == 'g' &&
10555 name[1] == 'e' &&
10556 name[2] == 't' &&
10557 name[3] == 'p' &&
10558 name[4] == 'r' &&
10559 name[5] == 'o' &&
10560 name[6] == 't' &&
10561 name[7] == 'o' &&
10562 name[8] == 'b' &&
10563 name[9] == 'y' &&
10564 name[10] == 'n' &&
10565 name[11] == 'u' &&
10566 name[12] == 'm' &&
10567 name[13] == 'b' &&
10568 name[14] == 'e' &&
10569 name[15] == 'r')
10570 { /* getprotobynumber */
10571 return -KEY_getprotobynumber;
10572 }
10573
10574 goto unknown;
10575
10576 default:
10577 goto unknown;
e2e1dd5a 10578 }
4c3bbe0f
MHM
10579
10580unknown:
e2e1dd5a 10581 return 0;
a687059c
LW
10582}
10583
76e3520e 10584STATIC void
c94115d8 10585S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
a687059c 10586{
97aff369 10587 dVAR;
2f3197b3 10588
7918f24d
NC
10589 PERL_ARGS_ASSERT_CHECKCOMMA;
10590
d008e5eb 10591 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
d008e5eb
GS
10592 if (ckWARN(WARN_SYNTAX)) {
10593 int level = 1;
26ff0806 10594 const char *w;
d008e5eb
GS
10595 for (w = s+2; *w && level; w++) {
10596 if (*w == '(')
10597 ++level;
10598 else if (*w == ')')
10599 --level;
10600 }
888fea98
NC
10601 while (isSPACE(*w))
10602 ++w;
b1439985
RGS
10603 /* the list of chars below is for end of statements or
10604 * block / parens, boolean operators (&&, ||, //) and branch
10605 * constructs (or, and, if, until, unless, while, err, for).
10606 * Not a very solid hack... */
10607 if (!*w || !strchr(";&/|})]oaiuwef!=", *w))
9014280d 10608 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
65cec589 10609 "%s (...) interpreted as function",name);
d008e5eb 10610 }
2f3197b3 10611 }
3280af22 10612 while (s < PL_bufend && isSPACE(*s))
2f3197b3 10613 s++;
a687059c
LW
10614 if (*s == '(')
10615 s++;
3280af22 10616 while (s < PL_bufend && isSPACE(*s))
a687059c 10617 s++;
7e2040f0 10618 if (isIDFIRST_lazy_if(s,UTF)) {
26ff0806 10619 const char * const w = s++;
7e2040f0 10620 while (isALNUM_lazy_if(s,UTF))
a687059c 10621 s++;
3280af22 10622 while (s < PL_bufend && isSPACE(*s))
a687059c 10623 s++;
e929a76b 10624 if (*s == ',') {
c94115d8 10625 GV* gv;
5458a98a 10626 if (keyword(w, s - w, 0))
e929a76b 10627 return;
c94115d8
NC
10628
10629 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10630 if (gv && GvCVu(gv))
abbb3198 10631 return;
cea2e8a9 10632 Perl_croak(aTHX_ "No comma allowed after %s", what);
463ee0b2
LW
10633 }
10634 }
10635}
10636
423cee85
JH
10637/* Either returns sv, or mortalizes sv and returns a new SV*.
10638 Best used as sv=new_constant(..., sv, ...).
10639 If s, pv are NULL, calls subroutine with one argument,
10640 and type is used with error messages only. */
10641
b3ac6de7 10642STATIC SV *
eb0d8d16
NC
10643S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, STRLEN keylen,
10644 SV *sv, SV *pv, const char *type, STRLEN typelen)
b3ac6de7 10645{
27da23d5 10646 dVAR; dSP;
890ce7af 10647 HV * const table = GvHV(PL_hintgv); /* ^H */
b3ac6de7 10648 SV *res;
b3ac6de7
IZ
10649 SV **cvp;
10650 SV *cv, *typesv;
89e33a05 10651 const char *why1 = "", *why2 = "", *why3 = "";
4e553d73 10652
7918f24d
NC
10653 PERL_ARGS_ASSERT_NEW_CONSTANT;
10654
f0af216f 10655 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
423cee85
JH
10656 SV *msg;
10657
10edeb5d
JH
10658 why2 = (const char *)
10659 (strEQ(key,"charnames")
10660 ? "(possibly a missing \"use charnames ...\")"
10661 : "");
4e553d73 10662 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
41ab332f
JH
10663 (type ? type: "undef"), why2);
10664
10665 /* This is convoluted and evil ("goto considered harmful")
10666 * but I do not understand the intricacies of all the different
10667 * failure modes of %^H in here. The goal here is to make
10668 * the most probable error message user-friendly. --jhi */
10669
10670 goto msgdone;
10671
423cee85 10672 report:
4e553d73 10673 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
f0af216f 10674 (type ? type: "undef"), why1, why2, why3);
41ab332f 10675 msgdone:
95a20fc0 10676 yyerror(SvPVX_const(msg));
423cee85
JH
10677 SvREFCNT_dec(msg);
10678 return sv;
10679 }
eb0d8d16 10680 cvp = hv_fetch(table, key, keylen, FALSE);
b3ac6de7 10681 if (!cvp || !SvOK(*cvp)) {
423cee85
JH
10682 why1 = "$^H{";
10683 why2 = key;
f0af216f 10684 why3 = "} is not defined";
423cee85 10685 goto report;
b3ac6de7
IZ
10686 }
10687 sv_2mortal(sv); /* Parent created it permanently */
10688 cv = *cvp;
423cee85 10689 if (!pv && s)
59cd0e26 10690 pv = newSVpvn_flags(s, len, SVs_TEMP);
423cee85 10691 if (type && pv)
59cd0e26 10692 typesv = newSVpvn_flags(type, typelen, SVs_TEMP);
b3ac6de7 10693 else
423cee85 10694 typesv = &PL_sv_undef;
4e553d73 10695
e788e7d3 10696 PUSHSTACKi(PERLSI_OVERLOAD);
423cee85
JH
10697 ENTER ;
10698 SAVETMPS;
4e553d73 10699
423cee85 10700 PUSHMARK(SP) ;
a5845cb7 10701 EXTEND(sp, 3);
423cee85
JH
10702 if (pv)
10703 PUSHs(pv);
b3ac6de7 10704 PUSHs(sv);
423cee85
JH
10705 if (pv)
10706 PUSHs(typesv);
b3ac6de7 10707 PUTBACK;
423cee85 10708 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
4e553d73 10709
423cee85 10710 SPAGAIN ;
4e553d73 10711
423cee85 10712 /* Check the eval first */
9b0e499b 10713 if (!PL_in_eval && SvTRUE(ERRSV)) {
396482e1 10714 sv_catpvs(ERRSV, "Propagated");
8b6b16e7 10715 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
e1f15930 10716 (void)POPs;
b37c2d43 10717 res = SvREFCNT_inc_simple(sv);
423cee85
JH
10718 }
10719 else {
10720 res = POPs;
b37c2d43 10721 SvREFCNT_inc_simple_void(res);
423cee85 10722 }
4e553d73 10723
423cee85
JH
10724 PUTBACK ;
10725 FREETMPS ;
10726 LEAVE ;
b3ac6de7 10727 POPSTACK;
4e553d73 10728
b3ac6de7 10729 if (!SvOK(res)) {
423cee85
JH
10730 why1 = "Call to &{$^H{";
10731 why2 = key;
f0af216f 10732 why3 = "}} did not return a defined value";
423cee85
JH
10733 sv = res;
10734 goto report;
9b0e499b 10735 }
423cee85 10736
9b0e499b 10737 return res;
b3ac6de7 10738}
4e553d73 10739
d0a148a6
NC
10740/* Returns a NUL terminated string, with the length of the string written to
10741 *slp
10742 */
76e3520e 10743STATIC char *
cea2e8a9 10744S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
463ee0b2 10745{
97aff369 10746 dVAR;
463ee0b2 10747 register char *d = dest;
890ce7af 10748 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
7918f24d
NC
10749
10750 PERL_ARGS_ASSERT_SCAN_WORD;
10751
463ee0b2 10752 for (;;) {
8903cb82 10753 if (d >= e)
cea2e8a9 10754 Perl_croak(aTHX_ ident_too_long);
834a4ddd 10755 if (isALNUM(*s)) /* UTF handled below */
463ee0b2 10756 *d++ = *s++;
c35e046a 10757 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
463ee0b2
LW
10758 *d++ = ':';
10759 *d++ = ':';
10760 s++;
10761 }
c35e046a 10762 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
463ee0b2
LW
10763 *d++ = *s++;
10764 *d++ = *s++;
10765 }
fd400ab9 10766 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
a0ed51b3 10767 char *t = s + UTF8SKIP(s);
c35e046a 10768 size_t len;
fd400ab9 10769 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
a0ed51b3 10770 t += UTF8SKIP(t);
c35e046a
AL
10771 len = t - s;
10772 if (d + len > e)
cea2e8a9 10773 Perl_croak(aTHX_ ident_too_long);
c35e046a
AL
10774 Copy(s, d, len, char);
10775 d += len;
a0ed51b3
LW
10776 s = t;
10777 }
463ee0b2
LW
10778 else {
10779 *d = '\0';
10780 *slp = d - dest;
10781 return s;
e929a76b 10782 }
378cc40b
LW
10783 }
10784}
10785
76e3520e 10786STATIC char *
f54cb97a 10787S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
378cc40b 10788{
97aff369 10789 dVAR;
6136c704 10790 char *bracket = NULL;
748a9306 10791 char funny = *s++;
6136c704
AL
10792 register char *d = dest;
10793 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
378cc40b 10794
7918f24d
NC
10795 PERL_ARGS_ASSERT_SCAN_IDENT;
10796
a0d0e21e 10797 if (isSPACE(*s))
29595ff2 10798 s = PEEKSPACE(s);
de3bb511 10799 if (isDIGIT(*s)) {
8903cb82 10800 while (isDIGIT(*s)) {
10801 if (d >= e)
cea2e8a9 10802 Perl_croak(aTHX_ ident_too_long);
378cc40b 10803 *d++ = *s++;
8903cb82 10804 }
378cc40b
LW
10805 }
10806 else {
463ee0b2 10807 for (;;) {
8903cb82 10808 if (d >= e)
cea2e8a9 10809 Perl_croak(aTHX_ ident_too_long);
834a4ddd 10810 if (isALNUM(*s)) /* UTF handled below */
463ee0b2 10811 *d++ = *s++;
7e2040f0 10812 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
463ee0b2
LW
10813 *d++ = ':';
10814 *d++ = ':';
10815 s++;
10816 }
a0d0e21e 10817 else if (*s == ':' && s[1] == ':') {
463ee0b2
LW
10818 *d++ = *s++;
10819 *d++ = *s++;
10820 }
fd400ab9 10821 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
a0ed51b3 10822 char *t = s + UTF8SKIP(s);
fd400ab9 10823 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
a0ed51b3
LW
10824 t += UTF8SKIP(t);
10825 if (d + (t - s) > e)
cea2e8a9 10826 Perl_croak(aTHX_ ident_too_long);
a0ed51b3
LW
10827 Copy(s, d, t - s, char);
10828 d += t - s;
10829 s = t;
10830 }
463ee0b2
LW
10831 else
10832 break;
10833 }
378cc40b
LW
10834 }
10835 *d = '\0';
10836 d = dest;
79072805 10837 if (*d) {
3280af22
NIS
10838 if (PL_lex_state != LEX_NORMAL)
10839 PL_lex_state = LEX_INTERPENDMAYBE;
79072805 10840 return s;
378cc40b 10841 }
748a9306 10842 if (*s == '$' && s[1] &&
3792a11b 10843 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
5cd24f17 10844 {
4810e5ec 10845 return s;
5cd24f17 10846 }
79072805
LW
10847 if (*s == '{') {
10848 bracket = s;
10849 s++;
10850 }
10851 else if (ck_uni)
10852 check_uni();
93a17b20 10853 if (s < send)
79072805
LW
10854 *d = *s++;
10855 d[1] = '\0';
2b92dfce 10856 if (*d == '^' && *s && isCONTROLVAR(*s)) {
bbce6d69 10857 *d = toCTRL(*s);
10858 s++;
de3bb511 10859 }
79072805 10860 if (bracket) {
748a9306 10861 if (isSPACE(s[-1])) {
fa83b5b6 10862 while (s < send) {
f54cb97a 10863 const char ch = *s++;
bf4acbe4 10864 if (!SPACE_OR_TAB(ch)) {
fa83b5b6 10865 *d = ch;
10866 break;
10867 }
10868 }
748a9306 10869 }
7e2040f0 10870 if (isIDFIRST_lazy_if(d,UTF)) {
79072805 10871 d++;
a0ed51b3 10872 if (UTF) {
6136c704
AL
10873 char *end = s;
10874 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10875 end += UTF8SKIP(end);
10876 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10877 end += UTF8SKIP(end);
a0ed51b3 10878 }
6136c704
AL
10879 Copy(s, d, end - s, char);
10880 d += end - s;
10881 s = end;
a0ed51b3
LW
10882 }
10883 else {
2b92dfce 10884 while ((isALNUM(*s) || *s == ':') && d < e)
a0ed51b3 10885 *d++ = *s++;
2b92dfce 10886 if (d >= e)
cea2e8a9 10887 Perl_croak(aTHX_ ident_too_long);
a0ed51b3 10888 }
79072805 10889 *d = '\0';
c35e046a
AL
10890 while (s < send && SPACE_OR_TAB(*s))
10891 s++;
ff68c719 10892 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
5458a98a 10893 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
10edeb5d
JH
10894 const char * const brack =
10895 (const char *)
10896 ((*s == '[') ? "[...]" : "{...}");
9014280d 10897 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
599cee73 10898 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
748a9306
LW
10899 funny, dest, brack, funny, dest, brack);
10900 }
79072805 10901 bracket++;
a0be28da 10902 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
79072805
LW
10903 return s;
10904 }
4e553d73
NIS
10905 }
10906 /* Handle extended ${^Foo} variables
2b92dfce
GS
10907 * 1999-02-27 mjd-perl-patch@plover.com */
10908 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10909 && isALNUM(*s))
10910 {
10911 d++;
10912 while (isALNUM(*s) && d < e) {
10913 *d++ = *s++;
10914 }
10915 if (d >= e)
cea2e8a9 10916 Perl_croak(aTHX_ ident_too_long);
2b92dfce 10917 *d = '\0';
79072805
LW
10918 }
10919 if (*s == '}') {
10920 s++;
7df0d042 10921 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
3280af22 10922 PL_lex_state = LEX_INTERPEND;
7df0d042
AE
10923 PL_expect = XREF;
10924 }
d008e5eb 10925 if (PL_lex_state == LEX_NORMAL) {
d008e5eb 10926 if (ckWARN(WARN_AMBIGUOUS) &&
780a5241
NC
10927 (keyword(dest, d - dest, 0)
10928 || get_cvn_flags(dest, d - dest, 0)))
d008e5eb 10929 {
c35e046a
AL
10930 if (funny == '#')
10931 funny = '@';
9014280d 10932 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
d008e5eb
GS
10933 "Ambiguous use of %c{%s} resolved to %c%s",
10934 funny, dest, funny, dest);
10935 }
10936 }
79072805
LW
10937 }
10938 else {
10939 s = bracket; /* let the parser handle it */
93a17b20 10940 *dest = '\0';
79072805
LW
10941 }
10942 }
3280af22
NIS
10943 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10944 PL_lex_state = LEX_INTERPEND;
378cc40b
LW
10945 return s;
10946}
10947
cea2e8a9 10948void
2b36a5a0 10949Perl_pmflag(pTHX_ U32* pmfl, int ch)
a0d0e21e 10950{
7918f24d
NC
10951 PERL_ARGS_ASSERT_PMFLAG;
10952
96a5add6 10953 PERL_UNUSED_CONTEXT;
cde0cee5 10954 if (ch<256) {
15f169a1 10955 const char c = (char)ch;
cde0cee5
YO
10956 switch (c) {
10957 CASE_STD_PMMOD_FLAGS_PARSE_SET(pmfl);
a20207d7
YO
10958 case GLOBAL_PAT_MOD: *pmfl |= PMf_GLOBAL; break;
10959 case CONTINUE_PAT_MOD: *pmfl |= PMf_CONTINUE; break;
10960 case ONCE_PAT_MOD: *pmfl |= PMf_KEEP; break;
10961 case KEEPCOPY_PAT_MOD: *pmfl |= PMf_KEEPCOPY; break;
cde0cee5
YO
10962 }
10963 }
a0d0e21e 10964}
378cc40b 10965
76e3520e 10966STATIC char *
cea2e8a9 10967S_scan_pat(pTHX_ char *start, I32 type)
378cc40b 10968{
97aff369 10969 dVAR;
79072805 10970 PMOP *pm;
5db06880 10971 char *s = scan_str(start,!!PL_madskills,FALSE);
10edeb5d 10972 const char * const valid_flags =
a20207d7 10973 (const char *)((type == OP_QR) ? QR_PAT_MODS : M_PAT_MODS);
5db06880
NC
10974#ifdef PERL_MAD
10975 char *modstart;
10976#endif
10977
7918f24d 10978 PERL_ARGS_ASSERT_SCAN_PAT;
378cc40b 10979
25c09cbf 10980 if (!s) {
6136c704 10981 const char * const delimiter = skipspace(start);
10edeb5d
JH
10982 Perl_croak(aTHX_
10983 (const char *)
10984 (*delimiter == '?'
10985 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10986 : "Search pattern not terminated" ));
25c09cbf 10987 }
bbce6d69 10988
8782bef2 10989 pm = (PMOP*)newPMOP(type, 0);
ad639bfb
NC
10990 if (PL_multi_open == '?') {
10991 /* This is the only point in the code that sets PMf_ONCE: */
79072805 10992 pm->op_pmflags |= PMf_ONCE;
ad639bfb
NC
10993
10994 /* Hence it's safe to do this bit of PMOP book-keeping here, which
10995 allows us to restrict the list needed by reset to just the ??
10996 matches. */
10997 assert(type != OP_TRANS);
10998 if (PL_curstash) {
daba3364 10999 MAGIC *mg = mg_find((const SV *)PL_curstash, PERL_MAGIC_symtab);
ad639bfb
NC
11000 U32 elements;
11001 if (!mg) {
daba3364 11002 mg = sv_magicext(MUTABLE_SV(PL_curstash), 0, PERL_MAGIC_symtab, 0, 0,
ad639bfb
NC
11003 0);
11004 }
11005 elements = mg->mg_len / sizeof(PMOP**);
11006 Renewc(mg->mg_ptr, elements + 1, PMOP*, char);
11007 ((PMOP**)mg->mg_ptr) [elements++] = pm;
11008 mg->mg_len = elements * sizeof(PMOP**);
11009 PmopSTASH_set(pm,PL_curstash);
11010 }
11011 }
5db06880
NC
11012#ifdef PERL_MAD
11013 modstart = s;
11014#endif
6136c704
AL
11015 while (*s && strchr(valid_flags, *s))
11016 pmflag(&pm->op_pmflags,*s++);
5db06880
NC
11017#ifdef PERL_MAD
11018 if (PL_madskills && modstart != s) {
11019 SV* tmptoken = newSVpvn(modstart, s - modstart);
11020 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
11021 }
11022#endif
4ac733c9 11023 /* issue a warning if /c is specified,but /g is not */
a2a5de95 11024 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL))
4ac733c9 11025 {
a2a5de95
NC
11026 Perl_ck_warner(aTHX_ packWARN(WARN_REGEXP),
11027 "Use of /c modifier is meaningless without /g" );
4ac733c9
MJD
11028 }
11029
3280af22 11030 PL_lex_op = (OP*)pm;
6154021b 11031 pl_yylval.ival = OP_MATCH;
378cc40b
LW
11032 return s;
11033}
11034
76e3520e 11035STATIC char *
cea2e8a9 11036S_scan_subst(pTHX_ char *start)
79072805 11037{
27da23d5 11038 dVAR;
a0d0e21e 11039 register char *s;
79072805 11040 register PMOP *pm;
4fdae800 11041 I32 first_start;
79072805 11042 I32 es = 0;
5db06880
NC
11043#ifdef PERL_MAD
11044 char *modstart;
11045#endif
79072805 11046
7918f24d
NC
11047 PERL_ARGS_ASSERT_SCAN_SUBST;
11048
6154021b 11049 pl_yylval.ival = OP_NULL;
79072805 11050
5db06880 11051 s = scan_str(start,!!PL_madskills,FALSE);
79072805 11052
37fd879b 11053 if (!s)
cea2e8a9 11054 Perl_croak(aTHX_ "Substitution pattern not terminated");
79072805 11055
3280af22 11056 if (s[-1] == PL_multi_open)
79072805 11057 s--;
5db06880
NC
11058#ifdef PERL_MAD
11059 if (PL_madskills) {
cd81e915
NC
11060 CURMAD('q', PL_thisopen);
11061 CURMAD('_', PL_thiswhite);
11062 CURMAD('E', PL_thisstuff);
11063 CURMAD('Q', PL_thisclose);
11064 PL_realtokenstart = s - SvPVX(PL_linestr);
5db06880
NC
11065 }
11066#endif
79072805 11067
3280af22 11068 first_start = PL_multi_start;
5db06880 11069 s = scan_str(s,!!PL_madskills,FALSE);
79072805 11070 if (!s) {
37fd879b 11071 if (PL_lex_stuff) {
3280af22 11072 SvREFCNT_dec(PL_lex_stuff);
a0714e2c 11073 PL_lex_stuff = NULL;
37fd879b 11074 }
cea2e8a9 11075 Perl_croak(aTHX_ "Substitution replacement not terminated");
a687059c 11076 }
3280af22 11077 PL_multi_start = first_start; /* so whole substitution is taken together */
2f3197b3 11078
79072805 11079 pm = (PMOP*)newPMOP(OP_SUBST, 0);
5db06880
NC
11080
11081#ifdef PERL_MAD
11082 if (PL_madskills) {
cd81e915
NC
11083 CURMAD('z', PL_thisopen);
11084 CURMAD('R', PL_thisstuff);
11085 CURMAD('Z', PL_thisclose);
5db06880
NC
11086 }
11087 modstart = s;
11088#endif
11089
48c036b1 11090 while (*s) {
a20207d7 11091 if (*s == EXEC_PAT_MOD) {
a687059c 11092 s++;
2f3197b3 11093 es++;
a687059c 11094 }
a20207d7 11095 else if (strchr(S_PAT_MODS, *s))
a0d0e21e 11096 pmflag(&pm->op_pmflags,*s++);
48c036b1
GS
11097 else
11098 break;
378cc40b 11099 }
79072805 11100
5db06880
NC
11101#ifdef PERL_MAD
11102 if (PL_madskills) {
11103 if (modstart != s)
11104 curmad('m', newSVpvn(modstart, s - modstart));
cd81e915
NC
11105 append_madprops(PL_thismad, (OP*)pm, 0);
11106 PL_thismad = 0;
5db06880
NC
11107 }
11108#endif
a2a5de95
NC
11109 if ((pm->op_pmflags & PMf_CONTINUE)) {
11110 Perl_ck_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
4ac733c9
MJD
11111 }
11112
79072805 11113 if (es) {
6136c704
AL
11114 SV * const repl = newSVpvs("");
11115
0244c3a4
GS
11116 PL_sublex_info.super_bufptr = s;
11117 PL_sublex_info.super_bufend = PL_bufend;
11118 PL_multi_end = 0;
79072805 11119 pm->op_pmflags |= PMf_EVAL;
a5849ce5
NC
11120 while (es-- > 0) {
11121 if (es)
11122 sv_catpvs(repl, "eval ");
11123 else
11124 sv_catpvs(repl, "do ");
11125 }
6f43d98f 11126 sv_catpvs(repl, "{");
3280af22 11127 sv_catsv(repl, PL_lex_repl);
9badc361
RGS
11128 if (strchr(SvPVX(PL_lex_repl), '#'))
11129 sv_catpvs(repl, "\n");
11130 sv_catpvs(repl, "}");
25da4f38 11131 SvEVALED_on(repl);
3280af22
NIS
11132 SvREFCNT_dec(PL_lex_repl);
11133 PL_lex_repl = repl;
378cc40b 11134 }
79072805 11135
3280af22 11136 PL_lex_op = (OP*)pm;
6154021b 11137 pl_yylval.ival = OP_SUBST;
378cc40b
LW
11138 return s;
11139}
11140
76e3520e 11141STATIC char *
cea2e8a9 11142S_scan_trans(pTHX_ char *start)
378cc40b 11143{
97aff369 11144 dVAR;
a0d0e21e 11145 register char* s;
11343788 11146 OP *o;
79072805 11147 short *tbl;
b84c11c8
NC
11148 U8 squash;
11149 U8 del;
11150 U8 complement;
5db06880
NC
11151#ifdef PERL_MAD
11152 char *modstart;
11153#endif
79072805 11154
7918f24d
NC
11155 PERL_ARGS_ASSERT_SCAN_TRANS;
11156
6154021b 11157 pl_yylval.ival = OP_NULL;
79072805 11158
5db06880 11159 s = scan_str(start,!!PL_madskills,FALSE);
37fd879b 11160 if (!s)
cea2e8a9 11161 Perl_croak(aTHX_ "Transliteration pattern not terminated");
5db06880 11162
3280af22 11163 if (s[-1] == PL_multi_open)
2f3197b3 11164 s--;
5db06880
NC
11165#ifdef PERL_MAD
11166 if (PL_madskills) {
cd81e915
NC
11167 CURMAD('q', PL_thisopen);
11168 CURMAD('_', PL_thiswhite);
11169 CURMAD('E', PL_thisstuff);
11170 CURMAD('Q', PL_thisclose);
11171 PL_realtokenstart = s - SvPVX(PL_linestr);
5db06880
NC
11172 }
11173#endif
2f3197b3 11174
5db06880 11175 s = scan_str(s,!!PL_madskills,FALSE);
79072805 11176 if (!s) {
37fd879b 11177 if (PL_lex_stuff) {
3280af22 11178 SvREFCNT_dec(PL_lex_stuff);
a0714e2c 11179 PL_lex_stuff = NULL;
37fd879b 11180 }
cea2e8a9 11181 Perl_croak(aTHX_ "Transliteration replacement not terminated");
a687059c 11182 }
5db06880 11183 if (PL_madskills) {
cd81e915
NC
11184 CURMAD('z', PL_thisopen);
11185 CURMAD('R', PL_thisstuff);
11186 CURMAD('Z', PL_thisclose);
5db06880 11187 }
79072805 11188
a0ed51b3 11189 complement = del = squash = 0;
5db06880
NC
11190#ifdef PERL_MAD
11191 modstart = s;
11192#endif
7a1e2023
NC
11193 while (1) {
11194 switch (*s) {
11195 case 'c':
79072805 11196 complement = OPpTRANS_COMPLEMENT;
7a1e2023
NC
11197 break;
11198 case 'd':
a0ed51b3 11199 del = OPpTRANS_DELETE;
7a1e2023
NC
11200 break;
11201 case 's':
79072805 11202 squash = OPpTRANS_SQUASH;
7a1e2023
NC
11203 break;
11204 default:
11205 goto no_more;
11206 }
395c3793
LW
11207 s++;
11208 }
7a1e2023 11209 no_more:
8973db79 11210
aa1f7c5b 11211 tbl = (short *)PerlMemShared_calloc(complement&&!del?258:256, sizeof(short));
8973db79 11212 o = newPVOP(OP_TRANS, 0, (char*)tbl);
59f00321
RGS
11213 o->op_private &= ~OPpTRANS_ALL;
11214 o->op_private |= del|squash|complement|
7948272d
NIS
11215 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
11216 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
79072805 11217
3280af22 11218 PL_lex_op = o;
6154021b 11219 pl_yylval.ival = OP_TRANS;
5db06880
NC
11220
11221#ifdef PERL_MAD
11222 if (PL_madskills) {
11223 if (modstart != s)
11224 curmad('m', newSVpvn(modstart, s - modstart));
cd81e915
NC
11225 append_madprops(PL_thismad, o, 0);
11226 PL_thismad = 0;
5db06880
NC
11227 }
11228#endif
11229
79072805
LW
11230 return s;
11231}
11232
76e3520e 11233STATIC char *
cea2e8a9 11234S_scan_heredoc(pTHX_ register char *s)
79072805 11235{
97aff369 11236 dVAR;
79072805
LW
11237 SV *herewas;
11238 I32 op_type = OP_SCALAR;
11239 I32 len;
11240 SV *tmpstr;
11241 char term;
73d840c0 11242 const char *found_newline;
79072805 11243 register char *d;
fc36a67e 11244 register char *e;
4633a7c4 11245 char *peek;
f54cb97a 11246 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
5db06880
NC
11247#ifdef PERL_MAD
11248 I32 stuffstart = s - SvPVX(PL_linestr);
11249 char *tstart;
11250
cd81e915 11251 PL_realtokenstart = -1;
5db06880 11252#endif
79072805 11253
7918f24d
NC
11254 PERL_ARGS_ASSERT_SCAN_HEREDOC;
11255
79072805 11256 s += 2;
3280af22
NIS
11257 d = PL_tokenbuf;
11258 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
fd2d0953 11259 if (!outer)
79072805 11260 *d++ = '\n';
c35e046a
AL
11261 peek = s;
11262 while (SPACE_OR_TAB(*peek))
11263 peek++;
3792a11b 11264 if (*peek == '`' || *peek == '\'' || *peek =='"') {
4633a7c4 11265 s = peek;
79072805 11266 term = *s++;
3280af22 11267 s = delimcpy(d, e, s, PL_bufend, term, &len);
fc36a67e 11268 d += len;
3280af22 11269 if (s < PL_bufend)
79072805 11270 s++;
79072805
LW
11271 }
11272 else {
11273 if (*s == '\\')
11274 s++, term = '\'';
11275 else
11276 term = '"';
7e2040f0 11277 if (!isALNUM_lazy_if(s,UTF))
8ab8f082 11278 deprecate("bare << to mean <<\"\"");
7e2040f0 11279 for (; isALNUM_lazy_if(s,UTF); s++) {
fc36a67e 11280 if (d < e)
11281 *d++ = *s;
11282 }
11283 }
3280af22 11284 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
cea2e8a9 11285 Perl_croak(aTHX_ "Delimiter for here document is too long");
79072805
LW
11286 *d++ = '\n';
11287 *d = '\0';
3280af22 11288 len = d - PL_tokenbuf;
5db06880
NC
11289
11290#ifdef PERL_MAD
11291 if (PL_madskills) {
11292 tstart = PL_tokenbuf + !outer;
cd81e915 11293 PL_thisclose = newSVpvn(tstart, len - !outer);
5db06880 11294 tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915 11295 PL_thisopen = newSVpvn(tstart, s - tstart);
5db06880
NC
11296 stuffstart = s - SvPVX(PL_linestr);
11297 }
11298#endif
6a27c188 11299#ifndef PERL_STRICT_CR
f63a84b2
LW
11300 d = strchr(s, '\r');
11301 if (d) {
b464bac0 11302 char * const olds = s;
f63a84b2 11303 s = d;
3280af22 11304 while (s < PL_bufend) {
f63a84b2
LW
11305 if (*s == '\r') {
11306 *d++ = '\n';
11307 if (*++s == '\n')
11308 s++;
11309 }
11310 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
11311 *d++ = *s++;
11312 s++;
11313 }
11314 else
11315 *d++ = *s++;
11316 }
11317 *d = '\0';
3280af22 11318 PL_bufend = d;
95a20fc0 11319 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
f63a84b2
LW
11320 s = olds;
11321 }
11322#endif
5db06880
NC
11323#ifdef PERL_MAD
11324 found_newline = 0;
11325#endif
10edeb5d 11326 if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
73d840c0
AL
11327 herewas = newSVpvn(s,PL_bufend-s);
11328 }
11329 else {
5db06880
NC
11330#ifdef PERL_MAD
11331 herewas = newSVpvn(s-1,found_newline-s+1);
11332#else
73d840c0
AL
11333 s--;
11334 herewas = newSVpvn(s,found_newline-s);
5db06880 11335#endif
73d840c0 11336 }
5db06880
NC
11337#ifdef PERL_MAD
11338 if (PL_madskills) {
11339 tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915
NC
11340 if (PL_thisstuff)
11341 sv_catpvn(PL_thisstuff, tstart, s - tstart);
5db06880 11342 else
cd81e915 11343 PL_thisstuff = newSVpvn(tstart, s - tstart);
5db06880
NC
11344 }
11345#endif
79072805 11346 s += SvCUR(herewas);
748a9306 11347
5db06880
NC
11348#ifdef PERL_MAD
11349 stuffstart = s - SvPVX(PL_linestr);
11350
11351 if (found_newline)
11352 s--;
11353#endif
11354
7d0a29fe
NC
11355 tmpstr = newSV_type(SVt_PVIV);
11356 SvGROW(tmpstr, 80);
748a9306 11357 if (term == '\'') {
79072805 11358 op_type = OP_CONST;
45977657 11359 SvIV_set(tmpstr, -1);
748a9306
LW
11360 }
11361 else if (term == '`') {
79072805 11362 op_type = OP_BACKTICK;
45977657 11363 SvIV_set(tmpstr, '\\');
748a9306 11364 }
79072805
LW
11365
11366 CLINE;
57843af0 11367 PL_multi_start = CopLINE(PL_curcop);
3280af22
NIS
11368 PL_multi_open = PL_multi_close = '<';
11369 term = *PL_tokenbuf;
0244c3a4 11370 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
6136c704
AL
11371 char * const bufptr = PL_sublex_info.super_bufptr;
11372 char * const bufend = PL_sublex_info.super_bufend;
b464bac0 11373 char * const olds = s - SvCUR(herewas);
0244c3a4
GS
11374 s = strchr(bufptr, '\n');
11375 if (!s)
11376 s = bufend;
11377 d = s;
11378 while (s < bufend &&
11379 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11380 if (*s++ == '\n')
57843af0 11381 CopLINE_inc(PL_curcop);
0244c3a4
GS
11382 }
11383 if (s >= bufend) {
eb160463 11384 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
0244c3a4
GS
11385 missingterm(PL_tokenbuf);
11386 }
11387 sv_setpvn(herewas,bufptr,d-bufptr+1);
11388 sv_setpvn(tmpstr,d+1,s-d);
11389 s += len - 1;
11390 sv_catpvn(herewas,s,bufend-s);
95a20fc0 11391 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
0244c3a4
GS
11392
11393 s = olds;
11394 goto retval;
11395 }
11396 else if (!outer) {
79072805 11397 d = s;
3280af22
NIS
11398 while (s < PL_bufend &&
11399 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
79072805 11400 if (*s++ == '\n')
57843af0 11401 CopLINE_inc(PL_curcop);
79072805 11402 }
3280af22 11403 if (s >= PL_bufend) {
eb160463 11404 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
3280af22 11405 missingterm(PL_tokenbuf);
79072805
LW
11406 }
11407 sv_setpvn(tmpstr,d+1,s-d);
5db06880
NC
11408#ifdef PERL_MAD
11409 if (PL_madskills) {
cd81e915
NC
11410 if (PL_thisstuff)
11411 sv_catpvn(PL_thisstuff, d + 1, s - d);
5db06880 11412 else
cd81e915 11413 PL_thisstuff = newSVpvn(d + 1, s - d);
5db06880
NC
11414 stuffstart = s - SvPVX(PL_linestr);
11415 }
11416#endif
79072805 11417 s += len - 1;
57843af0 11418 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
49d8d3a1 11419
3280af22
NIS
11420 sv_catpvn(herewas,s,PL_bufend-s);
11421 sv_setsv(PL_linestr,herewas);
11422 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11423 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 11424 PL_last_lop = PL_last_uni = NULL;
79072805
LW
11425 }
11426 else
76f68e9b 11427 sv_setpvs(tmpstr,""); /* avoid "uninitialized" warning */
3280af22 11428 while (s >= PL_bufend) { /* multiple line string? */
5db06880
NC
11429#ifdef PERL_MAD
11430 if (PL_madskills) {
11431 tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915
NC
11432 if (PL_thisstuff)
11433 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
5db06880 11434 else
cd81e915 11435 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
5db06880
NC
11436 }
11437#endif
fd2d0953 11438 if (!outer ||
3280af22 11439 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
eb160463 11440 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
3280af22 11441 missingterm(PL_tokenbuf);
79072805 11442 }
5db06880
NC
11443#ifdef PERL_MAD
11444 stuffstart = s - SvPVX(PL_linestr);
11445#endif
57843af0 11446 CopLINE_inc(PL_curcop);
3280af22 11447 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 11448 PL_last_lop = PL_last_uni = NULL;
6a27c188 11449#ifndef PERL_STRICT_CR
3280af22 11450 if (PL_bufend - PL_linestart >= 2) {
a1529941
NIS
11451 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11452 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
c6f14548 11453 {
3280af22
NIS
11454 PL_bufend[-2] = '\n';
11455 PL_bufend--;
95a20fc0 11456 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
f63a84b2 11457 }
3280af22
NIS
11458 else if (PL_bufend[-1] == '\r')
11459 PL_bufend[-1] = '\n';
f63a84b2 11460 }
3280af22
NIS
11461 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11462 PL_bufend[-1] = '\n';
f63a84b2 11463#endif
65269a95 11464 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
5fa550fb 11465 update_debugger_info(PL_linestr, NULL, 0);
3280af22 11466 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
95a20fc0 11467 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
1de9afcd 11468 *(SvPVX(PL_linestr) + off ) = ' ';
3280af22
NIS
11469 sv_catsv(PL_linestr,herewas);
11470 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1de9afcd 11471 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
79072805
LW
11472 }
11473 else {
3280af22
NIS
11474 s = PL_bufend;
11475 sv_catsv(tmpstr,PL_linestr);
395c3793
LW
11476 }
11477 }
79072805 11478 s++;
0244c3a4 11479retval:
57843af0 11480 PL_multi_end = CopLINE(PL_curcop);
79072805 11481 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
1da4ca5f 11482 SvPV_shrink_to_cur(tmpstr);
79072805 11483 }
8990e307 11484 SvREFCNT_dec(herewas);
2f31ce75 11485 if (!IN_BYTES) {
95a20fc0 11486 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
2f31ce75
JH
11487 SvUTF8_on(tmpstr);
11488 else if (PL_encoding)
11489 sv_recode_to_utf8(tmpstr, PL_encoding);
11490 }
3280af22 11491 PL_lex_stuff = tmpstr;
6154021b 11492 pl_yylval.ival = op_type;
79072805
LW
11493 return s;
11494}
11495
02aa26ce
NT
11496/* scan_inputsymbol
11497 takes: current position in input buffer
11498 returns: new position in input buffer
6154021b 11499 side-effects: pl_yylval and lex_op are set.
02aa26ce
NT
11500
11501 This code handles:
11502
11503 <> read from ARGV
11504 <FH> read from filehandle
11505 <pkg::FH> read from package qualified filehandle
11506 <pkg'FH> read from package qualified filehandle
11507 <$fh> read from filehandle in $fh
11508 <*.h> filename glob
11509
11510*/
11511
76e3520e 11512STATIC char *
cea2e8a9 11513S_scan_inputsymbol(pTHX_ char *start)
79072805 11514{
97aff369 11515 dVAR;
02aa26ce 11516 register char *s = start; /* current position in buffer */
1b420867 11517 char *end;
79072805 11518 I32 len;
6136c704
AL
11519 char *d = PL_tokenbuf; /* start of temp holding space */
11520 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11521
7918f24d
NC
11522 PERL_ARGS_ASSERT_SCAN_INPUTSYMBOL;
11523
1b420867
GS
11524 end = strchr(s, '\n');
11525 if (!end)
11526 end = PL_bufend;
11527 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
02aa26ce
NT
11528
11529 /* die if we didn't have space for the contents of the <>,
1b420867 11530 or if it didn't end, or if we see a newline
02aa26ce
NT
11531 */
11532
bb7a0f54 11533 if (len >= (I32)sizeof PL_tokenbuf)
cea2e8a9 11534 Perl_croak(aTHX_ "Excessively long <> operator");
1b420867 11535 if (s >= end)
cea2e8a9 11536 Perl_croak(aTHX_ "Unterminated <> operator");
02aa26ce 11537
fc36a67e 11538 s++;
02aa26ce
NT
11539
11540 /* check for <$fh>
11541 Remember, only scalar variables are interpreted as filehandles by
11542 this code. Anything more complex (e.g., <$fh{$num}>) will be
11543 treated as a glob() call.
11544 This code makes use of the fact that except for the $ at the front,
11545 a scalar variable and a filehandle look the same.
11546 */
4633a7c4 11547 if (*d == '$' && d[1]) d++;
02aa26ce
NT
11548
11549 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
7e2040f0 11550 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
79072805 11551 d++;
02aa26ce
NT
11552
11553 /* If we've tried to read what we allow filehandles to look like, and
11554 there's still text left, then it must be a glob() and not a getline.
11555 Use scan_str to pull out the stuff between the <> and treat it
11556 as nothing more than a string.
11557 */
11558
3280af22 11559 if (d - PL_tokenbuf != len) {
6154021b 11560 pl_yylval.ival = OP_GLOB;
5db06880 11561 s = scan_str(start,!!PL_madskills,FALSE);
79072805 11562 if (!s)
cea2e8a9 11563 Perl_croak(aTHX_ "Glob not terminated");
79072805
LW
11564 return s;
11565 }
395c3793 11566 else {
9b3023bc 11567 bool readline_overriden = FALSE;
6136c704 11568 GV *gv_readline;
9b3023bc 11569 GV **gvp;
02aa26ce 11570 /* we're in a filehandle read situation */
3280af22 11571 d = PL_tokenbuf;
02aa26ce
NT
11572
11573 /* turn <> into <ARGV> */
79072805 11574 if (!len)
689badd5 11575 Copy("ARGV",d,5,char);
02aa26ce 11576
9b3023bc 11577 /* Check whether readline() is overriden */
fafc274c 11578 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
6136c704 11579 if ((gv_readline
ba979b31 11580 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
9b3023bc 11581 ||
017a3ce5 11582 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
9e0d86f8 11583 && (gv_readline = *gvp) && isGV_with_GP(gv_readline)
ba979b31 11584 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
9b3023bc
RGS
11585 readline_overriden = TRUE;
11586
02aa26ce
NT
11587 /* if <$fh>, create the ops to turn the variable into a
11588 filehandle
11589 */
79072805 11590 if (*d == '$') {
02aa26ce
NT
11591 /* try to find it in the pad for this block, otherwise find
11592 add symbol table ops
11593 */
bbd11bfc
AL
11594 const PADOFFSET tmp = pad_findmy(d);
11595 if (tmp != NOT_IN_PAD) {
00b1698f 11596 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6136c704
AL
11597 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11598 HEK * const stashname = HvNAME_HEK(stash);
11599 SV * const sym = sv_2mortal(newSVhek(stashname));
396482e1 11600 sv_catpvs(sym, "::");
f558d5af
JH
11601 sv_catpv(sym, d+1);
11602 d = SvPVX(sym);
11603 goto intro_sym;
11604 }
11605 else {
6136c704 11606 OP * const o = newOP(OP_PADSV, 0);
f558d5af 11607 o->op_targ = tmp;
9b3023bc
RGS
11608 PL_lex_op = readline_overriden
11609 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11610 append_elem(OP_LIST, o,
11611 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11612 : (OP*)newUNOP(OP_READLINE, 0, o);
f558d5af 11613 }
a0d0e21e
LW
11614 }
11615 else {
f558d5af
JH
11616 GV *gv;
11617 ++d;
11618intro_sym:
11619 gv = gv_fetchpv(d,
11620 (PL_in_eval
11621 ? (GV_ADDMULTI | GV_ADDINEVAL)
bea70d1e 11622 : GV_ADDMULTI),
f558d5af 11623 SVt_PV);
9b3023bc
RGS
11624 PL_lex_op = readline_overriden
11625 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11626 append_elem(OP_LIST,
11627 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11628 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11629 : (OP*)newUNOP(OP_READLINE, 0,
11630 newUNOP(OP_RV2SV, 0,
11631 newGVOP(OP_GV, 0, gv)));
a0d0e21e 11632 }
7c6fadd6
RGS
11633 if (!readline_overriden)
11634 PL_lex_op->op_flags |= OPf_SPECIAL;
6154021b
RGS
11635 /* we created the ops in PL_lex_op, so make pl_yylval.ival a null op */
11636 pl_yylval.ival = OP_NULL;
79072805 11637 }
02aa26ce
NT
11638
11639 /* If it's none of the above, it must be a literal filehandle
11640 (<Foo::BAR> or <FOO>) so build a simple readline OP */
79072805 11641 else {
6136c704 11642 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
9b3023bc
RGS
11643 PL_lex_op = readline_overriden
11644 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11645 append_elem(OP_LIST,
11646 newGVOP(OP_GV, 0, gv),
11647 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11648 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
6154021b 11649 pl_yylval.ival = OP_NULL;
79072805
LW
11650 }
11651 }
02aa26ce 11652
79072805
LW
11653 return s;
11654}
11655
02aa26ce
NT
11656
11657/* scan_str
11658 takes: start position in buffer
09bef843
SB
11659 keep_quoted preserve \ on the embedded delimiter(s)
11660 keep_delims preserve the delimiters around the string
02aa26ce
NT
11661 returns: position to continue reading from buffer
11662 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11663 updates the read buffer.
11664
11665 This subroutine pulls a string out of the input. It is called for:
11666 q single quotes q(literal text)
11667 ' single quotes 'literal text'
11668 qq double quotes qq(interpolate $here please)
11669 " double quotes "interpolate $here please"
11670 qx backticks qx(/bin/ls -l)
11671 ` backticks `/bin/ls -l`
11672 qw quote words @EXPORT_OK = qw( func() $spam )
11673 m// regexp match m/this/
11674 s/// regexp substitute s/this/that/
11675 tr/// string transliterate tr/this/that/
11676 y/// string transliterate y/this/that/
11677 ($*@) sub prototypes sub foo ($)
09bef843 11678 (stuff) sub attr parameters sub foo : attr(stuff)
02aa26ce
NT
11679 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11680
11681 In most of these cases (all but <>, patterns and transliterate)
11682 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11683 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11684 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11685 calls scan_str().
4e553d73 11686
02aa26ce
NT
11687 It skips whitespace before the string starts, and treats the first
11688 character as the delimiter. If the delimiter is one of ([{< then
11689 the corresponding "close" character )]}> is used as the closing
11690 delimiter. It allows quoting of delimiters, and if the string has
11691 balanced delimiters ([{<>}]) it allows nesting.
11692
37fd879b
HS
11693 On success, the SV with the resulting string is put into lex_stuff or,
11694 if that is already non-NULL, into lex_repl. The second case occurs only
11695 when parsing the RHS of the special constructs s/// and tr/// (y///).
11696 For convenience, the terminating delimiter character is stuffed into
11697 SvIVX of the SV.
02aa26ce
NT
11698*/
11699
76e3520e 11700STATIC char *
09bef843 11701S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
79072805 11702{
97aff369 11703 dVAR;
02aa26ce 11704 SV *sv; /* scalar value: string */
d3fcec1f 11705 const char *tmps; /* temp string, used for delimiter matching */
02aa26ce
NT
11706 register char *s = start; /* current position in the buffer */
11707 register char term; /* terminating character */
11708 register char *to; /* current position in the sv's data */
11709 I32 brackets = 1; /* bracket nesting level */
89491803 11710 bool has_utf8 = FALSE; /* is there any utf8 content? */
220e2d4e 11711 I32 termcode; /* terminating char. code */
89ebb4a3 11712 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
220e2d4e 11713 STRLEN termlen; /* length of terminating string */
0331ef07 11714 int last_off = 0; /* last position for nesting bracket */
5db06880
NC
11715#ifdef PERL_MAD
11716 int stuffstart;
11717 char *tstart;
11718#endif
02aa26ce 11719
7918f24d
NC
11720 PERL_ARGS_ASSERT_SCAN_STR;
11721
02aa26ce 11722 /* skip space before the delimiter */
29595ff2
NC
11723 if (isSPACE(*s)) {
11724 s = PEEKSPACE(s);
11725 }
02aa26ce 11726
5db06880 11727#ifdef PERL_MAD
cd81e915
NC
11728 if (PL_realtokenstart >= 0) {
11729 stuffstart = PL_realtokenstart;
11730 PL_realtokenstart = -1;
5db06880
NC
11731 }
11732 else
11733 stuffstart = start - SvPVX(PL_linestr);
11734#endif
02aa26ce 11735 /* mark where we are, in case we need to report errors */
79072805 11736 CLINE;
02aa26ce
NT
11737
11738 /* after skipping whitespace, the next character is the terminator */
a0d0e21e 11739 term = *s;
220e2d4e
IH
11740 if (!UTF) {
11741 termcode = termstr[0] = term;
11742 termlen = 1;
11743 }
11744 else {
f3b9ce0f 11745 termcode = utf8_to_uvchr((U8*)s, &termlen);
220e2d4e
IH
11746 Copy(s, termstr, termlen, U8);
11747 if (!UTF8_IS_INVARIANT(term))
11748 has_utf8 = TRUE;
11749 }
b1c7b182 11750
02aa26ce 11751 /* mark where we are */
57843af0 11752 PL_multi_start = CopLINE(PL_curcop);
3280af22 11753 PL_multi_open = term;
02aa26ce
NT
11754
11755 /* find corresponding closing delimiter */
93a17b20 11756 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
220e2d4e
IH
11757 termcode = termstr[0] = term = tmps[5];
11758
3280af22 11759 PL_multi_close = term;
79072805 11760
561b68a9
SH
11761 /* create a new SV to hold the contents. 79 is the SV's initial length.
11762 What a random number. */
7d0a29fe
NC
11763 sv = newSV_type(SVt_PVIV);
11764 SvGROW(sv, 80);
45977657 11765 SvIV_set(sv, termcode);
a0d0e21e 11766 (void)SvPOK_only(sv); /* validate pointer */
02aa26ce
NT
11767
11768 /* move past delimiter and try to read a complete string */
09bef843 11769 if (keep_delims)
220e2d4e
IH
11770 sv_catpvn(sv, s, termlen);
11771 s += termlen;
5db06880
NC
11772#ifdef PERL_MAD
11773 tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915
NC
11774 if (!PL_thisopen && !keep_delims) {
11775 PL_thisopen = newSVpvn(tstart, s - tstart);
5db06880
NC
11776 stuffstart = s - SvPVX(PL_linestr);
11777 }
11778#endif
93a17b20 11779 for (;;) {
220e2d4e
IH
11780 if (PL_encoding && !UTF) {
11781 bool cont = TRUE;
11782
11783 while (cont) {
95a20fc0 11784 int offset = s - SvPVX_const(PL_linestr);
66a1b24b 11785 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
f3b9ce0f 11786 &offset, (char*)termstr, termlen);
6136c704
AL
11787 const char * const ns = SvPVX_const(PL_linestr) + offset;
11788 char * const svlast = SvEND(sv) - 1;
220e2d4e
IH
11789
11790 for (; s < ns; s++) {
11791 if (*s == '\n' && !PL_rsfp)
11792 CopLINE_inc(PL_curcop);
11793 }
11794 if (!found)
11795 goto read_more_line;
11796 else {
11797 /* handle quoted delimiters */
52327caf 11798 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
f54cb97a 11799 const char *t;
95a20fc0 11800 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
220e2d4e
IH
11801 t--;
11802 if ((svlast-1 - t) % 2) {
11803 if (!keep_quoted) {
11804 *(svlast-1) = term;
11805 *svlast = '\0';
11806 SvCUR_set(sv, SvCUR(sv) - 1);
11807 }
11808 continue;
11809 }
11810 }
11811 if (PL_multi_open == PL_multi_close) {
11812 cont = FALSE;
11813 }
11814 else {
f54cb97a
AL
11815 const char *t;
11816 char *w;
0331ef07 11817 for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
220e2d4e
IH
11818 /* At here, all closes are "was quoted" one,
11819 so we don't check PL_multi_close. */
11820 if (*t == '\\') {
11821 if (!keep_quoted && *(t+1) == PL_multi_open)
11822 t++;
11823 else
11824 *w++ = *t++;
11825 }
11826 else if (*t == PL_multi_open)
11827 brackets++;
11828
11829 *w = *t;
11830 }
11831 if (w < t) {
11832 *w++ = term;
11833 *w = '\0';
95a20fc0 11834 SvCUR_set(sv, w - SvPVX_const(sv));
220e2d4e 11835 }
0331ef07 11836 last_off = w - SvPVX(sv);
220e2d4e
IH
11837 if (--brackets <= 0)
11838 cont = FALSE;
11839 }
11840 }
11841 }
11842 if (!keep_delims) {
11843 SvCUR_set(sv, SvCUR(sv) - 1);
11844 *SvEND(sv) = '\0';
11845 }
11846 break;
11847 }
11848
02aa26ce 11849 /* extend sv if need be */
3280af22 11850 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
02aa26ce 11851 /* set 'to' to the next character in the sv's string */
463ee0b2 11852 to = SvPVX(sv)+SvCUR(sv);
09bef843 11853
02aa26ce 11854 /* if open delimiter is the close delimiter read unbridle */
3280af22
NIS
11855 if (PL_multi_open == PL_multi_close) {
11856 for (; s < PL_bufend; s++,to++) {
02aa26ce 11857 /* embedded newlines increment the current line number */
3280af22 11858 if (*s == '\n' && !PL_rsfp)
57843af0 11859 CopLINE_inc(PL_curcop);
02aa26ce 11860 /* handle quoted delimiters */
3280af22 11861 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
09bef843 11862 if (!keep_quoted && s[1] == term)
a0d0e21e 11863 s++;
02aa26ce 11864 /* any other quotes are simply copied straight through */
a0d0e21e
LW
11865 else
11866 *to++ = *s++;
11867 }
02aa26ce
NT
11868 /* terminate when run out of buffer (the for() condition), or
11869 have found the terminator */
220e2d4e
IH
11870 else if (*s == term) {
11871 if (termlen == 1)
11872 break;
f3b9ce0f 11873 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
220e2d4e
IH
11874 break;
11875 }
63cd0674 11876 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
89491803 11877 has_utf8 = TRUE;
93a17b20
LW
11878 *to = *s;
11879 }
11880 }
02aa26ce
NT
11881
11882 /* if the terminator isn't the same as the start character (e.g.,
11883 matched brackets), we have to allow more in the quoting, and
11884 be prepared for nested brackets.
11885 */
93a17b20 11886 else {
02aa26ce 11887 /* read until we run out of string, or we find the terminator */
3280af22 11888 for (; s < PL_bufend; s++,to++) {
02aa26ce 11889 /* embedded newlines increment the line count */
3280af22 11890 if (*s == '\n' && !PL_rsfp)
57843af0 11891 CopLINE_inc(PL_curcop);
02aa26ce 11892 /* backslashes can escape the open or closing characters */
3280af22 11893 if (*s == '\\' && s+1 < PL_bufend) {
09bef843
SB
11894 if (!keep_quoted &&
11895 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
a0d0e21e
LW
11896 s++;
11897 else
11898 *to++ = *s++;
11899 }
02aa26ce 11900 /* allow nested opens and closes */
3280af22 11901 else if (*s == PL_multi_close && --brackets <= 0)
93a17b20 11902 break;
3280af22 11903 else if (*s == PL_multi_open)
93a17b20 11904 brackets++;
63cd0674 11905 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
89491803 11906 has_utf8 = TRUE;
93a17b20
LW
11907 *to = *s;
11908 }
11909 }
02aa26ce 11910 /* terminate the copied string and update the sv's end-of-string */
93a17b20 11911 *to = '\0';
95a20fc0 11912 SvCUR_set(sv, to - SvPVX_const(sv));
93a17b20 11913
02aa26ce
NT
11914 /*
11915 * this next chunk reads more into the buffer if we're not done yet
11916 */
11917
b1c7b182
GS
11918 if (s < PL_bufend)
11919 break; /* handle case where we are done yet :-) */
79072805 11920
6a27c188 11921#ifndef PERL_STRICT_CR
95a20fc0 11922 if (to - SvPVX_const(sv) >= 2) {
c6f14548
GS
11923 if ((to[-2] == '\r' && to[-1] == '\n') ||
11924 (to[-2] == '\n' && to[-1] == '\r'))
11925 {
f63a84b2
LW
11926 to[-2] = '\n';
11927 to--;
95a20fc0 11928 SvCUR_set(sv, to - SvPVX_const(sv));
f63a84b2
LW
11929 }
11930 else if (to[-1] == '\r')
11931 to[-1] = '\n';
11932 }
95a20fc0 11933 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
f63a84b2
LW
11934 to[-1] = '\n';
11935#endif
11936
220e2d4e 11937 read_more_line:
02aa26ce
NT
11938 /* if we're out of file, or a read fails, bail and reset the current
11939 line marker so we can report where the unterminated string began
11940 */
5db06880
NC
11941#ifdef PERL_MAD
11942 if (PL_madskills) {
c35e046a 11943 char * const tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915
NC
11944 if (PL_thisstuff)
11945 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
5db06880 11946 else
cd81e915 11947 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
5db06880
NC
11948 }
11949#endif
3280af22
NIS
11950 if (!PL_rsfp ||
11951 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
c07a80fd 11952 sv_free(sv);
eb160463 11953 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
bd61b366 11954 return NULL;
79072805 11955 }
5db06880
NC
11956#ifdef PERL_MAD
11957 stuffstart = 0;
11958#endif
02aa26ce 11959 /* we read a line, so increment our line counter */
57843af0 11960 CopLINE_inc(PL_curcop);
a0ed51b3 11961
02aa26ce 11962 /* update debugger info */
65269a95 11963 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
5fa550fb 11964 update_debugger_info(PL_linestr, NULL, 0);
a0ed51b3 11965
3280af22
NIS
11966 /* having changed the buffer, we must update PL_bufend */
11967 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 11968 PL_last_lop = PL_last_uni = NULL;
378cc40b 11969 }
4e553d73 11970
02aa26ce
NT
11971 /* at this point, we have successfully read the delimited string */
11972
220e2d4e 11973 if (!PL_encoding || UTF) {
5db06880
NC
11974#ifdef PERL_MAD
11975 if (PL_madskills) {
c35e046a 11976 char * const tstart = SvPVX(PL_linestr) + stuffstart;
29522234 11977 const int len = s - tstart;
cd81e915 11978 if (PL_thisstuff)
c35e046a 11979 sv_catpvn(PL_thisstuff, tstart, len);
5db06880 11980 else
c35e046a 11981 PL_thisstuff = newSVpvn(tstart, len);
cd81e915
NC
11982 if (!PL_thisclose && !keep_delims)
11983 PL_thisclose = newSVpvn(s,termlen);
5db06880
NC
11984 }
11985#endif
11986
220e2d4e
IH
11987 if (keep_delims)
11988 sv_catpvn(sv, s, termlen);
11989 s += termlen;
11990 }
5db06880
NC
11991#ifdef PERL_MAD
11992 else {
11993 if (PL_madskills) {
c35e046a
AL
11994 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11995 const int len = s - tstart - termlen;
cd81e915 11996 if (PL_thisstuff)
c35e046a 11997 sv_catpvn(PL_thisstuff, tstart, len);
5db06880 11998 else
c35e046a 11999 PL_thisstuff = newSVpvn(tstart, len);
cd81e915
NC
12000 if (!PL_thisclose && !keep_delims)
12001 PL_thisclose = newSVpvn(s - termlen,termlen);
5db06880
NC
12002 }
12003 }
12004#endif
220e2d4e 12005 if (has_utf8 || PL_encoding)
b1c7b182 12006 SvUTF8_on(sv);
d0063567 12007
57843af0 12008 PL_multi_end = CopLINE(PL_curcop);
02aa26ce
NT
12009
12010 /* if we allocated too much space, give some back */
93a17b20
LW
12011 if (SvCUR(sv) + 5 < SvLEN(sv)) {
12012 SvLEN_set(sv, SvCUR(sv) + 1);
b7e9a5c2 12013 SvPV_renew(sv, SvLEN(sv));
79072805 12014 }
02aa26ce
NT
12015
12016 /* decide whether this is the first or second quoted string we've read
12017 for this op
12018 */
4e553d73 12019
3280af22
NIS
12020 if (PL_lex_stuff)
12021 PL_lex_repl = sv;
79072805 12022 else
3280af22 12023 PL_lex_stuff = sv;
378cc40b
LW
12024 return s;
12025}
12026
02aa26ce
NT
12027/*
12028 scan_num
12029 takes: pointer to position in buffer
12030 returns: pointer to new position in buffer
6154021b 12031 side-effects: builds ops for the constant in pl_yylval.op
02aa26ce
NT
12032
12033 Read a number in any of the formats that Perl accepts:
12034
7fd134d9
JH
12035 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
12036 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
24138b49
JH
12037 0b[01](_?[01])*
12038 0[0-7](_?[0-7])*
12039 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
02aa26ce 12040
3280af22 12041 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
02aa26ce
NT
12042 thing it reads.
12043
12044 If it reads a number without a decimal point or an exponent, it will
12045 try converting the number to an integer and see if it can do so
12046 without loss of precision.
12047*/
4e553d73 12048
378cc40b 12049char *
bfed75c6 12050Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
378cc40b 12051{
97aff369 12052 dVAR;
bfed75c6 12053 register const char *s = start; /* current position in buffer */
02aa26ce
NT
12054 register char *d; /* destination in temp buffer */
12055 register char *e; /* end of temp buffer */
86554af2 12056 NV nv; /* number read, as a double */
a0714e2c 12057 SV *sv = NULL; /* place to put the converted number */
a86a20aa 12058 bool floatit; /* boolean: int or float? */
cbbf8932 12059 const char *lastub = NULL; /* position of last underbar */
bfed75c6 12060 static char const number_too_long[] = "Number too long";
378cc40b 12061
7918f24d
NC
12062 PERL_ARGS_ASSERT_SCAN_NUM;
12063
02aa26ce
NT
12064 /* We use the first character to decide what type of number this is */
12065
378cc40b 12066 switch (*s) {
79072805 12067 default:
cea2e8a9 12068 Perl_croak(aTHX_ "panic: scan_num");
4e553d73 12069
02aa26ce 12070 /* if it starts with a 0, it could be an octal number, a decimal in
a7cb1f99 12071 0.13 disguise, or a hexadecimal number, or a binary number. */
378cc40b
LW
12072 case '0':
12073 {
02aa26ce
NT
12074 /* variables:
12075 u holds the "number so far"
4f19785b
WSI
12076 shift the power of 2 of the base
12077 (hex == 4, octal == 3, binary == 1)
02aa26ce
NT
12078 overflowed was the number more than we can hold?
12079
12080 Shift is used when we add a digit. It also serves as an "are
4f19785b
WSI
12081 we in octal/hex/binary?" indicator to disallow hex characters
12082 when in octal mode.
02aa26ce 12083 */
9e24b6e2
JH
12084 NV n = 0.0;
12085 UV u = 0;
79072805 12086 I32 shift;
9e24b6e2 12087 bool overflowed = FALSE;
61f33854 12088 bool just_zero = TRUE; /* just plain 0 or binary number? */
27da23d5
JH
12089 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
12090 static const char* const bases[5] =
12091 { "", "binary", "", "octal", "hexadecimal" };
12092 static const char* const Bases[5] =
12093 { "", "Binary", "", "Octal", "Hexadecimal" };
12094 static const char* const maxima[5] =
12095 { "",
12096 "0b11111111111111111111111111111111",
12097 "",
12098 "037777777777",
12099 "0xffffffff" };
bfed75c6 12100 const char *base, *Base, *max;
378cc40b 12101
02aa26ce 12102 /* check for hex */
378cc40b
LW
12103 if (s[1] == 'x') {
12104 shift = 4;
12105 s += 2;
61f33854 12106 just_zero = FALSE;
4f19785b
WSI
12107 } else if (s[1] == 'b') {
12108 shift = 1;
12109 s += 2;
61f33854 12110 just_zero = FALSE;
378cc40b 12111 }
02aa26ce 12112 /* check for a decimal in disguise */
b78218b7 12113 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
378cc40b 12114 goto decimal;
02aa26ce 12115 /* so it must be octal */
928753ea 12116 else {
378cc40b 12117 shift = 3;
928753ea
JH
12118 s++;
12119 }
12120
12121 if (*s == '_') {
a2a5de95 12122 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
928753ea
JH
12123 "Misplaced _ in number");
12124 lastub = s++;
12125 }
9e24b6e2
JH
12126
12127 base = bases[shift];
12128 Base = Bases[shift];
12129 max = maxima[shift];
02aa26ce 12130
4f19785b 12131 /* read the rest of the number */
378cc40b 12132 for (;;) {
9e24b6e2 12133 /* x is used in the overflow test,
893fe2c2 12134 b is the digit we're adding on. */
9e24b6e2 12135 UV x, b;
55497cff 12136
378cc40b 12137 switch (*s) {
02aa26ce
NT
12138
12139 /* if we don't mention it, we're done */
378cc40b
LW
12140 default:
12141 goto out;
02aa26ce 12142
928753ea 12143 /* _ are ignored -- but warned about if consecutive */
de3bb511 12144 case '_':
a2a5de95
NC
12145 if (lastub && s == lastub + 1)
12146 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
12147 "Misplaced _ in number");
928753ea 12148 lastub = s++;
de3bb511 12149 break;
02aa26ce
NT
12150
12151 /* 8 and 9 are not octal */
378cc40b 12152 case '8': case '9':
4f19785b 12153 if (shift == 3)
cea2e8a9 12154 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
378cc40b 12155 /* FALL THROUGH */
02aa26ce
NT
12156
12157 /* octal digits */
4f19785b 12158 case '2': case '3': case '4':
378cc40b 12159 case '5': case '6': case '7':
4f19785b 12160 if (shift == 1)
cea2e8a9 12161 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
4f19785b
WSI
12162 /* FALL THROUGH */
12163
12164 case '0': case '1':
02aa26ce 12165 b = *s++ & 15; /* ASCII digit -> value of digit */
55497cff 12166 goto digit;
02aa26ce
NT
12167
12168 /* hex digits */
378cc40b
LW
12169 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
12170 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
02aa26ce 12171 /* make sure they said 0x */
378cc40b
LW
12172 if (shift != 4)
12173 goto out;
55497cff 12174 b = (*s++ & 7) + 9;
02aa26ce
NT
12175
12176 /* Prepare to put the digit we have onto the end
12177 of the number so far. We check for overflows.
12178 */
12179
55497cff 12180 digit:
61f33854 12181 just_zero = FALSE;
9e24b6e2
JH
12182 if (!overflowed) {
12183 x = u << shift; /* make room for the digit */
12184
12185 if ((x >> shift) != u
12186 && !(PL_hints & HINT_NEW_BINARY)) {
9e24b6e2
JH
12187 overflowed = TRUE;
12188 n = (NV) u;
9b387841
NC
12189 Perl_ck_warner_d(aTHX_ packWARN(WARN_OVERFLOW),
12190 "Integer overflow in %s number",
12191 base);
9e24b6e2
JH
12192 } else
12193 u = x | b; /* add the digit to the end */
12194 }
12195 if (overflowed) {
12196 n *= nvshift[shift];
12197 /* If an NV has not enough bits in its
12198 * mantissa to represent an UV this summing of
12199 * small low-order numbers is a waste of time
12200 * (because the NV cannot preserve the
12201 * low-order bits anyway): we could just
12202 * remember when did we overflow and in the
12203 * end just multiply n by the right
12204 * amount. */
12205 n += (NV) b;
55497cff 12206 }
378cc40b
LW
12207 break;
12208 }
12209 }
02aa26ce
NT
12210
12211 /* if we get here, we had success: make a scalar value from
12212 the number.
12213 */
378cc40b 12214 out:
928753ea
JH
12215
12216 /* final misplaced underbar check */
12217 if (s[-1] == '_') {
a2a5de95 12218 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
928753ea
JH
12219 }
12220
561b68a9 12221 sv = newSV(0);
9e24b6e2 12222 if (overflowed) {
a2a5de95
NC
12223 if (n > 4294967295.0)
12224 Perl_ck_warner(aTHX_ packWARN(WARN_PORTABLE),
12225 "%s number > %s non-portable",
12226 Base, max);
9e24b6e2
JH
12227 sv_setnv(sv, n);
12228 }
12229 else {
15041a67 12230#if UVSIZE > 4
a2a5de95
NC
12231 if (u > 0xffffffff)
12232 Perl_ck_warner(aTHX_ packWARN(WARN_PORTABLE),
12233 "%s number > %s non-portable",
12234 Base, max);
2cc4c2dc 12235#endif
9e24b6e2
JH
12236 sv_setuv(sv, u);
12237 }
61f33854 12238 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
bfed75c6 12239 sv = new_constant(start, s - start, "integer",
eb0d8d16 12240 sv, NULL, NULL, 0);
61f33854 12241 else if (PL_hints & HINT_NEW_BINARY)
eb0d8d16 12242 sv = new_constant(start, s - start, "binary", sv, NULL, NULL, 0);
378cc40b
LW
12243 }
12244 break;
02aa26ce
NT
12245
12246 /*
12247 handle decimal numbers.
12248 we're also sent here when we read a 0 as the first digit
12249 */
378cc40b
LW
12250 case '1': case '2': case '3': case '4': case '5':
12251 case '6': case '7': case '8': case '9': case '.':
12252 decimal:
3280af22
NIS
12253 d = PL_tokenbuf;
12254 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
79072805 12255 floatit = FALSE;
02aa26ce
NT
12256
12257 /* read next group of digits and _ and copy into d */
de3bb511 12258 while (isDIGIT(*s) || *s == '_') {
4e553d73 12259 /* skip underscores, checking for misplaced ones
02aa26ce
NT
12260 if -w is on
12261 */
93a17b20 12262 if (*s == '_') {
a2a5de95
NC
12263 if (lastub && s == lastub + 1)
12264 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
12265 "Misplaced _ in number");
928753ea 12266 lastub = s++;
93a17b20 12267 }
fc36a67e 12268 else {
02aa26ce 12269 /* check for end of fixed-length buffer */
fc36a67e 12270 if (d >= e)
cea2e8a9 12271 Perl_croak(aTHX_ number_too_long);
02aa26ce 12272 /* if we're ok, copy the character */
378cc40b 12273 *d++ = *s++;
fc36a67e 12274 }
378cc40b 12275 }
02aa26ce
NT
12276
12277 /* final misplaced underbar check */
928753ea 12278 if (lastub && s == lastub + 1) {
a2a5de95 12279 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
d008e5eb 12280 }
02aa26ce
NT
12281
12282 /* read a decimal portion if there is one. avoid
12283 3..5 being interpreted as the number 3. followed
12284 by .5
12285 */
2f3197b3 12286 if (*s == '.' && s[1] != '.') {
79072805 12287 floatit = TRUE;
378cc40b 12288 *d++ = *s++;
02aa26ce 12289
928753ea 12290 if (*s == '_') {
a2a5de95
NC
12291 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
12292 "Misplaced _ in number");
928753ea
JH
12293 lastub = s;
12294 }
12295
12296 /* copy, ignoring underbars, until we run out of digits.
02aa26ce 12297 */
fc36a67e 12298 for (; isDIGIT(*s) || *s == '_'; s++) {
02aa26ce 12299 /* fixed length buffer check */
fc36a67e 12300 if (d >= e)
cea2e8a9 12301 Perl_croak(aTHX_ number_too_long);
928753ea 12302 if (*s == '_') {
a2a5de95
NC
12303 if (lastub && s == lastub + 1)
12304 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
12305 "Misplaced _ in number");
928753ea
JH
12306 lastub = s;
12307 }
12308 else
fc36a67e 12309 *d++ = *s;
378cc40b 12310 }
928753ea
JH
12311 /* fractional part ending in underbar? */
12312 if (s[-1] == '_') {
a2a5de95
NC
12313 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
12314 "Misplaced _ in number");
928753ea 12315 }
dd629d5b
GS
12316 if (*s == '.' && isDIGIT(s[1])) {
12317 /* oops, it's really a v-string, but without the "v" */
f4758303 12318 s = start;
dd629d5b
GS
12319 goto vstring;
12320 }
378cc40b 12321 }
02aa26ce
NT
12322
12323 /* read exponent part, if present */
3792a11b 12324 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
79072805
LW
12325 floatit = TRUE;
12326 s++;
02aa26ce
NT
12327
12328 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
79072805 12329 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
02aa26ce 12330
7fd134d9
JH
12331 /* stray preinitial _ */
12332 if (*s == '_') {
a2a5de95
NC
12333 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
12334 "Misplaced _ in number");
7fd134d9
JH
12335 lastub = s++;
12336 }
12337
02aa26ce 12338 /* allow positive or negative exponent */
378cc40b
LW
12339 if (*s == '+' || *s == '-')
12340 *d++ = *s++;
02aa26ce 12341
7fd134d9
JH
12342 /* stray initial _ */
12343 if (*s == '_') {
a2a5de95
NC
12344 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
12345 "Misplaced _ in number");
7fd134d9
JH
12346 lastub = s++;
12347 }
12348
7fd134d9
JH
12349 /* read digits of exponent */
12350 while (isDIGIT(*s) || *s == '_') {
12351 if (isDIGIT(*s)) {
12352 if (d >= e)
12353 Perl_croak(aTHX_ number_too_long);
b3b48e3e 12354 *d++ = *s++;
7fd134d9
JH
12355 }
12356 else {
041457d9 12357 if (((lastub && s == lastub + 1) ||
a2a5de95
NC
12358 (!isDIGIT(s[1]) && s[1] != '_')))
12359 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
12360 "Misplaced _ in number");
b3b48e3e 12361 lastub = s++;
7fd134d9 12362 }
7fd134d9 12363 }
378cc40b 12364 }
02aa26ce 12365
02aa26ce
NT
12366
12367 /* make an sv from the string */
561b68a9 12368 sv = newSV(0);
097ee67d 12369
0b7fceb9 12370 /*
58bb9ec3
NC
12371 We try to do an integer conversion first if no characters
12372 indicating "float" have been found.
0b7fceb9
MU
12373 */
12374
12375 if (!floatit) {
58bb9ec3 12376 UV uv;
6136c704 12377 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
58bb9ec3
NC
12378
12379 if (flags == IS_NUMBER_IN_UV) {
12380 if (uv <= IV_MAX)
86554af2 12381 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
58bb9ec3 12382 else
c239479b 12383 sv_setuv(sv, uv);
58bb9ec3
NC
12384 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
12385 if (uv <= (UV) IV_MIN)
12386 sv_setiv(sv, -(IV)uv);
12387 else
12388 floatit = TRUE;
12389 } else
12390 floatit = TRUE;
12391 }
0b7fceb9 12392 if (floatit) {
58bb9ec3
NC
12393 /* terminate the string */
12394 *d = '\0';
86554af2
JH
12395 nv = Atof(PL_tokenbuf);
12396 sv_setnv(sv, nv);
12397 }
86554af2 12398
eb0d8d16
NC
12399 if ( floatit
12400 ? (PL_hints & HINT_NEW_FLOAT) : (PL_hints & HINT_NEW_INTEGER) ) {
12401 const char *const key = floatit ? "float" : "integer";
12402 const STRLEN keylen = floatit ? 5 : 7;
12403 sv = S_new_constant(aTHX_ PL_tokenbuf, d - PL_tokenbuf,
12404 key, keylen, sv, NULL, NULL, 0);
12405 }
378cc40b 12406 break;
0b7fceb9 12407
e312add1 12408 /* if it starts with a v, it could be a v-string */
a7cb1f99 12409 case 'v':
dd629d5b 12410vstring:
561b68a9 12411 sv = newSV(5); /* preallocate storage space */
65b06e02 12412 s = scan_vstring(s, PL_bufend, sv);
a7cb1f99 12413 break;
79072805 12414 }
a687059c 12415
02aa26ce
NT
12416 /* make the op for the constant and return */
12417
a86a20aa 12418 if (sv)
b73d6f50 12419 lvalp->opval = newSVOP(OP_CONST, 0, sv);
a7cb1f99 12420 else
5f66b61c 12421 lvalp->opval = NULL;
a687059c 12422
73d840c0 12423 return (char *)s;
378cc40b
LW
12424}
12425
76e3520e 12426STATIC char *
cea2e8a9 12427S_scan_formline(pTHX_ register char *s)
378cc40b 12428{
97aff369 12429 dVAR;
79072805 12430 register char *eol;
378cc40b 12431 register char *t;
6136c704 12432 SV * const stuff = newSVpvs("");
79072805 12433 bool needargs = FALSE;
c5ee2135 12434 bool eofmt = FALSE;
5db06880
NC
12435#ifdef PERL_MAD
12436 char *tokenstart = s;
4f61fd4b
JC
12437 SV* savewhite = NULL;
12438
5db06880 12439 if (PL_madskills) {
cd81e915
NC
12440 savewhite = PL_thiswhite;
12441 PL_thiswhite = 0;
5db06880
NC
12442 }
12443#endif
378cc40b 12444
7918f24d
NC
12445 PERL_ARGS_ASSERT_SCAN_FORMLINE;
12446
79072805 12447 while (!needargs) {
a1b95068 12448 if (*s == '.') {
c35e046a 12449 t = s+1;
51882d45 12450#ifdef PERL_STRICT_CR
c35e046a
AL
12451 while (SPACE_OR_TAB(*t))
12452 t++;
51882d45 12453#else
c35e046a
AL
12454 while (SPACE_OR_TAB(*t) || *t == '\r')
12455 t++;
51882d45 12456#endif
c5ee2135
WL
12457 if (*t == '\n' || t == PL_bufend) {
12458 eofmt = TRUE;
79072805 12459 break;
c5ee2135 12460 }
79072805 12461 }
3280af22 12462 if (PL_in_eval && !PL_rsfp) {
07409e01 12463 eol = (char *) memchr(s,'\n',PL_bufend-s);
0f85fab0 12464 if (!eol++)
3280af22 12465 eol = PL_bufend;
0f85fab0
LW
12466 }
12467 else
3280af22 12468 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
79072805 12469 if (*s != '#') {
a0d0e21e
LW
12470 for (t = s; t < eol; t++) {
12471 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12472 needargs = FALSE;
12473 goto enough; /* ~~ must be first line in formline */
378cc40b 12474 }
a0d0e21e
LW
12475 if (*t == '@' || *t == '^')
12476 needargs = TRUE;
378cc40b 12477 }
7121b347
MG
12478 if (eol > s) {
12479 sv_catpvn(stuff, s, eol-s);
2dc4c65b 12480#ifndef PERL_STRICT_CR
7121b347
MG
12481 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12482 char *end = SvPVX(stuff) + SvCUR(stuff);
12483 end[-2] = '\n';
12484 end[-1] = '\0';
b162af07 12485 SvCUR_set(stuff, SvCUR(stuff) - 1);
7121b347 12486 }
2dc4c65b 12487#endif
7121b347
MG
12488 }
12489 else
12490 break;
79072805 12491 }
95a20fc0 12492 s = (char*)eol;
3280af22 12493 if (PL_rsfp) {
5db06880
NC
12494#ifdef PERL_MAD
12495 if (PL_madskills) {
cd81e915
NC
12496 if (PL_thistoken)
12497 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
5db06880 12498 else
cd81e915 12499 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
5db06880
NC
12500 }
12501#endif
3280af22 12502 s = filter_gets(PL_linestr, PL_rsfp, 0);
5db06880
NC
12503#ifdef PERL_MAD
12504 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12505#else
3280af22 12506 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
5db06880 12507#endif
3280af22 12508 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
bd61b366 12509 PL_last_lop = PL_last_uni = NULL;
79072805 12510 if (!s) {
3280af22 12511 s = PL_bufptr;
378cc40b
LW
12512 break;
12513 }
378cc40b 12514 }
463ee0b2 12515 incline(s);
79072805 12516 }
a0d0e21e
LW
12517 enough:
12518 if (SvCUR(stuff)) {
3280af22 12519 PL_expect = XTERM;
79072805 12520 if (needargs) {
3280af22 12521 PL_lex_state = LEX_NORMAL;
cd81e915 12522 start_force(PL_curforce);
9ded7720 12523 NEXTVAL_NEXTTOKE.ival = 0;
79072805
LW
12524 force_next(',');
12525 }
a0d0e21e 12526 else
3280af22 12527 PL_lex_state = LEX_FORMLINE;
1bd51a4c 12528 if (!IN_BYTES) {
95a20fc0 12529 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
1bd51a4c
IH
12530 SvUTF8_on(stuff);
12531 else if (PL_encoding)
12532 sv_recode_to_utf8(stuff, PL_encoding);
12533 }
cd81e915 12534 start_force(PL_curforce);
9ded7720 12535 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
79072805 12536 force_next(THING);
cd81e915 12537 start_force(PL_curforce);
9ded7720 12538 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
79072805 12539 force_next(LSTOP);
378cc40b 12540 }
79072805 12541 else {
8990e307 12542 SvREFCNT_dec(stuff);
c5ee2135
WL
12543 if (eofmt)
12544 PL_lex_formbrack = 0;
3280af22 12545 PL_bufptr = s;
79072805 12546 }
5db06880
NC
12547#ifdef PERL_MAD
12548 if (PL_madskills) {
cd81e915
NC
12549 if (PL_thistoken)
12550 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
5db06880 12551 else
cd81e915
NC
12552 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12553 PL_thiswhite = savewhite;
5db06880
NC
12554 }
12555#endif
79072805 12556 return s;
378cc40b 12557}
a687059c 12558
ba6d6ac9 12559I32
864dbfa3 12560Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
8990e307 12561{
97aff369 12562 dVAR;
a3b680e6 12563 const I32 oldsavestack_ix = PL_savestack_ix;
6136c704 12564 CV* const outsidecv = PL_compcv;
8990e307 12565
3280af22
NIS
12566 if (PL_compcv) {
12567 assert(SvTYPE(PL_compcv) == SVt_PVCV);
e9a444f0 12568 }
7766f137 12569 SAVEI32(PL_subline);
3280af22 12570 save_item(PL_subname);
3280af22 12571 SAVESPTR(PL_compcv);
3280af22 12572
ea726b52 12573 PL_compcv = MUTABLE_CV(newSV_type(is_format ? SVt_PVFM : SVt_PVCV));
3280af22
NIS
12574 CvFLAGS(PL_compcv) |= flags;
12575
57843af0 12576 PL_subline = CopLINE(PL_curcop);
dd2155a4 12577 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
ea726b52 12578 CvOUTSIDE(PL_compcv) = MUTABLE_CV(SvREFCNT_inc_simple(outsidecv));
a3985cdc 12579 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
748a9306 12580
8990e307
LW
12581 return oldsavestack_ix;
12582}
12583
084592ab
CN
12584#ifdef __SC__
12585#pragma segment Perl_yylex
12586#endif
af41e527
NC
12587static int
12588S_yywarn(pTHX_ const char *const s)
8990e307 12589{
97aff369 12590 dVAR;
7918f24d
NC
12591
12592 PERL_ARGS_ASSERT_YYWARN;
12593
faef0170 12594 PL_in_eval |= EVAL_WARNONLY;
748a9306 12595 yyerror(s);
faef0170 12596 PL_in_eval &= ~EVAL_WARNONLY;
748a9306 12597 return 0;
8990e307
LW
12598}
12599
12600int
15f169a1 12601Perl_yyerror(pTHX_ const char *const s)
463ee0b2 12602{
97aff369 12603 dVAR;
bfed75c6
AL
12604 const char *where = NULL;
12605 const char *context = NULL;
68dc0745 12606 int contlen = -1;
46fc3d4c 12607 SV *msg;
5912531f 12608 int yychar = PL_parser->yychar;
463ee0b2 12609
7918f24d
NC
12610 PERL_ARGS_ASSERT_YYERROR;
12611
3280af22 12612 if (!yychar || (yychar == ';' && !PL_rsfp))
54310121 12613 where = "at EOF";
8bcfe651
TM
12614 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12615 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12616 PL_oldbufptr != PL_bufptr) {
f355267c
JH
12617 /*
12618 Only for NetWare:
12619 The code below is removed for NetWare because it abends/crashes on NetWare
12620 when the script has error such as not having the closing quotes like:
12621 if ($var eq "value)
12622 Checking of white spaces is anyway done in NetWare code.
12623 */
12624#ifndef NETWARE
3280af22
NIS
12625 while (isSPACE(*PL_oldoldbufptr))
12626 PL_oldoldbufptr++;
f355267c 12627#endif
3280af22
NIS
12628 context = PL_oldoldbufptr;
12629 contlen = PL_bufptr - PL_oldoldbufptr;
463ee0b2 12630 }
8bcfe651
TM
12631 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12632 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
f355267c
JH
12633 /*
12634 Only for NetWare:
12635 The code below is removed for NetWare because it abends/crashes on NetWare
12636 when the script has error such as not having the closing quotes like:
12637 if ($var eq "value)
12638 Checking of white spaces is anyway done in NetWare code.
12639 */
12640#ifndef NETWARE
3280af22
NIS
12641 while (isSPACE(*PL_oldbufptr))
12642 PL_oldbufptr++;
f355267c 12643#endif
3280af22
NIS
12644 context = PL_oldbufptr;
12645 contlen = PL_bufptr - PL_oldbufptr;
463ee0b2
LW
12646 }
12647 else if (yychar > 255)
68dc0745 12648 where = "next token ???";
12fbd33b 12649 else if (yychar == -2) { /* YYEMPTY */
3280af22
NIS
12650 if (PL_lex_state == LEX_NORMAL ||
12651 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
68dc0745 12652 where = "at end of line";
3280af22 12653 else if (PL_lex_inpat)
68dc0745 12654 where = "within pattern";
463ee0b2 12655 else
68dc0745 12656 where = "within string";
463ee0b2 12657 }
46fc3d4c 12658 else {
84bafc02 12659 SV * const where_sv = newSVpvs_flags("next char ", SVs_TEMP);
46fc3d4c 12660 if (yychar < 32)
cea2e8a9 12661 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
5e7aa789 12662 else if (isPRINT_LC(yychar)) {
88c9ea1e 12663 const char string = yychar;
5e7aa789
NC
12664 sv_catpvn(where_sv, &string, 1);
12665 }
463ee0b2 12666 else
cea2e8a9 12667 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
95a20fc0 12668 where = SvPVX_const(where_sv);
463ee0b2 12669 }
46fc3d4c 12670 msg = sv_2mortal(newSVpv(s, 0));
ed094faf 12671 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
248c2a4d 12672 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
68dc0745 12673 if (context)
cea2e8a9 12674 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
463ee0b2 12675 else
cea2e8a9 12676 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
57843af0 12677 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
cf2093f6 12678 Perl_sv_catpvf(aTHX_ msg,
57def98f 12679 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
cf2093f6 12680 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
3280af22 12681 PL_multi_end = 0;
a0d0e21e 12682 }
500960a6 12683 if (PL_in_eval & EVAL_WARNONLY) {
9b387841 12684 Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, SVfARG(msg));
500960a6 12685 }
463ee0b2 12686 else
5a844595 12687 qerror(msg);
c7d6bfb2
GS
12688 if (PL_error_count >= 10) {
12689 if (PL_in_eval && SvCUR(ERRSV))
d2560b70 12690 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
be2597df 12691 SVfARG(ERRSV), OutCopFILE(PL_curcop));
c7d6bfb2
GS
12692 else
12693 Perl_croak(aTHX_ "%s has too many errors.\n",
248c2a4d 12694 OutCopFILE(PL_curcop));
c7d6bfb2 12695 }
3280af22 12696 PL_in_my = 0;
5c284bb0 12697 PL_in_my_stash = NULL;
463ee0b2
LW
12698 return 0;
12699}
084592ab
CN
12700#ifdef __SC__
12701#pragma segment Main
12702#endif
4e35701f 12703
b250498f 12704STATIC char*
3ae08724 12705S_swallow_bom(pTHX_ U8 *s)
01ec43d0 12706{
97aff369 12707 dVAR;
f54cb97a 12708 const STRLEN slen = SvCUR(PL_linestr);
7918f24d
NC
12709
12710 PERL_ARGS_ASSERT_SWALLOW_BOM;
12711
7aa207d6 12712 switch (s[0]) {
4e553d73
NIS
12713 case 0xFF:
12714 if (s[1] == 0xFE) {
7aa207d6 12715 /* UTF-16 little-endian? (or UTF32-LE?) */
3ae08724 12716 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
7aa207d6 12717 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
01ec43d0 12718#ifndef PERL_NO_UTF16_FILTER
7aa207d6 12719 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
3ae08724 12720 s += 2;
7aa207d6 12721 utf16le:
dea0fc0b
JH
12722 if (PL_bufend > (char*)s) {
12723 U8 *news;
12724 I32 newlen;
12725
12726 filter_add(utf16rev_textfilter, NULL);
a02a5408 12727 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
1de9afcd 12728 utf16_to_utf8_reversed(s, news,
aed58286 12729 PL_bufend - (char*)s - 1,
1de9afcd 12730 &newlen);
7aa207d6 12731 sv_setpvn(PL_linestr, (const char*)news, newlen);
5db06880
NC
12732#ifdef PERL_MAD
12733 s = (U8*)SvPVX(PL_linestr);
12734 Copy(news, s, newlen, U8);
12735 s[newlen] = '\0';
12736#endif
dea0fc0b 12737 Safefree(news);
7aa207d6
JH
12738 SvUTF8_on(PL_linestr);
12739 s = (U8*)SvPVX(PL_linestr);
5db06880
NC
12740#ifdef PERL_MAD
12741 /* FIXME - is this a general bug fix? */
12742 s[newlen] = '\0';
12743#endif
7aa207d6 12744 PL_bufend = SvPVX(PL_linestr) + newlen;
dea0fc0b 12745 }
b250498f 12746#else
7aa207d6 12747 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
b250498f 12748#endif
01ec43d0
GS
12749 }
12750 break;
78ae23f5 12751 case 0xFE:
7aa207d6 12752 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
01ec43d0 12753#ifndef PERL_NO_UTF16_FILTER
7aa207d6 12754 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
dea0fc0b 12755 s += 2;
7aa207d6 12756 utf16be:
dea0fc0b
JH
12757 if (PL_bufend > (char *)s) {
12758 U8 *news;
12759 I32 newlen;
12760
12761 filter_add(utf16_textfilter, NULL);
a02a5408 12762 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
1de9afcd
RGS
12763 utf16_to_utf8(s, news,
12764 PL_bufend - (char*)s,
12765 &newlen);
7aa207d6 12766 sv_setpvn(PL_linestr, (const char*)news, newlen);
dea0fc0b 12767 Safefree(news);
7aa207d6
JH
12768 SvUTF8_on(PL_linestr);
12769 s = (U8*)SvPVX(PL_linestr);
12770 PL_bufend = SvPVX(PL_linestr) + newlen;
dea0fc0b 12771 }
b250498f 12772#else
7aa207d6 12773 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
b250498f 12774#endif
01ec43d0
GS
12775 }
12776 break;
3ae08724
GS
12777 case 0xEF:
12778 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
7aa207d6 12779 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
01ec43d0
GS
12780 s += 3; /* UTF-8 */
12781 }
12782 break;
12783 case 0:
7aa207d6
JH
12784 if (slen > 3) {
12785 if (s[1] == 0) {
12786 if (s[2] == 0xFE && s[3] == 0xFF) {
12787 /* UTF-32 big-endian */
12788 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12789 }
12790 }
12791 else if (s[2] == 0 && s[3] != 0) {
12792 /* Leading bytes
12793 * 00 xx 00 xx
12794 * are a good indicator of UTF-16BE. */
12795 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12796 goto utf16be;
12797 }
01ec43d0 12798 }
e294cc5d
JH
12799#ifdef EBCDIC
12800 case 0xDD:
12801 if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
12802 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12803 s += 4; /* UTF-8 */
12804 }
12805 break;
12806#endif
12807
7aa207d6
JH
12808 default:
12809 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12810 /* Leading bytes
12811 * xx 00 xx 00
12812 * are a good indicator of UTF-16LE. */
12813 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12814 goto utf16le;
12815 }
01ec43d0 12816 }
b8f84bb2 12817 return (char*)s;
b250498f 12818}
4755096e 12819
6e3aabd6
GS
12820
12821#ifndef PERL_NO_UTF16_FILTER
12822static I32
acfe0abc 12823utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
6e3aabd6 12824{
97aff369 12825 dVAR;
f54cb97a
AL
12826 const STRLEN old = SvCUR(sv);
12827 const I32 count = FILTER_READ(idx+1, sv, maxlen);
1de9afcd
RGS
12828 DEBUG_P(PerlIO_printf(Perl_debug_log,
12829 "utf16_textfilter(%p): %d %d (%d)\n",
55662e27
JH
12830 FPTR2DPTR(void *, utf16_textfilter),
12831 idx, maxlen, (int) count));
6e3aabd6
GS
12832 if (count) {
12833 U8* tmps;
dea0fc0b 12834 I32 newlen;
a02a5408 12835 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
95a20fc0
SP
12836 Copy(SvPVX_const(sv), tmps, old, char);
12837 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
1de9afcd
RGS
12838 SvCUR(sv) - old, &newlen);
12839 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
6e3aabd6 12840 }
1de9afcd
RGS
12841 DEBUG_P({sv_dump(sv);});
12842 return SvCUR(sv);
6e3aabd6
GS
12843}
12844
12845static I32
acfe0abc 12846utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
6e3aabd6 12847{
97aff369 12848 dVAR;
f54cb97a
AL
12849 const STRLEN old = SvCUR(sv);
12850 const I32 count = FILTER_READ(idx+1, sv, maxlen);
1de9afcd
RGS
12851 DEBUG_P(PerlIO_printf(Perl_debug_log,
12852 "utf16rev_textfilter(%p): %d %d (%d)\n",
55662e27
JH
12853 FPTR2DPTR(void *, utf16rev_textfilter),
12854 idx, maxlen, (int) count));
6e3aabd6
GS
12855 if (count) {
12856 U8* tmps;
dea0fc0b 12857 I32 newlen;
a02a5408 12858 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
95a20fc0
SP
12859 Copy(SvPVX_const(sv), tmps, old, char);
12860 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
1de9afcd
RGS
12861 SvCUR(sv) - old, &newlen);
12862 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
6e3aabd6 12863 }
1de9afcd 12864 DEBUG_P({ sv_dump(sv); });
6e3aabd6
GS
12865 return count;
12866}
12867#endif
9f4817db 12868
f333445c
JP
12869/*
12870Returns a pointer to the next character after the parsed
12871vstring, as well as updating the passed in sv.
12872
12873Function must be called like
12874
561b68a9 12875 sv = newSV(5);
65b06e02 12876 s = scan_vstring(s,e,sv);
f333445c 12877
65b06e02 12878where s and e are the start and end of the string.
f333445c
JP
12879The sv should already be large enough to store the vstring
12880passed in, for performance reasons.
12881
12882*/
12883
12884char *
15f169a1 12885Perl_scan_vstring(pTHX_ const char *s, const char *const e, SV *sv)
f333445c 12886{
97aff369 12887 dVAR;
bfed75c6
AL
12888 const char *pos = s;
12889 const char *start = s;
7918f24d
NC
12890
12891 PERL_ARGS_ASSERT_SCAN_VSTRING;
12892
f333445c 12893 if (*pos == 'v') pos++; /* get past 'v' */
65b06e02 12894 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
3e884cbf 12895 pos++;
f333445c
JP
12896 if ( *pos != '.') {
12897 /* this may not be a v-string if followed by => */
bfed75c6 12898 const char *next = pos;
65b06e02 12899 while (next < e && isSPACE(*next))
8fc7bb1c 12900 ++next;
65b06e02 12901 if ((e - next) >= 2 && *next == '=' && next[1] == '>' ) {
f333445c
JP
12902 /* return string not v-string */
12903 sv_setpvn(sv,(char *)s,pos-s);
73d840c0 12904 return (char *)pos;
f333445c
JP
12905 }
12906 }
12907
12908 if (!isALPHA(*pos)) {
89ebb4a3 12909 U8 tmpbuf[UTF8_MAXBYTES+1];
f333445c 12910
d4c19fe8
AL
12911 if (*s == 'v')
12912 s++; /* get past 'v' */
f333445c 12913
76f68e9b 12914 sv_setpvs(sv, "");
f333445c
JP
12915
12916 for (;;) {
d4c19fe8 12917 /* this is atoi() that tolerates underscores */
0bd48802
AL
12918 U8 *tmpend;
12919 UV rev = 0;
d4c19fe8
AL
12920 const char *end = pos;
12921 UV mult = 1;
12922 while (--end >= s) {
12923 if (*end != '_') {
12924 const UV orev = rev;
f333445c
JP
12925 rev += (*end - '0') * mult;
12926 mult *= 10;
9b387841
NC
12927 if (orev > rev)
12928 Perl_ck_warner_d(aTHX_ packWARN(WARN_OVERFLOW),
12929 "Integer overflow in decimal number");
f333445c
JP
12930 }
12931 }
12932#ifdef EBCDIC
12933 if (rev > 0x7FFFFFFF)
12934 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12935#endif
12936 /* Append native character for the rev point */
12937 tmpend = uvchr_to_utf8(tmpbuf, rev);
12938 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12939 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12940 SvUTF8_on(sv);
65b06e02 12941 if (pos + 1 < e && *pos == '.' && isDIGIT(pos[1]))
f333445c
JP
12942 s = ++pos;
12943 else {
12944 s = pos;
12945 break;
12946 }
65b06e02 12947 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
f333445c
JP
12948 pos++;
12949 }
12950 SvPOK_on(sv);
12951 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12952 SvRMAGICAL_on(sv);
12953 }
73d840c0 12954 return (char *)s;
f333445c
JP
12955}
12956
1da4ca5f
NC
12957/*
12958 * Local variables:
12959 * c-indentation-style: bsd
12960 * c-basic-offset: 4
12961 * indent-tabs-mode: t
12962 * End:
12963 *
37442d52
RGS
12964 * ex: set ts=8 sts=4 sw=4 noet:
12965 */