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