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