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