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