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