This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: When should PERL_SYS_TERM() be called? [was: Re: [PATCH] Re: [PATCH] Re: [PATCH...
[perl5.git] / toke.c
CommitLineData
a0d0e21e 1/* toke.c
a687059c 2 *
4bb101f2 3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
b94e2f88 4 * 2000, 2001, 2002, 2003, 2004, 2005, 2006, 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/*
12 * "It all comes from here, the stench and the peril." --Frodo
378cc40b
LW
13 */
14
9cbb5ea2
GS
15/*
16 * This file is the lexer for Perl. It's closely linked to the
4e553d73 17 * parser, perly.y.
ffb4593c
NT
18 *
19 * The main routine is yylex(), which returns the next token.
20 */
21
378cc40b 22#include "EXTERN.h"
864dbfa3 23#define PERL_IN_TOKE_C
378cc40b 24#include "perl.h"
378cc40b 25
12fbd33b
DM
26#define yychar (*PL_yycharp)
27#define yylval (*PL_yylvalp)
d3b6f988 28
0bd48802 29static const char ident_too_long[] = "Identifier too long";
c445ea15 30static const char commaless_variable_list[] = "comma-less variable list";
8903cb82 31
acfe0abc 32static void restore_rsfp(pTHX_ void *f);
6e3aabd6 33#ifndef PERL_NO_UTF16_FILTER
acfe0abc
GS
34static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
35static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
6e3aabd6 36#endif
51371543 37
29595ff2 38#ifdef PERL_MAD
29595ff2 39# define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; }
cd81e915 40# define NEXTVAL_NEXTTOKE PL_nexttoke[PL_curforce].next_val
9ded7720 41#else
5db06880 42# define CURMAD(slot,sv)
9ded7720 43# define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
29595ff2
NC
44#endif
45
9059aa12
LW
46#define XFAKEBRACK 128
47#define XENUMMASK 127
48
39e02b42
JH
49#ifdef USE_UTF8_SCRIPTS
50# define UTF (!IN_BYTES)
2b9d42f0 51#else
746b446a 52# define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
2b9d42f0 53#endif
a0ed51b3 54
61f0cdd9 55/* In variables named $^X, these are the legal values for X.
2b92dfce
GS
56 * 1999-02-27 mjd-perl-patch@plover.com */
57#define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
58
bf4acbe4
GS
59/* On MacOS, respect nonbreaking spaces */
60#ifdef MACOS_TRADITIONAL
61#define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
62#else
63#define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
64#endif
65
ffb4593c
NT
66/* LEX_* are values for PL_lex_state, the state of the lexer.
67 * They are arranged oddly so that the guard on the switch statement
79072805
LW
68 * can get by with a single comparison (if the compiler is smart enough).
69 */
70
fb73857a 71/* #define LEX_NOTPARSING 11 is done in perl.h. */
72
b6007c36
DM
73#define LEX_NORMAL 10 /* normal code (ie not within "...") */
74#define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
75#define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
76#define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
77#define LEX_INTERPSTART 6 /* expecting the start of a $var */
78
79 /* at end of code, eg "$x" followed by: */
80#define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
81#define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
82
83#define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
84 string or after \E, $foo, etc */
85#define LEX_INTERPCONST 2 /* NOT USED */
86#define LEX_FORMLINE 1 /* expecting a format line */
87#define LEX_KNOWNEXT 0 /* next token known; just return it */
88
79072805 89
bbf60fe6 90#ifdef DEBUGGING
27da23d5 91static const char* const lex_state_names[] = {
bbf60fe6
DM
92 "KNOWNEXT",
93 "FORMLINE",
94 "INTERPCONST",
95 "INTERPCONCAT",
96 "INTERPENDMAYBE",
97 "INTERPEND",
98 "INTERPSTART",
99 "INTERPPUSH",
100 "INTERPCASEMOD",
101 "INTERPNORMAL",
102 "NORMAL"
103};
104#endif
105
79072805
LW
106#ifdef ff_next
107#undef ff_next
d48672a2
LW
108#endif
109
79072805 110#include "keywords.h"
fe14fcc3 111
ffb4593c
NT
112/* CLINE is a macro that ensures PL_copline has a sane value */
113
ae986130
LW
114#ifdef CLINE
115#undef CLINE
116#endif
57843af0 117#define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
3280af22 118
5db06880 119#ifdef PERL_MAD
29595ff2
NC
120# define SKIPSPACE0(s) skipspace0(s)
121# define SKIPSPACE1(s) skipspace1(s)
122# define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
123# define PEEKSPACE(s) skipspace2(s,0)
124#else
125# define SKIPSPACE0(s) skipspace(s)
126# define SKIPSPACE1(s) skipspace(s)
127# define SKIPSPACE2(s,tsv) skipspace(s)
128# define PEEKSPACE(s) skipspace(s)
129#endif
130
ffb4593c
NT
131/*
132 * Convenience functions to return different tokens and prime the
9cbb5ea2 133 * lexer for the next token. They all take an argument.
ffb4593c
NT
134 *
135 * TOKEN : generic token (used for '(', DOLSHARP, etc)
136 * OPERATOR : generic operator
137 * AOPERATOR : assignment operator
138 * PREBLOCK : beginning the block after an if, while, foreach, ...
139 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
140 * PREREF : *EXPR where EXPR is not a simple identifier
141 * TERM : expression term
142 * LOOPX : loop exiting command (goto, last, dump, etc)
143 * FTST : file test operator
144 * FUN0 : zero-argument function
2d2e263d 145 * FUN1 : not used, except for not, which isn't a UNIOP
ffb4593c
NT
146 * BOop : bitwise or or xor
147 * BAop : bitwise and
148 * SHop : shift operator
149 * PWop : power operator
9cbb5ea2 150 * PMop : pattern-matching operator
ffb4593c
NT
151 * Aop : addition-level operator
152 * Mop : multiplication-level operator
153 * Eop : equality-testing operator
e5edeb50 154 * Rop : relational operator <= != gt
ffb4593c
NT
155 *
156 * Also see LOP and lop() below.
157 */
158
998054bd 159#ifdef DEBUGGING /* Serve -DT. */
f5bd084c 160# define REPORT(retval) tokereport((I32)retval)
998054bd 161#else
bbf60fe6 162# define REPORT(retval) (retval)
998054bd
SC
163#endif
164
bbf60fe6
DM
165#define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
166#define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
167#define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
168#define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
169#define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
170#define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
171#define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
172#define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
173#define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
174#define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
175#define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
176#define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
177#define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
178#define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
179#define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
180#define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
181#define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
182#define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
183#define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
184#define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
2f3197b3 185
a687059c
LW
186/* This bit of chicanery makes a unary function followed by
187 * a parenthesis into a function with one argument, highest precedence.
6f33ba73
RGS
188 * The UNIDOR macro is for unary functions that can be followed by the //
189 * operator (such as C<shift // 0>).
a687059c 190 */
376fcdbf
AL
191#define UNI2(f,x) { \
192 yylval.ival = f; \
193 PL_expect = x; \
194 PL_bufptr = s; \
195 PL_last_uni = PL_oldbufptr; \
196 PL_last_lop_op = f; \
197 if (*s == '(') \
198 return REPORT( (int)FUNC1 ); \
29595ff2 199 s = PEEKSPACE(s); \
376fcdbf
AL
200 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
201 }
6f33ba73
RGS
202#define UNI(f) UNI2(f,XTERM)
203#define UNIDOR(f) UNI2(f,XTERMORDORDOR)
a687059c 204
376fcdbf
AL
205#define UNIBRACK(f) { \
206 yylval.ival = f; \
207 PL_bufptr = s; \
208 PL_last_uni = PL_oldbufptr; \
209 if (*s == '(') \
210 return REPORT( (int)FUNC1 ); \
29595ff2 211 s = PEEKSPACE(s); \
376fcdbf
AL
212 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
213 }
79072805 214
9f68db38 215/* grandfather return to old style */
3280af22 216#define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
79072805 217
8fa7f367
JH
218#ifdef DEBUGGING
219
bbf60fe6
DM
220/* how to interpret the yylval associated with the token */
221enum token_type {
222 TOKENTYPE_NONE,
223 TOKENTYPE_IVAL,
224 TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
225 TOKENTYPE_PVAL,
226 TOKENTYPE_OPVAL,
227 TOKENTYPE_GVVAL
228};
229
6d4a66ac
NC
230static struct debug_tokens {
231 const int token;
232 enum token_type type;
233 const char *name;
234} const debug_tokens[] =
9041c2e3 235{
bbf60fe6
DM
236 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
237 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
238 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
239 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
240 { ARROW, TOKENTYPE_NONE, "ARROW" },
241 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
242 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
243 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
244 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
245 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
0d863452 246 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
bbf60fe6
DM
247 { DO, TOKENTYPE_NONE, "DO" },
248 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
249 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
250 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
251 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
252 { ELSE, TOKENTYPE_NONE, "ELSE" },
253 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
254 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
255 { FOR, TOKENTYPE_IVAL, "FOR" },
256 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
257 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
258 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
259 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
260 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
261 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
0d863452 262 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
bbf60fe6
DM
263 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
264 { IF, TOKENTYPE_IVAL, "IF" },
265 { LABEL, TOKENTYPE_PVAL, "LABEL" },
266 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
267 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
268 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
269 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
270 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
271 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
272 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
273 { MY, TOKENTYPE_IVAL, "MY" },
274 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
275 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
276 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
277 { OROP, TOKENTYPE_IVAL, "OROP" },
278 { OROR, TOKENTYPE_NONE, "OROR" },
279 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
280 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
281 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
282 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
283 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
284 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
285 { PREINC, TOKENTYPE_NONE, "PREINC" },
286 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
287 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
288 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
289 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
290 { SUB, TOKENTYPE_NONE, "SUB" },
291 { THING, TOKENTYPE_OPVAL, "THING" },
292 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
293 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
294 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
295 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
296 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
297 { USE, TOKENTYPE_IVAL, "USE" },
0d863452 298 { WHEN, TOKENTYPE_IVAL, "WHEN" },
bbf60fe6
DM
299 { WHILE, TOKENTYPE_IVAL, "WHILE" },
300 { WORD, TOKENTYPE_OPVAL, "WORD" },
c35e046a 301 { 0, TOKENTYPE_NONE, NULL }
bbf60fe6
DM
302};
303
304/* dump the returned token in rv, plus any optional arg in yylval */
998054bd 305
bbf60fe6 306STATIC int
f5bd084c 307S_tokereport(pTHX_ I32 rv)
bbf60fe6 308{
97aff369 309 dVAR;
bbf60fe6 310 if (DEBUG_T_TEST) {
bd61b366 311 const char *name = NULL;
bbf60fe6 312 enum token_type type = TOKENTYPE_NONE;
f54cb97a 313 const struct debug_tokens *p;
396482e1 314 SV* const report = newSVpvs("<== ");
bbf60fe6 315
f54cb97a 316 for (p = debug_tokens; p->token; p++) {
bbf60fe6
DM
317 if (p->token == (int)rv) {
318 name = p->name;
319 type = p->type;
320 break;
321 }
322 }
323 if (name)
54667de8 324 Perl_sv_catpv(aTHX_ report, name);
bbf60fe6
DM
325 else if ((char)rv > ' ' && (char)rv < '~')
326 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
327 else if (!rv)
396482e1 328 sv_catpvs(report, "EOF");
bbf60fe6
DM
329 else
330 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
331 switch (type) {
332 case TOKENTYPE_NONE:
333 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
334 break;
335 case TOKENTYPE_IVAL:
e4584336 336 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival);
bbf60fe6
DM
337 break;
338 case TOKENTYPE_OPNUM:
339 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
340 PL_op_name[yylval.ival]);
341 break;
342 case TOKENTYPE_PVAL:
343 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
344 break;
345 case TOKENTYPE_OPVAL:
b6007c36 346 if (yylval.opval) {
401441c0 347 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
bbf60fe6 348 PL_op_name[yylval.opval->op_type]);
b6007c36
DM
349 if (yylval.opval->op_type == OP_CONST) {
350 Perl_sv_catpvf(aTHX_ report, " %s",
351 SvPEEK(cSVOPx_sv(yylval.opval)));
352 }
353
354 }
401441c0 355 else
396482e1 356 sv_catpvs(report, "(opval=null)");
bbf60fe6
DM
357 break;
358 }
b6007c36 359 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
bbf60fe6
DM
360 };
361 return (int)rv;
998054bd
SC
362}
363
b6007c36
DM
364
365/* print the buffer with suitable escapes */
366
367STATIC void
368S_printbuf(pTHX_ const char* fmt, const char* s)
369{
396482e1 370 SV* const tmp = newSVpvs("");
b6007c36
DM
371 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
372 SvREFCNT_dec(tmp);
373}
374
8fa7f367
JH
375#endif
376
ffb4593c
NT
377/*
378 * S_ao
379 *
c963b151
BD
380 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
381 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
ffb4593c
NT
382 */
383
76e3520e 384STATIC int
cea2e8a9 385S_ao(pTHX_ int toketype)
a0d0e21e 386{
97aff369 387 dVAR;
3280af22
NIS
388 if (*PL_bufptr == '=') {
389 PL_bufptr++;
a0d0e21e
LW
390 if (toketype == ANDAND)
391 yylval.ival = OP_ANDASSIGN;
392 else if (toketype == OROR)
393 yylval.ival = OP_ORASSIGN;
c963b151
BD
394 else if (toketype == DORDOR)
395 yylval.ival = OP_DORASSIGN;
a0d0e21e
LW
396 toketype = ASSIGNOP;
397 }
398 return toketype;
399}
400
ffb4593c
NT
401/*
402 * S_no_op
403 * When Perl expects an operator and finds something else, no_op
404 * prints the warning. It always prints "<something> found where
405 * operator expected. It prints "Missing semicolon on previous line?"
406 * if the surprise occurs at the start of the line. "do you need to
407 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
408 * where the compiler doesn't know if foo is a method call or a function.
409 * It prints "Missing operator before end of line" if there's nothing
410 * after the missing operator, or "... before <...>" if there is something
411 * after the missing operator.
412 */
413
76e3520e 414STATIC void
bfed75c6 415S_no_op(pTHX_ const char *what, char *s)
463ee0b2 416{
97aff369 417 dVAR;
9d4ba2ae
AL
418 char * const oldbp = PL_bufptr;
419 const bool is_first = (PL_oldbufptr == PL_linestart);
68dc0745 420
1189a94a
GS
421 if (!s)
422 s = oldbp;
07c798fb 423 else
1189a94a 424 PL_bufptr = s;
cea2e8a9 425 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
56da5a46
RGS
426 if (ckWARN_d(WARN_SYNTAX)) {
427 if (is_first)
428 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
429 "\t(Missing semicolon on previous line?)\n");
430 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
f54cb97a 431 const char *t;
c35e046a
AL
432 for (t = PL_oldoldbufptr; (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
433 NOOP;
56da5a46
RGS
434 if (t < PL_bufptr && isSPACE(*t))
435 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
436 "\t(Do you need to predeclare %.*s?)\n",
551405c4 437 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
56da5a46
RGS
438 }
439 else {
440 assert(s >= oldbp);
441 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
551405c4 442 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
56da5a46 443 }
07c798fb 444 }
3280af22 445 PL_bufptr = oldbp;
8990e307
LW
446}
447
ffb4593c
NT
448/*
449 * S_missingterm
450 * Complain about missing quote/regexp/heredoc terminator.
d4c19fe8 451 * If it's called with NULL then it cauterizes the line buffer.
ffb4593c
NT
452 * If we're in a delimited string and the delimiter is a control
453 * character, it's reformatted into a two-char sequence like ^C.
454 * This is fatal.
455 */
456
76e3520e 457STATIC void
cea2e8a9 458S_missingterm(pTHX_ char *s)
8990e307 459{
97aff369 460 dVAR;
8990e307
LW
461 char tmpbuf[3];
462 char q;
463 if (s) {
9d4ba2ae 464 char * const nl = strrchr(s,'\n');
d2719217 465 if (nl)
8990e307
LW
466 *nl = '\0';
467 }
9d116dd7
JH
468 else if (
469#ifdef EBCDIC
470 iscntrl(PL_multi_close)
471#else
472 PL_multi_close < 32 || PL_multi_close == 127
473#endif
474 ) {
8990e307 475 *tmpbuf = '^';
585ec06d 476 tmpbuf[1] = (char)toCTRL(PL_multi_close);
8990e307
LW
477 tmpbuf[2] = '\0';
478 s = tmpbuf;
479 }
480 else {
eb160463 481 *tmpbuf = (char)PL_multi_close;
8990e307
LW
482 tmpbuf[1] = '\0';
483 s = tmpbuf;
484 }
485 q = strchr(s,'"') ? '\'' : '"';
cea2e8a9 486 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
463ee0b2 487}
79072805 488
ef89dcc3 489#define FEATURE_IS_ENABLED(name) \
0d863452 490 ((0 != (PL_hints & HINT_LOCALIZE_HH)) \
89529cee 491 && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
0d863452
RH
492/*
493 * S_feature_is_enabled
494 * Check whether the named feature is enabled.
495 */
496STATIC bool
d4c19fe8 497S_feature_is_enabled(pTHX_ const char *name, STRLEN namelen)
0d863452 498{
97aff369 499 dVAR;
0d863452 500 HV * const hinthv = GvHV(PL_hintgv);
7b9ef140 501 char he_name[32] = "feature_";
6fca0082 502 (void) my_strlcpy(&he_name[8], name, 24);
d4c19fe8 503
7b9ef140 504 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
0d863452
RH
505}
506
ffb4593c
NT
507/*
508 * Perl_deprecate
ffb4593c
NT
509 */
510
79072805 511void
bfed75c6 512Perl_deprecate(pTHX_ const char *s)
a0d0e21e 513{
599cee73 514 if (ckWARN(WARN_DEPRECATED))
9014280d 515 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
a0d0e21e
LW
516}
517
12bcd1a6 518void
bfed75c6 519Perl_deprecate_old(pTHX_ const char *s)
12bcd1a6
PM
520{
521 /* This function should NOT be called for any new deprecated warnings */
522 /* Use Perl_deprecate instead */
523 /* */
524 /* It is here to maintain backward compatibility with the pre-5.8 */
525 /* warnings category hierarchy. The "deprecated" category used to */
526 /* live under the "syntax" category. It is now a top-level category */
527 /* in its own right. */
528
529 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
bfed75c6 530 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
12bcd1a6
PM
531 "Use of %s is deprecated", s);
532}
533
ffb4593c 534/*
9cbb5ea2
GS
535 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
536 * utf16-to-utf8-reversed.
ffb4593c
NT
537 */
538
c39cd008
GS
539#ifdef PERL_CR_FILTER
540static void
541strip_return(SV *sv)
542{
95a20fc0 543 register const char *s = SvPVX_const(sv);
9d4ba2ae 544 register const char * const e = s + SvCUR(sv);
c39cd008
GS
545 /* outer loop optimized to do nothing if there are no CR-LFs */
546 while (s < e) {
547 if (*s++ == '\r' && *s == '\n') {
548 /* hit a CR-LF, need to copy the rest */
549 register char *d = s - 1;
550 *d++ = *s++;
551 while (s < e) {
552 if (*s == '\r' && s[1] == '\n')
553 s++;
554 *d++ = *s++;
555 }
556 SvCUR(sv) -= s - d;
557 return;
558 }
559 }
560}
a868473f 561
76e3520e 562STATIC I32
c39cd008 563S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
a868473f 564{
f54cb97a 565 const I32 count = FILTER_READ(idx+1, sv, maxlen);
c39cd008
GS
566 if (count > 0 && !maxlen)
567 strip_return(sv);
568 return count;
a868473f
NIS
569}
570#endif
571
ffb4593c
NT
572/*
573 * Perl_lex_start
9cbb5ea2
GS
574 * Initialize variables. Uses the Perl save_stack to save its state (for
575 * recursive calls to the parser).
ffb4593c
NT
576 */
577
a0d0e21e 578void
864dbfa3 579Perl_lex_start(pTHX_ SV *line)
79072805 580{
97aff369 581 dVAR;
cfd0369c 582 const char *s;
8990e307
LW
583 STRLEN len;
584
3280af22
NIS
585 SAVEI32(PL_lex_dojoin);
586 SAVEI32(PL_lex_brackets);
3280af22
NIS
587 SAVEI32(PL_lex_casemods);
588 SAVEI32(PL_lex_starts);
589 SAVEI32(PL_lex_state);
7766f137 590 SAVEVPTR(PL_lex_inpat);
3280af22 591 SAVEI32(PL_lex_inwhat);
5db06880
NC
592#ifdef PERL_MAD
593 if (PL_lex_state == LEX_KNOWNEXT) {
594 I32 toke = PL_lasttoke;
595 while (--toke >= 0) {
596 SAVEI32(PL_nexttoke[toke].next_type);
597 SAVEVPTR(PL_nexttoke[toke].next_val);
598 if (PL_madskills)
599 SAVEVPTR(PL_nexttoke[toke].next_mad);
600 }
601 SAVEI32(PL_lasttoke);
602 }
603 if (PL_madskills) {
cd81e915
NC
604 SAVESPTR(PL_thistoken);
605 SAVESPTR(PL_thiswhite);
606 SAVESPTR(PL_nextwhite);
607 SAVESPTR(PL_thisopen);
608 SAVESPTR(PL_thisclose);
609 SAVESPTR(PL_thisstuff);
610 SAVEVPTR(PL_thismad);
611 SAVEI32(PL_realtokenstart);
612 SAVEI32(PL_faketokens);
613 }
614 SAVEI32(PL_curforce);
5db06880 615#else
18b09519
GS
616 if (PL_lex_state == LEX_KNOWNEXT) {
617 I32 toke = PL_nexttoke;
618 while (--toke >= 0) {
619 SAVEI32(PL_nexttype[toke]);
620 SAVEVPTR(PL_nextval[toke]);
621 }
622 SAVEI32(PL_nexttoke);
18b09519 623 }
5db06880 624#endif
57843af0 625 SAVECOPLINE(PL_curcop);
3280af22
NIS
626 SAVEPPTR(PL_bufptr);
627 SAVEPPTR(PL_bufend);
628 SAVEPPTR(PL_oldbufptr);
629 SAVEPPTR(PL_oldoldbufptr);
207e3d1a
JH
630 SAVEPPTR(PL_last_lop);
631 SAVEPPTR(PL_last_uni);
3280af22
NIS
632 SAVEPPTR(PL_linestart);
633 SAVESPTR(PL_linestr);
8edd5f42
RGS
634 SAVEGENERICPV(PL_lex_brackstack);
635 SAVEGENERICPV(PL_lex_casestack);
c76ac1ee 636 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
3280af22
NIS
637 SAVESPTR(PL_lex_stuff);
638 SAVEI32(PL_lex_defer);
09bef843 639 SAVEI32(PL_sublex_info.sub_inwhat);
3280af22 640 SAVESPTR(PL_lex_repl);
bebdddfc
GS
641 SAVEINT(PL_expect);
642 SAVEINT(PL_lex_expect);
3280af22
NIS
643
644 PL_lex_state = LEX_NORMAL;
645 PL_lex_defer = 0;
646 PL_expect = XSTATE;
647 PL_lex_brackets = 0;
a02a5408
JC
648 Newx(PL_lex_brackstack, 120, char);
649 Newx(PL_lex_casestack, 12, char);
3280af22
NIS
650 PL_lex_casemods = 0;
651 *PL_lex_casestack = '\0';
652 PL_lex_dojoin = 0;
653 PL_lex_starts = 0;
a0714e2c
SS
654 PL_lex_stuff = NULL;
655 PL_lex_repl = NULL;
3280af22 656 PL_lex_inpat = 0;
5db06880
NC
657#ifdef PERL_MAD
658 PL_lasttoke = 0;
659#else
76be56bc 660 PL_nexttoke = 0;
5db06880 661#endif
3280af22 662 PL_lex_inwhat = 0;
09bef843 663 PL_sublex_info.sub_inwhat = 0;
3280af22 664 PL_linestr = line;
cfd0369c 665 s = SvPV_const(PL_linestr, len);
0eb20fa2
DM
666 if (SvREADONLY(PL_linestr) || !len || s[len-1] != ';') {
667 PL_linestr = sv_2mortal(len ? newSVsv(PL_linestr) : newSVpvn(s, 0));
668 if (!len || s[len-1] != ';')
669 sv_catpvs(PL_linestr, "\n;");
8990e307 670 }
3280af22
NIS
671 SvTEMP_off(PL_linestr);
672 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
673 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
bd61b366 674 PL_last_lop = PL_last_uni = NULL;
3280af22 675 PL_rsfp = 0;
79072805 676}
a687059c 677
ffb4593c
NT
678/*
679 * Perl_lex_end
9cbb5ea2
GS
680 * Finalizer for lexing operations. Must be called when the parser is
681 * done with the lexer.
ffb4593c
NT
682 */
683
463ee0b2 684void
864dbfa3 685Perl_lex_end(pTHX)
463ee0b2 686{
97aff369 687 dVAR;
3280af22 688 PL_doextract = FALSE;
463ee0b2
LW
689}
690
ffb4593c
NT
691/*
692 * S_incline
693 * This subroutine has nothing to do with tilting, whether at windmills
694 * or pinball tables. Its name is short for "increment line". It
57843af0 695 * increments the current line number in CopLINE(PL_curcop) and checks
ffb4593c 696 * to see whether the line starts with a comment of the form
9cbb5ea2
GS
697 * # line 500 "foo.pm"
698 * If so, it sets the current line number and file to the values in the comment.
ffb4593c
NT
699 */
700
76e3520e 701STATIC void
cea2e8a9 702S_incline(pTHX_ char *s)
463ee0b2 703{
97aff369 704 dVAR;
463ee0b2
LW
705 char *t;
706 char *n;
73659bf1 707 char *e;
463ee0b2 708 char ch;
463ee0b2 709
57843af0 710 CopLINE_inc(PL_curcop);
463ee0b2
LW
711 if (*s++ != '#')
712 return;
d4c19fe8
AL
713 while (SPACE_OR_TAB(*s))
714 s++;
73659bf1
GS
715 if (strnEQ(s, "line", 4))
716 s += 4;
717 else
718 return;
084592ab 719 if (SPACE_OR_TAB(*s))
73659bf1 720 s++;
4e553d73 721 else
73659bf1 722 return;
d4c19fe8
AL
723 while (SPACE_OR_TAB(*s))
724 s++;
463ee0b2
LW
725 if (!isDIGIT(*s))
726 return;
d4c19fe8 727
463ee0b2
LW
728 n = s;
729 while (isDIGIT(*s))
730 s++;
bf4acbe4 731 while (SPACE_OR_TAB(*s))
463ee0b2 732 s++;
73659bf1 733 if (*s == '"' && (t = strchr(s+1, '"'))) {
463ee0b2 734 s++;
73659bf1
GS
735 e = t + 1;
736 }
463ee0b2 737 else {
c35e046a
AL
738 t = s;
739 while (!isSPACE(*t))
740 t++;
73659bf1 741 e = t;
463ee0b2 742 }
bf4acbe4 743 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
73659bf1
GS
744 e++;
745 if (*e != '\n' && *e != '\0')
746 return; /* false alarm */
747
463ee0b2
LW
748 ch = *t;
749 *t = '\0';
f4dd75d9 750 if (t - s > 0) {
8a5ee598 751#ifndef USE_ITHREADS
c4420975 752 const char * const cf = CopFILE(PL_curcop);
42d9b98d
NC
753 STRLEN tmplen = cf ? strlen(cf) : 0;
754 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
e66cf94c
RGS
755 /* must copy *{"::_<(eval N)[oldfilename:L]"}
756 * to *{"::_<newfilename"} */
757 char smallbuf[256], smallbuf2[256];
758 char *tmpbuf, *tmpbuf2;
8a5ee598 759 GV **gvp, *gv2;
e66cf94c
RGS
760 STRLEN tmplen2 = strlen(s);
761 if (tmplen + 3 < sizeof smallbuf)
762 tmpbuf = smallbuf;
763 else
764 Newx(tmpbuf, tmplen + 3, char);
765 if (tmplen2 + 3 < sizeof smallbuf2)
766 tmpbuf2 = smallbuf2;
767 else
768 Newx(tmpbuf2, tmplen2 + 3, char);
769 tmpbuf[0] = tmpbuf2[0] = '_';
770 tmpbuf[1] = tmpbuf2[1] = '<';
771 memcpy(tmpbuf + 2, cf, ++tmplen);
772 memcpy(tmpbuf2 + 2, s, ++tmplen2);
773 ++tmplen; ++tmplen2;
8a5ee598
RGS
774 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
775 if (gvp) {
776 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
e5527e4b 777 if (!isGV(gv2)) {
8a5ee598 778 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
e5527e4b
RGS
779 /* adjust ${"::_<newfilename"} to store the new file name */
780 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
781 GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
782 GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
783 }
8a5ee598 784 }
e66cf94c
RGS
785 if (tmpbuf != smallbuf) Safefree(tmpbuf);
786 if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2);
787 }
8a5ee598 788#endif
05ec9bb3 789 CopFILE_free(PL_curcop);
57843af0 790 CopFILE_set(PL_curcop, s);
f4dd75d9 791 }
463ee0b2 792 *t = ch;
57843af0 793 CopLINE_set(PL_curcop, atoi(n)-1);
463ee0b2
LW
794}
795
29595ff2 796#ifdef PERL_MAD
cd81e915 797/* skip space before PL_thistoken */
29595ff2
NC
798
799STATIC char *
800S_skipspace0(pTHX_ register char *s)
801{
802 s = skipspace(s);
803 if (!PL_madskills)
804 return s;
cd81e915
NC
805 if (PL_skipwhite) {
806 if (!PL_thiswhite)
6b29d1f5 807 PL_thiswhite = newSVpvs("");
cd81e915
NC
808 sv_catsv(PL_thiswhite, PL_skipwhite);
809 sv_free(PL_skipwhite);
810 PL_skipwhite = 0;
811 }
812 PL_realtokenstart = s - SvPVX(PL_linestr);
29595ff2
NC
813 return s;
814}
815
cd81e915 816/* skip space after PL_thistoken */
29595ff2
NC
817
818STATIC char *
819S_skipspace1(pTHX_ register char *s)
820{
d4c19fe8 821 const char *start = s;
29595ff2
NC
822 I32 startoff = start - SvPVX(PL_linestr);
823
824 s = skipspace(s);
825 if (!PL_madskills)
826 return s;
827 start = SvPVX(PL_linestr) + startoff;
cd81e915 828 if (!PL_thistoken && PL_realtokenstart >= 0) {
d4c19fe8 829 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
cd81e915
NC
830 PL_thistoken = newSVpvn(tstart, start - tstart);
831 }
832 PL_realtokenstart = -1;
833 if (PL_skipwhite) {
834 if (!PL_nextwhite)
6b29d1f5 835 PL_nextwhite = newSVpvs("");
cd81e915
NC
836 sv_catsv(PL_nextwhite, PL_skipwhite);
837 sv_free(PL_skipwhite);
838 PL_skipwhite = 0;
29595ff2
NC
839 }
840 return s;
841}
842
843STATIC char *
844S_skipspace2(pTHX_ register char *s, SV **svp)
845{
c35e046a
AL
846 char *start;
847 const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
848 const I32 startoff = s - SvPVX(PL_linestr);
849
29595ff2
NC
850 s = skipspace(s);
851 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
852 if (!PL_madskills || !svp)
853 return s;
854 start = SvPVX(PL_linestr) + startoff;
cd81e915 855 if (!PL_thistoken && PL_realtokenstart >= 0) {
d4c19fe8 856 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
cd81e915
NC
857 PL_thistoken = newSVpvn(tstart, start - tstart);
858 PL_realtokenstart = -1;
29595ff2 859 }
cd81e915 860 if (PL_skipwhite) {
29595ff2 861 if (!*svp)
6b29d1f5 862 *svp = newSVpvs("");
cd81e915
NC
863 sv_setsv(*svp, PL_skipwhite);
864 sv_free(PL_skipwhite);
865 PL_skipwhite = 0;
29595ff2
NC
866 }
867
868 return s;
869}
870#endif
871
80a702cd
RGS
872STATIC void
873S_update_debugger_info_pv(pTHX_ const char *buf, STRLEN len)
874{
875 AV *av = CopFILEAVx(PL_curcop);
876 if (av) {
877 SV * const sv = newSV(0);
878 sv_upgrade(sv, SVt_PVMG);
879 sv_setpvn(sv, buf, len);
880 (void)SvIOK_on(sv);
881 SvIV_set(sv, 0);
882 av_store(av, (I32)CopLINE(PL_curcop), sv);
883 }
884}
885
886STATIC void
887S_update_debugger_info_sv(pTHX_ SV *orig_sv)
888{
889 AV *av = CopFILEAVx(PL_curcop);
890 if (av) {
891 SV * const sv = newSV(0);
892 sv_upgrade(sv, SVt_PVMG);
893 sv_setsv(sv, orig_sv);
894 (void)SvIOK_on(sv);
895 SvIV_set(sv, 0);
896 av_store(av, (I32)CopLINE(PL_curcop), sv);
897 }
898}
899
ffb4593c
NT
900/*
901 * S_skipspace
902 * Called to gobble the appropriate amount and type of whitespace.
903 * Skips comments as well.
904 */
905
76e3520e 906STATIC char *
cea2e8a9 907S_skipspace(pTHX_ register char *s)
a687059c 908{
97aff369 909 dVAR;
5db06880
NC
910#ifdef PERL_MAD
911 int curoff;
912 int startoff = s - SvPVX(PL_linestr);
913
cd81e915
NC
914 if (PL_skipwhite) {
915 sv_free(PL_skipwhite);
916 PL_skipwhite = 0;
5db06880
NC
917 }
918#endif
919
3280af22 920 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
bf4acbe4 921 while (s < PL_bufend && SPACE_OR_TAB(*s))
463ee0b2 922 s++;
5db06880
NC
923#ifdef PERL_MAD
924 goto done;
925#else
463ee0b2 926 return s;
5db06880 927#endif
463ee0b2
LW
928 }
929 for (;;) {
fd049845 930 STRLEN prevlen;
09bef843 931 SSize_t oldprevlen, oldoldprevlen;
9c5ffd7c 932 SSize_t oldloplen = 0, oldunilen = 0;
60e6418e
GS
933 while (s < PL_bufend && isSPACE(*s)) {
934 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
935 incline(s);
936 }
ffb4593c
NT
937
938 /* comment */
3280af22
NIS
939 if (s < PL_bufend && *s == '#') {
940 while (s < PL_bufend && *s != '\n')
463ee0b2 941 s++;
60e6418e 942 if (s < PL_bufend) {
463ee0b2 943 s++;
60e6418e
GS
944 if (PL_in_eval && !PL_rsfp) {
945 incline(s);
946 continue;
947 }
948 }
463ee0b2 949 }
ffb4593c
NT
950
951 /* only continue to recharge the buffer if we're at the end
952 * of the buffer, we're not reading from a source filter, and
953 * we're in normal lexing mode
954 */
09bef843
SB
955 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
956 PL_lex_state == LEX_FORMLINE)
5db06880
NC
957#ifdef PERL_MAD
958 goto done;
959#else
463ee0b2 960 return s;
5db06880 961#endif
ffb4593c
NT
962
963 /* try to recharge the buffer */
5db06880
NC
964#ifdef PERL_MAD
965 curoff = s - SvPVX(PL_linestr);
966#endif
967
9cbb5ea2 968 if ((s = filter_gets(PL_linestr, PL_rsfp,
bd61b366 969 (prevlen = SvCUR(PL_linestr)))) == NULL)
9cbb5ea2 970 {
5db06880
NC
971#ifdef PERL_MAD
972 if (PL_madskills && curoff != startoff) {
cd81e915 973 if (!PL_skipwhite)
6b29d1f5 974 PL_skipwhite = newSVpvs("");
cd81e915 975 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
5db06880
NC
976 curoff - startoff);
977 }
978
979 /* mustn't throw out old stuff yet if madpropping */
980 SvCUR(PL_linestr) = curoff;
981 s = SvPVX(PL_linestr) + curoff;
982 *s = 0;
983 if (curoff && s[-1] == '\n')
984 s[-1] = ' ';
985#endif
986
9cbb5ea2 987 /* end of file. Add on the -p or -n magic */
cd81e915 988 /* XXX these shouldn't really be added here, can't set PL_faketokens */
01a19ab0 989 if (PL_minus_p) {
5db06880
NC
990#ifdef PERL_MAD
991 sv_catpv(PL_linestr,
992 ";}continue{print or die qq(-p destination: $!\\n);}");
993#else
01a19ab0
NC
994 sv_setpv(PL_linestr,
995 ";}continue{print or die qq(-p destination: $!\\n);}");
5db06880 996#endif
3280af22 997 PL_minus_n = PL_minus_p = 0;
a0d0e21e 998 }
01a19ab0 999 else if (PL_minus_n) {
5db06880
NC
1000#ifdef PERL_MAD
1001 sv_catpvn(PL_linestr, ";}", 2);
1002#else
01a19ab0 1003 sv_setpvn(PL_linestr, ";}", 2);
5db06880 1004#endif
01a19ab0
NC
1005 PL_minus_n = 0;
1006 }
a0d0e21e 1007 else
5db06880
NC
1008#ifdef PERL_MAD
1009 sv_catpvn(PL_linestr,";", 1);
1010#else
4147a61b 1011 sv_setpvn(PL_linestr,";", 1);
5db06880 1012#endif
ffb4593c
NT
1013
1014 /* reset variables for next time we lex */
9cbb5ea2 1015 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
89122651
NC
1016 = SvPVX(PL_linestr)
1017#ifdef PERL_MAD
1018 + curoff
1019#endif
1020 ;
3280af22 1021 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 1022 PL_last_lop = PL_last_uni = NULL;
ffb4593c
NT
1023
1024 /* Close the filehandle. Could be from -P preprocessor,
1025 * STDIN, or a regular file. If we were reading code from
1026 * STDIN (because the commandline held no -e or filename)
1027 * then we don't close it, we reset it so the code can
1028 * read from STDIN too.
1029 */
1030
3280af22
NIS
1031 if (PL_preprocess && !PL_in_eval)
1032 (void)PerlProc_pclose(PL_rsfp);
1033 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
1034 PerlIO_clearerr(PL_rsfp);
8990e307 1035 else
3280af22 1036 (void)PerlIO_close(PL_rsfp);
4608196e 1037 PL_rsfp = NULL;
463ee0b2
LW
1038 return s;
1039 }
ffb4593c
NT
1040
1041 /* not at end of file, so we only read another line */
09bef843
SB
1042 /* make corresponding updates to old pointers, for yyerror() */
1043 oldprevlen = PL_oldbufptr - PL_bufend;
1044 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1045 if (PL_last_uni)
1046 oldunilen = PL_last_uni - PL_bufend;
1047 if (PL_last_lop)
1048 oldloplen = PL_last_lop - PL_bufend;
3280af22
NIS
1049 PL_linestart = PL_bufptr = s + prevlen;
1050 PL_bufend = s + SvCUR(PL_linestr);
1051 s = PL_bufptr;
09bef843
SB
1052 PL_oldbufptr = s + oldprevlen;
1053 PL_oldoldbufptr = s + oldoldprevlen;
1054 if (PL_last_uni)
1055 PL_last_uni = s + oldunilen;
1056 if (PL_last_lop)
1057 PL_last_lop = s + oldloplen;
a0d0e21e 1058 incline(s);
ffb4593c
NT
1059
1060 /* debugger active and we're not compiling the debugger code,
1061 * so store the line into the debugger's array of lines
1062 */
80a702cd
RGS
1063 if (PERLDB_LINE && PL_curstash != PL_debstash)
1064 update_debugger_info_pv(PL_bufptr, PL_bufend - PL_bufptr);
463ee0b2 1065 }
5db06880
NC
1066
1067#ifdef PERL_MAD
1068 done:
1069 if (PL_madskills) {
cd81e915 1070 if (!PL_skipwhite)
6b29d1f5 1071 PL_skipwhite = newSVpvs("");
5db06880
NC
1072 curoff = s - SvPVX(PL_linestr);
1073 if (curoff - startoff)
cd81e915 1074 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
5db06880
NC
1075 curoff - startoff);
1076 }
1077 return s;
1078#endif
a687059c 1079}
378cc40b 1080
ffb4593c
NT
1081/*
1082 * S_check_uni
1083 * Check the unary operators to ensure there's no ambiguity in how they're
1084 * used. An ambiguous piece of code would be:
1085 * rand + 5
1086 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1087 * the +5 is its argument.
1088 */
1089
76e3520e 1090STATIC void
cea2e8a9 1091S_check_uni(pTHX)
ba106d47 1092{
97aff369 1093 dVAR;
d4c19fe8
AL
1094 const char *s;
1095 const char *t;
2f3197b3 1096
3280af22 1097 if (PL_oldoldbufptr != PL_last_uni)
2f3197b3 1098 return;
3280af22
NIS
1099 while (isSPACE(*PL_last_uni))
1100 PL_last_uni++;
c35e046a
AL
1101 s = PL_last_uni;
1102 while (isALNUM_lazy_if(s,UTF) || *s == '-')
1103 s++;
3280af22 1104 if ((t = strchr(s, '(')) && t < PL_bufptr)
a0d0e21e 1105 return;
6136c704 1106
0453d815 1107 if (ckWARN_d(WARN_AMBIGUOUS)){
9014280d 1108 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
32d45c1d
NC
1109 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1110 (int)(s - PL_last_uni), PL_last_uni);
0453d815 1111 }
2f3197b3
LW
1112}
1113
ffb4593c
NT
1114/*
1115 * LOP : macro to build a list operator. Its behaviour has been replaced
1116 * with a subroutine, S_lop() for which LOP is just another name.
1117 */
1118
a0d0e21e
LW
1119#define LOP(f,x) return lop(f,x,s)
1120
ffb4593c
NT
1121/*
1122 * S_lop
1123 * Build a list operator (or something that might be one). The rules:
1124 * - if we have a next token, then it's a list operator [why?]
1125 * - if the next thing is an opening paren, then it's a function
1126 * - else it's a list operator
1127 */
1128
76e3520e 1129STATIC I32
a0be28da 1130S_lop(pTHX_ I32 f, int x, char *s)
ffed7fef 1131{
97aff369 1132 dVAR;
79072805 1133 yylval.ival = f;
35c8bce7 1134 CLINE;
3280af22
NIS
1135 PL_expect = x;
1136 PL_bufptr = s;
1137 PL_last_lop = PL_oldbufptr;
eb160463 1138 PL_last_lop_op = (OPCODE)f;
5db06880
NC
1139#ifdef PERL_MAD
1140 if (PL_lasttoke)
1141 return REPORT(LSTOP);
1142#else
3280af22 1143 if (PL_nexttoke)
bbf60fe6 1144 return REPORT(LSTOP);
5db06880 1145#endif
79072805 1146 if (*s == '(')
bbf60fe6 1147 return REPORT(FUNC);
29595ff2 1148 s = PEEKSPACE(s);
79072805 1149 if (*s == '(')
bbf60fe6 1150 return REPORT(FUNC);
79072805 1151 else
bbf60fe6 1152 return REPORT(LSTOP);
79072805
LW
1153}
1154
5db06880
NC
1155#ifdef PERL_MAD
1156 /*
1157 * S_start_force
1158 * Sets up for an eventual force_next(). start_force(0) basically does
1159 * an unshift, while start_force(-1) does a push. yylex removes items
1160 * on the "pop" end.
1161 */
1162
1163STATIC void
1164S_start_force(pTHX_ int where)
1165{
1166 int i;
1167
cd81e915 1168 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
5db06880 1169 where = PL_lasttoke;
cd81e915
NC
1170 assert(PL_curforce < 0 || PL_curforce == where);
1171 if (PL_curforce != where) {
5db06880
NC
1172 for (i = PL_lasttoke; i > where; --i) {
1173 PL_nexttoke[i] = PL_nexttoke[i-1];
1174 }
1175 PL_lasttoke++;
1176 }
cd81e915 1177 if (PL_curforce < 0) /* in case of duplicate start_force() */
5db06880 1178 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
cd81e915
NC
1179 PL_curforce = where;
1180 if (PL_nextwhite) {
5db06880 1181 if (PL_madskills)
6b29d1f5 1182 curmad('^', newSVpvs(""));
cd81e915 1183 CURMAD('_', PL_nextwhite);
5db06880
NC
1184 }
1185}
1186
1187STATIC void
1188S_curmad(pTHX_ char slot, SV *sv)
1189{
1190 MADPROP **where;
1191
1192 if (!sv)
1193 return;
cd81e915
NC
1194 if (PL_curforce < 0)
1195 where = &PL_thismad;
5db06880 1196 else
cd81e915 1197 where = &PL_nexttoke[PL_curforce].next_mad;
5db06880 1198
cd81e915 1199 if (PL_faketokens)
5db06880
NC
1200 sv_setpvn(sv, "", 0);
1201 else {
1202 if (!IN_BYTES) {
1203 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1204 SvUTF8_on(sv);
1205 else if (PL_encoding) {
1206 sv_recode_to_utf8(sv, PL_encoding);
1207 }
1208 }
1209 }
1210
1211 /* keep a slot open for the head of the list? */
1212 if (slot != '_' && *where && (*where)->mad_key == '^') {
1213 (*where)->mad_key = slot;
1214 sv_free((*where)->mad_val);
1215 (*where)->mad_val = (void*)sv;
1216 }
1217 else
1218 addmad(newMADsv(slot, sv), where, 0);
1219}
1220#else
b3f24c00
MHM
1221# define start_force(where) NOOP
1222# define curmad(slot, sv) NOOP
5db06880
NC
1223#endif
1224
ffb4593c
NT
1225/*
1226 * S_force_next
9cbb5ea2 1227 * When the lexer realizes it knows the next token (for instance,
ffb4593c 1228 * it is reordering tokens for the parser) then it can call S_force_next
9cbb5ea2 1229 * to know what token to return the next time the lexer is called. Caller
5db06880
NC
1230 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1231 * and possibly PL_expect to ensure the lexer handles the token correctly.
ffb4593c
NT
1232 */
1233
4e553d73 1234STATIC void
cea2e8a9 1235S_force_next(pTHX_ I32 type)
79072805 1236{
97aff369 1237 dVAR;
5db06880 1238#ifdef PERL_MAD
cd81e915 1239 if (PL_curforce < 0)
5db06880 1240 start_force(PL_lasttoke);
cd81e915 1241 PL_nexttoke[PL_curforce].next_type = type;
5db06880
NC
1242 if (PL_lex_state != LEX_KNOWNEXT)
1243 PL_lex_defer = PL_lex_state;
1244 PL_lex_state = LEX_KNOWNEXT;
1245 PL_lex_expect = PL_expect;
cd81e915 1246 PL_curforce = -1;
5db06880 1247#else
3280af22
NIS
1248 PL_nexttype[PL_nexttoke] = type;
1249 PL_nexttoke++;
1250 if (PL_lex_state != LEX_KNOWNEXT) {
1251 PL_lex_defer = PL_lex_state;
1252 PL_lex_expect = PL_expect;
1253 PL_lex_state = LEX_KNOWNEXT;
79072805 1254 }
5db06880 1255#endif
79072805
LW
1256}
1257
d0a148a6
NC
1258STATIC SV *
1259S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
1260{
97aff369 1261 dVAR;
9d4ba2ae 1262 SV * const sv = newSVpvn(start,len);
bfed75c6 1263 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
d0a148a6
NC
1264 SvUTF8_on(sv);
1265 return sv;
1266}
1267
ffb4593c
NT
1268/*
1269 * S_force_word
1270 * When the lexer knows the next thing is a word (for instance, it has
1271 * just seen -> and it knows that the next char is a word char, then
1272 * it calls S_force_word to stick the next word into the PL_next lookahead.
1273 *
1274 * Arguments:
b1b65b59 1275 * char *start : buffer position (must be within PL_linestr)
ffb4593c
NT
1276 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
1277 * int check_keyword : if true, Perl checks to make sure the word isn't
1278 * a keyword (do this if the word is a label, e.g. goto FOO)
1279 * int allow_pack : if true, : characters will also be allowed (require,
1280 * use, etc. do this)
9cbb5ea2 1281 * int allow_initial_tick : used by the "sub" lexer only.
ffb4593c
NT
1282 */
1283
76e3520e 1284STATIC char *
cea2e8a9 1285S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
79072805 1286{
97aff369 1287 dVAR;
463ee0b2
LW
1288 register char *s;
1289 STRLEN len;
4e553d73 1290
29595ff2 1291 start = SKIPSPACE1(start);
463ee0b2 1292 s = start;
7e2040f0 1293 if (isIDFIRST_lazy_if(s,UTF) ||
a0d0e21e 1294 (allow_pack && *s == ':') ||
15f0808c 1295 (allow_initial_tick && *s == '\'') )
a0d0e21e 1296 {
3280af22 1297 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
5458a98a 1298 if (check_keyword && keyword(PL_tokenbuf, len, 0))
463ee0b2 1299 return start;
cd81e915 1300 start_force(PL_curforce);
5db06880
NC
1301 if (PL_madskills)
1302 curmad('X', newSVpvn(start,s-start));
463ee0b2 1303 if (token == METHOD) {
29595ff2 1304 s = SKIPSPACE1(s);
463ee0b2 1305 if (*s == '(')
3280af22 1306 PL_expect = XTERM;
463ee0b2 1307 else {
3280af22 1308 PL_expect = XOPERATOR;
463ee0b2 1309 }
79072805 1310 }
9ded7720 1311 NEXTVAL_NEXTTOKE.opval
d0a148a6
NC
1312 = (OP*)newSVOP(OP_CONST,0,
1313 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
9ded7720 1314 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
79072805
LW
1315 force_next(token);
1316 }
1317 return s;
1318}
1319
ffb4593c
NT
1320/*
1321 * S_force_ident
9cbb5ea2 1322 * Called when the lexer wants $foo *foo &foo etc, but the program
ffb4593c
NT
1323 * text only contains the "foo" portion. The first argument is a pointer
1324 * to the "foo", and the second argument is the type symbol to prefix.
1325 * Forces the next token to be a "WORD".
9cbb5ea2 1326 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
ffb4593c
NT
1327 */
1328
76e3520e 1329STATIC void
bfed75c6 1330S_force_ident(pTHX_ register const char *s, int kind)
79072805 1331{
97aff369 1332 dVAR;
c35e046a 1333 if (*s) {
90e5519e
NC
1334 const STRLEN len = strlen(s);
1335 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
cd81e915 1336 start_force(PL_curforce);
9ded7720 1337 NEXTVAL_NEXTTOKE.opval = o;
79072805 1338 force_next(WORD);
748a9306 1339 if (kind) {
11343788 1340 o->op_private = OPpCONST_ENTERED;
55497cff 1341 /* XXX see note in pp_entereval() for why we forgo typo
1342 warnings if the symbol must be introduced in an eval.
1343 GSAR 96-10-12 */
90e5519e
NC
1344 gv_fetchpvn_flags(s, len,
1345 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1346 : GV_ADD,
1347 kind == '$' ? SVt_PV :
1348 kind == '@' ? SVt_PVAV :
1349 kind == '%' ? SVt_PVHV :
a0d0e21e 1350 SVt_PVGV
90e5519e 1351 );
748a9306 1352 }
79072805
LW
1353 }
1354}
1355
1571675a
GS
1356NV
1357Perl_str_to_version(pTHX_ SV *sv)
1358{
1359 NV retval = 0.0;
1360 NV nshift = 1.0;
1361 STRLEN len;
cfd0369c 1362 const char *start = SvPV_const(sv,len);
9d4ba2ae 1363 const char * const end = start + len;
504618e9 1364 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1571675a 1365 while (start < end) {
ba210ebe 1366 STRLEN skip;
1571675a
GS
1367 UV n;
1368 if (utf)
9041c2e3 1369 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1571675a
GS
1370 else {
1371 n = *(U8*)start;
1372 skip = 1;
1373 }
1374 retval += ((NV)n)/nshift;
1375 start += skip;
1376 nshift *= 1000;
1377 }
1378 return retval;
1379}
1380
4e553d73 1381/*
ffb4593c
NT
1382 * S_force_version
1383 * Forces the next token to be a version number.
e759cc13
RGS
1384 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1385 * and if "guessing" is TRUE, then no new token is created (and the caller
1386 * must use an alternative parsing method).
ffb4593c
NT
1387 */
1388
76e3520e 1389STATIC char *
e759cc13 1390S_force_version(pTHX_ char *s, int guessing)
89bfa8cd 1391{
97aff369 1392 dVAR;
5f66b61c 1393 OP *version = NULL;
44dcb63b 1394 char *d;
5db06880
NC
1395#ifdef PERL_MAD
1396 I32 startoff = s - SvPVX(PL_linestr);
1397#endif
89bfa8cd 1398
29595ff2 1399 s = SKIPSPACE1(s);
89bfa8cd 1400
44dcb63b 1401 d = s;
dd629d5b 1402 if (*d == 'v')
44dcb63b 1403 d++;
44dcb63b 1404 if (isDIGIT(*d)) {
e759cc13
RGS
1405 while (isDIGIT(*d) || *d == '_' || *d == '.')
1406 d++;
5db06880
NC
1407#ifdef PERL_MAD
1408 if (PL_madskills) {
cd81e915 1409 start_force(PL_curforce);
5db06880
NC
1410 curmad('X', newSVpvn(s,d-s));
1411 }
1412#endif
9f3d182e 1413 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
dd629d5b 1414 SV *ver;
b73d6f50 1415 s = scan_num(s, &yylval);
89bfa8cd 1416 version = yylval.opval;
dd629d5b
GS
1417 ver = cSVOPx(version)->op_sv;
1418 if (SvPOK(ver) && !SvNIOK(ver)) {
862a34c6 1419 SvUPGRADE(ver, SVt_PVNV);
9d6ce603 1420 SvNV_set(ver, str_to_version(ver));
1571675a 1421 SvNOK_on(ver); /* hint that it is a version */
44dcb63b 1422 }
89bfa8cd 1423 }
5db06880
NC
1424 else if (guessing) {
1425#ifdef PERL_MAD
1426 if (PL_madskills) {
cd81e915
NC
1427 sv_free(PL_nextwhite); /* let next token collect whitespace */
1428 PL_nextwhite = 0;
5db06880
NC
1429 s = SvPVX(PL_linestr) + startoff;
1430 }
1431#endif
e759cc13 1432 return s;
5db06880 1433 }
89bfa8cd 1434 }
1435
5db06880
NC
1436#ifdef PERL_MAD
1437 if (PL_madskills && !version) {
cd81e915
NC
1438 sv_free(PL_nextwhite); /* let next token collect whitespace */
1439 PL_nextwhite = 0;
5db06880
NC
1440 s = SvPVX(PL_linestr) + startoff;
1441 }
1442#endif
89bfa8cd 1443 /* NOTE: The parser sees the package name and the VERSION swapped */
cd81e915 1444 start_force(PL_curforce);
9ded7720 1445 NEXTVAL_NEXTTOKE.opval = version;
4e553d73 1446 force_next(WORD);
89bfa8cd 1447
e759cc13 1448 return s;
89bfa8cd 1449}
1450
ffb4593c
NT
1451/*
1452 * S_tokeq
1453 * Tokenize a quoted string passed in as an SV. It finds the next
1454 * chunk, up to end of string or a backslash. It may make a new
1455 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1456 * turns \\ into \.
1457 */
1458
76e3520e 1459STATIC SV *
cea2e8a9 1460S_tokeq(pTHX_ SV *sv)
79072805 1461{
97aff369 1462 dVAR;
79072805
LW
1463 register char *s;
1464 register char *send;
1465 register char *d;
b3ac6de7
IZ
1466 STRLEN len = 0;
1467 SV *pv = sv;
79072805
LW
1468
1469 if (!SvLEN(sv))
b3ac6de7 1470 goto finish;
79072805 1471
a0d0e21e 1472 s = SvPV_force(sv, len);
21a311ee 1473 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
b3ac6de7 1474 goto finish;
463ee0b2 1475 send = s + len;
79072805
LW
1476 while (s < send && *s != '\\')
1477 s++;
1478 if (s == send)
b3ac6de7 1479 goto finish;
79072805 1480 d = s;
be4731d2 1481 if ( PL_hints & HINT_NEW_STRING ) {
95a20fc0 1482 pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
be4731d2
NIS
1483 if (SvUTF8(sv))
1484 SvUTF8_on(pv);
1485 }
79072805
LW
1486 while (s < send) {
1487 if (*s == '\\') {
a0d0e21e 1488 if (s + 1 < send && (s[1] == '\\'))
79072805
LW
1489 s++; /* all that, just for this */
1490 }
1491 *d++ = *s++;
1492 }
1493 *d = '\0';
95a20fc0 1494 SvCUR_set(sv, d - SvPVX_const(sv));
b3ac6de7 1495 finish:
3280af22 1496 if ( PL_hints & HINT_NEW_STRING )
b3ac6de7 1497 return new_constant(NULL, 0, "q", sv, pv, "q");
79072805
LW
1498 return sv;
1499}
1500
ffb4593c
NT
1501/*
1502 * Now come three functions related to double-quote context,
1503 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1504 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1505 * interact with PL_lex_state, and create fake ( ... ) argument lists
1506 * to handle functions and concatenation.
1507 * They assume that whoever calls them will be setting up a fake
1508 * join call, because each subthing puts a ',' after it. This lets
1509 * "lower \luPpEr"
1510 * become
1511 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1512 *
1513 * (I'm not sure whether the spurious commas at the end of lcfirst's
1514 * arguments and join's arguments are created or not).
1515 */
1516
1517/*
1518 * S_sublex_start
1519 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1520 *
1521 * Pattern matching will set PL_lex_op to the pattern-matching op to
1522 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1523 *
1524 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1525 *
1526 * Everything else becomes a FUNC.
1527 *
1528 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1529 * had an OP_CONST or OP_READLINE). This just sets us up for a
1530 * call to S_sublex_push().
1531 */
1532
76e3520e 1533STATIC I32
cea2e8a9 1534S_sublex_start(pTHX)
79072805 1535{
97aff369 1536 dVAR;
0d46e09a 1537 register const I32 op_type = yylval.ival;
79072805
LW
1538
1539 if (op_type == OP_NULL) {
3280af22 1540 yylval.opval = PL_lex_op;
5f66b61c 1541 PL_lex_op = NULL;
79072805
LW
1542 return THING;
1543 }
1544 if (op_type == OP_CONST || op_type == OP_READLINE) {
3280af22 1545 SV *sv = tokeq(PL_lex_stuff);
b3ac6de7
IZ
1546
1547 if (SvTYPE(sv) == SVt_PVIV) {
1548 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1549 STRLEN len;
96a5add6 1550 const char * const p = SvPV_const(sv, len);
f54cb97a 1551 SV * const nsv = newSVpvn(p, len);
01ec43d0
GS
1552 if (SvUTF8(sv))
1553 SvUTF8_on(nsv);
b3ac6de7
IZ
1554 SvREFCNT_dec(sv);
1555 sv = nsv;
4e553d73 1556 }
b3ac6de7 1557 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
a0714e2c 1558 PL_lex_stuff = NULL;
6f33ba73
RGS
1559 /* Allow <FH> // "foo" */
1560 if (op_type == OP_READLINE)
1561 PL_expect = XTERMORDORDOR;
79072805
LW
1562 return THING;
1563 }
e3f73d4e
RGS
1564 else if (op_type == OP_BACKTICK && PL_lex_op) {
1565 /* readpipe() vas overriden */
1566 cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff);
1567 yylval.opval = PL_lex_op;
9b201d7d 1568 PL_lex_op = NULL;
e3f73d4e
RGS
1569 PL_lex_stuff = NULL;
1570 return THING;
1571 }
79072805 1572
3280af22
NIS
1573 PL_sublex_info.super_state = PL_lex_state;
1574 PL_sublex_info.sub_inwhat = op_type;
1575 PL_sublex_info.sub_op = PL_lex_op;
1576 PL_lex_state = LEX_INTERPPUSH;
55497cff 1577
3280af22
NIS
1578 PL_expect = XTERM;
1579 if (PL_lex_op) {
1580 yylval.opval = PL_lex_op;
5f66b61c 1581 PL_lex_op = NULL;
55497cff 1582 return PMFUNC;
1583 }
1584 else
1585 return FUNC;
1586}
1587
ffb4593c
NT
1588/*
1589 * S_sublex_push
1590 * Create a new scope to save the lexing state. The scope will be
1591 * ended in S_sublex_done. Returns a '(', starting the function arguments
1592 * to the uc, lc, etc. found before.
1593 * Sets PL_lex_state to LEX_INTERPCONCAT.
1594 */
1595
76e3520e 1596STATIC I32
cea2e8a9 1597S_sublex_push(pTHX)
55497cff 1598{
27da23d5 1599 dVAR;
f46d017c 1600 ENTER;
55497cff 1601
3280af22
NIS
1602 PL_lex_state = PL_sublex_info.super_state;
1603 SAVEI32(PL_lex_dojoin);
1604 SAVEI32(PL_lex_brackets);
3280af22
NIS
1605 SAVEI32(PL_lex_casemods);
1606 SAVEI32(PL_lex_starts);
1607 SAVEI32(PL_lex_state);
7766f137 1608 SAVEVPTR(PL_lex_inpat);
3280af22 1609 SAVEI32(PL_lex_inwhat);
57843af0 1610 SAVECOPLINE(PL_curcop);
3280af22 1611 SAVEPPTR(PL_bufptr);
8452ff4b 1612 SAVEPPTR(PL_bufend);
3280af22
NIS
1613 SAVEPPTR(PL_oldbufptr);
1614 SAVEPPTR(PL_oldoldbufptr);
207e3d1a
JH
1615 SAVEPPTR(PL_last_lop);
1616 SAVEPPTR(PL_last_uni);
3280af22
NIS
1617 SAVEPPTR(PL_linestart);
1618 SAVESPTR(PL_linestr);
8edd5f42
RGS
1619 SAVEGENERICPV(PL_lex_brackstack);
1620 SAVEGENERICPV(PL_lex_casestack);
3280af22
NIS
1621
1622 PL_linestr = PL_lex_stuff;
a0714e2c 1623 PL_lex_stuff = NULL;
3280af22 1624
9cbb5ea2
GS
1625 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1626 = SvPVX(PL_linestr);
3280af22 1627 PL_bufend += SvCUR(PL_linestr);
bd61b366 1628 PL_last_lop = PL_last_uni = NULL;
3280af22
NIS
1629 SAVEFREESV(PL_linestr);
1630
1631 PL_lex_dojoin = FALSE;
1632 PL_lex_brackets = 0;
a02a5408
JC
1633 Newx(PL_lex_brackstack, 120, char);
1634 Newx(PL_lex_casestack, 12, char);
3280af22
NIS
1635 PL_lex_casemods = 0;
1636 *PL_lex_casestack = '\0';
1637 PL_lex_starts = 0;
1638 PL_lex_state = LEX_INTERPCONCAT;
eb160463 1639 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
3280af22
NIS
1640
1641 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1642 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1643 PL_lex_inpat = PL_sublex_info.sub_op;
79072805 1644 else
5f66b61c 1645 PL_lex_inpat = NULL;
79072805 1646
55497cff 1647 return '(';
79072805
LW
1648}
1649
ffb4593c
NT
1650/*
1651 * S_sublex_done
1652 * Restores lexer state after a S_sublex_push.
1653 */
1654
76e3520e 1655STATIC I32
cea2e8a9 1656S_sublex_done(pTHX)
79072805 1657{
27da23d5 1658 dVAR;
3280af22 1659 if (!PL_lex_starts++) {
396482e1 1660 SV * const sv = newSVpvs("");
9aa983d2
JH
1661 if (SvUTF8(PL_linestr))
1662 SvUTF8_on(sv);
3280af22 1663 PL_expect = XOPERATOR;
9aa983d2 1664 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
79072805
LW
1665 return THING;
1666 }
1667
3280af22
NIS
1668 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1669 PL_lex_state = LEX_INTERPCASEMOD;
cea2e8a9 1670 return yylex();
79072805
LW
1671 }
1672
ffb4593c 1673 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
3280af22
NIS
1674 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1675 PL_linestr = PL_lex_repl;
1676 PL_lex_inpat = 0;
1677 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1678 PL_bufend += SvCUR(PL_linestr);
bd61b366 1679 PL_last_lop = PL_last_uni = NULL;
3280af22
NIS
1680 SAVEFREESV(PL_linestr);
1681 PL_lex_dojoin = FALSE;
1682 PL_lex_brackets = 0;
3280af22
NIS
1683 PL_lex_casemods = 0;
1684 *PL_lex_casestack = '\0';
1685 PL_lex_starts = 0;
25da4f38 1686 if (SvEVALED(PL_lex_repl)) {
3280af22
NIS
1687 PL_lex_state = LEX_INTERPNORMAL;
1688 PL_lex_starts++;
e9fa98b2
HS
1689 /* we don't clear PL_lex_repl here, so that we can check later
1690 whether this is an evalled subst; that means we rely on the
1691 logic to ensure sublex_done() is called again only via the
1692 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
79072805 1693 }
e9fa98b2 1694 else {
3280af22 1695 PL_lex_state = LEX_INTERPCONCAT;
a0714e2c 1696 PL_lex_repl = NULL;
e9fa98b2 1697 }
79072805 1698 return ',';
ffed7fef
LW
1699 }
1700 else {
5db06880
NC
1701#ifdef PERL_MAD
1702 if (PL_madskills) {
cd81e915
NC
1703 if (PL_thiswhite) {
1704 if (!PL_endwhite)
6b29d1f5 1705 PL_endwhite = newSVpvs("");
cd81e915
NC
1706 sv_catsv(PL_endwhite, PL_thiswhite);
1707 PL_thiswhite = 0;
1708 }
1709 if (PL_thistoken)
1710 sv_setpvn(PL_thistoken,"",0);
5db06880 1711 else
cd81e915 1712 PL_realtokenstart = -1;
5db06880
NC
1713 }
1714#endif
f46d017c 1715 LEAVE;
3280af22
NIS
1716 PL_bufend = SvPVX(PL_linestr);
1717 PL_bufend += SvCUR(PL_linestr);
1718 PL_expect = XOPERATOR;
09bef843 1719 PL_sublex_info.sub_inwhat = 0;
79072805 1720 return ')';
ffed7fef
LW
1721 }
1722}
1723
02aa26ce
NT
1724/*
1725 scan_const
1726
1727 Extracts a pattern, double-quoted string, or transliteration. This
1728 is terrifying code.
1729
94def140 1730 It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
3280af22 1731 processing a pattern (PL_lex_inpat is true), a transliteration
94def140 1732 (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
02aa26ce 1733
94def140
TS
1734 Returns a pointer to the character scanned up to. If this is
1735 advanced from the start pointer supplied (i.e. if anything was
9b599b2a
GS
1736 successfully parsed), will leave an OP for the substring scanned
1737 in yylval. Caller must intuit reason for not parsing further
1738 by looking at the next characters herself.
1739
02aa26ce
NT
1740 In patterns:
1741 backslashes:
1742 double-quoted style: \r and \n
1743 regexp special ones: \D \s
94def140
TS
1744 constants: \x31
1745 backrefs: \1
02aa26ce
NT
1746 case and quoting: \U \Q \E
1747 stops on @ and $, but not for $ as tail anchor
1748
1749 In transliterations:
1750 characters are VERY literal, except for - not at the start or end
94def140
TS
1751 of the string, which indicates a range. If the range is in bytes,
1752 scan_const expands the range to the full set of intermediate
1753 characters. If the range is in utf8, the hyphen is replaced with
1754 a certain range mark which will be handled by pmtrans() in op.c.
02aa26ce
NT
1755
1756 In double-quoted strings:
1757 backslashes:
1758 double-quoted style: \r and \n
94def140
TS
1759 constants: \x31
1760 deprecated backrefs: \1 (in substitution replacements)
02aa26ce
NT
1761 case and quoting: \U \Q \E
1762 stops on @ and $
1763
1764 scan_const does *not* construct ops to handle interpolated strings.
1765 It stops processing as soon as it finds an embedded $ or @ variable
1766 and leaves it to the caller to work out what's going on.
1767
94def140
TS
1768 embedded arrays (whether in pattern or not) could be:
1769 @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
1770
1771 $ in double-quoted strings must be the symbol of an embedded scalar.
02aa26ce
NT
1772
1773 $ in pattern could be $foo or could be tail anchor. Assumption:
1774 it's a tail anchor if $ is the last thing in the string, or if it's
94def140 1775 followed by one of "()| \r\n\t"
02aa26ce
NT
1776
1777 \1 (backreferences) are turned into $1
1778
1779 The structure of the code is
1780 while (there's a character to process) {
94def140
TS
1781 handle transliteration ranges
1782 skip regexp comments /(?#comment)/ and codes /(?{code})/
1783 skip #-initiated comments in //x patterns
1784 check for embedded arrays
02aa26ce
NT
1785 check for embedded scalars
1786 if (backslash) {
94def140
TS
1787 leave intact backslashes from leaveit (below)
1788 deprecate \1 in substitution replacements
02aa26ce
NT
1789 handle string-changing backslashes \l \U \Q \E, etc.
1790 switch (what was escaped) {
94def140
TS
1791 handle \- in a transliteration (becomes a literal -)
1792 handle \132 (octal characters)
1793 handle \x15 and \x{1234} (hex characters)
1794 handle \N{name} (named characters)
1795 handle \cV (control characters)
1796 handle printf-style backslashes (\f, \r, \n, etc)
02aa26ce
NT
1797 } (end switch)
1798 } (end if backslash)
1799 } (end while character to read)
4e553d73 1800
02aa26ce
NT
1801*/
1802
76e3520e 1803STATIC char *
cea2e8a9 1804S_scan_const(pTHX_ char *start)
79072805 1805{
97aff369 1806 dVAR;
3280af22 1807 register char *send = PL_bufend; /* end of the constant */
561b68a9 1808 SV *sv = newSV(send - start); /* sv for the constant */
02aa26ce
NT
1809 register char *s = start; /* start of the constant */
1810 register char *d = SvPVX(sv); /* destination for copies */
1811 bool dorange = FALSE; /* are we in a translit range? */
c2e66d9e 1812 bool didrange = FALSE; /* did we just finish a range? */
2b9d42f0
NIS
1813 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1814 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
012bcf8d 1815 UV uv;
4c3a8340
TS
1816#ifdef EBCDIC
1817 UV literal_endpoint = 0;
e294cc5d 1818 bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
4c3a8340 1819#endif
012bcf8d 1820
2b9d42f0
NIS
1821 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1822 /* If we are doing a trans and we know we want UTF8 set expectation */
1823 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1824 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1825 }
1826
1827
79072805 1828 while (s < send || dorange) {
02aa26ce 1829 /* get transliterations out of the way (they're most literal) */
3280af22 1830 if (PL_lex_inwhat == OP_TRANS) {
02aa26ce 1831 /* expand a range A-Z to the full set of characters. AIE! */
79072805 1832 if (dorange) {
1ba5c669
JH
1833 I32 i; /* current expanded character */
1834 I32 min; /* first character in range */
1835 I32 max; /* last character in range */
02aa26ce 1836
e294cc5d
JH
1837#ifdef EBCDIC
1838 UV uvmax = 0;
1839#endif
1840
1841 if (has_utf8
1842#ifdef EBCDIC
1843 && !native_range
1844#endif
1845 ) {
9d4ba2ae 1846 char * const c = (char*)utf8_hop((U8*)d, -1);
8973db79
JH
1847 char *e = d++;
1848 while (e-- > c)
1849 *(e + 1) = *e;
25716404 1850 *c = (char)UTF_TO_NATIVE(0xff);
8973db79
JH
1851 /* mark the range as done, and continue */
1852 dorange = FALSE;
1853 didrange = TRUE;
1854 continue;
1855 }
2b9d42f0 1856
95a20fc0 1857 i = d - SvPVX_const(sv); /* remember current offset */
e294cc5d
JH
1858#ifdef EBCDIC
1859 SvGROW(sv,
1860 SvLEN(sv) + (has_utf8 ?
1861 (512 - UTF_CONTINUATION_MARK +
1862 UNISKIP(0x100))
1863 : 256));
1864 /* How many two-byte within 0..255: 128 in UTF-8,
1865 * 96 in UTF-8-mod. */
1866#else
9cbb5ea2 1867 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
e294cc5d 1868#endif
9cbb5ea2 1869 d = SvPVX(sv) + i; /* refresh d after realloc */
e294cc5d
JH
1870#ifdef EBCDIC
1871 if (has_utf8) {
1872 int j;
1873 for (j = 0; j <= 1; j++) {
1874 char * const c = (char*)utf8_hop((U8*)d, -1);
1875 const UV uv = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
1876 if (j)
1877 min = (U8)uv;
1878 else if (uv < 256)
1879 max = (U8)uv;
1880 else {
1881 max = (U8)0xff; /* only to \xff */
1882 uvmax = uv; /* \x{100} to uvmax */
1883 }
1884 d = c; /* eat endpoint chars */
1885 }
1886 }
1887 else {
1888#endif
1889 d -= 2; /* eat the first char and the - */
1890 min = (U8)*d; /* first char in range */
1891 max = (U8)d[1]; /* last char in range */
1892#ifdef EBCDIC
1893 }
1894#endif
8ada0baa 1895
c2e66d9e 1896 if (min > max) {
01ec43d0 1897 Perl_croak(aTHX_
d1573ac7 1898 "Invalid range \"%c-%c\" in transliteration operator",
1ba5c669 1899 (char)min, (char)max);
c2e66d9e
GS
1900 }
1901
c7f1f016 1902#ifdef EBCDIC
4c3a8340
TS
1903 if (literal_endpoint == 2 &&
1904 ((isLOWER(min) && isLOWER(max)) ||
1905 (isUPPER(min) && isUPPER(max)))) {
8ada0baa
JH
1906 if (isLOWER(min)) {
1907 for (i = min; i <= max; i++)
1908 if (isLOWER(i))
db42d148 1909 *d++ = NATIVE_TO_NEED(has_utf8,i);
8ada0baa
JH
1910 } else {
1911 for (i = min; i <= max; i++)
1912 if (isUPPER(i))
db42d148 1913 *d++ = NATIVE_TO_NEED(has_utf8,i);
8ada0baa
JH
1914 }
1915 }
1916 else
1917#endif
1918 for (i = min; i <= max; i++)
e294cc5d
JH
1919#ifdef EBCDIC
1920 if (has_utf8) {
1921 const U8 ch = (U8)NATIVE_TO_UTF(i);
1922 if (UNI_IS_INVARIANT(ch))
1923 *d++ = (U8)i;
1924 else {
1925 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
1926 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
1927 }
1928 }
1929 else
1930#endif
1931 *d++ = (char)i;
1932
1933#ifdef EBCDIC
1934 if (uvmax) {
1935 d = (char*)uvchr_to_utf8((U8*)d, 0x100);
1936 if (uvmax > 0x101)
1937 *d++ = (char)UTF_TO_NATIVE(0xff);
1938 if (uvmax > 0x100)
1939 d = (char*)uvchr_to_utf8((U8*)d, uvmax);
1940 }
1941#endif
02aa26ce
NT
1942
1943 /* mark the range as done, and continue */
79072805 1944 dorange = FALSE;
01ec43d0 1945 didrange = TRUE;
4c3a8340
TS
1946#ifdef EBCDIC
1947 literal_endpoint = 0;
1948#endif
79072805 1949 continue;
4e553d73 1950 }
02aa26ce
NT
1951
1952 /* range begins (ignore - as first or last char) */
79072805 1953 else if (*s == '-' && s+1 < send && s != start) {
4e553d73 1954 if (didrange) {
1fafa243 1955 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
01ec43d0 1956 }
e294cc5d
JH
1957 if (has_utf8
1958#ifdef EBCDIC
1959 && !native_range
1960#endif
1961 ) {
25716404 1962 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
a0ed51b3
LW
1963 s++;
1964 continue;
1965 }
79072805
LW
1966 dorange = TRUE;
1967 s++;
01ec43d0
GS
1968 }
1969 else {
1970 didrange = FALSE;
4c3a8340
TS
1971#ifdef EBCDIC
1972 literal_endpoint = 0;
e294cc5d 1973 native_range = TRUE;
4c3a8340 1974#endif
01ec43d0 1975 }
79072805 1976 }
02aa26ce
NT
1977
1978 /* if we get here, we're not doing a transliteration */
1979
0f5d15d6
IZ
1980 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1981 except for the last char, which will be done separately. */
3280af22 1982 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
cc6b7395 1983 if (s[2] == '#') {
e994fd66 1984 while (s+1 < send && *s != ')')
db42d148 1985 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
155aba94
GS
1986 }
1987 else if (s[2] == '{' /* This should match regcomp.c */
1988 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1989 {
cc6b7395 1990 I32 count = 1;
0f5d15d6 1991 char *regparse = s + (s[2] == '{' ? 3 : 4);
cc6b7395
IZ
1992 char c;
1993
d9f97599
GS
1994 while (count && (c = *regparse)) {
1995 if (c == '\\' && regparse[1])
1996 regparse++;
4e553d73 1997 else if (c == '{')
cc6b7395 1998 count++;
4e553d73 1999 else if (c == '}')
cc6b7395 2000 count--;
d9f97599 2001 regparse++;
cc6b7395 2002 }
e994fd66 2003 if (*regparse != ')')
5bdf89e7 2004 regparse--; /* Leave one char for continuation. */
0f5d15d6 2005 while (s < regparse)
db42d148 2006 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
cc6b7395 2007 }
748a9306 2008 }
02aa26ce
NT
2009
2010 /* likewise skip #-initiated comments in //x patterns */
3280af22
NIS
2011 else if (*s == '#' && PL_lex_inpat &&
2012 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
748a9306 2013 while (s+1 < send && *s != '\n')
db42d148 2014 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
748a9306 2015 }
02aa26ce 2016
5d1d4326 2017 /* check for embedded arrays
da6eedaa 2018 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
5d1d4326 2019 */
1749ea0d
TS
2020 else if (*s == '@' && s[1]) {
2021 if (isALNUM_lazy_if(s+1,UTF))
2022 break;
2023 if (strchr(":'{$", s[1]))
2024 break;
2025 if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
2026 break; /* in regexp, neither @+ nor @- are interpolated */
2027 }
02aa26ce
NT
2028
2029 /* check for embedded scalars. only stop if we're sure it's a
2030 variable.
2031 */
79072805 2032 else if (*s == '$') {
3280af22 2033 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
79072805 2034 break;
6002328a 2035 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
79072805
LW
2036 break; /* in regexp, $ might be tail anchor */
2037 }
02aa26ce 2038
2b9d42f0
NIS
2039 /* End of else if chain - OP_TRANS rejoin rest */
2040
02aa26ce 2041 /* backslashes */
79072805
LW
2042 if (*s == '\\' && s+1 < send) {
2043 s++;
02aa26ce 2044
02aa26ce 2045 /* deprecate \1 in strings and substitution replacements */
3280af22 2046 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
a0d0e21e 2047 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
79072805 2048 {
599cee73 2049 if (ckWARN(WARN_SYNTAX))
9014280d 2050 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
79072805
LW
2051 *--s = '$';
2052 break;
2053 }
02aa26ce
NT
2054
2055 /* string-change backslash escapes */
3280af22 2056 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
79072805
LW
2057 --s;
2058 break;
2059 }
cc74c5bd
TS
2060 /* skip any other backslash escapes in a pattern */
2061 else if (PL_lex_inpat) {
2062 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2063 goto default_action;
2064 }
02aa26ce
NT
2065
2066 /* if we get here, it's either a quoted -, or a digit */
79072805 2067 switch (*s) {
02aa26ce
NT
2068
2069 /* quoted - in transliterations */
79072805 2070 case '-':
3280af22 2071 if (PL_lex_inwhat == OP_TRANS) {
79072805
LW
2072 *d++ = *s++;
2073 continue;
2074 }
2075 /* FALL THROUGH */
2076 default:
11b8faa4 2077 {
86f97054 2078 if ((isALPHA(*s) || isDIGIT(*s)) &&
041457d9 2079 ckWARN(WARN_MISC))
9014280d 2080 Perl_warner(aTHX_ packWARN(WARN_MISC),
e294cc5d
JH
2081 "Unrecognized escape \\%c passed through",
2082 *s);
11b8faa4 2083 /* default action is to copy the quoted character */
f9a63242 2084 goto default_action;
11b8faa4 2085 }
02aa26ce
NT
2086
2087 /* \132 indicates an octal constant */
79072805
LW
2088 case '0': case '1': case '2': case '3':
2089 case '4': case '5': case '6': case '7':
ba210ebe 2090 {
53305cf1
NC
2091 I32 flags = 0;
2092 STRLEN len = 3;
2093 uv = grok_oct(s, &len, &flags, NULL);
ba210ebe
JH
2094 s += len;
2095 }
012bcf8d 2096 goto NUM_ESCAPE_INSERT;
02aa26ce
NT
2097
2098 /* \x24 indicates a hex constant */
79072805 2099 case 'x':
a0ed51b3
LW
2100 ++s;
2101 if (*s == '{') {
9d4ba2ae 2102 char* const e = strchr(s, '}');
a4c04bdc
NC
2103 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2104 PERL_SCAN_DISALLOW_PREFIX;
53305cf1 2105 STRLEN len;
355860ce 2106
53305cf1 2107 ++s;
adaeee49 2108 if (!e) {
a0ed51b3 2109 yyerror("Missing right brace on \\x{}");
355860ce 2110 continue;
ba210ebe 2111 }
53305cf1
NC
2112 len = e - s;
2113 uv = grok_hex(s, &len, &flags, NULL);
ba210ebe 2114 s = e + 1;
a0ed51b3
LW
2115 }
2116 else {
ba210ebe 2117 {
53305cf1 2118 STRLEN len = 2;
a4c04bdc 2119 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
53305cf1 2120 uv = grok_hex(s, &len, &flags, NULL);
ba210ebe
JH
2121 s += len;
2122 }
012bcf8d
GS
2123 }
2124
2125 NUM_ESCAPE_INSERT:
2126 /* Insert oct or hex escaped character.
301d3d20 2127 * There will always enough room in sv since such
db42d148 2128 * escapes will be longer than any UTF-8 sequence
301d3d20 2129 * they can end up as. */
ba7cea30 2130
c7f1f016
NIS
2131 /* We need to map to chars to ASCII before doing the tests
2132 to cover EBCDIC
2133 */
c4d5f83a 2134 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
9aa983d2 2135 if (!has_utf8 && uv > 255) {
301d3d20
JH
2136 /* Might need to recode whatever we have
2137 * accumulated so far if it contains any
2138 * hibit chars.
2139 *
2140 * (Can't we keep track of that and avoid
2141 * this rescan? --jhi)
012bcf8d 2142 */
c7f1f016 2143 int hicount = 0;
63cd0674
NIS
2144 U8 *c;
2145 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
c4d5f83a 2146 if (!NATIVE_IS_INVARIANT(*c)) {
012bcf8d 2147 hicount++;
db42d148 2148 }
012bcf8d 2149 }
63cd0674 2150 if (hicount) {
9d4ba2ae 2151 const STRLEN offset = d - SvPVX_const(sv);
db42d148
NIS
2152 U8 *src, *dst;
2153 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
2154 src = (U8 *)d - 1;
2155 dst = src+hicount;
2156 d += hicount;
cfd0369c 2157 while (src >= (const U8 *)SvPVX_const(sv)) {
c4d5f83a 2158 if (!NATIVE_IS_INVARIANT(*src)) {
9d4ba2ae 2159 const U8 ch = NATIVE_TO_ASCII(*src);
eb160463
GS
2160 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
2161 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
012bcf8d
GS
2162 }
2163 else {
63cd0674 2164 *dst-- = *src;
012bcf8d 2165 }
c7f1f016 2166 src--;
012bcf8d
GS
2167 }
2168 }
2169 }
2170
9aa983d2 2171 if (has_utf8 || uv > 255) {
9041c2e3 2172 d = (char*)uvchr_to_utf8((U8*)d, uv);
4e553d73 2173 has_utf8 = TRUE;
f9a63242
JH
2174 if (PL_lex_inwhat == OP_TRANS &&
2175 PL_sublex_info.sub_op) {
2176 PL_sublex_info.sub_op->op_private |=
2177 (PL_lex_repl ? OPpTRANS_FROM_UTF
2178 : OPpTRANS_TO_UTF);
f9a63242 2179 }
e294cc5d
JH
2180#ifdef EBCDIC
2181 if (uv > 255 && !dorange)
2182 native_range = FALSE;
2183#endif
012bcf8d 2184 }
a0ed51b3 2185 else {
012bcf8d 2186 *d++ = (char)uv;
a0ed51b3 2187 }
012bcf8d
GS
2188 }
2189 else {
c4d5f83a 2190 *d++ = (char) uv;
a0ed51b3 2191 }
79072805 2192 continue;
02aa26ce 2193
b239daa5 2194 /* \N{LATIN SMALL LETTER A} is a named character */
4a2d328f 2195 case 'N':
55eda711 2196 ++s;
423cee85
JH
2197 if (*s == '{') {
2198 char* e = strchr(s, '}');
155aba94 2199 SV *res;
423cee85 2200 STRLEN len;
cfd0369c 2201 const char *str;
fc8cd66c 2202 SV *type;
4e553d73 2203
423cee85 2204 if (!e) {
5777a3f7 2205 yyerror("Missing right brace on \\N{}");
423cee85
JH
2206 e = s - 1;
2207 goto cont_scan;
2208 }
dbc0d4f2
JH
2209 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2210 /* \N{U+...} */
2211 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2212 PERL_SCAN_DISALLOW_PREFIX;
2213 s += 3;
2214 len = e - s;
2215 uv = grok_hex(s, &len, &flags, NULL);
b57a0404
JH
2216 if ( e > s && len != (STRLEN)(e - s) ) {
2217 uv = 0xFFFD;
fc8cd66c 2218 }
dbc0d4f2
JH
2219 s = e + 1;
2220 goto NUM_ESCAPE_INSERT;
2221 }
55eda711 2222 res = newSVpvn(s + 1, e - s - 1);
fc8cd66c 2223 type = newSVpvn(s - 2,e - s + 3);
bd61b366 2224 res = new_constant( NULL, 0, "charnames",
fc8cd66c
YO
2225 res, NULL, SvPVX(type) );
2226 SvREFCNT_dec(type);
f9a63242
JH
2227 if (has_utf8)
2228 sv_utf8_upgrade(res);
cfd0369c 2229 str = SvPV_const(res,len);
1c47067b
JH
2230#ifdef EBCDIC_NEVER_MIND
2231 /* charnames uses pack U and that has been
2232 * recently changed to do the below uni->native
2233 * mapping, so this would be redundant (and wrong,
2234 * the code point would be doubly converted).
2235 * But leave this in just in case the pack U change
2236 * gets revoked, but the semantics is still
2237 * desireable for charnames. --jhi */
cddc7ef4 2238 {
cfd0369c 2239 UV uv = utf8_to_uvchr((const U8*)str, 0);
cddc7ef4
JH
2240
2241 if (uv < 0x100) {
89ebb4a3 2242 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
cddc7ef4
JH
2243
2244 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2245 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
cfd0369c 2246 str = SvPV_const(res, len);
cddc7ef4
JH
2247 }
2248 }
2249#endif
89491803 2250 if (!has_utf8 && SvUTF8(res)) {
9d4ba2ae 2251 const char * const ostart = SvPVX_const(sv);
f08d6ad9
GS
2252 SvCUR_set(sv, d - ostart);
2253 SvPOK_on(sv);
e4f3eed8 2254 *d = '\0';
f08d6ad9 2255 sv_utf8_upgrade(sv);
d2f449dd 2256 /* this just broke our allocation above... */
eb160463 2257 SvGROW(sv, (STRLEN)(send - start));
f08d6ad9 2258 d = SvPVX(sv) + SvCUR(sv);
89491803 2259 has_utf8 = TRUE;
f08d6ad9 2260 }
eb160463 2261 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
9d4ba2ae 2262 const char * const odest = SvPVX_const(sv);
423cee85 2263
8973db79 2264 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
423cee85
JH
2265 d = SvPVX(sv) + (d - odest);
2266 }
e294cc5d
JH
2267#ifdef EBCDIC
2268 if (!dorange)
2269 native_range = FALSE; /* \N{} is guessed to be Unicode */
2270#endif
423cee85
JH
2271 Copy(str, d, len, char);
2272 d += len;
2273 SvREFCNT_dec(res);
2274 cont_scan:
2275 s = e + 1;
2276 }
2277 else
5777a3f7 2278 yyerror("Missing braces on \\N{}");
423cee85
JH
2279 continue;
2280
02aa26ce 2281 /* \c is a control character */
79072805
LW
2282 case 'c':
2283 s++;
961ce445 2284 if (s < send) {
ba210ebe 2285 U8 c = *s++;
c7f1f016
NIS
2286#ifdef EBCDIC
2287 if (isLOWER(c))
2288 c = toUPPER(c);
2289#endif
db42d148 2290 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
ba210ebe 2291 }
961ce445
RGS
2292 else {
2293 yyerror("Missing control char name in \\c");
2294 }
79072805 2295 continue;
02aa26ce
NT
2296
2297 /* printf-style backslashes, formfeeds, newlines, etc */
79072805 2298 case 'b':
db42d148 2299 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
79072805
LW
2300 break;
2301 case 'n':
db42d148 2302 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
79072805
LW
2303 break;
2304 case 'r':
db42d148 2305 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
79072805
LW
2306 break;
2307 case 'f':
db42d148 2308 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
79072805
LW
2309 break;
2310 case 't':
db42d148 2311 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
79072805 2312 break;
34a3fe2a 2313 case 'e':
db42d148 2314 *d++ = ASCII_TO_NEED(has_utf8,'\033');
34a3fe2a
PP
2315 break;
2316 case 'a':
db42d148 2317 *d++ = ASCII_TO_NEED(has_utf8,'\007');
79072805 2318 break;
02aa26ce
NT
2319 } /* end switch */
2320
79072805
LW
2321 s++;
2322 continue;
02aa26ce 2323 } /* end if (backslash) */
4c3a8340
TS
2324#ifdef EBCDIC
2325 else
2326 literal_endpoint++;
2327#endif
02aa26ce 2328
f9a63242 2329 default_action:
2b9d42f0
NIS
2330 /* If we started with encoded form, or already know we want it
2331 and then encode the next character */
2332 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
2333 STRLEN len = 1;
5f66b61c
AL
2334 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2335 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2b9d42f0
NIS
2336 s += len;
2337 if (need > len) {
2338 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
9d4ba2ae 2339 const STRLEN off = d - SvPVX_const(sv);
2b9d42f0
NIS
2340 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
2341 }
5f66b61c 2342 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2b9d42f0 2343 has_utf8 = TRUE;
e294cc5d
JH
2344#ifdef EBCDIC
2345 if (uv > 255 && !dorange)
2346 native_range = FALSE;
2347#endif
2b9d42f0
NIS
2348 }
2349 else {
2350 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2351 }
02aa26ce
NT
2352 } /* while loop to process each character */
2353
2354 /* terminate the string and set up the sv */
79072805 2355 *d = '\0';
95a20fc0 2356 SvCUR_set(sv, d - SvPVX_const(sv));
2b9d42f0 2357 if (SvCUR(sv) >= SvLEN(sv))
d0063567 2358 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2b9d42f0 2359
79072805 2360 SvPOK_on(sv);
9f4817db 2361 if (PL_encoding && !has_utf8) {
d0063567
DK
2362 sv_recode_to_utf8(sv, PL_encoding);
2363 if (SvUTF8(sv))
2364 has_utf8 = TRUE;
9f4817db 2365 }
2b9d42f0 2366 if (has_utf8) {
7e2040f0 2367 SvUTF8_on(sv);
2b9d42f0 2368 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
d0063567 2369 PL_sublex_info.sub_op->op_private |=
2b9d42f0
NIS
2370 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2371 }
2372 }
79072805 2373
02aa26ce 2374 /* shrink the sv if we allocated more than we used */
79072805 2375 if (SvCUR(sv) + 5 < SvLEN(sv)) {
1da4ca5f 2376 SvPV_shrink_to_cur(sv);
79072805 2377 }
02aa26ce 2378
9b599b2a 2379 /* return the substring (via yylval) only if we parsed anything */
3280af22
NIS
2380 if (s > PL_bufptr) {
2381 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
10edeb5d
JH
2382 sv = new_constant(start, s - start,
2383 (const char *)(PL_lex_inpat ? "qr" : "q"),
a0714e2c 2384 sv, NULL,
10edeb5d
JH
2385 (const char *)
2386 (( PL_lex_inwhat == OP_TRANS
2387 ? "tr"
2388 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
2389 ? "s"
2390 : "qq"))));
79072805 2391 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
b3ac6de7 2392 } else
8990e307 2393 SvREFCNT_dec(sv);
79072805
LW
2394 return s;
2395}
2396
ffb4593c
NT
2397/* S_intuit_more
2398 * Returns TRUE if there's more to the expression (e.g., a subscript),
2399 * FALSE otherwise.
ffb4593c
NT
2400 *
2401 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2402 *
2403 * ->[ and ->{ return TRUE
2404 * { and [ outside a pattern are always subscripts, so return TRUE
2405 * if we're outside a pattern and it's not { or [, then return FALSE
2406 * if we're in a pattern and the first char is a {
2407 * {4,5} (any digits around the comma) returns FALSE
2408 * if we're in a pattern and the first char is a [
2409 * [] returns FALSE
2410 * [SOMETHING] has a funky algorithm to decide whether it's a
2411 * character class or not. It has to deal with things like
2412 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2413 * anything else returns TRUE
2414 */
2415
9cbb5ea2
GS
2416/* This is the one truly awful dwimmer necessary to conflate C and sed. */
2417
76e3520e 2418STATIC int
cea2e8a9 2419S_intuit_more(pTHX_ register char *s)
79072805 2420{
97aff369 2421 dVAR;
3280af22 2422 if (PL_lex_brackets)
79072805
LW
2423 return TRUE;
2424 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2425 return TRUE;
2426 if (*s != '{' && *s != '[')
2427 return FALSE;
3280af22 2428 if (!PL_lex_inpat)
79072805
LW
2429 return TRUE;
2430
2431 /* In a pattern, so maybe we have {n,m}. */
2432 if (*s == '{') {
2433 s++;
2434 if (!isDIGIT(*s))
2435 return TRUE;
2436 while (isDIGIT(*s))
2437 s++;
2438 if (*s == ',')
2439 s++;
2440 while (isDIGIT(*s))
2441 s++;
2442 if (*s == '}')
2443 return FALSE;
2444 return TRUE;
2445
2446 }
2447
2448 /* On the other hand, maybe we have a character class */
2449
2450 s++;
2451 if (*s == ']' || *s == '^')
2452 return FALSE;
2453 else {
ffb4593c 2454 /* this is terrifying, and it works */
79072805
LW
2455 int weight = 2; /* let's weigh the evidence */
2456 char seen[256];
f27ffc4a 2457 unsigned char un_char = 255, last_un_char;
9d4ba2ae 2458 const char * const send = strchr(s,']');
3280af22 2459 char tmpbuf[sizeof PL_tokenbuf * 4];
79072805
LW
2460
2461 if (!send) /* has to be an expression */
2462 return TRUE;
2463
2464 Zero(seen,256,char);
2465 if (*s == '$')
2466 weight -= 3;
2467 else if (isDIGIT(*s)) {
2468 if (s[1] != ']') {
2469 if (isDIGIT(s[1]) && s[2] == ']')
2470 weight -= 10;
2471 }
2472 else
2473 weight -= 100;
2474 }
2475 for (; s < send; s++) {
2476 last_un_char = un_char;
2477 un_char = (unsigned char)*s;
2478 switch (*s) {
2479 case '@':
2480 case '&':
2481 case '$':
2482 weight -= seen[un_char] * 10;
7e2040f0 2483 if (isALNUM_lazy_if(s+1,UTF)) {
90e5519e 2484 int len;
8903cb82 2485 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
90e5519e
NC
2486 len = (int)strlen(tmpbuf);
2487 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
79072805
LW
2488 weight -= 100;
2489 else
2490 weight -= 10;
2491 }
2492 else if (*s == '$' && s[1] &&
93a17b20
LW
2493 strchr("[#!%*<>()-=",s[1])) {
2494 if (/*{*/ strchr("])} =",s[2]))
79072805
LW
2495 weight -= 10;
2496 else
2497 weight -= 1;
2498 }
2499 break;
2500 case '\\':
2501 un_char = 254;
2502 if (s[1]) {
93a17b20 2503 if (strchr("wds]",s[1]))
79072805 2504 weight += 100;
10edeb5d 2505 else if (seen[(U8)'\''] || seen[(U8)'"'])
79072805 2506 weight += 1;
93a17b20 2507 else if (strchr("rnftbxcav",s[1]))
79072805
LW
2508 weight += 40;
2509 else if (isDIGIT(s[1])) {
2510 weight += 40;
2511 while (s[1] && isDIGIT(s[1]))
2512 s++;
2513 }
2514 }
2515 else
2516 weight += 100;
2517 break;
2518 case '-':
2519 if (s[1] == '\\')
2520 weight += 50;
93a17b20 2521 if (strchr("aA01! ",last_un_char))
79072805 2522 weight += 30;
93a17b20 2523 if (strchr("zZ79~",s[1]))
79072805 2524 weight += 30;
f27ffc4a
GS
2525 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2526 weight -= 5; /* cope with negative subscript */
79072805
LW
2527 break;
2528 default:
3792a11b
NC
2529 if (!isALNUM(last_un_char)
2530 && !(last_un_char == '$' || last_un_char == '@'
2531 || last_un_char == '&')
2532 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
79072805
LW
2533 char *d = tmpbuf;
2534 while (isALPHA(*s))
2535 *d++ = *s++;
2536 *d = '\0';
5458a98a 2537 if (keyword(tmpbuf, d - tmpbuf, 0))
79072805
LW
2538 weight -= 150;
2539 }
2540 if (un_char == last_un_char + 1)
2541 weight += 5;
2542 weight -= seen[un_char];
2543 break;
2544 }
2545 seen[un_char]++;
2546 }
2547 if (weight >= 0) /* probably a character class */
2548 return FALSE;
2549 }
2550
2551 return TRUE;
2552}
ffed7fef 2553
ffb4593c
NT
2554/*
2555 * S_intuit_method
2556 *
2557 * Does all the checking to disambiguate
2558 * foo bar
2559 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2560 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2561 *
2562 * First argument is the stuff after the first token, e.g. "bar".
2563 *
2564 * Not a method if bar is a filehandle.
2565 * Not a method if foo is a subroutine prototyped to take a filehandle.
2566 * Not a method if it's really "Foo $bar"
2567 * Method if it's "foo $bar"
2568 * Not a method if it's really "print foo $bar"
2569 * Method if it's really "foo package::" (interpreted as package->foo)
8f8cf39c 2570 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
3cb0bbe5 2571 * Not a method if bar is a filehandle or package, but is quoted with
ffb4593c
NT
2572 * =>
2573 */
2574
76e3520e 2575STATIC int
62d55b22 2576S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
a0d0e21e 2577{
97aff369 2578 dVAR;
a0d0e21e 2579 char *s = start + (*start == '$');
3280af22 2580 char tmpbuf[sizeof PL_tokenbuf];
a0d0e21e
LW
2581 STRLEN len;
2582 GV* indirgv;
5db06880
NC
2583#ifdef PERL_MAD
2584 int soff;
2585#endif
a0d0e21e
LW
2586
2587 if (gv) {
62d55b22 2588 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
a0d0e21e 2589 return 0;
62d55b22
NC
2590 if (cv) {
2591 if (SvPOK(cv)) {
2592 const char *proto = SvPVX_const(cv);
2593 if (proto) {
2594 if (*proto == ';')
2595 proto++;
2596 if (*proto == '*')
2597 return 0;
2598 }
b6c543e3
IZ
2599 }
2600 } else
c35e046a 2601 gv = NULL;
a0d0e21e 2602 }
8903cb82 2603 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
ffb4593c
NT
2604 /* start is the beginning of the possible filehandle/object,
2605 * and s is the end of it
2606 * tmpbuf is a copy of it
2607 */
2608
a0d0e21e 2609 if (*start == '$') {
3280af22 2610 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
a0d0e21e 2611 return 0;
5db06880
NC
2612#ifdef PERL_MAD
2613 len = start - SvPVX(PL_linestr);
2614#endif
29595ff2 2615 s = PEEKSPACE(s);
f0092767 2616#ifdef PERL_MAD
5db06880
NC
2617 start = SvPVX(PL_linestr) + len;
2618#endif
3280af22
NIS
2619 PL_bufptr = start;
2620 PL_expect = XREF;
a0d0e21e
LW
2621 return *s == '(' ? FUNCMETH : METHOD;
2622 }
5458a98a 2623 if (!keyword(tmpbuf, len, 0)) {
c3e0f903
GS
2624 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2625 len -= 2;
2626 tmpbuf[len] = '\0';
5db06880
NC
2627#ifdef PERL_MAD
2628 soff = s - SvPVX(PL_linestr);
2629#endif
c3e0f903
GS
2630 goto bare_package;
2631 }
90e5519e 2632 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
8ebc5c01 2633 if (indirgv && GvCVu(indirgv))
a0d0e21e
LW
2634 return 0;
2635 /* filehandle or package name makes it a method */
89bfa8cd 2636 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
5db06880
NC
2637#ifdef PERL_MAD
2638 soff = s - SvPVX(PL_linestr);
2639#endif
29595ff2 2640 s = PEEKSPACE(s);
3280af22 2641 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
55497cff 2642 return 0; /* no assumptions -- "=>" quotes bearword */
c3e0f903 2643 bare_package:
cd81e915 2644 start_force(PL_curforce);
9ded7720 2645 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
79cb57f6 2646 newSVpvn(tmpbuf,len));
9ded7720 2647 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
5db06880
NC
2648 if (PL_madskills)
2649 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
3280af22 2650 PL_expect = XTERM;
a0d0e21e 2651 force_next(WORD);
3280af22 2652 PL_bufptr = s;
5db06880
NC
2653#ifdef PERL_MAD
2654 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2655#endif
a0d0e21e
LW
2656 return *s == '(' ? FUNCMETH : METHOD;
2657 }
2658 }
2659 return 0;
2660}
2661
ffb4593c
NT
2662/*
2663 * S_incl_perldb
2664 * Return a string of Perl code to load the debugger. If PERL5DB
2665 * is set, it will return the contents of that, otherwise a
2666 * compile-time require of perl5db.pl.
2667 */
2668
bfed75c6 2669STATIC const char*
cea2e8a9 2670S_incl_perldb(pTHX)
a0d0e21e 2671{
97aff369 2672 dVAR;
3280af22 2673 if (PL_perldb) {
9d4ba2ae 2674 const char * const pdb = PerlEnv_getenv("PERL5DB");
a0d0e21e
LW
2675
2676 if (pdb)
2677 return pdb;
93189314 2678 SETERRNO(0,SS_NORMAL);
a0d0e21e
LW
2679 return "BEGIN { require 'perl5db.pl' }";
2680 }
2681 return "";
2682}
2683
2684
16d20bd9 2685/* Encoded script support. filter_add() effectively inserts a
4e553d73 2686 * 'pre-processing' function into the current source input stream.
16d20bd9
AD
2687 * Note that the filter function only applies to the current source file
2688 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2689 *
2690 * The datasv parameter (which may be NULL) can be used to pass
2691 * private data to this instance of the filter. The filter function
2692 * can recover the SV using the FILTER_DATA macro and use it to
2693 * store private buffers and state information.
2694 *
2695 * The supplied datasv parameter is upgraded to a PVIO type
4755096e 2696 * and the IoDIRP/IoANY field is used to store the function pointer,
e0c19803 2697 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
16d20bd9
AD
2698 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2699 * private use must be set using malloc'd pointers.
2700 */
16d20bd9
AD
2701
2702SV *
864dbfa3 2703Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
16d20bd9 2704{
97aff369 2705 dVAR;
f4c556ac 2706 if (!funcp)
a0714e2c 2707 return NULL;
f4c556ac 2708
3280af22
NIS
2709 if (!PL_rsfp_filters)
2710 PL_rsfp_filters = newAV();
16d20bd9 2711 if (!datasv)
561b68a9 2712 datasv = newSV(0);
862a34c6 2713 SvUPGRADE(datasv, SVt_PVIO);
8141890a 2714 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
e0c19803 2715 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
f4c556ac 2716 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
55662e27
JH
2717 FPTR2DPTR(void *, IoANY(datasv)),
2718 SvPV_nolen(datasv)));
3280af22
NIS
2719 av_unshift(PL_rsfp_filters, 1);
2720 av_store(PL_rsfp_filters, 0, datasv) ;
16d20bd9
AD
2721 return(datasv);
2722}
4e553d73 2723
16d20bd9
AD
2724
2725/* Delete most recently added instance of this filter function. */
a0d0e21e 2726void
864dbfa3 2727Perl_filter_del(pTHX_ filter_t funcp)
16d20bd9 2728{
97aff369 2729 dVAR;
e0c19803 2730 SV *datasv;
24801a4b 2731
33073adb 2732#ifdef DEBUGGING
55662e27
JH
2733 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2734 FPTR2DPTR(void*, funcp)));
33073adb 2735#endif
3280af22 2736 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
16d20bd9
AD
2737 return;
2738 /* if filter is on top of stack (usual case) just pop it off */
e0c19803 2739 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
8141890a 2740 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
e0c19803 2741 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
4755096e 2742 IoANY(datasv) = (void *)NULL;
3280af22 2743 sv_free(av_pop(PL_rsfp_filters));
e50aee73 2744
16d20bd9
AD
2745 return;
2746 }
2747 /* we need to search for the correct entry and clear it */
cea2e8a9 2748 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
16d20bd9
AD
2749}
2750
2751
1de9afcd
RGS
2752/* Invoke the idxth filter function for the current rsfp. */
2753/* maxlen 0 = read one text line */
16d20bd9 2754I32
864dbfa3 2755Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
a0d0e21e 2756{
97aff369 2757 dVAR;
16d20bd9
AD
2758 filter_t funcp;
2759 SV *datasv = NULL;
f482118e
NC
2760 /* This API is bad. It should have been using unsigned int for maxlen.
2761 Not sure if we want to change the API, but if not we should sanity
2762 check the value here. */
39cd7a59
NC
2763 const unsigned int correct_length
2764 = maxlen < 0 ?
2765#ifdef PERL_MICRO
2766 0x7FFFFFFF
2767#else
2768 INT_MAX
2769#endif
2770 : maxlen;
e50aee73 2771
3280af22 2772 if (!PL_rsfp_filters)
16d20bd9 2773 return -1;
1de9afcd 2774 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
16d20bd9
AD
2775 /* Provide a default input filter to make life easy. */
2776 /* Note that we append to the line. This is handy. */
f4c556ac
GS
2777 DEBUG_P(PerlIO_printf(Perl_debug_log,
2778 "filter_read %d: from rsfp\n", idx));
f482118e 2779 if (correct_length) {
16d20bd9
AD
2780 /* Want a block */
2781 int len ;
f54cb97a 2782 const int old_len = SvCUR(buf_sv);
16d20bd9
AD
2783
2784 /* ensure buf_sv is large enough */
f482118e
NC
2785 SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2786 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2787 correct_length)) <= 0) {
3280af22 2788 if (PerlIO_error(PL_rsfp))
37120919
AD
2789 return -1; /* error */
2790 else
2791 return 0 ; /* end of file */
2792 }
16d20bd9
AD
2793 SvCUR_set(buf_sv, old_len + len) ;
2794 } else {
2795 /* Want a line */
3280af22
NIS
2796 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2797 if (PerlIO_error(PL_rsfp))
37120919
AD
2798 return -1; /* error */
2799 else
2800 return 0 ; /* end of file */
2801 }
16d20bd9
AD
2802 }
2803 return SvCUR(buf_sv);
2804 }
2805 /* Skip this filter slot if filter has been deleted */
1de9afcd 2806 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
f4c556ac
GS
2807 DEBUG_P(PerlIO_printf(Perl_debug_log,
2808 "filter_read %d: skipped (filter deleted)\n",
2809 idx));
f482118e 2810 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
16d20bd9
AD
2811 }
2812 /* Get function pointer hidden within datasv */
8141890a 2813 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
f4c556ac
GS
2814 DEBUG_P(PerlIO_printf(Perl_debug_log,
2815 "filter_read %d: via function %p (%s)\n",
ca0270c4 2816 idx, (void*)datasv, SvPV_nolen_const(datasv)));
16d20bd9
AD
2817 /* Call function. The function is expected to */
2818 /* call "FILTER_READ(idx+1, buf_sv)" first. */
37120919 2819 /* Return: <0:error, =0:eof, >0:not eof */
f482118e 2820 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
16d20bd9
AD
2821}
2822
76e3520e 2823STATIC char *
cea2e8a9 2824S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
16d20bd9 2825{
97aff369 2826 dVAR;
c39cd008 2827#ifdef PERL_CR_FILTER
3280af22 2828 if (!PL_rsfp_filters) {
c39cd008 2829 filter_add(S_cr_textfilter,NULL);
a868473f
NIS
2830 }
2831#endif
3280af22 2832 if (PL_rsfp_filters) {
55497cff 2833 if (!append)
2834 SvCUR_set(sv, 0); /* start with empty line */
16d20bd9
AD
2835 if (FILTER_READ(0, sv, 0) > 0)
2836 return ( SvPVX(sv) ) ;
2837 else
bd61b366 2838 return NULL ;
16d20bd9 2839 }
9d116dd7 2840 else
fd049845 2841 return (sv_gets(sv, fp, append));
a0d0e21e
LW
2842}
2843
01ec43d0 2844STATIC HV *
7fc63493 2845S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
def3634b 2846{
97aff369 2847 dVAR;
def3634b
GS
2848 GV *gv;
2849
01ec43d0 2850 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
def3634b
GS
2851 return PL_curstash;
2852
2853 if (len > 2 &&
2854 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
90e5519e 2855 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
01ec43d0
GS
2856 {
2857 return GvHV(gv); /* Foo:: */
def3634b
GS
2858 }
2859
2860 /* use constant CLASS => 'MyClass' */
c35e046a
AL
2861 gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
2862 if (gv && GvCV(gv)) {
2863 SV * const sv = cv_const_sv(GvCV(gv));
2864 if (sv)
83003860 2865 pkgname = SvPV_nolen_const(sv);
def3634b
GS
2866 }
2867
2868 return gv_stashpv(pkgname, FALSE);
2869}
a0d0e21e 2870
e3f73d4e
RGS
2871/*
2872 * S_readpipe_override
2873 * Check whether readpipe() is overriden, and generates the appropriate
2874 * optree, provided sublex_start() is called afterwards.
2875 */
2876STATIC void
1d51329b 2877S_readpipe_override(pTHX)
e3f73d4e
RGS
2878{
2879 GV **gvp;
2880 GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
2881 yylval.ival = OP_BACKTICK;
2882 if ((gv_readpipe
2883 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
2884 ||
2885 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
2886 && (gv_readpipe = *gvp) != (GV*)&PL_sv_undef
2887 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
2888 {
2889 PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
2890 append_elem(OP_LIST,
2891 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
2892 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
2893 }
2894 else {
2895 set_csh();
2896 }
2897}
2898
5db06880
NC
2899#ifdef PERL_MAD
2900 /*
2901 * Perl_madlex
2902 * The intent of this yylex wrapper is to minimize the changes to the
2903 * tokener when we aren't interested in collecting madprops. It remains
2904 * to be seen how successful this strategy will be...
2905 */
2906
2907int
2908Perl_madlex(pTHX)
2909{
2910 int optype;
2911 char *s = PL_bufptr;
2912
cd81e915
NC
2913 /* make sure PL_thiswhite is initialized */
2914 PL_thiswhite = 0;
2915 PL_thismad = 0;
5db06880 2916
cd81e915 2917 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
5db06880
NC
2918 if (PL_pending_ident)
2919 return S_pending_ident(aTHX);
2920
2921 /* previous token ate up our whitespace? */
cd81e915
NC
2922 if (!PL_lasttoke && PL_nextwhite) {
2923 PL_thiswhite = PL_nextwhite;
2924 PL_nextwhite = 0;
5db06880
NC
2925 }
2926
2927 /* isolate the token, and figure out where it is without whitespace */
cd81e915
NC
2928 PL_realtokenstart = -1;
2929 PL_thistoken = 0;
5db06880
NC
2930 optype = yylex();
2931 s = PL_bufptr;
cd81e915 2932 assert(PL_curforce < 0);
5db06880 2933
cd81e915
NC
2934 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
2935 if (!PL_thistoken) {
2936 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
6b29d1f5 2937 PL_thistoken = newSVpvs("");
5db06880 2938 else {
c35e046a 2939 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
cd81e915 2940 PL_thistoken = newSVpvn(tstart, s - tstart);
5db06880
NC
2941 }
2942 }
cd81e915
NC
2943 if (PL_thismad) /* install head */
2944 CURMAD('X', PL_thistoken);
5db06880
NC
2945 }
2946
2947 /* last whitespace of a sublex? */
cd81e915
NC
2948 if (optype == ')' && PL_endwhite) {
2949 CURMAD('X', PL_endwhite);
5db06880
NC
2950 }
2951
cd81e915 2952 if (!PL_thismad) {
5db06880
NC
2953
2954 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
cd81e915
NC
2955 if (!PL_thiswhite && !PL_endwhite && !optype) {
2956 sv_free(PL_thistoken);
2957 PL_thistoken = 0;
5db06880
NC
2958 return 0;
2959 }
2960
2961 /* put off final whitespace till peg */
2962 if (optype == ';' && !PL_rsfp) {
cd81e915
NC
2963 PL_nextwhite = PL_thiswhite;
2964 PL_thiswhite = 0;
5db06880 2965 }
cd81e915
NC
2966 else if (PL_thisopen) {
2967 CURMAD('q', PL_thisopen);
2968 if (PL_thistoken)
2969 sv_free(PL_thistoken);
2970 PL_thistoken = 0;
5db06880
NC
2971 }
2972 else {
2973 /* Store actual token text as madprop X */
cd81e915 2974 CURMAD('X', PL_thistoken);
5db06880
NC
2975 }
2976
cd81e915 2977 if (PL_thiswhite) {
5db06880 2978 /* add preceding whitespace as madprop _ */
cd81e915 2979 CURMAD('_', PL_thiswhite);
5db06880
NC
2980 }
2981
cd81e915 2982 if (PL_thisstuff) {
5db06880 2983 /* add quoted material as madprop = */
cd81e915 2984 CURMAD('=', PL_thisstuff);
5db06880
NC
2985 }
2986
cd81e915 2987 if (PL_thisclose) {
5db06880 2988 /* add terminating quote as madprop Q */
cd81e915 2989 CURMAD('Q', PL_thisclose);
5db06880
NC
2990 }
2991 }
2992
2993 /* special processing based on optype */
2994
2995 switch (optype) {
2996
2997 /* opval doesn't need a TOKEN since it can already store mp */
2998 case WORD:
2999 case METHOD:
3000 case FUNCMETH:
3001 case THING:
3002 case PMFUNC:
3003 case PRIVATEREF:
3004 case FUNC0SUB:
3005 case UNIOPSUB:
3006 case LSTOPSUB:
3007 if (yylval.opval)
cd81e915
NC
3008 append_madprops(PL_thismad, yylval.opval, 0);
3009 PL_thismad = 0;
5db06880
NC
3010 return optype;
3011
3012 /* fake EOF */
3013 case 0:
3014 optype = PEG;
cd81e915
NC
3015 if (PL_endwhite) {
3016 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
3017 PL_endwhite = 0;
5db06880
NC
3018 }
3019 break;
3020
3021 case ']':
3022 case '}':
cd81e915 3023 if (PL_faketokens)
5db06880
NC
3024 break;
3025 /* remember any fake bracket that lexer is about to discard */
3026 if (PL_lex_brackets == 1 &&
3027 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
3028 {
3029 s = PL_bufptr;
3030 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3031 s++;
3032 if (*s == '}') {
cd81e915
NC
3033 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
3034 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3035 PL_thiswhite = 0;
5db06880
NC
3036 PL_bufptr = s - 1;
3037 break; /* don't bother looking for trailing comment */
3038 }
3039 else
3040 s = PL_bufptr;
3041 }
3042 if (optype == ']')
3043 break;
3044 /* FALLTHROUGH */
3045
3046 /* attach a trailing comment to its statement instead of next token */
3047 case ';':
cd81e915 3048 if (PL_faketokens)
5db06880
NC
3049 break;
3050 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
3051 s = PL_bufptr;
3052 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3053 s++;
3054 if (*s == '\n' || *s == '#') {
3055 while (s < PL_bufend && *s != '\n')
3056 s++;
3057 if (s < PL_bufend)
3058 s++;
cd81e915
NC
3059 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
3060 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3061 PL_thiswhite = 0;
5db06880
NC
3062 PL_bufptr = s;
3063 }
3064 }
3065 break;
3066
3067 /* pval */
3068 case LABEL:
3069 break;
3070
3071 /* ival */
3072 default:
3073 break;
3074
3075 }
3076
3077 /* Create new token struct. Note: opvals return early above. */
cd81e915
NC
3078 yylval.tkval = newTOKEN(optype, yylval, PL_thismad);
3079 PL_thismad = 0;
5db06880
NC
3080 return optype;
3081}
3082#endif
3083
468aa647 3084STATIC char *
cc6ed77d 3085S_tokenize_use(pTHX_ int is_use, char *s) {
97aff369 3086 dVAR;
468aa647
RGS
3087 if (PL_expect != XSTATE)
3088 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
3089 is_use ? "use" : "no"));
29595ff2 3090 s = SKIPSPACE1(s);
468aa647
RGS
3091 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
3092 s = force_version(s, TRUE);
29595ff2 3093 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
cd81e915 3094 start_force(PL_curforce);
9ded7720 3095 NEXTVAL_NEXTTOKE.opval = NULL;
468aa647
RGS
3096 force_next(WORD);
3097 }
3098 else if (*s == 'v') {
3099 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3100 s = force_version(s, FALSE);
3101 }
3102 }
3103 else {
3104 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3105 s = force_version(s, FALSE);
3106 }
3107 yylval.ival = is_use;
3108 return s;
3109}
748a9306 3110#ifdef DEBUGGING
27da23d5 3111 static const char* const exp_name[] =
09bef843 3112 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
27308ded 3113 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
09bef843 3114 };
748a9306 3115#endif
463ee0b2 3116
02aa26ce
NT
3117/*
3118 yylex
3119
3120 Works out what to call the token just pulled out of the input
3121 stream. The yacc parser takes care of taking the ops we return and
3122 stitching them into a tree.
3123
3124 Returns:
3125 PRIVATEREF
3126
3127 Structure:
3128 if read an identifier
3129 if we're in a my declaration
3130 croak if they tried to say my($foo::bar)
3131 build the ops for a my() declaration
3132 if it's an access to a my() variable
3133 are we in a sort block?
3134 croak if my($a); $a <=> $b
3135 build ops for access to a my() variable
3136 if in a dq string, and they've said @foo and we can't find @foo
3137 croak
3138 build ops for a bareword
3139 if we already built the token before, use it.
3140*/
3141
20141f0e 3142
dba4d153
JH
3143#ifdef __SC__
3144#pragma segment Perl_yylex
3145#endif
dba4d153 3146int
dba4d153 3147Perl_yylex(pTHX)
20141f0e 3148{
97aff369 3149 dVAR;
3afc138a 3150 register char *s = PL_bufptr;
378cc40b 3151 register char *d;
463ee0b2 3152 STRLEN len;
aa7440fb 3153 bool bof = FALSE;
a687059c 3154
10edeb5d
JH
3155 /* orig_keyword, gvp, and gv are initialized here because
3156 * jump to the label just_a_word_zero can bypass their
3157 * initialization later. */
3158 I32 orig_keyword = 0;
3159 GV *gv = NULL;
3160 GV **gvp = NULL;
3161
bbf60fe6 3162 DEBUG_T( {
396482e1 3163 SV* tmp = newSVpvs("");
b6007c36
DM
3164 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3165 (IV)CopLINE(PL_curcop),
3166 lex_state_names[PL_lex_state],
3167 exp_name[PL_expect],
3168 pv_display(tmp, s, strlen(s), 0, 60));
3169 SvREFCNT_dec(tmp);
bbf60fe6 3170 } );
02aa26ce 3171 /* check if there's an identifier for us to look at */
ba979b31 3172 if (PL_pending_ident)
bbf60fe6 3173 return REPORT(S_pending_ident(aTHX));
bbce6d69 3174
02aa26ce
NT
3175 /* no identifier pending identification */
3176
3280af22 3177 switch (PL_lex_state) {
79072805
LW
3178#ifdef COMMENTARY
3179 case LEX_NORMAL: /* Some compilers will produce faster */
3180 case LEX_INTERPNORMAL: /* code if we comment these out. */
3181 break;
3182#endif
3183
09bef843 3184 /* when we've already built the next token, just pull it out of the queue */
79072805 3185 case LEX_KNOWNEXT:
5db06880
NC
3186#ifdef PERL_MAD
3187 PL_lasttoke--;
3188 yylval = PL_nexttoke[PL_lasttoke].next_val;
3189 if (PL_madskills) {
cd81e915 3190 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
5db06880 3191 PL_nexttoke[PL_lasttoke].next_mad = 0;
cd81e915
NC
3192 if (PL_thismad && PL_thismad->mad_key == '_') {
3193 PL_thiswhite = (SV*)PL_thismad->mad_val;
3194 PL_thismad->mad_val = 0;
3195 mad_free(PL_thismad);
3196 PL_thismad = 0;
5db06880
NC
3197 }
3198 }
3199 if (!PL_lasttoke) {
3200 PL_lex_state = PL_lex_defer;
3201 PL_expect = PL_lex_expect;
3202 PL_lex_defer = LEX_NORMAL;
3203 if (!PL_nexttoke[PL_lasttoke].next_type)
3204 return yylex();
3205 }
3206#else
3280af22 3207 PL_nexttoke--;
5db06880 3208 yylval = PL_nextval[PL_nexttoke];
3280af22
NIS
3209 if (!PL_nexttoke) {
3210 PL_lex_state = PL_lex_defer;
3211 PL_expect = PL_lex_expect;
3212 PL_lex_defer = LEX_NORMAL;
463ee0b2 3213 }
5db06880
NC
3214#endif
3215#ifdef PERL_MAD
3216 /* FIXME - can these be merged? */
3217 return(PL_nexttoke[PL_lasttoke].next_type);
3218#else
bbf60fe6 3219 return REPORT(PL_nexttype[PL_nexttoke]);
5db06880 3220#endif
79072805 3221
02aa26ce 3222 /* interpolated case modifiers like \L \U, including \Q and \E.
3280af22 3223 when we get here, PL_bufptr is at the \
02aa26ce 3224 */
79072805
LW
3225 case LEX_INTERPCASEMOD:
3226#ifdef DEBUGGING
3280af22 3227 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
cea2e8a9 3228 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
79072805 3229#endif
02aa26ce 3230 /* handle \E or end of string */
3280af22 3231 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
02aa26ce 3232 /* if at a \E */
3280af22 3233 if (PL_lex_casemods) {
f54cb97a 3234 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3280af22 3235 PL_lex_casestack[PL_lex_casemods] = '\0';
02aa26ce 3236
3792a11b
NC
3237 if (PL_bufptr != PL_bufend
3238 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3280af22
NIS
3239 PL_bufptr += 2;
3240 PL_lex_state = LEX_INTERPCONCAT;
5db06880
NC
3241#ifdef PERL_MAD
3242 if (PL_madskills)
6b29d1f5 3243 PL_thistoken = newSVpvs("\\E");
5db06880 3244#endif
a0d0e21e 3245 }
bbf60fe6 3246 return REPORT(')');
79072805 3247 }
5db06880
NC
3248#ifdef PERL_MAD
3249 while (PL_bufptr != PL_bufend &&
3250 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
cd81e915 3251 if (!PL_thiswhite)
6b29d1f5 3252 PL_thiswhite = newSVpvs("");
cd81e915 3253 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
5db06880
NC
3254 PL_bufptr += 2;
3255 }
3256#else
3280af22
NIS
3257 if (PL_bufptr != PL_bufend)
3258 PL_bufptr += 2;
5db06880 3259#endif
3280af22 3260 PL_lex_state = LEX_INTERPCONCAT;
cea2e8a9 3261 return yylex();
79072805
LW
3262 }
3263 else {
607df283 3264 DEBUG_T({ PerlIO_printf(Perl_debug_log,
b6007c36 3265 "### Saw case modifier\n"); });
3280af22 3266 s = PL_bufptr + 1;
6e909404 3267 if (s[1] == '\\' && s[2] == 'E') {
5db06880 3268#ifdef PERL_MAD
cd81e915 3269 if (!PL_thiswhite)
6b29d1f5 3270 PL_thiswhite = newSVpvs("");
cd81e915 3271 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
5db06880 3272#endif
89122651 3273 PL_bufptr = s + 3;
6e909404
JH
3274 PL_lex_state = LEX_INTERPCONCAT;
3275 return yylex();
a0d0e21e 3276 }
6e909404 3277 else {
90771dc0 3278 I32 tmp;
5db06880
NC
3279 if (!PL_madskills) /* when just compiling don't need correct */
3280 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3281 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3792a11b 3282 if ((*s == 'L' || *s == 'U') &&
6e909404
JH
3283 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3284 PL_lex_casestack[--PL_lex_casemods] = '\0';
bbf60fe6 3285 return REPORT(')');
6e909404
JH
3286 }
3287 if (PL_lex_casemods > 10)
3288 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3289 PL_lex_casestack[PL_lex_casemods++] = *s;
3290 PL_lex_casestack[PL_lex_casemods] = '\0';
3291 PL_lex_state = LEX_INTERPCONCAT;
cd81e915 3292 start_force(PL_curforce);
9ded7720 3293 NEXTVAL_NEXTTOKE.ival = 0;
6e909404 3294 force_next('(');
cd81e915 3295 start_force(PL_curforce);
6e909404 3296 if (*s == 'l')
9ded7720 3297 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
6e909404 3298 else if (*s == 'u')
9ded7720 3299 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
6e909404 3300 else if (*s == 'L')
9ded7720 3301 NEXTVAL_NEXTTOKE.ival = OP_LC;
6e909404 3302 else if (*s == 'U')
9ded7720 3303 NEXTVAL_NEXTTOKE.ival = OP_UC;
6e909404 3304 else if (*s == 'Q')
9ded7720 3305 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
6e909404
JH
3306 else
3307 Perl_croak(aTHX_ "panic: yylex");
5db06880 3308 if (PL_madskills) {
6b29d1f5 3309 SV* const tmpsv = newSVpvs("");
5db06880
NC
3310 Perl_sv_catpvf(aTHX_ tmpsv, "\\%c", *s);
3311 curmad('_', tmpsv);
3312 }
6e909404 3313 PL_bufptr = s + 1;
a0d0e21e 3314 }
79072805 3315 force_next(FUNC);
3280af22
NIS
3316 if (PL_lex_starts) {
3317 s = PL_bufptr;
3318 PL_lex_starts = 0;
5db06880
NC
3319#ifdef PERL_MAD
3320 if (PL_madskills) {
cd81e915
NC
3321 if (PL_thistoken)
3322 sv_free(PL_thistoken);
6b29d1f5 3323 PL_thistoken = newSVpvs("");
5db06880
NC
3324 }
3325#endif
131b3ad0
DM
3326 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3327 if (PL_lex_casemods == 1 && PL_lex_inpat)
3328 OPERATOR(',');
3329 else
3330 Aop(OP_CONCAT);
79072805
LW
3331 }
3332 else
cea2e8a9 3333 return yylex();
79072805
LW
3334 }
3335
55497cff 3336 case LEX_INTERPPUSH:
bbf60fe6 3337 return REPORT(sublex_push());
55497cff 3338
79072805 3339 case LEX_INTERPSTART:
3280af22 3340 if (PL_bufptr == PL_bufend)
bbf60fe6 3341 return REPORT(sublex_done());
607df283 3342 DEBUG_T({ PerlIO_printf(Perl_debug_log,
b6007c36 3343 "### Interpolated variable\n"); });
3280af22
NIS
3344 PL_expect = XTERM;
3345 PL_lex_dojoin = (*PL_bufptr == '@');
3346 PL_lex_state = LEX_INTERPNORMAL;
3347 if (PL_lex_dojoin) {
cd81e915 3348 start_force(PL_curforce);
9ded7720 3349 NEXTVAL_NEXTTOKE.ival = 0;
79072805 3350 force_next(',');
cd81e915 3351 start_force(PL_curforce);
a0d0e21e 3352 force_ident("\"", '$');
cd81e915 3353 start_force(PL_curforce);
9ded7720 3354 NEXTVAL_NEXTTOKE.ival = 0;
79072805 3355 force_next('$');
cd81e915 3356 start_force(PL_curforce);
9ded7720 3357 NEXTVAL_NEXTTOKE.ival = 0;
79072805 3358 force_next('(');
cd81e915 3359 start_force(PL_curforce);
9ded7720 3360 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
79072805
LW
3361 force_next(FUNC);
3362 }
3280af22
NIS
3363 if (PL_lex_starts++) {
3364 s = PL_bufptr;
5db06880
NC
3365#ifdef PERL_MAD
3366 if (PL_madskills) {
cd81e915
NC
3367 if (PL_thistoken)
3368 sv_free(PL_thistoken);
6b29d1f5 3369 PL_thistoken = newSVpvs("");
5db06880
NC
3370 }
3371#endif
131b3ad0
DM
3372 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3373 if (!PL_lex_casemods && PL_lex_inpat)
3374 OPERATOR(',');
3375 else
3376 Aop(OP_CONCAT);
79072805 3377 }
cea2e8a9 3378 return yylex();
79072805
LW
3379
3380 case LEX_INTERPENDMAYBE:
3280af22
NIS
3381 if (intuit_more(PL_bufptr)) {
3382 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
79072805
LW
3383 break;
3384 }
3385 /* FALL THROUGH */
3386
3387 case LEX_INTERPEND:
3280af22
NIS
3388 if (PL_lex_dojoin) {
3389 PL_lex_dojoin = FALSE;
3390 PL_lex_state = LEX_INTERPCONCAT;
5db06880
NC
3391#ifdef PERL_MAD
3392 if (PL_madskills) {
cd81e915
NC
3393 if (PL_thistoken)
3394 sv_free(PL_thistoken);
6b29d1f5 3395 PL_thistoken = newSVpvs("");
5db06880
NC
3396 }
3397#endif
bbf60fe6 3398 return REPORT(')');
79072805 3399 }
43a16006 3400 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
25da4f38 3401 && SvEVALED(PL_lex_repl))
43a16006 3402 {
e9fa98b2 3403 if (PL_bufptr != PL_bufend)
cea2e8a9 3404 Perl_croak(aTHX_ "Bad evalled substitution pattern");
a0714e2c 3405 PL_lex_repl = NULL;
e9fa98b2 3406 }
79072805
LW
3407 /* FALLTHROUGH */
3408 case LEX_INTERPCONCAT:
3409#ifdef DEBUGGING
3280af22 3410 if (PL_lex_brackets)
cea2e8a9 3411 Perl_croak(aTHX_ "panic: INTERPCONCAT");
79072805 3412#endif
3280af22 3413 if (PL_bufptr == PL_bufend)
bbf60fe6 3414 return REPORT(sublex_done());
79072805 3415
3280af22
NIS
3416 if (SvIVX(PL_linestr) == '\'') {
3417 SV *sv = newSVsv(PL_linestr);
3418 if (!PL_lex_inpat)
76e3520e 3419 sv = tokeq(sv);
3280af22 3420 else if ( PL_hints & HINT_NEW_RE )
b3ac6de7 3421 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
79072805 3422 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3280af22 3423 s = PL_bufend;
79072805
LW
3424 }
3425 else {
3280af22 3426 s = scan_const(PL_bufptr);
79072805 3427 if (*s == '\\')
3280af22 3428 PL_lex_state = LEX_INTERPCASEMOD;
79072805 3429 else
3280af22 3430 PL_lex_state = LEX_INTERPSTART;
79072805
LW
3431 }
3432
3280af22 3433 if (s != PL_bufptr) {
cd81e915 3434 start_force(PL_curforce);
5db06880
NC
3435 if (PL_madskills) {
3436 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3437 }
9ded7720 3438 NEXTVAL_NEXTTOKE = yylval;
3280af22 3439 PL_expect = XTERM;
79072805 3440 force_next(THING);
131b3ad0 3441 if (PL_lex_starts++) {
5db06880
NC
3442#ifdef PERL_MAD
3443 if (PL_madskills) {
cd81e915
NC
3444 if (PL_thistoken)
3445 sv_free(PL_thistoken);
6b29d1f5 3446 PL_thistoken = newSVpvs("");
5db06880
NC
3447 }
3448#endif
131b3ad0
DM
3449 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3450 if (!PL_lex_casemods && PL_lex_inpat)
3451 OPERATOR(',');
3452 else
3453 Aop(OP_CONCAT);
3454 }
79072805 3455 else {
3280af22 3456 PL_bufptr = s;
cea2e8a9 3457 return yylex();
79072805
LW
3458 }
3459 }
3460
cea2e8a9 3461 return yylex();
a0d0e21e 3462 case LEX_FORMLINE:
3280af22
NIS
3463 PL_lex_state = LEX_NORMAL;
3464 s = scan_formline(PL_bufptr);
3465 if (!PL_lex_formbrack)
a0d0e21e
LW
3466 goto rightbracket;
3467 OPERATOR(';');
79072805
LW
3468 }
3469
3280af22
NIS
3470 s = PL_bufptr;
3471 PL_oldoldbufptr = PL_oldbufptr;
3472 PL_oldbufptr = s;
463ee0b2
LW
3473
3474 retry:
5db06880 3475#ifdef PERL_MAD
cd81e915
NC
3476 if (PL_thistoken) {
3477 sv_free(PL_thistoken);
3478 PL_thistoken = 0;
5db06880 3479 }
cd81e915 3480 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
5db06880 3481#endif
378cc40b
LW
3482 switch (*s) {
3483 default:
7e2040f0 3484 if (isIDFIRST_lazy_if(s,UTF))
834a4ddd 3485 goto keylookup;
cea2e8a9 3486 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
e929a76b
LW
3487 case 4:
3488 case 26:
3489 goto fake_eof; /* emulate EOF on ^D or ^Z */
378cc40b 3490 case 0:
5db06880
NC
3491#ifdef PERL_MAD
3492 if (PL_madskills)
cd81e915 3493 PL_faketokens = 0;
5db06880 3494#endif
3280af22
NIS
3495 if (!PL_rsfp) {
3496 PL_last_uni = 0;
3497 PL_last_lop = 0;
c5ee2135 3498 if (PL_lex_brackets) {
10edeb5d
JH
3499 yyerror((const char *)
3500 (PL_lex_formbrack
3501 ? "Format not terminated"
3502 : "Missing right curly or square bracket"));
c5ee2135 3503 }
4e553d73 3504 DEBUG_T( { PerlIO_printf(Perl_debug_log,
607df283 3505 "### Tokener got EOF\n");
5f80b19c 3506 } );
79072805 3507 TOKEN(0);
463ee0b2 3508 }
3280af22 3509 if (s++ < PL_bufend)
a687059c 3510 goto retry; /* ignore stray nulls */
3280af22
NIS
3511 PL_last_uni = 0;
3512 PL_last_lop = 0;
3513 if (!PL_in_eval && !PL_preambled) {
3514 PL_preambled = TRUE;
5db06880
NC
3515#ifdef PERL_MAD
3516 if (PL_madskills)
cd81e915 3517 PL_faketokens = 1;
5db06880 3518#endif
3280af22
NIS
3519 sv_setpv(PL_linestr,incl_perldb());
3520 if (SvCUR(PL_linestr))
396482e1 3521 sv_catpvs(PL_linestr,";");
3280af22
NIS
3522 if (PL_preambleav){
3523 while(AvFILLp(PL_preambleav) >= 0) {
3524 SV *tmpsv = av_shift(PL_preambleav);
3525 sv_catsv(PL_linestr, tmpsv);
396482e1 3526 sv_catpvs(PL_linestr, ";");
91b7def8 3527 sv_free(tmpsv);
3528 }
3280af22
NIS
3529 sv_free((SV*)PL_preambleav);
3530 PL_preambleav = NULL;
91b7def8 3531 }
3280af22 3532 if (PL_minus_n || PL_minus_p) {
396482e1 3533 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3280af22 3534 if (PL_minus_l)
396482e1 3535 sv_catpvs(PL_linestr,"chomp;");
3280af22 3536 if (PL_minus_a) {
3280af22 3537 if (PL_minus_F) {
3792a11b
NC
3538 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3539 || *PL_splitstr == '"')
3280af22 3540 && strchr(PL_splitstr + 1, *PL_splitstr))
3db68c4c 3541 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
54310121 3542 else {
c8ef6a4b
NC
3543 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3544 bytes can be used as quoting characters. :-) */
dd374669 3545 const char *splits = PL_splitstr;
91d456ae 3546 sv_catpvs(PL_linestr, "our @F=split(q\0");
48c4c863
NC
3547 do {
3548 /* Need to \ \s */
dd374669
AL
3549 if (*splits == '\\')
3550 sv_catpvn(PL_linestr, splits, 1);
3551 sv_catpvn(PL_linestr, splits, 1);
3552 } while (*splits++);
48c4c863
NC
3553 /* This loop will embed the trailing NUL of
3554 PL_linestr as the last thing it does before
3555 terminating. */
396482e1 3556 sv_catpvs(PL_linestr, ");");
54310121 3557 }
2304df62
AD
3558 }
3559 else
396482e1 3560 sv_catpvs(PL_linestr,"our @F=split(' ');");
2304df62 3561 }
79072805 3562 }
bc9b29db 3563 if (PL_minus_E)
396482e1
GA
3564 sv_catpvs(PL_linestr,"use feature ':5.10';");
3565 sv_catpvs(PL_linestr, "\n");
3280af22
NIS
3566 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3567 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3568 PL_last_lop = PL_last_uni = NULL;
80a702cd
RGS
3569 if (PERLDB_LINE && PL_curstash != PL_debstash)
3570 update_debugger_info_sv(PL_linestr);
79072805 3571 goto retry;
a687059c 3572 }
e929a76b 3573 do {
aa7440fb 3574 bof = PL_rsfp ? TRUE : FALSE;
bd61b366 3575 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
7e28d3af 3576 fake_eof:
5db06880 3577#ifdef PERL_MAD
cd81e915 3578 PL_realtokenstart = -1;
5db06880 3579#endif
7e28d3af
JH
3580 if (PL_rsfp) {
3581 if (PL_preprocess && !PL_in_eval)
3582 (void)PerlProc_pclose(PL_rsfp);
3583 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3584 PerlIO_clearerr(PL_rsfp);
3585 else
3586 (void)PerlIO_close(PL_rsfp);
4608196e 3587 PL_rsfp = NULL;
7e28d3af
JH
3588 PL_doextract = FALSE;
3589 }
3590 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
5db06880
NC
3591#ifdef PERL_MAD
3592 if (PL_madskills)
cd81e915 3593 PL_faketokens = 1;
5db06880 3594#endif
10edeb5d
JH
3595 sv_setpv(PL_linestr,
3596 (const char *)
3597 (PL_minus_p
3598 ? ";}continue{print;}" : ";}"));
7e28d3af
JH
3599 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3600 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3601 PL_last_lop = PL_last_uni = NULL;
7e28d3af
JH
3602 PL_minus_n = PL_minus_p = 0;
3603 goto retry;
3604 }
3605 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
bd61b366 3606 PL_last_lop = PL_last_uni = NULL;
c69006e4 3607 sv_setpvn(PL_linestr,"",0);
7e28d3af
JH
3608 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3609 }
7aa207d6
JH
3610 /* If it looks like the start of a BOM or raw UTF-16,
3611 * check if it in fact is. */
3612 else if (bof &&
3613 (*s == 0 ||
3614 *(U8*)s == 0xEF ||
3615 *(U8*)s >= 0xFE ||
3616 s[1] == 0)) {
226017aa 3617#ifdef PERLIO_IS_STDIO
e3f494f1
JH
3618# ifdef __GNU_LIBRARY__
3619# if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
226017aa
DD
3620# define FTELL_FOR_PIPE_IS_BROKEN
3621# endif
e3f494f1
JH
3622# else
3623# ifdef __GLIBC__
3624# if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3625# define FTELL_FOR_PIPE_IS_BROKEN
3626# endif
3627# endif
226017aa
DD
3628# endif
3629#endif
3630#ifdef FTELL_FOR_PIPE_IS_BROKEN
3631 /* This loses the possibility to detect the bof
3632 * situation on perl -P when the libc5 is being used.
3633 * Workaround? Maybe attach some extra state to PL_rsfp?
3634 */
3635 if (!PL_preprocess)
7e28d3af 3636 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
226017aa 3637#else
eb160463 3638 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
226017aa 3639#endif
7e28d3af 3640 if (bof) {
3280af22 3641 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
7e28d3af 3642 s = swallow_bom((U8*)s);
e929a76b 3643 }
378cc40b 3644 }
3280af22 3645 if (PL_doextract) {
a0d0e21e 3646 /* Incest with pod. */
5db06880
NC
3647#ifdef PERL_MAD
3648 if (PL_madskills)
cd81e915 3649 sv_catsv(PL_thiswhite, PL_linestr);
5db06880 3650#endif
a0d0e21e 3651 if (*s == '=' && strnEQ(s, "=cut", 4)) {
c69006e4 3652 sv_setpvn(PL_linestr, "", 0);
3280af22
NIS
3653 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3654 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3655 PL_last_lop = PL_last_uni = NULL;
3280af22 3656 PL_doextract = FALSE;
a0d0e21e 3657 }
4e553d73 3658 }
463ee0b2 3659 incline(s);
3280af22
NIS
3660 } while (PL_doextract);
3661 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
80a702cd
RGS
3662 if (PERLDB_LINE && PL_curstash != PL_debstash)
3663 update_debugger_info_sv(PL_linestr);
3280af22 3664 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3665 PL_last_lop = PL_last_uni = NULL;
57843af0 3666 if (CopLINE(PL_curcop) == 1) {
3280af22 3667 while (s < PL_bufend && isSPACE(*s))
79072805 3668 s++;
a0d0e21e 3669 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
79072805 3670 s++;
5db06880
NC
3671#ifdef PERL_MAD
3672 if (PL_madskills)
cd81e915 3673 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
5db06880 3674#endif
bd61b366 3675 d = NULL;
3280af22 3676 if (!PL_in_eval) {
44a8e56a 3677 if (*s == '#' && *(s+1) == '!')
3678 d = s + 2;
3679#ifdef ALTERNATE_SHEBANG
3680 else {
bfed75c6 3681 static char const as[] = ALTERNATE_SHEBANG;
44a8e56a 3682 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3683 d = s + (sizeof(as) - 1);
3684 }
3685#endif /* ALTERNATE_SHEBANG */
3686 }
3687 if (d) {
b8378b72 3688 char *ipath;
774d564b 3689 char *ipathend;
b8378b72 3690
774d564b 3691 while (isSPACE(*d))
b8378b72
CS
3692 d++;
3693 ipath = d;
774d564b 3694 while (*d && !isSPACE(*d))
3695 d++;
3696 ipathend = d;
3697
3698#ifdef ARG_ZERO_IS_SCRIPT
3699 if (ipathend > ipath) {
3700 /*
3701 * HP-UX (at least) sets argv[0] to the script name,
3702 * which makes $^X incorrect. And Digital UNIX and Linux,
3703 * at least, set argv[0] to the basename of the Perl
3704 * interpreter. So, having found "#!", we'll set it right.
3705 */
fafc274c
NC
3706 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3707 SVt_PV)); /* $^X */
774d564b 3708 assert(SvPOK(x) || SvGMAGICAL(x));
cc49e20b 3709 if (sv_eq(x, CopFILESV(PL_curcop))) {
774d564b 3710 sv_setpvn(x, ipath, ipathend - ipath);
9607fc9c 3711 SvSETMAGIC(x);
3712 }
556c1dec
JH
3713 else {
3714 STRLEN blen;
3715 STRLEN llen;
cfd0369c 3716 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
9d4ba2ae 3717 const char * const lstart = SvPV_const(x,llen);
556c1dec
JH
3718 if (llen < blen) {
3719 bstart += blen - llen;
3720 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3721 sv_setpvn(x, ipath, ipathend - ipath);
3722 SvSETMAGIC(x);
3723 }
3724 }
3725 }
774d564b 3726 TAINT_NOT; /* $^X is always tainted, but that's OK */
8ebc5c01 3727 }
774d564b 3728#endif /* ARG_ZERO_IS_SCRIPT */
b8378b72
CS
3729
3730 /*
3731 * Look for options.
3732 */
748a9306 3733 d = instr(s,"perl -");
84e30d1a 3734 if (!d) {
748a9306 3735 d = instr(s,"perl");
84e30d1a
GS
3736#if defined(DOSISH)
3737 /* avoid getting into infinite loops when shebang
3738 * line contains "Perl" rather than "perl" */
3739 if (!d) {
3740 for (d = ipathend-4; d >= ipath; --d) {
3741 if ((*d == 'p' || *d == 'P')
3742 && !ibcmp(d, "perl", 4))
3743 {
3744 break;
3745 }
3746 }
3747 if (d < ipath)
bd61b366 3748 d = NULL;
84e30d1a
GS
3749 }
3750#endif
3751 }
44a8e56a 3752#ifdef ALTERNATE_SHEBANG
3753 /*
3754 * If the ALTERNATE_SHEBANG on this system starts with a
3755 * character that can be part of a Perl expression, then if
3756 * we see it but not "perl", we're probably looking at the
3757 * start of Perl code, not a request to hand off to some
3758 * other interpreter. Similarly, if "perl" is there, but
3759 * not in the first 'word' of the line, we assume the line
3760 * contains the start of the Perl program.
44a8e56a 3761 */
3762 if (d && *s != '#') {
f54cb97a 3763 const char *c = ipath;
44a8e56a 3764 while (*c && !strchr("; \t\r\n\f\v#", *c))
3765 c++;
3766 if (c < d)
bd61b366 3767 d = NULL; /* "perl" not in first word; ignore */
44a8e56a 3768 else
3769 *s = '#'; /* Don't try to parse shebang line */
3770 }
774d564b 3771#endif /* ALTERNATE_SHEBANG */
bf4acbe4 3772#ifndef MACOS_TRADITIONAL
748a9306 3773 if (!d &&
44a8e56a 3774 *s == '#' &&
774d564b 3775 ipathend > ipath &&
3280af22 3776 !PL_minus_c &&
748a9306 3777 !instr(s,"indir") &&
3280af22 3778 instr(PL_origargv[0],"perl"))
748a9306 3779 {
27da23d5 3780 dVAR;
9f68db38 3781 char **newargv;
9f68db38 3782
774d564b 3783 *ipathend = '\0';
3784 s = ipathend + 1;
3280af22 3785 while (s < PL_bufend && isSPACE(*s))
9f68db38 3786 s++;
3280af22 3787 if (s < PL_bufend) {
a02a5408 3788 Newxz(newargv,PL_origargc+3,char*);
9f68db38 3789 newargv[1] = s;
3280af22 3790 while (s < PL_bufend && !isSPACE(*s))
9f68db38
LW
3791 s++;
3792 *s = '\0';
3280af22 3793 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
9f68db38
LW
3794 }
3795 else
3280af22 3796 newargv = PL_origargv;
774d564b 3797 newargv[0] = ipath;
b35112e7 3798 PERL_FPU_PRE_EXEC
b4748376 3799 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
b35112e7 3800 PERL_FPU_POST_EXEC
cea2e8a9 3801 Perl_croak(aTHX_ "Can't exec %s", ipath);
9f68db38 3802 }
bf4acbe4 3803#endif
748a9306 3804 if (d) {
c35e046a
AL
3805 while (*d && !isSPACE(*d))
3806 d++;
3807 while (SPACE_OR_TAB(*d))
3808 d++;
748a9306
LW
3809
3810 if (*d++ == '-') {
f54cb97a 3811 const bool switches_done = PL_doswitches;
fb993905
GA
3812 const U32 oldpdb = PL_perldb;
3813 const bool oldn = PL_minus_n;
3814 const bool oldp = PL_minus_p;
3815
8cc95fdb 3816 do {
3ffe3ee4 3817 if (*d == 'M' || *d == 'm' || *d == 'C') {
9d4ba2ae 3818 const char * const m = d;
d4c19fe8
AL
3819 while (*d && !isSPACE(*d))
3820 d++;
cea2e8a9 3821 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
8cc95fdb 3822 (int)(d - m), m);
3823 }
97bd5664 3824 d = moreswitches(d);
8cc95fdb 3825 } while (d);
f0b2cf55
YST
3826 if (PL_doswitches && !switches_done) {
3827 int argc = PL_origargc;
3828 char **argv = PL_origargv;
3829 do {
3830 argc--,argv++;
3831 } while (argc && argv[0][0] == '-' && argv[0][1]);
3832 init_argv_symbols(argc,argv);
3833 }
155aba94
GS
3834 if ((PERLDB_LINE && !oldpdb) ||
3835 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
b084f20b 3836 /* if we have already added "LINE: while (<>) {",
3837 we must not do it again */
748a9306 3838 {
c69006e4 3839 sv_setpvn(PL_linestr, "", 0);
3280af22
NIS
3840 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3841 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3842 PL_last_lop = PL_last_uni = NULL;
3280af22 3843 PL_preambled = FALSE;
84902520 3844 if (PERLDB_LINE)
3280af22 3845 (void)gv_fetchfile(PL_origfilename);
748a9306
LW
3846 goto retry;
3847 }
a0d0e21e 3848 }
79072805 3849 }
9f68db38 3850 }
79072805 3851 }
3280af22
NIS
3852 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3853 PL_bufptr = s;
3854 PL_lex_state = LEX_FORMLINE;
cea2e8a9 3855 return yylex();
ae986130 3856 }
378cc40b 3857 goto retry;
4fdae800 3858 case '\r':
6a27c188 3859#ifdef PERL_STRICT_CR
cea2e8a9 3860 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
4e553d73 3861 Perl_croak(aTHX_
cc507455 3862 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
a868473f 3863#endif
4fdae800 3864 case ' ': case '\t': case '\f': case 013:
bf4acbe4
GS
3865#ifdef MACOS_TRADITIONAL
3866 case '\312':
3867#endif
5db06880 3868#ifdef PERL_MAD
cd81e915 3869 PL_realtokenstart = -1;
5db06880
NC
3870 s = SKIPSPACE0(s);
3871#else
378cc40b 3872 s++;
5db06880 3873#endif
378cc40b 3874 goto retry;
378cc40b 3875 case '#':
e929a76b 3876 case '\n':
5db06880 3877#ifdef PERL_MAD
cd81e915 3878 PL_realtokenstart = -1;
5db06880 3879 if (PL_madskills)
cd81e915 3880 PL_faketokens = 0;
5db06880 3881#endif
3280af22 3882 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
df0deb90
GS
3883 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3884 /* handle eval qq[#line 1 "foo"\n ...] */
3885 CopLINE_dec(PL_curcop);
3886 incline(s);
3887 }
5db06880
NC
3888 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
3889 s = SKIPSPACE0(s);
3890 if (!PL_in_eval || PL_rsfp)
3891 incline(s);
3892 }
3893 else {
3894 d = s;
3895 while (d < PL_bufend && *d != '\n')
3896 d++;
3897 if (d < PL_bufend)
3898 d++;
3899 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3900 Perl_croak(aTHX_ "panic: input overflow");
3901#ifdef PERL_MAD
3902 if (PL_madskills)
cd81e915 3903 PL_thiswhite = newSVpvn(s, d - s);
5db06880
NC
3904#endif
3905 s = d;
3906 incline(s);
3907 }
3280af22
NIS
3908 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3909 PL_bufptr = s;
3910 PL_lex_state = LEX_FORMLINE;
cea2e8a9 3911 return yylex();
a687059c 3912 }
378cc40b 3913 }
a687059c 3914 else {
5db06880
NC
3915#ifdef PERL_MAD
3916 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
3917 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
cd81e915 3918 PL_faketokens = 0;
5db06880
NC
3919 s = SKIPSPACE0(s);
3920 TOKEN(PEG); /* make sure any #! line is accessible */
3921 }
3922 s = SKIPSPACE0(s);
3923 }
3924 else {
3925/* if (PL_madskills && PL_lex_formbrack) { */
3926 d = s;
3927 while (d < PL_bufend && *d != '\n')
3928 d++;
3929 if (d < PL_bufend)
3930 d++;
3931 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3932 Perl_croak(aTHX_ "panic: input overflow");
3933 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
cd81e915 3934 if (!PL_thiswhite)
6b29d1f5 3935 PL_thiswhite = newSVpvs("");
5db06880 3936 if (CopLINE(PL_curcop) == 1) {
cd81e915
NC
3937 sv_setpvn(PL_thiswhite, "", 0);
3938 PL_faketokens = 0;
5db06880 3939 }
cd81e915 3940 sv_catpvn(PL_thiswhite, s, d - s);
5db06880
NC
3941 }
3942 s = d;
3943/* }
3944 *s = '\0';
3945 PL_bufend = s; */
3946 }
3947#else
378cc40b 3948 *s = '\0';
3280af22 3949 PL_bufend = s;
5db06880 3950#endif
a687059c 3951 }
378cc40b
LW
3952 goto retry;
3953 case '-':
79072805 3954 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
e5edeb50 3955 I32 ftst = 0;
90771dc0 3956 char tmp;
e5edeb50 3957
378cc40b 3958 s++;
3280af22 3959 PL_bufptr = s;
748a9306
LW
3960 tmp = *s++;
3961
bf4acbe4 3962 while (s < PL_bufend && SPACE_OR_TAB(*s))
748a9306
LW
3963 s++;
3964
3965 if (strnEQ(s,"=>",2)) {
3280af22 3966 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
931e0695 3967 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
748a9306
LW
3968 OPERATOR('-'); /* unary minus */
3969 }
3280af22 3970 PL_last_uni = PL_oldbufptr;
748a9306 3971 switch (tmp) {
e5edeb50
JH
3972 case 'r': ftst = OP_FTEREAD; break;
3973 case 'w': ftst = OP_FTEWRITE; break;
3974 case 'x': ftst = OP_FTEEXEC; break;
3975 case 'o': ftst = OP_FTEOWNED; break;
3976 case 'R': ftst = OP_FTRREAD; break;
3977 case 'W': ftst = OP_FTRWRITE; break;
3978 case 'X': ftst = OP_FTREXEC; break;
3979 case 'O': ftst = OP_FTROWNED; break;
3980 case 'e': ftst = OP_FTIS; break;
3981 case 'z': ftst = OP_FTZERO; break;
3982 case 's': ftst = OP_FTSIZE; break;
3983 case 'f': ftst = OP_FTFILE; break;
3984 case 'd': ftst = OP_FTDIR; break;
3985 case 'l': ftst = OP_FTLINK; break;
3986 case 'p': ftst = OP_FTPIPE; break;
3987 case 'S': ftst = OP_FTSOCK; break;
3988 case 'u': ftst = OP_FTSUID; break;
3989 case 'g': ftst = OP_FTSGID; break;
3990 case 'k': ftst = OP_FTSVTX; break;
3991 case 'b': ftst = OP_FTBLK; break;
3992 case 'c': ftst = OP_FTCHR; break;
3993 case 't': ftst = OP_FTTTY; break;
3994 case 'T': ftst = OP_FTTEXT; break;
3995 case 'B': ftst = OP_FTBINARY; break;
3996 case 'M': case 'A': case 'C':
fafc274c 3997 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
e5edeb50
JH
3998 switch (tmp) {
3999 case 'M': ftst = OP_FTMTIME; break;
4000 case 'A': ftst = OP_FTATIME; break;
4001 case 'C': ftst = OP_FTCTIME; break;
4002 default: break;
4003 }
4004 break;
378cc40b 4005 default:
378cc40b
LW
4006 break;
4007 }
e5edeb50 4008 if (ftst) {
eb160463 4009 PL_last_lop_op = (OPCODE)ftst;
4e553d73 4010 DEBUG_T( { PerlIO_printf(Perl_debug_log,
a18d764d 4011 "### Saw file test %c\n", (int)tmp);
5f80b19c 4012 } );
e5edeb50
JH
4013 FTST(ftst);
4014 }
4015 else {
4016 /* Assume it was a minus followed by a one-letter named
4017 * subroutine call (or a -bareword), then. */
95c31fe3 4018 DEBUG_T( { PerlIO_printf(Perl_debug_log,
17ad61e0 4019 "### '-%c' looked like a file test but was not\n",
4fccd7c6 4020 (int) tmp);
5f80b19c 4021 } );
3cf7b4c4 4022 s = --PL_bufptr;
e5edeb50 4023 }
378cc40b 4024 }
90771dc0
NC
4025 {
4026 const char tmp = *s++;
4027 if (*s == tmp) {
4028 s++;
4029 if (PL_expect == XOPERATOR)
4030 TERM(POSTDEC);
4031 else
4032 OPERATOR(PREDEC);
4033 }
4034 else if (*s == '>') {
4035 s++;
29595ff2 4036 s = SKIPSPACE1(s);
90771dc0
NC
4037 if (isIDFIRST_lazy_if(s,UTF)) {
4038 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
4039 TOKEN(ARROW);
4040 }
4041 else if (*s == '$')
4042 OPERATOR(ARROW);
4043 else
4044 TERM(ARROW);
4045 }
3280af22 4046 if (PL_expect == XOPERATOR)
90771dc0
NC
4047 Aop(OP_SUBTRACT);
4048 else {
4049 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4050 check_uni();
4051 OPERATOR('-'); /* unary minus */
79072805 4052 }
2f3197b3 4053 }
79072805 4054
378cc40b 4055 case '+':
90771dc0
NC
4056 {
4057 const char tmp = *s++;
4058 if (*s == tmp) {
4059 s++;
4060 if (PL_expect == XOPERATOR)
4061 TERM(POSTINC);
4062 else
4063 OPERATOR(PREINC);
4064 }
3280af22 4065 if (PL_expect == XOPERATOR)
90771dc0
NC
4066 Aop(OP_ADD);
4067 else {
4068 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4069 check_uni();
4070 OPERATOR('+');
4071 }
2f3197b3 4072 }
a687059c 4073
378cc40b 4074 case '*':
3280af22
NIS
4075 if (PL_expect != XOPERATOR) {
4076 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4077 PL_expect = XOPERATOR;
4078 force_ident(PL_tokenbuf, '*');
4079 if (!*PL_tokenbuf)
a0d0e21e 4080 PREREF('*');
79072805 4081 TERM('*');
a687059c 4082 }
79072805
LW
4083 s++;
4084 if (*s == '*') {
a687059c 4085 s++;
79072805 4086 PWop(OP_POW);
a687059c 4087 }
79072805
LW
4088 Mop(OP_MULTIPLY);
4089
378cc40b 4090 case '%':
3280af22 4091 if (PL_expect == XOPERATOR) {
bbce6d69 4092 ++s;
4093 Mop(OP_MODULO);
a687059c 4094 }
3280af22
NIS
4095 PL_tokenbuf[0] = '%';
4096 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
4097 if (!PL_tokenbuf[1]) {
bbce6d69 4098 PREREF('%');
a687059c 4099 }
3280af22 4100 PL_pending_ident = '%';
bbce6d69 4101 TERM('%');
a687059c 4102
378cc40b 4103 case '^':
79072805 4104 s++;
a0d0e21e 4105 BOop(OP_BIT_XOR);
79072805 4106 case '[':
3280af22 4107 PL_lex_brackets++;
79072805 4108 /* FALL THROUGH */
378cc40b 4109 case '~':
0d863452
RH
4110 if (s[1] == '~'
4111 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR)
ef89dcc3 4112 && FEATURE_IS_ENABLED("~~"))
0d863452
RH
4113 {
4114 s += 2;
4115 Eop(OP_SMARTMATCH);
4116 }
378cc40b 4117 case ',':
90771dc0
NC
4118 {
4119 const char tmp = *s++;
4120 OPERATOR(tmp);
4121 }
a0d0e21e
LW
4122 case ':':
4123 if (s[1] == ':') {
4124 len = 0;
0bfa2a8a 4125 goto just_a_word_zero_gv;
a0d0e21e
LW
4126 }
4127 s++;
09bef843
SB
4128 switch (PL_expect) {
4129 OP *attrs;
5db06880
NC
4130#ifdef PERL_MAD
4131 I32 stuffstart;
4132#endif
09bef843
SB
4133 case XOPERATOR:
4134 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
4135 break;
4136 PL_bufptr = s; /* update in case we back off */
4137 goto grabattrs;
4138 case XATTRBLOCK:
4139 PL_expect = XBLOCK;
4140 goto grabattrs;
4141 case XATTRTERM:
4142 PL_expect = XTERMBLOCK;
4143 grabattrs:
5db06880
NC
4144#ifdef PERL_MAD
4145 stuffstart = s - SvPVX(PL_linestr) - 1;
4146#endif
29595ff2 4147 s = PEEKSPACE(s);
5f66b61c 4148 attrs = NULL;
7e2040f0 4149 while (isIDFIRST_lazy_if(s,UTF)) {
90771dc0 4150 I32 tmp;
5cc237b8 4151 SV *sv;
09bef843 4152 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5458a98a 4153 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
f9829d6b
GS
4154 if (tmp < 0) tmp = -tmp;
4155 switch (tmp) {
4156 case KEY_or:
4157 case KEY_and:
c963b151 4158 case KEY_err:
f9829d6b
GS
4159 case KEY_for:
4160 case KEY_unless:
4161 case KEY_if:
4162 case KEY_while:
4163 case KEY_until:
4164 goto got_attrs;
4165 default:
4166 break;
4167 }
4168 }
5cc237b8 4169 sv = newSVpvn(s, len);
09bef843
SB
4170 if (*d == '(') {
4171 d = scan_str(d,TRUE,TRUE);
4172 if (!d) {
09bef843
SB
4173 /* MUST advance bufptr here to avoid bogus
4174 "at end of line" context messages from yyerror().
4175 */
4176 PL_bufptr = s + len;
4177 yyerror("Unterminated attribute parameter in attribute list");
4178 if (attrs)
4179 op_free(attrs);
5cc237b8 4180 sv_free(sv);
bbf60fe6 4181 return REPORT(0); /* EOF indicator */
09bef843
SB
4182 }
4183 }
4184 if (PL_lex_stuff) {
09bef843
SB
4185 sv_catsv(sv, PL_lex_stuff);
4186 attrs = append_elem(OP_LIST, attrs,
4187 newSVOP(OP_CONST, 0, sv));
4188 SvREFCNT_dec(PL_lex_stuff);
a0714e2c 4189 PL_lex_stuff = NULL;
09bef843
SB
4190 }
4191 else {
5cc237b8
BS
4192 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4193 sv_free(sv);
1108974d 4194 if (PL_in_my == KEY_our) {
371fce9b
DM
4195#ifdef USE_ITHREADS
4196 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
4197#else
1108974d 4198 /* skip to avoid loading attributes.pm */
371fce9b 4199#endif
df9a6019 4200 deprecate(":unique");
1108974d 4201 }
bfed75c6 4202 else
371fce9b
DM
4203 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4204 }
4205
d3cea301
SB
4206 /* NOTE: any CV attrs applied here need to be part of
4207 the CVf_BUILTIN_ATTRS define in cv.h! */
5cc237b8
BS
4208 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4209 sv_free(sv);
78f9721b 4210 CvLVALUE_on(PL_compcv);
5cc237b8
BS
4211 }
4212 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4213 sv_free(sv);
78f9721b 4214 CvLOCKED_on(PL_compcv);
5cc237b8
BS
4215 }
4216 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4217 sv_free(sv);
78f9721b 4218 CvMETHOD_on(PL_compcv);
5cc237b8
BS
4219 }
4220 else if (!PL_in_my && len == 9 && strnEQ(SvPVX(sv), "assertion", len)) {
4221 sv_free(sv);
06492da6 4222 CvASSERTION_on(PL_compcv);
5cc237b8 4223 }
78f9721b
SM
4224 /* After we've set the flags, it could be argued that
4225 we don't need to do the attributes.pm-based setting
4226 process, and shouldn't bother appending recognized
d3cea301
SB
4227 flags. To experiment with that, uncomment the
4228 following "else". (Note that's already been
4229 uncommented. That keeps the above-applied built-in
4230 attributes from being intercepted (and possibly
4231 rejected) by a package's attribute routines, but is
4232 justified by the performance win for the common case
4233 of applying only built-in attributes.) */
0256094b 4234 else
78f9721b
SM
4235 attrs = append_elem(OP_LIST, attrs,
4236 newSVOP(OP_CONST, 0,
5cc237b8 4237 sv));
09bef843 4238 }
29595ff2 4239 s = PEEKSPACE(d);
0120eecf 4240 if (*s == ':' && s[1] != ':')
29595ff2 4241 s = PEEKSPACE(s+1);
0120eecf
GS
4242 else if (s == d)
4243 break; /* require real whitespace or :'s */
29595ff2 4244 /* XXX losing whitespace on sequential attributes here */
09bef843 4245 }
90771dc0
NC
4246 {
4247 const char tmp
4248 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4249 if (*s != ';' && *s != '}' && *s != tmp
4250 && (tmp != '=' || *s != ')')) {
4251 const char q = ((*s == '\'') ? '"' : '\'');
4252 /* If here for an expression, and parsed no attrs, back
4253 off. */
4254 if (tmp == '=' && !attrs) {
4255 s = PL_bufptr;
4256 break;
4257 }
4258 /* MUST advance bufptr here to avoid bogus "at end of line"
4259 context messages from yyerror().
4260 */
4261 PL_bufptr = s;
10edeb5d
JH
4262 yyerror( (const char *)
4263 (*s
4264 ? Perl_form(aTHX_ "Invalid separator character "
4265 "%c%c%c in attribute list", q, *s, q)
4266 : "Unterminated attribute list" ) );
90771dc0
NC
4267 if (attrs)
4268 op_free(attrs);
4269 OPERATOR(':');
09bef843 4270 }
09bef843 4271 }
f9829d6b 4272 got_attrs:
09bef843 4273 if (attrs) {
cd81e915 4274 start_force(PL_curforce);
9ded7720 4275 NEXTVAL_NEXTTOKE.opval = attrs;
cd81e915 4276 CURMAD('_', PL_nextwhite);
89122651 4277 force_next(THING);
5db06880
NC
4278 }
4279#ifdef PERL_MAD
4280 if (PL_madskills) {
cd81e915 4281 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
5db06880 4282 (s - SvPVX(PL_linestr)) - stuffstart);
09bef843 4283 }
5db06880 4284#endif
09bef843
SB
4285 TOKEN(COLONATTR);
4286 }
a0d0e21e 4287 OPERATOR(':');
8990e307
LW
4288 case '(':
4289 s++;
3280af22
NIS
4290 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4291 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
a0d0e21e 4292 else
3280af22 4293 PL_expect = XTERM;
29595ff2 4294 s = SKIPSPACE1(s);
a0d0e21e 4295 TOKEN('(');
378cc40b 4296 case ';':
f4dd75d9 4297 CLINE;
90771dc0
NC
4298 {
4299 const char tmp = *s++;
4300 OPERATOR(tmp);
4301 }
378cc40b 4302 case ')':
90771dc0
NC
4303 {
4304 const char tmp = *s++;
29595ff2 4305 s = SKIPSPACE1(s);
90771dc0
NC
4306 if (*s == '{')
4307 PREBLOCK(tmp);
4308 TERM(tmp);
4309 }
79072805
LW
4310 case ']':
4311 s++;
3280af22 4312 if (PL_lex_brackets <= 0)
d98d5fff 4313 yyerror("Unmatched right square bracket");
463ee0b2 4314 else
3280af22
NIS
4315 --PL_lex_brackets;
4316 if (PL_lex_state == LEX_INTERPNORMAL) {
4317 if (PL_lex_brackets == 0) {
a0d0e21e 4318 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
3280af22 4319 PL_lex_state = LEX_INTERPEND;
79072805
LW
4320 }
4321 }
4633a7c4 4322 TERM(']');
79072805
LW
4323 case '{':
4324 leftbracket:
79072805 4325 s++;
3280af22 4326 if (PL_lex_brackets > 100) {
8edd5f42 4327 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
8990e307 4328 }
3280af22 4329 switch (PL_expect) {
a0d0e21e 4330 case XTERM:
3280af22 4331 if (PL_lex_formbrack) {
a0d0e21e
LW
4332 s--;
4333 PRETERMBLOCK(DO);
4334 }
3280af22
NIS
4335 if (PL_oldoldbufptr == PL_last_lop)
4336 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
a0d0e21e 4337 else
3280af22 4338 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
79072805 4339 OPERATOR(HASHBRACK);
a0d0e21e 4340 case XOPERATOR:
bf4acbe4 4341 while (s < PL_bufend && SPACE_OR_TAB(*s))
748a9306 4342 s++;
44a8e56a 4343 d = s;
3280af22
NIS
4344 PL_tokenbuf[0] = '\0';
4345 if (d < PL_bufend && *d == '-') {
4346 PL_tokenbuf[0] = '-';
44a8e56a 4347 d++;
bf4acbe4 4348 while (d < PL_bufend && SPACE_OR_TAB(*d))
44a8e56a 4349 d++;
4350 }
7e2040f0 4351 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
3280af22 4352 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
8903cb82 4353 FALSE, &len);
bf4acbe4 4354 while (d < PL_bufend && SPACE_OR_TAB(*d))
748a9306
LW
4355 d++;
4356 if (*d == '}') {
f54cb97a 4357 const char minus = (PL_tokenbuf[0] == '-');
44a8e56a 4358 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4359 if (minus)
4360 force_next('-');
748a9306
LW
4361 }
4362 }
4363 /* FALL THROUGH */
09bef843 4364 case XATTRBLOCK:
748a9306 4365 case XBLOCK:
3280af22
NIS
4366 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4367 PL_expect = XSTATE;
a0d0e21e 4368 break;
09bef843 4369 case XATTRTERM:
a0d0e21e 4370 case XTERMBLOCK:
3280af22
NIS
4371 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4372 PL_expect = XSTATE;
a0d0e21e
LW
4373 break;
4374 default: {
f54cb97a 4375 const char *t;
3280af22
NIS
4376 if (PL_oldoldbufptr == PL_last_lop)
4377 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
a0d0e21e 4378 else
3280af22 4379 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
29595ff2 4380 s = SKIPSPACE1(s);
8452ff4b
SB
4381 if (*s == '}') {
4382 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4383 PL_expect = XTERM;
4384 /* This hack is to get the ${} in the message. */
4385 PL_bufptr = s+1;
4386 yyerror("syntax error");
4387 break;
4388 }
a0d0e21e 4389 OPERATOR(HASHBRACK);
8452ff4b 4390 }
b8a4b1be
GS
4391 /* This hack serves to disambiguate a pair of curlies
4392 * as being a block or an anon hash. Normally, expectation
4393 * determines that, but in cases where we're not in a
4394 * position to expect anything in particular (like inside
4395 * eval"") we have to resolve the ambiguity. This code
4396 * covers the case where the first term in the curlies is a
4397 * quoted string. Most other cases need to be explicitly
a0288114 4398 * disambiguated by prepending a "+" before the opening
b8a4b1be
GS
4399 * curly in order to force resolution as an anon hash.
4400 *
4401 * XXX should probably propagate the outer expectation
4402 * into eval"" to rely less on this hack, but that could
4403 * potentially break current behavior of eval"".
4404 * GSAR 97-07-21
4405 */
4406 t = s;
4407 if (*s == '\'' || *s == '"' || *s == '`') {
4408 /* common case: get past first string, handling escapes */
3280af22 4409 for (t++; t < PL_bufend && *t != *s;)
b8a4b1be
GS
4410 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4411 t++;
4412 t++;
a0d0e21e 4413 }
b8a4b1be 4414 else if (*s == 'q') {
3280af22 4415 if (++t < PL_bufend
b8a4b1be 4416 && (!isALNUM(*t)
3280af22 4417 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
0505442f
GS
4418 && !isALNUM(*t))))
4419 {
abc667d1 4420 /* skip q//-like construct */
f54cb97a 4421 const char *tmps;
b8a4b1be
GS
4422 char open, close, term;
4423 I32 brackets = 1;
4424
3280af22 4425 while (t < PL_bufend && isSPACE(*t))
b8a4b1be 4426 t++;
abc667d1
DM
4427 /* check for q => */
4428 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4429 OPERATOR(HASHBRACK);
4430 }
b8a4b1be
GS
4431 term = *t;
4432 open = term;
4433 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4434 term = tmps[5];
4435 close = term;
4436 if (open == close)
3280af22
NIS
4437 for (t++; t < PL_bufend; t++) {
4438 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
b8a4b1be 4439 t++;
6d07e5e9 4440 else if (*t == open)
b8a4b1be
GS
4441 break;
4442 }
abc667d1 4443 else {
3280af22
NIS
4444 for (t++; t < PL_bufend; t++) {
4445 if (*t == '\\' && t+1 < PL_bufend)
b8a4b1be 4446 t++;
6d07e5e9 4447 else if (*t == close && --brackets <= 0)
b8a4b1be
GS
4448 break;
4449 else if (*t == open)
4450 brackets++;
4451 }
abc667d1
DM
4452 }
4453 t++;
b8a4b1be 4454 }
abc667d1
DM
4455 else
4456 /* skip plain q word */
4457 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4458 t += UTF8SKIP(t);
a0d0e21e 4459 }
7e2040f0 4460 else if (isALNUM_lazy_if(t,UTF)) {
0505442f 4461 t += UTF8SKIP(t);
7e2040f0 4462 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
0505442f 4463 t += UTF8SKIP(t);
a0d0e21e 4464 }
3280af22 4465 while (t < PL_bufend && isSPACE(*t))
a0d0e21e 4466 t++;
b8a4b1be
GS
4467 /* if comma follows first term, call it an anon hash */
4468 /* XXX it could be a comma expression with loop modifiers */
3280af22 4469 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
b8a4b1be 4470 || (*t == '=' && t[1] == '>')))
a0d0e21e 4471 OPERATOR(HASHBRACK);
3280af22 4472 if (PL_expect == XREF)
4e4e412b 4473 PL_expect = XTERM;
a0d0e21e 4474 else {
3280af22
NIS
4475 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4476 PL_expect = XSTATE;
a0d0e21e 4477 }
8990e307 4478 }
a0d0e21e 4479 break;
463ee0b2 4480 }
57843af0 4481 yylval.ival = CopLINE(PL_curcop);
79072805 4482 if (isSPACE(*s) || *s == '#')
3280af22 4483 PL_copline = NOLINE; /* invalidate current command line number */
79072805 4484 TOKEN('{');
378cc40b 4485 case '}':
79072805
LW
4486 rightbracket:
4487 s++;
3280af22 4488 if (PL_lex_brackets <= 0)
d98d5fff 4489 yyerror("Unmatched right curly bracket");
463ee0b2 4490 else
3280af22 4491 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
c2e66d9e 4492 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
3280af22
NIS
4493 PL_lex_formbrack = 0;
4494 if (PL_lex_state == LEX_INTERPNORMAL) {
4495 if (PL_lex_brackets == 0) {
9059aa12
LW
4496 if (PL_expect & XFAKEBRACK) {
4497 PL_expect &= XENUMMASK;
3280af22
NIS
4498 PL_lex_state = LEX_INTERPEND;
4499 PL_bufptr = s;
5db06880
NC
4500#if 0
4501 if (PL_madskills) {
cd81e915 4502 if (!PL_thiswhite)
6b29d1f5 4503 PL_thiswhite = newSVpvs("");
cd81e915 4504 sv_catpvn(PL_thiswhite,"}",1);
5db06880
NC
4505 }
4506#endif
cea2e8a9 4507 return yylex(); /* ignore fake brackets */
79072805 4508 }
fa83b5b6 4509 if (*s == '-' && s[1] == '>')
3280af22 4510 PL_lex_state = LEX_INTERPENDMAYBE;
fa83b5b6 4511 else if (*s != '[' && *s != '{')
3280af22 4512 PL_lex_state = LEX_INTERPEND;
79072805
LW
4513 }
4514 }
9059aa12
LW
4515 if (PL_expect & XFAKEBRACK) {
4516 PL_expect &= XENUMMASK;
3280af22 4517 PL_bufptr = s;
cea2e8a9 4518 return yylex(); /* ignore fake brackets */
748a9306 4519 }
cd81e915 4520 start_force(PL_curforce);
5db06880
NC
4521 if (PL_madskills) {
4522 curmad('X', newSVpvn(s-1,1));
cd81e915 4523 CURMAD('_', PL_thiswhite);
5db06880 4524 }
79072805 4525 force_next('}');
5db06880 4526#ifdef PERL_MAD
cd81e915 4527 if (!PL_thistoken)
6b29d1f5 4528 PL_thistoken = newSVpvs("");
5db06880 4529#endif
79072805 4530 TOKEN(';');
378cc40b
LW
4531 case '&':
4532 s++;
90771dc0 4533 if (*s++ == '&')
a0d0e21e 4534 AOPERATOR(ANDAND);
378cc40b 4535 s--;
3280af22 4536 if (PL_expect == XOPERATOR) {
041457d9
DM
4537 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4538 && isIDFIRST_lazy_if(s,UTF))
7e2040f0 4539 {
57843af0 4540 CopLINE_dec(PL_curcop);
9014280d 4541 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
57843af0 4542 CopLINE_inc(PL_curcop);
463ee0b2 4543 }
79072805 4544 BAop(OP_BIT_AND);
463ee0b2 4545 }
79072805 4546
3280af22
NIS
4547 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4548 if (*PL_tokenbuf) {
4549 PL_expect = XOPERATOR;
4550 force_ident(PL_tokenbuf, '&');
463ee0b2 4551 }
79072805
LW
4552 else
4553 PREREF('&');
c07a80fd 4554 yylval.ival = (OPpENTERSUB_AMPER<<8);
79072805
LW
4555 TERM('&');
4556
378cc40b
LW
4557 case '|':
4558 s++;
90771dc0 4559 if (*s++ == '|')
a0d0e21e 4560 AOPERATOR(OROR);
378cc40b 4561 s--;
79072805 4562 BOop(OP_BIT_OR);
378cc40b
LW
4563 case '=':
4564 s++;
748a9306 4565 {
90771dc0
NC
4566 const char tmp = *s++;
4567 if (tmp == '=')
4568 Eop(OP_EQ);
4569 if (tmp == '>')
4570 OPERATOR(',');
4571 if (tmp == '~')
4572 PMop(OP_MATCH);
4573 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4574 && strchr("+-*/%.^&|<",tmp))
4575 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4576 "Reversed %c= operator",(int)tmp);
4577 s--;
4578 if (PL_expect == XSTATE && isALPHA(tmp) &&
4579 (s == PL_linestart+1 || s[-2] == '\n') )
4580 {
4581 if (PL_in_eval && !PL_rsfp) {
4582 d = PL_bufend;
4583 while (s < d) {
4584 if (*s++ == '\n') {
4585 incline(s);
4586 if (strnEQ(s,"=cut",4)) {
4587 s = strchr(s,'\n');
4588 if (s)
4589 s++;
4590 else
4591 s = d;
4592 incline(s);
4593 goto retry;
4594 }
4595 }
a5f75d66 4596 }
90771dc0 4597 goto retry;
a5f75d66 4598 }
5db06880
NC
4599#ifdef PERL_MAD
4600 if (PL_madskills) {
cd81e915 4601 if (!PL_thiswhite)
6b29d1f5 4602 PL_thiswhite = newSVpvs("");
cd81e915 4603 sv_catpvn(PL_thiswhite, PL_linestart,
5db06880
NC
4604 PL_bufend - PL_linestart);
4605 }
4606#endif
90771dc0
NC
4607 s = PL_bufend;
4608 PL_doextract = TRUE;
4609 goto retry;
a5f75d66 4610 }
a0d0e21e 4611 }
3280af22 4612 if (PL_lex_brackets < PL_lex_formbrack) {
c35e046a 4613 const char *t = s;
51882d45 4614#ifdef PERL_STRICT_CR
c35e046a 4615 while (SPACE_OR_TAB(*t))
51882d45 4616#else
c35e046a 4617 while (SPACE_OR_TAB(*t) || *t == '\r')
51882d45 4618#endif
c35e046a 4619 t++;
a0d0e21e
LW
4620 if (*t == '\n' || *t == '#') {
4621 s--;
3280af22 4622 PL_expect = XBLOCK;
a0d0e21e
LW
4623 goto leftbracket;
4624 }
79072805 4625 }
a0d0e21e
LW
4626 yylval.ival = 0;
4627 OPERATOR(ASSIGNOP);
378cc40b
LW
4628 case '!':
4629 s++;
90771dc0
NC
4630 {
4631 const char tmp = *s++;
4632 if (tmp == '=') {
4633 /* was this !=~ where !~ was meant?
4634 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4635
4636 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4637 const char *t = s+1;
4638
4639 while (t < PL_bufend && isSPACE(*t))
4640 ++t;
4641
4642 if (*t == '/' || *t == '?' ||
4643 ((*t == 'm' || *t == 's' || *t == 'y')
4644 && !isALNUM(t[1])) ||
4645 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4646 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4647 "!=~ should be !~");
4648 }
4649 Eop(OP_NE);
4650 }
4651 if (tmp == '~')
4652 PMop(OP_NOT);
4653 }
378cc40b
LW
4654 s--;
4655 OPERATOR('!');
4656 case '<':
3280af22 4657 if (PL_expect != XOPERATOR) {
93a17b20 4658 if (s[1] != '<' && !strchr(s,'>'))
2f3197b3 4659 check_uni();
79072805
LW
4660 if (s[1] == '<')
4661 s = scan_heredoc(s);
4662 else
4663 s = scan_inputsymbol(s);
4664 TERM(sublex_start());
378cc40b
LW
4665 }
4666 s++;
90771dc0
NC
4667 {
4668 char tmp = *s++;
4669 if (tmp == '<')
4670 SHop(OP_LEFT_SHIFT);
4671 if (tmp == '=') {
4672 tmp = *s++;
4673 if (tmp == '>')
4674 Eop(OP_NCMP);
4675 s--;
4676 Rop(OP_LE);
4677 }
395c3793 4678 }
378cc40b 4679 s--;
79072805 4680 Rop(OP_LT);
378cc40b
LW
4681 case '>':
4682 s++;
90771dc0
NC
4683 {
4684 const char tmp = *s++;
4685 if (tmp == '>')
4686 SHop(OP_RIGHT_SHIFT);
d4c19fe8 4687 else if (tmp == '=')
90771dc0
NC
4688 Rop(OP_GE);
4689 }
378cc40b 4690 s--;
79072805 4691 Rop(OP_GT);
378cc40b
LW
4692
4693 case '$':
bbce6d69 4694 CLINE;
4695
3280af22
NIS
4696 if (PL_expect == XOPERATOR) {
4697 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4698 PL_expect = XTERM;
c445ea15 4699 deprecate_old(commaless_variable_list);
bbf60fe6 4700 return REPORT(','); /* grandfather non-comma-format format */
a0d0e21e 4701 }
8990e307 4702 }
a0d0e21e 4703
7e2040f0 4704 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
3280af22 4705 PL_tokenbuf[0] = '@';
376b8730
SM
4706 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4707 sizeof PL_tokenbuf - 1, FALSE);
4708 if (PL_expect == XOPERATOR)
4709 no_op("Array length", s);
3280af22 4710 if (!PL_tokenbuf[1])
a0d0e21e 4711 PREREF(DOLSHARP);
3280af22
NIS
4712 PL_expect = XOPERATOR;
4713 PL_pending_ident = '#';
463ee0b2 4714 TOKEN(DOLSHARP);
79072805 4715 }
bbce6d69 4716
3280af22 4717 PL_tokenbuf[0] = '$';
376b8730
SM
4718 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4719 sizeof PL_tokenbuf - 1, FALSE);
4720 if (PL_expect == XOPERATOR)
4721 no_op("Scalar", s);
3280af22
NIS
4722 if (!PL_tokenbuf[1]) {
4723 if (s == PL_bufend)
bbce6d69 4724 yyerror("Final $ should be \\$ or $name");
4725 PREREF('$');
8990e307 4726 }
a0d0e21e 4727
bbce6d69 4728 /* This kludge not intended to be bulletproof. */
3280af22 4729 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
bbce6d69 4730 yylval.opval = newSVOP(OP_CONST, 0,
fc15ae8f 4731 newSViv(CopARYBASE_get(&PL_compiling)));
bbce6d69 4732 yylval.opval->op_private = OPpCONST_ARYBASE;
4733 TERM(THING);
4734 }
4735
ff68c719 4736 d = s;
90771dc0
NC
4737 {
4738 const char tmp = *s;
4739 if (PL_lex_state == LEX_NORMAL)
29595ff2 4740 s = SKIPSPACE1(s);
ff68c719 4741
90771dc0
NC
4742 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4743 && intuit_more(s)) {
4744 if (*s == '[') {
4745 PL_tokenbuf[0] = '@';
4746 if (ckWARN(WARN_SYNTAX)) {
c35e046a
AL
4747 char *t = s+1;
4748
4749 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4750 t++;
90771dc0 4751 if (*t++ == ',') {
29595ff2 4752 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
90771dc0
NC
4753 while (t < PL_bufend && *t != ']')
4754 t++;
9014280d 4755 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
90771dc0 4756 "Multidimensional syntax %.*s not supported",
36c7798d 4757 (int)((t - PL_bufptr) + 1), PL_bufptr);
90771dc0 4758 }
748a9306 4759 }
93a17b20 4760 }
90771dc0
NC
4761 else if (*s == '{') {
4762 char *t;
4763 PL_tokenbuf[0] = '%';
4764 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4765 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4766 {
4767 char tmpbuf[sizeof PL_tokenbuf];
c35e046a
AL
4768 do {
4769 t++;
4770 } while (isSPACE(*t));
90771dc0 4771 if (isIDFIRST_lazy_if(t,UTF)) {
5f66b61c 4772 STRLEN dummylen;
90771dc0 4773 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
5f66b61c 4774 &dummylen);
c35e046a
AL
4775 while (isSPACE(*t))
4776 t++;
90771dc0
NC
4777 if (*t == ';' && get_cv(tmpbuf, FALSE))
4778 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4779 "You need to quote \"%s\"",
4780 tmpbuf);
4781 }
4782 }
4783 }
93a17b20 4784 }
bbce6d69 4785
90771dc0
NC
4786 PL_expect = XOPERATOR;
4787 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4788 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4789 if (!islop || PL_last_lop_op == OP_GREPSTART)
4790 PL_expect = XOPERATOR;
4791 else if (strchr("$@\"'`q", *s))
4792 PL_expect = XTERM; /* e.g. print $fh "foo" */
4793 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4794 PL_expect = XTERM; /* e.g. print $fh &sub */
4795 else if (isIDFIRST_lazy_if(s,UTF)) {
4796 char tmpbuf[sizeof PL_tokenbuf];
4797 int t2;
4798 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5458a98a 4799 if ((t2 = keyword(tmpbuf, len, 0))) {
90771dc0
NC
4800 /* binary operators exclude handle interpretations */
4801 switch (t2) {
4802 case -KEY_x:
4803 case -KEY_eq:
4804 case -KEY_ne:
4805 case -KEY_gt:
4806 case -KEY_lt:
4807 case -KEY_ge:
4808 case -KEY_le:
4809 case -KEY_cmp:
4810 break;
4811 default:
4812 PL_expect = XTERM; /* e.g. print $fh length() */
4813 break;
4814 }
4815 }
4816 else {
4817 PL_expect = XTERM; /* e.g. print $fh subr() */
84902520
TB
4818 }
4819 }
90771dc0
NC
4820 else if (isDIGIT(*s))
4821 PL_expect = XTERM; /* e.g. print $fh 3 */
4822 else if (*s == '.' && isDIGIT(s[1]))
4823 PL_expect = XTERM; /* e.g. print $fh .3 */
4824 else if ((*s == '?' || *s == '-' || *s == '+')
4825 && !isSPACE(s[1]) && s[1] != '=')
4826 PL_expect = XTERM; /* e.g. print $fh -1 */
4827 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4828 && s[1] != '/')
4829 PL_expect = XTERM; /* e.g. print $fh /.../
4830 XXX except DORDOR operator
4831 */
4832 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4833 && s[2] != '=')
4834 PL_expect = XTERM; /* print $fh <<"EOF" */
93a17b20 4835 }
bbce6d69 4836 }
3280af22 4837 PL_pending_ident = '$';
79072805 4838 TOKEN('$');
378cc40b
LW
4839
4840 case '@':
3280af22 4841 if (PL_expect == XOPERATOR)
bbce6d69 4842 no_op("Array", s);
3280af22
NIS
4843 PL_tokenbuf[0] = '@';
4844 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
4845 if (!PL_tokenbuf[1]) {
bbce6d69 4846 PREREF('@');
4847 }
3280af22 4848 if (PL_lex_state == LEX_NORMAL)
29595ff2 4849 s = SKIPSPACE1(s);
3280af22 4850 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
bbce6d69 4851 if (*s == '{')
3280af22 4852 PL_tokenbuf[0] = '%';
a0d0e21e
LW
4853
4854 /* Warn about @ where they meant $. */
041457d9
DM
4855 if (*s == '[' || *s == '{') {
4856 if (ckWARN(WARN_SYNTAX)) {
f54cb97a 4857 const char *t = s + 1;
7e2040f0 4858 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
a0d0e21e
LW
4859 t++;
4860 if (*t == '}' || *t == ']') {
4861 t++;
29595ff2 4862 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
9014280d 4863 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
599cee73 4864 "Scalar value %.*s better written as $%.*s",
36c7798d
DM
4865 (int)(t-PL_bufptr), PL_bufptr,
4866 (int)(t-PL_bufptr-1), PL_bufptr+1);
a0d0e21e 4867 }
93a17b20
LW
4868 }
4869 }
463ee0b2 4870 }
3280af22 4871 PL_pending_ident = '@';
79072805 4872 TERM('@');
378cc40b 4873
c963b151 4874 case '/': /* may be division, defined-or, or pattern */
6f33ba73
RGS
4875 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
4876 s += 2;
4877 AOPERATOR(DORDOR);
4878 }
c963b151
BD
4879 case '?': /* may either be conditional or pattern */
4880 if(PL_expect == XOPERATOR) {
90771dc0 4881 char tmp = *s++;
c963b151
BD
4882 if(tmp == '?') {
4883 OPERATOR('?');
4884 }
4885 else {
4886 tmp = *s++;
4887 if(tmp == '/') {
4888 /* A // operator. */
4889 AOPERATOR(DORDOR);
4890 }
4891 else {
4892 s--;
4893 Mop(OP_DIVIDE);
4894 }
4895 }
4896 }
4897 else {
4898 /* Disable warning on "study /blah/" */
4899 if (PL_oldoldbufptr == PL_last_uni
4900 && (*PL_last_uni != 's' || s - PL_last_uni < 5
4901 || memNE(PL_last_uni, "study", 5)
4902 || isALNUM_lazy_if(PL_last_uni+5,UTF)
4903 ))
4904 check_uni();
4905 s = scan_pat(s,OP_MATCH);
4906 TERM(sublex_start());
4907 }
378cc40b
LW
4908
4909 case '.':
51882d45
GS
4910 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
4911#ifdef PERL_STRICT_CR
4912 && s[1] == '\n'
4913#else
4914 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
4915#endif
4916 && (s == PL_linestart || s[-1] == '\n') )
4917 {
3280af22
NIS
4918 PL_lex_formbrack = 0;
4919 PL_expect = XSTATE;
79072805
LW
4920 goto rightbracket;
4921 }
3280af22 4922 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
90771dc0 4923 char tmp = *s++;
a687059c
LW
4924 if (*s == tmp) {
4925 s++;
2f3197b3
LW
4926 if (*s == tmp) {
4927 s++;
79072805 4928 yylval.ival = OPf_SPECIAL;
2f3197b3
LW
4929 }
4930 else
79072805 4931 yylval.ival = 0;
378cc40b 4932 OPERATOR(DOTDOT);
a687059c 4933 }
3280af22 4934 if (PL_expect != XOPERATOR)
2f3197b3 4935 check_uni();
79072805 4936 Aop(OP_CONCAT);
378cc40b
LW
4937 }
4938 /* FALL THROUGH */
4939 case '0': case '1': case '2': case '3': case '4':
4940 case '5': case '6': case '7': case '8': case '9':
b73d6f50 4941 s = scan_num(s, &yylval);
931e0695 4942 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
3280af22 4943 if (PL_expect == XOPERATOR)
8990e307 4944 no_op("Number",s);
79072805
LW
4945 TERM(THING);
4946
4947 case '\'':
5db06880 4948 s = scan_str(s,!!PL_madskills,FALSE);
931e0695 4949 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
3280af22
NIS
4950 if (PL_expect == XOPERATOR) {
4951 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4952 PL_expect = XTERM;
c445ea15 4953 deprecate_old(commaless_variable_list);
bbf60fe6 4954 return REPORT(','); /* grandfather non-comma-format format */
a0d0e21e 4955 }
463ee0b2 4956 else
8990e307 4957 no_op("String",s);
463ee0b2 4958 }
79072805 4959 if (!s)
d4c19fe8 4960 missingterm(NULL);
79072805
LW
4961 yylval.ival = OP_CONST;
4962 TERM(sublex_start());
4963
4964 case '"':
5db06880 4965 s = scan_str(s,!!PL_madskills,FALSE);
931e0695 4966 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
3280af22
NIS
4967 if (PL_expect == XOPERATOR) {
4968 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4969 PL_expect = XTERM;
c445ea15 4970 deprecate_old(commaless_variable_list);
bbf60fe6 4971 return REPORT(','); /* grandfather non-comma-format format */
a0d0e21e 4972 }
463ee0b2 4973 else
8990e307 4974 no_op("String",s);
463ee0b2 4975 }
79072805 4976 if (!s)
d4c19fe8 4977 missingterm(NULL);
4633a7c4 4978 yylval.ival = OP_CONST;
cfd0369c
NC
4979 /* FIXME. I think that this can be const if char *d is replaced by
4980 more localised variables. */
3280af22 4981 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
63cd0674 4982 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
4633a7c4
LW
4983 yylval.ival = OP_STRINGIFY;
4984 break;
4985 }
4986 }
79072805
LW
4987 TERM(sublex_start());
4988
4989 case '`':
5db06880 4990 s = scan_str(s,!!PL_madskills,FALSE);
931e0695 4991 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
3280af22 4992 if (PL_expect == XOPERATOR)
8990e307 4993 no_op("Backticks",s);
79072805 4994 if (!s)
d4c19fe8 4995 missingterm(NULL);
9b201d7d 4996 readpipe_override();
79072805
LW
4997 TERM(sublex_start());
4998
4999 case '\\':
5000 s++;
041457d9 5001 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
9014280d 5002 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
599cee73 5003 *s, *s);
3280af22 5004 if (PL_expect == XOPERATOR)
8990e307 5005 no_op("Backslash",s);
79072805
LW
5006 OPERATOR(REFGEN);
5007
a7cb1f99 5008 case 'v':
e526c9e6 5009 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
f54cb97a 5010 char *start = s + 2;
dd629d5b 5011 while (isDIGIT(*start) || *start == '_')
a7cb1f99
GS
5012 start++;
5013 if (*start == '.' && isDIGIT(start[1])) {
b73d6f50 5014 s = scan_num(s, &yylval);
a7cb1f99
GS
5015 TERM(THING);
5016 }
e526c9e6 5017 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
6f33ba73
RGS
5018 else if (!isALPHA(*start) && (PL_expect == XTERM
5019 || PL_expect == XREF || PL_expect == XSTATE
5020 || PL_expect == XTERMORDORDOR)) {
d4c19fe8 5021 /* XXX Use gv_fetchpvn rather than stomping on a const string */
f54cb97a 5022 const char c = *start;
e526c9e6
GS
5023 GV *gv;
5024 *start = '\0';
f776e3cd 5025 gv = gv_fetchpv(s, 0, SVt_PVCV);
e526c9e6
GS
5026 *start = c;
5027 if (!gv) {
b73d6f50 5028 s = scan_num(s, &yylval);
e526c9e6
GS
5029 TERM(THING);
5030 }
5031 }
a7cb1f99
GS
5032 }
5033 goto keylookup;
79072805 5034 case 'x':
3280af22 5035 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
79072805
LW
5036 s++;
5037 Mop(OP_REPEAT);
2f3197b3 5038 }
79072805
LW
5039 goto keylookup;
5040
378cc40b 5041 case '_':
79072805
LW
5042 case 'a': case 'A':
5043 case 'b': case 'B':
5044 case 'c': case 'C':
5045 case 'd': case 'D':
5046 case 'e': case 'E':
5047 case 'f': case 'F':
5048 case 'g': case 'G':
5049 case 'h': case 'H':
5050 case 'i': case 'I':
5051 case 'j': case 'J':
5052 case 'k': case 'K':
5053 case 'l': case 'L':
5054 case 'm': case 'M':
5055 case 'n': case 'N':
5056 case 'o': case 'O':
5057 case 'p': case 'P':
5058 case 'q': case 'Q':
5059 case 'r': case 'R':
5060 case 's': case 'S':
5061 case 't': case 'T':
5062 case 'u': case 'U':
a7cb1f99 5063 case 'V':
79072805
LW
5064 case 'w': case 'W':
5065 case 'X':
5066 case 'y': case 'Y':
5067 case 'z': case 'Z':
5068
49dc05e3 5069 keylookup: {
90771dc0 5070 I32 tmp;
10edeb5d
JH
5071
5072 orig_keyword = 0;
5073 gv = NULL;
5074 gvp = NULL;
49dc05e3 5075
3280af22
NIS
5076 PL_bufptr = s;
5077 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
8ebc5c01 5078
5079 /* Some keywords can be followed by any delimiter, including ':' */
155aba94
GS
5080 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
5081 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
5082 (PL_tokenbuf[0] == 'q' &&
5083 strchr("qwxr", PL_tokenbuf[1])))));
8ebc5c01 5084
5085 /* x::* is just a word, unless x is "CORE" */
3280af22 5086 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
4633a7c4
LW
5087 goto just_a_word;
5088
3643fb5f 5089 d = s;
3280af22 5090 while (d < PL_bufend && isSPACE(*d))
3643fb5f
CS
5091 d++; /* no comments skipped here, or s### is misparsed */
5092
5093 /* Is this a label? */
3280af22
NIS
5094 if (!tmp && PL_expect == XSTATE
5095 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
8ebc5c01 5096 s = d + 1;
3280af22 5097 yylval.pval = savepv(PL_tokenbuf);
8ebc5c01 5098 CLINE;
5099 TOKEN(LABEL);
3643fb5f
CS
5100 }
5101
5102 /* Check for keywords */
5458a98a 5103 tmp = keyword(PL_tokenbuf, len, 0);
748a9306
LW
5104
5105 /* Is this a word before a => operator? */
1c3923b3 5106 if (*d == '=' && d[1] == '>') {
748a9306 5107 CLINE;
d0a148a6
NC
5108 yylval.opval
5109 = (OP*)newSVOP(OP_CONST, 0,
5110 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
748a9306
LW
5111 yylval.opval->op_private = OPpCONST_BARE;
5112 TERM(WORD);
5113 }
5114
a0d0e21e 5115 if (tmp < 0) { /* second-class keyword? */
cbbf8932
AL
5116 GV *ogv = NULL; /* override (winner) */
5117 GV *hgv = NULL; /* hidden (loser) */
3280af22 5118 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
56f7f34b 5119 CV *cv;
90e5519e 5120 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
56f7f34b
CS
5121 (cv = GvCVu(gv)))
5122 {
5123 if (GvIMPORTED_CV(gv))
5124 ogv = gv;
5125 else if (! CvMETHOD(cv))
5126 hgv = gv;
5127 }
5128 if (!ogv &&
3280af22
NIS
5129 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
5130 (gv = *gvp) != (GV*)&PL_sv_undef &&
56f7f34b
CS
5131 GvCVu(gv) && GvIMPORTED_CV(gv))
5132 {
5133 ogv = gv;
5134 }
5135 }
5136 if (ogv) {
30fe34ed 5137 orig_keyword = tmp;
56f7f34b 5138 tmp = 0; /* overridden by import or by GLOBAL */
6e7b2336
GS
5139 }
5140 else if (gv && !gvp
5141 && -tmp==KEY_lock /* XXX generalizable kludge */
d0456cad 5142 && GvCVu(gv)
017a3ce5 5143 && !hv_fetchs(GvHVn(PL_incgv), "Thread.pm", FALSE))
6e7b2336
GS
5144 {
5145 tmp = 0; /* any sub overrides "weak" keyword */
a0d0e21e 5146 }
56f7f34b
CS
5147 else { /* no override */
5148 tmp = -tmp;
ac206dc8 5149 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
9014280d 5150 Perl_warner(aTHX_ packWARN(WARN_MISC),
ac206dc8
RGS
5151 "dump() better written as CORE::dump()");
5152 }
a0714e2c 5153 gv = NULL;
56f7f34b 5154 gvp = 0;
041457d9
DM
5155 if (hgv && tmp != KEY_x && tmp != KEY_CORE
5156 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
9014280d 5157 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
599cee73 5158 "Ambiguous call resolved as CORE::%s(), %s",
2f3ca594 5159 GvENAME(hgv), "qualify as such or use &");
49dc05e3 5160 }
a0d0e21e
LW
5161 }
5162
5163 reserved_word:
5164 switch (tmp) {
79072805
LW
5165
5166 default: /* not a keyword */
0bfa2a8a
NC
5167 /* Trade off - by using this evil construction we can pull the
5168 variable gv into the block labelled keylookup. If not, then
5169 we have to give it function scope so that the goto from the
5170 earlier ':' case doesn't bypass the initialisation. */
5171 if (0) {
5172 just_a_word_zero_gv:
5173 gv = NULL;
5174 gvp = NULL;
8bee0991 5175 orig_keyword = 0;
0bfa2a8a 5176 }
93a17b20 5177 just_a_word: {
96e4d5b1 5178 SV *sv;
ce29ac45 5179 int pkgname = 0;
f54cb97a 5180 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5069cc75 5181 CV *cv;
5db06880 5182#ifdef PERL_MAD
cd81e915 5183 SV *nextPL_nextwhite = 0;
5db06880
NC
5184#endif
5185
8990e307
LW
5186
5187 /* Get the rest if it looks like a package qualifier */
5188
155aba94 5189 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
c3e0f903 5190 STRLEN morelen;
3280af22 5191 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
c3e0f903
GS
5192 TRUE, &morelen);
5193 if (!morelen)
cea2e8a9 5194 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
ec2ab091 5195 *s == '\'' ? "'" : "::");
c3e0f903 5196 len += morelen;
ce29ac45 5197 pkgname = 1;
a0d0e21e 5198 }
8990e307 5199
3280af22
NIS
5200 if (PL_expect == XOPERATOR) {
5201 if (PL_bufptr == PL_linestart) {
57843af0 5202 CopLINE_dec(PL_curcop);
9014280d 5203 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
57843af0 5204 CopLINE_inc(PL_curcop);
463ee0b2
LW
5205 }
5206 else
54310121 5207 no_op("Bareword",s);
463ee0b2 5208 }
8990e307 5209
c3e0f903
GS
5210 /* Look for a subroutine with this name in current package,
5211 unless name is "Foo::", in which case Foo is a bearword
5212 (and a package name). */
5213
5db06880 5214 if (len > 2 && !PL_madskills &&
3280af22 5215 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
c3e0f903 5216 {
f776e3cd 5217 if (ckWARN(WARN_BAREWORD)
90e5519e 5218 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
9014280d 5219 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
599cee73 5220 "Bareword \"%s\" refers to nonexistent package",
3280af22 5221 PL_tokenbuf);
c3e0f903 5222 len -= 2;
3280af22 5223 PL_tokenbuf[len] = '\0';
a0714e2c 5224 gv = NULL;
c3e0f903
GS
5225 gvp = 0;
5226 }
5227 else {
62d55b22
NC
5228 if (!gv) {
5229 /* Mustn't actually add anything to a symbol table.
5230 But also don't want to "initialise" any placeholder
5231 constants that might already be there into full
5232 blown PVGVs with attached PVCV. */
90e5519e
NC
5233 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5234 GV_NOADD_NOINIT, SVt_PVCV);
62d55b22 5235 }
b3d904f3 5236 len = 0;
c3e0f903
GS
5237 }
5238
5239 /* if we saw a global override before, get the right name */
8990e307 5240
49dc05e3 5241 if (gvp) {
396482e1 5242 sv = newSVpvs("CORE::GLOBAL::");
3280af22 5243 sv_catpv(sv,PL_tokenbuf);
49dc05e3 5244 }
8a7a129d
NC
5245 else {
5246 /* If len is 0, newSVpv does strlen(), which is correct.
5247 If len is non-zero, then it will be the true length,
5248 and so the scalar will be created correctly. */
5249 sv = newSVpv(PL_tokenbuf,len);
5250 }
5db06880 5251#ifdef PERL_MAD
cd81e915
NC
5252 if (PL_madskills && !PL_thistoken) {
5253 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5254 PL_thistoken = newSVpv(start,s - start);
5255 PL_realtokenstart = s - SvPVX(PL_linestr);
5db06880
NC
5256 }
5257#endif
8990e307 5258
a0d0e21e
LW
5259 /* Presume this is going to be a bareword of some sort. */
5260
5261 CLINE;
49dc05e3 5262 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
a0d0e21e 5263 yylval.opval->op_private = OPpCONST_BARE;
8f8cf39c
JH
5264 /* UTF-8 package name? */
5265 if (UTF && !IN_BYTES &&
95a20fc0 5266 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
8f8cf39c 5267 SvUTF8_on(sv);
a0d0e21e 5268
c3e0f903
GS
5269 /* And if "Foo::", then that's what it certainly is. */
5270
5271 if (len)
5272 goto safe_bareword;
5273
5069cc75
NC
5274 /* Do the explicit type check so that we don't need to force
5275 the initialisation of the symbol table to have a real GV.
5276 Beware - gv may not really be a PVGV, cv may not really be
5277 a PVCV, (because of the space optimisations that gv_init
5278 understands) But they're true if for this symbol there is
5279 respectively a typeglob and a subroutine.
5280 */
5281 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5282 /* Real typeglob, so get the real subroutine: */
5283 ? GvCVu(gv)
5284 /* A proxy for a subroutine in this package? */
5285 : SvOK(gv) ? (CV *) gv : NULL)
5286 : NULL;
5287
8990e307
LW
5288 /* See if it's the indirect object for a list operator. */
5289
3280af22
NIS
5290 if (PL_oldoldbufptr &&
5291 PL_oldoldbufptr < PL_bufptr &&
65cec589
GS
5292 (PL_oldoldbufptr == PL_last_lop
5293 || PL_oldoldbufptr == PL_last_uni) &&
a0d0e21e 5294 /* NO SKIPSPACE BEFORE HERE! */
a9ef352a
GS
5295 (PL_expect == XREF ||
5296 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
a0d0e21e 5297 {
748a9306
LW
5298 bool immediate_paren = *s == '(';
5299
a0d0e21e 5300 /* (Now we can afford to cross potential line boundary.) */
cd81e915 5301 s = SKIPSPACE2(s,nextPL_nextwhite);
5db06880 5302#ifdef PERL_MAD
cd81e915 5303 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5db06880 5304#endif
a0d0e21e
LW
5305
5306 /* Two barewords in a row may indicate method call. */
5307
62d55b22
NC
5308 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5309 (tmp = intuit_method(s, gv, cv)))
bbf60fe6 5310 return REPORT(tmp);
a0d0e21e
LW
5311
5312 /* If not a declared subroutine, it's an indirect object. */
5313 /* (But it's an indir obj regardless for sort.) */
7294df96 5314 /* Also, if "_" follows a filetest operator, it's a bareword */
a0d0e21e 5315
7294df96
RGS
5316 if (
5317 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5069cc75 5318 ((!gv || !cv) &&
a9ef352a 5319 (PL_last_lop_op != OP_MAPSTART &&
f0670693 5320 PL_last_lop_op != OP_GREPSTART))))
7294df96
RGS
5321 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5322 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5323 )
a9ef352a 5324 {
3280af22 5325 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
748a9306 5326 goto bareword;
93a17b20
LW
5327 }
5328 }
8990e307 5329
3280af22 5330 PL_expect = XOPERATOR;
5db06880
NC
5331#ifdef PERL_MAD
5332 if (isSPACE(*s))
cd81e915
NC
5333 s = SKIPSPACE2(s,nextPL_nextwhite);
5334 PL_nextwhite = nextPL_nextwhite;
5db06880 5335#else
8990e307 5336 s = skipspace(s);
5db06880 5337#endif
1c3923b3
GS
5338
5339 /* Is this a word before a => operator? */
ce29ac45 5340 if (*s == '=' && s[1] == '>' && !pkgname) {
1c3923b3
GS
5341 CLINE;
5342 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
0064a8a9 5343 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
7948272d 5344 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
1c3923b3
GS
5345 TERM(WORD);
5346 }
5347
5348 /* If followed by a paren, it's certainly a subroutine. */
93a17b20 5349 if (*s == '(') {
79072805 5350 CLINE;
5069cc75 5351 if (cv) {
c35e046a
AL
5352 d = s + 1;
5353 while (SPACE_OR_TAB(*d))
5354 d++;
62d55b22 5355 if (*d == ')' && (sv = gv_const_sv(gv))) {
96e4d5b1 5356 s = d + 1;
5db06880
NC
5357#ifdef PERL_MAD
5358 if (PL_madskills) {
cd81e915
NC
5359 char *par = SvPVX(PL_linestr) + PL_realtokenstart;
5360 sv_catpvn(PL_thistoken, par, s - par);
5361 if (PL_nextwhite) {
5362 sv_free(PL_nextwhite);
5363 PL_nextwhite = 0;
5db06880
NC
5364 }
5365 }
5366#endif
96e4d5b1 5367 goto its_constant;
5368 }
5369 }
5db06880
NC
5370#ifdef PERL_MAD
5371 if (PL_madskills) {
cd81e915
NC
5372 PL_nextwhite = PL_thiswhite;
5373 PL_thiswhite = 0;
5db06880 5374 }
cd81e915 5375 start_force(PL_curforce);
5db06880 5376#endif
9ded7720 5377 NEXTVAL_NEXTTOKE.opval = yylval.opval;
3280af22 5378 PL_expect = XOPERATOR;
5db06880
NC
5379#ifdef PERL_MAD
5380 if (PL_madskills) {
cd81e915
NC
5381 PL_nextwhite = nextPL_nextwhite;
5382 curmad('X', PL_thistoken);
6b29d1f5 5383 PL_thistoken = newSVpvs("");
5db06880
NC
5384 }
5385#endif
93a17b20 5386 force_next(WORD);
c07a80fd 5387 yylval.ival = 0;
463ee0b2 5388 TOKEN('&');
79072805 5389 }
93a17b20 5390
a0d0e21e 5391 /* If followed by var or block, call it a method (unless sub) */
8990e307 5392
62d55b22 5393 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
3280af22
NIS
5394 PL_last_lop = PL_oldbufptr;
5395 PL_last_lop_op = OP_METHOD;
93a17b20 5396 PREBLOCK(METHOD);
463ee0b2
LW
5397 }
5398
8990e307
LW
5399 /* If followed by a bareword, see if it looks like indir obj. */
5400
30fe34ed
RGS
5401 if (!orig_keyword
5402 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
62d55b22 5403 && (tmp = intuit_method(s, gv, cv)))
bbf60fe6 5404 return REPORT(tmp);
93a17b20 5405
8990e307
LW
5406 /* Not a method, so call it a subroutine (if defined) */
5407
5069cc75 5408 if (cv) {
0453d815 5409 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
9014280d 5410 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
0453d815 5411 "Ambiguous use of -%s resolved as -&%s()",
3280af22 5412 PL_tokenbuf, PL_tokenbuf);
89bfa8cd 5413 /* Check for a constant sub */
62d55b22 5414 if ((sv = gv_const_sv(gv))) {
96e4d5b1 5415 its_constant:
5416 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
b37c2d43 5417 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
96e4d5b1 5418 yylval.opval->op_private = 0;
5419 TOKEN(WORD);
89bfa8cd 5420 }
5421
a5f75d66 5422 /* Resolve to GV now. */
62d55b22 5423 if (SvTYPE(gv) != SVt_PVGV) {
b3d904f3 5424 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
62d55b22
NC
5425 assert (SvTYPE(gv) == SVt_PVGV);
5426 /* cv must have been some sort of placeholder, so
5427 now needs replacing with a real code reference. */
5428 cv = GvCV(gv);
5429 }
5430
a5f75d66
AD
5431 op_free(yylval.opval);
5432 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
9675f7ac 5433 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
7a52d87a 5434 PL_last_lop = PL_oldbufptr;
bf848113 5435 PL_last_lop_op = OP_ENTERSUB;
4633a7c4 5436 /* Is there a prototype? */
5db06880
NC
5437 if (
5438#ifdef PERL_MAD
5439 cv &&
5440#endif
d9f2850e
RGS
5441 SvPOK(cv))
5442 {
5f66b61c
AL
5443 STRLEN protolen;
5444 const char *proto = SvPV_const((SV*)cv, protolen);
5445 if (!protolen)
4633a7c4 5446 TERM(FUNC0SUB);
8c28b960 5447 if ((*proto == '$' || *proto == '_') && proto[1] == '\0')
4633a7c4 5448 OPERATOR(UNIOPSUB);
0f5d0394
AE
5449 while (*proto == ';')
5450 proto++;
7a52d87a 5451 if (*proto == '&' && *s == '{') {
10edeb5d
JH
5452 sv_setpv(PL_subname,
5453 (const char *)
5454 (PL_curstash ?
5455 "__ANON__" : "__ANON__::__ANON__"));
4633a7c4
LW
5456 PREBLOCK(LSTOPSUB);
5457 }
a9ef352a 5458 }
5db06880
NC
5459#ifdef PERL_MAD
5460 {
5461 if (PL_madskills) {
cd81e915
NC
5462 PL_nextwhite = PL_thiswhite;
5463 PL_thiswhite = 0;
5db06880 5464 }
cd81e915 5465 start_force(PL_curforce);
5db06880
NC
5466 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5467 PL_expect = XTERM;
5468 if (PL_madskills) {
cd81e915
NC
5469 PL_nextwhite = nextPL_nextwhite;
5470 curmad('X', PL_thistoken);
6b29d1f5 5471 PL_thistoken = newSVpvs("");
5db06880
NC
5472 }
5473 force_next(WORD);
5474 TOKEN(NOAMP);
5475 }
5476 }
5477
5478 /* Guess harder when madskills require "best effort". */
5479 if (PL_madskills && (!gv || !GvCVu(gv))) {
5480 int probable_sub = 0;
5481 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5482 probable_sub = 1;
5483 else if (isALPHA(*s)) {
5484 char tmpbuf[1024];
5485 STRLEN tmplen;
5486 d = s;
5487 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5458a98a 5488 if (!keyword(tmpbuf, tmplen, 0))
5db06880
NC
5489 probable_sub = 1;
5490 else {
5491 while (d < PL_bufend && isSPACE(*d))
5492 d++;
5493 if (*d == '=' && d[1] == '>')
5494 probable_sub = 1;
5495 }
5496 }
5497 if (probable_sub) {
5498 gv = gv_fetchpv(PL_tokenbuf, TRUE, SVt_PVCV);
5499 op_free(yylval.opval);
5500 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5501 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5502 PL_last_lop = PL_oldbufptr;
5503 PL_last_lop_op = OP_ENTERSUB;
cd81e915
NC
5504 PL_nextwhite = PL_thiswhite;
5505 PL_thiswhite = 0;
5506 start_force(PL_curforce);
5db06880
NC
5507 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5508 PL_expect = XTERM;
cd81e915
NC
5509 PL_nextwhite = nextPL_nextwhite;
5510 curmad('X', PL_thistoken);
6b29d1f5 5511 PL_thistoken = newSVpvs("");
5db06880
NC
5512 force_next(WORD);
5513 TOKEN(NOAMP);
5514 }
5515#else
9ded7720 5516 NEXTVAL_NEXTTOKE.opval = yylval.opval;
3280af22 5517 PL_expect = XTERM;
8990e307
LW
5518 force_next(WORD);
5519 TOKEN(NOAMP);
5db06880 5520#endif
8990e307 5521 }
748a9306 5522
8990e307
LW
5523 /* Call it a bare word */
5524
5603f27d
GS
5525 if (PL_hints & HINT_STRICT_SUBS)
5526 yylval.opval->op_private |= OPpCONST_STRICT;
5527 else {
5528 bareword:
041457d9
DM
5529 if (lastchar != '-') {
5530 if (ckWARN(WARN_RESERVED)) {
c35e046a
AL
5531 d = PL_tokenbuf;
5532 while (isLOWER(*d))
5533 d++;
238ae712 5534 if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
9014280d 5535 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5603f27d
GS
5536 PL_tokenbuf);
5537 }
748a9306
LW
5538 }
5539 }
c3e0f903
GS
5540
5541 safe_bareword:
3792a11b
NC
5542 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5543 && ckWARN_d(WARN_AMBIGUOUS)) {
9014280d 5544 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
0453d815 5545 "Operator or semicolon missing before %c%s",
3280af22 5546 lastchar, PL_tokenbuf);
9014280d 5547 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
0453d815 5548 "Ambiguous use of %c resolved as operator %c",
748a9306
LW
5549 lastchar, lastchar);
5550 }
93a17b20 5551 TOKEN(WORD);
79072805 5552 }
79072805 5553
68dc0745 5554 case KEY___FILE__:
46fc3d4c 5555 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
ed094faf 5556 newSVpv(CopFILE(PL_curcop),0));
46fc3d4c 5557 TERM(THING);
5558
79072805 5559 case KEY___LINE__:
cf2093f6 5560 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
57843af0 5561 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
79072805 5562 TERM(THING);
68dc0745 5563
5564 case KEY___PACKAGE__:
5565 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
3280af22 5566 (PL_curstash
5aaec2b4 5567 ? newSVhek(HvNAME_HEK(PL_curstash))
3280af22 5568 : &PL_sv_undef));
79072805 5569 TERM(THING);
79072805 5570
e50aee73 5571 case KEY___DATA__:
79072805
LW
5572 case KEY___END__: {
5573 GV *gv;
3280af22 5574 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
bfed75c6 5575 const char *pname = "main";
3280af22 5576 if (PL_tokenbuf[2] == 'D')
bfcb3514 5577 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
f776e3cd
NC
5578 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5579 SVt_PVIO);
a5f75d66 5580 GvMULTI_on(gv);
79072805 5581 if (!GvIO(gv))
a0d0e21e 5582 GvIOp(gv) = newIO();
3280af22 5583 IoIFP(GvIOp(gv)) = PL_rsfp;
a0d0e21e
LW
5584#if defined(HAS_FCNTL) && defined(F_SETFD)
5585 {
f54cb97a 5586 const int fd = PerlIO_fileno(PL_rsfp);
a0d0e21e
LW
5587 fcntl(fd,F_SETFD,fd >= 3);
5588 }
79072805 5589#endif
fd049845 5590 /* Mark this internal pseudo-handle as clean */
5591 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
3280af22 5592 if (PL_preprocess)
50952442 5593 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
3280af22 5594 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
50952442 5595 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
79072805 5596 else
50952442 5597 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
c39cd008
GS
5598#if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5599 /* if the script was opened in binmode, we need to revert
53129d29 5600 * it to text mode for compatibility; but only iff it has CRs
c39cd008 5601 * XXX this is a questionable hack at best. */
53129d29
GS
5602 if (PL_bufend-PL_bufptr > 2
5603 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
c39cd008
GS
5604 {
5605 Off_t loc = 0;
50952442 5606 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
c39cd008
GS
5607 loc = PerlIO_tell(PL_rsfp);
5608 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5609 }
2986a63f
JH
5610#ifdef NETWARE
5611 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5612#else
c39cd008 5613 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
2986a63f 5614#endif /* NETWARE */
1143fce0
JH
5615#ifdef PERLIO_IS_STDIO /* really? */
5616# if defined(__BORLANDC__)
cb359b41
JH
5617 /* XXX see note in do_binmode() */
5618 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
1143fce0
JH
5619# endif
5620#endif
c39cd008
GS
5621 if (loc > 0)
5622 PerlIO_seek(PL_rsfp, loc, 0);
5623 }
5624 }
5625#endif
7948272d 5626#ifdef PERLIO_LAYERS
52d2e0f4
JH
5627 if (!IN_BYTES) {
5628 if (UTF)
5629 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5630 else if (PL_encoding) {
5631 SV *name;
5632 dSP;
5633 ENTER;
5634 SAVETMPS;
5635 PUSHMARK(sp);
5636 EXTEND(SP, 1);
5637 XPUSHs(PL_encoding);
5638 PUTBACK;
5639 call_method("name", G_SCALAR);
5640 SPAGAIN;
5641 name = POPs;
5642 PUTBACK;
bfed75c6 5643 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
52d2e0f4 5644 Perl_form(aTHX_ ":encoding(%"SVf")",
95b63a38 5645 (void*)name));
52d2e0f4
JH
5646 FREETMPS;
5647 LEAVE;
5648 }
5649 }
7948272d 5650#endif
5db06880
NC
5651#ifdef PERL_MAD
5652 if (PL_madskills) {
cd81e915
NC
5653 if (PL_realtokenstart >= 0) {
5654 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5655 if (!PL_endwhite)
6b29d1f5 5656 PL_endwhite = newSVpvs("");
cd81e915
NC
5657 sv_catsv(PL_endwhite, PL_thiswhite);
5658 PL_thiswhite = 0;
5659 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5660 PL_realtokenstart = -1;
5db06880 5661 }
cd81e915
NC
5662 while ((s = filter_gets(PL_endwhite, PL_rsfp,
5663 SvCUR(PL_endwhite))) != Nullch) ;
5db06880
NC
5664 }
5665#endif
4608196e 5666 PL_rsfp = NULL;
79072805
LW
5667 }
5668 goto fake_eof;
e929a76b 5669 }
de3bb511 5670
8990e307 5671 case KEY_AUTOLOAD:
ed6116ce 5672 case KEY_DESTROY:
79072805 5673 case KEY_BEGIN:
3c10abe3 5674 case KEY_UNITCHECK:
7d30b5c4 5675 case KEY_CHECK:
7d07dbc2 5676 case KEY_INIT:
7d30b5c4 5677 case KEY_END:
3280af22
NIS
5678 if (PL_expect == XSTATE) {
5679 s = PL_bufptr;
93a17b20 5680 goto really_sub;
79072805
LW
5681 }
5682 goto just_a_word;
5683
a0d0e21e
LW
5684 case KEY_CORE:
5685 if (*s == ':' && s[1] == ':') {
5686 s += 2;
748a9306 5687 d = s;
3280af22 5688 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5458a98a 5689 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
6798c92b 5690 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
a0d0e21e
LW
5691 if (tmp < 0)
5692 tmp = -tmp;
850e8516 5693 else if (tmp == KEY_require || tmp == KEY_do)
a72a1c8b 5694 /* that's a way to remember we saw "CORE::" */
850e8516 5695 orig_keyword = tmp;
a0d0e21e
LW
5696 goto reserved_word;
5697 }
5698 goto just_a_word;
5699
463ee0b2
LW
5700 case KEY_abs:
5701 UNI(OP_ABS);
5702
79072805
LW
5703 case KEY_alarm:
5704 UNI(OP_ALARM);
5705
5706 case KEY_accept:
a0d0e21e 5707 LOP(OP_ACCEPT,XTERM);
79072805 5708
463ee0b2
LW
5709 case KEY_and:
5710 OPERATOR(ANDOP);
5711
79072805 5712 case KEY_atan2:
a0d0e21e 5713 LOP(OP_ATAN2,XTERM);
85e6fe83 5714
79072805 5715 case KEY_bind:
a0d0e21e 5716 LOP(OP_BIND,XTERM);
79072805
LW
5717
5718 case KEY_binmode:
1c1fc3ea 5719 LOP(OP_BINMODE,XTERM);
79072805
LW
5720
5721 case KEY_bless:
a0d0e21e 5722 LOP(OP_BLESS,XTERM);
79072805 5723
0d863452
RH
5724 case KEY_break:
5725 FUN0(OP_BREAK);
5726
79072805
LW
5727 case KEY_chop:
5728 UNI(OP_CHOP);
5729
5730 case KEY_continue:
0d863452
RH
5731 /* When 'use switch' is in effect, continue has a dual
5732 life as a control operator. */
5733 {
ef89dcc3 5734 if (!FEATURE_IS_ENABLED("switch"))
0d863452
RH
5735 PREBLOCK(CONTINUE);
5736 else {
5737 /* We have to disambiguate the two senses of
5738 "continue". If the next token is a '{' then
5739 treat it as the start of a continue block;
5740 otherwise treat it as a control operator.
5741 */
5742 s = skipspace(s);
5743 if (*s == '{')
79072805 5744 PREBLOCK(CONTINUE);
0d863452
RH
5745 else
5746 FUN0(OP_CONTINUE);
5747 }
5748 }
79072805
LW
5749
5750 case KEY_chdir:
fafc274c
NC
5751 /* may use HOME */
5752 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
79072805
LW
5753 UNI(OP_CHDIR);
5754
5755 case KEY_close:
5756 UNI(OP_CLOSE);
5757
5758 case KEY_closedir:
5759 UNI(OP_CLOSEDIR);
5760
5761 case KEY_cmp:
5762 Eop(OP_SCMP);
5763
5764 case KEY_caller:
5765 UNI(OP_CALLER);
5766
5767 case KEY_crypt:
5768#ifdef FCRYPT
f4c556ac
GS
5769 if (!PL_cryptseen) {
5770 PL_cryptseen = TRUE;
de3bb511 5771 init_des();
f4c556ac 5772 }
a687059c 5773#endif
a0d0e21e 5774 LOP(OP_CRYPT,XTERM);
79072805
LW
5775
5776 case KEY_chmod:
a0d0e21e 5777 LOP(OP_CHMOD,XTERM);
79072805
LW
5778
5779 case KEY_chown:
a0d0e21e 5780 LOP(OP_CHOWN,XTERM);
79072805
LW
5781
5782 case KEY_connect:
a0d0e21e 5783 LOP(OP_CONNECT,XTERM);
79072805 5784
463ee0b2
LW
5785 case KEY_chr:
5786 UNI(OP_CHR);
5787
79072805
LW
5788 case KEY_cos:
5789 UNI(OP_COS);
5790
5791 case KEY_chroot:
5792 UNI(OP_CHROOT);
5793
0d863452
RH
5794 case KEY_default:
5795 PREBLOCK(DEFAULT);
5796
79072805 5797 case KEY_do:
29595ff2 5798 s = SKIPSPACE1(s);
79072805 5799 if (*s == '{')
a0d0e21e 5800 PRETERMBLOCK(DO);
79072805 5801 if (*s != '\'')
89c5585f 5802 s = force_word(s,WORD,TRUE,TRUE,FALSE);
850e8516
RGS
5803 if (orig_keyword == KEY_do) {
5804 orig_keyword = 0;
5805 yylval.ival = 1;
5806 }
5807 else
5808 yylval.ival = 0;
378cc40b 5809 OPERATOR(DO);
79072805
LW
5810
5811 case KEY_die:
3280af22 5812 PL_hints |= HINT_BLOCK_SCOPE;
a0d0e21e 5813 LOP(OP_DIE,XTERM);
79072805
LW
5814
5815 case KEY_defined:
5816 UNI(OP_DEFINED);
5817
5818 case KEY_delete:
a0d0e21e 5819 UNI(OP_DELETE);
79072805
LW
5820
5821 case KEY_dbmopen:
5c1737d1 5822 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
a0d0e21e 5823 LOP(OP_DBMOPEN,XTERM);
79072805
LW
5824
5825 case KEY_dbmclose:
5826 UNI(OP_DBMCLOSE);
5827
5828 case KEY_dump:
a0d0e21e 5829 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
5830 LOOPX(OP_DUMP);
5831
5832 case KEY_else:
5833 PREBLOCK(ELSE);
5834
5835 case KEY_elsif:
57843af0 5836 yylval.ival = CopLINE(PL_curcop);
79072805
LW
5837 OPERATOR(ELSIF);
5838
5839 case KEY_eq:
5840 Eop(OP_SEQ);
5841
a0d0e21e
LW
5842 case KEY_exists:
5843 UNI(OP_EXISTS);
4e553d73 5844
79072805 5845 case KEY_exit:
5db06880
NC
5846 if (PL_madskills)
5847 UNI(OP_INT);
79072805
LW
5848 UNI(OP_EXIT);
5849
5850 case KEY_eval:
29595ff2 5851 s = SKIPSPACE1(s);
3280af22 5852 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
463ee0b2 5853 UNIBRACK(OP_ENTEREVAL);
79072805
LW
5854
5855 case KEY_eof:
5856 UNI(OP_EOF);
5857
c963b151
BD
5858 case KEY_err:
5859 OPERATOR(DOROP);
5860
79072805
LW
5861 case KEY_exp:
5862 UNI(OP_EXP);
5863
5864 case KEY_each:
5865 UNI(OP_EACH);
5866
5867 case KEY_exec:
5868 set_csh();
a0d0e21e 5869 LOP(OP_EXEC,XREF);
79072805
LW
5870
5871 case KEY_endhostent:
5872 FUN0(OP_EHOSTENT);
5873
5874 case KEY_endnetent:
5875 FUN0(OP_ENETENT);
5876
5877 case KEY_endservent:
5878 FUN0(OP_ESERVENT);
5879
5880 case KEY_endprotoent:
5881 FUN0(OP_EPROTOENT);
5882
5883 case KEY_endpwent:
5884 FUN0(OP_EPWENT);
5885
5886 case KEY_endgrent:
5887 FUN0(OP_EGRENT);
5888
5889 case KEY_for:
5890 case KEY_foreach:
57843af0 5891 yylval.ival = CopLINE(PL_curcop);
29595ff2 5892 s = SKIPSPACE1(s);
7e2040f0 5893 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
55497cff 5894 char *p = s;
5db06880
NC
5895#ifdef PERL_MAD
5896 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5897#endif
5898
3280af22 5899 if ((PL_bufend - p) >= 3 &&
55497cff 5900 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5901 p += 2;
77ca0c92
LW
5902 else if ((PL_bufend - p) >= 4 &&
5903 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5904 p += 3;
29595ff2 5905 p = PEEKSPACE(p);
7e2040f0 5906 if (isIDFIRST_lazy_if(p,UTF)) {
77ca0c92
LW
5907 p = scan_ident(p, PL_bufend,
5908 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
29595ff2 5909 p = PEEKSPACE(p);
77ca0c92
LW
5910 }
5911 if (*p != '$')
cea2e8a9 5912 Perl_croak(aTHX_ "Missing $ on loop variable");
5db06880
NC
5913#ifdef PERL_MAD
5914 s = SvPVX(PL_linestr) + soff;
5915#endif
55497cff 5916 }
79072805
LW
5917 OPERATOR(FOR);
5918
5919 case KEY_formline:
a0d0e21e 5920 LOP(OP_FORMLINE,XTERM);
79072805
LW
5921
5922 case KEY_fork:
5923 FUN0(OP_FORK);
5924
5925 case KEY_fcntl:
a0d0e21e 5926 LOP(OP_FCNTL,XTERM);
79072805
LW
5927
5928 case KEY_fileno:
5929 UNI(OP_FILENO);
5930
5931 case KEY_flock:
a0d0e21e 5932 LOP(OP_FLOCK,XTERM);
79072805
LW
5933
5934 case KEY_gt:
5935 Rop(OP_SGT);
5936
5937 case KEY_ge:
5938 Rop(OP_SGE);
5939
5940 case KEY_grep:
2c38e13d 5941 LOP(OP_GREPSTART, XREF);
79072805
LW
5942
5943 case KEY_goto:
a0d0e21e 5944 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
5945 LOOPX(OP_GOTO);
5946
5947 case KEY_gmtime:
5948 UNI(OP_GMTIME);
5949
5950 case KEY_getc:
6f33ba73 5951 UNIDOR(OP_GETC);
79072805
LW
5952
5953 case KEY_getppid:
5954 FUN0(OP_GETPPID);
5955
5956 case KEY_getpgrp:
5957 UNI(OP_GETPGRP);
5958
5959 case KEY_getpriority:
a0d0e21e 5960 LOP(OP_GETPRIORITY,XTERM);
79072805
LW
5961
5962 case KEY_getprotobyname:
5963 UNI(OP_GPBYNAME);
5964
5965 case KEY_getprotobynumber:
a0d0e21e 5966 LOP(OP_GPBYNUMBER,XTERM);
79072805
LW
5967
5968 case KEY_getprotoent:
5969 FUN0(OP_GPROTOENT);
5970
5971 case KEY_getpwent:
5972 FUN0(OP_GPWENT);
5973
5974 case KEY_getpwnam:
ff68c719 5975 UNI(OP_GPWNAM);
79072805
LW
5976
5977 case KEY_getpwuid:
ff68c719 5978 UNI(OP_GPWUID);
79072805
LW
5979
5980 case KEY_getpeername:
5981 UNI(OP_GETPEERNAME);
5982
5983 case KEY_gethostbyname:
5984 UNI(OP_GHBYNAME);
5985
5986 case KEY_gethostbyaddr:
a0d0e21e 5987 LOP(OP_GHBYADDR,XTERM);
79072805
LW
5988
5989 case KEY_gethostent:
5990 FUN0(OP_GHOSTENT);
5991
5992 case KEY_getnetbyname:
5993 UNI(OP_GNBYNAME);
5994
5995 case KEY_getnetbyaddr:
a0d0e21e 5996 LOP(OP_GNBYADDR,XTERM);
79072805
LW
5997
5998 case KEY_getnetent:
5999 FUN0(OP_GNETENT);
6000
6001 case KEY_getservbyname:
a0d0e21e 6002 LOP(OP_GSBYNAME,XTERM);
79072805
LW
6003
6004 case KEY_getservbyport:
a0d0e21e 6005 LOP(OP_GSBYPORT,XTERM);
79072805
LW
6006
6007 case KEY_getservent:
6008 FUN0(OP_GSERVENT);
6009
6010 case KEY_getsockname:
6011 UNI(OP_GETSOCKNAME);
6012
6013 case KEY_getsockopt:
a0d0e21e 6014 LOP(OP_GSOCKOPT,XTERM);
79072805
LW
6015
6016 case KEY_getgrent:
6017 FUN0(OP_GGRENT);
6018
6019 case KEY_getgrnam:
ff68c719 6020 UNI(OP_GGRNAM);
79072805
LW
6021
6022 case KEY_getgrgid:
ff68c719 6023 UNI(OP_GGRGID);
79072805
LW
6024
6025 case KEY_getlogin:
6026 FUN0(OP_GETLOGIN);
6027
0d863452
RH
6028 case KEY_given:
6029 yylval.ival = CopLINE(PL_curcop);
6030 OPERATOR(GIVEN);
6031
93a17b20 6032 case KEY_glob:
a0d0e21e
LW
6033 set_csh();
6034 LOP(OP_GLOB,XTERM);
93a17b20 6035
79072805
LW
6036 case KEY_hex:
6037 UNI(OP_HEX);
6038
6039 case KEY_if:
57843af0 6040 yylval.ival = CopLINE(PL_curcop);
79072805
LW
6041 OPERATOR(IF);
6042
6043 case KEY_index:
a0d0e21e 6044 LOP(OP_INDEX,XTERM);
79072805
LW
6045
6046 case KEY_int:
6047 UNI(OP_INT);
6048
6049 case KEY_ioctl:
a0d0e21e 6050 LOP(OP_IOCTL,XTERM);
79072805
LW
6051
6052 case KEY_join:
a0d0e21e 6053 LOP(OP_JOIN,XTERM);
79072805
LW
6054
6055 case KEY_keys:
6056 UNI(OP_KEYS);
6057
6058 case KEY_kill:
a0d0e21e 6059 LOP(OP_KILL,XTERM);
79072805
LW
6060
6061 case KEY_last:
a0d0e21e 6062 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805 6063 LOOPX(OP_LAST);
4e553d73 6064
79072805
LW
6065 case KEY_lc:
6066 UNI(OP_LC);
6067
6068 case KEY_lcfirst:
6069 UNI(OP_LCFIRST);
6070
6071 case KEY_local:
09bef843 6072 yylval.ival = 0;
79072805
LW
6073 OPERATOR(LOCAL);
6074
6075 case KEY_length:
6076 UNI(OP_LENGTH);
6077
6078 case KEY_lt:
6079 Rop(OP_SLT);
6080
6081 case KEY_le:
6082 Rop(OP_SLE);
6083
6084 case KEY_localtime:
6085 UNI(OP_LOCALTIME);
6086
6087 case KEY_log:
6088 UNI(OP_LOG);
6089
6090 case KEY_link:
a0d0e21e 6091 LOP(OP_LINK,XTERM);
79072805
LW
6092
6093 case KEY_listen:
a0d0e21e 6094 LOP(OP_LISTEN,XTERM);
79072805 6095
c0329465
MB
6096 case KEY_lock:
6097 UNI(OP_LOCK);
6098
79072805
LW
6099 case KEY_lstat:
6100 UNI(OP_LSTAT);
6101
6102 case KEY_m:
8782bef2 6103 s = scan_pat(s,OP_MATCH);
79072805
LW
6104 TERM(sublex_start());
6105
a0d0e21e 6106 case KEY_map:
2c38e13d 6107 LOP(OP_MAPSTART, XREF);
4e4e412b 6108
79072805 6109 case KEY_mkdir:
a0d0e21e 6110 LOP(OP_MKDIR,XTERM);
79072805
LW
6111
6112 case KEY_msgctl:
a0d0e21e 6113 LOP(OP_MSGCTL,XTERM);
79072805
LW
6114
6115 case KEY_msgget:
a0d0e21e 6116 LOP(OP_MSGGET,XTERM);
79072805
LW
6117
6118 case KEY_msgrcv:
a0d0e21e 6119 LOP(OP_MSGRCV,XTERM);
79072805
LW
6120
6121 case KEY_msgsnd:
a0d0e21e 6122 LOP(OP_MSGSND,XTERM);
79072805 6123
77ca0c92 6124 case KEY_our:
93a17b20 6125 case KEY_my:
952306ac 6126 case KEY_state:
77ca0c92 6127 PL_in_my = tmp;
29595ff2 6128 s = SKIPSPACE1(s);
7e2040f0 6129 if (isIDFIRST_lazy_if(s,UTF)) {
5db06880
NC
6130#ifdef PERL_MAD
6131 char* start = s;
6132#endif
3280af22 6133 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
09bef843
SB
6134 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
6135 goto really_sub;
def3634b 6136 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
3280af22 6137 if (!PL_in_my_stash) {
c750a3ec 6138 char tmpbuf[1024];
3280af22 6139 PL_bufptr = s;
d9fad198 6140 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
c750a3ec
MB
6141 yyerror(tmpbuf);
6142 }
5db06880
NC
6143#ifdef PERL_MAD
6144 if (PL_madskills) { /* just add type to declarator token */
cd81e915
NC
6145 sv_catsv(PL_thistoken, PL_nextwhite);
6146 PL_nextwhite = 0;
6147 sv_catpvn(PL_thistoken, start, s - start);
5db06880
NC
6148 }
6149#endif
c750a3ec 6150 }
09bef843 6151 yylval.ival = 1;
55497cff 6152 OPERATOR(MY);
93a17b20 6153
79072805 6154 case KEY_next:
a0d0e21e 6155 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
6156 LOOPX(OP_NEXT);
6157
6158 case KEY_ne:
6159 Eop(OP_SNE);
6160
a0d0e21e 6161 case KEY_no:
468aa647 6162 s = tokenize_use(0, s);
a0d0e21e
LW
6163 OPERATOR(USE);
6164
6165 case KEY_not:
29595ff2 6166 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
2d2e263d
LW
6167 FUN1(OP_NOT);
6168 else
6169 OPERATOR(NOTOP);
a0d0e21e 6170
79072805 6171 case KEY_open:
29595ff2 6172 s = SKIPSPACE1(s);
7e2040f0 6173 if (isIDFIRST_lazy_if(s,UTF)) {
f54cb97a 6174 const char *t;
c35e046a
AL
6175 for (d = s; isALNUM_lazy_if(d,UTF);)
6176 d++;
6177 for (t=d; isSPACE(*t);)
6178 t++;
e2ab214b 6179 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
66fbe8fb
HS
6180 /* [perl #16184] */
6181 && !(t[0] == '=' && t[1] == '>')
6182 ) {
5f66b61c 6183 int parms_len = (int)(d-s);
9014280d 6184 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
0453d815 6185 "Precedence problem: open %.*s should be open(%.*s)",
5f66b61c 6186 parms_len, s, parms_len, s);
66fbe8fb 6187 }
93a17b20 6188 }
a0d0e21e 6189 LOP(OP_OPEN,XTERM);
79072805 6190
463ee0b2 6191 case KEY_or:
a0d0e21e 6192 yylval.ival = OP_OR;
463ee0b2
LW
6193 OPERATOR(OROP);
6194
79072805
LW
6195 case KEY_ord:
6196 UNI(OP_ORD);
6197
6198 case KEY_oct:
6199 UNI(OP_OCT);
6200
6201 case KEY_opendir:
a0d0e21e 6202 LOP(OP_OPEN_DIR,XTERM);
79072805
LW
6203
6204 case KEY_print:
3280af22 6205 checkcomma(s,PL_tokenbuf,"filehandle");
a0d0e21e 6206 LOP(OP_PRINT,XREF);
79072805
LW
6207
6208 case KEY_printf:
3280af22 6209 checkcomma(s,PL_tokenbuf,"filehandle");
a0d0e21e 6210 LOP(OP_PRTF,XREF);
79072805 6211
c07a80fd 6212 case KEY_prototype:
6213 UNI(OP_PROTOTYPE);
6214
79072805 6215 case KEY_push:
a0d0e21e 6216 LOP(OP_PUSH,XTERM);
79072805
LW
6217
6218 case KEY_pop:
6f33ba73 6219 UNIDOR(OP_POP);
79072805 6220
a0d0e21e 6221 case KEY_pos:
6f33ba73 6222 UNIDOR(OP_POS);
4e553d73 6223
79072805 6224 case KEY_pack:
a0d0e21e 6225 LOP(OP_PACK,XTERM);
79072805
LW
6226
6227 case KEY_package:
a0d0e21e 6228 s = force_word(s,WORD,FALSE,TRUE,FALSE);
79072805
LW
6229 OPERATOR(PACKAGE);
6230
6231 case KEY_pipe:
a0d0e21e 6232 LOP(OP_PIPE_OP,XTERM);
79072805
LW
6233
6234 case KEY_q:
5db06880 6235 s = scan_str(s,!!PL_madskills,FALSE);
79072805 6236 if (!s)
d4c19fe8 6237 missingterm(NULL);
79072805
LW
6238 yylval.ival = OP_CONST;
6239 TERM(sublex_start());
6240
a0d0e21e
LW
6241 case KEY_quotemeta:
6242 UNI(OP_QUOTEMETA);
6243
8990e307 6244 case KEY_qw:
5db06880 6245 s = scan_str(s,!!PL_madskills,FALSE);
8990e307 6246 if (!s)
d4c19fe8 6247 missingterm(NULL);
3480a8d2 6248 PL_expect = XOPERATOR;
8127e0e3
GS
6249 force_next(')');
6250 if (SvCUR(PL_lex_stuff)) {
5f66b61c 6251 OP *words = NULL;
8127e0e3 6252 int warned = 0;
3280af22 6253 d = SvPV_force(PL_lex_stuff, len);
8127e0e3 6254 while (len) {
d4c19fe8
AL
6255 for (; isSPACE(*d) && len; --len, ++d)
6256 /**/;
8127e0e3 6257 if (len) {
d4c19fe8 6258 SV *sv;
f54cb97a 6259 const char *b = d;
e476b1b5 6260 if (!warned && ckWARN(WARN_QW)) {
8127e0e3
GS
6261 for (; !isSPACE(*d) && len; --len, ++d) {
6262 if (*d == ',') {
9014280d 6263 Perl_warner(aTHX_ packWARN(WARN_QW),
8127e0e3
GS
6264 "Possible attempt to separate words with commas");
6265 ++warned;
6266 }
6267 else if (*d == '#') {
9014280d 6268 Perl_warner(aTHX_ packWARN(WARN_QW),
8127e0e3
GS
6269 "Possible attempt to put comments in qw() list");
6270 ++warned;
6271 }
6272 }
6273 }
6274 else {
d4c19fe8
AL
6275 for (; !isSPACE(*d) && len; --len, ++d)
6276 /**/;
8127e0e3 6277 }
7948272d
NIS
6278 sv = newSVpvn(b, d-b);
6279 if (DO_UTF8(PL_lex_stuff))
6280 SvUTF8_on(sv);
8127e0e3 6281 words = append_elem(OP_LIST, words,
7948272d 6282 newSVOP(OP_CONST, 0, tokeq(sv)));
55497cff 6283 }
6284 }
8127e0e3 6285 if (words) {
cd81e915 6286 start_force(PL_curforce);
9ded7720 6287 NEXTVAL_NEXTTOKE.opval = words;
8127e0e3
GS
6288 force_next(THING);
6289 }
55497cff 6290 }
37fd879b 6291 if (PL_lex_stuff) {
8127e0e3 6292 SvREFCNT_dec(PL_lex_stuff);
a0714e2c 6293 PL_lex_stuff = NULL;
37fd879b 6294 }
3280af22 6295 PL_expect = XTERM;
8127e0e3 6296 TOKEN('(');
8990e307 6297
79072805 6298 case KEY_qq:
5db06880 6299 s = scan_str(s,!!PL_madskills,FALSE);
79072805 6300 if (!s)
d4c19fe8 6301 missingterm(NULL);
a0d0e21e 6302 yylval.ival = OP_STRINGIFY;
3280af22 6303 if (SvIVX(PL_lex_stuff) == '\'')
45977657 6304 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
79072805
LW
6305 TERM(sublex_start());
6306
8782bef2
GB
6307 case KEY_qr:
6308 s = scan_pat(s,OP_QR);
6309 TERM(sublex_start());
6310
79072805 6311 case KEY_qx:
5db06880 6312 s = scan_str(s,!!PL_madskills,FALSE);
79072805 6313 if (!s)
d4c19fe8 6314 missingterm(NULL);
9b201d7d 6315 readpipe_override();
79072805
LW
6316 TERM(sublex_start());
6317
6318 case KEY_return:
6319 OLDLOP(OP_RETURN);
6320
6321 case KEY_require:
29595ff2 6322 s = SKIPSPACE1(s);
e759cc13
RGS
6323 if (isDIGIT(*s)) {
6324 s = force_version(s, FALSE);
a7cb1f99 6325 }
e759cc13
RGS
6326 else if (*s != 'v' || !isDIGIT(s[1])
6327 || (s = force_version(s, TRUE), *s == 'v'))
6328 {
a7cb1f99
GS
6329 *PL_tokenbuf = '\0';
6330 s = force_word(s,WORD,TRUE,TRUE,FALSE);
7e2040f0 6331 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
a7cb1f99
GS
6332 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
6333 else if (*s == '<')
6334 yyerror("<> should be quotes");
6335 }
a72a1c8b
RGS
6336 if (orig_keyword == KEY_require) {
6337 orig_keyword = 0;
6338 yylval.ival = 1;
6339 }
6340 else
6341 yylval.ival = 0;
6342 PL_expect = XTERM;
6343 PL_bufptr = s;
6344 PL_last_uni = PL_oldbufptr;
6345 PL_last_lop_op = OP_REQUIRE;
6346 s = skipspace(s);
6347 return REPORT( (int)REQUIRE );
79072805
LW
6348
6349 case KEY_reset:
6350 UNI(OP_RESET);
6351
6352 case KEY_redo:
a0d0e21e 6353 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
6354 LOOPX(OP_REDO);
6355
6356 case KEY_rename:
a0d0e21e 6357 LOP(OP_RENAME,XTERM);
79072805
LW
6358
6359 case KEY_rand:
6360 UNI(OP_RAND);
6361
6362 case KEY_rmdir:
6363 UNI(OP_RMDIR);
6364
6365 case KEY_rindex:
a0d0e21e 6366 LOP(OP_RINDEX,XTERM);
79072805
LW
6367
6368 case KEY_read:
a0d0e21e 6369 LOP(OP_READ,XTERM);
79072805
LW
6370
6371 case KEY_readdir:
6372 UNI(OP_READDIR);
6373
93a17b20
LW
6374 case KEY_readline:
6375 set_csh();
6f33ba73 6376 UNIDOR(OP_READLINE);
93a17b20
LW
6377
6378 case KEY_readpipe:
6379 set_csh();
6380 UNI(OP_BACKTICK);
6381
79072805
LW
6382 case KEY_rewinddir:
6383 UNI(OP_REWINDDIR);
6384
6385 case KEY_recv:
a0d0e21e 6386 LOP(OP_RECV,XTERM);
79072805
LW
6387
6388 case KEY_reverse:
a0d0e21e 6389 LOP(OP_REVERSE,XTERM);
79072805
LW
6390
6391 case KEY_readlink:
6f33ba73 6392 UNIDOR(OP_READLINK);
79072805
LW
6393
6394 case KEY_ref:
6395 UNI(OP_REF);
6396
6397 case KEY_s:
6398 s = scan_subst(s);
6399 if (yylval.opval)
6400 TERM(sublex_start());
6401 else
6402 TOKEN(1); /* force error */
6403
0d863452
RH
6404 case KEY_say:
6405 checkcomma(s,PL_tokenbuf,"filehandle");
6406 LOP(OP_SAY,XREF);
6407
a0d0e21e
LW
6408 case KEY_chomp:
6409 UNI(OP_CHOMP);
4e553d73 6410
79072805
LW
6411 case KEY_scalar:
6412 UNI(OP_SCALAR);
6413
6414 case KEY_select:
a0d0e21e 6415 LOP(OP_SELECT,XTERM);
79072805
LW
6416
6417 case KEY_seek:
a0d0e21e 6418 LOP(OP_SEEK,XTERM);
79072805
LW
6419
6420 case KEY_semctl:
a0d0e21e 6421 LOP(OP_SEMCTL,XTERM);
79072805
LW
6422
6423 case KEY_semget:
a0d0e21e 6424 LOP(OP_SEMGET,XTERM);
79072805
LW
6425
6426 case KEY_semop:
a0d0e21e 6427 LOP(OP_SEMOP,XTERM);
79072805
LW
6428
6429 case KEY_send:
a0d0e21e 6430 LOP(OP_SEND,XTERM);
79072805
LW
6431
6432 case KEY_setpgrp:
a0d0e21e 6433 LOP(OP_SETPGRP,XTERM);
79072805
LW
6434
6435 case KEY_setpriority:
a0d0e21e 6436 LOP(OP_SETPRIORITY,XTERM);
79072805
LW
6437
6438 case KEY_sethostent:
ff68c719 6439 UNI(OP_SHOSTENT);
79072805
LW
6440
6441 case KEY_setnetent:
ff68c719 6442 UNI(OP_SNETENT);
79072805
LW
6443
6444 case KEY_setservent:
ff68c719 6445 UNI(OP_SSERVENT);
79072805
LW
6446
6447 case KEY_setprotoent:
ff68c719 6448 UNI(OP_SPROTOENT);
79072805
LW
6449
6450 case KEY_setpwent:
6451 FUN0(OP_SPWENT);
6452
6453 case KEY_setgrent:
6454 FUN0(OP_SGRENT);
6455
6456 case KEY_seekdir:
a0d0e21e 6457 LOP(OP_SEEKDIR,XTERM);
79072805
LW
6458
6459 case KEY_setsockopt:
a0d0e21e 6460 LOP(OP_SSOCKOPT,XTERM);
79072805
LW
6461
6462 case KEY_shift:
6f33ba73 6463 UNIDOR(OP_SHIFT);
79072805
LW
6464
6465 case KEY_shmctl:
a0d0e21e 6466 LOP(OP_SHMCTL,XTERM);
79072805
LW
6467
6468 case KEY_shmget:
a0d0e21e 6469 LOP(OP_SHMGET,XTERM);
79072805
LW
6470
6471 case KEY_shmread:
a0d0e21e 6472 LOP(OP_SHMREAD,XTERM);
79072805
LW
6473
6474 case KEY_shmwrite:
a0d0e21e 6475 LOP(OP_SHMWRITE,XTERM);
79072805
LW
6476
6477 case KEY_shutdown:
a0d0e21e 6478 LOP(OP_SHUTDOWN,XTERM);
79072805
LW
6479
6480 case KEY_sin:
6481 UNI(OP_SIN);
6482
6483 case KEY_sleep:
6484 UNI(OP_SLEEP);
6485
6486 case KEY_socket:
a0d0e21e 6487 LOP(OP_SOCKET,XTERM);
79072805
LW
6488
6489 case KEY_socketpair:
a0d0e21e 6490 LOP(OP_SOCKPAIR,XTERM);
79072805
LW
6491
6492 case KEY_sort:
3280af22 6493 checkcomma(s,PL_tokenbuf,"subroutine name");
29595ff2 6494 s = SKIPSPACE1(s);
79072805 6495 if (*s == ';' || *s == ')') /* probably a close */
cea2e8a9 6496 Perl_croak(aTHX_ "sort is now a reserved word");
3280af22 6497 PL_expect = XTERM;
15f0808c 6498 s = force_word(s,WORD,TRUE,TRUE,FALSE);
a0d0e21e 6499 LOP(OP_SORT,XREF);
79072805
LW
6500
6501 case KEY_split:
a0d0e21e 6502 LOP(OP_SPLIT,XTERM);
79072805
LW
6503
6504 case KEY_sprintf:
a0d0e21e 6505 LOP(OP_SPRINTF,XTERM);
79072805
LW
6506
6507 case KEY_splice:
a0d0e21e 6508 LOP(OP_SPLICE,XTERM);
79072805
LW
6509
6510 case KEY_sqrt:
6511 UNI(OP_SQRT);
6512
6513 case KEY_srand:
6514 UNI(OP_SRAND);
6515
6516 case KEY_stat:
6517 UNI(OP_STAT);
6518
6519 case KEY_study:
79072805
LW
6520 UNI(OP_STUDY);
6521
6522 case KEY_substr:
a0d0e21e 6523 LOP(OP_SUBSTR,XTERM);
79072805
LW
6524
6525 case KEY_format:
6526 case KEY_sub:
93a17b20 6527 really_sub:
09bef843 6528 {
3280af22 6529 char tmpbuf[sizeof PL_tokenbuf];
9c5ffd7c 6530 SSize_t tboffset = 0;
09bef843 6531 expectation attrful;
28cc6278 6532 bool have_name, have_proto;
f54cb97a 6533 const int key = tmp;
09bef843 6534
5db06880
NC
6535#ifdef PERL_MAD
6536 SV *tmpwhite = 0;
6537
cd81e915 6538 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5db06880 6539 SV *subtoken = newSVpvn(tstart, s - tstart);
cd81e915 6540 PL_thistoken = 0;
5db06880
NC
6541
6542 d = s;
6543 s = SKIPSPACE2(s,tmpwhite);
6544#else
09bef843 6545 s = skipspace(s);
5db06880 6546#endif
09bef843 6547
7e2040f0 6548 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
09bef843
SB
6549 (*s == ':' && s[1] == ':'))
6550 {
5db06880
NC
6551#ifdef PERL_MAD
6552 SV *nametoke;
6553#endif
6554
09bef843
SB
6555 PL_expect = XBLOCK;
6556 attrful = XATTRBLOCK;
b1b65b59
JH
6557 /* remember buffer pos'n for later force_word */
6558 tboffset = s - PL_oldbufptr;
09bef843 6559 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5db06880
NC
6560#ifdef PERL_MAD
6561 if (PL_madskills)
6562 nametoke = newSVpvn(s, d - s);
6563#endif
09bef843
SB
6564 if (strchr(tmpbuf, ':'))
6565 sv_setpv(PL_subname, tmpbuf);
6566 else {
6567 sv_setsv(PL_subname,PL_curstname);
396482e1 6568 sv_catpvs(PL_subname,"::");
09bef843
SB
6569 sv_catpvn(PL_subname,tmpbuf,len);
6570 }
09bef843 6571 have_name = TRUE;
5db06880
NC
6572
6573#ifdef PERL_MAD
6574
6575 start_force(0);
6576 CURMAD('X', nametoke);
6577 CURMAD('_', tmpwhite);
6578 (void) force_word(PL_oldbufptr + tboffset, WORD,
6579 FALSE, TRUE, TRUE);
6580
6581 s = SKIPSPACE2(d,tmpwhite);
6582#else
6583 s = skipspace(d);
6584#endif
09bef843 6585 }
463ee0b2 6586 else {
09bef843
SB
6587 if (key == KEY_my)
6588 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6589 PL_expect = XTERMBLOCK;
6590 attrful = XATTRTERM;
c69006e4 6591 sv_setpvn(PL_subname,"?",1);
09bef843 6592 have_name = FALSE;
463ee0b2 6593 }
4633a7c4 6594
09bef843
SB
6595 if (key == KEY_format) {
6596 if (*s == '=')
6597 PL_lex_formbrack = PL_lex_brackets + 1;
5db06880 6598#ifdef PERL_MAD
cd81e915 6599 PL_thistoken = subtoken;
5db06880
NC
6600 s = d;
6601#else
09bef843 6602 if (have_name)
b1b65b59
JH
6603 (void) force_word(PL_oldbufptr + tboffset, WORD,
6604 FALSE, TRUE, TRUE);
5db06880 6605#endif
09bef843
SB
6606 OPERATOR(FORMAT);
6607 }
79072805 6608
09bef843
SB
6609 /* Look for a prototype */
6610 if (*s == '(') {
d9f2850e
RGS
6611 char *p;
6612 bool bad_proto = FALSE;
6613 const bool warnsyntax = ckWARN(WARN_SYNTAX);
09bef843 6614
5db06880 6615 s = scan_str(s,!!PL_madskills,FALSE);
37fd879b 6616 if (!s)
09bef843 6617 Perl_croak(aTHX_ "Prototype not terminated");
2f758a16 6618 /* strip spaces and check for bad characters */
09bef843
SB
6619 d = SvPVX(PL_lex_stuff);
6620 tmp = 0;
d9f2850e
RGS
6621 for (p = d; *p; ++p) {
6622 if (!isSPACE(*p)) {
6623 d[tmp++] = *p;
b13fd70a 6624 if (warnsyntax && !strchr("$@%*;[]&\\_", *p))
d9f2850e 6625 bad_proto = TRUE;
d37a9538 6626 }
09bef843 6627 }
d9f2850e
RGS
6628 d[tmp] = '\0';
6629 if (bad_proto)
6630 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6631 "Illegal character in prototype for %"SVf" : %s",
6632 (void*)PL_subname, d);
b162af07 6633 SvCUR_set(PL_lex_stuff, tmp);
09bef843 6634 have_proto = TRUE;
68dc0745 6635
5db06880
NC
6636#ifdef PERL_MAD
6637 start_force(0);
cd81e915 6638 CURMAD('q', PL_thisopen);
5db06880 6639 CURMAD('_', tmpwhite);
cd81e915
NC
6640 CURMAD('=', PL_thisstuff);
6641 CURMAD('Q', PL_thisclose);
5db06880
NC
6642 NEXTVAL_NEXTTOKE.opval =
6643 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6644 PL_lex_stuff = Nullsv;
6645 force_next(THING);
6646
6647 s = SKIPSPACE2(s,tmpwhite);
6648#else
09bef843 6649 s = skipspace(s);
5db06880 6650#endif
4633a7c4 6651 }
09bef843
SB
6652 else
6653 have_proto = FALSE;
6654
6655 if (*s == ':' && s[1] != ':')
6656 PL_expect = attrful;
8e742a20
MHM
6657 else if (*s != '{' && key == KEY_sub) {
6658 if (!have_name)
6659 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6660 else if (*s != ';')
95b63a38 6661 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, (void*)PL_subname);
8e742a20 6662 }
09bef843 6663
5db06880
NC
6664#ifdef PERL_MAD
6665 start_force(0);
6666 if (tmpwhite) {
6667 if (PL_madskills)
6b29d1f5 6668 curmad('^', newSVpvs(""));
5db06880
NC
6669 CURMAD('_', tmpwhite);
6670 }
6671 force_next(0);
6672
cd81e915 6673 PL_thistoken = subtoken;
5db06880 6674#else
09bef843 6675 if (have_proto) {
9ded7720 6676 NEXTVAL_NEXTTOKE.opval =
b1b65b59 6677 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
a0714e2c 6678 PL_lex_stuff = NULL;
09bef843 6679 force_next(THING);
68dc0745 6680 }
5db06880 6681#endif
09bef843 6682 if (!have_name) {
c99da370 6683 sv_setpv(PL_subname,
10edeb5d
JH
6684 (const char *)
6685 (PL_curstash ? "__ANON__" : "__ANON__::__ANON__"));
09bef843 6686 TOKEN(ANONSUB);
4633a7c4 6687 }
5db06880 6688#ifndef PERL_MAD
b1b65b59
JH
6689 (void) force_word(PL_oldbufptr + tboffset, WORD,
6690 FALSE, TRUE, TRUE);
5db06880 6691#endif
09bef843
SB
6692 if (key == KEY_my)
6693 TOKEN(MYSUB);
6694 TOKEN(SUB);
4633a7c4 6695 }
79072805
LW
6696
6697 case KEY_system:
6698 set_csh();
a0d0e21e 6699 LOP(OP_SYSTEM,XREF);
79072805
LW
6700
6701 case KEY_symlink:
a0d0e21e 6702 LOP(OP_SYMLINK,XTERM);
79072805
LW
6703
6704 case KEY_syscall:
a0d0e21e 6705 LOP(OP_SYSCALL,XTERM);
79072805 6706
c07a80fd 6707 case KEY_sysopen:
6708 LOP(OP_SYSOPEN,XTERM);
6709
137443ea 6710 case KEY_sysseek:
6711 LOP(OP_SYSSEEK,XTERM);
6712
79072805 6713 case KEY_sysread:
a0d0e21e 6714 LOP(OP_SYSREAD,XTERM);
79072805
LW
6715
6716 case KEY_syswrite:
a0d0e21e 6717 LOP(OP_SYSWRITE,XTERM);
79072805
LW
6718
6719 case KEY_tr:
6720 s = scan_trans(s);
6721 TERM(sublex_start());
6722
6723 case KEY_tell:
6724 UNI(OP_TELL);
6725
6726 case KEY_telldir:
6727 UNI(OP_TELLDIR);
6728
463ee0b2 6729 case KEY_tie:
a0d0e21e 6730 LOP(OP_TIE,XTERM);
463ee0b2 6731
c07a80fd 6732 case KEY_tied:
6733 UNI(OP_TIED);
6734
79072805
LW
6735 case KEY_time:
6736 FUN0(OP_TIME);
6737
6738 case KEY_times:
6739 FUN0(OP_TMS);
6740
6741 case KEY_truncate:
a0d0e21e 6742 LOP(OP_TRUNCATE,XTERM);
79072805
LW
6743
6744 case KEY_uc:
6745 UNI(OP_UC);
6746
6747 case KEY_ucfirst:
6748 UNI(OP_UCFIRST);
6749
463ee0b2
LW
6750 case KEY_untie:
6751 UNI(OP_UNTIE);
6752
79072805 6753 case KEY_until:
57843af0 6754 yylval.ival = CopLINE(PL_curcop);
79072805
LW
6755 OPERATOR(UNTIL);
6756
6757 case KEY_unless:
57843af0 6758 yylval.ival = CopLINE(PL_curcop);
79072805
LW
6759 OPERATOR(UNLESS);
6760
6761 case KEY_unlink:
a0d0e21e 6762 LOP(OP_UNLINK,XTERM);
79072805
LW
6763
6764 case KEY_undef:
6f33ba73 6765 UNIDOR(OP_UNDEF);
79072805
LW
6766
6767 case KEY_unpack:
a0d0e21e 6768 LOP(OP_UNPACK,XTERM);
79072805
LW
6769
6770 case KEY_utime:
a0d0e21e 6771 LOP(OP_UTIME,XTERM);
79072805
LW
6772
6773 case KEY_umask:
6f33ba73 6774 UNIDOR(OP_UMASK);
79072805
LW
6775
6776 case KEY_unshift:
a0d0e21e
LW
6777 LOP(OP_UNSHIFT,XTERM);
6778
6779 case KEY_use:
468aa647 6780 s = tokenize_use(1, s);
a0d0e21e 6781 OPERATOR(USE);
79072805
LW
6782
6783 case KEY_values:
6784 UNI(OP_VALUES);
6785
6786 case KEY_vec:
a0d0e21e 6787 LOP(OP_VEC,XTERM);
79072805 6788
0d863452
RH
6789 case KEY_when:
6790 yylval.ival = CopLINE(PL_curcop);
6791 OPERATOR(WHEN);
6792
79072805 6793 case KEY_while:
57843af0 6794 yylval.ival = CopLINE(PL_curcop);
79072805
LW
6795 OPERATOR(WHILE);
6796
6797 case KEY_warn:
3280af22 6798 PL_hints |= HINT_BLOCK_SCOPE;
a0d0e21e 6799 LOP(OP_WARN,XTERM);
79072805
LW
6800
6801 case KEY_wait:
6802 FUN0(OP_WAIT);
6803
6804 case KEY_waitpid:
a0d0e21e 6805 LOP(OP_WAITPID,XTERM);
79072805
LW
6806
6807 case KEY_wantarray:
6808 FUN0(OP_WANTARRAY);
6809
6810 case KEY_write:
9d116dd7
JH
6811#ifdef EBCDIC
6812 {
df3728a2
JH
6813 char ctl_l[2];
6814 ctl_l[0] = toCTRL('L');
6815 ctl_l[1] = '\0';
fafc274c 6816 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
9d116dd7
JH
6817 }
6818#else
fafc274c
NC
6819 /* Make sure $^L is defined */
6820 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
9d116dd7 6821#endif
79072805
LW
6822 UNI(OP_ENTERWRITE);
6823
6824 case KEY_x:
3280af22 6825 if (PL_expect == XOPERATOR)
79072805
LW
6826 Mop(OP_REPEAT);
6827 check_uni();
6828 goto just_a_word;
6829
a0d0e21e
LW
6830 case KEY_xor:
6831 yylval.ival = OP_XOR;
6832 OPERATOR(OROP);
6833
79072805
LW
6834 case KEY_y:
6835 s = scan_trans(s);
6836 TERM(sublex_start());
6837 }
49dc05e3 6838 }}
79072805 6839}
bf4acbe4
GS
6840#ifdef __SC__
6841#pragma segment Main
6842#endif
79072805 6843
e930465f
JH
6844static int
6845S_pending_ident(pTHX)
8eceec63 6846{
97aff369 6847 dVAR;
8eceec63 6848 register char *d;
bbd11bfc 6849 PADOFFSET tmp = 0;
8eceec63
SC
6850 /* pit holds the identifier we read and pending_ident is reset */
6851 char pit = PL_pending_ident;
6852 PL_pending_ident = 0;
6853
cd81e915 6854 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
8eceec63 6855 DEBUG_T({ PerlIO_printf(Perl_debug_log,
b6007c36 6856 "### Pending identifier '%s'\n", PL_tokenbuf); });
8eceec63
SC
6857
6858 /* if we're in a my(), we can't allow dynamics here.
6859 $foo'bar has already been turned into $foo::bar, so
6860 just check for colons.
6861
6862 if it's a legal name, the OP is a PADANY.
6863 */
6864 if (PL_in_my) {
6865 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
6866 if (strchr(PL_tokenbuf,':'))
6867 yyerror(Perl_form(aTHX_ "No package name allowed for "
6868 "variable %s in \"our\"",
6869 PL_tokenbuf));
dd2155a4 6870 tmp = allocmy(PL_tokenbuf);
8eceec63
SC
6871 }
6872 else {
6873 if (strchr(PL_tokenbuf,':'))
952306ac
RGS
6874 yyerror(Perl_form(aTHX_ PL_no_myglob,
6875 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
8eceec63
SC
6876
6877 yylval.opval = newOP(OP_PADANY, 0);
dd2155a4 6878 yylval.opval->op_targ = allocmy(PL_tokenbuf);
8eceec63
SC
6879 return PRIVATEREF;
6880 }
6881 }
6882
6883 /*
6884 build the ops for accesses to a my() variable.
6885
6886 Deny my($a) or my($b) in a sort block, *if* $a or $b is
6887 then used in a comparison. This catches most, but not
6888 all cases. For instance, it catches
6889 sort { my($a); $a <=> $b }
6890 but not
6891 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6892 (although why you'd do that is anyone's guess).
6893 */
6894
6895 if (!strchr(PL_tokenbuf,':')) {
8716503d
DM
6896 if (!PL_in_my)
6897 tmp = pad_findmy(PL_tokenbuf);
6898 if (tmp != NOT_IN_PAD) {
8eceec63 6899 /* might be an "our" variable" */
00b1698f 6900 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
8eceec63 6901 /* build ops for a bareword */
b64e5050
AL
6902 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
6903 HEK * const stashname = HvNAME_HEK(stash);
6904 SV * const sym = newSVhek(stashname);
396482e1 6905 sv_catpvs(sym, "::");
8eceec63
SC
6906 sv_catpv(sym, PL_tokenbuf+1);
6907 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6908 yylval.opval->op_private = OPpCONST_ENTERED;
7a5fd60d 6909 gv_fetchsv(sym,
8eceec63
SC
6910 (PL_in_eval
6911 ? (GV_ADDMULTI | GV_ADDINEVAL)
700078d2 6912 : GV_ADDMULTI
8eceec63
SC
6913 ),
6914 ((PL_tokenbuf[0] == '$') ? SVt_PV
6915 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6916 : SVt_PVHV));
6917 return WORD;
6918 }
6919
6920 /* if it's a sort block and they're naming $a or $b */
6921 if (PL_last_lop_op == OP_SORT &&
6922 PL_tokenbuf[0] == '$' &&
6923 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
6924 && !PL_tokenbuf[2])
6925 {
6926 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
6927 d < PL_bufend && *d != '\n';
6928 d++)
6929 {
6930 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
6931 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
6932 PL_tokenbuf);
6933 }
6934 }
6935 }
6936
6937 yylval.opval = newOP(OP_PADANY, 0);
6938 yylval.opval->op_targ = tmp;
6939 return PRIVATEREF;
6940 }
6941 }
6942
6943 /*
6944 Whine if they've said @foo in a doublequoted string,
6945 and @foo isn't a variable we can find in the symbol
6946 table.
6947 */
6948 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
f776e3cd 6949 GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
8eceec63
SC
6950 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
6951 && ckWARN(WARN_AMBIGUOUS))
6952 {
6953 /* Downgraded from fatal to warning 20000522 mjd */
9014280d 6954 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
8eceec63
SC
6955 "Possible unintended interpolation of %s in string",
6956 PL_tokenbuf);
6957 }
6958 }
6959
6960 /* build ops for a bareword */
6961 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
6962 yylval.opval->op_private = OPpCONST_ENTERED;
adc51b97
RGS
6963 gv_fetchpv(
6964 PL_tokenbuf+1,
d6069db2
RGS
6965 /* If the identifier refers to a stash, don't autovivify it.
6966 * Change 24660 had the side effect of causing symbol table
6967 * hashes to always be defined, even if they were freshly
6968 * created and the only reference in the entire program was
6969 * the single statement with the defined %foo::bar:: test.
6970 * It appears that all code in the wild doing this actually
6971 * wants to know whether sub-packages have been loaded, so
6972 * by avoiding auto-vivifying symbol tables, we ensure that
6973 * defined %foo::bar:: continues to be false, and the existing
6974 * tests still give the expected answers, even though what
6975 * they're actually testing has now changed subtly.
6976 */
6977 (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
6978 ? 0
6979 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
adc51b97
RGS
6980 ((PL_tokenbuf[0] == '$') ? SVt_PV
6981 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6982 : SVt_PVHV));
8eceec63
SC
6983 return WORD;
6984}
6985
4c3bbe0f
MHM
6986/*
6987 * The following code was generated by perl_keyword.pl.
6988 */
e2e1dd5a 6989
79072805 6990I32
5458a98a 6991Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
4c3bbe0f 6992{
952306ac 6993 dVAR;
4c3bbe0f
MHM
6994 switch (len)
6995 {
6996 case 1: /* 5 tokens of length 1 */
6997 switch (name[0])
e2e1dd5a 6998 {
4c3bbe0f
MHM
6999 case 'm':
7000 { /* m */
7001 return KEY_m;
7002 }
7003
4c3bbe0f
MHM
7004 case 'q':
7005 { /* q */
7006 return KEY_q;
7007 }
7008
4c3bbe0f
MHM
7009 case 's':
7010 { /* s */
7011 return KEY_s;
7012 }
7013
4c3bbe0f
MHM
7014 case 'x':
7015 { /* x */
7016 return -KEY_x;
7017 }
7018
4c3bbe0f
MHM
7019 case 'y':
7020 { /* y */
7021 return KEY_y;
7022 }
7023
4c3bbe0f
MHM
7024 default:
7025 goto unknown;
e2e1dd5a 7026 }
4c3bbe0f
MHM
7027
7028 case 2: /* 18 tokens of length 2 */
7029 switch (name[0])
e2e1dd5a 7030 {
4c3bbe0f
MHM
7031 case 'd':
7032 if (name[1] == 'o')
7033 { /* do */
7034 return KEY_do;
7035 }
7036
7037 goto unknown;
7038
7039 case 'e':
7040 if (name[1] == 'q')
7041 { /* eq */
7042 return -KEY_eq;
7043 }
7044
7045 goto unknown;
7046
7047 case 'g':
7048 switch (name[1])
7049 {
7050 case 'e':
7051 { /* ge */
7052 return -KEY_ge;
7053 }
7054
4c3bbe0f
MHM
7055 case 't':
7056 { /* gt */
7057 return -KEY_gt;
7058 }
7059
4c3bbe0f
MHM
7060 default:
7061 goto unknown;
7062 }
7063
7064 case 'i':
7065 if (name[1] == 'f')
7066 { /* if */
7067 return KEY_if;
7068 }
7069
7070 goto unknown;
7071
7072 case 'l':
7073 switch (name[1])
7074 {
7075 case 'c':
7076 { /* lc */
7077 return -KEY_lc;
7078 }
7079
4c3bbe0f
MHM
7080 case 'e':
7081 { /* le */
7082 return -KEY_le;
7083 }
7084
4c3bbe0f
MHM
7085 case 't':
7086 { /* lt */
7087 return -KEY_lt;
7088 }
7089
4c3bbe0f
MHM
7090 default:
7091 goto unknown;
7092 }
7093
7094 case 'm':
7095 if (name[1] == 'y')
7096 { /* my */
7097 return KEY_my;
7098 }
7099
7100 goto unknown;
7101
7102 case 'n':
7103 switch (name[1])
7104 {
7105 case 'e':
7106 { /* ne */
7107 return -KEY_ne;
7108 }
7109
4c3bbe0f
MHM
7110 case 'o':
7111 { /* no */
7112 return KEY_no;
7113 }
7114
4c3bbe0f
MHM
7115 default:
7116 goto unknown;
7117 }
7118
7119 case 'o':
7120 if (name[1] == 'r')
7121 { /* or */
7122 return -KEY_or;
7123 }
7124
7125 goto unknown;
7126
7127 case 'q':
7128 switch (name[1])
7129 {
7130 case 'q':
7131 { /* qq */
7132 return KEY_qq;
7133 }
7134
4c3bbe0f
MHM
7135 case 'r':
7136 { /* qr */
7137 return KEY_qr;
7138 }
7139
4c3bbe0f
MHM
7140 case 'w':
7141 { /* qw */
7142 return KEY_qw;
7143 }
7144
4c3bbe0f
MHM
7145 case 'x':
7146 { /* qx */
7147 return KEY_qx;
7148 }
7149
4c3bbe0f
MHM
7150 default:
7151 goto unknown;
7152 }
7153
7154 case 't':
7155 if (name[1] == 'r')
7156 { /* tr */
7157 return KEY_tr;
7158 }
7159
7160 goto unknown;
7161
7162 case 'u':
7163 if (name[1] == 'c')
7164 { /* uc */
7165 return -KEY_uc;
7166 }
7167
7168 goto unknown;
7169
7170 default:
7171 goto unknown;
e2e1dd5a 7172 }
4c3bbe0f 7173
0d863452 7174 case 3: /* 29 tokens of length 3 */
4c3bbe0f 7175 switch (name[0])
e2e1dd5a 7176 {
4c3bbe0f
MHM
7177 case 'E':
7178 if (name[1] == 'N' &&
7179 name[2] == 'D')
7180 { /* END */
7181 return KEY_END;
7182 }
7183
7184 goto unknown;
7185
7186 case 'a':
7187 switch (name[1])
7188 {
7189 case 'b':
7190 if (name[2] == 's')
7191 { /* abs */
7192 return -KEY_abs;
7193 }
7194
7195 goto unknown;
7196
7197 case 'n':
7198 if (name[2] == 'd')
7199 { /* and */
7200 return -KEY_and;
7201 }
7202
7203 goto unknown;
7204
7205 default:
7206 goto unknown;
7207 }
7208
7209 case 'c':
7210 switch (name[1])
7211 {
7212 case 'h':
7213 if (name[2] == 'r')
7214 { /* chr */
7215 return -KEY_chr;
7216 }
7217
7218 goto unknown;
7219
7220 case 'm':
7221 if (name[2] == 'p')
7222 { /* cmp */
7223 return -KEY_cmp;
7224 }
7225
7226 goto unknown;
7227
7228 case 'o':
7229 if (name[2] == 's')
7230 { /* cos */
7231 return -KEY_cos;
7232 }
7233
7234 goto unknown;
7235
7236 default:
7237 goto unknown;
7238 }
7239
7240 case 'd':
7241 if (name[1] == 'i' &&
7242 name[2] == 'e')
7243 { /* die */
7244 return -KEY_die;
7245 }
7246
7247 goto unknown;
7248
7249 case 'e':
7250 switch (name[1])
7251 {
7252 case 'o':
7253 if (name[2] == 'f')
7254 { /* eof */
7255 return -KEY_eof;
7256 }
7257
7258 goto unknown;
7259
7260 case 'r':
7261 if (name[2] == 'r')
7262 { /* err */
5458a98a 7263 return (all_keywords || FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
4c3bbe0f
MHM
7264 }
7265
7266 goto unknown;
7267
7268 case 'x':
7269 if (name[2] == 'p')
7270 { /* exp */
7271 return -KEY_exp;
7272 }
7273
7274 goto unknown;
7275
7276 default:
7277 goto unknown;
7278 }
7279
7280 case 'f':
7281 if (name[1] == 'o' &&
7282 name[2] == 'r')
7283 { /* for */
7284 return KEY_for;
7285 }
7286
7287 goto unknown;
7288
7289 case 'h':
7290 if (name[1] == 'e' &&
7291 name[2] == 'x')
7292 { /* hex */
7293 return -KEY_hex;
7294 }
7295
7296 goto unknown;
7297
7298 case 'i':
7299 if (name[1] == 'n' &&
7300 name[2] == 't')
7301 { /* int */
7302 return -KEY_int;
7303 }
7304
7305 goto unknown;
7306
7307 case 'l':
7308 if (name[1] == 'o' &&
7309 name[2] == 'g')
7310 { /* log */
7311 return -KEY_log;
7312 }
7313
7314 goto unknown;
7315
7316 case 'm':
7317 if (name[1] == 'a' &&
7318 name[2] == 'p')
7319 { /* map */
7320 return KEY_map;
7321 }
7322
7323 goto unknown;
7324
7325 case 'n':
7326 if (name[1] == 'o' &&
7327 name[2] == 't')
7328 { /* not */
7329 return -KEY_not;
7330 }
7331
7332 goto unknown;
7333
7334 case 'o':
7335 switch (name[1])
7336 {
7337 case 'c':
7338 if (name[2] == 't')
7339 { /* oct */
7340 return -KEY_oct;
7341 }
7342
7343 goto unknown;
7344
7345 case 'r':
7346 if (name[2] == 'd')
7347 { /* ord */
7348 return -KEY_ord;
7349 }
7350
7351 goto unknown;
7352
7353 case 'u':
7354 if (name[2] == 'r')
7355 { /* our */
7356 return KEY_our;
7357 }
7358
7359 goto unknown;
7360
7361 default:
7362 goto unknown;
7363 }
7364
7365 case 'p':
7366 if (name[1] == 'o')
7367 {
7368 switch (name[2])
7369 {
7370 case 'p':
7371 { /* pop */
7372 return -KEY_pop;
7373 }
7374
4c3bbe0f
MHM
7375 case 's':
7376 { /* pos */
7377 return KEY_pos;
7378 }
7379
4c3bbe0f
MHM
7380 default:
7381 goto unknown;
7382 }
7383 }
7384
7385 goto unknown;
7386
7387 case 'r':
7388 if (name[1] == 'e' &&
7389 name[2] == 'f')
7390 { /* ref */
7391 return -KEY_ref;
7392 }
7393
7394 goto unknown;
7395
7396 case 's':
7397 switch (name[1])
7398 {
0d863452
RH
7399 case 'a':
7400 if (name[2] == 'y')
7401 { /* say */
e3e804c9 7402 return (all_keywords || FEATURE_IS_ENABLED("say") ? KEY_say : 0);
0d863452
RH
7403 }
7404
7405 goto unknown;
7406
4c3bbe0f
MHM
7407 case 'i':
7408 if (name[2] == 'n')
7409 { /* sin */
7410 return -KEY_sin;
7411 }
7412
7413 goto unknown;
7414
7415 case 'u':
7416 if (name[2] == 'b')
7417 { /* sub */
7418 return KEY_sub;
7419 }
7420
7421 goto unknown;
7422
7423 default:
7424 goto unknown;
7425 }
7426
7427 case 't':
7428 if (name[1] == 'i' &&
7429 name[2] == 'e')
7430 { /* tie */
7431 return KEY_tie;
7432 }
7433
7434 goto unknown;
7435
7436 case 'u':
7437 if (name[1] == 's' &&
7438 name[2] == 'e')
7439 { /* use */
7440 return KEY_use;
7441 }
7442
7443 goto unknown;
7444
7445 case 'v':
7446 if (name[1] == 'e' &&
7447 name[2] == 'c')
7448 { /* vec */
7449 return -KEY_vec;
7450 }
7451
7452 goto unknown;
7453
7454 case 'x':
7455 if (name[1] == 'o' &&
7456 name[2] == 'r')
7457 { /* xor */
7458 return -KEY_xor;
7459 }
7460
7461 goto unknown;
7462
7463 default:
7464 goto unknown;
e2e1dd5a 7465 }
4c3bbe0f 7466
0d863452 7467 case 4: /* 41 tokens of length 4 */
4c3bbe0f 7468 switch (name[0])
e2e1dd5a 7469 {
4c3bbe0f
MHM
7470 case 'C':
7471 if (name[1] == 'O' &&
7472 name[2] == 'R' &&
7473 name[3] == 'E')
7474 { /* CORE */
7475 return -KEY_CORE;
7476 }
7477
7478 goto unknown;
7479
7480 case 'I':
7481 if (name[1] == 'N' &&
7482 name[2] == 'I' &&
7483 name[3] == 'T')
7484 { /* INIT */
7485 return KEY_INIT;
7486 }
7487
7488 goto unknown;
7489
7490 case 'b':
7491 if (name[1] == 'i' &&
7492 name[2] == 'n' &&
7493 name[3] == 'd')
7494 { /* bind */
7495 return -KEY_bind;
7496 }
7497
7498 goto unknown;
7499
7500 case 'c':
7501 if (name[1] == 'h' &&
7502 name[2] == 'o' &&
7503 name[3] == 'p')
7504 { /* chop */
7505 return -KEY_chop;
7506 }
7507
7508 goto unknown;
7509
7510 case 'd':
7511 if (name[1] == 'u' &&
7512 name[2] == 'm' &&
7513 name[3] == 'p')
7514 { /* dump */
7515 return -KEY_dump;
7516 }
7517
7518 goto unknown;
7519
7520 case 'e':
7521 switch (name[1])
7522 {
7523 case 'a':
7524 if (name[2] == 'c' &&
7525 name[3] == 'h')
7526 { /* each */
7527 return -KEY_each;
7528 }
7529
7530 goto unknown;
7531
7532 case 'l':
7533 if (name[2] == 's' &&
7534 name[3] == 'e')
7535 { /* else */
7536 return KEY_else;
7537 }
7538
7539 goto unknown;
7540
7541 case 'v':
7542 if (name[2] == 'a' &&
7543 name[3] == 'l')
7544 { /* eval */
7545 return KEY_eval;
7546 }
7547
7548 goto unknown;
7549
7550 case 'x':
7551 switch (name[2])
7552 {
7553 case 'e':
7554 if (name[3] == 'c')
7555 { /* exec */
7556 return -KEY_exec;
7557 }
7558
7559 goto unknown;
7560
7561 case 'i':
7562 if (name[3] == 't')
7563 { /* exit */
7564 return -KEY_exit;
7565 }
7566
7567 goto unknown;
7568
7569 default:
7570 goto unknown;
7571 }
7572
7573 default:
7574 goto unknown;
7575 }
7576
7577 case 'f':
7578 if (name[1] == 'o' &&
7579 name[2] == 'r' &&
7580 name[3] == 'k')
7581 { /* fork */
7582 return -KEY_fork;
7583 }
7584
7585 goto unknown;
7586
7587 case 'g':
7588 switch (name[1])
7589 {
7590 case 'e':
7591 if (name[2] == 't' &&
7592 name[3] == 'c')
7593 { /* getc */
7594 return -KEY_getc;
7595 }
7596
7597 goto unknown;
7598
7599 case 'l':
7600 if (name[2] == 'o' &&
7601 name[3] == 'b')
7602 { /* glob */
7603 return KEY_glob;
7604 }
7605
7606 goto unknown;
7607
7608 case 'o':
7609 if (name[2] == 't' &&
7610 name[3] == 'o')
7611 { /* goto */
7612 return KEY_goto;
7613 }
7614
7615 goto unknown;
7616
7617 case 'r':
7618 if (name[2] == 'e' &&
7619 name[3] == 'p')
7620 { /* grep */
7621 return KEY_grep;
7622 }
7623
7624 goto unknown;
7625
7626 default:
7627 goto unknown;
7628 }
7629
7630 case 'j':
7631 if (name[1] == 'o' &&
7632 name[2] == 'i' &&
7633 name[3] == 'n')
7634 { /* join */
7635 return -KEY_join;
7636 }
7637
7638 goto unknown;
7639
7640 case 'k':
7641 switch (name[1])
7642 {
7643 case 'e':
7644 if (name[2] == 'y' &&
7645 name[3] == 's')
7646 { /* keys */
7647 return -KEY_keys;
7648 }
7649
7650 goto unknown;
7651
7652 case 'i':
7653 if (name[2] == 'l' &&
7654 name[3] == 'l')
7655 { /* kill */
7656 return -KEY_kill;
7657 }
7658
7659 goto unknown;
7660
7661 default:
7662 goto unknown;
7663 }
7664
7665 case 'l':
7666 switch (name[1])
7667 {
7668 case 'a':
7669 if (name[2] == 's' &&
7670 name[3] == 't')
7671 { /* last */
7672 return KEY_last;
7673 }
7674
7675 goto unknown;
7676
7677 case 'i':
7678 if (name[2] == 'n' &&
7679 name[3] == 'k')
7680 { /* link */
7681 return -KEY_link;
7682 }
7683
7684 goto unknown;
7685
7686 case 'o':
7687 if (name[2] == 'c' &&
7688 name[3] == 'k')
7689 { /* lock */
7690 return -KEY_lock;
7691 }
7692
7693 goto unknown;
7694
7695 default:
7696 goto unknown;
7697 }
7698
7699 case 'n':
7700 if (name[1] == 'e' &&
7701 name[2] == 'x' &&
7702 name[3] == 't')
7703 { /* next */
7704 return KEY_next;
7705 }
7706
7707 goto unknown;
7708
7709 case 'o':
7710 if (name[1] == 'p' &&
7711 name[2] == 'e' &&
7712 name[3] == 'n')
7713 { /* open */
7714 return -KEY_open;
7715 }
7716
7717 goto unknown;
7718
7719 case 'p':
7720 switch (name[1])
7721 {
7722 case 'a':
7723 if (name[2] == 'c' &&
7724 name[3] == 'k')
7725 { /* pack */
7726 return -KEY_pack;
7727 }
7728
7729 goto unknown;
7730
7731 case 'i':
7732 if (name[2] == 'p' &&
7733 name[3] == 'e')
7734 { /* pipe */
7735 return -KEY_pipe;
7736 }
7737
7738 goto unknown;
7739
7740 case 'u':
7741 if (name[2] == 's' &&
7742 name[3] == 'h')
7743 { /* push */
7744 return -KEY_push;
7745 }
7746
7747 goto unknown;
7748
7749 default:
7750 goto unknown;
7751 }
7752
7753 case 'r':
7754 switch (name[1])
7755 {
7756 case 'a':
7757 if (name[2] == 'n' &&
7758 name[3] == 'd')
7759 { /* rand */
7760 return -KEY_rand;
7761 }
7762
7763 goto unknown;
7764
7765 case 'e':
7766 switch (name[2])
7767 {
7768 case 'a':
7769 if (name[3] == 'd')
7770 { /* read */
7771 return -KEY_read;
7772 }
7773
7774 goto unknown;
7775
7776 case 'c':
7777 if (name[3] == 'v')
7778 { /* recv */
7779 return -KEY_recv;
7780 }
7781
7782 goto unknown;
7783
7784 case 'd':
7785 if (name[3] == 'o')
7786 { /* redo */
7787 return KEY_redo;
7788 }
7789
7790 goto unknown;
7791
7792 default:
7793 goto unknown;
7794 }
7795
7796 default:
7797 goto unknown;
7798 }
7799
7800 case 's':
7801 switch (name[1])
7802 {
7803 case 'e':
7804 switch (name[2])
7805 {
7806 case 'e':
7807 if (name[3] == 'k')
7808 { /* seek */
7809 return -KEY_seek;
7810 }
7811
7812 goto unknown;
7813
7814 case 'n':
7815 if (name[3] == 'd')
7816 { /* send */
7817 return -KEY_send;
7818 }
7819
7820 goto unknown;
7821
7822 default:
7823 goto unknown;
7824 }
7825
7826 case 'o':
7827 if (name[2] == 'r' &&
7828 name[3] == 't')
7829 { /* sort */
7830 return KEY_sort;
7831 }
7832
7833 goto unknown;
7834
7835 case 'q':
7836 if (name[2] == 'r' &&
7837 name[3] == 't')
7838 { /* sqrt */
7839 return -KEY_sqrt;
7840 }
7841
7842 goto unknown;
7843
7844 case 't':
7845 if (name[2] == 'a' &&
7846 name[3] == 't')
7847 { /* stat */
7848 return -KEY_stat;
7849 }
7850
7851 goto unknown;
7852
7853 default:
7854 goto unknown;
7855 }
7856
7857 case 't':
7858 switch (name[1])
7859 {
7860 case 'e':
7861 if (name[2] == 'l' &&
7862 name[3] == 'l')
7863 { /* tell */
7864 return -KEY_tell;
7865 }
7866
7867 goto unknown;
7868
7869 case 'i':
7870 switch (name[2])
7871 {
7872 case 'e':
7873 if (name[3] == 'd')
7874 { /* tied */
7875 return KEY_tied;
7876 }
7877
7878 goto unknown;
7879
7880 case 'm':
7881 if (name[3] == 'e')
7882 { /* time */
7883 return -KEY_time;
7884 }
7885
7886 goto unknown;
7887
7888 default:
7889 goto unknown;
7890 }
7891
7892 default:
7893 goto unknown;
7894 }
7895
7896 case 'w':
0d863452 7897 switch (name[1])
4c3bbe0f 7898 {
0d863452 7899 case 'a':
952306ac
RGS
7900 switch (name[2])
7901 {
7902 case 'i':
7903 if (name[3] == 't')
7904 { /* wait */
7905 return -KEY_wait;
7906 }
4c3bbe0f 7907
952306ac 7908 goto unknown;
4c3bbe0f 7909
952306ac
RGS
7910 case 'r':
7911 if (name[3] == 'n')
7912 { /* warn */
7913 return -KEY_warn;
7914 }
4c3bbe0f 7915
952306ac 7916 goto unknown;
4c3bbe0f 7917
952306ac
RGS
7918 default:
7919 goto unknown;
7920 }
0d863452
RH
7921
7922 case 'h':
7923 if (name[2] == 'e' &&
7924 name[3] == 'n')
7925 { /* when */
5458a98a 7926 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
952306ac 7927 }
4c3bbe0f 7928
952306ac 7929 goto unknown;
4c3bbe0f 7930
952306ac
RGS
7931 default:
7932 goto unknown;
7933 }
4c3bbe0f 7934
0d863452
RH
7935 default:
7936 goto unknown;
7937 }
7938
952306ac 7939 case 5: /* 39 tokens of length 5 */
4c3bbe0f 7940 switch (name[0])
e2e1dd5a 7941 {
4c3bbe0f
MHM
7942 case 'B':
7943 if (name[1] == 'E' &&
7944 name[2] == 'G' &&
7945 name[3] == 'I' &&
7946 name[4] == 'N')
7947 { /* BEGIN */
7948 return KEY_BEGIN;
7949 }
7950
7951 goto unknown;
7952
7953 case 'C':
7954 if (name[1] == 'H' &&
7955 name[2] == 'E' &&
7956 name[3] == 'C' &&
7957 name[4] == 'K')
7958 { /* CHECK */
7959 return KEY_CHECK;
7960 }
7961
7962 goto unknown;
7963
7964 case 'a':
7965 switch (name[1])
7966 {
7967 case 'l':
7968 if (name[2] == 'a' &&
7969 name[3] == 'r' &&
7970 name[4] == 'm')
7971 { /* alarm */
7972 return -KEY_alarm;
7973 }
7974
7975 goto unknown;
7976
7977 case 't':
7978 if (name[2] == 'a' &&
7979 name[3] == 'n' &&
7980 name[4] == '2')
7981 { /* atan2 */
7982 return -KEY_atan2;
7983 }
7984
7985 goto unknown;
7986
7987 default:
7988 goto unknown;
7989 }
7990
7991 case 'b':
0d863452
RH
7992 switch (name[1])
7993 {
7994 case 'l':
7995 if (name[2] == 'e' &&
952306ac
RGS
7996 name[3] == 's' &&
7997 name[4] == 's')
7998 { /* bless */
7999 return -KEY_bless;
8000 }
4c3bbe0f 8001
952306ac 8002 goto unknown;
4c3bbe0f 8003
0d863452
RH
8004 case 'r':
8005 if (name[2] == 'e' &&
8006 name[3] == 'a' &&
8007 name[4] == 'k')
8008 { /* break */
5458a98a 8009 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
0d863452
RH
8010 }
8011
8012 goto unknown;
8013
8014 default:
8015 goto unknown;
8016 }
8017
4c3bbe0f
MHM
8018 case 'c':
8019 switch (name[1])
8020 {
8021 case 'h':
8022 switch (name[2])
8023 {
8024 case 'd':
8025 if (name[3] == 'i' &&
8026 name[4] == 'r')
8027 { /* chdir */
8028 return -KEY_chdir;
8029 }
8030
8031 goto unknown;
8032
8033 case 'm':
8034 if (name[3] == 'o' &&
8035 name[4] == 'd')
8036 { /* chmod */
8037 return -KEY_chmod;
8038 }
8039
8040 goto unknown;
8041
8042 case 'o':
8043 switch (name[3])
8044 {
8045 case 'm':
8046 if (name[4] == 'p')
8047 { /* chomp */
8048 return -KEY_chomp;
8049 }
8050
8051 goto unknown;
8052
8053 case 'w':
8054 if (name[4] == 'n')
8055 { /* chown */
8056 return -KEY_chown;
8057 }
8058
8059 goto unknown;
8060
8061 default:
8062 goto unknown;
8063 }
8064
8065 default:
8066 goto unknown;
8067 }
8068
8069 case 'l':
8070 if (name[2] == 'o' &&
8071 name[3] == 's' &&
8072 name[4] == 'e')
8073 { /* close */
8074 return -KEY_close;
8075 }
8076
8077 goto unknown;
8078
8079 case 'r':
8080 if (name[2] == 'y' &&
8081 name[3] == 'p' &&
8082 name[4] == 't')
8083 { /* crypt */
8084 return -KEY_crypt;
8085 }
8086
8087 goto unknown;
8088
8089 default:
8090 goto unknown;
8091 }
8092
8093 case 'e':
8094 if (name[1] == 'l' &&
8095 name[2] == 's' &&
8096 name[3] == 'i' &&
8097 name[4] == 'f')
8098 { /* elsif */
8099 return KEY_elsif;
8100 }
8101
8102 goto unknown;
8103
8104 case 'f':
8105 switch (name[1])
8106 {
8107 case 'c':
8108 if (name[2] == 'n' &&
8109 name[3] == 't' &&
8110 name[4] == 'l')
8111 { /* fcntl */
8112 return -KEY_fcntl;
8113 }
8114
8115 goto unknown;
8116
8117 case 'l':
8118 if (name[2] == 'o' &&
8119 name[3] == 'c' &&
8120 name[4] == 'k')
8121 { /* flock */
8122 return -KEY_flock;
8123 }
8124
8125 goto unknown;
8126
8127 default:
8128 goto unknown;
8129 }
8130
0d863452
RH
8131 case 'g':
8132 if (name[1] == 'i' &&
8133 name[2] == 'v' &&
8134 name[3] == 'e' &&
8135 name[4] == 'n')
8136 { /* given */
5458a98a 8137 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
0d863452
RH
8138 }
8139
8140 goto unknown;
8141
4c3bbe0f
MHM
8142 case 'i':
8143 switch (name[1])
8144 {
8145 case 'n':
8146 if (name[2] == 'd' &&
8147 name[3] == 'e' &&
8148 name[4] == 'x')
8149 { /* index */
8150 return -KEY_index;
8151 }
8152
8153 goto unknown;
8154
8155 case 'o':
8156 if (name[2] == 'c' &&
8157 name[3] == 't' &&
8158 name[4] == 'l')
8159 { /* ioctl */
8160 return -KEY_ioctl;
8161 }
8162
8163 goto unknown;
8164
8165 default:
8166 goto unknown;
8167 }
8168
8169 case 'l':
8170 switch (name[1])
8171 {
8172 case 'o':
8173 if (name[2] == 'c' &&
8174 name[3] == 'a' &&
8175 name[4] == 'l')
8176 { /* local */
8177 return KEY_local;
8178 }
8179
8180 goto unknown;
8181
8182 case 's':
8183 if (name[2] == 't' &&
8184 name[3] == 'a' &&
8185 name[4] == 't')
8186 { /* lstat */
8187 return -KEY_lstat;
8188 }
8189
8190 goto unknown;
8191
8192 default:
8193 goto unknown;
8194 }
8195
8196 case 'm':
8197 if (name[1] == 'k' &&
8198 name[2] == 'd' &&
8199 name[3] == 'i' &&
8200 name[4] == 'r')
8201 { /* mkdir */
8202 return -KEY_mkdir;
8203 }
8204
8205 goto unknown;
8206
8207 case 'p':
8208 if (name[1] == 'r' &&
8209 name[2] == 'i' &&
8210 name[3] == 'n' &&
8211 name[4] == 't')
8212 { /* print */
8213 return KEY_print;
8214 }
8215
8216 goto unknown;
8217
8218 case 'r':
8219 switch (name[1])
8220 {
8221 case 'e':
8222 if (name[2] == 's' &&
8223 name[3] == 'e' &&
8224 name[4] == 't')
8225 { /* reset */
8226 return -KEY_reset;
8227 }
8228
8229 goto unknown;
8230
8231 case 'm':
8232 if (name[2] == 'd' &&
8233 name[3] == 'i' &&
8234 name[4] == 'r')
8235 { /* rmdir */
8236 return -KEY_rmdir;
8237 }
8238
8239 goto unknown;
8240
8241 default:
8242 goto unknown;
8243 }
8244
8245 case 's':
8246 switch (name[1])
8247 {
8248 case 'e':
8249 if (name[2] == 'm' &&
8250 name[3] == 'o' &&
8251 name[4] == 'p')
8252 { /* semop */
8253 return -KEY_semop;
8254 }
8255
8256 goto unknown;
8257
8258 case 'h':
8259 if (name[2] == 'i' &&
8260 name[3] == 'f' &&
8261 name[4] == 't')
8262 { /* shift */
8263 return -KEY_shift;
8264 }
8265
8266 goto unknown;
8267
8268 case 'l':
8269 if (name[2] == 'e' &&
8270 name[3] == 'e' &&
8271 name[4] == 'p')
8272 { /* sleep */
8273 return -KEY_sleep;
8274 }
8275
8276 goto unknown;
8277
8278 case 'p':
8279 if (name[2] == 'l' &&
8280 name[3] == 'i' &&
8281 name[4] == 't')
8282 { /* split */
8283 return KEY_split;
8284 }
8285
8286 goto unknown;
8287
8288 case 'r':
8289 if (name[2] == 'a' &&
8290 name[3] == 'n' &&
8291 name[4] == 'd')
8292 { /* srand */
8293 return -KEY_srand;
8294 }
8295
8296 goto unknown;
8297
8298 case 't':
952306ac
RGS
8299 switch (name[2])
8300 {
8301 case 'a':
8302 if (name[3] == 't' &&
8303 name[4] == 'e')
8304 { /* state */
5458a98a 8305 return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
952306ac 8306 }
4c3bbe0f 8307
952306ac
RGS
8308 goto unknown;
8309
8310 case 'u':
8311 if (name[3] == 'd' &&
8312 name[4] == 'y')
8313 { /* study */
8314 return KEY_study;
8315 }
8316
8317 goto unknown;
8318
8319 default:
8320 goto unknown;
8321 }
4c3bbe0f
MHM
8322
8323 default:
8324 goto unknown;
8325 }
8326
8327 case 't':
8328 if (name[1] == 'i' &&
8329 name[2] == 'm' &&
8330 name[3] == 'e' &&
8331 name[4] == 's')
8332 { /* times */
8333 return -KEY_times;
8334 }
8335
8336 goto unknown;
8337
8338 case 'u':
8339 switch (name[1])
8340 {
8341 case 'm':
8342 if (name[2] == 'a' &&
8343 name[3] == 's' &&
8344 name[4] == 'k')
8345 { /* umask */
8346 return -KEY_umask;
8347 }
8348
8349 goto unknown;
8350
8351 case 'n':
8352 switch (name[2])
8353 {
8354 case 'd':
8355 if (name[3] == 'e' &&
8356 name[4] == 'f')
8357 { /* undef */
8358 return KEY_undef;
8359 }
8360
8361 goto unknown;
8362
8363 case 't':
8364 if (name[3] == 'i')
8365 {
8366 switch (name[4])
8367 {
8368 case 'e':
8369 { /* untie */
8370 return KEY_untie;
8371 }
8372
4c3bbe0f
MHM
8373 case 'l':
8374 { /* until */
8375 return KEY_until;
8376 }
8377
4c3bbe0f
MHM
8378 default:
8379 goto unknown;
8380 }
8381 }
8382
8383 goto unknown;
8384
8385 default:
8386 goto unknown;
8387 }
8388
8389 case 't':
8390 if (name[2] == 'i' &&
8391 name[3] == 'm' &&
8392 name[4] == 'e')
8393 { /* utime */
8394 return -KEY_utime;
8395 }
8396
8397 goto unknown;
8398
8399 default:
8400 goto unknown;
8401 }
8402
8403 case 'w':
8404 switch (name[1])
8405 {
8406 case 'h':
8407 if (name[2] == 'i' &&
8408 name[3] == 'l' &&
8409 name[4] == 'e')
8410 { /* while */
8411 return KEY_while;
8412 }
8413
8414 goto unknown;
8415
8416 case 'r':
8417 if (name[2] == 'i' &&
8418 name[3] == 't' &&
8419 name[4] == 'e')
8420 { /* write */
8421 return -KEY_write;
8422 }
8423
8424 goto unknown;
8425
8426 default:
8427 goto unknown;
8428 }
8429
8430 default:
8431 goto unknown;
e2e1dd5a 8432 }
4c3bbe0f
MHM
8433
8434 case 6: /* 33 tokens of length 6 */
8435 switch (name[0])
8436 {
8437 case 'a':
8438 if (name[1] == 'c' &&
8439 name[2] == 'c' &&
8440 name[3] == 'e' &&
8441 name[4] == 'p' &&
8442 name[5] == 't')
8443 { /* accept */
8444 return -KEY_accept;
8445 }
8446
8447 goto unknown;
8448
8449 case 'c':
8450 switch (name[1])
8451 {
8452 case 'a':
8453 if (name[2] == 'l' &&
8454 name[3] == 'l' &&
8455 name[4] == 'e' &&
8456 name[5] == 'r')
8457 { /* caller */
8458 return -KEY_caller;
8459 }
8460
8461 goto unknown;
8462
8463 case 'h':
8464 if (name[2] == 'r' &&
8465 name[3] == 'o' &&
8466 name[4] == 'o' &&
8467 name[5] == 't')
8468 { /* chroot */
8469 return -KEY_chroot;
8470 }
8471
8472 goto unknown;
8473
8474 default:
8475 goto unknown;
8476 }
8477
8478 case 'd':
8479 if (name[1] == 'e' &&
8480 name[2] == 'l' &&
8481 name[3] == 'e' &&
8482 name[4] == 't' &&
8483 name[5] == 'e')
8484 { /* delete */
8485 return KEY_delete;
8486 }
8487
8488 goto unknown;
8489
8490 case 'e':
8491 switch (name[1])
8492 {
8493 case 'l':
8494 if (name[2] == 's' &&
8495 name[3] == 'e' &&
8496 name[4] == 'i' &&
8497 name[5] == 'f')
8498 { /* elseif */
8499 if(ckWARN_d(WARN_SYNTAX))
8500 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8501 }
8502
8503 goto unknown;
8504
8505 case 'x':
8506 if (name[2] == 'i' &&
8507 name[3] == 's' &&
8508 name[4] == 't' &&
8509 name[5] == 's')
8510 { /* exists */
8511 return KEY_exists;
8512 }
8513
8514 goto unknown;
8515
8516 default:
8517 goto unknown;
8518 }
8519
8520 case 'f':
8521 switch (name[1])
8522 {
8523 case 'i':
8524 if (name[2] == 'l' &&
8525 name[3] == 'e' &&
8526 name[4] == 'n' &&
8527 name[5] == 'o')
8528 { /* fileno */
8529 return -KEY_fileno;
8530 }
8531
8532 goto unknown;
8533
8534 case 'o':
8535 if (name[2] == 'r' &&
8536 name[3] == 'm' &&
8537 name[4] == 'a' &&
8538 name[5] == 't')
8539 { /* format */
8540 return KEY_format;
8541 }
8542
8543 goto unknown;
8544
8545 default:
8546 goto unknown;
8547 }
8548
8549 case 'g':
8550 if (name[1] == 'm' &&
8551 name[2] == 't' &&
8552 name[3] == 'i' &&
8553 name[4] == 'm' &&
8554 name[5] == 'e')
8555 { /* gmtime */
8556 return -KEY_gmtime;
8557 }
8558
8559 goto unknown;
8560
8561 case 'l':
8562 switch (name[1])
8563 {
8564 case 'e':
8565 if (name[2] == 'n' &&
8566 name[3] == 'g' &&
8567 name[4] == 't' &&
8568 name[5] == 'h')
8569 { /* length */
8570 return -KEY_length;
8571 }
8572
8573 goto unknown;
8574
8575 case 'i':
8576 if (name[2] == 's' &&
8577 name[3] == 't' &&
8578 name[4] == 'e' &&
8579 name[5] == 'n')
8580 { /* listen */
8581 return -KEY_listen;
8582 }
8583
8584 goto unknown;
8585
8586 default:
8587 goto unknown;
8588 }
8589
8590 case 'm':
8591 if (name[1] == 's' &&
8592 name[2] == 'g')
8593 {
8594 switch (name[3])
8595 {
8596 case 'c':
8597 if (name[4] == 't' &&
8598 name[5] == 'l')
8599 { /* msgctl */
8600 return -KEY_msgctl;
8601 }
8602
8603 goto unknown;
8604
8605 case 'g':
8606 if (name[4] == 'e' &&
8607 name[5] == 't')
8608 { /* msgget */
8609 return -KEY_msgget;
8610 }
8611
8612 goto unknown;
8613
8614 case 'r':
8615 if (name[4] == 'c' &&
8616 name[5] == 'v')
8617 { /* msgrcv */
8618 return -KEY_msgrcv;
8619 }
8620
8621 goto unknown;
8622
8623 case 's':
8624 if (name[4] == 'n' &&
8625 name[5] == 'd')
8626 { /* msgsnd */
8627 return -KEY_msgsnd;
8628 }
8629
8630 goto unknown;
8631
8632 default:
8633 goto unknown;
8634 }
8635 }
8636
8637 goto unknown;
8638
8639 case 'p':
8640 if (name[1] == 'r' &&
8641 name[2] == 'i' &&
8642 name[3] == 'n' &&
8643 name[4] == 't' &&
8644 name[5] == 'f')
8645 { /* printf */
8646 return KEY_printf;
8647 }
8648
8649 goto unknown;
8650
8651 case 'r':
8652 switch (name[1])
8653 {
8654 case 'e':
8655 switch (name[2])
8656 {
8657 case 'n':
8658 if (name[3] == 'a' &&
8659 name[4] == 'm' &&
8660 name[5] == 'e')
8661 { /* rename */
8662 return -KEY_rename;
8663 }
8664
8665 goto unknown;
8666
8667 case 't':
8668 if (name[3] == 'u' &&
8669 name[4] == 'r' &&
8670 name[5] == 'n')
8671 { /* return */
8672 return KEY_return;
8673 }
8674
8675 goto unknown;
8676
8677 default:
8678 goto unknown;
8679 }
8680
8681 case 'i':
8682 if (name[2] == 'n' &&
8683 name[3] == 'd' &&
8684 name[4] == 'e' &&
8685 name[5] == 'x')
8686 { /* rindex */
8687 return -KEY_rindex;
8688 }
8689
8690 goto unknown;
8691
8692 default:
8693 goto unknown;
8694 }
8695
8696 case 's':
8697 switch (name[1])
8698 {
8699 case 'c':
8700 if (name[2] == 'a' &&
8701 name[3] == 'l' &&
8702 name[4] == 'a' &&
8703 name[5] == 'r')
8704 { /* scalar */
8705 return KEY_scalar;
8706 }
8707
8708 goto unknown;
8709
8710 case 'e':
8711 switch (name[2])
8712 {
8713 case 'l':
8714 if (name[3] == 'e' &&
8715 name[4] == 'c' &&
8716 name[5] == 't')
8717 { /* select */
8718 return -KEY_select;
8719 }
8720
8721 goto unknown;
8722
8723 case 'm':
8724 switch (name[3])
8725 {
8726 case 'c':
8727 if (name[4] == 't' &&
8728 name[5] == 'l')
8729 { /* semctl */
8730 return -KEY_semctl;
8731 }
8732
8733 goto unknown;
8734
8735 case 'g':
8736 if (name[4] == 'e' &&
8737 name[5] == 't')
8738 { /* semget */
8739 return -KEY_semget;
8740 }
8741
8742 goto unknown;
8743
8744 default:
8745 goto unknown;
8746 }
8747
8748 default:
8749 goto unknown;
8750 }
8751
8752 case 'h':
8753 if (name[2] == 'm')
8754 {
8755 switch (name[3])
8756 {
8757 case 'c':
8758 if (name[4] == 't' &&
8759 name[5] == 'l')
8760 { /* shmctl */
8761 return -KEY_shmctl;
8762 }
8763
8764 goto unknown;
8765
8766 case 'g':
8767 if (name[4] == 'e' &&
8768 name[5] == 't')
8769 { /* shmget */
8770 return -KEY_shmget;
8771 }
8772
8773 goto unknown;
8774
8775 default:
8776 goto unknown;
8777 }
8778 }
8779
8780 goto unknown;
8781
8782 case 'o':
8783 if (name[2] == 'c' &&
8784 name[3] == 'k' &&
8785 name[4] == 'e' &&
8786 name[5] == 't')
8787 { /* socket */
8788 return -KEY_socket;
8789 }
8790
8791 goto unknown;
8792
8793 case 'p':
8794 if (name[2] == 'l' &&
8795 name[3] == 'i' &&
8796 name[4] == 'c' &&
8797 name[5] == 'e')
8798 { /* splice */
8799 return -KEY_splice;
8800 }
8801
8802 goto unknown;
8803
8804 case 'u':
8805 if (name[2] == 'b' &&
8806 name[3] == 's' &&
8807 name[4] == 't' &&
8808 name[5] == 'r')
8809 { /* substr */
8810 return -KEY_substr;
8811 }
8812
8813 goto unknown;
8814
8815 case 'y':
8816 if (name[2] == 's' &&
8817 name[3] == 't' &&
8818 name[4] == 'e' &&
8819 name[5] == 'm')
8820 { /* system */
8821 return -KEY_system;
8822 }
8823
8824 goto unknown;
8825
8826 default:
8827 goto unknown;
8828 }
8829
8830 case 'u':
8831 if (name[1] == 'n')
8832 {
8833 switch (name[2])
8834 {
8835 case 'l':
8836 switch (name[3])
8837 {
8838 case 'e':
8839 if (name[4] == 's' &&
8840 name[5] == 's')
8841 { /* unless */
8842 return KEY_unless;
8843 }
8844
8845 goto unknown;
8846
8847 case 'i':
8848 if (name[4] == 'n' &&
8849 name[5] == 'k')
8850 { /* unlink */
8851 return -KEY_unlink;
8852 }
8853
8854 goto unknown;
8855
8856 default:
8857 goto unknown;
8858 }
8859
8860 case 'p':
8861 if (name[3] == 'a' &&
8862 name[4] == 'c' &&
8863 name[5] == 'k')
8864 { /* unpack */
8865 return -KEY_unpack;
8866 }
8867
8868 goto unknown;
8869
8870 default:
8871 goto unknown;
8872 }
8873 }
8874
8875 goto unknown;
8876
8877 case 'v':
8878 if (name[1] == 'a' &&
8879 name[2] == 'l' &&
8880 name[3] == 'u' &&
8881 name[4] == 'e' &&
8882 name[5] == 's')
8883 { /* values */
8884 return -KEY_values;
8885 }
8886
8887 goto unknown;
8888
8889 default:
8890 goto unknown;
e2e1dd5a 8891 }
4c3bbe0f 8892
0d863452 8893 case 7: /* 29 tokens of length 7 */
4c3bbe0f
MHM
8894 switch (name[0])
8895 {
8896 case 'D':
8897 if (name[1] == 'E' &&
8898 name[2] == 'S' &&
8899 name[3] == 'T' &&
8900 name[4] == 'R' &&
8901 name[5] == 'O' &&
8902 name[6] == 'Y')
8903 { /* DESTROY */
8904 return KEY_DESTROY;
8905 }
8906
8907 goto unknown;
8908
8909 case '_':
8910 if (name[1] == '_' &&
8911 name[2] == 'E' &&
8912 name[3] == 'N' &&
8913 name[4] == 'D' &&
8914 name[5] == '_' &&
8915 name[6] == '_')
8916 { /* __END__ */
8917 return KEY___END__;
8918 }
8919
8920 goto unknown;
8921
8922 case 'b':
8923 if (name[1] == 'i' &&
8924 name[2] == 'n' &&
8925 name[3] == 'm' &&
8926 name[4] == 'o' &&
8927 name[5] == 'd' &&
8928 name[6] == 'e')
8929 { /* binmode */
8930 return -KEY_binmode;
8931 }
8932
8933 goto unknown;
8934
8935 case 'c':
8936 if (name[1] == 'o' &&
8937 name[2] == 'n' &&
8938 name[3] == 'n' &&
8939 name[4] == 'e' &&
8940 name[5] == 'c' &&
8941 name[6] == 't')
8942 { /* connect */
8943 return -KEY_connect;
8944 }
8945
8946 goto unknown;
8947
8948 case 'd':
8949 switch (name[1])
8950 {
8951 case 'b':
8952 if (name[2] == 'm' &&
8953 name[3] == 'o' &&
8954 name[4] == 'p' &&
8955 name[5] == 'e' &&
8956 name[6] == 'n')
8957 { /* dbmopen */
8958 return -KEY_dbmopen;
8959 }
8960
8961 goto unknown;
8962
8963 case 'e':
0d863452
RH
8964 if (name[2] == 'f')
8965 {
8966 switch (name[3])
8967 {
8968 case 'a':
8969 if (name[4] == 'u' &&
8970 name[5] == 'l' &&
8971 name[6] == 't')
8972 { /* default */
5458a98a 8973 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
0d863452
RH
8974 }
8975
8976 goto unknown;
8977
8978 case 'i':
8979 if (name[4] == 'n' &&
952306ac
RGS
8980 name[5] == 'e' &&
8981 name[6] == 'd')
8982 { /* defined */
8983 return KEY_defined;
8984 }
4c3bbe0f 8985
952306ac 8986 goto unknown;
4c3bbe0f 8987
952306ac
RGS
8988 default:
8989 goto unknown;
8990 }
0d863452
RH
8991 }
8992
8993 goto unknown;
8994
8995 default:
8996 goto unknown;
8997 }
4c3bbe0f
MHM
8998
8999 case 'f':
9000 if (name[1] == 'o' &&
9001 name[2] == 'r' &&
9002 name[3] == 'e' &&
9003 name[4] == 'a' &&
9004 name[5] == 'c' &&
9005 name[6] == 'h')
9006 { /* foreach */
9007 return KEY_foreach;
9008 }
9009
9010 goto unknown;
9011
9012 case 'g':
9013 if (name[1] == 'e' &&
9014 name[2] == 't' &&
9015 name[3] == 'p')
9016 {
9017 switch (name[4])
9018 {
9019 case 'g':
9020 if (name[5] == 'r' &&
9021 name[6] == 'p')
9022 { /* getpgrp */
9023 return -KEY_getpgrp;
9024 }
9025
9026 goto unknown;
9027
9028 case 'p':
9029 if (name[5] == 'i' &&
9030 name[6] == 'd')
9031 { /* getppid */
9032 return -KEY_getppid;
9033 }
9034
9035 goto unknown;
9036
9037 default:
9038 goto unknown;
9039 }
9040 }
9041
9042 goto unknown;
9043
9044 case 'l':
9045 if (name[1] == 'c' &&
9046 name[2] == 'f' &&
9047 name[3] == 'i' &&
9048 name[4] == 'r' &&
9049 name[5] == 's' &&
9050 name[6] == 't')
9051 { /* lcfirst */
9052 return -KEY_lcfirst;
9053 }
9054
9055 goto unknown;
9056
9057 case 'o':
9058 if (name[1] == 'p' &&
9059 name[2] == 'e' &&
9060 name[3] == 'n' &&
9061 name[4] == 'd' &&
9062 name[5] == 'i' &&
9063 name[6] == 'r')
9064 { /* opendir */
9065 return -KEY_opendir;
9066 }
9067
9068 goto unknown;
9069
9070 case 'p':
9071 if (name[1] == 'a' &&
9072 name[2] == 'c' &&
9073 name[3] == 'k' &&
9074 name[4] == 'a' &&
9075 name[5] == 'g' &&
9076 name[6] == 'e')
9077 { /* package */
9078 return KEY_package;
9079 }
9080
9081 goto unknown;
9082
9083 case 'r':
9084 if (name[1] == 'e')
9085 {
9086 switch (name[2])
9087 {
9088 case 'a':
9089 if (name[3] == 'd' &&
9090 name[4] == 'd' &&
9091 name[5] == 'i' &&
9092 name[6] == 'r')
9093 { /* readdir */
9094 return -KEY_readdir;
9095 }
9096
9097 goto unknown;
9098
9099 case 'q':
9100 if (name[3] == 'u' &&
9101 name[4] == 'i' &&
9102 name[5] == 'r' &&
9103 name[6] == 'e')
9104 { /* require */
9105 return KEY_require;
9106 }
9107
9108 goto unknown;
9109
9110 case 'v':
9111 if (name[3] == 'e' &&
9112 name[4] == 'r' &&
9113 name[5] == 's' &&
9114 name[6] == 'e')
9115 { /* reverse */
9116 return -KEY_reverse;
9117 }
9118
9119 goto unknown;
9120
9121 default:
9122 goto unknown;
9123 }
9124 }
9125
9126 goto unknown;
9127
9128 case 's':
9129 switch (name[1])
9130 {
9131 case 'e':
9132 switch (name[2])
9133 {
9134 case 'e':
9135 if (name[3] == 'k' &&
9136 name[4] == 'd' &&
9137 name[5] == 'i' &&
9138 name[6] == 'r')
9139 { /* seekdir */
9140 return -KEY_seekdir;
9141 }
9142
9143 goto unknown;
9144
9145 case 't':
9146 if (name[3] == 'p' &&
9147 name[4] == 'g' &&
9148 name[5] == 'r' &&
9149 name[6] == 'p')
9150 { /* setpgrp */
9151 return -KEY_setpgrp;
9152 }
9153
9154 goto unknown;
9155
9156 default:
9157 goto unknown;
9158 }
9159
9160 case 'h':
9161 if (name[2] == 'm' &&
9162 name[3] == 'r' &&
9163 name[4] == 'e' &&
9164 name[5] == 'a' &&
9165 name[6] == 'd')
9166 { /* shmread */
9167 return -KEY_shmread;
9168 }
9169
9170 goto unknown;
9171
9172 case 'p':
9173 if (name[2] == 'r' &&
9174 name[3] == 'i' &&
9175 name[4] == 'n' &&
9176 name[5] == 't' &&
9177 name[6] == 'f')
9178 { /* sprintf */
9179 return -KEY_sprintf;
9180 }
9181
9182 goto unknown;
9183
9184 case 'y':
9185 switch (name[2])
9186 {
9187 case 'm':
9188 if (name[3] == 'l' &&
9189 name[4] == 'i' &&
9190 name[5] == 'n' &&
9191 name[6] == 'k')
9192 { /* symlink */
9193 return -KEY_symlink;
9194 }
9195
9196 goto unknown;
9197
9198 case 's':
9199 switch (name[3])
9200 {
9201 case 'c':
9202 if (name[4] == 'a' &&
9203 name[5] == 'l' &&
9204 name[6] == 'l')
9205 { /* syscall */
9206 return -KEY_syscall;
9207 }
9208
9209 goto unknown;
9210
9211 case 'o':
9212 if (name[4] == 'p' &&
9213 name[5] == 'e' &&
9214 name[6] == 'n')
9215 { /* sysopen */
9216 return -KEY_sysopen;
9217 }
9218
9219 goto unknown;
9220
9221 case 'r':
9222 if (name[4] == 'e' &&
9223 name[5] == 'a' &&
9224 name[6] == 'd')
9225 { /* sysread */
9226 return -KEY_sysread;
9227 }
9228
9229 goto unknown;
9230
9231 case 's':
9232 if (name[4] == 'e' &&
9233 name[5] == 'e' &&
9234 name[6] == 'k')
9235 { /* sysseek */
9236 return -KEY_sysseek;
9237 }
9238
9239 goto unknown;
9240
9241 default:
9242 goto unknown;
9243 }
9244
9245 default:
9246 goto unknown;
9247 }
9248
9249 default:
9250 goto unknown;
9251 }
9252
9253 case 't':
9254 if (name[1] == 'e' &&
9255 name[2] == 'l' &&
9256 name[3] == 'l' &&
9257 name[4] == 'd' &&
9258 name[5] == 'i' &&
9259 name[6] == 'r')
9260 { /* telldir */
9261 return -KEY_telldir;
9262 }
9263
9264 goto unknown;
9265
9266 case 'u':
9267 switch (name[1])
9268 {
9269 case 'c':
9270 if (name[2] == 'f' &&
9271 name[3] == 'i' &&
9272 name[4] == 'r' &&
9273 name[5] == 's' &&
9274 name[6] == 't')
9275 { /* ucfirst */
9276 return -KEY_ucfirst;
9277 }
9278
9279 goto unknown;
9280
9281 case 'n':
9282 if (name[2] == 's' &&
9283 name[3] == 'h' &&
9284 name[4] == 'i' &&
9285 name[5] == 'f' &&
9286 name[6] == 't')
9287 { /* unshift */
9288 return -KEY_unshift;
9289 }
9290
9291 goto unknown;
9292
9293 default:
9294 goto unknown;
9295 }
9296
9297 case 'w':
9298 if (name[1] == 'a' &&
9299 name[2] == 'i' &&
9300 name[3] == 't' &&
9301 name[4] == 'p' &&
9302 name[5] == 'i' &&
9303 name[6] == 'd')
9304 { /* waitpid */
9305 return -KEY_waitpid;
9306 }
9307
9308 goto unknown;
9309
9310 default:
9311 goto unknown;
9312 }
9313
9314 case 8: /* 26 tokens of length 8 */
9315 switch (name[0])
9316 {
9317 case 'A':
9318 if (name[1] == 'U' &&
9319 name[2] == 'T' &&
9320 name[3] == 'O' &&
9321 name[4] == 'L' &&
9322 name[5] == 'O' &&
9323 name[6] == 'A' &&
9324 name[7] == 'D')
9325 { /* AUTOLOAD */
9326 return KEY_AUTOLOAD;
9327 }
9328
9329 goto unknown;
9330
9331 case '_':
9332 if (name[1] == '_')
9333 {
9334 switch (name[2])
9335 {
9336 case 'D':
9337 if (name[3] == 'A' &&
9338 name[4] == 'T' &&
9339 name[5] == 'A' &&
9340 name[6] == '_' &&
9341 name[7] == '_')
9342 { /* __DATA__ */
9343 return KEY___DATA__;
9344 }
9345
9346 goto unknown;
9347
9348 case 'F':
9349 if (name[3] == 'I' &&
9350 name[4] == 'L' &&
9351 name[5] == 'E' &&
9352 name[6] == '_' &&
9353 name[7] == '_')
9354 { /* __FILE__ */
9355 return -KEY___FILE__;
9356 }
9357
9358 goto unknown;
9359
9360 case 'L':
9361 if (name[3] == 'I' &&
9362 name[4] == 'N' &&
9363 name[5] == 'E' &&
9364 name[6] == '_' &&
9365 name[7] == '_')
9366 { /* __LINE__ */
9367 return -KEY___LINE__;
9368 }
9369
9370 goto unknown;
9371
9372 default:
9373 goto unknown;
9374 }
9375 }
9376
9377 goto unknown;
9378
9379 case 'c':
9380 switch (name[1])
9381 {
9382 case 'l':
9383 if (name[2] == 'o' &&
9384 name[3] == 's' &&
9385 name[4] == 'e' &&
9386 name[5] == 'd' &&
9387 name[6] == 'i' &&
9388 name[7] == 'r')
9389 { /* closedir */
9390 return -KEY_closedir;
9391 }
9392
9393 goto unknown;
9394
9395 case 'o':
9396 if (name[2] == 'n' &&
9397 name[3] == 't' &&
9398 name[4] == 'i' &&
9399 name[5] == 'n' &&
9400 name[6] == 'u' &&
9401 name[7] == 'e')
9402 { /* continue */
9403 return -KEY_continue;
9404 }
9405
9406 goto unknown;
9407
9408 default:
9409 goto unknown;
9410 }
9411
9412 case 'd':
9413 if (name[1] == 'b' &&
9414 name[2] == 'm' &&
9415 name[3] == 'c' &&
9416 name[4] == 'l' &&
9417 name[5] == 'o' &&
9418 name[6] == 's' &&
9419 name[7] == 'e')
9420 { /* dbmclose */
9421 return -KEY_dbmclose;
9422 }
9423
9424 goto unknown;
9425
9426 case 'e':
9427 if (name[1] == 'n' &&
9428 name[2] == 'd')
9429 {
9430 switch (name[3])
9431 {
9432 case 'g':
9433 if (name[4] == 'r' &&
9434 name[5] == 'e' &&
9435 name[6] == 'n' &&
9436 name[7] == 't')
9437 { /* endgrent */
9438 return -KEY_endgrent;
9439 }
9440
9441 goto unknown;
9442
9443 case 'p':
9444 if (name[4] == 'w' &&
9445 name[5] == 'e' &&
9446 name[6] == 'n' &&
9447 name[7] == 't')
9448 { /* endpwent */
9449 return -KEY_endpwent;
9450 }
9451
9452 goto unknown;
9453
9454 default:
9455 goto unknown;
9456 }
9457 }
9458
9459 goto unknown;
9460
9461 case 'f':
9462 if (name[1] == 'o' &&
9463 name[2] == 'r' &&
9464 name[3] == 'm' &&
9465 name[4] == 'l' &&
9466 name[5] == 'i' &&
9467 name[6] == 'n' &&
9468 name[7] == 'e')
9469 { /* formline */
9470 return -KEY_formline;
9471 }
9472
9473 goto unknown;
9474
9475 case 'g':
9476 if (name[1] == 'e' &&
9477 name[2] == 't')
9478 {
9479 switch (name[3])
9480 {
9481 case 'g':
9482 if (name[4] == 'r')
9483 {
9484 switch (name[5])
9485 {
9486 case 'e':
9487 if (name[6] == 'n' &&
9488 name[7] == 't')
9489 { /* getgrent */
9490 return -KEY_getgrent;
9491 }
9492
9493 goto unknown;
9494
9495 case 'g':
9496 if (name[6] == 'i' &&
9497 name[7] == 'd')
9498 { /* getgrgid */
9499 return -KEY_getgrgid;
9500 }
9501
9502 goto unknown;
9503
9504 case 'n':
9505 if (name[6] == 'a' &&
9506 name[7] == 'm')
9507 { /* getgrnam */
9508 return -KEY_getgrnam;
9509 }
9510
9511 goto unknown;
9512
9513 default:
9514 goto unknown;
9515 }
9516 }
9517
9518 goto unknown;
9519
9520 case 'l':
9521 if (name[4] == 'o' &&
9522 name[5] == 'g' &&
9523 name[6] == 'i' &&
9524 name[7] == 'n')
9525 { /* getlogin */
9526 return -KEY_getlogin;
9527 }
9528
9529 goto unknown;
9530
9531 case 'p':
9532 if (name[4] == 'w')
9533 {
9534 switch (name[5])
9535 {
9536 case 'e':
9537 if (name[6] == 'n' &&
9538 name[7] == 't')
9539 { /* getpwent */
9540 return -KEY_getpwent;
9541 }
9542
9543 goto unknown;
9544
9545 case 'n':
9546 if (name[6] == 'a' &&
9547 name[7] == 'm')
9548 { /* getpwnam */
9549 return -KEY_getpwnam;
9550 }
9551
9552 goto unknown;
9553
9554 case 'u':
9555 if (name[6] == 'i' &&
9556 name[7] == 'd')
9557 { /* getpwuid */
9558 return -KEY_getpwuid;
9559 }
9560
9561 goto unknown;
9562
9563 default:
9564 goto unknown;
9565 }
9566 }
9567
9568 goto unknown;
9569
9570 default:
9571 goto unknown;
9572 }
9573 }
9574
9575 goto unknown;
9576
9577 case 'r':
9578 if (name[1] == 'e' &&
9579 name[2] == 'a' &&
9580 name[3] == 'd')
9581 {
9582 switch (name[4])
9583 {
9584 case 'l':
9585 if (name[5] == 'i' &&
9586 name[6] == 'n')
9587 {
9588 switch (name[7])
9589 {
9590 case 'e':
9591 { /* readline */
9592 return -KEY_readline;
9593 }
9594
4c3bbe0f
MHM
9595 case 'k':
9596 { /* readlink */
9597 return -KEY_readlink;
9598 }
9599
4c3bbe0f
MHM
9600 default:
9601 goto unknown;
9602 }
9603 }
9604
9605 goto unknown;
9606
9607 case 'p':
9608 if (name[5] == 'i' &&
9609 name[6] == 'p' &&
9610 name[7] == 'e')
9611 { /* readpipe */
9612 return -KEY_readpipe;
9613 }
9614
9615 goto unknown;
9616
9617 default:
9618 goto unknown;
9619 }
9620 }
9621
9622 goto unknown;
9623
9624 case 's':
9625 switch (name[1])
9626 {
9627 case 'e':
9628 if (name[2] == 't')
9629 {
9630 switch (name[3])
9631 {
9632 case 'g':
9633 if (name[4] == 'r' &&
9634 name[5] == 'e' &&
9635 name[6] == 'n' &&
9636 name[7] == 't')
9637 { /* setgrent */
9638 return -KEY_setgrent;
9639 }
9640
9641 goto unknown;
9642
9643 case 'p':
9644 if (name[4] == 'w' &&
9645 name[5] == 'e' &&
9646 name[6] == 'n' &&
9647 name[7] == 't')
9648 { /* setpwent */
9649 return -KEY_setpwent;
9650 }
9651
9652 goto unknown;
9653
9654 default:
9655 goto unknown;
9656 }
9657 }
9658
9659 goto unknown;
9660
9661 case 'h':
9662 switch (name[2])
9663 {
9664 case 'm':
9665 if (name[3] == 'w' &&
9666 name[4] == 'r' &&
9667 name[5] == 'i' &&
9668 name[6] == 't' &&
9669 name[7] == 'e')
9670 { /* shmwrite */
9671 return -KEY_shmwrite;
9672 }
9673
9674 goto unknown;
9675
9676 case 'u':
9677 if (name[3] == 't' &&
9678 name[4] == 'd' &&
9679 name[5] == 'o' &&
9680 name[6] == 'w' &&
9681 name[7] == 'n')
9682 { /* shutdown */
9683 return -KEY_shutdown;
9684 }
9685
9686 goto unknown;
9687
9688 default:
9689 goto unknown;
9690 }
9691
9692 case 'y':
9693 if (name[2] == 's' &&
9694 name[3] == 'w' &&
9695 name[4] == 'r' &&
9696 name[5] == 'i' &&
9697 name[6] == 't' &&
9698 name[7] == 'e')
9699 { /* syswrite */
9700 return -KEY_syswrite;
9701 }
9702
9703 goto unknown;
9704
9705 default:
9706 goto unknown;
9707 }
9708
9709 case 't':
9710 if (name[1] == 'r' &&
9711 name[2] == 'u' &&
9712 name[3] == 'n' &&
9713 name[4] == 'c' &&
9714 name[5] == 'a' &&
9715 name[6] == 't' &&
9716 name[7] == 'e')
9717 { /* truncate */
9718 return -KEY_truncate;
9719 }
9720
9721 goto unknown;
9722
9723 default:
9724 goto unknown;
9725 }
9726
3c10abe3 9727 case 9: /* 9 tokens of length 9 */
4c3bbe0f
MHM
9728 switch (name[0])
9729 {
3c10abe3
AG
9730 case 'U':
9731 if (name[1] == 'N' &&
9732 name[2] == 'I' &&
9733 name[3] == 'T' &&
9734 name[4] == 'C' &&
9735 name[5] == 'H' &&
9736 name[6] == 'E' &&
9737 name[7] == 'C' &&
9738 name[8] == 'K')
9739 { /* UNITCHECK */
9740 return KEY_UNITCHECK;
9741 }
9742
9743 goto unknown;
9744
4c3bbe0f
MHM
9745 case 'e':
9746 if (name[1] == 'n' &&
9747 name[2] == 'd' &&
9748 name[3] == 'n' &&
9749 name[4] == 'e' &&
9750 name[5] == 't' &&
9751 name[6] == 'e' &&
9752 name[7] == 'n' &&
9753 name[8] == 't')
9754 { /* endnetent */
9755 return -KEY_endnetent;
9756 }
9757
9758 goto unknown;
9759
9760 case 'g':
9761 if (name[1] == 'e' &&
9762 name[2] == 't' &&
9763 name[3] == 'n' &&
9764 name[4] == 'e' &&
9765 name[5] == 't' &&
9766 name[6] == 'e' &&
9767 name[7] == 'n' &&
9768 name[8] == 't')
9769 { /* getnetent */
9770 return -KEY_getnetent;
9771 }
9772
9773 goto unknown;
9774
9775 case 'l':
9776 if (name[1] == 'o' &&
9777 name[2] == 'c' &&
9778 name[3] == 'a' &&
9779 name[4] == 'l' &&
9780 name[5] == 't' &&
9781 name[6] == 'i' &&
9782 name[7] == 'm' &&
9783 name[8] == 'e')
9784 { /* localtime */
9785 return -KEY_localtime;
9786 }
9787
9788 goto unknown;
9789
9790 case 'p':
9791 if (name[1] == 'r' &&
9792 name[2] == 'o' &&
9793 name[3] == 't' &&
9794 name[4] == 'o' &&
9795 name[5] == 't' &&
9796 name[6] == 'y' &&
9797 name[7] == 'p' &&
9798 name[8] == 'e')
9799 { /* prototype */
9800 return KEY_prototype;
9801 }
9802
9803 goto unknown;
9804
9805 case 'q':
9806 if (name[1] == 'u' &&
9807 name[2] == 'o' &&
9808 name[3] == 't' &&
9809 name[4] == 'e' &&
9810 name[5] == 'm' &&
9811 name[6] == 'e' &&
9812 name[7] == 't' &&
9813 name[8] == 'a')
9814 { /* quotemeta */
9815 return -KEY_quotemeta;
9816 }
9817
9818 goto unknown;
9819
9820 case 'r':
9821 if (name[1] == 'e' &&
9822 name[2] == 'w' &&
9823 name[3] == 'i' &&
9824 name[4] == 'n' &&
9825 name[5] == 'd' &&
9826 name[6] == 'd' &&
9827 name[7] == 'i' &&
9828 name[8] == 'r')
9829 { /* rewinddir */
9830 return -KEY_rewinddir;
9831 }
9832
9833 goto unknown;
9834
9835 case 's':
9836 if (name[1] == 'e' &&
9837 name[2] == 't' &&
9838 name[3] == 'n' &&
9839 name[4] == 'e' &&
9840 name[5] == 't' &&
9841 name[6] == 'e' &&
9842 name[7] == 'n' &&
9843 name[8] == 't')
9844 { /* setnetent */
9845 return -KEY_setnetent;
9846 }
9847
9848 goto unknown;
9849
9850 case 'w':
9851 if (name[1] == 'a' &&
9852 name[2] == 'n' &&
9853 name[3] == 't' &&
9854 name[4] == 'a' &&
9855 name[5] == 'r' &&
9856 name[6] == 'r' &&
9857 name[7] == 'a' &&
9858 name[8] == 'y')
9859 { /* wantarray */
9860 return -KEY_wantarray;
9861 }
9862
9863 goto unknown;
9864
9865 default:
9866 goto unknown;
9867 }
9868
9869 case 10: /* 9 tokens of length 10 */
9870 switch (name[0])
9871 {
9872 case 'e':
9873 if (name[1] == 'n' &&
9874 name[2] == 'd')
9875 {
9876 switch (name[3])
9877 {
9878 case 'h':
9879 if (name[4] == 'o' &&
9880 name[5] == 's' &&
9881 name[6] == 't' &&
9882 name[7] == 'e' &&
9883 name[8] == 'n' &&
9884 name[9] == 't')
9885 { /* endhostent */
9886 return -KEY_endhostent;
9887 }
9888
9889 goto unknown;
9890
9891 case 's':
9892 if (name[4] == 'e' &&
9893 name[5] == 'r' &&
9894 name[6] == 'v' &&
9895 name[7] == 'e' &&
9896 name[8] == 'n' &&
9897 name[9] == 't')
9898 { /* endservent */
9899 return -KEY_endservent;
9900 }
9901
9902 goto unknown;
9903
9904 default:
9905 goto unknown;
9906 }
9907 }
9908
9909 goto unknown;
9910
9911 case 'g':
9912 if (name[1] == 'e' &&
9913 name[2] == 't')
9914 {
9915 switch (name[3])
9916 {
9917 case 'h':
9918 if (name[4] == 'o' &&
9919 name[5] == 's' &&
9920 name[6] == 't' &&
9921 name[7] == 'e' &&
9922 name[8] == 'n' &&
9923 name[9] == 't')
9924 { /* gethostent */
9925 return -KEY_gethostent;
9926 }
9927
9928 goto unknown;
9929
9930 case 's':
9931 switch (name[4])
9932 {
9933 case 'e':
9934 if (name[5] == 'r' &&
9935 name[6] == 'v' &&
9936 name[7] == 'e' &&
9937 name[8] == 'n' &&
9938 name[9] == 't')
9939 { /* getservent */
9940 return -KEY_getservent;
9941 }
9942
9943 goto unknown;
9944
9945 case 'o':
9946 if (name[5] == 'c' &&
9947 name[6] == 'k' &&
9948 name[7] == 'o' &&
9949 name[8] == 'p' &&
9950 name[9] == 't')
9951 { /* getsockopt */
9952 return -KEY_getsockopt;
9953 }
9954
9955 goto unknown;
9956
9957 default:
9958 goto unknown;
9959 }
9960
9961 default:
9962 goto unknown;
9963 }
9964 }
9965
9966 goto unknown;
9967
9968 case 's':
9969 switch (name[1])
9970 {
9971 case 'e':
9972 if (name[2] == 't')
9973 {
9974 switch (name[3])
9975 {
9976 case 'h':
9977 if (name[4] == 'o' &&
9978 name[5] == 's' &&
9979 name[6] == 't' &&
9980 name[7] == 'e' &&
9981 name[8] == 'n' &&
9982 name[9] == 't')
9983 { /* sethostent */
9984 return -KEY_sethostent;
9985 }
9986
9987 goto unknown;
9988
9989 case 's':
9990 switch (name[4])
9991 {
9992 case 'e':
9993 if (name[5] == 'r' &&
9994 name[6] == 'v' &&
9995 name[7] == 'e' &&
9996 name[8] == 'n' &&
9997 name[9] == 't')
9998 { /* setservent */
9999 return -KEY_setservent;
10000 }
10001
10002 goto unknown;
10003
10004 case 'o':
10005 if (name[5] == 'c' &&
10006 name[6] == 'k' &&
10007 name[7] == 'o' &&
10008 name[8] == 'p' &&
10009 name[9] == 't')
10010 { /* setsockopt */
10011 return -KEY_setsockopt;
10012 }
10013
10014 goto unknown;
10015
10016 default:
10017 goto unknown;
10018 }
10019
10020 default:
10021 goto unknown;
10022 }
10023 }
10024
10025 goto unknown;
10026
10027 case 'o':
10028 if (name[2] == 'c' &&
10029 name[3] == 'k' &&
10030 name[4] == 'e' &&
10031 name[5] == 't' &&
10032 name[6] == 'p' &&
10033 name[7] == 'a' &&
10034 name[8] == 'i' &&
10035 name[9] == 'r')
10036 { /* socketpair */
10037 return -KEY_socketpair;
10038 }
10039
10040 goto unknown;
10041
10042 default:
10043 goto unknown;
10044 }
10045
10046 default:
10047 goto unknown;
e2e1dd5a 10048 }
4c3bbe0f
MHM
10049
10050 case 11: /* 8 tokens of length 11 */
10051 switch (name[0])
10052 {
10053 case '_':
10054 if (name[1] == '_' &&
10055 name[2] == 'P' &&
10056 name[3] == 'A' &&
10057 name[4] == 'C' &&
10058 name[5] == 'K' &&
10059 name[6] == 'A' &&
10060 name[7] == 'G' &&
10061 name[8] == 'E' &&
10062 name[9] == '_' &&
10063 name[10] == '_')
10064 { /* __PACKAGE__ */
10065 return -KEY___PACKAGE__;
10066 }
10067
10068 goto unknown;
10069
10070 case 'e':
10071 if (name[1] == 'n' &&
10072 name[2] == 'd' &&
10073 name[3] == 'p' &&
10074 name[4] == 'r' &&
10075 name[5] == 'o' &&
10076 name[6] == 't' &&
10077 name[7] == 'o' &&
10078 name[8] == 'e' &&
10079 name[9] == 'n' &&
10080 name[10] == 't')
10081 { /* endprotoent */
10082 return -KEY_endprotoent;
10083 }
10084
10085 goto unknown;
10086
10087 case 'g':
10088 if (name[1] == 'e' &&
10089 name[2] == 't')
10090 {
10091 switch (name[3])
10092 {
10093 case 'p':
10094 switch (name[4])
10095 {
10096 case 'e':
10097 if (name[5] == 'e' &&
10098 name[6] == 'r' &&
10099 name[7] == 'n' &&
10100 name[8] == 'a' &&
10101 name[9] == 'm' &&
10102 name[10] == 'e')
10103 { /* getpeername */
10104 return -KEY_getpeername;
10105 }
10106
10107 goto unknown;
10108
10109 case 'r':
10110 switch (name[5])
10111 {
10112 case 'i':
10113 if (name[6] == 'o' &&
10114 name[7] == 'r' &&
10115 name[8] == 'i' &&
10116 name[9] == 't' &&
10117 name[10] == 'y')
10118 { /* getpriority */
10119 return -KEY_getpriority;
10120 }
10121
10122 goto unknown;
10123
10124 case 'o':
10125 if (name[6] == 't' &&
10126 name[7] == 'o' &&
10127 name[8] == 'e' &&
10128 name[9] == 'n' &&
10129 name[10] == 't')
10130 { /* getprotoent */
10131 return -KEY_getprotoent;
10132 }
10133
10134 goto unknown;
10135
10136 default:
10137 goto unknown;
10138 }
10139
10140 default:
10141 goto unknown;
10142 }
10143
10144 case 's':
10145 if (name[4] == 'o' &&
10146 name[5] == 'c' &&
10147 name[6] == 'k' &&
10148 name[7] == 'n' &&
10149 name[8] == 'a' &&
10150 name[9] == 'm' &&
10151 name[10] == 'e')
10152 { /* getsockname */
10153 return -KEY_getsockname;
10154 }
10155
10156 goto unknown;
10157
10158 default:
10159 goto unknown;
10160 }
10161 }
10162
10163 goto unknown;
10164
10165 case 's':
10166 if (name[1] == 'e' &&
10167 name[2] == 't' &&
10168 name[3] == 'p' &&
10169 name[4] == 'r')
10170 {
10171 switch (name[5])
10172 {
10173 case 'i':
10174 if (name[6] == 'o' &&
10175 name[7] == 'r' &&
10176 name[8] == 'i' &&
10177 name[9] == 't' &&
10178 name[10] == 'y')
10179 { /* setpriority */
10180 return -KEY_setpriority;
10181 }
10182
10183 goto unknown;
10184
10185 case 'o':
10186 if (name[6] == 't' &&
10187 name[7] == 'o' &&
10188 name[8] == 'e' &&
10189 name[9] == 'n' &&
10190 name[10] == 't')
10191 { /* setprotoent */
10192 return -KEY_setprotoent;
10193 }
10194
10195 goto unknown;
10196
10197 default:
10198 goto unknown;
10199 }
10200 }
10201
10202 goto unknown;
10203
10204 default:
10205 goto unknown;
e2e1dd5a 10206 }
4c3bbe0f
MHM
10207
10208 case 12: /* 2 tokens of length 12 */
10209 if (name[0] == 'g' &&
10210 name[1] == 'e' &&
10211 name[2] == 't' &&
10212 name[3] == 'n' &&
10213 name[4] == 'e' &&
10214 name[5] == 't' &&
10215 name[6] == 'b' &&
10216 name[7] == 'y')
10217 {
10218 switch (name[8])
10219 {
10220 case 'a':
10221 if (name[9] == 'd' &&
10222 name[10] == 'd' &&
10223 name[11] == 'r')
10224 { /* getnetbyaddr */
10225 return -KEY_getnetbyaddr;
10226 }
10227
10228 goto unknown;
10229
10230 case 'n':
10231 if (name[9] == 'a' &&
10232 name[10] == 'm' &&
10233 name[11] == 'e')
10234 { /* getnetbyname */
10235 return -KEY_getnetbyname;
10236 }
10237
10238 goto unknown;
10239
10240 default:
10241 goto unknown;
10242 }
e2e1dd5a 10243 }
4c3bbe0f
MHM
10244
10245 goto unknown;
10246
10247 case 13: /* 4 tokens of length 13 */
10248 if (name[0] == 'g' &&
10249 name[1] == 'e' &&
10250 name[2] == 't')
10251 {
10252 switch (name[3])
10253 {
10254 case 'h':
10255 if (name[4] == 'o' &&
10256 name[5] == 's' &&
10257 name[6] == 't' &&
10258 name[7] == 'b' &&
10259 name[8] == 'y')
10260 {
10261 switch (name[9])
10262 {
10263 case 'a':
10264 if (name[10] == 'd' &&
10265 name[11] == 'd' &&
10266 name[12] == 'r')
10267 { /* gethostbyaddr */
10268 return -KEY_gethostbyaddr;
10269 }
10270
10271 goto unknown;
10272
10273 case 'n':
10274 if (name[10] == 'a' &&
10275 name[11] == 'm' &&
10276 name[12] == 'e')
10277 { /* gethostbyname */
10278 return -KEY_gethostbyname;
10279 }
10280
10281 goto unknown;
10282
10283 default:
10284 goto unknown;
10285 }
10286 }
10287
10288 goto unknown;
10289
10290 case 's':
10291 if (name[4] == 'e' &&
10292 name[5] == 'r' &&
10293 name[6] == 'v' &&
10294 name[7] == 'b' &&
10295 name[8] == 'y')
10296 {
10297 switch (name[9])
10298 {
10299 case 'n':
10300 if (name[10] == 'a' &&
10301 name[11] == 'm' &&
10302 name[12] == 'e')
10303 { /* getservbyname */
10304 return -KEY_getservbyname;
10305 }
10306
10307 goto unknown;
10308
10309 case 'p':
10310 if (name[10] == 'o' &&
10311 name[11] == 'r' &&
10312 name[12] == 't')
10313 { /* getservbyport */
10314 return -KEY_getservbyport;
10315 }
10316
10317 goto unknown;
10318
10319 default:
10320 goto unknown;
10321 }
10322 }
10323
10324 goto unknown;
10325
10326 default:
10327 goto unknown;
10328 }
e2e1dd5a 10329 }
4c3bbe0f
MHM
10330
10331 goto unknown;
10332
10333 case 14: /* 1 tokens of length 14 */
10334 if (name[0] == 'g' &&
10335 name[1] == 'e' &&
10336 name[2] == 't' &&
10337 name[3] == 'p' &&
10338 name[4] == 'r' &&
10339 name[5] == 'o' &&
10340 name[6] == 't' &&
10341 name[7] == 'o' &&
10342 name[8] == 'b' &&
10343 name[9] == 'y' &&
10344 name[10] == 'n' &&
10345 name[11] == 'a' &&
10346 name[12] == 'm' &&
10347 name[13] == 'e')
10348 { /* getprotobyname */
10349 return -KEY_getprotobyname;
10350 }
10351
10352 goto unknown;
10353
10354 case 16: /* 1 tokens of length 16 */
10355 if (name[0] == 'g' &&
10356 name[1] == 'e' &&
10357 name[2] == 't' &&
10358 name[3] == 'p' &&
10359 name[4] == 'r' &&
10360 name[5] == 'o' &&
10361 name[6] == 't' &&
10362 name[7] == 'o' &&
10363 name[8] == 'b' &&
10364 name[9] == 'y' &&
10365 name[10] == 'n' &&
10366 name[11] == 'u' &&
10367 name[12] == 'm' &&
10368 name[13] == 'b' &&
10369 name[14] == 'e' &&
10370 name[15] == 'r')
10371 { /* getprotobynumber */
10372 return -KEY_getprotobynumber;
10373 }
10374
10375 goto unknown;
10376
10377 default:
10378 goto unknown;
e2e1dd5a 10379 }
4c3bbe0f
MHM
10380
10381unknown:
e2e1dd5a 10382 return 0;
a687059c
LW
10383}
10384
76e3520e 10385STATIC void
c94115d8 10386S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
a687059c 10387{
97aff369 10388 dVAR;
2f3197b3 10389
d008e5eb 10390 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
d008e5eb
GS
10391 if (ckWARN(WARN_SYNTAX)) {
10392 int level = 1;
26ff0806 10393 const char *w;
d008e5eb
GS
10394 for (w = s+2; *w && level; w++) {
10395 if (*w == '(')
10396 ++level;
10397 else if (*w == ')')
10398 --level;
10399 }
888fea98
NC
10400 while (isSPACE(*w))
10401 ++w;
d008e5eb 10402 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
9014280d 10403 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
65cec589 10404 "%s (...) interpreted as function",name);
d008e5eb 10405 }
2f3197b3 10406 }
3280af22 10407 while (s < PL_bufend && isSPACE(*s))
2f3197b3 10408 s++;
a687059c
LW
10409 if (*s == '(')
10410 s++;
3280af22 10411 while (s < PL_bufend && isSPACE(*s))
a687059c 10412 s++;
7e2040f0 10413 if (isIDFIRST_lazy_if(s,UTF)) {
26ff0806 10414 const char * const w = s++;
7e2040f0 10415 while (isALNUM_lazy_if(s,UTF))
a687059c 10416 s++;
3280af22 10417 while (s < PL_bufend && isSPACE(*s))
a687059c 10418 s++;
e929a76b 10419 if (*s == ',') {
c94115d8 10420 GV* gv;
5458a98a 10421 if (keyword(w, s - w, 0))
e929a76b 10422 return;
c94115d8
NC
10423
10424 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10425 if (gv && GvCVu(gv))
abbb3198 10426 return;
cea2e8a9 10427 Perl_croak(aTHX_ "No comma allowed after %s", what);
463ee0b2
LW
10428 }
10429 }
10430}
10431
423cee85
JH
10432/* Either returns sv, or mortalizes sv and returns a new SV*.
10433 Best used as sv=new_constant(..., sv, ...).
10434 If s, pv are NULL, calls subroutine with one argument,
10435 and type is used with error messages only. */
10436
b3ac6de7 10437STATIC SV *
7fc63493 10438S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
9b0e499b 10439 const char *type)
b3ac6de7 10440{
27da23d5 10441 dVAR; dSP;
890ce7af 10442 HV * const table = GvHV(PL_hintgv); /* ^H */
b3ac6de7 10443 SV *res;
b3ac6de7
IZ
10444 SV **cvp;
10445 SV *cv, *typesv;
89e33a05 10446 const char *why1 = "", *why2 = "", *why3 = "";
4e553d73 10447
f0af216f 10448 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
423cee85
JH
10449 SV *msg;
10450
10edeb5d
JH
10451 why2 = (const char *)
10452 (strEQ(key,"charnames")
10453 ? "(possibly a missing \"use charnames ...\")"
10454 : "");
4e553d73 10455 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
41ab332f
JH
10456 (type ? type: "undef"), why2);
10457
10458 /* This is convoluted and evil ("goto considered harmful")
10459 * but I do not understand the intricacies of all the different
10460 * failure modes of %^H in here. The goal here is to make
10461 * the most probable error message user-friendly. --jhi */
10462
10463 goto msgdone;
10464
423cee85 10465 report:
4e553d73 10466 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
f0af216f 10467 (type ? type: "undef"), why1, why2, why3);
41ab332f 10468 msgdone:
95a20fc0 10469 yyerror(SvPVX_const(msg));
423cee85
JH
10470 SvREFCNT_dec(msg);
10471 return sv;
10472 }
b3ac6de7
IZ
10473 cvp = hv_fetch(table, key, strlen(key), FALSE);
10474 if (!cvp || !SvOK(*cvp)) {
423cee85
JH
10475 why1 = "$^H{";
10476 why2 = key;
f0af216f 10477 why3 = "} is not defined";
423cee85 10478 goto report;
b3ac6de7
IZ
10479 }
10480 sv_2mortal(sv); /* Parent created it permanently */
10481 cv = *cvp;
423cee85
JH
10482 if (!pv && s)
10483 pv = sv_2mortal(newSVpvn(s, len));
10484 if (type && pv)
10485 typesv = sv_2mortal(newSVpv(type, 0));
b3ac6de7 10486 else
423cee85 10487 typesv = &PL_sv_undef;
4e553d73 10488
e788e7d3 10489 PUSHSTACKi(PERLSI_OVERLOAD);
423cee85
JH
10490 ENTER ;
10491 SAVETMPS;
4e553d73 10492
423cee85 10493 PUSHMARK(SP) ;
a5845cb7 10494 EXTEND(sp, 3);
423cee85
JH
10495 if (pv)
10496 PUSHs(pv);
b3ac6de7 10497 PUSHs(sv);
423cee85
JH
10498 if (pv)
10499 PUSHs(typesv);
b3ac6de7 10500 PUTBACK;
423cee85 10501 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
4e553d73 10502
423cee85 10503 SPAGAIN ;
4e553d73 10504
423cee85 10505 /* Check the eval first */
9b0e499b 10506 if (!PL_in_eval && SvTRUE(ERRSV)) {
396482e1 10507 sv_catpvs(ERRSV, "Propagated");
8b6b16e7 10508 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
e1f15930 10509 (void)POPs;
b37c2d43 10510 res = SvREFCNT_inc_simple(sv);
423cee85
JH
10511 }
10512 else {
10513 res = POPs;
b37c2d43 10514 SvREFCNT_inc_simple_void(res);
423cee85 10515 }
4e553d73 10516
423cee85
JH
10517 PUTBACK ;
10518 FREETMPS ;
10519 LEAVE ;
b3ac6de7 10520 POPSTACK;
4e553d73 10521
b3ac6de7 10522 if (!SvOK(res)) {
423cee85
JH
10523 why1 = "Call to &{$^H{";
10524 why2 = key;
f0af216f 10525 why3 = "}} did not return a defined value";
423cee85
JH
10526 sv = res;
10527 goto report;
9b0e499b 10528 }
423cee85 10529
9b0e499b 10530 return res;
b3ac6de7 10531}
4e553d73 10532
d0a148a6
NC
10533/* Returns a NUL terminated string, with the length of the string written to
10534 *slp
10535 */
76e3520e 10536STATIC char *
cea2e8a9 10537S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
463ee0b2 10538{
97aff369 10539 dVAR;
463ee0b2 10540 register char *d = dest;
890ce7af 10541 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
463ee0b2 10542 for (;;) {
8903cb82 10543 if (d >= e)
cea2e8a9 10544 Perl_croak(aTHX_ ident_too_long);
834a4ddd 10545 if (isALNUM(*s)) /* UTF handled below */
463ee0b2 10546 *d++ = *s++;
c35e046a 10547 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
463ee0b2
LW
10548 *d++ = ':';
10549 *d++ = ':';
10550 s++;
10551 }
c35e046a 10552 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
463ee0b2
LW
10553 *d++ = *s++;
10554 *d++ = *s++;
10555 }
fd400ab9 10556 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
a0ed51b3 10557 char *t = s + UTF8SKIP(s);
c35e046a 10558 size_t len;
fd400ab9 10559 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
a0ed51b3 10560 t += UTF8SKIP(t);
c35e046a
AL
10561 len = t - s;
10562 if (d + len > e)
cea2e8a9 10563 Perl_croak(aTHX_ ident_too_long);
c35e046a
AL
10564 Copy(s, d, len, char);
10565 d += len;
a0ed51b3
LW
10566 s = t;
10567 }
463ee0b2
LW
10568 else {
10569 *d = '\0';
10570 *slp = d - dest;
10571 return s;
e929a76b 10572 }
378cc40b
LW
10573 }
10574}
10575
76e3520e 10576STATIC char *
f54cb97a 10577S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
378cc40b 10578{
97aff369 10579 dVAR;
6136c704 10580 char *bracket = NULL;
748a9306 10581 char funny = *s++;
6136c704
AL
10582 register char *d = dest;
10583 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
378cc40b 10584
a0d0e21e 10585 if (isSPACE(*s))
29595ff2 10586 s = PEEKSPACE(s);
de3bb511 10587 if (isDIGIT(*s)) {
8903cb82 10588 while (isDIGIT(*s)) {
10589 if (d >= e)
cea2e8a9 10590 Perl_croak(aTHX_ ident_too_long);
378cc40b 10591 *d++ = *s++;
8903cb82 10592 }
378cc40b
LW
10593 }
10594 else {
463ee0b2 10595 for (;;) {
8903cb82 10596 if (d >= e)
cea2e8a9 10597 Perl_croak(aTHX_ ident_too_long);
834a4ddd 10598 if (isALNUM(*s)) /* UTF handled below */
463ee0b2 10599 *d++ = *s++;
7e2040f0 10600 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
463ee0b2
LW
10601 *d++ = ':';
10602 *d++ = ':';
10603 s++;
10604 }
a0d0e21e 10605 else if (*s == ':' && s[1] == ':') {
463ee0b2
LW
10606 *d++ = *s++;
10607 *d++ = *s++;
10608 }
fd400ab9 10609 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
a0ed51b3 10610 char *t = s + UTF8SKIP(s);
fd400ab9 10611 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
a0ed51b3
LW
10612 t += UTF8SKIP(t);
10613 if (d + (t - s) > e)
cea2e8a9 10614 Perl_croak(aTHX_ ident_too_long);
a0ed51b3
LW
10615 Copy(s, d, t - s, char);
10616 d += t - s;
10617 s = t;
10618 }
463ee0b2
LW
10619 else
10620 break;
10621 }
378cc40b
LW
10622 }
10623 *d = '\0';
10624 d = dest;
79072805 10625 if (*d) {
3280af22
NIS
10626 if (PL_lex_state != LEX_NORMAL)
10627 PL_lex_state = LEX_INTERPENDMAYBE;
79072805 10628 return s;
378cc40b 10629 }
748a9306 10630 if (*s == '$' && s[1] &&
3792a11b 10631 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
5cd24f17 10632 {
4810e5ec 10633 return s;
5cd24f17 10634 }
79072805
LW
10635 if (*s == '{') {
10636 bracket = s;
10637 s++;
10638 }
10639 else if (ck_uni)
10640 check_uni();
93a17b20 10641 if (s < send)
79072805
LW
10642 *d = *s++;
10643 d[1] = '\0';
2b92dfce 10644 if (*d == '^' && *s && isCONTROLVAR(*s)) {
bbce6d69 10645 *d = toCTRL(*s);
10646 s++;
de3bb511 10647 }
79072805 10648 if (bracket) {
748a9306 10649 if (isSPACE(s[-1])) {
fa83b5b6 10650 while (s < send) {
f54cb97a 10651 const char ch = *s++;
bf4acbe4 10652 if (!SPACE_OR_TAB(ch)) {
fa83b5b6 10653 *d = ch;
10654 break;
10655 }
10656 }
748a9306 10657 }
7e2040f0 10658 if (isIDFIRST_lazy_if(d,UTF)) {
79072805 10659 d++;
a0ed51b3 10660 if (UTF) {
6136c704
AL
10661 char *end = s;
10662 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10663 end += UTF8SKIP(end);
10664 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10665 end += UTF8SKIP(end);
a0ed51b3 10666 }
6136c704
AL
10667 Copy(s, d, end - s, char);
10668 d += end - s;
10669 s = end;
a0ed51b3
LW
10670 }
10671 else {
2b92dfce 10672 while ((isALNUM(*s) || *s == ':') && d < e)
a0ed51b3 10673 *d++ = *s++;
2b92dfce 10674 if (d >= e)
cea2e8a9 10675 Perl_croak(aTHX_ ident_too_long);
a0ed51b3 10676 }
79072805 10677 *d = '\0';
c35e046a
AL
10678 while (s < send && SPACE_OR_TAB(*s))
10679 s++;
ff68c719 10680 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
5458a98a 10681 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
10edeb5d
JH
10682 const char * const brack =
10683 (const char *)
10684 ((*s == '[') ? "[...]" : "{...}");
9014280d 10685 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
599cee73 10686 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
748a9306
LW
10687 funny, dest, brack, funny, dest, brack);
10688 }
79072805 10689 bracket++;
a0be28da 10690 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
79072805
LW
10691 return s;
10692 }
4e553d73
NIS
10693 }
10694 /* Handle extended ${^Foo} variables
2b92dfce
GS
10695 * 1999-02-27 mjd-perl-patch@plover.com */
10696 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10697 && isALNUM(*s))
10698 {
10699 d++;
10700 while (isALNUM(*s) && d < e) {
10701 *d++ = *s++;
10702 }
10703 if (d >= e)
cea2e8a9 10704 Perl_croak(aTHX_ ident_too_long);
2b92dfce 10705 *d = '\0';
79072805
LW
10706 }
10707 if (*s == '}') {
10708 s++;
7df0d042 10709 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
3280af22 10710 PL_lex_state = LEX_INTERPEND;
7df0d042
AE
10711 PL_expect = XREF;
10712 }
d008e5eb 10713 if (PL_lex_state == LEX_NORMAL) {
d008e5eb 10714 if (ckWARN(WARN_AMBIGUOUS) &&
5458a98a 10715 (keyword(dest, d - dest, 0) || get_cv(dest, FALSE)))
d008e5eb 10716 {
c35e046a
AL
10717 if (funny == '#')
10718 funny = '@';
9014280d 10719 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
d008e5eb
GS
10720 "Ambiguous use of %c{%s} resolved to %c%s",
10721 funny, dest, funny, dest);
10722 }
10723 }
79072805
LW
10724 }
10725 else {
10726 s = bracket; /* let the parser handle it */
93a17b20 10727 *dest = '\0';
79072805
LW
10728 }
10729 }
3280af22
NIS
10730 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10731 PL_lex_state = LEX_INTERPEND;
378cc40b
LW
10732 return s;
10733}
10734
cea2e8a9 10735void
2b36a5a0 10736Perl_pmflag(pTHX_ U32* pmfl, int ch)
a0d0e21e 10737{
96a5add6 10738 PERL_UNUSED_CONTEXT;
bbce6d69 10739 if (ch == 'i')
a0d0e21e 10740 *pmfl |= PMf_FOLD;
a0d0e21e
LW
10741 else if (ch == 'g')
10742 *pmfl |= PMf_GLOBAL;
c90c0ff4 10743 else if (ch == 'c')
10744 *pmfl |= PMf_CONTINUE;
a0d0e21e
LW
10745 else if (ch == 'o')
10746 *pmfl |= PMf_KEEP;
10747 else if (ch == 'm')
10748 *pmfl |= PMf_MULTILINE;
10749 else if (ch == 's')
10750 *pmfl |= PMf_SINGLELINE;
10751 else if (ch == 'x')
10752 *pmfl |= PMf_EXTENDED;
10753}
378cc40b 10754
76e3520e 10755STATIC char *
cea2e8a9 10756S_scan_pat(pTHX_ char *start, I32 type)
378cc40b 10757{
97aff369 10758 dVAR;
79072805 10759 PMOP *pm;
5db06880 10760 char *s = scan_str(start,!!PL_madskills,FALSE);
10edeb5d
JH
10761 const char * const valid_flags =
10762 (const char *)((type == OP_QR) ? "iomsx" : "iogcmsx");
5db06880
NC
10763#ifdef PERL_MAD
10764 char *modstart;
10765#endif
10766
378cc40b 10767
25c09cbf 10768 if (!s) {
6136c704 10769 const char * const delimiter = skipspace(start);
10edeb5d
JH
10770 Perl_croak(aTHX_
10771 (const char *)
10772 (*delimiter == '?'
10773 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10774 : "Search pattern not terminated" ));
25c09cbf 10775 }
bbce6d69 10776
8782bef2 10777 pm = (PMOP*)newPMOP(type, 0);
3280af22 10778 if (PL_multi_open == '?')
79072805 10779 pm->op_pmflags |= PMf_ONCE;
5db06880
NC
10780#ifdef PERL_MAD
10781 modstart = s;
10782#endif
6136c704
AL
10783 while (*s && strchr(valid_flags, *s))
10784 pmflag(&pm->op_pmflags,*s++);
5db06880
NC
10785#ifdef PERL_MAD
10786 if (PL_madskills && modstart != s) {
10787 SV* tmptoken = newSVpvn(modstart, s - modstart);
10788 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10789 }
10790#endif
4ac733c9 10791 /* issue a warning if /c is specified,but /g is not */
041457d9
DM
10792 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10793 && ckWARN(WARN_REGEXP))
4ac733c9 10794 {
0bd48802 10795 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless without /g" );
4ac733c9
MJD
10796 }
10797
4633a7c4 10798 pm->op_pmpermflags = pm->op_pmflags;
bbce6d69 10799
3280af22 10800 PL_lex_op = (OP*)pm;
79072805 10801 yylval.ival = OP_MATCH;
378cc40b
LW
10802 return s;
10803}
10804
76e3520e 10805STATIC char *
cea2e8a9 10806S_scan_subst(pTHX_ char *start)
79072805 10807{
27da23d5 10808 dVAR;
a0d0e21e 10809 register char *s;
79072805 10810 register PMOP *pm;
4fdae800 10811 I32 first_start;
79072805 10812 I32 es = 0;
5db06880
NC
10813#ifdef PERL_MAD
10814 char *modstart;
10815#endif
79072805 10816
79072805
LW
10817 yylval.ival = OP_NULL;
10818
5db06880 10819 s = scan_str(start,!!PL_madskills,FALSE);
79072805 10820
37fd879b 10821 if (!s)
cea2e8a9 10822 Perl_croak(aTHX_ "Substitution pattern not terminated");
79072805 10823
3280af22 10824 if (s[-1] == PL_multi_open)
79072805 10825 s--;
5db06880
NC
10826#ifdef PERL_MAD
10827 if (PL_madskills) {
cd81e915
NC
10828 CURMAD('q', PL_thisopen);
10829 CURMAD('_', PL_thiswhite);
10830 CURMAD('E', PL_thisstuff);
10831 CURMAD('Q', PL_thisclose);
10832 PL_realtokenstart = s - SvPVX(PL_linestr);
5db06880
NC
10833 }
10834#endif
79072805 10835
3280af22 10836 first_start = PL_multi_start;
5db06880 10837 s = scan_str(s,!!PL_madskills,FALSE);
79072805 10838 if (!s) {
37fd879b 10839 if (PL_lex_stuff) {
3280af22 10840 SvREFCNT_dec(PL_lex_stuff);
a0714e2c 10841 PL_lex_stuff = NULL;
37fd879b 10842 }
cea2e8a9 10843 Perl_croak(aTHX_ "Substitution replacement not terminated");
a687059c 10844 }
3280af22 10845 PL_multi_start = first_start; /* so whole substitution is taken together */
2f3197b3 10846
79072805 10847 pm = (PMOP*)newPMOP(OP_SUBST, 0);
5db06880
NC
10848
10849#ifdef PERL_MAD
10850 if (PL_madskills) {
cd81e915
NC
10851 CURMAD('z', PL_thisopen);
10852 CURMAD('R', PL_thisstuff);
10853 CURMAD('Z', PL_thisclose);
5db06880
NC
10854 }
10855 modstart = s;
10856#endif
10857
48c036b1 10858 while (*s) {
a687059c
LW
10859 if (*s == 'e') {
10860 s++;
2f3197b3 10861 es++;
a687059c 10862 }
b3eb6a9b 10863 else if (strchr("iogcmsx", *s))
a0d0e21e 10864 pmflag(&pm->op_pmflags,*s++);
48c036b1
GS
10865 else
10866 break;
378cc40b 10867 }
79072805 10868
5db06880
NC
10869#ifdef PERL_MAD
10870 if (PL_madskills) {
10871 if (modstart != s)
10872 curmad('m', newSVpvn(modstart, s - modstart));
cd81e915
NC
10873 append_madprops(PL_thismad, (OP*)pm, 0);
10874 PL_thismad = 0;
5db06880
NC
10875 }
10876#endif
0bd48802
AL
10877 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10878 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
4ac733c9
MJD
10879 }
10880
79072805 10881 if (es) {
6136c704
AL
10882 SV * const repl = newSVpvs("");
10883
0244c3a4
GS
10884 PL_sublex_info.super_bufptr = s;
10885 PL_sublex_info.super_bufend = PL_bufend;
10886 PL_multi_end = 0;
79072805 10887 pm->op_pmflags |= PMf_EVAL;
463ee0b2 10888 while (es-- > 0)
10edeb5d 10889 sv_catpv(repl, (const char *)(es ? "eval " : "do "));
6f43d98f 10890 sv_catpvs(repl, "{");
3280af22 10891 sv_catsv(repl, PL_lex_repl);
9badc361
RGS
10892 if (strchr(SvPVX(PL_lex_repl), '#'))
10893 sv_catpvs(repl, "\n");
10894 sv_catpvs(repl, "}");
25da4f38 10895 SvEVALED_on(repl);
3280af22
NIS
10896 SvREFCNT_dec(PL_lex_repl);
10897 PL_lex_repl = repl;
378cc40b 10898 }
79072805 10899
4633a7c4 10900 pm->op_pmpermflags = pm->op_pmflags;
3280af22 10901 PL_lex_op = (OP*)pm;
79072805 10902 yylval.ival = OP_SUBST;
378cc40b
LW
10903 return s;
10904}
10905
76e3520e 10906STATIC char *
cea2e8a9 10907S_scan_trans(pTHX_ char *start)
378cc40b 10908{
97aff369 10909 dVAR;
a0d0e21e 10910 register char* s;
11343788 10911 OP *o;
79072805
LW
10912 short *tbl;
10913 I32 squash;
a0ed51b3 10914 I32 del;
79072805 10915 I32 complement;
5db06880
NC
10916#ifdef PERL_MAD
10917 char *modstart;
10918#endif
79072805
LW
10919
10920 yylval.ival = OP_NULL;
10921
5db06880 10922 s = scan_str(start,!!PL_madskills,FALSE);
37fd879b 10923 if (!s)
cea2e8a9 10924 Perl_croak(aTHX_ "Transliteration pattern not terminated");
5db06880 10925
3280af22 10926 if (s[-1] == PL_multi_open)
2f3197b3 10927 s--;
5db06880
NC
10928#ifdef PERL_MAD
10929 if (PL_madskills) {
cd81e915
NC
10930 CURMAD('q', PL_thisopen);
10931 CURMAD('_', PL_thiswhite);
10932 CURMAD('E', PL_thisstuff);
10933 CURMAD('Q', PL_thisclose);
10934 PL_realtokenstart = s - SvPVX(PL_linestr);
5db06880
NC
10935 }
10936#endif
2f3197b3 10937
5db06880 10938 s = scan_str(s,!!PL_madskills,FALSE);
79072805 10939 if (!s) {
37fd879b 10940 if (PL_lex_stuff) {
3280af22 10941 SvREFCNT_dec(PL_lex_stuff);
a0714e2c 10942 PL_lex_stuff = NULL;
37fd879b 10943 }
cea2e8a9 10944 Perl_croak(aTHX_ "Transliteration replacement not terminated");
a687059c 10945 }
5db06880 10946 if (PL_madskills) {
cd81e915
NC
10947 CURMAD('z', PL_thisopen);
10948 CURMAD('R', PL_thisstuff);
10949 CURMAD('Z', PL_thisclose);
5db06880 10950 }
79072805 10951
a0ed51b3 10952 complement = del = squash = 0;
5db06880
NC
10953#ifdef PERL_MAD
10954 modstart = s;
10955#endif
7a1e2023
NC
10956 while (1) {
10957 switch (*s) {
10958 case 'c':
79072805 10959 complement = OPpTRANS_COMPLEMENT;
7a1e2023
NC
10960 break;
10961 case 'd':
a0ed51b3 10962 del = OPpTRANS_DELETE;
7a1e2023
NC
10963 break;
10964 case 's':
79072805 10965 squash = OPpTRANS_SQUASH;
7a1e2023
NC
10966 break;
10967 default:
10968 goto no_more;
10969 }
395c3793
LW
10970 s++;
10971 }
7a1e2023 10972 no_more:
8973db79 10973
a02a5408 10974 Newx(tbl, complement&&!del?258:256, short);
8973db79 10975 o = newPVOP(OP_TRANS, 0, (char*)tbl);
59f00321
RGS
10976 o->op_private &= ~OPpTRANS_ALL;
10977 o->op_private |= del|squash|complement|
7948272d
NIS
10978 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
10979 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
79072805 10980
3280af22 10981 PL_lex_op = o;
79072805 10982 yylval.ival = OP_TRANS;
5db06880
NC
10983
10984#ifdef PERL_MAD
10985 if (PL_madskills) {
10986 if (modstart != s)
10987 curmad('m', newSVpvn(modstart, s - modstart));
cd81e915
NC
10988 append_madprops(PL_thismad, o, 0);
10989 PL_thismad = 0;
5db06880
NC
10990 }
10991#endif
10992
79072805
LW
10993 return s;
10994}
10995
76e3520e 10996STATIC char *
cea2e8a9 10997S_scan_heredoc(pTHX_ register char *s)
79072805 10998{
97aff369 10999 dVAR;
79072805
LW
11000 SV *herewas;
11001 I32 op_type = OP_SCALAR;
11002 I32 len;
11003 SV *tmpstr;
11004 char term;
73d840c0 11005 const char *found_newline;
79072805 11006 register char *d;
fc36a67e 11007 register char *e;
4633a7c4 11008 char *peek;
f54cb97a 11009 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
5db06880
NC
11010#ifdef PERL_MAD
11011 I32 stuffstart = s - SvPVX(PL_linestr);
11012 char *tstart;
11013
cd81e915 11014 PL_realtokenstart = -1;
5db06880 11015#endif
79072805
LW
11016
11017 s += 2;
3280af22
NIS
11018 d = PL_tokenbuf;
11019 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
fd2d0953 11020 if (!outer)
79072805 11021 *d++ = '\n';
c35e046a
AL
11022 peek = s;
11023 while (SPACE_OR_TAB(*peek))
11024 peek++;
3792a11b 11025 if (*peek == '`' || *peek == '\'' || *peek =='"') {
4633a7c4 11026 s = peek;
79072805 11027 term = *s++;
3280af22 11028 s = delimcpy(d, e, s, PL_bufend, term, &len);
fc36a67e 11029 d += len;
3280af22 11030 if (s < PL_bufend)
79072805 11031 s++;
79072805
LW
11032 }
11033 else {
11034 if (*s == '\\')
11035 s++, term = '\'';
11036 else
11037 term = '"';
7e2040f0 11038 if (!isALNUM_lazy_if(s,UTF))
12bcd1a6 11039 deprecate_old("bare << to mean <<\"\"");
7e2040f0 11040 for (; isALNUM_lazy_if(s,UTF); s++) {
fc36a67e 11041 if (d < e)
11042 *d++ = *s;
11043 }
11044 }
3280af22 11045 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
cea2e8a9 11046 Perl_croak(aTHX_ "Delimiter for here document is too long");
79072805
LW
11047 *d++ = '\n';
11048 *d = '\0';
3280af22 11049 len = d - PL_tokenbuf;
5db06880
NC
11050
11051#ifdef PERL_MAD
11052 if (PL_madskills) {
11053 tstart = PL_tokenbuf + !outer;
cd81e915 11054 PL_thisclose = newSVpvn(tstart, len - !outer);
5db06880 11055 tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915 11056 PL_thisopen = newSVpvn(tstart, s - tstart);
5db06880
NC
11057 stuffstart = s - SvPVX(PL_linestr);
11058 }
11059#endif
6a27c188 11060#ifndef PERL_STRICT_CR
f63a84b2
LW
11061 d = strchr(s, '\r');
11062 if (d) {
b464bac0 11063 char * const olds = s;
f63a84b2 11064 s = d;
3280af22 11065 while (s < PL_bufend) {
f63a84b2
LW
11066 if (*s == '\r') {
11067 *d++ = '\n';
11068 if (*++s == '\n')
11069 s++;
11070 }
11071 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
11072 *d++ = *s++;
11073 s++;
11074 }
11075 else
11076 *d++ = *s++;
11077 }
11078 *d = '\0';
3280af22 11079 PL_bufend = d;
95a20fc0 11080 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
f63a84b2
LW
11081 s = olds;
11082 }
11083#endif
5db06880
NC
11084#ifdef PERL_MAD
11085 found_newline = 0;
11086#endif
10edeb5d 11087 if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
73d840c0
AL
11088 herewas = newSVpvn(s,PL_bufend-s);
11089 }
11090 else {
5db06880
NC
11091#ifdef PERL_MAD
11092 herewas = newSVpvn(s-1,found_newline-s+1);
11093#else
73d840c0
AL
11094 s--;
11095 herewas = newSVpvn(s,found_newline-s);
5db06880 11096#endif
73d840c0 11097 }
5db06880
NC
11098#ifdef PERL_MAD
11099 if (PL_madskills) {
11100 tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915
NC
11101 if (PL_thisstuff)
11102 sv_catpvn(PL_thisstuff, tstart, s - tstart);
5db06880 11103 else
cd81e915 11104 PL_thisstuff = newSVpvn(tstart, s - tstart);
5db06880
NC
11105 }
11106#endif
79072805 11107 s += SvCUR(herewas);
748a9306 11108
5db06880
NC
11109#ifdef PERL_MAD
11110 stuffstart = s - SvPVX(PL_linestr);
11111
11112 if (found_newline)
11113 s--;
11114#endif
11115
561b68a9 11116 tmpstr = newSV(79);
748a9306
LW
11117 sv_upgrade(tmpstr, SVt_PVIV);
11118 if (term == '\'') {
79072805 11119 op_type = OP_CONST;
45977657 11120 SvIV_set(tmpstr, -1);
748a9306
LW
11121 }
11122 else if (term == '`') {
79072805 11123 op_type = OP_BACKTICK;
45977657 11124 SvIV_set(tmpstr, '\\');
748a9306 11125 }
79072805
LW
11126
11127 CLINE;
57843af0 11128 PL_multi_start = CopLINE(PL_curcop);
3280af22
NIS
11129 PL_multi_open = PL_multi_close = '<';
11130 term = *PL_tokenbuf;
0244c3a4 11131 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
6136c704
AL
11132 char * const bufptr = PL_sublex_info.super_bufptr;
11133 char * const bufend = PL_sublex_info.super_bufend;
b464bac0 11134 char * const olds = s - SvCUR(herewas);
0244c3a4
GS
11135 s = strchr(bufptr, '\n');
11136 if (!s)
11137 s = bufend;
11138 d = s;
11139 while (s < bufend &&
11140 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11141 if (*s++ == '\n')
57843af0 11142 CopLINE_inc(PL_curcop);
0244c3a4
GS
11143 }
11144 if (s >= bufend) {
eb160463 11145 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
0244c3a4
GS
11146 missingterm(PL_tokenbuf);
11147 }
11148 sv_setpvn(herewas,bufptr,d-bufptr+1);
11149 sv_setpvn(tmpstr,d+1,s-d);
11150 s += len - 1;
11151 sv_catpvn(herewas,s,bufend-s);
95a20fc0 11152 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
0244c3a4
GS
11153
11154 s = olds;
11155 goto retval;
11156 }
11157 else if (!outer) {
79072805 11158 d = s;
3280af22
NIS
11159 while (s < PL_bufend &&
11160 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
79072805 11161 if (*s++ == '\n')
57843af0 11162 CopLINE_inc(PL_curcop);
79072805 11163 }
3280af22 11164 if (s >= PL_bufend) {
eb160463 11165 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
3280af22 11166 missingterm(PL_tokenbuf);
79072805
LW
11167 }
11168 sv_setpvn(tmpstr,d+1,s-d);
5db06880
NC
11169#ifdef PERL_MAD
11170 if (PL_madskills) {
cd81e915
NC
11171 if (PL_thisstuff)
11172 sv_catpvn(PL_thisstuff, d + 1, s - d);
5db06880 11173 else
cd81e915 11174 PL_thisstuff = newSVpvn(d + 1, s - d);
5db06880
NC
11175 stuffstart = s - SvPVX(PL_linestr);
11176 }
11177#endif
79072805 11178 s += len - 1;
57843af0 11179 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
49d8d3a1 11180
3280af22
NIS
11181 sv_catpvn(herewas,s,PL_bufend-s);
11182 sv_setsv(PL_linestr,herewas);
11183 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11184 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 11185 PL_last_lop = PL_last_uni = NULL;
79072805
LW
11186 }
11187 else
11188 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
3280af22 11189 while (s >= PL_bufend) { /* multiple line string? */
5db06880
NC
11190#ifdef PERL_MAD
11191 if (PL_madskills) {
11192 tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915
NC
11193 if (PL_thisstuff)
11194 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
5db06880 11195 else
cd81e915 11196 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
5db06880
NC
11197 }
11198#endif
fd2d0953 11199 if (!outer ||
3280af22 11200 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
eb160463 11201 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
3280af22 11202 missingterm(PL_tokenbuf);
79072805 11203 }
5db06880
NC
11204#ifdef PERL_MAD
11205 stuffstart = s - SvPVX(PL_linestr);
11206#endif
57843af0 11207 CopLINE_inc(PL_curcop);
3280af22 11208 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 11209 PL_last_lop = PL_last_uni = NULL;
6a27c188 11210#ifndef PERL_STRICT_CR
3280af22 11211 if (PL_bufend - PL_linestart >= 2) {
a1529941
NIS
11212 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11213 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
c6f14548 11214 {
3280af22
NIS
11215 PL_bufend[-2] = '\n';
11216 PL_bufend--;
95a20fc0 11217 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
f63a84b2 11218 }
3280af22
NIS
11219 else if (PL_bufend[-1] == '\r')
11220 PL_bufend[-1] = '\n';
f63a84b2 11221 }
3280af22
NIS
11222 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11223 PL_bufend[-1] = '\n';
f63a84b2 11224#endif
80a702cd
RGS
11225 if (PERLDB_LINE && PL_curstash != PL_debstash)
11226 update_debugger_info_sv(PL_linestr);
3280af22 11227 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
95a20fc0 11228 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
1de9afcd 11229 *(SvPVX(PL_linestr) + off ) = ' ';
3280af22
NIS
11230 sv_catsv(PL_linestr,herewas);
11231 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1de9afcd 11232 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
79072805
LW
11233 }
11234 else {
3280af22
NIS
11235 s = PL_bufend;
11236 sv_catsv(tmpstr,PL_linestr);
395c3793
LW
11237 }
11238 }
79072805 11239 s++;
0244c3a4 11240retval:
57843af0 11241 PL_multi_end = CopLINE(PL_curcop);
79072805 11242 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
1da4ca5f 11243 SvPV_shrink_to_cur(tmpstr);
79072805 11244 }
8990e307 11245 SvREFCNT_dec(herewas);
2f31ce75 11246 if (!IN_BYTES) {
95a20fc0 11247 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
2f31ce75
JH
11248 SvUTF8_on(tmpstr);
11249 else if (PL_encoding)
11250 sv_recode_to_utf8(tmpstr, PL_encoding);
11251 }
3280af22 11252 PL_lex_stuff = tmpstr;
79072805
LW
11253 yylval.ival = op_type;
11254 return s;
11255}
11256
02aa26ce
NT
11257/* scan_inputsymbol
11258 takes: current position in input buffer
11259 returns: new position in input buffer
11260 side-effects: yylval and lex_op are set.
11261
11262 This code handles:
11263
11264 <> read from ARGV
11265 <FH> read from filehandle
11266 <pkg::FH> read from package qualified filehandle
11267 <pkg'FH> read from package qualified filehandle
11268 <$fh> read from filehandle in $fh
11269 <*.h> filename glob
11270
11271*/
11272
76e3520e 11273STATIC char *
cea2e8a9 11274S_scan_inputsymbol(pTHX_ char *start)
79072805 11275{
97aff369 11276 dVAR;
02aa26ce 11277 register char *s = start; /* current position in buffer */
1b420867 11278 char *end;
79072805
LW
11279 I32 len;
11280
6136c704
AL
11281 char *d = PL_tokenbuf; /* start of temp holding space */
11282 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11283
1b420867
GS
11284 end = strchr(s, '\n');
11285 if (!end)
11286 end = PL_bufend;
11287 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
02aa26ce
NT
11288
11289 /* die if we didn't have space for the contents of the <>,
1b420867 11290 or if it didn't end, or if we see a newline
02aa26ce
NT
11291 */
11292
bb7a0f54 11293 if (len >= (I32)sizeof PL_tokenbuf)
cea2e8a9 11294 Perl_croak(aTHX_ "Excessively long <> operator");
1b420867 11295 if (s >= end)
cea2e8a9 11296 Perl_croak(aTHX_ "Unterminated <> operator");
02aa26ce 11297
fc36a67e 11298 s++;
02aa26ce
NT
11299
11300 /* check for <$fh>
11301 Remember, only scalar variables are interpreted as filehandles by
11302 this code. Anything more complex (e.g., <$fh{$num}>) will be
11303 treated as a glob() call.
11304 This code makes use of the fact that except for the $ at the front,
11305 a scalar variable and a filehandle look the same.
11306 */
4633a7c4 11307 if (*d == '$' && d[1]) d++;
02aa26ce
NT
11308
11309 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
7e2040f0 11310 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
79072805 11311 d++;
02aa26ce
NT
11312
11313 /* If we've tried to read what we allow filehandles to look like, and
11314 there's still text left, then it must be a glob() and not a getline.
11315 Use scan_str to pull out the stuff between the <> and treat it
11316 as nothing more than a string.
11317 */
11318
3280af22 11319 if (d - PL_tokenbuf != len) {
79072805
LW
11320 yylval.ival = OP_GLOB;
11321 set_csh();
5db06880 11322 s = scan_str(start,!!PL_madskills,FALSE);
79072805 11323 if (!s)
cea2e8a9 11324 Perl_croak(aTHX_ "Glob not terminated");
79072805
LW
11325 return s;
11326 }
395c3793 11327 else {
9b3023bc 11328 bool readline_overriden = FALSE;
6136c704 11329 GV *gv_readline;
9b3023bc 11330 GV **gvp;
02aa26ce 11331 /* we're in a filehandle read situation */
3280af22 11332 d = PL_tokenbuf;
02aa26ce
NT
11333
11334 /* turn <> into <ARGV> */
79072805 11335 if (!len)
689badd5 11336 Copy("ARGV",d,5,char);
02aa26ce 11337
9b3023bc 11338 /* Check whether readline() is overriden */
fafc274c 11339 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
6136c704 11340 if ((gv_readline
ba979b31 11341 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
9b3023bc 11342 ||
017a3ce5 11343 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
9b3023bc 11344 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
ba979b31 11345 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
9b3023bc
RGS
11346 readline_overriden = TRUE;
11347
02aa26ce
NT
11348 /* if <$fh>, create the ops to turn the variable into a
11349 filehandle
11350 */
79072805 11351 if (*d == '$') {
02aa26ce
NT
11352 /* try to find it in the pad for this block, otherwise find
11353 add symbol table ops
11354 */
bbd11bfc
AL
11355 const PADOFFSET tmp = pad_findmy(d);
11356 if (tmp != NOT_IN_PAD) {
00b1698f 11357 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6136c704
AL
11358 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11359 HEK * const stashname = HvNAME_HEK(stash);
11360 SV * const sym = sv_2mortal(newSVhek(stashname));
396482e1 11361 sv_catpvs(sym, "::");
f558d5af
JH
11362 sv_catpv(sym, d+1);
11363 d = SvPVX(sym);
11364 goto intro_sym;
11365 }
11366 else {
6136c704 11367 OP * const o = newOP(OP_PADSV, 0);
f558d5af 11368 o->op_targ = tmp;
9b3023bc
RGS
11369 PL_lex_op = readline_overriden
11370 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11371 append_elem(OP_LIST, o,
11372 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11373 : (OP*)newUNOP(OP_READLINE, 0, o);
f558d5af 11374 }
a0d0e21e
LW
11375 }
11376 else {
f558d5af
JH
11377 GV *gv;
11378 ++d;
11379intro_sym:
11380 gv = gv_fetchpv(d,
11381 (PL_in_eval
11382 ? (GV_ADDMULTI | GV_ADDINEVAL)
bea70d1e 11383 : GV_ADDMULTI),
f558d5af 11384 SVt_PV);
9b3023bc
RGS
11385 PL_lex_op = readline_overriden
11386 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11387 append_elem(OP_LIST,
11388 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11389 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11390 : (OP*)newUNOP(OP_READLINE, 0,
11391 newUNOP(OP_RV2SV, 0,
11392 newGVOP(OP_GV, 0, gv)));
a0d0e21e 11393 }
7c6fadd6
RGS
11394 if (!readline_overriden)
11395 PL_lex_op->op_flags |= OPf_SPECIAL;
f5284f61 11396 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
79072805
LW
11397 yylval.ival = OP_NULL;
11398 }
02aa26ce
NT
11399
11400 /* If it's none of the above, it must be a literal filehandle
11401 (<Foo::BAR> or <FOO>) so build a simple readline OP */
79072805 11402 else {
6136c704 11403 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
9b3023bc
RGS
11404 PL_lex_op = readline_overriden
11405 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11406 append_elem(OP_LIST,
11407 newGVOP(OP_GV, 0, gv),
11408 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11409 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
79072805
LW
11410 yylval.ival = OP_NULL;
11411 }
11412 }
02aa26ce 11413
79072805
LW
11414 return s;
11415}
11416
02aa26ce
NT
11417
11418/* scan_str
11419 takes: start position in buffer
09bef843
SB
11420 keep_quoted preserve \ on the embedded delimiter(s)
11421 keep_delims preserve the delimiters around the string
02aa26ce
NT
11422 returns: position to continue reading from buffer
11423 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11424 updates the read buffer.
11425
11426 This subroutine pulls a string out of the input. It is called for:
11427 q single quotes q(literal text)
11428 ' single quotes 'literal text'
11429 qq double quotes qq(interpolate $here please)
11430 " double quotes "interpolate $here please"
11431 qx backticks qx(/bin/ls -l)
11432 ` backticks `/bin/ls -l`
11433 qw quote words @EXPORT_OK = qw( func() $spam )
11434 m// regexp match m/this/
11435 s/// regexp substitute s/this/that/
11436 tr/// string transliterate tr/this/that/
11437 y/// string transliterate y/this/that/
11438 ($*@) sub prototypes sub foo ($)
09bef843 11439 (stuff) sub attr parameters sub foo : attr(stuff)
02aa26ce
NT
11440 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11441
11442 In most of these cases (all but <>, patterns and transliterate)
11443 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11444 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11445 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11446 calls scan_str().
4e553d73 11447
02aa26ce
NT
11448 It skips whitespace before the string starts, and treats the first
11449 character as the delimiter. If the delimiter is one of ([{< then
11450 the corresponding "close" character )]}> is used as the closing
11451 delimiter. It allows quoting of delimiters, and if the string has
11452 balanced delimiters ([{<>}]) it allows nesting.
11453
37fd879b
HS
11454 On success, the SV with the resulting string is put into lex_stuff or,
11455 if that is already non-NULL, into lex_repl. The second case occurs only
11456 when parsing the RHS of the special constructs s/// and tr/// (y///).
11457 For convenience, the terminating delimiter character is stuffed into
11458 SvIVX of the SV.
02aa26ce
NT
11459*/
11460
76e3520e 11461STATIC char *
09bef843 11462S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
79072805 11463{
97aff369 11464 dVAR;
02aa26ce 11465 SV *sv; /* scalar value: string */
d3fcec1f 11466 const char *tmps; /* temp string, used for delimiter matching */
02aa26ce
NT
11467 register char *s = start; /* current position in the buffer */
11468 register char term; /* terminating character */
11469 register char *to; /* current position in the sv's data */
11470 I32 brackets = 1; /* bracket nesting level */
89491803 11471 bool has_utf8 = FALSE; /* is there any utf8 content? */
220e2d4e 11472 I32 termcode; /* terminating char. code */
89ebb4a3 11473 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
220e2d4e 11474 STRLEN termlen; /* length of terminating string */
0331ef07 11475 int last_off = 0; /* last position for nesting bracket */
5db06880
NC
11476#ifdef PERL_MAD
11477 int stuffstart;
11478 char *tstart;
11479#endif
02aa26ce
NT
11480
11481 /* skip space before the delimiter */
29595ff2
NC
11482 if (isSPACE(*s)) {
11483 s = PEEKSPACE(s);
11484 }
02aa26ce 11485
5db06880 11486#ifdef PERL_MAD
cd81e915
NC
11487 if (PL_realtokenstart >= 0) {
11488 stuffstart = PL_realtokenstart;
11489 PL_realtokenstart = -1;
5db06880
NC
11490 }
11491 else
11492 stuffstart = start - SvPVX(PL_linestr);
11493#endif
02aa26ce 11494 /* mark where we are, in case we need to report errors */
79072805 11495 CLINE;
02aa26ce
NT
11496
11497 /* after skipping whitespace, the next character is the terminator */
a0d0e21e 11498 term = *s;
220e2d4e
IH
11499 if (!UTF) {
11500 termcode = termstr[0] = term;
11501 termlen = 1;
11502 }
11503 else {
f3b9ce0f 11504 termcode = utf8_to_uvchr((U8*)s, &termlen);
220e2d4e
IH
11505 Copy(s, termstr, termlen, U8);
11506 if (!UTF8_IS_INVARIANT(term))
11507 has_utf8 = TRUE;
11508 }
b1c7b182 11509
02aa26ce 11510 /* mark where we are */
57843af0 11511 PL_multi_start = CopLINE(PL_curcop);
3280af22 11512 PL_multi_open = term;
02aa26ce
NT
11513
11514 /* find corresponding closing delimiter */
93a17b20 11515 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
220e2d4e
IH
11516 termcode = termstr[0] = term = tmps[5];
11517
3280af22 11518 PL_multi_close = term;
79072805 11519
561b68a9
SH
11520 /* create a new SV to hold the contents. 79 is the SV's initial length.
11521 What a random number. */
11522 sv = newSV(79);
ed6116ce 11523 sv_upgrade(sv, SVt_PVIV);
45977657 11524 SvIV_set(sv, termcode);
a0d0e21e 11525 (void)SvPOK_only(sv); /* validate pointer */
02aa26ce
NT
11526
11527 /* move past delimiter and try to read a complete string */
09bef843 11528 if (keep_delims)
220e2d4e
IH
11529 sv_catpvn(sv, s, termlen);
11530 s += termlen;
5db06880
NC
11531#ifdef PERL_MAD
11532 tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915
NC
11533 if (!PL_thisopen && !keep_delims) {
11534 PL_thisopen = newSVpvn(tstart, s - tstart);
5db06880
NC
11535 stuffstart = s - SvPVX(PL_linestr);
11536 }
11537#endif
93a17b20 11538 for (;;) {
220e2d4e
IH
11539 if (PL_encoding && !UTF) {
11540 bool cont = TRUE;
11541
11542 while (cont) {
95a20fc0 11543 int offset = s - SvPVX_const(PL_linestr);
66a1b24b 11544 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
f3b9ce0f 11545 &offset, (char*)termstr, termlen);
6136c704
AL
11546 const char * const ns = SvPVX_const(PL_linestr) + offset;
11547 char * const svlast = SvEND(sv) - 1;
220e2d4e
IH
11548
11549 for (; s < ns; s++) {
11550 if (*s == '\n' && !PL_rsfp)
11551 CopLINE_inc(PL_curcop);
11552 }
11553 if (!found)
11554 goto read_more_line;
11555 else {
11556 /* handle quoted delimiters */
52327caf 11557 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
f54cb97a 11558 const char *t;
95a20fc0 11559 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
220e2d4e
IH
11560 t--;
11561 if ((svlast-1 - t) % 2) {
11562 if (!keep_quoted) {
11563 *(svlast-1) = term;
11564 *svlast = '\0';
11565 SvCUR_set(sv, SvCUR(sv) - 1);
11566 }
11567 continue;
11568 }
11569 }
11570 if (PL_multi_open == PL_multi_close) {
11571 cont = FALSE;
11572 }
11573 else {
f54cb97a
AL
11574 const char *t;
11575 char *w;
0331ef07 11576 for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
220e2d4e
IH
11577 /* At here, all closes are "was quoted" one,
11578 so we don't check PL_multi_close. */
11579 if (*t == '\\') {
11580 if (!keep_quoted && *(t+1) == PL_multi_open)
11581 t++;
11582 else
11583 *w++ = *t++;
11584 }
11585 else if (*t == PL_multi_open)
11586 brackets++;
11587
11588 *w = *t;
11589 }
11590 if (w < t) {
11591 *w++ = term;
11592 *w = '\0';
95a20fc0 11593 SvCUR_set(sv, w - SvPVX_const(sv));
220e2d4e 11594 }
0331ef07 11595 last_off = w - SvPVX(sv);
220e2d4e
IH
11596 if (--brackets <= 0)
11597 cont = FALSE;
11598 }
11599 }
11600 }
11601 if (!keep_delims) {
11602 SvCUR_set(sv, SvCUR(sv) - 1);
11603 *SvEND(sv) = '\0';
11604 }
11605 break;
11606 }
11607
02aa26ce 11608 /* extend sv if need be */
3280af22 11609 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
02aa26ce 11610 /* set 'to' to the next character in the sv's string */
463ee0b2 11611 to = SvPVX(sv)+SvCUR(sv);
09bef843 11612
02aa26ce 11613 /* if open delimiter is the close delimiter read unbridle */
3280af22
NIS
11614 if (PL_multi_open == PL_multi_close) {
11615 for (; s < PL_bufend; s++,to++) {
02aa26ce 11616 /* embedded newlines increment the current line number */
3280af22 11617 if (*s == '\n' && !PL_rsfp)
57843af0 11618 CopLINE_inc(PL_curcop);
02aa26ce 11619 /* handle quoted delimiters */
3280af22 11620 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
09bef843 11621 if (!keep_quoted && s[1] == term)
a0d0e21e 11622 s++;
02aa26ce 11623 /* any other quotes are simply copied straight through */
a0d0e21e
LW
11624 else
11625 *to++ = *s++;
11626 }
02aa26ce
NT
11627 /* terminate when run out of buffer (the for() condition), or
11628 have found the terminator */
220e2d4e
IH
11629 else if (*s == term) {
11630 if (termlen == 1)
11631 break;
f3b9ce0f 11632 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
220e2d4e
IH
11633 break;
11634 }
63cd0674 11635 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
89491803 11636 has_utf8 = TRUE;
93a17b20
LW
11637 *to = *s;
11638 }
11639 }
02aa26ce
NT
11640
11641 /* if the terminator isn't the same as the start character (e.g.,
11642 matched brackets), we have to allow more in the quoting, and
11643 be prepared for nested brackets.
11644 */
93a17b20 11645 else {
02aa26ce 11646 /* read until we run out of string, or we find the terminator */
3280af22 11647 for (; s < PL_bufend; s++,to++) {
02aa26ce 11648 /* embedded newlines increment the line count */
3280af22 11649 if (*s == '\n' && !PL_rsfp)
57843af0 11650 CopLINE_inc(PL_curcop);
02aa26ce 11651 /* backslashes can escape the open or closing characters */
3280af22 11652 if (*s == '\\' && s+1 < PL_bufend) {
09bef843
SB
11653 if (!keep_quoted &&
11654 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
a0d0e21e
LW
11655 s++;
11656 else
11657 *to++ = *s++;
11658 }
02aa26ce 11659 /* allow nested opens and closes */
3280af22 11660 else if (*s == PL_multi_close && --brackets <= 0)
93a17b20 11661 break;
3280af22 11662 else if (*s == PL_multi_open)
93a17b20 11663 brackets++;
63cd0674 11664 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
89491803 11665 has_utf8 = TRUE;
93a17b20
LW
11666 *to = *s;
11667 }
11668 }
02aa26ce 11669 /* terminate the copied string and update the sv's end-of-string */
93a17b20 11670 *to = '\0';
95a20fc0 11671 SvCUR_set(sv, to - SvPVX_const(sv));
93a17b20 11672
02aa26ce
NT
11673 /*
11674 * this next chunk reads more into the buffer if we're not done yet
11675 */
11676
b1c7b182
GS
11677 if (s < PL_bufend)
11678 break; /* handle case where we are done yet :-) */
79072805 11679
6a27c188 11680#ifndef PERL_STRICT_CR
95a20fc0 11681 if (to - SvPVX_const(sv) >= 2) {
c6f14548
GS
11682 if ((to[-2] == '\r' && to[-1] == '\n') ||
11683 (to[-2] == '\n' && to[-1] == '\r'))
11684 {
f63a84b2
LW
11685 to[-2] = '\n';
11686 to--;
95a20fc0 11687 SvCUR_set(sv, to - SvPVX_const(sv));
f63a84b2
LW
11688 }
11689 else if (to[-1] == '\r')
11690 to[-1] = '\n';
11691 }
95a20fc0 11692 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
f63a84b2
LW
11693 to[-1] = '\n';
11694#endif
11695
220e2d4e 11696 read_more_line:
02aa26ce
NT
11697 /* if we're out of file, or a read fails, bail and reset the current
11698 line marker so we can report where the unterminated string began
11699 */
5db06880
NC
11700#ifdef PERL_MAD
11701 if (PL_madskills) {
c35e046a 11702 char * const tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915
NC
11703 if (PL_thisstuff)
11704 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
5db06880 11705 else
cd81e915 11706 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
5db06880
NC
11707 }
11708#endif
3280af22
NIS
11709 if (!PL_rsfp ||
11710 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
c07a80fd 11711 sv_free(sv);
eb160463 11712 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
bd61b366 11713 return NULL;
79072805 11714 }
5db06880
NC
11715#ifdef PERL_MAD
11716 stuffstart = 0;
11717#endif
02aa26ce 11718 /* we read a line, so increment our line counter */
57843af0 11719 CopLINE_inc(PL_curcop);
a0ed51b3 11720
02aa26ce 11721 /* update debugger info */
80a702cd
RGS
11722 if (PERLDB_LINE && PL_curstash != PL_debstash)
11723 update_debugger_info_sv(PL_linestr);
a0ed51b3 11724
3280af22
NIS
11725 /* having changed the buffer, we must update PL_bufend */
11726 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 11727 PL_last_lop = PL_last_uni = NULL;
378cc40b 11728 }
4e553d73 11729
02aa26ce
NT
11730 /* at this point, we have successfully read the delimited string */
11731
220e2d4e 11732 if (!PL_encoding || UTF) {
5db06880
NC
11733#ifdef PERL_MAD
11734 if (PL_madskills) {
c35e046a
AL
11735 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11736 const int len = s - start;
cd81e915 11737 if (PL_thisstuff)
c35e046a 11738 sv_catpvn(PL_thisstuff, tstart, len);
5db06880 11739 else
c35e046a 11740 PL_thisstuff = newSVpvn(tstart, len);
cd81e915
NC
11741 if (!PL_thisclose && !keep_delims)
11742 PL_thisclose = newSVpvn(s,termlen);
5db06880
NC
11743 }
11744#endif
11745
220e2d4e
IH
11746 if (keep_delims)
11747 sv_catpvn(sv, s, termlen);
11748 s += termlen;
11749 }
5db06880
NC
11750#ifdef PERL_MAD
11751 else {
11752 if (PL_madskills) {
c35e046a
AL
11753 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11754 const int len = s - tstart - termlen;
cd81e915 11755 if (PL_thisstuff)
c35e046a 11756 sv_catpvn(PL_thisstuff, tstart, len);
5db06880 11757 else
c35e046a 11758 PL_thisstuff = newSVpvn(tstart, len);
cd81e915
NC
11759 if (!PL_thisclose && !keep_delims)
11760 PL_thisclose = newSVpvn(s - termlen,termlen);
5db06880
NC
11761 }
11762 }
11763#endif
220e2d4e 11764 if (has_utf8 || PL_encoding)
b1c7b182 11765 SvUTF8_on(sv);
d0063567 11766
57843af0 11767 PL_multi_end = CopLINE(PL_curcop);
02aa26ce
NT
11768
11769 /* if we allocated too much space, give some back */
93a17b20
LW
11770 if (SvCUR(sv) + 5 < SvLEN(sv)) {
11771 SvLEN_set(sv, SvCUR(sv) + 1);
b7e9a5c2 11772 SvPV_renew(sv, SvLEN(sv));
79072805 11773 }
02aa26ce
NT
11774
11775 /* decide whether this is the first or second quoted string we've read
11776 for this op
11777 */
4e553d73 11778
3280af22
NIS
11779 if (PL_lex_stuff)
11780 PL_lex_repl = sv;
79072805 11781 else
3280af22 11782 PL_lex_stuff = sv;
378cc40b
LW
11783 return s;
11784}
11785
02aa26ce
NT
11786/*
11787 scan_num
11788 takes: pointer to position in buffer
11789 returns: pointer to new position in buffer
11790 side-effects: builds ops for the constant in yylval.op
11791
11792 Read a number in any of the formats that Perl accepts:
11793
7fd134d9
JH
11794 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
11795 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
24138b49
JH
11796 0b[01](_?[01])*
11797 0[0-7](_?[0-7])*
11798 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
02aa26ce 11799
3280af22 11800 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
02aa26ce
NT
11801 thing it reads.
11802
11803 If it reads a number without a decimal point or an exponent, it will
11804 try converting the number to an integer and see if it can do so
11805 without loss of precision.
11806*/
4e553d73 11807
378cc40b 11808char *
bfed75c6 11809Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
378cc40b 11810{
97aff369 11811 dVAR;
bfed75c6 11812 register const char *s = start; /* current position in buffer */
02aa26ce
NT
11813 register char *d; /* destination in temp buffer */
11814 register char *e; /* end of temp buffer */
86554af2 11815 NV nv; /* number read, as a double */
a0714e2c 11816 SV *sv = NULL; /* place to put the converted number */
a86a20aa 11817 bool floatit; /* boolean: int or float? */
cbbf8932 11818 const char *lastub = NULL; /* position of last underbar */
bfed75c6 11819 static char const number_too_long[] = "Number too long";
378cc40b 11820
02aa26ce
NT
11821 /* We use the first character to decide what type of number this is */
11822
378cc40b 11823 switch (*s) {
79072805 11824 default:
cea2e8a9 11825 Perl_croak(aTHX_ "panic: scan_num");
4e553d73 11826
02aa26ce 11827 /* if it starts with a 0, it could be an octal number, a decimal in
a7cb1f99 11828 0.13 disguise, or a hexadecimal number, or a binary number. */
378cc40b
LW
11829 case '0':
11830 {
02aa26ce
NT
11831 /* variables:
11832 u holds the "number so far"
4f19785b
WSI
11833 shift the power of 2 of the base
11834 (hex == 4, octal == 3, binary == 1)
02aa26ce
NT
11835 overflowed was the number more than we can hold?
11836
11837 Shift is used when we add a digit. It also serves as an "are
4f19785b
WSI
11838 we in octal/hex/binary?" indicator to disallow hex characters
11839 when in octal mode.
02aa26ce 11840 */
9e24b6e2
JH
11841 NV n = 0.0;
11842 UV u = 0;
79072805 11843 I32 shift;
9e24b6e2 11844 bool overflowed = FALSE;
61f33854 11845 bool just_zero = TRUE; /* just plain 0 or binary number? */
27da23d5
JH
11846 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11847 static const char* const bases[5] =
11848 { "", "binary", "", "octal", "hexadecimal" };
11849 static const char* const Bases[5] =
11850 { "", "Binary", "", "Octal", "Hexadecimal" };
11851 static const char* const maxima[5] =
11852 { "",
11853 "0b11111111111111111111111111111111",
11854 "",
11855 "037777777777",
11856 "0xffffffff" };
bfed75c6 11857 const char *base, *Base, *max;
378cc40b 11858
02aa26ce 11859 /* check for hex */
378cc40b
LW
11860 if (s[1] == 'x') {
11861 shift = 4;
11862 s += 2;
61f33854 11863 just_zero = FALSE;
4f19785b
WSI
11864 } else if (s[1] == 'b') {
11865 shift = 1;
11866 s += 2;
61f33854 11867 just_zero = FALSE;
378cc40b 11868 }
02aa26ce 11869 /* check for a decimal in disguise */
b78218b7 11870 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
378cc40b 11871 goto decimal;
02aa26ce 11872 /* so it must be octal */
928753ea 11873 else {
378cc40b 11874 shift = 3;
928753ea
JH
11875 s++;
11876 }
11877
11878 if (*s == '_') {
11879 if (ckWARN(WARN_SYNTAX))
9014280d 11880 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
928753ea
JH
11881 "Misplaced _ in number");
11882 lastub = s++;
11883 }
9e24b6e2
JH
11884
11885 base = bases[shift];
11886 Base = Bases[shift];
11887 max = maxima[shift];
02aa26ce 11888
4f19785b 11889 /* read the rest of the number */
378cc40b 11890 for (;;) {
9e24b6e2 11891 /* x is used in the overflow test,
893fe2c2 11892 b is the digit we're adding on. */
9e24b6e2 11893 UV x, b;
55497cff 11894
378cc40b 11895 switch (*s) {
02aa26ce
NT
11896
11897 /* if we don't mention it, we're done */
378cc40b
LW
11898 default:
11899 goto out;
02aa26ce 11900
928753ea 11901 /* _ are ignored -- but warned about if consecutive */
de3bb511 11902 case '_':
041457d9 11903 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
9014280d 11904 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
928753ea
JH
11905 "Misplaced _ in number");
11906 lastub = s++;
de3bb511 11907 break;
02aa26ce
NT
11908
11909 /* 8 and 9 are not octal */
378cc40b 11910 case '8': case '9':
4f19785b 11911 if (shift == 3)
cea2e8a9 11912 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
378cc40b 11913 /* FALL THROUGH */
02aa26ce
NT
11914
11915 /* octal digits */
4f19785b 11916 case '2': case '3': case '4':
378cc40b 11917 case '5': case '6': case '7':
4f19785b 11918 if (shift == 1)
cea2e8a9 11919 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
4f19785b
WSI
11920 /* FALL THROUGH */
11921
11922 case '0': case '1':
02aa26ce 11923 b = *s++ & 15; /* ASCII digit -> value of digit */
55497cff 11924 goto digit;
02aa26ce
NT
11925
11926 /* hex digits */
378cc40b
LW
11927 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
11928 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
02aa26ce 11929 /* make sure they said 0x */
378cc40b
LW
11930 if (shift != 4)
11931 goto out;
55497cff 11932 b = (*s++ & 7) + 9;
02aa26ce
NT
11933
11934 /* Prepare to put the digit we have onto the end
11935 of the number so far. We check for overflows.
11936 */
11937
55497cff 11938 digit:
61f33854 11939 just_zero = FALSE;
9e24b6e2
JH
11940 if (!overflowed) {
11941 x = u << shift; /* make room for the digit */
11942
11943 if ((x >> shift) != u
11944 && !(PL_hints & HINT_NEW_BINARY)) {
9e24b6e2
JH
11945 overflowed = TRUE;
11946 n = (NV) u;
767a6a26 11947 if (ckWARN_d(WARN_OVERFLOW))
9014280d 11948 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
9e24b6e2
JH
11949 "Integer overflow in %s number",
11950 base);
11951 } else
11952 u = x | b; /* add the digit to the end */
11953 }
11954 if (overflowed) {
11955 n *= nvshift[shift];
11956 /* If an NV has not enough bits in its
11957 * mantissa to represent an UV this summing of
11958 * small low-order numbers is a waste of time
11959 * (because the NV cannot preserve the
11960 * low-order bits anyway): we could just
11961 * remember when did we overflow and in the
11962 * end just multiply n by the right
11963 * amount. */
11964 n += (NV) b;
55497cff 11965 }
378cc40b
LW
11966 break;
11967 }
11968 }
02aa26ce
NT
11969
11970 /* if we get here, we had success: make a scalar value from
11971 the number.
11972 */
378cc40b 11973 out:
928753ea
JH
11974
11975 /* final misplaced underbar check */
11976 if (s[-1] == '_') {
11977 if (ckWARN(WARN_SYNTAX))
9014280d 11978 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
928753ea
JH
11979 }
11980
561b68a9 11981 sv = newSV(0);
9e24b6e2 11982 if (overflowed) {
041457d9 11983 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
9014280d 11984 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
9e24b6e2
JH
11985 "%s number > %s non-portable",
11986 Base, max);
11987 sv_setnv(sv, n);
11988 }
11989 else {
15041a67 11990#if UVSIZE > 4
041457d9 11991 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
9014280d 11992 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
9e24b6e2
JH
11993 "%s number > %s non-portable",
11994 Base, max);
2cc4c2dc 11995#endif
9e24b6e2
JH
11996 sv_setuv(sv, u);
11997 }
61f33854 11998 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
bfed75c6 11999 sv = new_constant(start, s - start, "integer",
a0714e2c 12000 sv, NULL, NULL);
61f33854 12001 else if (PL_hints & HINT_NEW_BINARY)
a0714e2c 12002 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
378cc40b
LW
12003 }
12004 break;
02aa26ce
NT
12005
12006 /*
12007 handle decimal numbers.
12008 we're also sent here when we read a 0 as the first digit
12009 */
378cc40b
LW
12010 case '1': case '2': case '3': case '4': case '5':
12011 case '6': case '7': case '8': case '9': case '.':
12012 decimal:
3280af22
NIS
12013 d = PL_tokenbuf;
12014 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
79072805 12015 floatit = FALSE;
02aa26ce
NT
12016
12017 /* read next group of digits and _ and copy into d */
de3bb511 12018 while (isDIGIT(*s) || *s == '_') {
4e553d73 12019 /* skip underscores, checking for misplaced ones
02aa26ce
NT
12020 if -w is on
12021 */
93a17b20 12022 if (*s == '_') {
041457d9 12023 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
9014280d 12024 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
928753ea
JH
12025 "Misplaced _ in number");
12026 lastub = s++;
93a17b20 12027 }
fc36a67e 12028 else {
02aa26ce 12029 /* check for end of fixed-length buffer */
fc36a67e 12030 if (d >= e)
cea2e8a9 12031 Perl_croak(aTHX_ number_too_long);
02aa26ce 12032 /* if we're ok, copy the character */
378cc40b 12033 *d++ = *s++;
fc36a67e 12034 }
378cc40b 12035 }
02aa26ce
NT
12036
12037 /* final misplaced underbar check */
928753ea 12038 if (lastub && s == lastub + 1) {
d008e5eb 12039 if (ckWARN(WARN_SYNTAX))
9014280d 12040 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
d008e5eb 12041 }
02aa26ce
NT
12042
12043 /* read a decimal portion if there is one. avoid
12044 3..5 being interpreted as the number 3. followed
12045 by .5
12046 */
2f3197b3 12047 if (*s == '.' && s[1] != '.') {
79072805 12048 floatit = TRUE;
378cc40b 12049 *d++ = *s++;
02aa26ce 12050
928753ea
JH
12051 if (*s == '_') {
12052 if (ckWARN(WARN_SYNTAX))
9014280d 12053 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
928753ea
JH
12054 "Misplaced _ in number");
12055 lastub = s;
12056 }
12057
12058 /* copy, ignoring underbars, until we run out of digits.
02aa26ce 12059 */
fc36a67e 12060 for (; isDIGIT(*s) || *s == '_'; s++) {
02aa26ce 12061 /* fixed length buffer check */
fc36a67e 12062 if (d >= e)
cea2e8a9 12063 Perl_croak(aTHX_ number_too_long);
928753ea 12064 if (*s == '_') {
041457d9 12065 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
9014280d 12066 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
928753ea
JH
12067 "Misplaced _ in number");
12068 lastub = s;
12069 }
12070 else
fc36a67e 12071 *d++ = *s;
378cc40b 12072 }
928753ea
JH
12073 /* fractional part ending in underbar? */
12074 if (s[-1] == '_') {
12075 if (ckWARN(WARN_SYNTAX))
9014280d 12076 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
928753ea
JH
12077 "Misplaced _ in number");
12078 }
dd629d5b
GS
12079 if (*s == '.' && isDIGIT(s[1])) {
12080 /* oops, it's really a v-string, but without the "v" */
f4758303 12081 s = start;
dd629d5b
GS
12082 goto vstring;
12083 }
378cc40b 12084 }
02aa26ce
NT
12085
12086 /* read exponent part, if present */
3792a11b 12087 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
79072805
LW
12088 floatit = TRUE;
12089 s++;
02aa26ce
NT
12090
12091 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
79072805 12092 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
02aa26ce 12093
7fd134d9
JH
12094 /* stray preinitial _ */
12095 if (*s == '_') {
12096 if (ckWARN(WARN_SYNTAX))
9014280d 12097 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
7fd134d9
JH
12098 "Misplaced _ in number");
12099 lastub = s++;
12100 }
12101
02aa26ce 12102 /* allow positive or negative exponent */
378cc40b
LW
12103 if (*s == '+' || *s == '-')
12104 *d++ = *s++;
02aa26ce 12105
7fd134d9
JH
12106 /* stray initial _ */
12107 if (*s == '_') {
12108 if (ckWARN(WARN_SYNTAX))
9014280d 12109 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
7fd134d9
JH
12110 "Misplaced _ in number");
12111 lastub = s++;
12112 }
12113
7fd134d9
JH
12114 /* read digits of exponent */
12115 while (isDIGIT(*s) || *s == '_') {
12116 if (isDIGIT(*s)) {
12117 if (d >= e)
12118 Perl_croak(aTHX_ number_too_long);
b3b48e3e 12119 *d++ = *s++;
7fd134d9
JH
12120 }
12121 else {
041457d9
DM
12122 if (((lastub && s == lastub + 1) ||
12123 (!isDIGIT(s[1]) && s[1] != '_'))
12124 && ckWARN(WARN_SYNTAX))
9014280d 12125 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
7fd134d9 12126 "Misplaced _ in number");
b3b48e3e 12127 lastub = s++;
7fd134d9 12128 }
7fd134d9 12129 }
378cc40b 12130 }
02aa26ce 12131
02aa26ce
NT
12132
12133 /* make an sv from the string */
561b68a9 12134 sv = newSV(0);
097ee67d 12135
0b7fceb9 12136 /*
58bb9ec3
NC
12137 We try to do an integer conversion first if no characters
12138 indicating "float" have been found.
0b7fceb9
MU
12139 */
12140
12141 if (!floatit) {
58bb9ec3 12142 UV uv;
6136c704 12143 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
58bb9ec3
NC
12144
12145 if (flags == IS_NUMBER_IN_UV) {
12146 if (uv <= IV_MAX)
86554af2 12147 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
58bb9ec3 12148 else
c239479b 12149 sv_setuv(sv, uv);
58bb9ec3
NC
12150 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
12151 if (uv <= (UV) IV_MIN)
12152 sv_setiv(sv, -(IV)uv);
12153 else
12154 floatit = TRUE;
12155 } else
12156 floatit = TRUE;
12157 }
0b7fceb9 12158 if (floatit) {
58bb9ec3
NC
12159 /* terminate the string */
12160 *d = '\0';
86554af2
JH
12161 nv = Atof(PL_tokenbuf);
12162 sv_setnv(sv, nv);
12163 }
86554af2 12164
b8403495
JH
12165 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
12166 (PL_hints & HINT_NEW_INTEGER) )
10edeb5d
JH
12167 sv = new_constant(PL_tokenbuf,
12168 d - PL_tokenbuf,
12169 (const char *)
b8403495 12170 (floatit ? "float" : "integer"),
a0714e2c 12171 sv, NULL, NULL);
378cc40b 12172 break;
0b7fceb9 12173
e312add1 12174 /* if it starts with a v, it could be a v-string */
a7cb1f99 12175 case 'v':
dd629d5b 12176vstring:
561b68a9 12177 sv = newSV(5); /* preallocate storage space */
b0f01acb 12178 s = scan_vstring(s,sv);
a7cb1f99 12179 break;
79072805 12180 }
a687059c 12181
02aa26ce
NT
12182 /* make the op for the constant and return */
12183
a86a20aa 12184 if (sv)
b73d6f50 12185 lvalp->opval = newSVOP(OP_CONST, 0, sv);
a7cb1f99 12186 else
5f66b61c 12187 lvalp->opval = NULL;
a687059c 12188
73d840c0 12189 return (char *)s;
378cc40b
LW
12190}
12191
76e3520e 12192STATIC char *
cea2e8a9 12193S_scan_formline(pTHX_ register char *s)
378cc40b 12194{
97aff369 12195 dVAR;
79072805 12196 register char *eol;
378cc40b 12197 register char *t;
6136c704 12198 SV * const stuff = newSVpvs("");
79072805 12199 bool needargs = FALSE;
c5ee2135 12200 bool eofmt = FALSE;
5db06880
NC
12201#ifdef PERL_MAD
12202 char *tokenstart = s;
12203 SV* savewhite;
12204
12205 if (PL_madskills) {
cd81e915
NC
12206 savewhite = PL_thiswhite;
12207 PL_thiswhite = 0;
5db06880
NC
12208 }
12209#endif
378cc40b 12210
79072805 12211 while (!needargs) {
a1b95068 12212 if (*s == '.') {
c35e046a 12213 t = s+1;
51882d45 12214#ifdef PERL_STRICT_CR
c35e046a
AL
12215 while (SPACE_OR_TAB(*t))
12216 t++;
51882d45 12217#else
c35e046a
AL
12218 while (SPACE_OR_TAB(*t) || *t == '\r')
12219 t++;
51882d45 12220#endif
c5ee2135
WL
12221 if (*t == '\n' || t == PL_bufend) {
12222 eofmt = TRUE;
79072805 12223 break;
c5ee2135 12224 }
79072805 12225 }
3280af22 12226 if (PL_in_eval && !PL_rsfp) {
07409e01 12227 eol = (char *) memchr(s,'\n',PL_bufend-s);
0f85fab0 12228 if (!eol++)
3280af22 12229 eol = PL_bufend;
0f85fab0
LW
12230 }
12231 else
3280af22 12232 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
79072805 12233 if (*s != '#') {
a0d0e21e
LW
12234 for (t = s; t < eol; t++) {
12235 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12236 needargs = FALSE;
12237 goto enough; /* ~~ must be first line in formline */
378cc40b 12238 }
a0d0e21e
LW
12239 if (*t == '@' || *t == '^')
12240 needargs = TRUE;
378cc40b 12241 }
7121b347
MG
12242 if (eol > s) {
12243 sv_catpvn(stuff, s, eol-s);
2dc4c65b 12244#ifndef PERL_STRICT_CR
7121b347
MG
12245 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12246 char *end = SvPVX(stuff) + SvCUR(stuff);
12247 end[-2] = '\n';
12248 end[-1] = '\0';
b162af07 12249 SvCUR_set(stuff, SvCUR(stuff) - 1);
7121b347 12250 }
2dc4c65b 12251#endif
7121b347
MG
12252 }
12253 else
12254 break;
79072805 12255 }
95a20fc0 12256 s = (char*)eol;
3280af22 12257 if (PL_rsfp) {
5db06880
NC
12258#ifdef PERL_MAD
12259 if (PL_madskills) {
cd81e915
NC
12260 if (PL_thistoken)
12261 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
5db06880 12262 else
cd81e915 12263 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
5db06880
NC
12264 }
12265#endif
3280af22 12266 s = filter_gets(PL_linestr, PL_rsfp, 0);
5db06880
NC
12267#ifdef PERL_MAD
12268 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12269#else
3280af22 12270 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
5db06880 12271#endif
3280af22 12272 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
bd61b366 12273 PL_last_lop = PL_last_uni = NULL;
79072805 12274 if (!s) {
3280af22 12275 s = PL_bufptr;
378cc40b
LW
12276 break;
12277 }
378cc40b 12278 }
463ee0b2 12279 incline(s);
79072805 12280 }
a0d0e21e
LW
12281 enough:
12282 if (SvCUR(stuff)) {
3280af22 12283 PL_expect = XTERM;
79072805 12284 if (needargs) {
3280af22 12285 PL_lex_state = LEX_NORMAL;
cd81e915 12286 start_force(PL_curforce);
9ded7720 12287 NEXTVAL_NEXTTOKE.ival = 0;
79072805
LW
12288 force_next(',');
12289 }
a0d0e21e 12290 else
3280af22 12291 PL_lex_state = LEX_FORMLINE;
1bd51a4c 12292 if (!IN_BYTES) {
95a20fc0 12293 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
1bd51a4c
IH
12294 SvUTF8_on(stuff);
12295 else if (PL_encoding)
12296 sv_recode_to_utf8(stuff, PL_encoding);
12297 }
cd81e915 12298 start_force(PL_curforce);
9ded7720 12299 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
79072805 12300 force_next(THING);
cd81e915 12301 start_force(PL_curforce);
9ded7720 12302 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
79072805 12303 force_next(LSTOP);
378cc40b 12304 }
79072805 12305 else {
8990e307 12306 SvREFCNT_dec(stuff);
c5ee2135
WL
12307 if (eofmt)
12308 PL_lex_formbrack = 0;
3280af22 12309 PL_bufptr = s;
79072805 12310 }
5db06880
NC
12311#ifdef PERL_MAD
12312 if (PL_madskills) {
cd81e915
NC
12313 if (PL_thistoken)
12314 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
5db06880 12315 else
cd81e915
NC
12316 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12317 PL_thiswhite = savewhite;
5db06880
NC
12318 }
12319#endif
79072805 12320 return s;
378cc40b 12321}
a687059c 12322
76e3520e 12323STATIC void
cea2e8a9 12324S_set_csh(pTHX)
a687059c 12325{
ae986130 12326#ifdef CSH
97aff369 12327 dVAR;
3280af22
NIS
12328 if (!PL_cshlen)
12329 PL_cshlen = strlen(PL_cshname);
5f66b61c 12330#else
b2675967 12331#if defined(USE_ITHREADS)
96a5add6 12332 PERL_UNUSED_CONTEXT;
ae986130 12333#endif
b2675967 12334#endif
a687059c 12335}
463ee0b2 12336
ba6d6ac9 12337I32
864dbfa3 12338Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
8990e307 12339{
97aff369 12340 dVAR;
a3b680e6 12341 const I32 oldsavestack_ix = PL_savestack_ix;
6136c704 12342 CV* const outsidecv = PL_compcv;
8990e307 12343
3280af22
NIS
12344 if (PL_compcv) {
12345 assert(SvTYPE(PL_compcv) == SVt_PVCV);
e9a444f0 12346 }
7766f137 12347 SAVEI32(PL_subline);
3280af22 12348 save_item(PL_subname);
3280af22 12349 SAVESPTR(PL_compcv);
3280af22 12350
561b68a9 12351 PL_compcv = (CV*)newSV(0);
3280af22
NIS
12352 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
12353 CvFLAGS(PL_compcv) |= flags;
12354
57843af0 12355 PL_subline = CopLINE(PL_curcop);
dd2155a4 12356 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
b37c2d43 12357 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
a3985cdc 12358 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
748a9306 12359
8990e307
LW
12360 return oldsavestack_ix;
12361}
12362
084592ab
CN
12363#ifdef __SC__
12364#pragma segment Perl_yylex
12365#endif
8990e307 12366int
bfed75c6 12367Perl_yywarn(pTHX_ const char *s)
8990e307 12368{
97aff369 12369 dVAR;
faef0170 12370 PL_in_eval |= EVAL_WARNONLY;
748a9306 12371 yyerror(s);
faef0170 12372 PL_in_eval &= ~EVAL_WARNONLY;
748a9306 12373 return 0;
8990e307
LW
12374}
12375
12376int
bfed75c6 12377Perl_yyerror(pTHX_ const char *s)
463ee0b2 12378{
97aff369 12379 dVAR;
bfed75c6
AL
12380 const char *where = NULL;
12381 const char *context = NULL;
68dc0745 12382 int contlen = -1;
46fc3d4c 12383 SV *msg;
463ee0b2 12384
3280af22 12385 if (!yychar || (yychar == ';' && !PL_rsfp))
54310121 12386 where = "at EOF";
8bcfe651
TM
12387 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12388 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12389 PL_oldbufptr != PL_bufptr) {
f355267c
JH
12390 /*
12391 Only for NetWare:
12392 The code below is removed for NetWare because it abends/crashes on NetWare
12393 when the script has error such as not having the closing quotes like:
12394 if ($var eq "value)
12395 Checking of white spaces is anyway done in NetWare code.
12396 */
12397#ifndef NETWARE
3280af22
NIS
12398 while (isSPACE(*PL_oldoldbufptr))
12399 PL_oldoldbufptr++;
f355267c 12400#endif
3280af22
NIS
12401 context = PL_oldoldbufptr;
12402 contlen = PL_bufptr - PL_oldoldbufptr;
463ee0b2 12403 }
8bcfe651
TM
12404 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12405 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
f355267c
JH
12406 /*
12407 Only for NetWare:
12408 The code below is removed for NetWare because it abends/crashes on NetWare
12409 when the script has error such as not having the closing quotes like:
12410 if ($var eq "value)
12411 Checking of white spaces is anyway done in NetWare code.
12412 */
12413#ifndef NETWARE
3280af22
NIS
12414 while (isSPACE(*PL_oldbufptr))
12415 PL_oldbufptr++;
f355267c 12416#endif
3280af22
NIS
12417 context = PL_oldbufptr;
12418 contlen = PL_bufptr - PL_oldbufptr;
463ee0b2
LW
12419 }
12420 else if (yychar > 255)
68dc0745 12421 where = "next token ???";
12fbd33b 12422 else if (yychar == -2) { /* YYEMPTY */
3280af22
NIS
12423 if (PL_lex_state == LEX_NORMAL ||
12424 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
68dc0745 12425 where = "at end of line";
3280af22 12426 else if (PL_lex_inpat)
68dc0745 12427 where = "within pattern";
463ee0b2 12428 else
68dc0745 12429 where = "within string";
463ee0b2 12430 }
46fc3d4c 12431 else {
6136c704 12432 SV * const where_sv = sv_2mortal(newSVpvs("next char "));
46fc3d4c 12433 if (yychar < 32)
cea2e8a9 12434 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
46fc3d4c 12435 else if (isPRINT_LC(yychar))
cea2e8a9 12436 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
463ee0b2 12437 else
cea2e8a9 12438 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
95a20fc0 12439 where = SvPVX_const(where_sv);
463ee0b2 12440 }
46fc3d4c 12441 msg = sv_2mortal(newSVpv(s, 0));
ed094faf 12442 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
248c2a4d 12443 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
68dc0745 12444 if (context)
cea2e8a9 12445 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
463ee0b2 12446 else
cea2e8a9 12447 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
57843af0 12448 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
cf2093f6 12449 Perl_sv_catpvf(aTHX_ msg,
57def98f 12450 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
cf2093f6 12451 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
3280af22 12452 PL_multi_end = 0;
a0d0e21e 12453 }
56da5a46 12454 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
95b63a38 12455 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, (void*)msg);
463ee0b2 12456 else
5a844595 12457 qerror(msg);
c7d6bfb2
GS
12458 if (PL_error_count >= 10) {
12459 if (PL_in_eval && SvCUR(ERRSV))
d2560b70 12460 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
95b63a38 12461 (void*)ERRSV, OutCopFILE(PL_curcop));
c7d6bfb2
GS
12462 else
12463 Perl_croak(aTHX_ "%s has too many errors.\n",
248c2a4d 12464 OutCopFILE(PL_curcop));
c7d6bfb2 12465 }
3280af22 12466 PL_in_my = 0;
5c284bb0 12467 PL_in_my_stash = NULL;
463ee0b2
LW
12468 return 0;
12469}
084592ab
CN
12470#ifdef __SC__
12471#pragma segment Main
12472#endif
4e35701f 12473
b250498f 12474STATIC char*
3ae08724 12475S_swallow_bom(pTHX_ U8 *s)
01ec43d0 12476{
97aff369 12477 dVAR;
f54cb97a 12478 const STRLEN slen = SvCUR(PL_linestr);
7aa207d6 12479 switch (s[0]) {
4e553d73
NIS
12480 case 0xFF:
12481 if (s[1] == 0xFE) {
7aa207d6 12482 /* UTF-16 little-endian? (or UTF32-LE?) */
3ae08724 12483 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
7aa207d6 12484 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
01ec43d0 12485#ifndef PERL_NO_UTF16_FILTER
7aa207d6 12486 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
3ae08724 12487 s += 2;
7aa207d6 12488 utf16le:
dea0fc0b
JH
12489 if (PL_bufend > (char*)s) {
12490 U8 *news;
12491 I32 newlen;
12492
12493 filter_add(utf16rev_textfilter, NULL);
a02a5408 12494 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
1de9afcd 12495 utf16_to_utf8_reversed(s, news,
aed58286 12496 PL_bufend - (char*)s - 1,
1de9afcd 12497 &newlen);
7aa207d6 12498 sv_setpvn(PL_linestr, (const char*)news, newlen);
5db06880
NC
12499#ifdef PERL_MAD
12500 s = (U8*)SvPVX(PL_linestr);
12501 Copy(news, s, newlen, U8);
12502 s[newlen] = '\0';
12503#endif
dea0fc0b 12504 Safefree(news);
7aa207d6
JH
12505 SvUTF8_on(PL_linestr);
12506 s = (U8*)SvPVX(PL_linestr);
5db06880
NC
12507#ifdef PERL_MAD
12508 /* FIXME - is this a general bug fix? */
12509 s[newlen] = '\0';
12510#endif
7aa207d6 12511 PL_bufend = SvPVX(PL_linestr) + newlen;
dea0fc0b 12512 }
b250498f 12513#else
7aa207d6 12514 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
b250498f 12515#endif
01ec43d0
GS
12516 }
12517 break;
78ae23f5 12518 case 0xFE:
7aa207d6 12519 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
01ec43d0 12520#ifndef PERL_NO_UTF16_FILTER
7aa207d6 12521 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
dea0fc0b 12522 s += 2;
7aa207d6 12523 utf16be:
dea0fc0b
JH
12524 if (PL_bufend > (char *)s) {
12525 U8 *news;
12526 I32 newlen;
12527
12528 filter_add(utf16_textfilter, NULL);
a02a5408 12529 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
1de9afcd
RGS
12530 utf16_to_utf8(s, news,
12531 PL_bufend - (char*)s,
12532 &newlen);
7aa207d6 12533 sv_setpvn(PL_linestr, (const char*)news, newlen);
dea0fc0b 12534 Safefree(news);
7aa207d6
JH
12535 SvUTF8_on(PL_linestr);
12536 s = (U8*)SvPVX(PL_linestr);
12537 PL_bufend = SvPVX(PL_linestr) + newlen;
dea0fc0b 12538 }
b250498f 12539#else
7aa207d6 12540 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
b250498f 12541#endif
01ec43d0
GS
12542 }
12543 break;
3ae08724
GS
12544 case 0xEF:
12545 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
7aa207d6 12546 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
01ec43d0
GS
12547 s += 3; /* UTF-8 */
12548 }
12549 break;
12550 case 0:
7aa207d6
JH
12551 if (slen > 3) {
12552 if (s[1] == 0) {
12553 if (s[2] == 0xFE && s[3] == 0xFF) {
12554 /* UTF-32 big-endian */
12555 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12556 }
12557 }
12558 else if (s[2] == 0 && s[3] != 0) {
12559 /* Leading bytes
12560 * 00 xx 00 xx
12561 * are a good indicator of UTF-16BE. */
12562 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12563 goto utf16be;
12564 }
01ec43d0 12565 }
e294cc5d
JH
12566#ifdef EBCDIC
12567 case 0xDD:
12568 if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
12569 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12570 s += 4; /* UTF-8 */
12571 }
12572 break;
12573#endif
12574
7aa207d6
JH
12575 default:
12576 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12577 /* Leading bytes
12578 * xx 00 xx 00
12579 * are a good indicator of UTF-16LE. */
12580 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12581 goto utf16le;
12582 }
01ec43d0 12583 }
b8f84bb2 12584 return (char*)s;
b250498f 12585}
4755096e 12586
4755096e
GS
12587/*
12588 * restore_rsfp
12589 * Restore a source filter.
12590 */
12591
12592static void
acfe0abc 12593restore_rsfp(pTHX_ void *f)
4755096e 12594{
97aff369 12595 dVAR;
0bd48802 12596 PerlIO * const fp = (PerlIO*)f;
4755096e
GS
12597
12598 if (PL_rsfp == PerlIO_stdin())
12599 PerlIO_clearerr(PL_rsfp);
12600 else if (PL_rsfp && (PL_rsfp != fp))
12601 PerlIO_close(PL_rsfp);
12602 PL_rsfp = fp;
12603}
6e3aabd6
GS
12604
12605#ifndef PERL_NO_UTF16_FILTER
12606static I32
acfe0abc 12607utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
6e3aabd6 12608{
97aff369 12609 dVAR;
f54cb97a
AL
12610 const STRLEN old = SvCUR(sv);
12611 const I32 count = FILTER_READ(idx+1, sv, maxlen);
1de9afcd
RGS
12612 DEBUG_P(PerlIO_printf(Perl_debug_log,
12613 "utf16_textfilter(%p): %d %d (%d)\n",
55662e27
JH
12614 FPTR2DPTR(void *, utf16_textfilter),
12615 idx, maxlen, (int) count));
6e3aabd6
GS
12616 if (count) {
12617 U8* tmps;
dea0fc0b 12618 I32 newlen;
a02a5408 12619 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
95a20fc0
SP
12620 Copy(SvPVX_const(sv), tmps, old, char);
12621 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
1de9afcd
RGS
12622 SvCUR(sv) - old, &newlen);
12623 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
6e3aabd6 12624 }
1de9afcd
RGS
12625 DEBUG_P({sv_dump(sv);});
12626 return SvCUR(sv);
6e3aabd6
GS
12627}
12628
12629static I32
acfe0abc 12630utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
6e3aabd6 12631{
97aff369 12632 dVAR;
f54cb97a
AL
12633 const STRLEN old = SvCUR(sv);
12634 const I32 count = FILTER_READ(idx+1, sv, maxlen);
1de9afcd
RGS
12635 DEBUG_P(PerlIO_printf(Perl_debug_log,
12636 "utf16rev_textfilter(%p): %d %d (%d)\n",
55662e27
JH
12637 FPTR2DPTR(void *, utf16rev_textfilter),
12638 idx, maxlen, (int) count));
6e3aabd6
GS
12639 if (count) {
12640 U8* tmps;
dea0fc0b 12641 I32 newlen;
a02a5408 12642 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
95a20fc0
SP
12643 Copy(SvPVX_const(sv), tmps, old, char);
12644 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
1de9afcd
RGS
12645 SvCUR(sv) - old, &newlen);
12646 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
6e3aabd6 12647 }
1de9afcd 12648 DEBUG_P({ sv_dump(sv); });
6e3aabd6
GS
12649 return count;
12650}
12651#endif
9f4817db 12652
f333445c
JP
12653/*
12654Returns a pointer to the next character after the parsed
12655vstring, as well as updating the passed in sv.
12656
12657Function must be called like
12658
561b68a9 12659 sv = newSV(5);
f333445c
JP
12660 s = scan_vstring(s,sv);
12661
12662The sv should already be large enough to store the vstring
12663passed in, for performance reasons.
12664
12665*/
12666
12667char *
bfed75c6 12668Perl_scan_vstring(pTHX_ const char *s, SV *sv)
f333445c 12669{
97aff369 12670 dVAR;
bfed75c6
AL
12671 const char *pos = s;
12672 const char *start = s;
f333445c 12673 if (*pos == 'v') pos++; /* get past 'v' */
3e884cbf
JH
12674 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12675 pos++;
f333445c
JP
12676 if ( *pos != '.') {
12677 /* this may not be a v-string if followed by => */
bfed75c6 12678 const char *next = pos;
8fc7bb1c
SM
12679 while (next < PL_bufend && isSPACE(*next))
12680 ++next;
12681 if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
f333445c
JP
12682 /* return string not v-string */
12683 sv_setpvn(sv,(char *)s,pos-s);
73d840c0 12684 return (char *)pos;
f333445c
JP
12685 }
12686 }
12687
12688 if (!isALPHA(*pos)) {
89ebb4a3 12689 U8 tmpbuf[UTF8_MAXBYTES+1];
f333445c 12690
d4c19fe8
AL
12691 if (*s == 'v')
12692 s++; /* get past 'v' */
f333445c
JP
12693
12694 sv_setpvn(sv, "", 0);
12695
12696 for (;;) {
d4c19fe8 12697 /* this is atoi() that tolerates underscores */
0bd48802
AL
12698 U8 *tmpend;
12699 UV rev = 0;
d4c19fe8
AL
12700 const char *end = pos;
12701 UV mult = 1;
12702 while (--end >= s) {
12703 if (*end != '_') {
12704 const UV orev = rev;
f333445c
JP
12705 rev += (*end - '0') * mult;
12706 mult *= 10;
12707 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12708 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12709 "Integer overflow in decimal number");
12710 }
12711 }
12712#ifdef EBCDIC
12713 if (rev > 0x7FFFFFFF)
12714 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12715#endif
12716 /* Append native character for the rev point */
12717 tmpend = uvchr_to_utf8(tmpbuf, rev);
12718 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12719 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12720 SvUTF8_on(sv);
3e884cbf 12721 if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
f333445c
JP
12722 s = ++pos;
12723 else {
12724 s = pos;
12725 break;
12726 }
3e884cbf 12727 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
f333445c
JP
12728 pos++;
12729 }
12730 SvPOK_on(sv);
12731 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12732 SvRMAGICAL_on(sv);
12733 }
73d840c0 12734 return (char *)s;
f333445c
JP
12735}
12736
1da4ca5f
NC
12737/*
12738 * Local variables:
12739 * c-indentation-style: bsd
12740 * c-basic-offset: 4
12741 * indent-tabs-mode: t
12742 * End:
12743 *
37442d52
RGS
12744 * ex: set ts=8 sts=4 sw=4 noet:
12745 */