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