This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
S_op_destroy() was not static. Also tidy all other STATIC/static
[perl5.git] / toke.c
CommitLineData
a0d0e21e 1/* toke.c
a687059c 2 *
4bb101f2 3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
6ef55633 4 * 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 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
5912531f 26#define yylval (PL_parser->yylval)
d3b6f988 27
acdf0a21
DM
28/* YYINITDEPTH -- initial size of the parser's stacks. */
29#define YYINITDEPTH 200
30
199e78b7
DM
31/* XXX temporary backwards compatibility */
32#define PL_lex_brackets (PL_parser->lex_brackets)
33#define PL_lex_brackstack (PL_parser->lex_brackstack)
34#define PL_lex_casemods (PL_parser->lex_casemods)
35#define PL_lex_casestack (PL_parser->lex_casestack)
36#define PL_lex_defer (PL_parser->lex_defer)
37#define PL_lex_dojoin (PL_parser->lex_dojoin)
38#define PL_lex_expect (PL_parser->lex_expect)
39#define PL_lex_formbrack (PL_parser->lex_formbrack)
40#define PL_lex_inpat (PL_parser->lex_inpat)
41#define PL_lex_inwhat (PL_parser->lex_inwhat)
42#define PL_lex_op (PL_parser->lex_op)
43#define PL_lex_repl (PL_parser->lex_repl)
44#define PL_lex_starts (PL_parser->lex_starts)
45#define PL_lex_stuff (PL_parser->lex_stuff)
46#define PL_multi_start (PL_parser->multi_start)
47#define PL_multi_open (PL_parser->multi_open)
48#define PL_multi_close (PL_parser->multi_close)
49#define PL_pending_ident (PL_parser->pending_ident)
50#define PL_preambled (PL_parser->preambled)
51#define PL_sublex_info (PL_parser->sublex_info)
52
53#ifdef PERL_MAD
54# define PL_endwhite (PL_parser->endwhite)
55# define PL_faketokens (PL_parser->faketokens)
56# define PL_lasttoke (PL_parser->lasttoke)
57# define PL_nextwhite (PL_parser->nextwhite)
58# define PL_realtokenstart (PL_parser->realtokenstart)
59# define PL_skipwhite (PL_parser->skipwhite)
60# define PL_thisclose (PL_parser->thisclose)
61# define PL_thismad (PL_parser->thismad)
62# define PL_thisopen (PL_parser->thisopen)
63# define PL_thisstuff (PL_parser->thisstuff)
64# define PL_thistoken (PL_parser->thistoken)
65# define PL_thiswhite (PL_parser->thiswhite)
66#endif
67
3cbf51f5
DM
68static int
69S_pending_ident(pTHX);
199e78b7 70
0bd48802 71static const char ident_too_long[] = "Identifier too long";
c445ea15 72static const char commaless_variable_list[] = "comma-less variable list";
8903cb82 73
acfe0abc 74static void restore_rsfp(pTHX_ void *f);
6e3aabd6 75#ifndef PERL_NO_UTF16_FILTER
acfe0abc
GS
76static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
77static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
6e3aabd6 78#endif
51371543 79
29595ff2 80#ifdef PERL_MAD
29595ff2 81# define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; }
cd81e915 82# define NEXTVAL_NEXTTOKE PL_nexttoke[PL_curforce].next_val
9ded7720 83#else
5db06880 84# define CURMAD(slot,sv)
9ded7720 85# define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
29595ff2
NC
86#endif
87
9059aa12
LW
88#define XFAKEBRACK 128
89#define XENUMMASK 127
90
39e02b42
JH
91#ifdef USE_UTF8_SCRIPTS
92# define UTF (!IN_BYTES)
2b9d42f0 93#else
746b446a 94# define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
2b9d42f0 95#endif
a0ed51b3 96
61f0cdd9 97/* In variables named $^X, these are the legal values for X.
2b92dfce
GS
98 * 1999-02-27 mjd-perl-patch@plover.com */
99#define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
100
bf4acbe4
GS
101/* On MacOS, respect nonbreaking spaces */
102#ifdef MACOS_TRADITIONAL
103#define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
104#else
105#define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
106#endif
107
ffb4593c
NT
108/* LEX_* are values for PL_lex_state, the state of the lexer.
109 * They are arranged oddly so that the guard on the switch statement
79072805
LW
110 * can get by with a single comparison (if the compiler is smart enough).
111 */
112
fb73857a 113/* #define LEX_NOTPARSING 11 is done in perl.h. */
114
b6007c36
DM
115#define LEX_NORMAL 10 /* normal code (ie not within "...") */
116#define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
117#define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
118#define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
119#define LEX_INTERPSTART 6 /* expecting the start of a $var */
120
121 /* at end of code, eg "$x" followed by: */
122#define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
123#define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
124
125#define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
126 string or after \E, $foo, etc */
127#define LEX_INTERPCONST 2 /* NOT USED */
128#define LEX_FORMLINE 1 /* expecting a format line */
129#define LEX_KNOWNEXT 0 /* next token known; just return it */
130
79072805 131
bbf60fe6 132#ifdef DEBUGGING
27da23d5 133static const char* const lex_state_names[] = {
bbf60fe6
DM
134 "KNOWNEXT",
135 "FORMLINE",
136 "INTERPCONST",
137 "INTERPCONCAT",
138 "INTERPENDMAYBE",
139 "INTERPEND",
140 "INTERPSTART",
141 "INTERPPUSH",
142 "INTERPCASEMOD",
143 "INTERPNORMAL",
144 "NORMAL"
145};
146#endif
147
79072805
LW
148#ifdef ff_next
149#undef ff_next
d48672a2
LW
150#endif
151
79072805 152#include "keywords.h"
fe14fcc3 153
ffb4593c
NT
154/* CLINE is a macro that ensures PL_copline has a sane value */
155
ae986130
LW
156#ifdef CLINE
157#undef CLINE
158#endif
57843af0 159#define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
3280af22 160
5db06880 161#ifdef PERL_MAD
29595ff2
NC
162# define SKIPSPACE0(s) skipspace0(s)
163# define SKIPSPACE1(s) skipspace1(s)
164# define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
165# define PEEKSPACE(s) skipspace2(s,0)
166#else
167# define SKIPSPACE0(s) skipspace(s)
168# define SKIPSPACE1(s) skipspace(s)
169# define SKIPSPACE2(s,tsv) skipspace(s)
170# define PEEKSPACE(s) skipspace(s)
171#endif
172
ffb4593c
NT
173/*
174 * Convenience functions to return different tokens and prime the
9cbb5ea2 175 * lexer for the next token. They all take an argument.
ffb4593c
NT
176 *
177 * TOKEN : generic token (used for '(', DOLSHARP, etc)
178 * OPERATOR : generic operator
179 * AOPERATOR : assignment operator
180 * PREBLOCK : beginning the block after an if, while, foreach, ...
181 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
182 * PREREF : *EXPR where EXPR is not a simple identifier
183 * TERM : expression term
184 * LOOPX : loop exiting command (goto, last, dump, etc)
185 * FTST : file test operator
186 * FUN0 : zero-argument function
2d2e263d 187 * FUN1 : not used, except for not, which isn't a UNIOP
ffb4593c
NT
188 * BOop : bitwise or or xor
189 * BAop : bitwise and
190 * SHop : shift operator
191 * PWop : power operator
9cbb5ea2 192 * PMop : pattern-matching operator
ffb4593c
NT
193 * Aop : addition-level operator
194 * Mop : multiplication-level operator
195 * Eop : equality-testing operator
e5edeb50 196 * Rop : relational operator <= != gt
ffb4593c
NT
197 *
198 * Also see LOP and lop() below.
199 */
200
998054bd 201#ifdef DEBUGGING /* Serve -DT. */
f5bd084c 202# define REPORT(retval) tokereport((I32)retval)
998054bd 203#else
bbf60fe6 204# define REPORT(retval) (retval)
998054bd
SC
205#endif
206
bbf60fe6
DM
207#define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
208#define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
209#define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
210#define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
211#define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
212#define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
213#define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
214#define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
215#define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
216#define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
217#define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
218#define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
219#define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
220#define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
221#define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
222#define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
223#define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
224#define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
225#define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
226#define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
2f3197b3 227
a687059c
LW
228/* This bit of chicanery makes a unary function followed by
229 * a parenthesis into a function with one argument, highest precedence.
6f33ba73
RGS
230 * The UNIDOR macro is for unary functions that can be followed by the //
231 * operator (such as C<shift // 0>).
a687059c 232 */
376fcdbf
AL
233#define UNI2(f,x) { \
234 yylval.ival = f; \
235 PL_expect = x; \
236 PL_bufptr = s; \
237 PL_last_uni = PL_oldbufptr; \
238 PL_last_lop_op = f; \
239 if (*s == '(') \
240 return REPORT( (int)FUNC1 ); \
29595ff2 241 s = PEEKSPACE(s); \
376fcdbf
AL
242 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
243 }
6f33ba73
RGS
244#define UNI(f) UNI2(f,XTERM)
245#define UNIDOR(f) UNI2(f,XTERMORDORDOR)
a687059c 246
376fcdbf
AL
247#define UNIBRACK(f) { \
248 yylval.ival = f; \
249 PL_bufptr = s; \
250 PL_last_uni = PL_oldbufptr; \
251 if (*s == '(') \
252 return REPORT( (int)FUNC1 ); \
29595ff2 253 s = PEEKSPACE(s); \
376fcdbf
AL
254 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
255 }
79072805 256
9f68db38 257/* grandfather return to old style */
3280af22 258#define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
79072805 259
8fa7f367
JH
260#ifdef DEBUGGING
261
bbf60fe6
DM
262/* how to interpret the yylval associated with the token */
263enum token_type {
264 TOKENTYPE_NONE,
265 TOKENTYPE_IVAL,
266 TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
267 TOKENTYPE_PVAL,
268 TOKENTYPE_OPVAL,
269 TOKENTYPE_GVVAL
270};
271
6d4a66ac
NC
272static struct debug_tokens {
273 const int token;
274 enum token_type type;
275 const char *name;
276} const debug_tokens[] =
9041c2e3 277{
bbf60fe6
DM
278 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
279 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
280 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
281 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
282 { ARROW, TOKENTYPE_NONE, "ARROW" },
283 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
284 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
285 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
286 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
287 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
0d863452 288 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
bbf60fe6
DM
289 { DO, TOKENTYPE_NONE, "DO" },
290 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
291 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
292 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
293 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
294 { ELSE, TOKENTYPE_NONE, "ELSE" },
295 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
296 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
297 { FOR, TOKENTYPE_IVAL, "FOR" },
298 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
299 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
300 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
301 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
302 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
303 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
0d863452 304 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
bbf60fe6
DM
305 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
306 { IF, TOKENTYPE_IVAL, "IF" },
307 { LABEL, TOKENTYPE_PVAL, "LABEL" },
308 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
309 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
310 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
311 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
312 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
313 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
314 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
315 { MY, TOKENTYPE_IVAL, "MY" },
316 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
317 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
318 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
319 { OROP, TOKENTYPE_IVAL, "OROP" },
320 { OROR, TOKENTYPE_NONE, "OROR" },
321 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
322 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
323 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
324 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
325 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
326 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
327 { PREINC, TOKENTYPE_NONE, "PREINC" },
328 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
329 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
330 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
331 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
332 { SUB, TOKENTYPE_NONE, "SUB" },
333 { THING, TOKENTYPE_OPVAL, "THING" },
334 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
335 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
336 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
337 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
338 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
339 { USE, TOKENTYPE_IVAL, "USE" },
0d863452 340 { WHEN, TOKENTYPE_IVAL, "WHEN" },
bbf60fe6
DM
341 { WHILE, TOKENTYPE_IVAL, "WHILE" },
342 { WORD, TOKENTYPE_OPVAL, "WORD" },
c35e046a 343 { 0, TOKENTYPE_NONE, NULL }
bbf60fe6
DM
344};
345
346/* dump the returned token in rv, plus any optional arg in yylval */
998054bd 347
bbf60fe6 348STATIC int
f5bd084c 349S_tokereport(pTHX_ I32 rv)
bbf60fe6 350{
97aff369 351 dVAR;
bbf60fe6 352 if (DEBUG_T_TEST) {
bd61b366 353 const char *name = NULL;
bbf60fe6 354 enum token_type type = TOKENTYPE_NONE;
f54cb97a 355 const struct debug_tokens *p;
396482e1 356 SV* const report = newSVpvs("<== ");
bbf60fe6 357
f54cb97a 358 for (p = debug_tokens; p->token; p++) {
bbf60fe6
DM
359 if (p->token == (int)rv) {
360 name = p->name;
361 type = p->type;
362 break;
363 }
364 }
365 if (name)
54667de8 366 Perl_sv_catpv(aTHX_ report, name);
bbf60fe6
DM
367 else if ((char)rv > ' ' && (char)rv < '~')
368 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
369 else if (!rv)
396482e1 370 sv_catpvs(report, "EOF");
bbf60fe6
DM
371 else
372 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
373 switch (type) {
374 case TOKENTYPE_NONE:
375 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
376 break;
377 case TOKENTYPE_IVAL:
e4584336 378 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival);
bbf60fe6
DM
379 break;
380 case TOKENTYPE_OPNUM:
381 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
382 PL_op_name[yylval.ival]);
383 break;
384 case TOKENTYPE_PVAL:
385 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
386 break;
387 case TOKENTYPE_OPVAL:
b6007c36 388 if (yylval.opval) {
401441c0 389 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
bbf60fe6 390 PL_op_name[yylval.opval->op_type]);
b6007c36
DM
391 if (yylval.opval->op_type == OP_CONST) {
392 Perl_sv_catpvf(aTHX_ report, " %s",
393 SvPEEK(cSVOPx_sv(yylval.opval)));
394 }
395
396 }
401441c0 397 else
396482e1 398 sv_catpvs(report, "(opval=null)");
bbf60fe6
DM
399 break;
400 }
b6007c36 401 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
bbf60fe6
DM
402 };
403 return (int)rv;
998054bd
SC
404}
405
b6007c36
DM
406
407/* print the buffer with suitable escapes */
408
409STATIC void
410S_printbuf(pTHX_ const char* fmt, const char* s)
411{
396482e1 412 SV* const tmp = newSVpvs("");
b6007c36
DM
413 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
414 SvREFCNT_dec(tmp);
415}
416
8fa7f367
JH
417#endif
418
ffb4593c
NT
419/*
420 * S_ao
421 *
c963b151
BD
422 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
423 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
ffb4593c
NT
424 */
425
76e3520e 426STATIC int
cea2e8a9 427S_ao(pTHX_ int toketype)
a0d0e21e 428{
97aff369 429 dVAR;
3280af22
NIS
430 if (*PL_bufptr == '=') {
431 PL_bufptr++;
a0d0e21e
LW
432 if (toketype == ANDAND)
433 yylval.ival = OP_ANDASSIGN;
434 else if (toketype == OROR)
435 yylval.ival = OP_ORASSIGN;
c963b151
BD
436 else if (toketype == DORDOR)
437 yylval.ival = OP_DORASSIGN;
a0d0e21e
LW
438 toketype = ASSIGNOP;
439 }
440 return toketype;
441}
442
ffb4593c
NT
443/*
444 * S_no_op
445 * When Perl expects an operator and finds something else, no_op
446 * prints the warning. It always prints "<something> found where
447 * operator expected. It prints "Missing semicolon on previous line?"
448 * if the surprise occurs at the start of the line. "do you need to
449 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
450 * where the compiler doesn't know if foo is a method call or a function.
451 * It prints "Missing operator before end of line" if there's nothing
452 * after the missing operator, or "... before <...>" if there is something
453 * after the missing operator.
454 */
455
76e3520e 456STATIC void
bfed75c6 457S_no_op(pTHX_ const char *what, char *s)
463ee0b2 458{
97aff369 459 dVAR;
9d4ba2ae
AL
460 char * const oldbp = PL_bufptr;
461 const bool is_first = (PL_oldbufptr == PL_linestart);
68dc0745 462
1189a94a
GS
463 if (!s)
464 s = oldbp;
07c798fb 465 else
1189a94a 466 PL_bufptr = s;
cea2e8a9 467 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
56da5a46
RGS
468 if (ckWARN_d(WARN_SYNTAX)) {
469 if (is_first)
470 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
471 "\t(Missing semicolon on previous line?)\n");
472 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
f54cb97a 473 const char *t;
c35e046a
AL
474 for (t = PL_oldoldbufptr; (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
475 NOOP;
56da5a46
RGS
476 if (t < PL_bufptr && isSPACE(*t))
477 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
478 "\t(Do you need to predeclare %.*s?)\n",
551405c4 479 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
56da5a46
RGS
480 }
481 else {
482 assert(s >= oldbp);
483 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
551405c4 484 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
56da5a46 485 }
07c798fb 486 }
3280af22 487 PL_bufptr = oldbp;
8990e307
LW
488}
489
ffb4593c
NT
490/*
491 * S_missingterm
492 * Complain about missing quote/regexp/heredoc terminator.
d4c19fe8 493 * If it's called with NULL then it cauterizes the line buffer.
ffb4593c
NT
494 * If we're in a delimited string and the delimiter is a control
495 * character, it's reformatted into a two-char sequence like ^C.
496 * This is fatal.
497 */
498
76e3520e 499STATIC void
cea2e8a9 500S_missingterm(pTHX_ char *s)
8990e307 501{
97aff369 502 dVAR;
8990e307
LW
503 char tmpbuf[3];
504 char q;
505 if (s) {
9d4ba2ae 506 char * const nl = strrchr(s,'\n');
d2719217 507 if (nl)
8990e307
LW
508 *nl = '\0';
509 }
9d116dd7
JH
510 else if (
511#ifdef EBCDIC
512 iscntrl(PL_multi_close)
513#else
514 PL_multi_close < 32 || PL_multi_close == 127
515#endif
516 ) {
8990e307 517 *tmpbuf = '^';
585ec06d 518 tmpbuf[1] = (char)toCTRL(PL_multi_close);
8990e307
LW
519 tmpbuf[2] = '\0';
520 s = tmpbuf;
521 }
522 else {
eb160463 523 *tmpbuf = (char)PL_multi_close;
8990e307
LW
524 tmpbuf[1] = '\0';
525 s = tmpbuf;
526 }
527 q = strchr(s,'"') ? '\'' : '"';
cea2e8a9 528 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
463ee0b2 529}
79072805 530
ef89dcc3 531#define FEATURE_IS_ENABLED(name) \
0d863452 532 ((0 != (PL_hints & HINT_LOCALIZE_HH)) \
89529cee 533 && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
0d863452
RH
534/*
535 * S_feature_is_enabled
536 * Check whether the named feature is enabled.
537 */
538STATIC bool
d4c19fe8 539S_feature_is_enabled(pTHX_ const char *name, STRLEN namelen)
0d863452 540{
97aff369 541 dVAR;
0d863452 542 HV * const hinthv = GvHV(PL_hintgv);
7b9ef140 543 char he_name[32] = "feature_";
6fca0082 544 (void) my_strlcpy(&he_name[8], name, 24);
d4c19fe8 545
7b9ef140 546 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
0d863452
RH
547}
548
ffb4593c
NT
549/*
550 * Perl_deprecate
ffb4593c
NT
551 */
552
79072805 553void
bfed75c6 554Perl_deprecate(pTHX_ const char *s)
a0d0e21e 555{
599cee73 556 if (ckWARN(WARN_DEPRECATED))
9014280d 557 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
a0d0e21e
LW
558}
559
12bcd1a6 560void
bfed75c6 561Perl_deprecate_old(pTHX_ const char *s)
12bcd1a6
PM
562{
563 /* This function should NOT be called for any new deprecated warnings */
564 /* Use Perl_deprecate instead */
565 /* */
566 /* It is here to maintain backward compatibility with the pre-5.8 */
567 /* warnings category hierarchy. The "deprecated" category used to */
568 /* live under the "syntax" category. It is now a top-level category */
569 /* in its own right. */
570
571 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
bfed75c6 572 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
12bcd1a6
PM
573 "Use of %s is deprecated", s);
574}
575
ffb4593c 576/*
9cbb5ea2
GS
577 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
578 * utf16-to-utf8-reversed.
ffb4593c
NT
579 */
580
c39cd008
GS
581#ifdef PERL_CR_FILTER
582static void
583strip_return(SV *sv)
584{
95a20fc0 585 register const char *s = SvPVX_const(sv);
9d4ba2ae 586 register const char * const e = s + SvCUR(sv);
c39cd008
GS
587 /* outer loop optimized to do nothing if there are no CR-LFs */
588 while (s < e) {
589 if (*s++ == '\r' && *s == '\n') {
590 /* hit a CR-LF, need to copy the rest */
591 register char *d = s - 1;
592 *d++ = *s++;
593 while (s < e) {
594 if (*s == '\r' && s[1] == '\n')
595 s++;
596 *d++ = *s++;
597 }
598 SvCUR(sv) -= s - d;
599 return;
600 }
601 }
602}
a868473f 603
76e3520e 604STATIC I32
c39cd008 605S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
a868473f 606{
f54cb97a 607 const I32 count = FILTER_READ(idx+1, sv, maxlen);
c39cd008
GS
608 if (count > 0 && !maxlen)
609 strip_return(sv);
610 return count;
a868473f
NIS
611}
612#endif
613
199e78b7
DM
614
615
ffb4593c
NT
616/*
617 * Perl_lex_start
e3abe207 618 * Create a parser object and initialise its parser and lexer fields
ffb4593c
NT
619 */
620
a0d0e21e 621void
864dbfa3 622Perl_lex_start(pTHX_ SV *line)
79072805 623{
97aff369 624 dVAR;
6ef55633 625 const char *s = NULL;
8990e307 626 STRLEN len;
acdf0a21
DM
627 yy_parser *parser;
628
629 /* create and initialise a parser */
630
199e78b7 631 Newxz(parser, 1, yy_parser);
acdf0a21
DM
632 parser->old_parser = PL_parser;
633 PL_parser = parser;
634
635 Newx(parser->stack, YYINITDEPTH, yy_stack_frame);
636 parser->ps = parser->stack;
637 parser->stack_size = YYINITDEPTH;
638
639 parser->stack->state = 0;
640 parser->yyerrstatus = 0;
641 parser->yychar = YYEMPTY; /* Cause a token to be read. */
642
e3abe207
DM
643 /* on scope exit, free this parser and restore any outer one */
644 SAVEPARSER(parser);
645
acdf0a21 646 /* initialise lexer state */
8990e307 647
3280af22 648 SAVEI32(PL_lex_state);
5db06880
NC
649#ifdef PERL_MAD
650 if (PL_lex_state == LEX_KNOWNEXT) {
199e78b7 651 I32 toke = parser->old_parser->lasttoke;
5db06880
NC
652 while (--toke >= 0) {
653 SAVEI32(PL_nexttoke[toke].next_type);
654 SAVEVPTR(PL_nexttoke[toke].next_val);
655 if (PL_madskills)
656 SAVEVPTR(PL_nexttoke[toke].next_mad);
657 }
5db06880 658 }
cd81e915 659 SAVEI32(PL_curforce);
90e3715f 660 PL_curforce = -1;
5db06880 661#else
18b09519
GS
662 if (PL_lex_state == LEX_KNOWNEXT) {
663 I32 toke = PL_nexttoke;
664 while (--toke >= 0) {
665 SAVEI32(PL_nexttype[toke]);
666 SAVEVPTR(PL_nextval[toke]);
667 }
668 SAVEI32(PL_nexttoke);
18b09519 669 }
5db06880 670#endif
57843af0 671 SAVECOPLINE(PL_curcop);
3280af22
NIS
672 SAVEPPTR(PL_bufptr);
673 SAVEPPTR(PL_bufend);
674 SAVEPPTR(PL_oldbufptr);
675 SAVEPPTR(PL_oldoldbufptr);
207e3d1a
JH
676 SAVEPPTR(PL_last_lop);
677 SAVEPPTR(PL_last_uni);
3280af22
NIS
678 SAVEPPTR(PL_linestart);
679 SAVESPTR(PL_linestr);
c76ac1ee 680 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
bebdddfc 681 SAVEINT(PL_expect);
3280af22 682
ebca63ee 683 PL_copline = NOLINE;
3280af22 684 PL_lex_state = LEX_NORMAL;
3280af22 685 PL_expect = XSTATE;
199e78b7
DM
686 Newx(parser->lex_brackstack, 120, char);
687 Newx(parser->lex_casestack, 12, char);
688 *parser->lex_casestack = '\0';
689#ifndef PERL_MAD
76be56bc 690 PL_nexttoke = 0;
5db06880 691#endif
02b34bbe 692
10efb74f
NC
693 if (line) {
694 s = SvPV_const(line, len);
695 } else {
696 len = 0;
697 }
698 if (!len) {
699 PL_linestr = newSVpvs("\n;");
700 } else if (SvREADONLY(line) || s[len-1] != ';') {
701 PL_linestr = newSVsv(line);
702 if (s[len-1] != ';')
0eb20fa2 703 sv_catpvs(PL_linestr, "\n;");
6c5ce11d
NC
704 } else {
705 SvTEMP_off(line);
706 SvREFCNT_inc_simple_void_NN(line);
707 PL_linestr = line;
8990e307 708 }
db4997f0
NC
709 /* PL_linestr needs to survive until end of scope, not just the next
710 FREETMPS. See changes 17505 and 17546 which fixed the symptoms only. */
db4997f0 711 SAVEFREESV(PL_linestr);
3280af22
NIS
712 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
713 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
bd61b366 714 PL_last_lop = PL_last_uni = NULL;
3280af22 715 PL_rsfp = 0;
79072805 716}
a687059c 717
e3abe207
DM
718
719/* delete a parser object */
720
721void
722Perl_parser_free(pTHX_ const yy_parser *parser)
723{
724 Safefree(parser->stack);
725 Safefree(parser->lex_brackstack);
726 Safefree(parser->lex_casestack);
727 PL_parser = parser->old_parser;
728 Safefree(parser);
729}
730
731
ffb4593c
NT
732/*
733 * Perl_lex_end
9cbb5ea2
GS
734 * Finalizer for lexing operations. Must be called when the parser is
735 * done with the lexer.
ffb4593c
NT
736 */
737
463ee0b2 738void
864dbfa3 739Perl_lex_end(pTHX)
463ee0b2 740{
97aff369 741 dVAR;
3280af22 742 PL_doextract = FALSE;
463ee0b2
LW
743}
744
ffb4593c
NT
745/*
746 * S_incline
747 * This subroutine has nothing to do with tilting, whether at windmills
748 * or pinball tables. Its name is short for "increment line". It
57843af0 749 * increments the current line number in CopLINE(PL_curcop) and checks
ffb4593c 750 * to see whether the line starts with a comment of the form
9cbb5ea2
GS
751 * # line 500 "foo.pm"
752 * If so, it sets the current line number and file to the values in the comment.
ffb4593c
NT
753 */
754
76e3520e 755STATIC void
d9095cec 756S_incline(pTHX_ const char *s)
463ee0b2 757{
97aff369 758 dVAR;
d9095cec
NC
759 const char *t;
760 const char *n;
761 const char *e;
463ee0b2 762
57843af0 763 CopLINE_inc(PL_curcop);
463ee0b2
LW
764 if (*s++ != '#')
765 return;
d4c19fe8
AL
766 while (SPACE_OR_TAB(*s))
767 s++;
73659bf1
GS
768 if (strnEQ(s, "line", 4))
769 s += 4;
770 else
771 return;
084592ab 772 if (SPACE_OR_TAB(*s))
73659bf1 773 s++;
4e553d73 774 else
73659bf1 775 return;
d4c19fe8
AL
776 while (SPACE_OR_TAB(*s))
777 s++;
463ee0b2
LW
778 if (!isDIGIT(*s))
779 return;
d4c19fe8 780
463ee0b2
LW
781 n = s;
782 while (isDIGIT(*s))
783 s++;
bf4acbe4 784 while (SPACE_OR_TAB(*s))
463ee0b2 785 s++;
73659bf1 786 if (*s == '"' && (t = strchr(s+1, '"'))) {
463ee0b2 787 s++;
73659bf1
GS
788 e = t + 1;
789 }
463ee0b2 790 else {
c35e046a
AL
791 t = s;
792 while (!isSPACE(*t))
793 t++;
73659bf1 794 e = t;
463ee0b2 795 }
bf4acbe4 796 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
73659bf1
GS
797 e++;
798 if (*e != '\n' && *e != '\0')
799 return; /* false alarm */
800
f4dd75d9 801 if (t - s > 0) {
d9095cec 802 const STRLEN len = t - s;
8a5ee598 803#ifndef USE_ITHREADS
c4420975 804 const char * const cf = CopFILE(PL_curcop);
42d9b98d
NC
805 STRLEN tmplen = cf ? strlen(cf) : 0;
806 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
e66cf94c
RGS
807 /* must copy *{"::_<(eval N)[oldfilename:L]"}
808 * to *{"::_<newfilename"} */
44867030
NC
809 /* However, the long form of evals is only turned on by the
810 debugger - usually they're "(eval %lu)" */
811 char smallbuf[128];
812 char *tmpbuf;
813 GV **gvp;
d9095cec 814 STRLEN tmplen2 = len;
798b63bc 815 if (tmplen + 2 <= sizeof smallbuf)
e66cf94c
RGS
816 tmpbuf = smallbuf;
817 else
2ae0db35 818 Newx(tmpbuf, tmplen + 2, char);
44867030
NC
819 tmpbuf[0] = '_';
820 tmpbuf[1] = '<';
2ae0db35 821 memcpy(tmpbuf + 2, cf, tmplen);
44867030 822 tmplen += 2;
8a5ee598
RGS
823 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
824 if (gvp) {
44867030
NC
825 char *tmpbuf2;
826 GV *gv2;
827
828 if (tmplen2 + 2 <= sizeof smallbuf)
829 tmpbuf2 = smallbuf;
830 else
831 Newx(tmpbuf2, tmplen2 + 2, char);
832
833 if (tmpbuf2 != smallbuf || tmpbuf != smallbuf) {
834 /* Either they malloc'd it, or we malloc'd it,
835 so no prefix is present in ours. */
836 tmpbuf2[0] = '_';
837 tmpbuf2[1] = '<';
838 }
839
840 memcpy(tmpbuf2 + 2, s, tmplen2);
841 tmplen2 += 2;
842
8a5ee598 843 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
e5527e4b 844 if (!isGV(gv2)) {
8a5ee598 845 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
e5527e4b
RGS
846 /* adjust ${"::_<newfilename"} to store the new file name */
847 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
848 GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
849 GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
850 }
44867030
NC
851
852 if (tmpbuf2 != smallbuf) Safefree(tmpbuf2);
8a5ee598 853 }
e66cf94c 854 if (tmpbuf != smallbuf) Safefree(tmpbuf);
e66cf94c 855 }
8a5ee598 856#endif
05ec9bb3 857 CopFILE_free(PL_curcop);
d9095cec 858 CopFILE_setn(PL_curcop, s, len);
f4dd75d9 859 }
57843af0 860 CopLINE_set(PL_curcop, atoi(n)-1);
463ee0b2
LW
861}
862
29595ff2 863#ifdef PERL_MAD
cd81e915 864/* skip space before PL_thistoken */
29595ff2
NC
865
866STATIC char *
867S_skipspace0(pTHX_ register char *s)
868{
869 s = skipspace(s);
870 if (!PL_madskills)
871 return s;
cd81e915
NC
872 if (PL_skipwhite) {
873 if (!PL_thiswhite)
6b29d1f5 874 PL_thiswhite = newSVpvs("");
cd81e915
NC
875 sv_catsv(PL_thiswhite, PL_skipwhite);
876 sv_free(PL_skipwhite);
877 PL_skipwhite = 0;
878 }
879 PL_realtokenstart = s - SvPVX(PL_linestr);
29595ff2
NC
880 return s;
881}
882
cd81e915 883/* skip space after PL_thistoken */
29595ff2
NC
884
885STATIC char *
886S_skipspace1(pTHX_ register char *s)
887{
d4c19fe8 888 const char *start = s;
29595ff2
NC
889 I32 startoff = start - SvPVX(PL_linestr);
890
891 s = skipspace(s);
892 if (!PL_madskills)
893 return s;
894 start = SvPVX(PL_linestr) + startoff;
cd81e915 895 if (!PL_thistoken && PL_realtokenstart >= 0) {
d4c19fe8 896 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
cd81e915
NC
897 PL_thistoken = newSVpvn(tstart, start - tstart);
898 }
899 PL_realtokenstart = -1;
900 if (PL_skipwhite) {
901 if (!PL_nextwhite)
6b29d1f5 902 PL_nextwhite = newSVpvs("");
cd81e915
NC
903 sv_catsv(PL_nextwhite, PL_skipwhite);
904 sv_free(PL_skipwhite);
905 PL_skipwhite = 0;
29595ff2
NC
906 }
907 return s;
908}
909
910STATIC char *
911S_skipspace2(pTHX_ register char *s, SV **svp)
912{
c35e046a
AL
913 char *start;
914 const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
915 const I32 startoff = s - SvPVX(PL_linestr);
916
29595ff2
NC
917 s = skipspace(s);
918 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
919 if (!PL_madskills || !svp)
920 return s;
921 start = SvPVX(PL_linestr) + startoff;
cd81e915 922 if (!PL_thistoken && PL_realtokenstart >= 0) {
d4c19fe8 923 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
cd81e915
NC
924 PL_thistoken = newSVpvn(tstart, start - tstart);
925 PL_realtokenstart = -1;
29595ff2 926 }
cd81e915 927 if (PL_skipwhite) {
29595ff2 928 if (!*svp)
6b29d1f5 929 *svp = newSVpvs("");
cd81e915
NC
930 sv_setsv(*svp, PL_skipwhite);
931 sv_free(PL_skipwhite);
932 PL_skipwhite = 0;
29595ff2
NC
933 }
934
935 return s;
936}
937#endif
938
80a702cd 939STATIC void
5fa550fb 940S_update_debugger_info(pTHX_ SV *orig_sv, const char *buf, STRLEN len)
80a702cd
RGS
941{
942 AV *av = CopFILEAVx(PL_curcop);
943 if (av) {
b9f83d2f 944 SV * const sv = newSV_type(SVt_PVMG);
5fa550fb
NC
945 if (orig_sv)
946 sv_setsv(sv, orig_sv);
947 else
948 sv_setpvn(sv, buf, len);
80a702cd
RGS
949 (void)SvIOK_on(sv);
950 SvIV_set(sv, 0);
951 av_store(av, (I32)CopLINE(PL_curcop), sv);
952 }
953}
954
ffb4593c
NT
955/*
956 * S_skipspace
957 * Called to gobble the appropriate amount and type of whitespace.
958 * Skips comments as well.
959 */
960
76e3520e 961STATIC char *
cea2e8a9 962S_skipspace(pTHX_ register char *s)
a687059c 963{
97aff369 964 dVAR;
5db06880
NC
965#ifdef PERL_MAD
966 int curoff;
967 int startoff = s - SvPVX(PL_linestr);
968
cd81e915
NC
969 if (PL_skipwhite) {
970 sv_free(PL_skipwhite);
971 PL_skipwhite = 0;
5db06880
NC
972 }
973#endif
974
3280af22 975 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
bf4acbe4 976 while (s < PL_bufend && SPACE_OR_TAB(*s))
463ee0b2 977 s++;
5db06880
NC
978#ifdef PERL_MAD
979 goto done;
980#else
463ee0b2 981 return s;
5db06880 982#endif
463ee0b2
LW
983 }
984 for (;;) {
fd049845 985 STRLEN prevlen;
09bef843 986 SSize_t oldprevlen, oldoldprevlen;
9c5ffd7c 987 SSize_t oldloplen = 0, oldunilen = 0;
60e6418e
GS
988 while (s < PL_bufend && isSPACE(*s)) {
989 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
990 incline(s);
991 }
ffb4593c
NT
992
993 /* comment */
3280af22
NIS
994 if (s < PL_bufend && *s == '#') {
995 while (s < PL_bufend && *s != '\n')
463ee0b2 996 s++;
60e6418e 997 if (s < PL_bufend) {
463ee0b2 998 s++;
60e6418e
GS
999 if (PL_in_eval && !PL_rsfp) {
1000 incline(s);
1001 continue;
1002 }
1003 }
463ee0b2 1004 }
ffb4593c
NT
1005
1006 /* only continue to recharge the buffer if we're at the end
1007 * of the buffer, we're not reading from a source filter, and
1008 * we're in normal lexing mode
1009 */
09bef843
SB
1010 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
1011 PL_lex_state == LEX_FORMLINE)
5db06880
NC
1012#ifdef PERL_MAD
1013 goto done;
1014#else
463ee0b2 1015 return s;
5db06880 1016#endif
ffb4593c
NT
1017
1018 /* try to recharge the buffer */
5db06880
NC
1019#ifdef PERL_MAD
1020 curoff = s - SvPVX(PL_linestr);
1021#endif
1022
9cbb5ea2 1023 if ((s = filter_gets(PL_linestr, PL_rsfp,
bd61b366 1024 (prevlen = SvCUR(PL_linestr)))) == NULL)
9cbb5ea2 1025 {
5db06880
NC
1026#ifdef PERL_MAD
1027 if (PL_madskills && curoff != startoff) {
cd81e915 1028 if (!PL_skipwhite)
6b29d1f5 1029 PL_skipwhite = newSVpvs("");
cd81e915 1030 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
5db06880
NC
1031 curoff - startoff);
1032 }
1033
1034 /* mustn't throw out old stuff yet if madpropping */
1035 SvCUR(PL_linestr) = curoff;
1036 s = SvPVX(PL_linestr) + curoff;
1037 *s = 0;
1038 if (curoff && s[-1] == '\n')
1039 s[-1] = ' ';
1040#endif
1041
9cbb5ea2 1042 /* end of file. Add on the -p or -n magic */
cd81e915 1043 /* XXX these shouldn't really be added here, can't set PL_faketokens */
01a19ab0 1044 if (PL_minus_p) {
5db06880 1045#ifdef PERL_MAD
6502358f 1046 sv_catpvs(PL_linestr,
5db06880
NC
1047 ";}continue{print or die qq(-p destination: $!\\n);}");
1048#else
6502358f 1049 sv_setpvs(PL_linestr,
01a19ab0 1050 ";}continue{print or die qq(-p destination: $!\\n);}");
5db06880 1051#endif
3280af22 1052 PL_minus_n = PL_minus_p = 0;
a0d0e21e 1053 }
01a19ab0 1054 else if (PL_minus_n) {
5db06880
NC
1055#ifdef PERL_MAD
1056 sv_catpvn(PL_linestr, ";}", 2);
1057#else
01a19ab0 1058 sv_setpvn(PL_linestr, ";}", 2);
5db06880 1059#endif
01a19ab0
NC
1060 PL_minus_n = 0;
1061 }
a0d0e21e 1062 else
5db06880
NC
1063#ifdef PERL_MAD
1064 sv_catpvn(PL_linestr,";", 1);
1065#else
4147a61b 1066 sv_setpvn(PL_linestr,";", 1);
5db06880 1067#endif
ffb4593c
NT
1068
1069 /* reset variables for next time we lex */
9cbb5ea2 1070 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
89122651
NC
1071 = SvPVX(PL_linestr)
1072#ifdef PERL_MAD
1073 + curoff
1074#endif
1075 ;
3280af22 1076 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 1077 PL_last_lop = PL_last_uni = NULL;
ffb4593c
NT
1078
1079 /* Close the filehandle. Could be from -P preprocessor,
1080 * STDIN, or a regular file. If we were reading code from
1081 * STDIN (because the commandline held no -e or filename)
1082 * then we don't close it, we reset it so the code can
1083 * read from STDIN too.
1084 */
1085
3280af22
NIS
1086 if (PL_preprocess && !PL_in_eval)
1087 (void)PerlProc_pclose(PL_rsfp);
1088 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
1089 PerlIO_clearerr(PL_rsfp);
8990e307 1090 else
3280af22 1091 (void)PerlIO_close(PL_rsfp);
4608196e 1092 PL_rsfp = NULL;
463ee0b2
LW
1093 return s;
1094 }
ffb4593c
NT
1095
1096 /* not at end of file, so we only read another line */
09bef843
SB
1097 /* make corresponding updates to old pointers, for yyerror() */
1098 oldprevlen = PL_oldbufptr - PL_bufend;
1099 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1100 if (PL_last_uni)
1101 oldunilen = PL_last_uni - PL_bufend;
1102 if (PL_last_lop)
1103 oldloplen = PL_last_lop - PL_bufend;
3280af22
NIS
1104 PL_linestart = PL_bufptr = s + prevlen;
1105 PL_bufend = s + SvCUR(PL_linestr);
1106 s = PL_bufptr;
09bef843
SB
1107 PL_oldbufptr = s + oldprevlen;
1108 PL_oldoldbufptr = s + oldoldprevlen;
1109 if (PL_last_uni)
1110 PL_last_uni = s + oldunilen;
1111 if (PL_last_lop)
1112 PL_last_lop = s + oldloplen;
a0d0e21e 1113 incline(s);
ffb4593c
NT
1114
1115 /* debugger active and we're not compiling the debugger code,
1116 * so store the line into the debugger's array of lines
1117 */
80a702cd 1118 if (PERLDB_LINE && PL_curstash != PL_debstash)
5fa550fb 1119 update_debugger_info(NULL, PL_bufptr, PL_bufend - PL_bufptr);
463ee0b2 1120 }
5db06880
NC
1121
1122#ifdef PERL_MAD
1123 done:
1124 if (PL_madskills) {
cd81e915 1125 if (!PL_skipwhite)
6b29d1f5 1126 PL_skipwhite = newSVpvs("");
5db06880
NC
1127 curoff = s - SvPVX(PL_linestr);
1128 if (curoff - startoff)
cd81e915 1129 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
5db06880
NC
1130 curoff - startoff);
1131 }
1132 return s;
1133#endif
a687059c 1134}
378cc40b 1135
ffb4593c
NT
1136/*
1137 * S_check_uni
1138 * Check the unary operators to ensure there's no ambiguity in how they're
1139 * used. An ambiguous piece of code would be:
1140 * rand + 5
1141 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1142 * the +5 is its argument.
1143 */
1144
76e3520e 1145STATIC void
cea2e8a9 1146S_check_uni(pTHX)
ba106d47 1147{
97aff369 1148 dVAR;
d4c19fe8
AL
1149 const char *s;
1150 const char *t;
2f3197b3 1151
3280af22 1152 if (PL_oldoldbufptr != PL_last_uni)
2f3197b3 1153 return;
3280af22
NIS
1154 while (isSPACE(*PL_last_uni))
1155 PL_last_uni++;
c35e046a
AL
1156 s = PL_last_uni;
1157 while (isALNUM_lazy_if(s,UTF) || *s == '-')
1158 s++;
3280af22 1159 if ((t = strchr(s, '(')) && t < PL_bufptr)
a0d0e21e 1160 return;
6136c704 1161
0453d815 1162 if (ckWARN_d(WARN_AMBIGUOUS)){
9014280d 1163 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
32d45c1d
NC
1164 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1165 (int)(s - PL_last_uni), PL_last_uni);
0453d815 1166 }
2f3197b3
LW
1167}
1168
ffb4593c
NT
1169/*
1170 * LOP : macro to build a list operator. Its behaviour has been replaced
1171 * with a subroutine, S_lop() for which LOP is just another name.
1172 */
1173
a0d0e21e
LW
1174#define LOP(f,x) return lop(f,x,s)
1175
ffb4593c
NT
1176/*
1177 * S_lop
1178 * Build a list operator (or something that might be one). The rules:
1179 * - if we have a next token, then it's a list operator [why?]
1180 * - if the next thing is an opening paren, then it's a function
1181 * - else it's a list operator
1182 */
1183
76e3520e 1184STATIC I32
a0be28da 1185S_lop(pTHX_ I32 f, int x, char *s)
ffed7fef 1186{
97aff369 1187 dVAR;
79072805 1188 yylval.ival = f;
35c8bce7 1189 CLINE;
3280af22
NIS
1190 PL_expect = x;
1191 PL_bufptr = s;
1192 PL_last_lop = PL_oldbufptr;
eb160463 1193 PL_last_lop_op = (OPCODE)f;
5db06880
NC
1194#ifdef PERL_MAD
1195 if (PL_lasttoke)
1196 return REPORT(LSTOP);
1197#else
3280af22 1198 if (PL_nexttoke)
bbf60fe6 1199 return REPORT(LSTOP);
5db06880 1200#endif
79072805 1201 if (*s == '(')
bbf60fe6 1202 return REPORT(FUNC);
29595ff2 1203 s = PEEKSPACE(s);
79072805 1204 if (*s == '(')
bbf60fe6 1205 return REPORT(FUNC);
79072805 1206 else
bbf60fe6 1207 return REPORT(LSTOP);
79072805
LW
1208}
1209
5db06880
NC
1210#ifdef PERL_MAD
1211 /*
1212 * S_start_force
1213 * Sets up for an eventual force_next(). start_force(0) basically does
1214 * an unshift, while start_force(-1) does a push. yylex removes items
1215 * on the "pop" end.
1216 */
1217
1218STATIC void
1219S_start_force(pTHX_ int where)
1220{
1221 int i;
1222
cd81e915 1223 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
5db06880 1224 where = PL_lasttoke;
cd81e915
NC
1225 assert(PL_curforce < 0 || PL_curforce == where);
1226 if (PL_curforce != where) {
5db06880
NC
1227 for (i = PL_lasttoke; i > where; --i) {
1228 PL_nexttoke[i] = PL_nexttoke[i-1];
1229 }
1230 PL_lasttoke++;
1231 }
cd81e915 1232 if (PL_curforce < 0) /* in case of duplicate start_force() */
5db06880 1233 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
cd81e915
NC
1234 PL_curforce = where;
1235 if (PL_nextwhite) {
5db06880 1236 if (PL_madskills)
6b29d1f5 1237 curmad('^', newSVpvs(""));
cd81e915 1238 CURMAD('_', PL_nextwhite);
5db06880
NC
1239 }
1240}
1241
1242STATIC void
1243S_curmad(pTHX_ char slot, SV *sv)
1244{
1245 MADPROP **where;
1246
1247 if (!sv)
1248 return;
cd81e915
NC
1249 if (PL_curforce < 0)
1250 where = &PL_thismad;
5db06880 1251 else
cd81e915 1252 where = &PL_nexttoke[PL_curforce].next_mad;
5db06880 1253
cd81e915 1254 if (PL_faketokens)
5db06880
NC
1255 sv_setpvn(sv, "", 0);
1256 else {
1257 if (!IN_BYTES) {
1258 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1259 SvUTF8_on(sv);
1260 else if (PL_encoding) {
1261 sv_recode_to_utf8(sv, PL_encoding);
1262 }
1263 }
1264 }
1265
1266 /* keep a slot open for the head of the list? */
1267 if (slot != '_' && *where && (*where)->mad_key == '^') {
1268 (*where)->mad_key = slot;
1269 sv_free((*where)->mad_val);
1270 (*where)->mad_val = (void*)sv;
1271 }
1272 else
1273 addmad(newMADsv(slot, sv), where, 0);
1274}
1275#else
b3f24c00
MHM
1276# define start_force(where) NOOP
1277# define curmad(slot, sv) NOOP
5db06880
NC
1278#endif
1279
ffb4593c
NT
1280/*
1281 * S_force_next
9cbb5ea2 1282 * When the lexer realizes it knows the next token (for instance,
ffb4593c 1283 * it is reordering tokens for the parser) then it can call S_force_next
9cbb5ea2 1284 * to know what token to return the next time the lexer is called. Caller
5db06880
NC
1285 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1286 * and possibly PL_expect to ensure the lexer handles the token correctly.
ffb4593c
NT
1287 */
1288
4e553d73 1289STATIC void
cea2e8a9 1290S_force_next(pTHX_ I32 type)
79072805 1291{
97aff369 1292 dVAR;
5db06880 1293#ifdef PERL_MAD
cd81e915 1294 if (PL_curforce < 0)
5db06880 1295 start_force(PL_lasttoke);
cd81e915 1296 PL_nexttoke[PL_curforce].next_type = type;
5db06880
NC
1297 if (PL_lex_state != LEX_KNOWNEXT)
1298 PL_lex_defer = PL_lex_state;
1299 PL_lex_state = LEX_KNOWNEXT;
1300 PL_lex_expect = PL_expect;
cd81e915 1301 PL_curforce = -1;
5db06880 1302#else
3280af22
NIS
1303 PL_nexttype[PL_nexttoke] = type;
1304 PL_nexttoke++;
1305 if (PL_lex_state != LEX_KNOWNEXT) {
1306 PL_lex_defer = PL_lex_state;
1307 PL_lex_expect = PL_expect;
1308 PL_lex_state = LEX_KNOWNEXT;
79072805 1309 }
5db06880 1310#endif
79072805
LW
1311}
1312
d0a148a6
NC
1313STATIC SV *
1314S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
1315{
97aff369 1316 dVAR;
9d4ba2ae 1317 SV * const sv = newSVpvn(start,len);
bfed75c6 1318 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
d0a148a6
NC
1319 SvUTF8_on(sv);
1320 return sv;
1321}
1322
ffb4593c
NT
1323/*
1324 * S_force_word
1325 * When the lexer knows the next thing is a word (for instance, it has
1326 * just seen -> and it knows that the next char is a word char, then
02b34bbe
DM
1327 * it calls S_force_word to stick the next word into the PL_nexttoke/val
1328 * lookahead.
ffb4593c
NT
1329 *
1330 * Arguments:
b1b65b59 1331 * char *start : buffer position (must be within PL_linestr)
02b34bbe 1332 * int token : PL_next* will be this type of bare word (e.g., METHOD,WORD)
ffb4593c
NT
1333 * int check_keyword : if true, Perl checks to make sure the word isn't
1334 * a keyword (do this if the word is a label, e.g. goto FOO)
1335 * int allow_pack : if true, : characters will also be allowed (require,
1336 * use, etc. do this)
9cbb5ea2 1337 * int allow_initial_tick : used by the "sub" lexer only.
ffb4593c
NT
1338 */
1339
76e3520e 1340STATIC char *
cea2e8a9 1341S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
79072805 1342{
97aff369 1343 dVAR;
463ee0b2
LW
1344 register char *s;
1345 STRLEN len;
4e553d73 1346
29595ff2 1347 start = SKIPSPACE1(start);
463ee0b2 1348 s = start;
7e2040f0 1349 if (isIDFIRST_lazy_if(s,UTF) ||
a0d0e21e 1350 (allow_pack && *s == ':') ||
15f0808c 1351 (allow_initial_tick && *s == '\'') )
a0d0e21e 1352 {
3280af22 1353 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
5458a98a 1354 if (check_keyword && keyword(PL_tokenbuf, len, 0))
463ee0b2 1355 return start;
cd81e915 1356 start_force(PL_curforce);
5db06880
NC
1357 if (PL_madskills)
1358 curmad('X', newSVpvn(start,s-start));
463ee0b2 1359 if (token == METHOD) {
29595ff2 1360 s = SKIPSPACE1(s);
463ee0b2 1361 if (*s == '(')
3280af22 1362 PL_expect = XTERM;
463ee0b2 1363 else {
3280af22 1364 PL_expect = XOPERATOR;
463ee0b2 1365 }
79072805 1366 }
9ded7720 1367 NEXTVAL_NEXTTOKE.opval
d0a148a6
NC
1368 = (OP*)newSVOP(OP_CONST,0,
1369 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
9ded7720 1370 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
79072805
LW
1371 force_next(token);
1372 }
1373 return s;
1374}
1375
ffb4593c
NT
1376/*
1377 * S_force_ident
9cbb5ea2 1378 * Called when the lexer wants $foo *foo &foo etc, but the program
ffb4593c
NT
1379 * text only contains the "foo" portion. The first argument is a pointer
1380 * to the "foo", and the second argument is the type symbol to prefix.
1381 * Forces the next token to be a "WORD".
9cbb5ea2 1382 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
ffb4593c
NT
1383 */
1384
76e3520e 1385STATIC void
bfed75c6 1386S_force_ident(pTHX_ register const char *s, int kind)
79072805 1387{
97aff369 1388 dVAR;
c35e046a 1389 if (*s) {
90e5519e
NC
1390 const STRLEN len = strlen(s);
1391 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
cd81e915 1392 start_force(PL_curforce);
9ded7720 1393 NEXTVAL_NEXTTOKE.opval = o;
79072805 1394 force_next(WORD);
748a9306 1395 if (kind) {
11343788 1396 o->op_private = OPpCONST_ENTERED;
55497cff 1397 /* XXX see note in pp_entereval() for why we forgo typo
1398 warnings if the symbol must be introduced in an eval.
1399 GSAR 96-10-12 */
90e5519e
NC
1400 gv_fetchpvn_flags(s, len,
1401 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1402 : GV_ADD,
1403 kind == '$' ? SVt_PV :
1404 kind == '@' ? SVt_PVAV :
1405 kind == '%' ? SVt_PVHV :
a0d0e21e 1406 SVt_PVGV
90e5519e 1407 );
748a9306 1408 }
79072805
LW
1409 }
1410}
1411
1571675a
GS
1412NV
1413Perl_str_to_version(pTHX_ SV *sv)
1414{
1415 NV retval = 0.0;
1416 NV nshift = 1.0;
1417 STRLEN len;
cfd0369c 1418 const char *start = SvPV_const(sv,len);
9d4ba2ae 1419 const char * const end = start + len;
504618e9 1420 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1571675a 1421 while (start < end) {
ba210ebe 1422 STRLEN skip;
1571675a
GS
1423 UV n;
1424 if (utf)
9041c2e3 1425 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1571675a
GS
1426 else {
1427 n = *(U8*)start;
1428 skip = 1;
1429 }
1430 retval += ((NV)n)/nshift;
1431 start += skip;
1432 nshift *= 1000;
1433 }
1434 return retval;
1435}
1436
4e553d73 1437/*
ffb4593c
NT
1438 * S_force_version
1439 * Forces the next token to be a version number.
e759cc13
RGS
1440 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1441 * and if "guessing" is TRUE, then no new token is created (and the caller
1442 * must use an alternative parsing method).
ffb4593c
NT
1443 */
1444
76e3520e 1445STATIC char *
e759cc13 1446S_force_version(pTHX_ char *s, int guessing)
89bfa8cd 1447{
97aff369 1448 dVAR;
5f66b61c 1449 OP *version = NULL;
44dcb63b 1450 char *d;
5db06880
NC
1451#ifdef PERL_MAD
1452 I32 startoff = s - SvPVX(PL_linestr);
1453#endif
89bfa8cd 1454
29595ff2 1455 s = SKIPSPACE1(s);
89bfa8cd 1456
44dcb63b 1457 d = s;
dd629d5b 1458 if (*d == 'v')
44dcb63b 1459 d++;
44dcb63b 1460 if (isDIGIT(*d)) {
e759cc13
RGS
1461 while (isDIGIT(*d) || *d == '_' || *d == '.')
1462 d++;
5db06880
NC
1463#ifdef PERL_MAD
1464 if (PL_madskills) {
cd81e915 1465 start_force(PL_curforce);
5db06880
NC
1466 curmad('X', newSVpvn(s,d-s));
1467 }
1468#endif
9f3d182e 1469 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
dd629d5b 1470 SV *ver;
b73d6f50 1471 s = scan_num(s, &yylval);
89bfa8cd 1472 version = yylval.opval;
dd629d5b
GS
1473 ver = cSVOPx(version)->op_sv;
1474 if (SvPOK(ver) && !SvNIOK(ver)) {
862a34c6 1475 SvUPGRADE(ver, SVt_PVNV);
9d6ce603 1476 SvNV_set(ver, str_to_version(ver));
1571675a 1477 SvNOK_on(ver); /* hint that it is a version */
44dcb63b 1478 }
89bfa8cd 1479 }
5db06880
NC
1480 else if (guessing) {
1481#ifdef PERL_MAD
1482 if (PL_madskills) {
cd81e915
NC
1483 sv_free(PL_nextwhite); /* let next token collect whitespace */
1484 PL_nextwhite = 0;
5db06880
NC
1485 s = SvPVX(PL_linestr) + startoff;
1486 }
1487#endif
e759cc13 1488 return s;
5db06880 1489 }
89bfa8cd 1490 }
1491
5db06880
NC
1492#ifdef PERL_MAD
1493 if (PL_madskills && !version) {
cd81e915
NC
1494 sv_free(PL_nextwhite); /* let next token collect whitespace */
1495 PL_nextwhite = 0;
5db06880
NC
1496 s = SvPVX(PL_linestr) + startoff;
1497 }
1498#endif
89bfa8cd 1499 /* NOTE: The parser sees the package name and the VERSION swapped */
cd81e915 1500 start_force(PL_curforce);
9ded7720 1501 NEXTVAL_NEXTTOKE.opval = version;
4e553d73 1502 force_next(WORD);
89bfa8cd 1503
e759cc13 1504 return s;
89bfa8cd 1505}
1506
ffb4593c
NT
1507/*
1508 * S_tokeq
1509 * Tokenize a quoted string passed in as an SV. It finds the next
1510 * chunk, up to end of string or a backslash. It may make a new
1511 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1512 * turns \\ into \.
1513 */
1514
76e3520e 1515STATIC SV *
cea2e8a9 1516S_tokeq(pTHX_ SV *sv)
79072805 1517{
97aff369 1518 dVAR;
79072805
LW
1519 register char *s;
1520 register char *send;
1521 register char *d;
b3ac6de7
IZ
1522 STRLEN len = 0;
1523 SV *pv = sv;
79072805
LW
1524
1525 if (!SvLEN(sv))
b3ac6de7 1526 goto finish;
79072805 1527
a0d0e21e 1528 s = SvPV_force(sv, len);
21a311ee 1529 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
b3ac6de7 1530 goto finish;
463ee0b2 1531 send = s + len;
79072805
LW
1532 while (s < send && *s != '\\')
1533 s++;
1534 if (s == send)
b3ac6de7 1535 goto finish;
79072805 1536 d = s;
be4731d2 1537 if ( PL_hints & HINT_NEW_STRING ) {
95a20fc0 1538 pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
be4731d2
NIS
1539 if (SvUTF8(sv))
1540 SvUTF8_on(pv);
1541 }
79072805
LW
1542 while (s < send) {
1543 if (*s == '\\') {
a0d0e21e 1544 if (s + 1 < send && (s[1] == '\\'))
79072805
LW
1545 s++; /* all that, just for this */
1546 }
1547 *d++ = *s++;
1548 }
1549 *d = '\0';
95a20fc0 1550 SvCUR_set(sv, d - SvPVX_const(sv));
b3ac6de7 1551 finish:
3280af22 1552 if ( PL_hints & HINT_NEW_STRING )
b3ac6de7 1553 return new_constant(NULL, 0, "q", sv, pv, "q");
79072805
LW
1554 return sv;
1555}
1556
ffb4593c
NT
1557/*
1558 * Now come three functions related to double-quote context,
1559 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1560 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1561 * interact with PL_lex_state, and create fake ( ... ) argument lists
1562 * to handle functions and concatenation.
1563 * They assume that whoever calls them will be setting up a fake
1564 * join call, because each subthing puts a ',' after it. This lets
1565 * "lower \luPpEr"
1566 * become
1567 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1568 *
1569 * (I'm not sure whether the spurious commas at the end of lcfirst's
1570 * arguments and join's arguments are created or not).
1571 */
1572
1573/*
1574 * S_sublex_start
1575 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1576 *
1577 * Pattern matching will set PL_lex_op to the pattern-matching op to
1578 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1579 *
1580 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1581 *
1582 * Everything else becomes a FUNC.
1583 *
1584 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1585 * had an OP_CONST or OP_READLINE). This just sets us up for a
1586 * call to S_sublex_push().
1587 */
1588
76e3520e 1589STATIC I32
cea2e8a9 1590S_sublex_start(pTHX)
79072805 1591{
97aff369 1592 dVAR;
0d46e09a 1593 register const I32 op_type = yylval.ival;
79072805
LW
1594
1595 if (op_type == OP_NULL) {
3280af22 1596 yylval.opval = PL_lex_op;
5f66b61c 1597 PL_lex_op = NULL;
79072805
LW
1598 return THING;
1599 }
1600 if (op_type == OP_CONST || op_type == OP_READLINE) {
3280af22 1601 SV *sv = tokeq(PL_lex_stuff);
b3ac6de7
IZ
1602
1603 if (SvTYPE(sv) == SVt_PVIV) {
1604 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1605 STRLEN len;
96a5add6 1606 const char * const p = SvPV_const(sv, len);
f54cb97a 1607 SV * const nsv = newSVpvn(p, len);
01ec43d0
GS
1608 if (SvUTF8(sv))
1609 SvUTF8_on(nsv);
b3ac6de7
IZ
1610 SvREFCNT_dec(sv);
1611 sv = nsv;
4e553d73 1612 }
b3ac6de7 1613 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
a0714e2c 1614 PL_lex_stuff = NULL;
6f33ba73
RGS
1615 /* Allow <FH> // "foo" */
1616 if (op_type == OP_READLINE)
1617 PL_expect = XTERMORDORDOR;
79072805
LW
1618 return THING;
1619 }
e3f73d4e
RGS
1620 else if (op_type == OP_BACKTICK && PL_lex_op) {
1621 /* readpipe() vas overriden */
1622 cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff);
1623 yylval.opval = PL_lex_op;
9b201d7d 1624 PL_lex_op = NULL;
e3f73d4e
RGS
1625 PL_lex_stuff = NULL;
1626 return THING;
1627 }
79072805 1628
3280af22
NIS
1629 PL_sublex_info.super_state = PL_lex_state;
1630 PL_sublex_info.sub_inwhat = op_type;
1631 PL_sublex_info.sub_op = PL_lex_op;
1632 PL_lex_state = LEX_INTERPPUSH;
55497cff 1633
3280af22
NIS
1634 PL_expect = XTERM;
1635 if (PL_lex_op) {
1636 yylval.opval = PL_lex_op;
5f66b61c 1637 PL_lex_op = NULL;
55497cff 1638 return PMFUNC;
1639 }
1640 else
1641 return FUNC;
1642}
1643
ffb4593c
NT
1644/*
1645 * S_sublex_push
1646 * Create a new scope to save the lexing state. The scope will be
1647 * ended in S_sublex_done. Returns a '(', starting the function arguments
1648 * to the uc, lc, etc. found before.
1649 * Sets PL_lex_state to LEX_INTERPCONCAT.
1650 */
1651
76e3520e 1652STATIC I32
cea2e8a9 1653S_sublex_push(pTHX)
55497cff 1654{
27da23d5 1655 dVAR;
f46d017c 1656 ENTER;
55497cff 1657
3280af22
NIS
1658 PL_lex_state = PL_sublex_info.super_state;
1659 SAVEI32(PL_lex_dojoin);
1660 SAVEI32(PL_lex_brackets);
3280af22
NIS
1661 SAVEI32(PL_lex_casemods);
1662 SAVEI32(PL_lex_starts);
1663 SAVEI32(PL_lex_state);
7766f137 1664 SAVEVPTR(PL_lex_inpat);
3280af22 1665 SAVEI32(PL_lex_inwhat);
57843af0 1666 SAVECOPLINE(PL_curcop);
3280af22 1667 SAVEPPTR(PL_bufptr);
8452ff4b 1668 SAVEPPTR(PL_bufend);
3280af22
NIS
1669 SAVEPPTR(PL_oldbufptr);
1670 SAVEPPTR(PL_oldoldbufptr);
207e3d1a
JH
1671 SAVEPPTR(PL_last_lop);
1672 SAVEPPTR(PL_last_uni);
3280af22
NIS
1673 SAVEPPTR(PL_linestart);
1674 SAVESPTR(PL_linestr);
8edd5f42
RGS
1675 SAVEGENERICPV(PL_lex_brackstack);
1676 SAVEGENERICPV(PL_lex_casestack);
3280af22
NIS
1677
1678 PL_linestr = PL_lex_stuff;
a0714e2c 1679 PL_lex_stuff = NULL;
3280af22 1680
9cbb5ea2
GS
1681 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1682 = SvPVX(PL_linestr);
3280af22 1683 PL_bufend += SvCUR(PL_linestr);
bd61b366 1684 PL_last_lop = PL_last_uni = NULL;
3280af22
NIS
1685 SAVEFREESV(PL_linestr);
1686
1687 PL_lex_dojoin = FALSE;
1688 PL_lex_brackets = 0;
a02a5408
JC
1689 Newx(PL_lex_brackstack, 120, char);
1690 Newx(PL_lex_casestack, 12, char);
3280af22
NIS
1691 PL_lex_casemods = 0;
1692 *PL_lex_casestack = '\0';
1693 PL_lex_starts = 0;
1694 PL_lex_state = LEX_INTERPCONCAT;
eb160463 1695 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
3280af22
NIS
1696
1697 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1698 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1699 PL_lex_inpat = PL_sublex_info.sub_op;
79072805 1700 else
5f66b61c 1701 PL_lex_inpat = NULL;
79072805 1702
55497cff 1703 return '(';
79072805
LW
1704}
1705
ffb4593c
NT
1706/*
1707 * S_sublex_done
1708 * Restores lexer state after a S_sublex_push.
1709 */
1710
76e3520e 1711STATIC I32
cea2e8a9 1712S_sublex_done(pTHX)
79072805 1713{
27da23d5 1714 dVAR;
3280af22 1715 if (!PL_lex_starts++) {
396482e1 1716 SV * const sv = newSVpvs("");
9aa983d2
JH
1717 if (SvUTF8(PL_linestr))
1718 SvUTF8_on(sv);
3280af22 1719 PL_expect = XOPERATOR;
9aa983d2 1720 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
79072805
LW
1721 return THING;
1722 }
1723
3280af22
NIS
1724 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1725 PL_lex_state = LEX_INTERPCASEMOD;
cea2e8a9 1726 return yylex();
79072805
LW
1727 }
1728
ffb4593c 1729 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
3280af22
NIS
1730 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1731 PL_linestr = PL_lex_repl;
1732 PL_lex_inpat = 0;
1733 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1734 PL_bufend += SvCUR(PL_linestr);
bd61b366 1735 PL_last_lop = PL_last_uni = NULL;
3280af22
NIS
1736 SAVEFREESV(PL_linestr);
1737 PL_lex_dojoin = FALSE;
1738 PL_lex_brackets = 0;
3280af22
NIS
1739 PL_lex_casemods = 0;
1740 *PL_lex_casestack = '\0';
1741 PL_lex_starts = 0;
25da4f38 1742 if (SvEVALED(PL_lex_repl)) {
3280af22
NIS
1743 PL_lex_state = LEX_INTERPNORMAL;
1744 PL_lex_starts++;
e9fa98b2
HS
1745 /* we don't clear PL_lex_repl here, so that we can check later
1746 whether this is an evalled subst; that means we rely on the
1747 logic to ensure sublex_done() is called again only via the
1748 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
79072805 1749 }
e9fa98b2 1750 else {
3280af22 1751 PL_lex_state = LEX_INTERPCONCAT;
a0714e2c 1752 PL_lex_repl = NULL;
e9fa98b2 1753 }
79072805 1754 return ',';
ffed7fef
LW
1755 }
1756 else {
5db06880
NC
1757#ifdef PERL_MAD
1758 if (PL_madskills) {
cd81e915
NC
1759 if (PL_thiswhite) {
1760 if (!PL_endwhite)
6b29d1f5 1761 PL_endwhite = newSVpvs("");
cd81e915
NC
1762 sv_catsv(PL_endwhite, PL_thiswhite);
1763 PL_thiswhite = 0;
1764 }
1765 if (PL_thistoken)
1766 sv_setpvn(PL_thistoken,"",0);
5db06880 1767 else
cd81e915 1768 PL_realtokenstart = -1;
5db06880
NC
1769 }
1770#endif
f46d017c 1771 LEAVE;
3280af22
NIS
1772 PL_bufend = SvPVX(PL_linestr);
1773 PL_bufend += SvCUR(PL_linestr);
1774 PL_expect = XOPERATOR;
09bef843 1775 PL_sublex_info.sub_inwhat = 0;
79072805 1776 return ')';
ffed7fef
LW
1777 }
1778}
1779
02aa26ce
NT
1780/*
1781 scan_const
1782
1783 Extracts a pattern, double-quoted string, or transliteration. This
1784 is terrifying code.
1785
94def140 1786 It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
3280af22 1787 processing a pattern (PL_lex_inpat is true), a transliteration
94def140 1788 (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
02aa26ce 1789
94def140
TS
1790 Returns a pointer to the character scanned up to. If this is
1791 advanced from the start pointer supplied (i.e. if anything was
9b599b2a
GS
1792 successfully parsed), will leave an OP for the substring scanned
1793 in yylval. Caller must intuit reason for not parsing further
1794 by looking at the next characters herself.
1795
02aa26ce
NT
1796 In patterns:
1797 backslashes:
1798 double-quoted style: \r and \n
1799 regexp special ones: \D \s
94def140
TS
1800 constants: \x31
1801 backrefs: \1
02aa26ce
NT
1802 case and quoting: \U \Q \E
1803 stops on @ and $, but not for $ as tail anchor
1804
1805 In transliterations:
1806 characters are VERY literal, except for - not at the start or end
94def140
TS
1807 of the string, which indicates a range. If the range is in bytes,
1808 scan_const expands the range to the full set of intermediate
1809 characters. If the range is in utf8, the hyphen is replaced with
1810 a certain range mark which will be handled by pmtrans() in op.c.
02aa26ce
NT
1811
1812 In double-quoted strings:
1813 backslashes:
1814 double-quoted style: \r and \n
94def140
TS
1815 constants: \x31
1816 deprecated backrefs: \1 (in substitution replacements)
02aa26ce
NT
1817 case and quoting: \U \Q \E
1818 stops on @ and $
1819
1820 scan_const does *not* construct ops to handle interpolated strings.
1821 It stops processing as soon as it finds an embedded $ or @ variable
1822 and leaves it to the caller to work out what's going on.
1823
94def140
TS
1824 embedded arrays (whether in pattern or not) could be:
1825 @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
1826
1827 $ in double-quoted strings must be the symbol of an embedded scalar.
02aa26ce
NT
1828
1829 $ in pattern could be $foo or could be tail anchor. Assumption:
1830 it's a tail anchor if $ is the last thing in the string, or if it's
94def140 1831 followed by one of "()| \r\n\t"
02aa26ce
NT
1832
1833 \1 (backreferences) are turned into $1
1834
1835 The structure of the code is
1836 while (there's a character to process) {
94def140
TS
1837 handle transliteration ranges
1838 skip regexp comments /(?#comment)/ and codes /(?{code})/
1839 skip #-initiated comments in //x patterns
1840 check for embedded arrays
02aa26ce
NT
1841 check for embedded scalars
1842 if (backslash) {
94def140
TS
1843 leave intact backslashes from leaveit (below)
1844 deprecate \1 in substitution replacements
02aa26ce
NT
1845 handle string-changing backslashes \l \U \Q \E, etc.
1846 switch (what was escaped) {
94def140
TS
1847 handle \- in a transliteration (becomes a literal -)
1848 handle \132 (octal characters)
1849 handle \x15 and \x{1234} (hex characters)
1850 handle \N{name} (named characters)
1851 handle \cV (control characters)
1852 handle printf-style backslashes (\f, \r, \n, etc)
02aa26ce
NT
1853 } (end switch)
1854 } (end if backslash)
1855 } (end while character to read)
4e553d73 1856
02aa26ce
NT
1857*/
1858
76e3520e 1859STATIC char *
cea2e8a9 1860S_scan_const(pTHX_ char *start)
79072805 1861{
97aff369 1862 dVAR;
3280af22 1863 register char *send = PL_bufend; /* end of the constant */
561b68a9 1864 SV *sv = newSV(send - start); /* sv for the constant */
02aa26ce
NT
1865 register char *s = start; /* start of the constant */
1866 register char *d = SvPVX(sv); /* destination for copies */
1867 bool dorange = FALSE; /* are we in a translit range? */
c2e66d9e 1868 bool didrange = FALSE; /* did we just finish a range? */
2b9d42f0
NIS
1869 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1870 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
012bcf8d 1871 UV uv;
4c3a8340
TS
1872#ifdef EBCDIC
1873 UV literal_endpoint = 0;
e294cc5d 1874 bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
4c3a8340 1875#endif
012bcf8d 1876
2b9d42f0
NIS
1877 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1878 /* If we are doing a trans and we know we want UTF8 set expectation */
1879 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1880 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1881 }
1882
1883
79072805 1884 while (s < send || dorange) {
02aa26ce 1885 /* get transliterations out of the way (they're most literal) */
3280af22 1886 if (PL_lex_inwhat == OP_TRANS) {
02aa26ce 1887 /* expand a range A-Z to the full set of characters. AIE! */
79072805 1888 if (dorange) {
1ba5c669
JH
1889 I32 i; /* current expanded character */
1890 I32 min; /* first character in range */
1891 I32 max; /* last character in range */
02aa26ce 1892
e294cc5d
JH
1893#ifdef EBCDIC
1894 UV uvmax = 0;
1895#endif
1896
1897 if (has_utf8
1898#ifdef EBCDIC
1899 && !native_range
1900#endif
1901 ) {
9d4ba2ae 1902 char * const c = (char*)utf8_hop((U8*)d, -1);
8973db79
JH
1903 char *e = d++;
1904 while (e-- > c)
1905 *(e + 1) = *e;
25716404 1906 *c = (char)UTF_TO_NATIVE(0xff);
8973db79
JH
1907 /* mark the range as done, and continue */
1908 dorange = FALSE;
1909 didrange = TRUE;
1910 continue;
1911 }
2b9d42f0 1912
95a20fc0 1913 i = d - SvPVX_const(sv); /* remember current offset */
e294cc5d
JH
1914#ifdef EBCDIC
1915 SvGROW(sv,
1916 SvLEN(sv) + (has_utf8 ?
1917 (512 - UTF_CONTINUATION_MARK +
1918 UNISKIP(0x100))
1919 : 256));
1920 /* How many two-byte within 0..255: 128 in UTF-8,
1921 * 96 in UTF-8-mod. */
1922#else
9cbb5ea2 1923 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
e294cc5d 1924#endif
9cbb5ea2 1925 d = SvPVX(sv) + i; /* refresh d after realloc */
e294cc5d
JH
1926#ifdef EBCDIC
1927 if (has_utf8) {
1928 int j;
1929 for (j = 0; j <= 1; j++) {
1930 char * const c = (char*)utf8_hop((U8*)d, -1);
1931 const UV uv = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
1932 if (j)
1933 min = (U8)uv;
1934 else if (uv < 256)
1935 max = (U8)uv;
1936 else {
1937 max = (U8)0xff; /* only to \xff */
1938 uvmax = uv; /* \x{100} to uvmax */
1939 }
1940 d = c; /* eat endpoint chars */
1941 }
1942 }
1943 else {
1944#endif
1945 d -= 2; /* eat the first char and the - */
1946 min = (U8)*d; /* first char in range */
1947 max = (U8)d[1]; /* last char in range */
1948#ifdef EBCDIC
1949 }
1950#endif
8ada0baa 1951
c2e66d9e 1952 if (min > max) {
01ec43d0 1953 Perl_croak(aTHX_
d1573ac7 1954 "Invalid range \"%c-%c\" in transliteration operator",
1ba5c669 1955 (char)min, (char)max);
c2e66d9e
GS
1956 }
1957
c7f1f016 1958#ifdef EBCDIC
4c3a8340
TS
1959 if (literal_endpoint == 2 &&
1960 ((isLOWER(min) && isLOWER(max)) ||
1961 (isUPPER(min) && isUPPER(max)))) {
8ada0baa
JH
1962 if (isLOWER(min)) {
1963 for (i = min; i <= max; i++)
1964 if (isLOWER(i))
db42d148 1965 *d++ = NATIVE_TO_NEED(has_utf8,i);
8ada0baa
JH
1966 } else {
1967 for (i = min; i <= max; i++)
1968 if (isUPPER(i))
db42d148 1969 *d++ = NATIVE_TO_NEED(has_utf8,i);
8ada0baa
JH
1970 }
1971 }
1972 else
1973#endif
1974 for (i = min; i <= max; i++)
e294cc5d
JH
1975#ifdef EBCDIC
1976 if (has_utf8) {
1977 const U8 ch = (U8)NATIVE_TO_UTF(i);
1978 if (UNI_IS_INVARIANT(ch))
1979 *d++ = (U8)i;
1980 else {
1981 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
1982 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
1983 }
1984 }
1985 else
1986#endif
1987 *d++ = (char)i;
1988
1989#ifdef EBCDIC
1990 if (uvmax) {
1991 d = (char*)uvchr_to_utf8((U8*)d, 0x100);
1992 if (uvmax > 0x101)
1993 *d++ = (char)UTF_TO_NATIVE(0xff);
1994 if (uvmax > 0x100)
1995 d = (char*)uvchr_to_utf8((U8*)d, uvmax);
1996 }
1997#endif
02aa26ce
NT
1998
1999 /* mark the range as done, and continue */
79072805 2000 dorange = FALSE;
01ec43d0 2001 didrange = TRUE;
4c3a8340
TS
2002#ifdef EBCDIC
2003 literal_endpoint = 0;
2004#endif
79072805 2005 continue;
4e553d73 2006 }
02aa26ce
NT
2007
2008 /* range begins (ignore - as first or last char) */
79072805 2009 else if (*s == '-' && s+1 < send && s != start) {
4e553d73 2010 if (didrange) {
1fafa243 2011 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
01ec43d0 2012 }
e294cc5d
JH
2013 if (has_utf8
2014#ifdef EBCDIC
2015 && !native_range
2016#endif
2017 ) {
25716404 2018 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
a0ed51b3
LW
2019 s++;
2020 continue;
2021 }
79072805
LW
2022 dorange = TRUE;
2023 s++;
01ec43d0
GS
2024 }
2025 else {
2026 didrange = FALSE;
4c3a8340
TS
2027#ifdef EBCDIC
2028 literal_endpoint = 0;
e294cc5d 2029 native_range = TRUE;
4c3a8340 2030#endif
01ec43d0 2031 }
79072805 2032 }
02aa26ce
NT
2033
2034 /* if we get here, we're not doing a transliteration */
2035
0f5d15d6
IZ
2036 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
2037 except for the last char, which will be done separately. */
3280af22 2038 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
cc6b7395 2039 if (s[2] == '#') {
e994fd66 2040 while (s+1 < send && *s != ')')
db42d148 2041 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
155aba94
GS
2042 }
2043 else if (s[2] == '{' /* This should match regcomp.c */
67edc0c9 2044 || (s[2] == '?' && s[3] == '{'))
155aba94 2045 {
cc6b7395 2046 I32 count = 1;
0f5d15d6 2047 char *regparse = s + (s[2] == '{' ? 3 : 4);
cc6b7395
IZ
2048 char c;
2049
d9f97599
GS
2050 while (count && (c = *regparse)) {
2051 if (c == '\\' && regparse[1])
2052 regparse++;
4e553d73 2053 else if (c == '{')
cc6b7395 2054 count++;
4e553d73 2055 else if (c == '}')
cc6b7395 2056 count--;
d9f97599 2057 regparse++;
cc6b7395 2058 }
e994fd66 2059 if (*regparse != ')')
5bdf89e7 2060 regparse--; /* Leave one char for continuation. */
0f5d15d6 2061 while (s < regparse)
db42d148 2062 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
cc6b7395 2063 }
748a9306 2064 }
02aa26ce
NT
2065
2066 /* likewise skip #-initiated comments in //x patterns */
3280af22
NIS
2067 else if (*s == '#' && PL_lex_inpat &&
2068 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
748a9306 2069 while (s+1 < send && *s != '\n')
db42d148 2070 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
748a9306 2071 }
02aa26ce 2072
5d1d4326 2073 /* check for embedded arrays
da6eedaa 2074 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
5d1d4326 2075 */
1749ea0d
TS
2076 else if (*s == '@' && s[1]) {
2077 if (isALNUM_lazy_if(s+1,UTF))
2078 break;
2079 if (strchr(":'{$", s[1]))
2080 break;
2081 if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
2082 break; /* in regexp, neither @+ nor @- are interpolated */
2083 }
02aa26ce
NT
2084
2085 /* check for embedded scalars. only stop if we're sure it's a
2086 variable.
2087 */
79072805 2088 else if (*s == '$') {
3280af22 2089 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
79072805 2090 break;
6002328a 2091 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
79072805
LW
2092 break; /* in regexp, $ might be tail anchor */
2093 }
02aa26ce 2094
2b9d42f0
NIS
2095 /* End of else if chain - OP_TRANS rejoin rest */
2096
02aa26ce 2097 /* backslashes */
79072805
LW
2098 if (*s == '\\' && s+1 < send) {
2099 s++;
02aa26ce 2100
02aa26ce 2101 /* deprecate \1 in strings and substitution replacements */
3280af22 2102 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
a0d0e21e 2103 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
79072805 2104 {
599cee73 2105 if (ckWARN(WARN_SYNTAX))
9014280d 2106 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
79072805
LW
2107 *--s = '$';
2108 break;
2109 }
02aa26ce
NT
2110
2111 /* string-change backslash escapes */
3280af22 2112 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
79072805
LW
2113 --s;
2114 break;
2115 }
cc74c5bd
TS
2116 /* skip any other backslash escapes in a pattern */
2117 else if (PL_lex_inpat) {
2118 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2119 goto default_action;
2120 }
02aa26ce
NT
2121
2122 /* if we get here, it's either a quoted -, or a digit */
79072805 2123 switch (*s) {
02aa26ce
NT
2124
2125 /* quoted - in transliterations */
79072805 2126 case '-':
3280af22 2127 if (PL_lex_inwhat == OP_TRANS) {
79072805
LW
2128 *d++ = *s++;
2129 continue;
2130 }
2131 /* FALL THROUGH */
2132 default:
11b8faa4 2133 {
86f97054 2134 if ((isALPHA(*s) || isDIGIT(*s)) &&
041457d9 2135 ckWARN(WARN_MISC))
9014280d 2136 Perl_warner(aTHX_ packWARN(WARN_MISC),
e294cc5d
JH
2137 "Unrecognized escape \\%c passed through",
2138 *s);
11b8faa4 2139 /* default action is to copy the quoted character */
f9a63242 2140 goto default_action;
11b8faa4 2141 }
02aa26ce
NT
2142
2143 /* \132 indicates an octal constant */
79072805
LW
2144 case '0': case '1': case '2': case '3':
2145 case '4': case '5': case '6': case '7':
ba210ebe 2146 {
53305cf1
NC
2147 I32 flags = 0;
2148 STRLEN len = 3;
2149 uv = grok_oct(s, &len, &flags, NULL);
ba210ebe
JH
2150 s += len;
2151 }
012bcf8d 2152 goto NUM_ESCAPE_INSERT;
02aa26ce
NT
2153
2154 /* \x24 indicates a hex constant */
79072805 2155 case 'x':
a0ed51b3
LW
2156 ++s;
2157 if (*s == '{') {
9d4ba2ae 2158 char* const e = strchr(s, '}');
a4c04bdc
NC
2159 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2160 PERL_SCAN_DISALLOW_PREFIX;
53305cf1 2161 STRLEN len;
355860ce 2162
53305cf1 2163 ++s;
adaeee49 2164 if (!e) {
a0ed51b3 2165 yyerror("Missing right brace on \\x{}");
355860ce 2166 continue;
ba210ebe 2167 }
53305cf1
NC
2168 len = e - s;
2169 uv = grok_hex(s, &len, &flags, NULL);
ba210ebe 2170 s = e + 1;
a0ed51b3
LW
2171 }
2172 else {
ba210ebe 2173 {
53305cf1 2174 STRLEN len = 2;
a4c04bdc 2175 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
53305cf1 2176 uv = grok_hex(s, &len, &flags, NULL);
ba210ebe
JH
2177 s += len;
2178 }
012bcf8d
GS
2179 }
2180
2181 NUM_ESCAPE_INSERT:
2182 /* Insert oct or hex escaped character.
301d3d20 2183 * There will always enough room in sv since such
db42d148 2184 * escapes will be longer than any UTF-8 sequence
301d3d20 2185 * they can end up as. */
ba7cea30 2186
c7f1f016
NIS
2187 /* We need to map to chars to ASCII before doing the tests
2188 to cover EBCDIC
2189 */
c4d5f83a 2190 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
9aa983d2 2191 if (!has_utf8 && uv > 255) {
301d3d20
JH
2192 /* Might need to recode whatever we have
2193 * accumulated so far if it contains any
2194 * hibit chars.
2195 *
2196 * (Can't we keep track of that and avoid
2197 * this rescan? --jhi)
012bcf8d 2198 */
c7f1f016 2199 int hicount = 0;
63cd0674
NIS
2200 U8 *c;
2201 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
c4d5f83a 2202 if (!NATIVE_IS_INVARIANT(*c)) {
012bcf8d 2203 hicount++;
db42d148 2204 }
012bcf8d 2205 }
63cd0674 2206 if (hicount) {
9d4ba2ae 2207 const STRLEN offset = d - SvPVX_const(sv);
db42d148
NIS
2208 U8 *src, *dst;
2209 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
2210 src = (U8 *)d - 1;
2211 dst = src+hicount;
2212 d += hicount;
cfd0369c 2213 while (src >= (const U8 *)SvPVX_const(sv)) {
c4d5f83a 2214 if (!NATIVE_IS_INVARIANT(*src)) {
9d4ba2ae 2215 const U8 ch = NATIVE_TO_ASCII(*src);
eb160463
GS
2216 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
2217 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
012bcf8d
GS
2218 }
2219 else {
63cd0674 2220 *dst-- = *src;
012bcf8d 2221 }
c7f1f016 2222 src--;
012bcf8d
GS
2223 }
2224 }
2225 }
2226
9aa983d2 2227 if (has_utf8 || uv > 255) {
9041c2e3 2228 d = (char*)uvchr_to_utf8((U8*)d, uv);
4e553d73 2229 has_utf8 = TRUE;
f9a63242
JH
2230 if (PL_lex_inwhat == OP_TRANS &&
2231 PL_sublex_info.sub_op) {
2232 PL_sublex_info.sub_op->op_private |=
2233 (PL_lex_repl ? OPpTRANS_FROM_UTF
2234 : OPpTRANS_TO_UTF);
f9a63242 2235 }
e294cc5d
JH
2236#ifdef EBCDIC
2237 if (uv > 255 && !dorange)
2238 native_range = FALSE;
2239#endif
012bcf8d 2240 }
a0ed51b3 2241 else {
012bcf8d 2242 *d++ = (char)uv;
a0ed51b3 2243 }
012bcf8d
GS
2244 }
2245 else {
c4d5f83a 2246 *d++ = (char) uv;
a0ed51b3 2247 }
79072805 2248 continue;
02aa26ce 2249
b239daa5 2250 /* \N{LATIN SMALL LETTER A} is a named character */
4a2d328f 2251 case 'N':
55eda711 2252 ++s;
423cee85
JH
2253 if (*s == '{') {
2254 char* e = strchr(s, '}');
155aba94 2255 SV *res;
423cee85 2256 STRLEN len;
cfd0369c 2257 const char *str;
fc8cd66c 2258 SV *type;
4e553d73 2259
423cee85 2260 if (!e) {
5777a3f7 2261 yyerror("Missing right brace on \\N{}");
423cee85
JH
2262 e = s - 1;
2263 goto cont_scan;
2264 }
dbc0d4f2
JH
2265 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2266 /* \N{U+...} */
2267 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2268 PERL_SCAN_DISALLOW_PREFIX;
2269 s += 3;
2270 len = e - s;
2271 uv = grok_hex(s, &len, &flags, NULL);
b57a0404
JH
2272 if ( e > s && len != (STRLEN)(e - s) ) {
2273 uv = 0xFFFD;
fc8cd66c 2274 }
dbc0d4f2
JH
2275 s = e + 1;
2276 goto NUM_ESCAPE_INSERT;
2277 }
55eda711 2278 res = newSVpvn(s + 1, e - s - 1);
fc8cd66c 2279 type = newSVpvn(s - 2,e - s + 3);
bd61b366 2280 res = new_constant( NULL, 0, "charnames",
fc8cd66c
YO
2281 res, NULL, SvPVX(type) );
2282 SvREFCNT_dec(type);
f9a63242
JH
2283 if (has_utf8)
2284 sv_utf8_upgrade(res);
cfd0369c 2285 str = SvPV_const(res,len);
1c47067b
JH
2286#ifdef EBCDIC_NEVER_MIND
2287 /* charnames uses pack U and that has been
2288 * recently changed to do the below uni->native
2289 * mapping, so this would be redundant (and wrong,
2290 * the code point would be doubly converted).
2291 * But leave this in just in case the pack U change
2292 * gets revoked, but the semantics is still
2293 * desireable for charnames. --jhi */
cddc7ef4 2294 {
cfd0369c 2295 UV uv = utf8_to_uvchr((const U8*)str, 0);
cddc7ef4
JH
2296
2297 if (uv < 0x100) {
89ebb4a3 2298 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
cddc7ef4
JH
2299
2300 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2301 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
cfd0369c 2302 str = SvPV_const(res, len);
cddc7ef4
JH
2303 }
2304 }
2305#endif
89491803 2306 if (!has_utf8 && SvUTF8(res)) {
9d4ba2ae 2307 const char * const ostart = SvPVX_const(sv);
f08d6ad9
GS
2308 SvCUR_set(sv, d - ostart);
2309 SvPOK_on(sv);
e4f3eed8 2310 *d = '\0';
f08d6ad9 2311 sv_utf8_upgrade(sv);
d2f449dd 2312 /* this just broke our allocation above... */
eb160463 2313 SvGROW(sv, (STRLEN)(send - start));
f08d6ad9 2314 d = SvPVX(sv) + SvCUR(sv);
89491803 2315 has_utf8 = TRUE;
f08d6ad9 2316 }
eb160463 2317 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
9d4ba2ae 2318 const char * const odest = SvPVX_const(sv);
423cee85 2319
8973db79 2320 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
423cee85
JH
2321 d = SvPVX(sv) + (d - odest);
2322 }
e294cc5d
JH
2323#ifdef EBCDIC
2324 if (!dorange)
2325 native_range = FALSE; /* \N{} is guessed to be Unicode */
2326#endif
423cee85
JH
2327 Copy(str, d, len, char);
2328 d += len;
2329 SvREFCNT_dec(res);
2330 cont_scan:
2331 s = e + 1;
2332 }
2333 else
5777a3f7 2334 yyerror("Missing braces on \\N{}");
423cee85
JH
2335 continue;
2336
02aa26ce 2337 /* \c is a control character */
79072805
LW
2338 case 'c':
2339 s++;
961ce445 2340 if (s < send) {
ba210ebe 2341 U8 c = *s++;
c7f1f016
NIS
2342#ifdef EBCDIC
2343 if (isLOWER(c))
2344 c = toUPPER(c);
2345#endif
db42d148 2346 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
ba210ebe 2347 }
961ce445
RGS
2348 else {
2349 yyerror("Missing control char name in \\c");
2350 }
79072805 2351 continue;
02aa26ce
NT
2352
2353 /* printf-style backslashes, formfeeds, newlines, etc */
79072805 2354 case 'b':
db42d148 2355 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
79072805
LW
2356 break;
2357 case 'n':
db42d148 2358 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
79072805
LW
2359 break;
2360 case 'r':
db42d148 2361 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
79072805
LW
2362 break;
2363 case 'f':
db42d148 2364 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
79072805
LW
2365 break;
2366 case 't':
db42d148 2367 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
79072805 2368 break;
34a3fe2a 2369 case 'e':
db42d148 2370 *d++ = ASCII_TO_NEED(has_utf8,'\033');
34a3fe2a
PP
2371 break;
2372 case 'a':
db42d148 2373 *d++ = ASCII_TO_NEED(has_utf8,'\007');
79072805 2374 break;
02aa26ce
NT
2375 } /* end switch */
2376
79072805
LW
2377 s++;
2378 continue;
02aa26ce 2379 } /* end if (backslash) */
4c3a8340
TS
2380#ifdef EBCDIC
2381 else
2382 literal_endpoint++;
2383#endif
02aa26ce 2384
f9a63242 2385 default_action:
2b9d42f0
NIS
2386 /* If we started with encoded form, or already know we want it
2387 and then encode the next character */
2388 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
2389 STRLEN len = 1;
5f66b61c
AL
2390 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2391 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2b9d42f0
NIS
2392 s += len;
2393 if (need > len) {
2394 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
9d4ba2ae 2395 const STRLEN off = d - SvPVX_const(sv);
2b9d42f0
NIS
2396 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
2397 }
5f66b61c 2398 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2b9d42f0 2399 has_utf8 = TRUE;
e294cc5d
JH
2400#ifdef EBCDIC
2401 if (uv > 255 && !dorange)
2402 native_range = FALSE;
2403#endif
2b9d42f0
NIS
2404 }
2405 else {
2406 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2407 }
02aa26ce
NT
2408 } /* while loop to process each character */
2409
2410 /* terminate the string and set up the sv */
79072805 2411 *d = '\0';
95a20fc0 2412 SvCUR_set(sv, d - SvPVX_const(sv));
2b9d42f0 2413 if (SvCUR(sv) >= SvLEN(sv))
d0063567 2414 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2b9d42f0 2415
79072805 2416 SvPOK_on(sv);
9f4817db 2417 if (PL_encoding && !has_utf8) {
d0063567
DK
2418 sv_recode_to_utf8(sv, PL_encoding);
2419 if (SvUTF8(sv))
2420 has_utf8 = TRUE;
9f4817db 2421 }
2b9d42f0 2422 if (has_utf8) {
7e2040f0 2423 SvUTF8_on(sv);
2b9d42f0 2424 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
d0063567 2425 PL_sublex_info.sub_op->op_private |=
2b9d42f0
NIS
2426 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2427 }
2428 }
79072805 2429
02aa26ce 2430 /* shrink the sv if we allocated more than we used */
79072805 2431 if (SvCUR(sv) + 5 < SvLEN(sv)) {
1da4ca5f 2432 SvPV_shrink_to_cur(sv);
79072805 2433 }
02aa26ce 2434
9b599b2a 2435 /* return the substring (via yylval) only if we parsed anything */
3280af22
NIS
2436 if (s > PL_bufptr) {
2437 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
10edeb5d
JH
2438 sv = new_constant(start, s - start,
2439 (const char *)(PL_lex_inpat ? "qr" : "q"),
a0714e2c 2440 sv, NULL,
10edeb5d
JH
2441 (const char *)
2442 (( PL_lex_inwhat == OP_TRANS
2443 ? "tr"
2444 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
2445 ? "s"
2446 : "qq"))));
79072805 2447 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
b3ac6de7 2448 } else
8990e307 2449 SvREFCNT_dec(sv);
79072805
LW
2450 return s;
2451}
2452
ffb4593c
NT
2453/* S_intuit_more
2454 * Returns TRUE if there's more to the expression (e.g., a subscript),
2455 * FALSE otherwise.
ffb4593c
NT
2456 *
2457 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2458 *
2459 * ->[ and ->{ return TRUE
2460 * { and [ outside a pattern are always subscripts, so return TRUE
2461 * if we're outside a pattern and it's not { or [, then return FALSE
2462 * if we're in a pattern and the first char is a {
2463 * {4,5} (any digits around the comma) returns FALSE
2464 * if we're in a pattern and the first char is a [
2465 * [] returns FALSE
2466 * [SOMETHING] has a funky algorithm to decide whether it's a
2467 * character class or not. It has to deal with things like
2468 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2469 * anything else returns TRUE
2470 */
2471
9cbb5ea2
GS
2472/* This is the one truly awful dwimmer necessary to conflate C and sed. */
2473
76e3520e 2474STATIC int
cea2e8a9 2475S_intuit_more(pTHX_ register char *s)
79072805 2476{
97aff369 2477 dVAR;
3280af22 2478 if (PL_lex_brackets)
79072805
LW
2479 return TRUE;
2480 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2481 return TRUE;
2482 if (*s != '{' && *s != '[')
2483 return FALSE;
3280af22 2484 if (!PL_lex_inpat)
79072805
LW
2485 return TRUE;
2486
2487 /* In a pattern, so maybe we have {n,m}. */
2488 if (*s == '{') {
2489 s++;
2490 if (!isDIGIT(*s))
2491 return TRUE;
2492 while (isDIGIT(*s))
2493 s++;
2494 if (*s == ',')
2495 s++;
2496 while (isDIGIT(*s))
2497 s++;
2498 if (*s == '}')
2499 return FALSE;
2500 return TRUE;
2501
2502 }
2503
2504 /* On the other hand, maybe we have a character class */
2505
2506 s++;
2507 if (*s == ']' || *s == '^')
2508 return FALSE;
2509 else {
ffb4593c 2510 /* this is terrifying, and it works */
79072805
LW
2511 int weight = 2; /* let's weigh the evidence */
2512 char seen[256];
f27ffc4a 2513 unsigned char un_char = 255, last_un_char;
9d4ba2ae 2514 const char * const send = strchr(s,']');
3280af22 2515 char tmpbuf[sizeof PL_tokenbuf * 4];
79072805
LW
2516
2517 if (!send) /* has to be an expression */
2518 return TRUE;
2519
2520 Zero(seen,256,char);
2521 if (*s == '$')
2522 weight -= 3;
2523 else if (isDIGIT(*s)) {
2524 if (s[1] != ']') {
2525 if (isDIGIT(s[1]) && s[2] == ']')
2526 weight -= 10;
2527 }
2528 else
2529 weight -= 100;
2530 }
2531 for (; s < send; s++) {
2532 last_un_char = un_char;
2533 un_char = (unsigned char)*s;
2534 switch (*s) {
2535 case '@':
2536 case '&':
2537 case '$':
2538 weight -= seen[un_char] * 10;
7e2040f0 2539 if (isALNUM_lazy_if(s+1,UTF)) {
90e5519e 2540 int len;
8903cb82 2541 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
90e5519e
NC
2542 len = (int)strlen(tmpbuf);
2543 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
79072805
LW
2544 weight -= 100;
2545 else
2546 weight -= 10;
2547 }
2548 else if (*s == '$' && s[1] &&
93a17b20
LW
2549 strchr("[#!%*<>()-=",s[1])) {
2550 if (/*{*/ strchr("])} =",s[2]))
79072805
LW
2551 weight -= 10;
2552 else
2553 weight -= 1;
2554 }
2555 break;
2556 case '\\':
2557 un_char = 254;
2558 if (s[1]) {
93a17b20 2559 if (strchr("wds]",s[1]))
79072805 2560 weight += 100;
10edeb5d 2561 else if (seen[(U8)'\''] || seen[(U8)'"'])
79072805 2562 weight += 1;
93a17b20 2563 else if (strchr("rnftbxcav",s[1]))
79072805
LW
2564 weight += 40;
2565 else if (isDIGIT(s[1])) {
2566 weight += 40;
2567 while (s[1] && isDIGIT(s[1]))
2568 s++;
2569 }
2570 }
2571 else
2572 weight += 100;
2573 break;
2574 case '-':
2575 if (s[1] == '\\')
2576 weight += 50;
93a17b20 2577 if (strchr("aA01! ",last_un_char))
79072805 2578 weight += 30;
93a17b20 2579 if (strchr("zZ79~",s[1]))
79072805 2580 weight += 30;
f27ffc4a
GS
2581 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2582 weight -= 5; /* cope with negative subscript */
79072805
LW
2583 break;
2584 default:
3792a11b
NC
2585 if (!isALNUM(last_un_char)
2586 && !(last_un_char == '$' || last_un_char == '@'
2587 || last_un_char == '&')
2588 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
79072805
LW
2589 char *d = tmpbuf;
2590 while (isALPHA(*s))
2591 *d++ = *s++;
2592 *d = '\0';
5458a98a 2593 if (keyword(tmpbuf, d - tmpbuf, 0))
79072805
LW
2594 weight -= 150;
2595 }
2596 if (un_char == last_un_char + 1)
2597 weight += 5;
2598 weight -= seen[un_char];
2599 break;
2600 }
2601 seen[un_char]++;
2602 }
2603 if (weight >= 0) /* probably a character class */
2604 return FALSE;
2605 }
2606
2607 return TRUE;
2608}
ffed7fef 2609
ffb4593c
NT
2610/*
2611 * S_intuit_method
2612 *
2613 * Does all the checking to disambiguate
2614 * foo bar
2615 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2616 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2617 *
2618 * First argument is the stuff after the first token, e.g. "bar".
2619 *
2620 * Not a method if bar is a filehandle.
2621 * Not a method if foo is a subroutine prototyped to take a filehandle.
2622 * Not a method if it's really "Foo $bar"
2623 * Method if it's "foo $bar"
2624 * Not a method if it's really "print foo $bar"
2625 * Method if it's really "foo package::" (interpreted as package->foo)
8f8cf39c 2626 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
3cb0bbe5 2627 * Not a method if bar is a filehandle or package, but is quoted with
ffb4593c
NT
2628 * =>
2629 */
2630
76e3520e 2631STATIC int
62d55b22 2632S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
a0d0e21e 2633{
97aff369 2634 dVAR;
a0d0e21e 2635 char *s = start + (*start == '$');
3280af22 2636 char tmpbuf[sizeof PL_tokenbuf];
a0d0e21e
LW
2637 STRLEN len;
2638 GV* indirgv;
5db06880
NC
2639#ifdef PERL_MAD
2640 int soff;
2641#endif
a0d0e21e
LW
2642
2643 if (gv) {
62d55b22 2644 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
a0d0e21e 2645 return 0;
62d55b22
NC
2646 if (cv) {
2647 if (SvPOK(cv)) {
2648 const char *proto = SvPVX_const(cv);
2649 if (proto) {
2650 if (*proto == ';')
2651 proto++;
2652 if (*proto == '*')
2653 return 0;
2654 }
b6c543e3
IZ
2655 }
2656 } else
c35e046a 2657 gv = NULL;
a0d0e21e 2658 }
8903cb82 2659 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
ffb4593c
NT
2660 /* start is the beginning of the possible filehandle/object,
2661 * and s is the end of it
2662 * tmpbuf is a copy of it
2663 */
2664
a0d0e21e 2665 if (*start == '$') {
3ef1310e
RGS
2666 if (gv || PL_last_lop_op == OP_PRINT || PL_last_lop_op == OP_SAY ||
2667 isUPPER(*PL_tokenbuf))
a0d0e21e 2668 return 0;
5db06880
NC
2669#ifdef PERL_MAD
2670 len = start - SvPVX(PL_linestr);
2671#endif
29595ff2 2672 s = PEEKSPACE(s);
f0092767 2673#ifdef PERL_MAD
5db06880
NC
2674 start = SvPVX(PL_linestr) + len;
2675#endif
3280af22
NIS
2676 PL_bufptr = start;
2677 PL_expect = XREF;
a0d0e21e
LW
2678 return *s == '(' ? FUNCMETH : METHOD;
2679 }
5458a98a 2680 if (!keyword(tmpbuf, len, 0)) {
c3e0f903
GS
2681 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2682 len -= 2;
2683 tmpbuf[len] = '\0';
5db06880
NC
2684#ifdef PERL_MAD
2685 soff = s - SvPVX(PL_linestr);
2686#endif
c3e0f903
GS
2687 goto bare_package;
2688 }
90e5519e 2689 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
8ebc5c01 2690 if (indirgv && GvCVu(indirgv))
a0d0e21e
LW
2691 return 0;
2692 /* filehandle or package name makes it a method */
da51bb9b 2693 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, 0)) {
5db06880
NC
2694#ifdef PERL_MAD
2695 soff = s - SvPVX(PL_linestr);
2696#endif
29595ff2 2697 s = PEEKSPACE(s);
3280af22 2698 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
55497cff 2699 return 0; /* no assumptions -- "=>" quotes bearword */
c3e0f903 2700 bare_package:
cd81e915 2701 start_force(PL_curforce);
9ded7720 2702 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
79cb57f6 2703 newSVpvn(tmpbuf,len));
9ded7720 2704 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
5db06880
NC
2705 if (PL_madskills)
2706 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
3280af22 2707 PL_expect = XTERM;
a0d0e21e 2708 force_next(WORD);
3280af22 2709 PL_bufptr = s;
5db06880
NC
2710#ifdef PERL_MAD
2711 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2712#endif
a0d0e21e
LW
2713 return *s == '(' ? FUNCMETH : METHOD;
2714 }
2715 }
2716 return 0;
2717}
2718
ffb4593c
NT
2719/*
2720 * S_incl_perldb
2721 * Return a string of Perl code to load the debugger. If PERL5DB
2722 * is set, it will return the contents of that, otherwise a
2723 * compile-time require of perl5db.pl.
2724 */
2725
bfed75c6 2726STATIC const char*
cea2e8a9 2727S_incl_perldb(pTHX)
a0d0e21e 2728{
97aff369 2729 dVAR;
3280af22 2730 if (PL_perldb) {
9d4ba2ae 2731 const char * const pdb = PerlEnv_getenv("PERL5DB");
a0d0e21e
LW
2732
2733 if (pdb)
2734 return pdb;
93189314 2735 SETERRNO(0,SS_NORMAL);
a0d0e21e
LW
2736 return "BEGIN { require 'perl5db.pl' }";
2737 }
2738 return "";
2739}
2740
2741
16d20bd9 2742/* Encoded script support. filter_add() effectively inserts a
4e553d73 2743 * 'pre-processing' function into the current source input stream.
16d20bd9
AD
2744 * Note that the filter function only applies to the current source file
2745 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2746 *
2747 * The datasv parameter (which may be NULL) can be used to pass
2748 * private data to this instance of the filter. The filter function
2749 * can recover the SV using the FILTER_DATA macro and use it to
2750 * store private buffers and state information.
2751 *
2752 * The supplied datasv parameter is upgraded to a PVIO type
4755096e 2753 * and the IoDIRP/IoANY field is used to store the function pointer,
e0c19803 2754 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
16d20bd9
AD
2755 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2756 * private use must be set using malloc'd pointers.
2757 */
16d20bd9
AD
2758
2759SV *
864dbfa3 2760Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
16d20bd9 2761{
97aff369 2762 dVAR;
f4c556ac 2763 if (!funcp)
a0714e2c 2764 return NULL;
f4c556ac 2765
3280af22
NIS
2766 if (!PL_rsfp_filters)
2767 PL_rsfp_filters = newAV();
16d20bd9 2768 if (!datasv)
561b68a9 2769 datasv = newSV(0);
862a34c6 2770 SvUPGRADE(datasv, SVt_PVIO);
8141890a 2771 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
e0c19803 2772 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
f4c556ac 2773 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
55662e27
JH
2774 FPTR2DPTR(void *, IoANY(datasv)),
2775 SvPV_nolen(datasv)));
3280af22
NIS
2776 av_unshift(PL_rsfp_filters, 1);
2777 av_store(PL_rsfp_filters, 0, datasv) ;
16d20bd9
AD
2778 return(datasv);
2779}
4e553d73 2780
16d20bd9
AD
2781
2782/* Delete most recently added instance of this filter function. */
a0d0e21e 2783void
864dbfa3 2784Perl_filter_del(pTHX_ filter_t funcp)
16d20bd9 2785{
97aff369 2786 dVAR;
e0c19803 2787 SV *datasv;
24801a4b 2788
33073adb 2789#ifdef DEBUGGING
55662e27
JH
2790 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2791 FPTR2DPTR(void*, funcp)));
33073adb 2792#endif
3280af22 2793 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
16d20bd9
AD
2794 return;
2795 /* if filter is on top of stack (usual case) just pop it off */
e0c19803 2796 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
8141890a 2797 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
e0c19803 2798 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
4755096e 2799 IoANY(datasv) = (void *)NULL;
3280af22 2800 sv_free(av_pop(PL_rsfp_filters));
e50aee73 2801
16d20bd9
AD
2802 return;
2803 }
2804 /* we need to search for the correct entry and clear it */
cea2e8a9 2805 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
16d20bd9
AD
2806}
2807
2808
1de9afcd
RGS
2809/* Invoke the idxth filter function for the current rsfp. */
2810/* maxlen 0 = read one text line */
16d20bd9 2811I32
864dbfa3 2812Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
a0d0e21e 2813{
97aff369 2814 dVAR;
16d20bd9
AD
2815 filter_t funcp;
2816 SV *datasv = NULL;
f482118e
NC
2817 /* This API is bad. It should have been using unsigned int for maxlen.
2818 Not sure if we want to change the API, but if not we should sanity
2819 check the value here. */
39cd7a59
NC
2820 const unsigned int correct_length
2821 = maxlen < 0 ?
2822#ifdef PERL_MICRO
2823 0x7FFFFFFF
2824#else
2825 INT_MAX
2826#endif
2827 : maxlen;
e50aee73 2828
3280af22 2829 if (!PL_rsfp_filters)
16d20bd9 2830 return -1;
1de9afcd 2831 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
16d20bd9
AD
2832 /* Provide a default input filter to make life easy. */
2833 /* Note that we append to the line. This is handy. */
f4c556ac
GS
2834 DEBUG_P(PerlIO_printf(Perl_debug_log,
2835 "filter_read %d: from rsfp\n", idx));
f482118e 2836 if (correct_length) {
16d20bd9
AD
2837 /* Want a block */
2838 int len ;
f54cb97a 2839 const int old_len = SvCUR(buf_sv);
16d20bd9
AD
2840
2841 /* ensure buf_sv is large enough */
f482118e
NC
2842 SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2843 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2844 correct_length)) <= 0) {
3280af22 2845 if (PerlIO_error(PL_rsfp))
37120919
AD
2846 return -1; /* error */
2847 else
2848 return 0 ; /* end of file */
2849 }
16d20bd9
AD
2850 SvCUR_set(buf_sv, old_len + len) ;
2851 } else {
2852 /* Want a line */
3280af22
NIS
2853 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2854 if (PerlIO_error(PL_rsfp))
37120919
AD
2855 return -1; /* error */
2856 else
2857 return 0 ; /* end of file */
2858 }
16d20bd9
AD
2859 }
2860 return SvCUR(buf_sv);
2861 }
2862 /* Skip this filter slot if filter has been deleted */
1de9afcd 2863 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
f4c556ac
GS
2864 DEBUG_P(PerlIO_printf(Perl_debug_log,
2865 "filter_read %d: skipped (filter deleted)\n",
2866 idx));
f482118e 2867 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
16d20bd9
AD
2868 }
2869 /* Get function pointer hidden within datasv */
8141890a 2870 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
f4c556ac
GS
2871 DEBUG_P(PerlIO_printf(Perl_debug_log,
2872 "filter_read %d: via function %p (%s)\n",
ca0270c4 2873 idx, (void*)datasv, SvPV_nolen_const(datasv)));
16d20bd9
AD
2874 /* Call function. The function is expected to */
2875 /* call "FILTER_READ(idx+1, buf_sv)" first. */
37120919 2876 /* Return: <0:error, =0:eof, >0:not eof */
f482118e 2877 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
16d20bd9
AD
2878}
2879
76e3520e 2880STATIC char *
cea2e8a9 2881S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
16d20bd9 2882{
97aff369 2883 dVAR;
c39cd008 2884#ifdef PERL_CR_FILTER
3280af22 2885 if (!PL_rsfp_filters) {
c39cd008 2886 filter_add(S_cr_textfilter,NULL);
a868473f
NIS
2887 }
2888#endif
3280af22 2889 if (PL_rsfp_filters) {
55497cff 2890 if (!append)
2891 SvCUR_set(sv, 0); /* start with empty line */
16d20bd9
AD
2892 if (FILTER_READ(0, sv, 0) > 0)
2893 return ( SvPVX(sv) ) ;
2894 else
bd61b366 2895 return NULL ;
16d20bd9 2896 }
9d116dd7 2897 else
fd049845 2898 return (sv_gets(sv, fp, append));
a0d0e21e
LW
2899}
2900
01ec43d0 2901STATIC HV *
7fc63493 2902S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
def3634b 2903{
97aff369 2904 dVAR;
def3634b
GS
2905 GV *gv;
2906
01ec43d0 2907 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
def3634b
GS
2908 return PL_curstash;
2909
2910 if (len > 2 &&
2911 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
90e5519e 2912 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
01ec43d0
GS
2913 {
2914 return GvHV(gv); /* Foo:: */
def3634b
GS
2915 }
2916
2917 /* use constant CLASS => 'MyClass' */
c35e046a
AL
2918 gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
2919 if (gv && GvCV(gv)) {
2920 SV * const sv = cv_const_sv(GvCV(gv));
2921 if (sv)
83003860 2922 pkgname = SvPV_nolen_const(sv);
def3634b
GS
2923 }
2924
da51bb9b 2925 return gv_stashpv(pkgname, 0);
def3634b 2926}
a0d0e21e 2927
e3f73d4e
RGS
2928/*
2929 * S_readpipe_override
2930 * Check whether readpipe() is overriden, and generates the appropriate
2931 * optree, provided sublex_start() is called afterwards.
2932 */
2933STATIC void
1d51329b 2934S_readpipe_override(pTHX)
e3f73d4e
RGS
2935{
2936 GV **gvp;
2937 GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
2938 yylval.ival = OP_BACKTICK;
2939 if ((gv_readpipe
2940 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
2941 ||
2942 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
d5e716f5 2943 && (gv_readpipe = *gvp) && isGV_with_GP(gv_readpipe)
e3f73d4e
RGS
2944 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
2945 {
2946 PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
2947 append_elem(OP_LIST,
2948 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
2949 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
2950 }
2951 else {
2952 set_csh();
2953 }
2954}
2955
5db06880
NC
2956#ifdef PERL_MAD
2957 /*
2958 * Perl_madlex
2959 * The intent of this yylex wrapper is to minimize the changes to the
2960 * tokener when we aren't interested in collecting madprops. It remains
2961 * to be seen how successful this strategy will be...
2962 */
2963
2964int
2965Perl_madlex(pTHX)
2966{
2967 int optype;
2968 char *s = PL_bufptr;
2969
cd81e915
NC
2970 /* make sure PL_thiswhite is initialized */
2971 PL_thiswhite = 0;
2972 PL_thismad = 0;
5db06880 2973
cd81e915 2974 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
5db06880
NC
2975 if (PL_pending_ident)
2976 return S_pending_ident(aTHX);
2977
2978 /* previous token ate up our whitespace? */
cd81e915
NC
2979 if (!PL_lasttoke && PL_nextwhite) {
2980 PL_thiswhite = PL_nextwhite;
2981 PL_nextwhite = 0;
5db06880
NC
2982 }
2983
2984 /* isolate the token, and figure out where it is without whitespace */
cd81e915
NC
2985 PL_realtokenstart = -1;
2986 PL_thistoken = 0;
5db06880
NC
2987 optype = yylex();
2988 s = PL_bufptr;
cd81e915 2989 assert(PL_curforce < 0);
5db06880 2990
cd81e915
NC
2991 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
2992 if (!PL_thistoken) {
2993 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
6b29d1f5 2994 PL_thistoken = newSVpvs("");
5db06880 2995 else {
c35e046a 2996 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
cd81e915 2997 PL_thistoken = newSVpvn(tstart, s - tstart);
5db06880
NC
2998 }
2999 }
cd81e915
NC
3000 if (PL_thismad) /* install head */
3001 CURMAD('X', PL_thistoken);
5db06880
NC
3002 }
3003
3004 /* last whitespace of a sublex? */
cd81e915
NC
3005 if (optype == ')' && PL_endwhite) {
3006 CURMAD('X', PL_endwhite);
5db06880
NC
3007 }
3008
cd81e915 3009 if (!PL_thismad) {
5db06880
NC
3010
3011 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
cd81e915
NC
3012 if (!PL_thiswhite && !PL_endwhite && !optype) {
3013 sv_free(PL_thistoken);
3014 PL_thistoken = 0;
5db06880
NC
3015 return 0;
3016 }
3017
3018 /* put off final whitespace till peg */
3019 if (optype == ';' && !PL_rsfp) {
cd81e915
NC
3020 PL_nextwhite = PL_thiswhite;
3021 PL_thiswhite = 0;
5db06880 3022 }
cd81e915
NC
3023 else if (PL_thisopen) {
3024 CURMAD('q', PL_thisopen);
3025 if (PL_thistoken)
3026 sv_free(PL_thistoken);
3027 PL_thistoken = 0;
5db06880
NC
3028 }
3029 else {
3030 /* Store actual token text as madprop X */
cd81e915 3031 CURMAD('X', PL_thistoken);
5db06880
NC
3032 }
3033
cd81e915 3034 if (PL_thiswhite) {
5db06880 3035 /* add preceding whitespace as madprop _ */
cd81e915 3036 CURMAD('_', PL_thiswhite);
5db06880
NC
3037 }
3038
cd81e915 3039 if (PL_thisstuff) {
5db06880 3040 /* add quoted material as madprop = */
cd81e915 3041 CURMAD('=', PL_thisstuff);
5db06880
NC
3042 }
3043
cd81e915 3044 if (PL_thisclose) {
5db06880 3045 /* add terminating quote as madprop Q */
cd81e915 3046 CURMAD('Q', PL_thisclose);
5db06880
NC
3047 }
3048 }
3049
3050 /* special processing based on optype */
3051
3052 switch (optype) {
3053
3054 /* opval doesn't need a TOKEN since it can already store mp */
3055 case WORD:
3056 case METHOD:
3057 case FUNCMETH:
3058 case THING:
3059 case PMFUNC:
3060 case PRIVATEREF:
3061 case FUNC0SUB:
3062 case UNIOPSUB:
3063 case LSTOPSUB:
3064 if (yylval.opval)
cd81e915
NC
3065 append_madprops(PL_thismad, yylval.opval, 0);
3066 PL_thismad = 0;
5db06880
NC
3067 return optype;
3068
3069 /* fake EOF */
3070 case 0:
3071 optype = PEG;
cd81e915
NC
3072 if (PL_endwhite) {
3073 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
3074 PL_endwhite = 0;
5db06880
NC
3075 }
3076 break;
3077
3078 case ']':
3079 case '}':
cd81e915 3080 if (PL_faketokens)
5db06880
NC
3081 break;
3082 /* remember any fake bracket that lexer is about to discard */
3083 if (PL_lex_brackets == 1 &&
3084 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
3085 {
3086 s = PL_bufptr;
3087 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3088 s++;
3089 if (*s == '}') {
cd81e915
NC
3090 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
3091 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3092 PL_thiswhite = 0;
5db06880
NC
3093 PL_bufptr = s - 1;
3094 break; /* don't bother looking for trailing comment */
3095 }
3096 else
3097 s = PL_bufptr;
3098 }
3099 if (optype == ']')
3100 break;
3101 /* FALLTHROUGH */
3102
3103 /* attach a trailing comment to its statement instead of next token */
3104 case ';':
cd81e915 3105 if (PL_faketokens)
5db06880
NC
3106 break;
3107 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
3108 s = PL_bufptr;
3109 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3110 s++;
3111 if (*s == '\n' || *s == '#') {
3112 while (s < PL_bufend && *s != '\n')
3113 s++;
3114 if (s < PL_bufend)
3115 s++;
cd81e915
NC
3116 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
3117 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3118 PL_thiswhite = 0;
5db06880
NC
3119 PL_bufptr = s;
3120 }
3121 }
3122 break;
3123
3124 /* pval */
3125 case LABEL:
3126 break;
3127
3128 /* ival */
3129 default:
3130 break;
3131
3132 }
3133
3134 /* Create new token struct. Note: opvals return early above. */
cd81e915
NC
3135 yylval.tkval = newTOKEN(optype, yylval, PL_thismad);
3136 PL_thismad = 0;
5db06880
NC
3137 return optype;
3138}
3139#endif
3140
468aa647 3141STATIC char *
cc6ed77d 3142S_tokenize_use(pTHX_ int is_use, char *s) {
97aff369 3143 dVAR;
468aa647
RGS
3144 if (PL_expect != XSTATE)
3145 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
3146 is_use ? "use" : "no"));
29595ff2 3147 s = SKIPSPACE1(s);
468aa647
RGS
3148 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
3149 s = force_version(s, TRUE);
29595ff2 3150 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
cd81e915 3151 start_force(PL_curforce);
9ded7720 3152 NEXTVAL_NEXTTOKE.opval = NULL;
468aa647
RGS
3153 force_next(WORD);
3154 }
3155 else if (*s == 'v') {
3156 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3157 s = force_version(s, FALSE);
3158 }
3159 }
3160 else {
3161 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3162 s = force_version(s, FALSE);
3163 }
3164 yylval.ival = is_use;
3165 return s;
3166}
748a9306 3167#ifdef DEBUGGING
27da23d5 3168 static const char* const exp_name[] =
09bef843 3169 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
27308ded 3170 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
09bef843 3171 };
748a9306 3172#endif
463ee0b2 3173
02aa26ce
NT
3174/*
3175 yylex
3176
3177 Works out what to call the token just pulled out of the input
3178 stream. The yacc parser takes care of taking the ops we return and
3179 stitching them into a tree.
3180
3181 Returns:
3182 PRIVATEREF
3183
3184 Structure:
3185 if read an identifier
3186 if we're in a my declaration
3187 croak if they tried to say my($foo::bar)
3188 build the ops for a my() declaration
3189 if it's an access to a my() variable
3190 are we in a sort block?
3191 croak if my($a); $a <=> $b
3192 build ops for access to a my() variable
3193 if in a dq string, and they've said @foo and we can't find @foo
3194 croak
3195 build ops for a bareword
3196 if we already built the token before, use it.
3197*/
3198
20141f0e 3199
dba4d153
JH
3200#ifdef __SC__
3201#pragma segment Perl_yylex
3202#endif
dba4d153 3203int
dba4d153 3204Perl_yylex(pTHX)
20141f0e 3205{
97aff369 3206 dVAR;
3afc138a 3207 register char *s = PL_bufptr;
378cc40b 3208 register char *d;
463ee0b2 3209 STRLEN len;
aa7440fb 3210 bool bof = FALSE;
a687059c 3211
10edeb5d
JH
3212 /* orig_keyword, gvp, and gv are initialized here because
3213 * jump to the label just_a_word_zero can bypass their
3214 * initialization later. */
3215 I32 orig_keyword = 0;
3216 GV *gv = NULL;
3217 GV **gvp = NULL;
3218
bbf60fe6 3219 DEBUG_T( {
396482e1 3220 SV* tmp = newSVpvs("");
b6007c36
DM
3221 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3222 (IV)CopLINE(PL_curcop),
3223 lex_state_names[PL_lex_state],
3224 exp_name[PL_expect],
3225 pv_display(tmp, s, strlen(s), 0, 60));
3226 SvREFCNT_dec(tmp);
bbf60fe6 3227 } );
02aa26ce 3228 /* check if there's an identifier for us to look at */
ba979b31 3229 if (PL_pending_ident)
bbf60fe6 3230 return REPORT(S_pending_ident(aTHX));
bbce6d69 3231
02aa26ce
NT
3232 /* no identifier pending identification */
3233
3280af22 3234 switch (PL_lex_state) {
79072805
LW
3235#ifdef COMMENTARY
3236 case LEX_NORMAL: /* Some compilers will produce faster */
3237 case LEX_INTERPNORMAL: /* code if we comment these out. */
3238 break;
3239#endif
3240
09bef843 3241 /* when we've already built the next token, just pull it out of the queue */
79072805 3242 case LEX_KNOWNEXT:
5db06880
NC
3243#ifdef PERL_MAD
3244 PL_lasttoke--;
3245 yylval = PL_nexttoke[PL_lasttoke].next_val;
3246 if (PL_madskills) {
cd81e915 3247 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
5db06880 3248 PL_nexttoke[PL_lasttoke].next_mad = 0;
cd81e915
NC
3249 if (PL_thismad && PL_thismad->mad_key == '_') {
3250 PL_thiswhite = (SV*)PL_thismad->mad_val;
3251 PL_thismad->mad_val = 0;
3252 mad_free(PL_thismad);
3253 PL_thismad = 0;
5db06880
NC
3254 }
3255 }
3256 if (!PL_lasttoke) {
3257 PL_lex_state = PL_lex_defer;
3258 PL_expect = PL_lex_expect;
3259 PL_lex_defer = LEX_NORMAL;
3260 if (!PL_nexttoke[PL_lasttoke].next_type)
3261 return yylex();
3262 }
3263#else
3280af22 3264 PL_nexttoke--;
5db06880 3265 yylval = PL_nextval[PL_nexttoke];
3280af22
NIS
3266 if (!PL_nexttoke) {
3267 PL_lex_state = PL_lex_defer;
3268 PL_expect = PL_lex_expect;
3269 PL_lex_defer = LEX_NORMAL;
463ee0b2 3270 }
5db06880
NC
3271#endif
3272#ifdef PERL_MAD
3273 /* FIXME - can these be merged? */
3274 return(PL_nexttoke[PL_lasttoke].next_type);
3275#else
bbf60fe6 3276 return REPORT(PL_nexttype[PL_nexttoke]);
5db06880 3277#endif
79072805 3278
02aa26ce 3279 /* interpolated case modifiers like \L \U, including \Q and \E.
3280af22 3280 when we get here, PL_bufptr is at the \
02aa26ce 3281 */
79072805
LW
3282 case LEX_INTERPCASEMOD:
3283#ifdef DEBUGGING
3280af22 3284 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
cea2e8a9 3285 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
79072805 3286#endif
02aa26ce 3287 /* handle \E or end of string */
3280af22 3288 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
02aa26ce 3289 /* if at a \E */
3280af22 3290 if (PL_lex_casemods) {
f54cb97a 3291 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3280af22 3292 PL_lex_casestack[PL_lex_casemods] = '\0';
02aa26ce 3293
3792a11b
NC
3294 if (PL_bufptr != PL_bufend
3295 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3280af22
NIS
3296 PL_bufptr += 2;
3297 PL_lex_state = LEX_INTERPCONCAT;
5db06880
NC
3298#ifdef PERL_MAD
3299 if (PL_madskills)
6b29d1f5 3300 PL_thistoken = newSVpvs("\\E");
5db06880 3301#endif
a0d0e21e 3302 }
bbf60fe6 3303 return REPORT(')');
79072805 3304 }
5db06880
NC
3305#ifdef PERL_MAD
3306 while (PL_bufptr != PL_bufend &&
3307 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
cd81e915 3308 if (!PL_thiswhite)
6b29d1f5 3309 PL_thiswhite = newSVpvs("");
cd81e915 3310 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
5db06880
NC
3311 PL_bufptr += 2;
3312 }
3313#else
3280af22
NIS
3314 if (PL_bufptr != PL_bufend)
3315 PL_bufptr += 2;
5db06880 3316#endif
3280af22 3317 PL_lex_state = LEX_INTERPCONCAT;
cea2e8a9 3318 return yylex();
79072805
LW
3319 }
3320 else {
607df283 3321 DEBUG_T({ PerlIO_printf(Perl_debug_log,
b6007c36 3322 "### Saw case modifier\n"); });
3280af22 3323 s = PL_bufptr + 1;
6e909404 3324 if (s[1] == '\\' && s[2] == 'E') {
5db06880 3325#ifdef PERL_MAD
cd81e915 3326 if (!PL_thiswhite)
6b29d1f5 3327 PL_thiswhite = newSVpvs("");
cd81e915 3328 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
5db06880 3329#endif
89122651 3330 PL_bufptr = s + 3;
6e909404
JH
3331 PL_lex_state = LEX_INTERPCONCAT;
3332 return yylex();
a0d0e21e 3333 }
6e909404 3334 else {
90771dc0 3335 I32 tmp;
5db06880
NC
3336 if (!PL_madskills) /* when just compiling don't need correct */
3337 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3338 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3792a11b 3339 if ((*s == 'L' || *s == 'U') &&
6e909404
JH
3340 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3341 PL_lex_casestack[--PL_lex_casemods] = '\0';
bbf60fe6 3342 return REPORT(')');
6e909404
JH
3343 }
3344 if (PL_lex_casemods > 10)
3345 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3346 PL_lex_casestack[PL_lex_casemods++] = *s;
3347 PL_lex_casestack[PL_lex_casemods] = '\0';
3348 PL_lex_state = LEX_INTERPCONCAT;
cd81e915 3349 start_force(PL_curforce);
9ded7720 3350 NEXTVAL_NEXTTOKE.ival = 0;
6e909404 3351 force_next('(');
cd81e915 3352 start_force(PL_curforce);
6e909404 3353 if (*s == 'l')
9ded7720 3354 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
6e909404 3355 else if (*s == 'u')
9ded7720 3356 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
6e909404 3357 else if (*s == 'L')
9ded7720 3358 NEXTVAL_NEXTTOKE.ival = OP_LC;
6e909404 3359 else if (*s == 'U')
9ded7720 3360 NEXTVAL_NEXTTOKE.ival = OP_UC;
6e909404 3361 else if (*s == 'Q')
9ded7720 3362 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
6e909404
JH
3363 else
3364 Perl_croak(aTHX_ "panic: yylex");
5db06880 3365 if (PL_madskills) {
6b29d1f5 3366 SV* const tmpsv = newSVpvs("");
5db06880
NC
3367 Perl_sv_catpvf(aTHX_ tmpsv, "\\%c", *s);
3368 curmad('_', tmpsv);
3369 }
6e909404 3370 PL_bufptr = s + 1;
a0d0e21e 3371 }
79072805 3372 force_next(FUNC);
3280af22
NIS
3373 if (PL_lex_starts) {
3374 s = PL_bufptr;
3375 PL_lex_starts = 0;
5db06880
NC
3376#ifdef PERL_MAD
3377 if (PL_madskills) {
cd81e915
NC
3378 if (PL_thistoken)
3379 sv_free(PL_thistoken);
6b29d1f5 3380 PL_thistoken = newSVpvs("");
5db06880
NC
3381 }
3382#endif
131b3ad0
DM
3383 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3384 if (PL_lex_casemods == 1 && PL_lex_inpat)
3385 OPERATOR(',');
3386 else
3387 Aop(OP_CONCAT);
79072805
LW
3388 }
3389 else
cea2e8a9 3390 return yylex();
79072805
LW
3391 }
3392
55497cff 3393 case LEX_INTERPPUSH:
bbf60fe6 3394 return REPORT(sublex_push());
55497cff 3395
79072805 3396 case LEX_INTERPSTART:
3280af22 3397 if (PL_bufptr == PL_bufend)
bbf60fe6 3398 return REPORT(sublex_done());
607df283 3399 DEBUG_T({ PerlIO_printf(Perl_debug_log,
b6007c36 3400 "### Interpolated variable\n"); });
3280af22
NIS
3401 PL_expect = XTERM;
3402 PL_lex_dojoin = (*PL_bufptr == '@');
3403 PL_lex_state = LEX_INTERPNORMAL;
3404 if (PL_lex_dojoin) {
cd81e915 3405 start_force(PL_curforce);
9ded7720 3406 NEXTVAL_NEXTTOKE.ival = 0;
79072805 3407 force_next(',');
cd81e915 3408 start_force(PL_curforce);
a0d0e21e 3409 force_ident("\"", '$');
cd81e915 3410 start_force(PL_curforce);
9ded7720 3411 NEXTVAL_NEXTTOKE.ival = 0;
79072805 3412 force_next('$');
cd81e915 3413 start_force(PL_curforce);
9ded7720 3414 NEXTVAL_NEXTTOKE.ival = 0;
79072805 3415 force_next('(');
cd81e915 3416 start_force(PL_curforce);
9ded7720 3417 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
79072805
LW
3418 force_next(FUNC);
3419 }
3280af22
NIS
3420 if (PL_lex_starts++) {
3421 s = PL_bufptr;
5db06880
NC
3422#ifdef PERL_MAD
3423 if (PL_madskills) {
cd81e915
NC
3424 if (PL_thistoken)
3425 sv_free(PL_thistoken);
6b29d1f5 3426 PL_thistoken = newSVpvs("");
5db06880
NC
3427 }
3428#endif
131b3ad0
DM
3429 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3430 if (!PL_lex_casemods && PL_lex_inpat)
3431 OPERATOR(',');
3432 else
3433 Aop(OP_CONCAT);
79072805 3434 }
cea2e8a9 3435 return yylex();
79072805
LW
3436
3437 case LEX_INTERPENDMAYBE:
3280af22
NIS
3438 if (intuit_more(PL_bufptr)) {
3439 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
79072805
LW
3440 break;
3441 }
3442 /* FALL THROUGH */
3443
3444 case LEX_INTERPEND:
3280af22
NIS
3445 if (PL_lex_dojoin) {
3446 PL_lex_dojoin = FALSE;
3447 PL_lex_state = LEX_INTERPCONCAT;
5db06880
NC
3448#ifdef PERL_MAD
3449 if (PL_madskills) {
cd81e915
NC
3450 if (PL_thistoken)
3451 sv_free(PL_thistoken);
6b29d1f5 3452 PL_thistoken = newSVpvs("");
5db06880
NC
3453 }
3454#endif
bbf60fe6 3455 return REPORT(')');
79072805 3456 }
43a16006 3457 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
25da4f38 3458 && SvEVALED(PL_lex_repl))
43a16006 3459 {
e9fa98b2 3460 if (PL_bufptr != PL_bufend)
cea2e8a9 3461 Perl_croak(aTHX_ "Bad evalled substitution pattern");
a0714e2c 3462 PL_lex_repl = NULL;
e9fa98b2 3463 }
79072805
LW
3464 /* FALLTHROUGH */
3465 case LEX_INTERPCONCAT:
3466#ifdef DEBUGGING
3280af22 3467 if (PL_lex_brackets)
cea2e8a9 3468 Perl_croak(aTHX_ "panic: INTERPCONCAT");
79072805 3469#endif
3280af22 3470 if (PL_bufptr == PL_bufend)
bbf60fe6 3471 return REPORT(sublex_done());
79072805 3472
3280af22
NIS
3473 if (SvIVX(PL_linestr) == '\'') {
3474 SV *sv = newSVsv(PL_linestr);
3475 if (!PL_lex_inpat)
76e3520e 3476 sv = tokeq(sv);
3280af22 3477 else if ( PL_hints & HINT_NEW_RE )
b3ac6de7 3478 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
79072805 3479 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3280af22 3480 s = PL_bufend;
79072805
LW
3481 }
3482 else {
3280af22 3483 s = scan_const(PL_bufptr);
79072805 3484 if (*s == '\\')
3280af22 3485 PL_lex_state = LEX_INTERPCASEMOD;
79072805 3486 else
3280af22 3487 PL_lex_state = LEX_INTERPSTART;
79072805
LW
3488 }
3489
3280af22 3490 if (s != PL_bufptr) {
cd81e915 3491 start_force(PL_curforce);
5db06880
NC
3492 if (PL_madskills) {
3493 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3494 }
9ded7720 3495 NEXTVAL_NEXTTOKE = yylval;
3280af22 3496 PL_expect = XTERM;
79072805 3497 force_next(THING);
131b3ad0 3498 if (PL_lex_starts++) {
5db06880
NC
3499#ifdef PERL_MAD
3500 if (PL_madskills) {
cd81e915
NC
3501 if (PL_thistoken)
3502 sv_free(PL_thistoken);
6b29d1f5 3503 PL_thistoken = newSVpvs("");
5db06880
NC
3504 }
3505#endif
131b3ad0
DM
3506 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3507 if (!PL_lex_casemods && PL_lex_inpat)
3508 OPERATOR(',');
3509 else
3510 Aop(OP_CONCAT);
3511 }
79072805 3512 else {
3280af22 3513 PL_bufptr = s;
cea2e8a9 3514 return yylex();
79072805
LW
3515 }
3516 }
3517
cea2e8a9 3518 return yylex();
a0d0e21e 3519 case LEX_FORMLINE:
3280af22
NIS
3520 PL_lex_state = LEX_NORMAL;
3521 s = scan_formline(PL_bufptr);
3522 if (!PL_lex_formbrack)
a0d0e21e
LW
3523 goto rightbracket;
3524 OPERATOR(';');
79072805
LW
3525 }
3526
3280af22
NIS
3527 s = PL_bufptr;
3528 PL_oldoldbufptr = PL_oldbufptr;
3529 PL_oldbufptr = s;
463ee0b2
LW
3530
3531 retry:
5db06880 3532#ifdef PERL_MAD
cd81e915
NC
3533 if (PL_thistoken) {
3534 sv_free(PL_thistoken);
3535 PL_thistoken = 0;
5db06880 3536 }
cd81e915 3537 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
5db06880 3538#endif
378cc40b
LW
3539 switch (*s) {
3540 default:
7e2040f0 3541 if (isIDFIRST_lazy_if(s,UTF))
834a4ddd 3542 goto keylookup;
cea2e8a9 3543 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
e929a76b
LW
3544 case 4:
3545 case 26:
3546 goto fake_eof; /* emulate EOF on ^D or ^Z */
378cc40b 3547 case 0:
5db06880
NC
3548#ifdef PERL_MAD
3549 if (PL_madskills)
cd81e915 3550 PL_faketokens = 0;
5db06880 3551#endif
3280af22
NIS
3552 if (!PL_rsfp) {
3553 PL_last_uni = 0;
3554 PL_last_lop = 0;
c5ee2135 3555 if (PL_lex_brackets) {
10edeb5d
JH
3556 yyerror((const char *)
3557 (PL_lex_formbrack
3558 ? "Format not terminated"
3559 : "Missing right curly or square bracket"));
c5ee2135 3560 }
4e553d73 3561 DEBUG_T( { PerlIO_printf(Perl_debug_log,
607df283 3562 "### Tokener got EOF\n");
5f80b19c 3563 } );
79072805 3564 TOKEN(0);
463ee0b2 3565 }
3280af22 3566 if (s++ < PL_bufend)
a687059c 3567 goto retry; /* ignore stray nulls */
3280af22
NIS
3568 PL_last_uni = 0;
3569 PL_last_lop = 0;
3570 if (!PL_in_eval && !PL_preambled) {
3571 PL_preambled = TRUE;
5db06880
NC
3572#ifdef PERL_MAD
3573 if (PL_madskills)
cd81e915 3574 PL_faketokens = 1;
5db06880 3575#endif
3280af22
NIS
3576 sv_setpv(PL_linestr,incl_perldb());
3577 if (SvCUR(PL_linestr))
396482e1 3578 sv_catpvs(PL_linestr,";");
3280af22
NIS
3579 if (PL_preambleav){
3580 while(AvFILLp(PL_preambleav) >= 0) {
3581 SV *tmpsv = av_shift(PL_preambleav);
3582 sv_catsv(PL_linestr, tmpsv);
396482e1 3583 sv_catpvs(PL_linestr, ";");
91b7def8 3584 sv_free(tmpsv);
3585 }
3280af22
NIS
3586 sv_free((SV*)PL_preambleav);
3587 PL_preambleav = NULL;
91b7def8 3588 }
3280af22 3589 if (PL_minus_n || PL_minus_p) {
396482e1 3590 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3280af22 3591 if (PL_minus_l)
396482e1 3592 sv_catpvs(PL_linestr,"chomp;");
3280af22 3593 if (PL_minus_a) {
3280af22 3594 if (PL_minus_F) {
3792a11b
NC
3595 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3596 || *PL_splitstr == '"')
3280af22 3597 && strchr(PL_splitstr + 1, *PL_splitstr))
3db68c4c 3598 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
54310121 3599 else {
c8ef6a4b
NC
3600 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3601 bytes can be used as quoting characters. :-) */
dd374669 3602 const char *splits = PL_splitstr;
91d456ae 3603 sv_catpvs(PL_linestr, "our @F=split(q\0");
48c4c863
NC
3604 do {
3605 /* Need to \ \s */
dd374669
AL
3606 if (*splits == '\\')
3607 sv_catpvn(PL_linestr, splits, 1);
3608 sv_catpvn(PL_linestr, splits, 1);
3609 } while (*splits++);
48c4c863
NC
3610 /* This loop will embed the trailing NUL of
3611 PL_linestr as the last thing it does before
3612 terminating. */
396482e1 3613 sv_catpvs(PL_linestr, ");");
54310121 3614 }
2304df62
AD
3615 }
3616 else
396482e1 3617 sv_catpvs(PL_linestr,"our @F=split(' ');");
2304df62 3618 }
79072805 3619 }
bc9b29db 3620 if (PL_minus_E)
396482e1
GA
3621 sv_catpvs(PL_linestr,"use feature ':5.10';");
3622 sv_catpvs(PL_linestr, "\n");
3280af22
NIS
3623 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3624 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3625 PL_last_lop = PL_last_uni = NULL;
80a702cd 3626 if (PERLDB_LINE && PL_curstash != PL_debstash)
5fa550fb 3627 update_debugger_info(PL_linestr, NULL, 0);
79072805 3628 goto retry;
a687059c 3629 }
e929a76b 3630 do {
aa7440fb 3631 bof = PL_rsfp ? TRUE : FALSE;
bd61b366 3632 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
7e28d3af 3633 fake_eof:
5db06880 3634#ifdef PERL_MAD
cd81e915 3635 PL_realtokenstart = -1;
5db06880 3636#endif
7e28d3af
JH
3637 if (PL_rsfp) {
3638 if (PL_preprocess && !PL_in_eval)
3639 (void)PerlProc_pclose(PL_rsfp);
3640 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3641 PerlIO_clearerr(PL_rsfp);
3642 else
3643 (void)PerlIO_close(PL_rsfp);
4608196e 3644 PL_rsfp = NULL;
7e28d3af
JH
3645 PL_doextract = FALSE;
3646 }
3647 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
5db06880
NC
3648#ifdef PERL_MAD
3649 if (PL_madskills)
cd81e915 3650 PL_faketokens = 1;
5db06880 3651#endif
10edeb5d
JH
3652 sv_setpv(PL_linestr,
3653 (const char *)
3654 (PL_minus_p
3655 ? ";}continue{print;}" : ";}"));
7e28d3af
JH
3656 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3657 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3658 PL_last_lop = PL_last_uni = NULL;
7e28d3af
JH
3659 PL_minus_n = PL_minus_p = 0;
3660 goto retry;
3661 }
3662 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
bd61b366 3663 PL_last_lop = PL_last_uni = NULL;
c69006e4 3664 sv_setpvn(PL_linestr,"",0);
7e28d3af
JH
3665 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3666 }
7aa207d6
JH
3667 /* If it looks like the start of a BOM or raw UTF-16,
3668 * check if it in fact is. */
3669 else if (bof &&
3670 (*s == 0 ||
3671 *(U8*)s == 0xEF ||
3672 *(U8*)s >= 0xFE ||
3673 s[1] == 0)) {
226017aa 3674#ifdef PERLIO_IS_STDIO
e3f494f1
JH
3675# ifdef __GNU_LIBRARY__
3676# if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
226017aa
DD
3677# define FTELL_FOR_PIPE_IS_BROKEN
3678# endif
e3f494f1
JH
3679# else
3680# ifdef __GLIBC__
3681# if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3682# define FTELL_FOR_PIPE_IS_BROKEN
3683# endif
3684# endif
226017aa
DD
3685# endif
3686#endif
3687#ifdef FTELL_FOR_PIPE_IS_BROKEN
3688 /* This loses the possibility to detect the bof
3689 * situation on perl -P when the libc5 is being used.
3690 * Workaround? Maybe attach some extra state to PL_rsfp?
3691 */
3692 if (!PL_preprocess)
7e28d3af 3693 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
226017aa 3694#else
eb160463 3695 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
226017aa 3696#endif
7e28d3af 3697 if (bof) {
3280af22 3698 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
7e28d3af 3699 s = swallow_bom((U8*)s);
e929a76b 3700 }
378cc40b 3701 }
3280af22 3702 if (PL_doextract) {
a0d0e21e 3703 /* Incest with pod. */
5db06880
NC
3704#ifdef PERL_MAD
3705 if (PL_madskills)
cd81e915 3706 sv_catsv(PL_thiswhite, PL_linestr);
5db06880 3707#endif
01a57ef7 3708 if (*s == '=' && strnEQ(s, "=cut", 4) && !isALPHA(s[4])) {
c69006e4 3709 sv_setpvn(PL_linestr, "", 0);
3280af22
NIS
3710 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3711 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3712 PL_last_lop = PL_last_uni = NULL;
3280af22 3713 PL_doextract = FALSE;
a0d0e21e 3714 }
4e553d73 3715 }
463ee0b2 3716 incline(s);
3280af22
NIS
3717 } while (PL_doextract);
3718 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
80a702cd 3719 if (PERLDB_LINE && PL_curstash != PL_debstash)
5fa550fb 3720 update_debugger_info(PL_linestr, NULL, 0);
3280af22 3721 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3722 PL_last_lop = PL_last_uni = NULL;
57843af0 3723 if (CopLINE(PL_curcop) == 1) {
3280af22 3724 while (s < PL_bufend && isSPACE(*s))
79072805 3725 s++;
a0d0e21e 3726 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
79072805 3727 s++;
5db06880
NC
3728#ifdef PERL_MAD
3729 if (PL_madskills)
cd81e915 3730 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
5db06880 3731#endif
bd61b366 3732 d = NULL;
3280af22 3733 if (!PL_in_eval) {
44a8e56a 3734 if (*s == '#' && *(s+1) == '!')
3735 d = s + 2;
3736#ifdef ALTERNATE_SHEBANG
3737 else {
bfed75c6 3738 static char const as[] = ALTERNATE_SHEBANG;
44a8e56a 3739 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3740 d = s + (sizeof(as) - 1);
3741 }
3742#endif /* ALTERNATE_SHEBANG */
3743 }
3744 if (d) {
b8378b72 3745 char *ipath;
774d564b 3746 char *ipathend;
b8378b72 3747
774d564b 3748 while (isSPACE(*d))
b8378b72
CS
3749 d++;
3750 ipath = d;
774d564b 3751 while (*d && !isSPACE(*d))
3752 d++;
3753 ipathend = d;
3754
3755#ifdef ARG_ZERO_IS_SCRIPT
3756 if (ipathend > ipath) {
3757 /*
3758 * HP-UX (at least) sets argv[0] to the script name,
3759 * which makes $^X incorrect. And Digital UNIX and Linux,
3760 * at least, set argv[0] to the basename of the Perl
3761 * interpreter. So, having found "#!", we'll set it right.
3762 */
fafc274c
NC
3763 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3764 SVt_PV)); /* $^X */
774d564b 3765 assert(SvPOK(x) || SvGMAGICAL(x));
cc49e20b 3766 if (sv_eq(x, CopFILESV(PL_curcop))) {
774d564b 3767 sv_setpvn(x, ipath, ipathend - ipath);
9607fc9c 3768 SvSETMAGIC(x);
3769 }
556c1dec
JH
3770 else {
3771 STRLEN blen;
3772 STRLEN llen;
cfd0369c 3773 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
9d4ba2ae 3774 const char * const lstart = SvPV_const(x,llen);
556c1dec
JH
3775 if (llen < blen) {
3776 bstart += blen - llen;
3777 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3778 sv_setpvn(x, ipath, ipathend - ipath);
3779 SvSETMAGIC(x);
3780 }
3781 }
3782 }
774d564b 3783 TAINT_NOT; /* $^X is always tainted, but that's OK */
8ebc5c01 3784 }
774d564b 3785#endif /* ARG_ZERO_IS_SCRIPT */
b8378b72
CS
3786
3787 /*
3788 * Look for options.
3789 */
748a9306 3790 d = instr(s,"perl -");
84e30d1a 3791 if (!d) {
748a9306 3792 d = instr(s,"perl");
84e30d1a
GS
3793#if defined(DOSISH)
3794 /* avoid getting into infinite loops when shebang
3795 * line contains "Perl" rather than "perl" */
3796 if (!d) {
3797 for (d = ipathend-4; d >= ipath; --d) {
3798 if ((*d == 'p' || *d == 'P')
3799 && !ibcmp(d, "perl", 4))
3800 {
3801 break;
3802 }
3803 }
3804 if (d < ipath)
bd61b366 3805 d = NULL;
84e30d1a
GS
3806 }
3807#endif
3808 }
44a8e56a 3809#ifdef ALTERNATE_SHEBANG
3810 /*
3811 * If the ALTERNATE_SHEBANG on this system starts with a
3812 * character that can be part of a Perl expression, then if
3813 * we see it but not "perl", we're probably looking at the
3814 * start of Perl code, not a request to hand off to some
3815 * other interpreter. Similarly, if "perl" is there, but
3816 * not in the first 'word' of the line, we assume the line
3817 * contains the start of the Perl program.
44a8e56a 3818 */
3819 if (d && *s != '#') {
f54cb97a 3820 const char *c = ipath;
44a8e56a 3821 while (*c && !strchr("; \t\r\n\f\v#", *c))
3822 c++;
3823 if (c < d)
bd61b366 3824 d = NULL; /* "perl" not in first word; ignore */
44a8e56a 3825 else
3826 *s = '#'; /* Don't try to parse shebang line */
3827 }
774d564b 3828#endif /* ALTERNATE_SHEBANG */
bf4acbe4 3829#ifndef MACOS_TRADITIONAL
748a9306 3830 if (!d &&
44a8e56a 3831 *s == '#' &&
774d564b 3832 ipathend > ipath &&
3280af22 3833 !PL_minus_c &&
748a9306 3834 !instr(s,"indir") &&
3280af22 3835 instr(PL_origargv[0],"perl"))
748a9306 3836 {
27da23d5 3837 dVAR;
9f68db38 3838 char **newargv;
9f68db38 3839
774d564b 3840 *ipathend = '\0';
3841 s = ipathend + 1;
3280af22 3842 while (s < PL_bufend && isSPACE(*s))
9f68db38 3843 s++;
3280af22 3844 if (s < PL_bufend) {
a02a5408 3845 Newxz(newargv,PL_origargc+3,char*);
9f68db38 3846 newargv[1] = s;
3280af22 3847 while (s < PL_bufend && !isSPACE(*s))
9f68db38
LW
3848 s++;
3849 *s = '\0';
3280af22 3850 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
9f68db38
LW
3851 }
3852 else
3280af22 3853 newargv = PL_origargv;
774d564b 3854 newargv[0] = ipath;
b35112e7 3855 PERL_FPU_PRE_EXEC
b4748376 3856 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
b35112e7 3857 PERL_FPU_POST_EXEC
cea2e8a9 3858 Perl_croak(aTHX_ "Can't exec %s", ipath);
9f68db38 3859 }
bf4acbe4 3860#endif
748a9306 3861 if (d) {
c35e046a
AL
3862 while (*d && !isSPACE(*d))
3863 d++;
3864 while (SPACE_OR_TAB(*d))
3865 d++;
748a9306
LW
3866
3867 if (*d++ == '-') {
f54cb97a 3868 const bool switches_done = PL_doswitches;
fb993905
GA
3869 const U32 oldpdb = PL_perldb;
3870 const bool oldn = PL_minus_n;
3871 const bool oldp = PL_minus_p;
3872
8cc95fdb 3873 do {
3ffe3ee4 3874 if (*d == 'M' || *d == 'm' || *d == 'C') {
9d4ba2ae 3875 const char * const m = d;
d4c19fe8
AL
3876 while (*d && !isSPACE(*d))
3877 d++;
cea2e8a9 3878 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
8cc95fdb 3879 (int)(d - m), m);
3880 }
97bd5664 3881 d = moreswitches(d);
8cc95fdb 3882 } while (d);
f0b2cf55
YST
3883 if (PL_doswitches && !switches_done) {
3884 int argc = PL_origargc;
3885 char **argv = PL_origargv;
3886 do {
3887 argc--,argv++;
3888 } while (argc && argv[0][0] == '-' && argv[0][1]);
3889 init_argv_symbols(argc,argv);
3890 }
155aba94
GS
3891 if ((PERLDB_LINE && !oldpdb) ||
3892 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
b084f20b 3893 /* if we have already added "LINE: while (<>) {",
3894 we must not do it again */
748a9306 3895 {
c69006e4 3896 sv_setpvn(PL_linestr, "", 0);
3280af22
NIS
3897 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3898 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3899 PL_last_lop = PL_last_uni = NULL;
3280af22 3900 PL_preambled = FALSE;
84902520 3901 if (PERLDB_LINE)
3280af22 3902 (void)gv_fetchfile(PL_origfilename);
748a9306
LW
3903 goto retry;
3904 }
a0d0e21e 3905 }
79072805 3906 }
9f68db38 3907 }
79072805 3908 }
3280af22
NIS
3909 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3910 PL_bufptr = s;
3911 PL_lex_state = LEX_FORMLINE;
cea2e8a9 3912 return yylex();
ae986130 3913 }
378cc40b 3914 goto retry;
4fdae800 3915 case '\r':
6a27c188 3916#ifdef PERL_STRICT_CR
cea2e8a9 3917 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
4e553d73 3918 Perl_croak(aTHX_
cc507455 3919 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
a868473f 3920#endif
4fdae800 3921 case ' ': case '\t': case '\f': case 013:
bf4acbe4
GS
3922#ifdef MACOS_TRADITIONAL
3923 case '\312':
3924#endif
5db06880 3925#ifdef PERL_MAD
cd81e915 3926 PL_realtokenstart = -1;
ac372eb8
RD
3927 if (!PL_thiswhite)
3928 PL_thiswhite = newSVpvs("");
3929 sv_catpvn(PL_thiswhite, s, 1);
5db06880 3930#endif
ac372eb8 3931 s++;
378cc40b 3932 goto retry;
378cc40b 3933 case '#':
e929a76b 3934 case '\n':
5db06880 3935#ifdef PERL_MAD
cd81e915 3936 PL_realtokenstart = -1;
5db06880 3937 if (PL_madskills)
cd81e915 3938 PL_faketokens = 0;
5db06880 3939#endif
3280af22 3940 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
df0deb90
GS
3941 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3942 /* handle eval qq[#line 1 "foo"\n ...] */
3943 CopLINE_dec(PL_curcop);
3944 incline(s);
3945 }
5db06880
NC
3946 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
3947 s = SKIPSPACE0(s);
3948 if (!PL_in_eval || PL_rsfp)
3949 incline(s);
3950 }
3951 else {
3952 d = s;
3953 while (d < PL_bufend && *d != '\n')
3954 d++;
3955 if (d < PL_bufend)
3956 d++;
3957 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3958 Perl_croak(aTHX_ "panic: input overflow");
3959#ifdef PERL_MAD
3960 if (PL_madskills)
cd81e915 3961 PL_thiswhite = newSVpvn(s, d - s);
5db06880
NC
3962#endif
3963 s = d;
3964 incline(s);
3965 }
3280af22
NIS
3966 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3967 PL_bufptr = s;
3968 PL_lex_state = LEX_FORMLINE;
cea2e8a9 3969 return yylex();
a687059c 3970 }
378cc40b 3971 }
a687059c 3972 else {
5db06880
NC
3973#ifdef PERL_MAD
3974 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
3975 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
cd81e915 3976 PL_faketokens = 0;
5db06880
NC
3977 s = SKIPSPACE0(s);
3978 TOKEN(PEG); /* make sure any #! line is accessible */
3979 }
3980 s = SKIPSPACE0(s);
3981 }
3982 else {
3983/* if (PL_madskills && PL_lex_formbrack) { */
3984 d = s;
3985 while (d < PL_bufend && *d != '\n')
3986 d++;
3987 if (d < PL_bufend)
3988 d++;
3989 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3990 Perl_croak(aTHX_ "panic: input overflow");
3991 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
cd81e915 3992 if (!PL_thiswhite)
6b29d1f5 3993 PL_thiswhite = newSVpvs("");
5db06880 3994 if (CopLINE(PL_curcop) == 1) {
cd81e915
NC
3995 sv_setpvn(PL_thiswhite, "", 0);
3996 PL_faketokens = 0;
5db06880 3997 }
cd81e915 3998 sv_catpvn(PL_thiswhite, s, d - s);
5db06880
NC
3999 }
4000 s = d;
4001/* }
4002 *s = '\0';
4003 PL_bufend = s; */
4004 }
4005#else
378cc40b 4006 *s = '\0';
3280af22 4007 PL_bufend = s;
5db06880 4008#endif
a687059c 4009 }
378cc40b
LW
4010 goto retry;
4011 case '-':
79072805 4012 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
e5edeb50 4013 I32 ftst = 0;
90771dc0 4014 char tmp;
e5edeb50 4015
378cc40b 4016 s++;
3280af22 4017 PL_bufptr = s;
748a9306
LW
4018 tmp = *s++;
4019
bf4acbe4 4020 while (s < PL_bufend && SPACE_OR_TAB(*s))
748a9306
LW
4021 s++;
4022
4023 if (strnEQ(s,"=>",2)) {
3280af22 4024 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
931e0695 4025 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
748a9306
LW
4026 OPERATOR('-'); /* unary minus */
4027 }
3280af22 4028 PL_last_uni = PL_oldbufptr;
748a9306 4029 switch (tmp) {
e5edeb50
JH
4030 case 'r': ftst = OP_FTEREAD; break;
4031 case 'w': ftst = OP_FTEWRITE; break;
4032 case 'x': ftst = OP_FTEEXEC; break;
4033 case 'o': ftst = OP_FTEOWNED; break;
4034 case 'R': ftst = OP_FTRREAD; break;
4035 case 'W': ftst = OP_FTRWRITE; break;
4036 case 'X': ftst = OP_FTREXEC; break;
4037 case 'O': ftst = OP_FTROWNED; break;
4038 case 'e': ftst = OP_FTIS; break;
4039 case 'z': ftst = OP_FTZERO; break;
4040 case 's': ftst = OP_FTSIZE; break;
4041 case 'f': ftst = OP_FTFILE; break;
4042 case 'd': ftst = OP_FTDIR; break;
4043 case 'l': ftst = OP_FTLINK; break;
4044 case 'p': ftst = OP_FTPIPE; break;
4045 case 'S': ftst = OP_FTSOCK; break;
4046 case 'u': ftst = OP_FTSUID; break;
4047 case 'g': ftst = OP_FTSGID; break;
4048 case 'k': ftst = OP_FTSVTX; break;
4049 case 'b': ftst = OP_FTBLK; break;
4050 case 'c': ftst = OP_FTCHR; break;
4051 case 't': ftst = OP_FTTTY; break;
4052 case 'T': ftst = OP_FTTEXT; break;
4053 case 'B': ftst = OP_FTBINARY; break;
4054 case 'M': case 'A': case 'C':
fafc274c 4055 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
e5edeb50
JH
4056 switch (tmp) {
4057 case 'M': ftst = OP_FTMTIME; break;
4058 case 'A': ftst = OP_FTATIME; break;
4059 case 'C': ftst = OP_FTCTIME; break;
4060 default: break;
4061 }
4062 break;
378cc40b 4063 default:
378cc40b
LW
4064 break;
4065 }
e5edeb50 4066 if (ftst) {
eb160463 4067 PL_last_lop_op = (OPCODE)ftst;
4e553d73 4068 DEBUG_T( { PerlIO_printf(Perl_debug_log,
a18d764d 4069 "### Saw file test %c\n", (int)tmp);
5f80b19c 4070 } );
e5edeb50
JH
4071 FTST(ftst);
4072 }
4073 else {
4074 /* Assume it was a minus followed by a one-letter named
4075 * subroutine call (or a -bareword), then. */
95c31fe3 4076 DEBUG_T( { PerlIO_printf(Perl_debug_log,
17ad61e0 4077 "### '-%c' looked like a file test but was not\n",
4fccd7c6 4078 (int) tmp);
5f80b19c 4079 } );
3cf7b4c4 4080 s = --PL_bufptr;
e5edeb50 4081 }
378cc40b 4082 }
90771dc0
NC
4083 {
4084 const char tmp = *s++;
4085 if (*s == tmp) {
4086 s++;
4087 if (PL_expect == XOPERATOR)
4088 TERM(POSTDEC);
4089 else
4090 OPERATOR(PREDEC);
4091 }
4092 else if (*s == '>') {
4093 s++;
29595ff2 4094 s = SKIPSPACE1(s);
90771dc0
NC
4095 if (isIDFIRST_lazy_if(s,UTF)) {
4096 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
4097 TOKEN(ARROW);
4098 }
4099 else if (*s == '$')
4100 OPERATOR(ARROW);
4101 else
4102 TERM(ARROW);
4103 }
3280af22 4104 if (PL_expect == XOPERATOR)
90771dc0
NC
4105 Aop(OP_SUBTRACT);
4106 else {
4107 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4108 check_uni();
4109 OPERATOR('-'); /* unary minus */
79072805 4110 }
2f3197b3 4111 }
79072805 4112
378cc40b 4113 case '+':
90771dc0
NC
4114 {
4115 const char tmp = *s++;
4116 if (*s == tmp) {
4117 s++;
4118 if (PL_expect == XOPERATOR)
4119 TERM(POSTINC);
4120 else
4121 OPERATOR(PREINC);
4122 }
3280af22 4123 if (PL_expect == XOPERATOR)
90771dc0
NC
4124 Aop(OP_ADD);
4125 else {
4126 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4127 check_uni();
4128 OPERATOR('+');
4129 }
2f3197b3 4130 }
a687059c 4131
378cc40b 4132 case '*':
3280af22
NIS
4133 if (PL_expect != XOPERATOR) {
4134 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4135 PL_expect = XOPERATOR;
4136 force_ident(PL_tokenbuf, '*');
4137 if (!*PL_tokenbuf)
a0d0e21e 4138 PREREF('*');
79072805 4139 TERM('*');
a687059c 4140 }
79072805
LW
4141 s++;
4142 if (*s == '*') {
a687059c 4143 s++;
79072805 4144 PWop(OP_POW);
a687059c 4145 }
79072805
LW
4146 Mop(OP_MULTIPLY);
4147
378cc40b 4148 case '%':
3280af22 4149 if (PL_expect == XOPERATOR) {
bbce6d69 4150 ++s;
4151 Mop(OP_MODULO);
a687059c 4152 }
3280af22 4153 PL_tokenbuf[0] = '%';
e8ae98db
RGS
4154 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4155 sizeof PL_tokenbuf - 1, FALSE);
3280af22 4156 if (!PL_tokenbuf[1]) {
bbce6d69 4157 PREREF('%');
a687059c 4158 }
3280af22 4159 PL_pending_ident = '%';
bbce6d69 4160 TERM('%');
a687059c 4161
378cc40b 4162 case '^':
79072805 4163 s++;
a0d0e21e 4164 BOop(OP_BIT_XOR);
79072805 4165 case '[':
3280af22 4166 PL_lex_brackets++;
79072805 4167 /* FALL THROUGH */
378cc40b 4168 case '~':
0d863452 4169 if (s[1] == '~'
3e7dd34d 4170 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR))
0d863452
RH
4171 {
4172 s += 2;
4173 Eop(OP_SMARTMATCH);
4174 }
378cc40b 4175 case ',':
90771dc0
NC
4176 {
4177 const char tmp = *s++;
4178 OPERATOR(tmp);
4179 }
a0d0e21e
LW
4180 case ':':
4181 if (s[1] == ':') {
4182 len = 0;
0bfa2a8a 4183 goto just_a_word_zero_gv;
a0d0e21e
LW
4184 }
4185 s++;
09bef843
SB
4186 switch (PL_expect) {
4187 OP *attrs;
5db06880
NC
4188#ifdef PERL_MAD
4189 I32 stuffstart;
4190#endif
09bef843
SB
4191 case XOPERATOR:
4192 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
4193 break;
4194 PL_bufptr = s; /* update in case we back off */
4195 goto grabattrs;
4196 case XATTRBLOCK:
4197 PL_expect = XBLOCK;
4198 goto grabattrs;
4199 case XATTRTERM:
4200 PL_expect = XTERMBLOCK;
4201 grabattrs:
5db06880
NC
4202#ifdef PERL_MAD
4203 stuffstart = s - SvPVX(PL_linestr) - 1;
4204#endif
29595ff2 4205 s = PEEKSPACE(s);
5f66b61c 4206 attrs = NULL;
7e2040f0 4207 while (isIDFIRST_lazy_if(s,UTF)) {
90771dc0 4208 I32 tmp;
5cc237b8 4209 SV *sv;
09bef843 4210 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5458a98a 4211 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
f9829d6b
GS
4212 if (tmp < 0) tmp = -tmp;
4213 switch (tmp) {
4214 case KEY_or:
4215 case KEY_and:
c963b151 4216 case KEY_err:
f9829d6b
GS
4217 case KEY_for:
4218 case KEY_unless:
4219 case KEY_if:
4220 case KEY_while:
4221 case KEY_until:
4222 goto got_attrs;
4223 default:
4224 break;
4225 }
4226 }
5cc237b8 4227 sv = newSVpvn(s, len);
09bef843
SB
4228 if (*d == '(') {
4229 d = scan_str(d,TRUE,TRUE);
4230 if (!d) {
09bef843
SB
4231 /* MUST advance bufptr here to avoid bogus
4232 "at end of line" context messages from yyerror().
4233 */
4234 PL_bufptr = s + len;
4235 yyerror("Unterminated attribute parameter in attribute list");
4236 if (attrs)
4237 op_free(attrs);
5cc237b8 4238 sv_free(sv);
bbf60fe6 4239 return REPORT(0); /* EOF indicator */
09bef843
SB
4240 }
4241 }
4242 if (PL_lex_stuff) {
09bef843
SB
4243 sv_catsv(sv, PL_lex_stuff);
4244 attrs = append_elem(OP_LIST, attrs,
4245 newSVOP(OP_CONST, 0, sv));
4246 SvREFCNT_dec(PL_lex_stuff);
a0714e2c 4247 PL_lex_stuff = NULL;
09bef843
SB
4248 }
4249 else {
5cc237b8
BS
4250 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4251 sv_free(sv);
1108974d 4252 if (PL_in_my == KEY_our) {
371fce9b
DM
4253#ifdef USE_ITHREADS
4254 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
4255#else
1108974d 4256 /* skip to avoid loading attributes.pm */
371fce9b 4257#endif
df9a6019 4258 deprecate(":unique");
1108974d 4259 }
bfed75c6 4260 else
371fce9b
DM
4261 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4262 }
4263
d3cea301
SB
4264 /* NOTE: any CV attrs applied here need to be part of
4265 the CVf_BUILTIN_ATTRS define in cv.h! */
5cc237b8
BS
4266 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4267 sv_free(sv);
78f9721b 4268 CvLVALUE_on(PL_compcv);
5cc237b8
BS
4269 }
4270 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4271 sv_free(sv);
78f9721b 4272 CvLOCKED_on(PL_compcv);
5cc237b8
BS
4273 }
4274 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4275 sv_free(sv);
78f9721b 4276 CvMETHOD_on(PL_compcv);
5cc237b8
BS
4277 }
4278 else if (!PL_in_my && len == 9 && strnEQ(SvPVX(sv), "assertion", len)) {
4279 sv_free(sv);
06492da6 4280 CvASSERTION_on(PL_compcv);
5cc237b8 4281 }
78f9721b
SM
4282 /* After we've set the flags, it could be argued that
4283 we don't need to do the attributes.pm-based setting
4284 process, and shouldn't bother appending recognized
d3cea301
SB
4285 flags. To experiment with that, uncomment the
4286 following "else". (Note that's already been
4287 uncommented. That keeps the above-applied built-in
4288 attributes from being intercepted (and possibly
4289 rejected) by a package's attribute routines, but is
4290 justified by the performance win for the common case
4291 of applying only built-in attributes.) */
0256094b 4292 else
78f9721b
SM
4293 attrs = append_elem(OP_LIST, attrs,
4294 newSVOP(OP_CONST, 0,
5cc237b8 4295 sv));
09bef843 4296 }
29595ff2 4297 s = PEEKSPACE(d);
0120eecf 4298 if (*s == ':' && s[1] != ':')
29595ff2 4299 s = PEEKSPACE(s+1);
0120eecf
GS
4300 else if (s == d)
4301 break; /* require real whitespace or :'s */
29595ff2 4302 /* XXX losing whitespace on sequential attributes here */
09bef843 4303 }
90771dc0
NC
4304 {
4305 const char tmp
4306 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4307 if (*s != ';' && *s != '}' && *s != tmp
4308 && (tmp != '=' || *s != ')')) {
4309 const char q = ((*s == '\'') ? '"' : '\'');
4310 /* If here for an expression, and parsed no attrs, back
4311 off. */
4312 if (tmp == '=' && !attrs) {
4313 s = PL_bufptr;
4314 break;
4315 }
4316 /* MUST advance bufptr here to avoid bogus "at end of line"
4317 context messages from yyerror().
4318 */
4319 PL_bufptr = s;
10edeb5d
JH
4320 yyerror( (const char *)
4321 (*s
4322 ? Perl_form(aTHX_ "Invalid separator character "
4323 "%c%c%c in attribute list", q, *s, q)
4324 : "Unterminated attribute list" ) );
90771dc0
NC
4325 if (attrs)
4326 op_free(attrs);
4327 OPERATOR(':');
09bef843 4328 }
09bef843 4329 }
f9829d6b 4330 got_attrs:
09bef843 4331 if (attrs) {
cd81e915 4332 start_force(PL_curforce);
9ded7720 4333 NEXTVAL_NEXTTOKE.opval = attrs;
cd81e915 4334 CURMAD('_', PL_nextwhite);
89122651 4335 force_next(THING);
5db06880
NC
4336 }
4337#ifdef PERL_MAD
4338 if (PL_madskills) {
cd81e915 4339 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
5db06880 4340 (s - SvPVX(PL_linestr)) - stuffstart);
09bef843 4341 }
5db06880 4342#endif
09bef843
SB
4343 TOKEN(COLONATTR);
4344 }
a0d0e21e 4345 OPERATOR(':');
8990e307
LW
4346 case '(':
4347 s++;
3280af22
NIS
4348 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4349 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
a0d0e21e 4350 else
3280af22 4351 PL_expect = XTERM;
29595ff2 4352 s = SKIPSPACE1(s);
a0d0e21e 4353 TOKEN('(');
378cc40b 4354 case ';':
f4dd75d9 4355 CLINE;
90771dc0
NC
4356 {
4357 const char tmp = *s++;
4358 OPERATOR(tmp);
4359 }
378cc40b 4360 case ')':
90771dc0
NC
4361 {
4362 const char tmp = *s++;
29595ff2 4363 s = SKIPSPACE1(s);
90771dc0
NC
4364 if (*s == '{')
4365 PREBLOCK(tmp);
4366 TERM(tmp);
4367 }
79072805
LW
4368 case ']':
4369 s++;
3280af22 4370 if (PL_lex_brackets <= 0)
d98d5fff 4371 yyerror("Unmatched right square bracket");
463ee0b2 4372 else
3280af22
NIS
4373 --PL_lex_brackets;
4374 if (PL_lex_state == LEX_INTERPNORMAL) {
4375 if (PL_lex_brackets == 0) {
a0d0e21e 4376 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
3280af22 4377 PL_lex_state = LEX_INTERPEND;
79072805
LW
4378 }
4379 }
4633a7c4 4380 TERM(']');
79072805
LW
4381 case '{':
4382 leftbracket:
79072805 4383 s++;
3280af22 4384 if (PL_lex_brackets > 100) {
8edd5f42 4385 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
8990e307 4386 }
3280af22 4387 switch (PL_expect) {
a0d0e21e 4388 case XTERM:
3280af22 4389 if (PL_lex_formbrack) {
a0d0e21e
LW
4390 s--;
4391 PRETERMBLOCK(DO);
4392 }
3280af22
NIS
4393 if (PL_oldoldbufptr == PL_last_lop)
4394 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
a0d0e21e 4395 else
3280af22 4396 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
79072805 4397 OPERATOR(HASHBRACK);
a0d0e21e 4398 case XOPERATOR:
bf4acbe4 4399 while (s < PL_bufend && SPACE_OR_TAB(*s))
748a9306 4400 s++;
44a8e56a 4401 d = s;
3280af22
NIS
4402 PL_tokenbuf[0] = '\0';
4403 if (d < PL_bufend && *d == '-') {
4404 PL_tokenbuf[0] = '-';
44a8e56a 4405 d++;
bf4acbe4 4406 while (d < PL_bufend && SPACE_OR_TAB(*d))
44a8e56a 4407 d++;
4408 }
7e2040f0 4409 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
3280af22 4410 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
8903cb82 4411 FALSE, &len);
bf4acbe4 4412 while (d < PL_bufend && SPACE_OR_TAB(*d))
748a9306
LW
4413 d++;
4414 if (*d == '}') {
f54cb97a 4415 const char minus = (PL_tokenbuf[0] == '-');
44a8e56a 4416 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4417 if (minus)
4418 force_next('-');
748a9306
LW
4419 }
4420 }
4421 /* FALL THROUGH */
09bef843 4422 case XATTRBLOCK:
748a9306 4423 case XBLOCK:
3280af22
NIS
4424 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4425 PL_expect = XSTATE;
a0d0e21e 4426 break;
09bef843 4427 case XATTRTERM:
a0d0e21e 4428 case XTERMBLOCK:
3280af22
NIS
4429 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4430 PL_expect = XSTATE;
a0d0e21e
LW
4431 break;
4432 default: {
f54cb97a 4433 const char *t;
3280af22
NIS
4434 if (PL_oldoldbufptr == PL_last_lop)
4435 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
a0d0e21e 4436 else
3280af22 4437 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
29595ff2 4438 s = SKIPSPACE1(s);
8452ff4b
SB
4439 if (*s == '}') {
4440 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4441 PL_expect = XTERM;
4442 /* This hack is to get the ${} in the message. */
4443 PL_bufptr = s+1;
4444 yyerror("syntax error");
4445 break;
4446 }
a0d0e21e 4447 OPERATOR(HASHBRACK);
8452ff4b 4448 }
b8a4b1be
GS
4449 /* This hack serves to disambiguate a pair of curlies
4450 * as being a block or an anon hash. Normally, expectation
4451 * determines that, but in cases where we're not in a
4452 * position to expect anything in particular (like inside
4453 * eval"") we have to resolve the ambiguity. This code
4454 * covers the case where the first term in the curlies is a
4455 * quoted string. Most other cases need to be explicitly
a0288114 4456 * disambiguated by prepending a "+" before the opening
b8a4b1be
GS
4457 * curly in order to force resolution as an anon hash.
4458 *
4459 * XXX should probably propagate the outer expectation
4460 * into eval"" to rely less on this hack, but that could
4461 * potentially break current behavior of eval"".
4462 * GSAR 97-07-21
4463 */
4464 t = s;
4465 if (*s == '\'' || *s == '"' || *s == '`') {
4466 /* common case: get past first string, handling escapes */
3280af22 4467 for (t++; t < PL_bufend && *t != *s;)
b8a4b1be
GS
4468 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4469 t++;
4470 t++;
a0d0e21e 4471 }
b8a4b1be 4472 else if (*s == 'q') {
3280af22 4473 if (++t < PL_bufend
b8a4b1be 4474 && (!isALNUM(*t)
3280af22 4475 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
0505442f
GS
4476 && !isALNUM(*t))))
4477 {
abc667d1 4478 /* skip q//-like construct */
f54cb97a 4479 const char *tmps;
b8a4b1be
GS
4480 char open, close, term;
4481 I32 brackets = 1;
4482
3280af22 4483 while (t < PL_bufend && isSPACE(*t))
b8a4b1be 4484 t++;
abc667d1
DM
4485 /* check for q => */
4486 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4487 OPERATOR(HASHBRACK);
4488 }
b8a4b1be
GS
4489 term = *t;
4490 open = term;
4491 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4492 term = tmps[5];
4493 close = term;
4494 if (open == close)
3280af22
NIS
4495 for (t++; t < PL_bufend; t++) {
4496 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
b8a4b1be 4497 t++;
6d07e5e9 4498 else if (*t == open)
b8a4b1be
GS
4499 break;
4500 }
abc667d1 4501 else {
3280af22
NIS
4502 for (t++; t < PL_bufend; t++) {
4503 if (*t == '\\' && t+1 < PL_bufend)
b8a4b1be 4504 t++;
6d07e5e9 4505 else if (*t == close && --brackets <= 0)
b8a4b1be
GS
4506 break;
4507 else if (*t == open)
4508 brackets++;
4509 }
abc667d1
DM
4510 }
4511 t++;
b8a4b1be 4512 }
abc667d1
DM
4513 else
4514 /* skip plain q word */
4515 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4516 t += UTF8SKIP(t);
a0d0e21e 4517 }
7e2040f0 4518 else if (isALNUM_lazy_if(t,UTF)) {
0505442f 4519 t += UTF8SKIP(t);
7e2040f0 4520 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
0505442f 4521 t += UTF8SKIP(t);
a0d0e21e 4522 }
3280af22 4523 while (t < PL_bufend && isSPACE(*t))
a0d0e21e 4524 t++;
b8a4b1be
GS
4525 /* if comma follows first term, call it an anon hash */
4526 /* XXX it could be a comma expression with loop modifiers */
3280af22 4527 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
b8a4b1be 4528 || (*t == '=' && t[1] == '>')))
a0d0e21e 4529 OPERATOR(HASHBRACK);
3280af22 4530 if (PL_expect == XREF)
4e4e412b 4531 PL_expect = XTERM;
a0d0e21e 4532 else {
3280af22
NIS
4533 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4534 PL_expect = XSTATE;
a0d0e21e 4535 }
8990e307 4536 }
a0d0e21e 4537 break;
463ee0b2 4538 }
57843af0 4539 yylval.ival = CopLINE(PL_curcop);
79072805 4540 if (isSPACE(*s) || *s == '#')
3280af22 4541 PL_copline = NOLINE; /* invalidate current command line number */
79072805 4542 TOKEN('{');
378cc40b 4543 case '}':
79072805
LW
4544 rightbracket:
4545 s++;
3280af22 4546 if (PL_lex_brackets <= 0)
d98d5fff 4547 yyerror("Unmatched right curly bracket");
463ee0b2 4548 else
3280af22 4549 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
c2e66d9e 4550 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
3280af22
NIS
4551 PL_lex_formbrack = 0;
4552 if (PL_lex_state == LEX_INTERPNORMAL) {
4553 if (PL_lex_brackets == 0) {
9059aa12
LW
4554 if (PL_expect & XFAKEBRACK) {
4555 PL_expect &= XENUMMASK;
3280af22
NIS
4556 PL_lex_state = LEX_INTERPEND;
4557 PL_bufptr = s;
5db06880
NC
4558#if 0
4559 if (PL_madskills) {
cd81e915 4560 if (!PL_thiswhite)
6b29d1f5 4561 PL_thiswhite = newSVpvs("");
cd81e915 4562 sv_catpvn(PL_thiswhite,"}",1);
5db06880
NC
4563 }
4564#endif
cea2e8a9 4565 return yylex(); /* ignore fake brackets */
79072805 4566 }
fa83b5b6 4567 if (*s == '-' && s[1] == '>')
3280af22 4568 PL_lex_state = LEX_INTERPENDMAYBE;
fa83b5b6 4569 else if (*s != '[' && *s != '{')
3280af22 4570 PL_lex_state = LEX_INTERPEND;
79072805
LW
4571 }
4572 }
9059aa12
LW
4573 if (PL_expect & XFAKEBRACK) {
4574 PL_expect &= XENUMMASK;
3280af22 4575 PL_bufptr = s;
cea2e8a9 4576 return yylex(); /* ignore fake brackets */
748a9306 4577 }
cd81e915 4578 start_force(PL_curforce);
5db06880
NC
4579 if (PL_madskills) {
4580 curmad('X', newSVpvn(s-1,1));
cd81e915 4581 CURMAD('_', PL_thiswhite);
5db06880 4582 }
79072805 4583 force_next('}');
5db06880 4584#ifdef PERL_MAD
cd81e915 4585 if (!PL_thistoken)
6b29d1f5 4586 PL_thistoken = newSVpvs("");
5db06880 4587#endif
79072805 4588 TOKEN(';');
378cc40b
LW
4589 case '&':
4590 s++;
90771dc0 4591 if (*s++ == '&')
a0d0e21e 4592 AOPERATOR(ANDAND);
378cc40b 4593 s--;
3280af22 4594 if (PL_expect == XOPERATOR) {
041457d9
DM
4595 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4596 && isIDFIRST_lazy_if(s,UTF))
7e2040f0 4597 {
57843af0 4598 CopLINE_dec(PL_curcop);
9014280d 4599 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
57843af0 4600 CopLINE_inc(PL_curcop);
463ee0b2 4601 }
79072805 4602 BAop(OP_BIT_AND);
463ee0b2 4603 }
79072805 4604
3280af22
NIS
4605 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4606 if (*PL_tokenbuf) {
4607 PL_expect = XOPERATOR;
4608 force_ident(PL_tokenbuf, '&');
463ee0b2 4609 }
79072805
LW
4610 else
4611 PREREF('&');
c07a80fd 4612 yylval.ival = (OPpENTERSUB_AMPER<<8);
79072805
LW
4613 TERM('&');
4614
378cc40b
LW
4615 case '|':
4616 s++;
90771dc0 4617 if (*s++ == '|')
a0d0e21e 4618 AOPERATOR(OROR);
378cc40b 4619 s--;
79072805 4620 BOop(OP_BIT_OR);
378cc40b
LW
4621 case '=':
4622 s++;
748a9306 4623 {
90771dc0
NC
4624 const char tmp = *s++;
4625 if (tmp == '=')
4626 Eop(OP_EQ);
4627 if (tmp == '>')
4628 OPERATOR(',');
4629 if (tmp == '~')
4630 PMop(OP_MATCH);
4631 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4632 && strchr("+-*/%.^&|<",tmp))
4633 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4634 "Reversed %c= operator",(int)tmp);
4635 s--;
4636 if (PL_expect == XSTATE && isALPHA(tmp) &&
4637 (s == PL_linestart+1 || s[-2] == '\n') )
4638 {
4639 if (PL_in_eval && !PL_rsfp) {
4640 d = PL_bufend;
4641 while (s < d) {
4642 if (*s++ == '\n') {
4643 incline(s);
4644 if (strnEQ(s,"=cut",4)) {
4645 s = strchr(s,'\n');
4646 if (s)
4647 s++;
4648 else
4649 s = d;
4650 incline(s);
4651 goto retry;
4652 }
4653 }
a5f75d66 4654 }
90771dc0 4655 goto retry;
a5f75d66 4656 }
5db06880
NC
4657#ifdef PERL_MAD
4658 if (PL_madskills) {
cd81e915 4659 if (!PL_thiswhite)
6b29d1f5 4660 PL_thiswhite = newSVpvs("");
cd81e915 4661 sv_catpvn(PL_thiswhite, PL_linestart,
5db06880
NC
4662 PL_bufend - PL_linestart);
4663 }
4664#endif
90771dc0
NC
4665 s = PL_bufend;
4666 PL_doextract = TRUE;
4667 goto retry;
a5f75d66 4668 }
a0d0e21e 4669 }
3280af22 4670 if (PL_lex_brackets < PL_lex_formbrack) {
c35e046a 4671 const char *t = s;
51882d45 4672#ifdef PERL_STRICT_CR
c35e046a 4673 while (SPACE_OR_TAB(*t))
51882d45 4674#else
c35e046a 4675 while (SPACE_OR_TAB(*t) || *t == '\r')
51882d45 4676#endif
c35e046a 4677 t++;
a0d0e21e
LW
4678 if (*t == '\n' || *t == '#') {
4679 s--;
3280af22 4680 PL_expect = XBLOCK;
a0d0e21e
LW
4681 goto leftbracket;
4682 }
79072805 4683 }
a0d0e21e
LW
4684 yylval.ival = 0;
4685 OPERATOR(ASSIGNOP);
378cc40b
LW
4686 case '!':
4687 s++;
90771dc0
NC
4688 {
4689 const char tmp = *s++;
4690 if (tmp == '=') {
4691 /* was this !=~ where !~ was meant?
4692 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4693
4694 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4695 const char *t = s+1;
4696
4697 while (t < PL_bufend && isSPACE(*t))
4698 ++t;
4699
4700 if (*t == '/' || *t == '?' ||
4701 ((*t == 'm' || *t == 's' || *t == 'y')
4702 && !isALNUM(t[1])) ||
4703 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4704 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4705 "!=~ should be !~");
4706 }
4707 Eop(OP_NE);
4708 }
4709 if (tmp == '~')
4710 PMop(OP_NOT);
4711 }
378cc40b
LW
4712 s--;
4713 OPERATOR('!');
4714 case '<':
3280af22 4715 if (PL_expect != XOPERATOR) {
93a17b20 4716 if (s[1] != '<' && !strchr(s,'>'))
2f3197b3 4717 check_uni();
79072805
LW
4718 if (s[1] == '<')
4719 s = scan_heredoc(s);
4720 else
4721 s = scan_inputsymbol(s);
4722 TERM(sublex_start());
378cc40b
LW
4723 }
4724 s++;
90771dc0
NC
4725 {
4726 char tmp = *s++;
4727 if (tmp == '<')
4728 SHop(OP_LEFT_SHIFT);
4729 if (tmp == '=') {
4730 tmp = *s++;
4731 if (tmp == '>')
4732 Eop(OP_NCMP);
4733 s--;
4734 Rop(OP_LE);
4735 }
395c3793 4736 }
378cc40b 4737 s--;
79072805 4738 Rop(OP_LT);
378cc40b
LW
4739 case '>':
4740 s++;
90771dc0
NC
4741 {
4742 const char tmp = *s++;
4743 if (tmp == '>')
4744 SHop(OP_RIGHT_SHIFT);
d4c19fe8 4745 else if (tmp == '=')
90771dc0
NC
4746 Rop(OP_GE);
4747 }
378cc40b 4748 s--;
79072805 4749 Rop(OP_GT);
378cc40b
LW
4750
4751 case '$':
bbce6d69 4752 CLINE;
4753
3280af22
NIS
4754 if (PL_expect == XOPERATOR) {
4755 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4756 PL_expect = XTERM;
c445ea15 4757 deprecate_old(commaless_variable_list);
bbf60fe6 4758 return REPORT(','); /* grandfather non-comma-format format */
a0d0e21e 4759 }
8990e307 4760 }
a0d0e21e 4761
7e2040f0 4762 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
3280af22 4763 PL_tokenbuf[0] = '@';
376b8730
SM
4764 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4765 sizeof PL_tokenbuf - 1, FALSE);
4766 if (PL_expect == XOPERATOR)
4767 no_op("Array length", s);
3280af22 4768 if (!PL_tokenbuf[1])
a0d0e21e 4769 PREREF(DOLSHARP);
3280af22
NIS
4770 PL_expect = XOPERATOR;
4771 PL_pending_ident = '#';
463ee0b2 4772 TOKEN(DOLSHARP);
79072805 4773 }
bbce6d69 4774
3280af22 4775 PL_tokenbuf[0] = '$';
376b8730
SM
4776 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4777 sizeof PL_tokenbuf - 1, FALSE);
4778 if (PL_expect == XOPERATOR)
4779 no_op("Scalar", s);
3280af22
NIS
4780 if (!PL_tokenbuf[1]) {
4781 if (s == PL_bufend)
bbce6d69 4782 yyerror("Final $ should be \\$ or $name");
4783 PREREF('$');
8990e307 4784 }
a0d0e21e 4785
bbce6d69 4786 /* This kludge not intended to be bulletproof. */
3280af22 4787 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
bbce6d69 4788 yylval.opval = newSVOP(OP_CONST, 0,
fc15ae8f 4789 newSViv(CopARYBASE_get(&PL_compiling)));
bbce6d69 4790 yylval.opval->op_private = OPpCONST_ARYBASE;
4791 TERM(THING);
4792 }
4793
ff68c719 4794 d = s;
90771dc0
NC
4795 {
4796 const char tmp = *s;
4797 if (PL_lex_state == LEX_NORMAL)
29595ff2 4798 s = SKIPSPACE1(s);
ff68c719 4799
90771dc0
NC
4800 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4801 && intuit_more(s)) {
4802 if (*s == '[') {
4803 PL_tokenbuf[0] = '@';
4804 if (ckWARN(WARN_SYNTAX)) {
c35e046a
AL
4805 char *t = s+1;
4806
4807 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4808 t++;
90771dc0 4809 if (*t++ == ',') {
29595ff2 4810 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
90771dc0
NC
4811 while (t < PL_bufend && *t != ']')
4812 t++;
9014280d 4813 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
90771dc0 4814 "Multidimensional syntax %.*s not supported",
36c7798d 4815 (int)((t - PL_bufptr) + 1), PL_bufptr);
90771dc0 4816 }
748a9306 4817 }
93a17b20 4818 }
90771dc0
NC
4819 else if (*s == '{') {
4820 char *t;
4821 PL_tokenbuf[0] = '%';
4822 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4823 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4824 {
4825 char tmpbuf[sizeof PL_tokenbuf];
c35e046a
AL
4826 do {
4827 t++;
4828 } while (isSPACE(*t));
90771dc0 4829 if (isIDFIRST_lazy_if(t,UTF)) {
780a5241 4830 STRLEN len;
90771dc0 4831 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
780a5241 4832 &len);
c35e046a
AL
4833 while (isSPACE(*t))
4834 t++;
780a5241 4835 if (*t == ';' && get_cvn_flags(tmpbuf, len, 0))
90771dc0
NC
4836 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4837 "You need to quote \"%s\"",
4838 tmpbuf);
4839 }
4840 }
4841 }
93a17b20 4842 }
bbce6d69 4843
90771dc0
NC
4844 PL_expect = XOPERATOR;
4845 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4846 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4847 if (!islop || PL_last_lop_op == OP_GREPSTART)
4848 PL_expect = XOPERATOR;
4849 else if (strchr("$@\"'`q", *s))
4850 PL_expect = XTERM; /* e.g. print $fh "foo" */
4851 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4852 PL_expect = XTERM; /* e.g. print $fh &sub */
4853 else if (isIDFIRST_lazy_if(s,UTF)) {
4854 char tmpbuf[sizeof PL_tokenbuf];
4855 int t2;
4856 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5458a98a 4857 if ((t2 = keyword(tmpbuf, len, 0))) {
90771dc0
NC
4858 /* binary operators exclude handle interpretations */
4859 switch (t2) {
4860 case -KEY_x:
4861 case -KEY_eq:
4862 case -KEY_ne:
4863 case -KEY_gt:
4864 case -KEY_lt:
4865 case -KEY_ge:
4866 case -KEY_le:
4867 case -KEY_cmp:
4868 break;
4869 default:
4870 PL_expect = XTERM; /* e.g. print $fh length() */
4871 break;
4872 }
4873 }
4874 else {
4875 PL_expect = XTERM; /* e.g. print $fh subr() */
84902520
TB
4876 }
4877 }
90771dc0
NC
4878 else if (isDIGIT(*s))
4879 PL_expect = XTERM; /* e.g. print $fh 3 */
4880 else if (*s == '.' && isDIGIT(s[1]))
4881 PL_expect = XTERM; /* e.g. print $fh .3 */
4882 else if ((*s == '?' || *s == '-' || *s == '+')
4883 && !isSPACE(s[1]) && s[1] != '=')
4884 PL_expect = XTERM; /* e.g. print $fh -1 */
4885 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4886 && s[1] != '/')
4887 PL_expect = XTERM; /* e.g. print $fh /.../
4888 XXX except DORDOR operator
4889 */
4890 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4891 && s[2] != '=')
4892 PL_expect = XTERM; /* print $fh <<"EOF" */
93a17b20 4893 }
bbce6d69 4894 }
3280af22 4895 PL_pending_ident = '$';
79072805 4896 TOKEN('$');
378cc40b
LW
4897
4898 case '@':
3280af22 4899 if (PL_expect == XOPERATOR)
bbce6d69 4900 no_op("Array", s);
3280af22
NIS
4901 PL_tokenbuf[0] = '@';
4902 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
4903 if (!PL_tokenbuf[1]) {
bbce6d69 4904 PREREF('@');
4905 }
3280af22 4906 if (PL_lex_state == LEX_NORMAL)
29595ff2 4907 s = SKIPSPACE1(s);
3280af22 4908 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
bbce6d69 4909 if (*s == '{')
3280af22 4910 PL_tokenbuf[0] = '%';
a0d0e21e
LW
4911
4912 /* Warn about @ where they meant $. */
041457d9
DM
4913 if (*s == '[' || *s == '{') {
4914 if (ckWARN(WARN_SYNTAX)) {
f54cb97a 4915 const char *t = s + 1;
7e2040f0 4916 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
a0d0e21e
LW
4917 t++;
4918 if (*t == '}' || *t == ']') {
4919 t++;
29595ff2 4920 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
9014280d 4921 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
599cee73 4922 "Scalar value %.*s better written as $%.*s",
36c7798d
DM
4923 (int)(t-PL_bufptr), PL_bufptr,
4924 (int)(t-PL_bufptr-1), PL_bufptr+1);
a0d0e21e 4925 }
93a17b20
LW
4926 }
4927 }
463ee0b2 4928 }
3280af22 4929 PL_pending_ident = '@';
79072805 4930 TERM('@');
378cc40b 4931
c963b151 4932 case '/': /* may be division, defined-or, or pattern */
6f33ba73
RGS
4933 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
4934 s += 2;
4935 AOPERATOR(DORDOR);
4936 }
c963b151
BD
4937 case '?': /* may either be conditional or pattern */
4938 if(PL_expect == XOPERATOR) {
90771dc0 4939 char tmp = *s++;
c963b151
BD
4940 if(tmp == '?') {
4941 OPERATOR('?');
4942 }
4943 else {
4944 tmp = *s++;
4945 if(tmp == '/') {
4946 /* A // operator. */
4947 AOPERATOR(DORDOR);
4948 }
4949 else {
4950 s--;
4951 Mop(OP_DIVIDE);
4952 }
4953 }
4954 }
4955 else {
4956 /* Disable warning on "study /blah/" */
4957 if (PL_oldoldbufptr == PL_last_uni
4958 && (*PL_last_uni != 's' || s - PL_last_uni < 5
4959 || memNE(PL_last_uni, "study", 5)
4960 || isALNUM_lazy_if(PL_last_uni+5,UTF)
4961 ))
4962 check_uni();
4963 s = scan_pat(s,OP_MATCH);
4964 TERM(sublex_start());
4965 }
378cc40b
LW
4966
4967 case '.':
51882d45
GS
4968 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
4969#ifdef PERL_STRICT_CR
4970 && s[1] == '\n'
4971#else
4972 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
4973#endif
4974 && (s == PL_linestart || s[-1] == '\n') )
4975 {
3280af22
NIS
4976 PL_lex_formbrack = 0;
4977 PL_expect = XSTATE;
79072805
LW
4978 goto rightbracket;
4979 }
3280af22 4980 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
90771dc0 4981 char tmp = *s++;
a687059c
LW
4982 if (*s == tmp) {
4983 s++;
2f3197b3
LW
4984 if (*s == tmp) {
4985 s++;
79072805 4986 yylval.ival = OPf_SPECIAL;
2f3197b3
LW
4987 }
4988 else
79072805 4989 yylval.ival = 0;
378cc40b 4990 OPERATOR(DOTDOT);
a687059c 4991 }
3280af22 4992 if (PL_expect != XOPERATOR)
2f3197b3 4993 check_uni();
79072805 4994 Aop(OP_CONCAT);
378cc40b
LW
4995 }
4996 /* FALL THROUGH */
4997 case '0': case '1': case '2': case '3': case '4':
4998 case '5': case '6': case '7': case '8': case '9':
b73d6f50 4999 s = scan_num(s, &yylval);
931e0695 5000 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
3280af22 5001 if (PL_expect == XOPERATOR)
8990e307 5002 no_op("Number",s);
79072805
LW
5003 TERM(THING);
5004
5005 case '\'':
5db06880 5006 s = scan_str(s,!!PL_madskills,FALSE);
931e0695 5007 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
3280af22
NIS
5008 if (PL_expect == XOPERATOR) {
5009 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5010 PL_expect = XTERM;
c445ea15 5011 deprecate_old(commaless_variable_list);
bbf60fe6 5012 return REPORT(','); /* grandfather non-comma-format format */
a0d0e21e 5013 }
463ee0b2 5014 else
8990e307 5015 no_op("String",s);
463ee0b2 5016 }
79072805 5017 if (!s)
d4c19fe8 5018 missingterm(NULL);
79072805
LW
5019 yylval.ival = OP_CONST;
5020 TERM(sublex_start());
5021
5022 case '"':
5db06880 5023 s = scan_str(s,!!PL_madskills,FALSE);
931e0695 5024 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
3280af22
NIS
5025 if (PL_expect == XOPERATOR) {
5026 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5027 PL_expect = XTERM;
c445ea15 5028 deprecate_old(commaless_variable_list);
bbf60fe6 5029 return REPORT(','); /* grandfather non-comma-format format */
a0d0e21e 5030 }
463ee0b2 5031 else
8990e307 5032 no_op("String",s);
463ee0b2 5033 }
79072805 5034 if (!s)
d4c19fe8 5035 missingterm(NULL);
4633a7c4 5036 yylval.ival = OP_CONST;
cfd0369c
NC
5037 /* FIXME. I think that this can be const if char *d is replaced by
5038 more localised variables. */
3280af22 5039 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
63cd0674 5040 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
4633a7c4
LW
5041 yylval.ival = OP_STRINGIFY;
5042 break;
5043 }
5044 }
79072805
LW
5045 TERM(sublex_start());
5046
5047 case '`':
5db06880 5048 s = scan_str(s,!!PL_madskills,FALSE);
931e0695 5049 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
3280af22 5050 if (PL_expect == XOPERATOR)
8990e307 5051 no_op("Backticks",s);
79072805 5052 if (!s)
d4c19fe8 5053 missingterm(NULL);
9b201d7d 5054 readpipe_override();
79072805
LW
5055 TERM(sublex_start());
5056
5057 case '\\':
5058 s++;
041457d9 5059 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
9014280d 5060 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
599cee73 5061 *s, *s);
3280af22 5062 if (PL_expect == XOPERATOR)
8990e307 5063 no_op("Backslash",s);
79072805
LW
5064 OPERATOR(REFGEN);
5065
a7cb1f99 5066 case 'v':
e526c9e6 5067 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
f54cb97a 5068 char *start = s + 2;
dd629d5b 5069 while (isDIGIT(*start) || *start == '_')
a7cb1f99
GS
5070 start++;
5071 if (*start == '.' && isDIGIT(start[1])) {
b73d6f50 5072 s = scan_num(s, &yylval);
a7cb1f99
GS
5073 TERM(THING);
5074 }
e526c9e6 5075 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
6f33ba73
RGS
5076 else if (!isALPHA(*start) && (PL_expect == XTERM
5077 || PL_expect == XREF || PL_expect == XSTATE
5078 || PL_expect == XTERMORDORDOR)) {
d4c19fe8 5079 /* XXX Use gv_fetchpvn rather than stomping on a const string */
f54cb97a 5080 const char c = *start;
e526c9e6
GS
5081 GV *gv;
5082 *start = '\0';
f776e3cd 5083 gv = gv_fetchpv(s, 0, SVt_PVCV);
e526c9e6
GS
5084 *start = c;
5085 if (!gv) {
b73d6f50 5086 s = scan_num(s, &yylval);
e526c9e6
GS
5087 TERM(THING);
5088 }
5089 }
a7cb1f99
GS
5090 }
5091 goto keylookup;
79072805 5092 case 'x':
3280af22 5093 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
79072805
LW
5094 s++;
5095 Mop(OP_REPEAT);
2f3197b3 5096 }
79072805
LW
5097 goto keylookup;
5098
378cc40b 5099 case '_':
79072805
LW
5100 case 'a': case 'A':
5101 case 'b': case 'B':
5102 case 'c': case 'C':
5103 case 'd': case 'D':
5104 case 'e': case 'E':
5105 case 'f': case 'F':
5106 case 'g': case 'G':
5107 case 'h': case 'H':
5108 case 'i': case 'I':
5109 case 'j': case 'J':
5110 case 'k': case 'K':
5111 case 'l': case 'L':
5112 case 'm': case 'M':
5113 case 'n': case 'N':
5114 case 'o': case 'O':
5115 case 'p': case 'P':
5116 case 'q': case 'Q':
5117 case 'r': case 'R':
5118 case 's': case 'S':
5119 case 't': case 'T':
5120 case 'u': case 'U':
a7cb1f99 5121 case 'V':
79072805
LW
5122 case 'w': case 'W':
5123 case 'X':
5124 case 'y': case 'Y':
5125 case 'z': case 'Z':
5126
49dc05e3 5127 keylookup: {
90771dc0 5128 I32 tmp;
10edeb5d
JH
5129
5130 orig_keyword = 0;
5131 gv = NULL;
5132 gvp = NULL;
49dc05e3 5133
3280af22
NIS
5134 PL_bufptr = s;
5135 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
8ebc5c01 5136
5137 /* Some keywords can be followed by any delimiter, including ':' */
155aba94
GS
5138 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
5139 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
5140 (PL_tokenbuf[0] == 'q' &&
5141 strchr("qwxr", PL_tokenbuf[1])))));
8ebc5c01 5142
5143 /* x::* is just a word, unless x is "CORE" */
3280af22 5144 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
4633a7c4
LW
5145 goto just_a_word;
5146
3643fb5f 5147 d = s;
3280af22 5148 while (d < PL_bufend && isSPACE(*d))
3643fb5f
CS
5149 d++; /* no comments skipped here, or s### is misparsed */
5150
5151 /* Is this a label? */
3280af22
NIS
5152 if (!tmp && PL_expect == XSTATE
5153 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
8ebc5c01 5154 s = d + 1;
63031daf 5155 yylval.pval = CopLABEL_alloc(PL_tokenbuf);
8ebc5c01 5156 CLINE;
5157 TOKEN(LABEL);
3643fb5f
CS
5158 }
5159
5160 /* Check for keywords */
5458a98a 5161 tmp = keyword(PL_tokenbuf, len, 0);
748a9306
LW
5162
5163 /* Is this a word before a => operator? */
1c3923b3 5164 if (*d == '=' && d[1] == '>') {
748a9306 5165 CLINE;
d0a148a6
NC
5166 yylval.opval
5167 = (OP*)newSVOP(OP_CONST, 0,
5168 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
748a9306
LW
5169 yylval.opval->op_private = OPpCONST_BARE;
5170 TERM(WORD);
5171 }
5172
a0d0e21e 5173 if (tmp < 0) { /* second-class keyword? */
cbbf8932
AL
5174 GV *ogv = NULL; /* override (winner) */
5175 GV *hgv = NULL; /* hidden (loser) */
3280af22 5176 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
56f7f34b 5177 CV *cv;
90e5519e 5178 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
56f7f34b
CS
5179 (cv = GvCVu(gv)))
5180 {
5181 if (GvIMPORTED_CV(gv))
5182 ogv = gv;
5183 else if (! CvMETHOD(cv))
5184 hgv = gv;
5185 }
5186 if (!ogv &&
3280af22 5187 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
9e0d86f8 5188 (gv = *gvp) && isGV_with_GP(gv) &&
56f7f34b
CS
5189 GvCVu(gv) && GvIMPORTED_CV(gv))
5190 {
5191 ogv = gv;
5192 }
5193 }
5194 if (ogv) {
30fe34ed 5195 orig_keyword = tmp;
56f7f34b 5196 tmp = 0; /* overridden by import or by GLOBAL */
6e7b2336
GS
5197 }
5198 else if (gv && !gvp
5199 && -tmp==KEY_lock /* XXX generalizable kludge */
d0456cad 5200 && GvCVu(gv)
017a3ce5 5201 && !hv_fetchs(GvHVn(PL_incgv), "Thread.pm", FALSE))
6e7b2336
GS
5202 {
5203 tmp = 0; /* any sub overrides "weak" keyword */
a0d0e21e 5204 }
56f7f34b
CS
5205 else { /* no override */
5206 tmp = -tmp;
ac206dc8 5207 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
9014280d 5208 Perl_warner(aTHX_ packWARN(WARN_MISC),
ac206dc8
RGS
5209 "dump() better written as CORE::dump()");
5210 }
a0714e2c 5211 gv = NULL;
56f7f34b 5212 gvp = 0;
041457d9
DM
5213 if (hgv && tmp != KEY_x && tmp != KEY_CORE
5214 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
9014280d 5215 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
599cee73 5216 "Ambiguous call resolved as CORE::%s(), %s",
2f3ca594 5217 GvENAME(hgv), "qualify as such or use &");
49dc05e3 5218 }
a0d0e21e
LW
5219 }
5220
5221 reserved_word:
5222 switch (tmp) {
79072805
LW
5223
5224 default: /* not a keyword */
0bfa2a8a
NC
5225 /* Trade off - by using this evil construction we can pull the
5226 variable gv into the block labelled keylookup. If not, then
5227 we have to give it function scope so that the goto from the
5228 earlier ':' case doesn't bypass the initialisation. */
5229 if (0) {
5230 just_a_word_zero_gv:
5231 gv = NULL;
5232 gvp = NULL;
8bee0991 5233 orig_keyword = 0;
0bfa2a8a 5234 }
93a17b20 5235 just_a_word: {
96e4d5b1 5236 SV *sv;
ce29ac45 5237 int pkgname = 0;
f54cb97a 5238 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5069cc75 5239 CV *cv;
5db06880 5240#ifdef PERL_MAD
cd81e915 5241 SV *nextPL_nextwhite = 0;
5db06880
NC
5242#endif
5243
8990e307
LW
5244
5245 /* Get the rest if it looks like a package qualifier */
5246
155aba94 5247 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
c3e0f903 5248 STRLEN morelen;
3280af22 5249 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
c3e0f903
GS
5250 TRUE, &morelen);
5251 if (!morelen)
cea2e8a9 5252 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
ec2ab091 5253 *s == '\'' ? "'" : "::");
c3e0f903 5254 len += morelen;
ce29ac45 5255 pkgname = 1;
a0d0e21e 5256 }
8990e307 5257
3280af22
NIS
5258 if (PL_expect == XOPERATOR) {
5259 if (PL_bufptr == PL_linestart) {
57843af0 5260 CopLINE_dec(PL_curcop);
9014280d 5261 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
57843af0 5262 CopLINE_inc(PL_curcop);
463ee0b2
LW
5263 }
5264 else
54310121 5265 no_op("Bareword",s);
463ee0b2 5266 }
8990e307 5267
c3e0f903
GS
5268 /* Look for a subroutine with this name in current package,
5269 unless name is "Foo::", in which case Foo is a bearword
5270 (and a package name). */
5271
5db06880 5272 if (len > 2 && !PL_madskills &&
3280af22 5273 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
c3e0f903 5274 {
f776e3cd 5275 if (ckWARN(WARN_BAREWORD)
90e5519e 5276 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
9014280d 5277 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
599cee73 5278 "Bareword \"%s\" refers to nonexistent package",
3280af22 5279 PL_tokenbuf);
c3e0f903 5280 len -= 2;
3280af22 5281 PL_tokenbuf[len] = '\0';
a0714e2c 5282 gv = NULL;
c3e0f903
GS
5283 gvp = 0;
5284 }
5285 else {
62d55b22
NC
5286 if (!gv) {
5287 /* Mustn't actually add anything to a symbol table.
5288 But also don't want to "initialise" any placeholder
5289 constants that might already be there into full
5290 blown PVGVs with attached PVCV. */
90e5519e
NC
5291 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5292 GV_NOADD_NOINIT, SVt_PVCV);
62d55b22 5293 }
b3d904f3 5294 len = 0;
c3e0f903
GS
5295 }
5296
5297 /* if we saw a global override before, get the right name */
8990e307 5298
49dc05e3 5299 if (gvp) {
396482e1 5300 sv = newSVpvs("CORE::GLOBAL::");
3280af22 5301 sv_catpv(sv,PL_tokenbuf);
49dc05e3 5302 }
8a7a129d
NC
5303 else {
5304 /* If len is 0, newSVpv does strlen(), which is correct.
5305 If len is non-zero, then it will be the true length,
5306 and so the scalar will be created correctly. */
5307 sv = newSVpv(PL_tokenbuf,len);
5308 }
5db06880 5309#ifdef PERL_MAD
cd81e915
NC
5310 if (PL_madskills && !PL_thistoken) {
5311 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5312 PL_thistoken = newSVpv(start,s - start);
5313 PL_realtokenstart = s - SvPVX(PL_linestr);
5db06880
NC
5314 }
5315#endif
8990e307 5316
a0d0e21e
LW
5317 /* Presume this is going to be a bareword of some sort. */
5318
5319 CLINE;
49dc05e3 5320 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
a0d0e21e 5321 yylval.opval->op_private = OPpCONST_BARE;
8f8cf39c
JH
5322 /* UTF-8 package name? */
5323 if (UTF && !IN_BYTES &&
95a20fc0 5324 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
8f8cf39c 5325 SvUTF8_on(sv);
a0d0e21e 5326
c3e0f903
GS
5327 /* And if "Foo::", then that's what it certainly is. */
5328
5329 if (len)
5330 goto safe_bareword;
5331
5069cc75
NC
5332 /* Do the explicit type check so that we don't need to force
5333 the initialisation of the symbol table to have a real GV.
5334 Beware - gv may not really be a PVGV, cv may not really be
5335 a PVCV, (because of the space optimisations that gv_init
5336 understands) But they're true if for this symbol there is
5337 respectively a typeglob and a subroutine.
5338 */
5339 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5340 /* Real typeglob, so get the real subroutine: */
5341 ? GvCVu(gv)
5342 /* A proxy for a subroutine in this package? */
5343 : SvOK(gv) ? (CV *) gv : NULL)
5344 : NULL;
5345
8990e307
LW
5346 /* See if it's the indirect object for a list operator. */
5347
3280af22
NIS
5348 if (PL_oldoldbufptr &&
5349 PL_oldoldbufptr < PL_bufptr &&
65cec589
GS
5350 (PL_oldoldbufptr == PL_last_lop
5351 || PL_oldoldbufptr == PL_last_uni) &&
a0d0e21e 5352 /* NO SKIPSPACE BEFORE HERE! */
a9ef352a
GS
5353 (PL_expect == XREF ||
5354 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
a0d0e21e 5355 {
748a9306
LW
5356 bool immediate_paren = *s == '(';
5357
a0d0e21e 5358 /* (Now we can afford to cross potential line boundary.) */
cd81e915 5359 s = SKIPSPACE2(s,nextPL_nextwhite);
5db06880 5360#ifdef PERL_MAD
cd81e915 5361 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5db06880 5362#endif
a0d0e21e
LW
5363
5364 /* Two barewords in a row may indicate method call. */
5365
62d55b22
NC
5366 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5367 (tmp = intuit_method(s, gv, cv)))
bbf60fe6 5368 return REPORT(tmp);
a0d0e21e
LW
5369
5370 /* If not a declared subroutine, it's an indirect object. */
5371 /* (But it's an indir obj regardless for sort.) */
7294df96 5372 /* Also, if "_" follows a filetest operator, it's a bareword */
a0d0e21e 5373
7294df96
RGS
5374 if (
5375 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5069cc75 5376 ((!gv || !cv) &&
a9ef352a 5377 (PL_last_lop_op != OP_MAPSTART &&
f0670693 5378 PL_last_lop_op != OP_GREPSTART))))
7294df96
RGS
5379 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5380 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5381 )
a9ef352a 5382 {
3280af22 5383 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
748a9306 5384 goto bareword;
93a17b20
LW
5385 }
5386 }
8990e307 5387
3280af22 5388 PL_expect = XOPERATOR;
5db06880
NC
5389#ifdef PERL_MAD
5390 if (isSPACE(*s))
cd81e915
NC
5391 s = SKIPSPACE2(s,nextPL_nextwhite);
5392 PL_nextwhite = nextPL_nextwhite;
5db06880 5393#else
8990e307 5394 s = skipspace(s);
5db06880 5395#endif
1c3923b3
GS
5396
5397 /* Is this a word before a => operator? */
ce29ac45 5398 if (*s == '=' && s[1] == '>' && !pkgname) {
1c3923b3
GS
5399 CLINE;
5400 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
0064a8a9 5401 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
7948272d 5402 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
1c3923b3
GS
5403 TERM(WORD);
5404 }
5405
5406 /* If followed by a paren, it's certainly a subroutine. */
93a17b20 5407 if (*s == '(') {
79072805 5408 CLINE;
5069cc75 5409 if (cv) {
c35e046a
AL
5410 d = s + 1;
5411 while (SPACE_OR_TAB(*d))
5412 d++;
62d55b22 5413 if (*d == ')' && (sv = gv_const_sv(gv))) {
96e4d5b1 5414 s = d + 1;
5db06880
NC
5415#ifdef PERL_MAD
5416 if (PL_madskills) {
cd81e915
NC
5417 char *par = SvPVX(PL_linestr) + PL_realtokenstart;
5418 sv_catpvn(PL_thistoken, par, s - par);
5419 if (PL_nextwhite) {
5420 sv_free(PL_nextwhite);
5421 PL_nextwhite = 0;
5db06880
NC
5422 }
5423 }
36dee510 5424 else
5db06880 5425#endif
36dee510 5426 goto its_constant;
96e4d5b1 5427 }
5428 }
5db06880
NC
5429#ifdef PERL_MAD
5430 if (PL_madskills) {
cd81e915
NC
5431 PL_nextwhite = PL_thiswhite;
5432 PL_thiswhite = 0;
5db06880 5433 }
cd81e915 5434 start_force(PL_curforce);
5db06880 5435#endif
9ded7720 5436 NEXTVAL_NEXTTOKE.opval = yylval.opval;
3280af22 5437 PL_expect = XOPERATOR;
5db06880
NC
5438#ifdef PERL_MAD
5439 if (PL_madskills) {
cd81e915
NC
5440 PL_nextwhite = nextPL_nextwhite;
5441 curmad('X', PL_thistoken);
6b29d1f5 5442 PL_thistoken = newSVpvs("");
5db06880
NC
5443 }
5444#endif
93a17b20 5445 force_next(WORD);
c07a80fd 5446 yylval.ival = 0;
463ee0b2 5447 TOKEN('&');
79072805 5448 }
93a17b20 5449
a0d0e21e 5450 /* If followed by var or block, call it a method (unless sub) */
8990e307 5451
62d55b22 5452 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
3280af22
NIS
5453 PL_last_lop = PL_oldbufptr;
5454 PL_last_lop_op = OP_METHOD;
93a17b20 5455 PREBLOCK(METHOD);
463ee0b2
LW
5456 }
5457
8990e307
LW
5458 /* If followed by a bareword, see if it looks like indir obj. */
5459
30fe34ed
RGS
5460 if (!orig_keyword
5461 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
62d55b22 5462 && (tmp = intuit_method(s, gv, cv)))
bbf60fe6 5463 return REPORT(tmp);
93a17b20 5464
8990e307
LW
5465 /* Not a method, so call it a subroutine (if defined) */
5466
5069cc75 5467 if (cv) {
0453d815 5468 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
9014280d 5469 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
0453d815 5470 "Ambiguous use of -%s resolved as -&%s()",
3280af22 5471 PL_tokenbuf, PL_tokenbuf);
89bfa8cd 5472 /* Check for a constant sub */
36dee510 5473 if ((sv = gv_const_sv(gv)) && !PL_madskills) {
96e4d5b1 5474 its_constant:
5475 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
b37c2d43 5476 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
96e4d5b1 5477 yylval.opval->op_private = 0;
5478 TOKEN(WORD);
89bfa8cd 5479 }
5480
a5f75d66 5481 /* Resolve to GV now. */
62d55b22 5482 if (SvTYPE(gv) != SVt_PVGV) {
b3d904f3 5483 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
62d55b22
NC
5484 assert (SvTYPE(gv) == SVt_PVGV);
5485 /* cv must have been some sort of placeholder, so
5486 now needs replacing with a real code reference. */
5487 cv = GvCV(gv);
5488 }
5489
a5f75d66
AD
5490 op_free(yylval.opval);
5491 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
9675f7ac 5492 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
7a52d87a 5493 PL_last_lop = PL_oldbufptr;
bf848113 5494 PL_last_lop_op = OP_ENTERSUB;
4633a7c4 5495 /* Is there a prototype? */
5db06880
NC
5496 if (
5497#ifdef PERL_MAD
5498 cv &&
5499#endif
d9f2850e
RGS
5500 SvPOK(cv))
5501 {
5f66b61c
AL
5502 STRLEN protolen;
5503 const char *proto = SvPV_const((SV*)cv, protolen);
5504 if (!protolen)
4633a7c4 5505 TERM(FUNC0SUB);
8c28b960 5506 if ((*proto == '$' || *proto == '_') && proto[1] == '\0')
4633a7c4 5507 OPERATOR(UNIOPSUB);
0f5d0394
AE
5508 while (*proto == ';')
5509 proto++;
7a52d87a 5510 if (*proto == '&' && *s == '{') {
10edeb5d
JH
5511 sv_setpv(PL_subname,
5512 (const char *)
5513 (PL_curstash ?
5514 "__ANON__" : "__ANON__::__ANON__"));
4633a7c4
LW
5515 PREBLOCK(LSTOPSUB);
5516 }
a9ef352a 5517 }
5db06880
NC
5518#ifdef PERL_MAD
5519 {
5520 if (PL_madskills) {
cd81e915
NC
5521 PL_nextwhite = PL_thiswhite;
5522 PL_thiswhite = 0;
5db06880 5523 }
cd81e915 5524 start_force(PL_curforce);
5db06880
NC
5525 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5526 PL_expect = XTERM;
5527 if (PL_madskills) {
cd81e915
NC
5528 PL_nextwhite = nextPL_nextwhite;
5529 curmad('X', PL_thistoken);
6b29d1f5 5530 PL_thistoken = newSVpvs("");
5db06880
NC
5531 }
5532 force_next(WORD);
5533 TOKEN(NOAMP);
5534 }
5535 }
5536
5537 /* Guess harder when madskills require "best effort". */
5538 if (PL_madskills && (!gv || !GvCVu(gv))) {
5539 int probable_sub = 0;
5540 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5541 probable_sub = 1;
5542 else if (isALPHA(*s)) {
5543 char tmpbuf[1024];
5544 STRLEN tmplen;
5545 d = s;
5546 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5458a98a 5547 if (!keyword(tmpbuf, tmplen, 0))
5db06880
NC
5548 probable_sub = 1;
5549 else {
5550 while (d < PL_bufend && isSPACE(*d))
5551 d++;
5552 if (*d == '=' && d[1] == '>')
5553 probable_sub = 1;
5554 }
5555 }
5556 if (probable_sub) {
7a6d04f4 5557 gv = gv_fetchpv(PL_tokenbuf, GV_ADD, SVt_PVCV);
5db06880
NC
5558 op_free(yylval.opval);
5559 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5560 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5561 PL_last_lop = PL_oldbufptr;
5562 PL_last_lop_op = OP_ENTERSUB;
cd81e915
NC
5563 PL_nextwhite = PL_thiswhite;
5564 PL_thiswhite = 0;
5565 start_force(PL_curforce);
5db06880
NC
5566 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5567 PL_expect = XTERM;
cd81e915
NC
5568 PL_nextwhite = nextPL_nextwhite;
5569 curmad('X', PL_thistoken);
6b29d1f5 5570 PL_thistoken = newSVpvs("");
5db06880
NC
5571 force_next(WORD);
5572 TOKEN(NOAMP);
5573 }
5574#else
9ded7720 5575 NEXTVAL_NEXTTOKE.opval = yylval.opval;
3280af22 5576 PL_expect = XTERM;
8990e307
LW
5577 force_next(WORD);
5578 TOKEN(NOAMP);
5db06880 5579#endif
8990e307 5580 }
748a9306 5581
8990e307
LW
5582 /* Call it a bare word */
5583
5603f27d
GS
5584 if (PL_hints & HINT_STRICT_SUBS)
5585 yylval.opval->op_private |= OPpCONST_STRICT;
5586 else {
5587 bareword:
041457d9
DM
5588 if (lastchar != '-') {
5589 if (ckWARN(WARN_RESERVED)) {
c35e046a
AL
5590 d = PL_tokenbuf;
5591 while (isLOWER(*d))
5592 d++;
da51bb9b 5593 if (!*d && !gv_stashpv(PL_tokenbuf, 0))
9014280d 5594 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5603f27d
GS
5595 PL_tokenbuf);
5596 }
748a9306
LW
5597 }
5598 }
c3e0f903
GS
5599
5600 safe_bareword:
3792a11b
NC
5601 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5602 && ckWARN_d(WARN_AMBIGUOUS)) {
9014280d 5603 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
0453d815 5604 "Operator or semicolon missing before %c%s",
3280af22 5605 lastchar, PL_tokenbuf);
9014280d 5606 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
0453d815 5607 "Ambiguous use of %c resolved as operator %c",
748a9306
LW
5608 lastchar, lastchar);
5609 }
93a17b20 5610 TOKEN(WORD);
79072805 5611 }
79072805 5612
68dc0745 5613 case KEY___FILE__:
46fc3d4c 5614 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
ed094faf 5615 newSVpv(CopFILE(PL_curcop),0));
46fc3d4c 5616 TERM(THING);
5617
79072805 5618 case KEY___LINE__:
cf2093f6 5619 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
57843af0 5620 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
79072805 5621 TERM(THING);
68dc0745 5622
5623 case KEY___PACKAGE__:
5624 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
3280af22 5625 (PL_curstash
5aaec2b4 5626 ? newSVhek(HvNAME_HEK(PL_curstash))
3280af22 5627 : &PL_sv_undef));
79072805 5628 TERM(THING);
79072805 5629
e50aee73 5630 case KEY___DATA__:
79072805
LW
5631 case KEY___END__: {
5632 GV *gv;
3280af22 5633 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
bfed75c6 5634 const char *pname = "main";
3280af22 5635 if (PL_tokenbuf[2] == 'D')
bfcb3514 5636 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
f776e3cd
NC
5637 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5638 SVt_PVIO);
a5f75d66 5639 GvMULTI_on(gv);
79072805 5640 if (!GvIO(gv))
a0d0e21e 5641 GvIOp(gv) = newIO();
3280af22 5642 IoIFP(GvIOp(gv)) = PL_rsfp;
a0d0e21e
LW
5643#if defined(HAS_FCNTL) && defined(F_SETFD)
5644 {
f54cb97a 5645 const int fd = PerlIO_fileno(PL_rsfp);
a0d0e21e
LW
5646 fcntl(fd,F_SETFD,fd >= 3);
5647 }
79072805 5648#endif
fd049845 5649 /* Mark this internal pseudo-handle as clean */
5650 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
3280af22 5651 if (PL_preprocess)
50952442 5652 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
3280af22 5653 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
50952442 5654 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
79072805 5655 else
50952442 5656 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
c39cd008
GS
5657#if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5658 /* if the script was opened in binmode, we need to revert
53129d29 5659 * it to text mode for compatibility; but only iff it has CRs
c39cd008 5660 * XXX this is a questionable hack at best. */
53129d29
GS
5661 if (PL_bufend-PL_bufptr > 2
5662 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
c39cd008
GS
5663 {
5664 Off_t loc = 0;
50952442 5665 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
c39cd008
GS
5666 loc = PerlIO_tell(PL_rsfp);
5667 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5668 }
2986a63f
JH
5669#ifdef NETWARE
5670 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5671#else
c39cd008 5672 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
2986a63f 5673#endif /* NETWARE */
1143fce0
JH
5674#ifdef PERLIO_IS_STDIO /* really? */
5675# if defined(__BORLANDC__)
cb359b41
JH
5676 /* XXX see note in do_binmode() */
5677 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
1143fce0
JH
5678# endif
5679#endif
c39cd008
GS
5680 if (loc > 0)
5681 PerlIO_seek(PL_rsfp, loc, 0);
5682 }
5683 }
5684#endif
7948272d 5685#ifdef PERLIO_LAYERS
52d2e0f4
JH
5686 if (!IN_BYTES) {
5687 if (UTF)
5688 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5689 else if (PL_encoding) {
5690 SV *name;
5691 dSP;
5692 ENTER;
5693 SAVETMPS;
5694 PUSHMARK(sp);
5695 EXTEND(SP, 1);
5696 XPUSHs(PL_encoding);
5697 PUTBACK;
5698 call_method("name", G_SCALAR);
5699 SPAGAIN;
5700 name = POPs;
5701 PUTBACK;
bfed75c6 5702 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
52d2e0f4 5703 Perl_form(aTHX_ ":encoding(%"SVf")",
be2597df 5704 SVfARG(name)));
52d2e0f4
JH
5705 FREETMPS;
5706 LEAVE;
5707 }
5708 }
7948272d 5709#endif
5db06880
NC
5710#ifdef PERL_MAD
5711 if (PL_madskills) {
cd81e915
NC
5712 if (PL_realtokenstart >= 0) {
5713 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5714 if (!PL_endwhite)
6b29d1f5 5715 PL_endwhite = newSVpvs("");
cd81e915
NC
5716 sv_catsv(PL_endwhite, PL_thiswhite);
5717 PL_thiswhite = 0;
5718 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5719 PL_realtokenstart = -1;
5db06880 5720 }
cd81e915
NC
5721 while ((s = filter_gets(PL_endwhite, PL_rsfp,
5722 SvCUR(PL_endwhite))) != Nullch) ;
5db06880
NC
5723 }
5724#endif
4608196e 5725 PL_rsfp = NULL;
79072805
LW
5726 }
5727 goto fake_eof;
e929a76b 5728 }
de3bb511 5729
8990e307 5730 case KEY_AUTOLOAD:
ed6116ce 5731 case KEY_DESTROY:
79072805 5732 case KEY_BEGIN:
3c10abe3 5733 case KEY_UNITCHECK:
7d30b5c4 5734 case KEY_CHECK:
7d07dbc2 5735 case KEY_INIT:
7d30b5c4 5736 case KEY_END:
3280af22
NIS
5737 if (PL_expect == XSTATE) {
5738 s = PL_bufptr;
93a17b20 5739 goto really_sub;
79072805
LW
5740 }
5741 goto just_a_word;
5742
a0d0e21e
LW
5743 case KEY_CORE:
5744 if (*s == ':' && s[1] == ':') {
5745 s += 2;
748a9306 5746 d = s;
3280af22 5747 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5458a98a 5748 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
6798c92b 5749 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
a0d0e21e
LW
5750 if (tmp < 0)
5751 tmp = -tmp;
850e8516 5752 else if (tmp == KEY_require || tmp == KEY_do)
a72a1c8b 5753 /* that's a way to remember we saw "CORE::" */
850e8516 5754 orig_keyword = tmp;
a0d0e21e
LW
5755 goto reserved_word;
5756 }
5757 goto just_a_word;
5758
463ee0b2
LW
5759 case KEY_abs:
5760 UNI(OP_ABS);
5761
79072805
LW
5762 case KEY_alarm:
5763 UNI(OP_ALARM);
5764
5765 case KEY_accept:
a0d0e21e 5766 LOP(OP_ACCEPT,XTERM);
79072805 5767
463ee0b2
LW
5768 case KEY_and:
5769 OPERATOR(ANDOP);
5770
79072805 5771 case KEY_atan2:
a0d0e21e 5772 LOP(OP_ATAN2,XTERM);
85e6fe83 5773
79072805 5774 case KEY_bind:
a0d0e21e 5775 LOP(OP_BIND,XTERM);
79072805
LW
5776
5777 case KEY_binmode:
1c1fc3ea 5778 LOP(OP_BINMODE,XTERM);
79072805
LW
5779
5780 case KEY_bless:
a0d0e21e 5781 LOP(OP_BLESS,XTERM);
79072805 5782
0d863452
RH
5783 case KEY_break:
5784 FUN0(OP_BREAK);
5785
79072805
LW
5786 case KEY_chop:
5787 UNI(OP_CHOP);
5788
5789 case KEY_continue:
0d863452
RH
5790 /* When 'use switch' is in effect, continue has a dual
5791 life as a control operator. */
5792 {
ef89dcc3 5793 if (!FEATURE_IS_ENABLED("switch"))
0d863452
RH
5794 PREBLOCK(CONTINUE);
5795 else {
5796 /* We have to disambiguate the two senses of
5797 "continue". If the next token is a '{' then
5798 treat it as the start of a continue block;
5799 otherwise treat it as a control operator.
5800 */
5801 s = skipspace(s);
5802 if (*s == '{')
79072805 5803 PREBLOCK(CONTINUE);
0d863452
RH
5804 else
5805 FUN0(OP_CONTINUE);
5806 }
5807 }
79072805
LW
5808
5809 case KEY_chdir:
fafc274c
NC
5810 /* may use HOME */
5811 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
79072805
LW
5812 UNI(OP_CHDIR);
5813
5814 case KEY_close:
5815 UNI(OP_CLOSE);
5816
5817 case KEY_closedir:
5818 UNI(OP_CLOSEDIR);
5819
5820 case KEY_cmp:
5821 Eop(OP_SCMP);
5822
5823 case KEY_caller:
5824 UNI(OP_CALLER);
5825
5826 case KEY_crypt:
5827#ifdef FCRYPT
f4c556ac
GS
5828 if (!PL_cryptseen) {
5829 PL_cryptseen = TRUE;
de3bb511 5830 init_des();
f4c556ac 5831 }
a687059c 5832#endif
a0d0e21e 5833 LOP(OP_CRYPT,XTERM);
79072805
LW
5834
5835 case KEY_chmod:
a0d0e21e 5836 LOP(OP_CHMOD,XTERM);
79072805
LW
5837
5838 case KEY_chown:
a0d0e21e 5839 LOP(OP_CHOWN,XTERM);
79072805
LW
5840
5841 case KEY_connect:
a0d0e21e 5842 LOP(OP_CONNECT,XTERM);
79072805 5843
463ee0b2
LW
5844 case KEY_chr:
5845 UNI(OP_CHR);
5846
79072805
LW
5847 case KEY_cos:
5848 UNI(OP_COS);
5849
5850 case KEY_chroot:
5851 UNI(OP_CHROOT);
5852
0d863452
RH
5853 case KEY_default:
5854 PREBLOCK(DEFAULT);
5855
79072805 5856 case KEY_do:
29595ff2 5857 s = SKIPSPACE1(s);
79072805 5858 if (*s == '{')
a0d0e21e 5859 PRETERMBLOCK(DO);
79072805 5860 if (*s != '\'')
89c5585f 5861 s = force_word(s,WORD,TRUE,TRUE,FALSE);
850e8516
RGS
5862 if (orig_keyword == KEY_do) {
5863 orig_keyword = 0;
5864 yylval.ival = 1;
5865 }
5866 else
5867 yylval.ival = 0;
378cc40b 5868 OPERATOR(DO);
79072805
LW
5869
5870 case KEY_die:
3280af22 5871 PL_hints |= HINT_BLOCK_SCOPE;
a0d0e21e 5872 LOP(OP_DIE,XTERM);
79072805
LW
5873
5874 case KEY_defined:
5875 UNI(OP_DEFINED);
5876
5877 case KEY_delete:
a0d0e21e 5878 UNI(OP_DELETE);
79072805
LW
5879
5880 case KEY_dbmopen:
5c1737d1 5881 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
a0d0e21e 5882 LOP(OP_DBMOPEN,XTERM);
79072805
LW
5883
5884 case KEY_dbmclose:
5885 UNI(OP_DBMCLOSE);
5886
5887 case KEY_dump:
a0d0e21e 5888 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
5889 LOOPX(OP_DUMP);
5890
5891 case KEY_else:
5892 PREBLOCK(ELSE);
5893
5894 case KEY_elsif:
57843af0 5895 yylval.ival = CopLINE(PL_curcop);
79072805
LW
5896 OPERATOR(ELSIF);
5897
5898 case KEY_eq:
5899 Eop(OP_SEQ);
5900
a0d0e21e
LW
5901 case KEY_exists:
5902 UNI(OP_EXISTS);
4e553d73 5903
79072805 5904 case KEY_exit:
5db06880
NC
5905 if (PL_madskills)
5906 UNI(OP_INT);
79072805
LW
5907 UNI(OP_EXIT);
5908
5909 case KEY_eval:
29595ff2 5910 s = SKIPSPACE1(s);
3280af22 5911 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
463ee0b2 5912 UNIBRACK(OP_ENTEREVAL);
79072805
LW
5913
5914 case KEY_eof:
5915 UNI(OP_EOF);
5916
c963b151
BD
5917 case KEY_err:
5918 OPERATOR(DOROP);
5919
79072805
LW
5920 case KEY_exp:
5921 UNI(OP_EXP);
5922
5923 case KEY_each:
5924 UNI(OP_EACH);
5925
5926 case KEY_exec:
5927 set_csh();
a0d0e21e 5928 LOP(OP_EXEC,XREF);
79072805
LW
5929
5930 case KEY_endhostent:
5931 FUN0(OP_EHOSTENT);
5932
5933 case KEY_endnetent:
5934 FUN0(OP_ENETENT);
5935
5936 case KEY_endservent:
5937 FUN0(OP_ESERVENT);
5938
5939 case KEY_endprotoent:
5940 FUN0(OP_EPROTOENT);
5941
5942 case KEY_endpwent:
5943 FUN0(OP_EPWENT);
5944
5945 case KEY_endgrent:
5946 FUN0(OP_EGRENT);
5947
5948 case KEY_for:
5949 case KEY_foreach:
57843af0 5950 yylval.ival = CopLINE(PL_curcop);
29595ff2 5951 s = SKIPSPACE1(s);
7e2040f0 5952 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
55497cff 5953 char *p = s;
5db06880
NC
5954#ifdef PERL_MAD
5955 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5956#endif
5957
3280af22 5958 if ((PL_bufend - p) >= 3 &&
55497cff 5959 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5960 p += 2;
77ca0c92
LW
5961 else if ((PL_bufend - p) >= 4 &&
5962 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5963 p += 3;
29595ff2 5964 p = PEEKSPACE(p);
7e2040f0 5965 if (isIDFIRST_lazy_if(p,UTF)) {
77ca0c92
LW
5966 p = scan_ident(p, PL_bufend,
5967 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
29595ff2 5968 p = PEEKSPACE(p);
77ca0c92
LW
5969 }
5970 if (*p != '$')
cea2e8a9 5971 Perl_croak(aTHX_ "Missing $ on loop variable");
5db06880
NC
5972#ifdef PERL_MAD
5973 s = SvPVX(PL_linestr) + soff;
5974#endif
55497cff 5975 }
79072805
LW
5976 OPERATOR(FOR);
5977
5978 case KEY_formline:
a0d0e21e 5979 LOP(OP_FORMLINE,XTERM);
79072805
LW
5980
5981 case KEY_fork:
5982 FUN0(OP_FORK);
5983
5984 case KEY_fcntl:
a0d0e21e 5985 LOP(OP_FCNTL,XTERM);
79072805
LW
5986
5987 case KEY_fileno:
5988 UNI(OP_FILENO);
5989
5990 case KEY_flock:
a0d0e21e 5991 LOP(OP_FLOCK,XTERM);
79072805
LW
5992
5993 case KEY_gt:
5994 Rop(OP_SGT);
5995
5996 case KEY_ge:
5997 Rop(OP_SGE);
5998
5999 case KEY_grep:
2c38e13d 6000 LOP(OP_GREPSTART, XREF);
79072805
LW
6001
6002 case KEY_goto:
a0d0e21e 6003 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
6004 LOOPX(OP_GOTO);
6005
6006 case KEY_gmtime:
6007 UNI(OP_GMTIME);
6008
6009 case KEY_getc:
6f33ba73 6010 UNIDOR(OP_GETC);
79072805
LW
6011
6012 case KEY_getppid:
6013 FUN0(OP_GETPPID);
6014
6015 case KEY_getpgrp:
6016 UNI(OP_GETPGRP);
6017
6018 case KEY_getpriority:
a0d0e21e 6019 LOP(OP_GETPRIORITY,XTERM);
79072805
LW
6020
6021 case KEY_getprotobyname:
6022 UNI(OP_GPBYNAME);
6023
6024 case KEY_getprotobynumber:
a0d0e21e 6025 LOP(OP_GPBYNUMBER,XTERM);
79072805
LW
6026
6027 case KEY_getprotoent:
6028 FUN0(OP_GPROTOENT);
6029
6030 case KEY_getpwent:
6031 FUN0(OP_GPWENT);
6032
6033 case KEY_getpwnam:
ff68c719 6034 UNI(OP_GPWNAM);
79072805
LW
6035
6036 case KEY_getpwuid:
ff68c719 6037 UNI(OP_GPWUID);
79072805
LW
6038
6039 case KEY_getpeername:
6040 UNI(OP_GETPEERNAME);
6041
6042 case KEY_gethostbyname:
6043 UNI(OP_GHBYNAME);
6044
6045 case KEY_gethostbyaddr:
a0d0e21e 6046 LOP(OP_GHBYADDR,XTERM);
79072805
LW
6047
6048 case KEY_gethostent:
6049 FUN0(OP_GHOSTENT);
6050
6051 case KEY_getnetbyname:
6052 UNI(OP_GNBYNAME);
6053
6054 case KEY_getnetbyaddr:
a0d0e21e 6055 LOP(OP_GNBYADDR,XTERM);
79072805
LW
6056
6057 case KEY_getnetent:
6058 FUN0(OP_GNETENT);
6059
6060 case KEY_getservbyname:
a0d0e21e 6061 LOP(OP_GSBYNAME,XTERM);
79072805
LW
6062
6063 case KEY_getservbyport:
a0d0e21e 6064 LOP(OP_GSBYPORT,XTERM);
79072805
LW
6065
6066 case KEY_getservent:
6067 FUN0(OP_GSERVENT);
6068
6069 case KEY_getsockname:
6070 UNI(OP_GETSOCKNAME);
6071
6072 case KEY_getsockopt:
a0d0e21e 6073 LOP(OP_GSOCKOPT,XTERM);
79072805
LW
6074
6075 case KEY_getgrent:
6076 FUN0(OP_GGRENT);
6077
6078 case KEY_getgrnam:
ff68c719 6079 UNI(OP_GGRNAM);
79072805
LW
6080
6081 case KEY_getgrgid:
ff68c719 6082 UNI(OP_GGRGID);
79072805
LW
6083
6084 case KEY_getlogin:
6085 FUN0(OP_GETLOGIN);
6086
0d863452
RH
6087 case KEY_given:
6088 yylval.ival = CopLINE(PL_curcop);
6089 OPERATOR(GIVEN);
6090
93a17b20 6091 case KEY_glob:
a0d0e21e
LW
6092 set_csh();
6093 LOP(OP_GLOB,XTERM);
93a17b20 6094
79072805
LW
6095 case KEY_hex:
6096 UNI(OP_HEX);
6097
6098 case KEY_if:
57843af0 6099 yylval.ival = CopLINE(PL_curcop);
79072805
LW
6100 OPERATOR(IF);
6101
6102 case KEY_index:
a0d0e21e 6103 LOP(OP_INDEX,XTERM);
79072805
LW
6104
6105 case KEY_int:
6106 UNI(OP_INT);
6107
6108 case KEY_ioctl:
a0d0e21e 6109 LOP(OP_IOCTL,XTERM);
79072805
LW
6110
6111 case KEY_join:
a0d0e21e 6112 LOP(OP_JOIN,XTERM);
79072805
LW
6113
6114 case KEY_keys:
6115 UNI(OP_KEYS);
6116
6117 case KEY_kill:
a0d0e21e 6118 LOP(OP_KILL,XTERM);
79072805
LW
6119
6120 case KEY_last:
a0d0e21e 6121 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805 6122 LOOPX(OP_LAST);
4e553d73 6123
79072805
LW
6124 case KEY_lc:
6125 UNI(OP_LC);
6126
6127 case KEY_lcfirst:
6128 UNI(OP_LCFIRST);
6129
6130 case KEY_local:
09bef843 6131 yylval.ival = 0;
79072805
LW
6132 OPERATOR(LOCAL);
6133
6134 case KEY_length:
6135 UNI(OP_LENGTH);
6136
6137 case KEY_lt:
6138 Rop(OP_SLT);
6139
6140 case KEY_le:
6141 Rop(OP_SLE);
6142
6143 case KEY_localtime:
6144 UNI(OP_LOCALTIME);
6145
6146 case KEY_log:
6147 UNI(OP_LOG);
6148
6149 case KEY_link:
a0d0e21e 6150 LOP(OP_LINK,XTERM);
79072805
LW
6151
6152 case KEY_listen:
a0d0e21e 6153 LOP(OP_LISTEN,XTERM);
79072805 6154
c0329465
MB
6155 case KEY_lock:
6156 UNI(OP_LOCK);
6157
79072805
LW
6158 case KEY_lstat:
6159 UNI(OP_LSTAT);
6160
6161 case KEY_m:
8782bef2 6162 s = scan_pat(s,OP_MATCH);
79072805
LW
6163 TERM(sublex_start());
6164
a0d0e21e 6165 case KEY_map:
2c38e13d 6166 LOP(OP_MAPSTART, XREF);
4e4e412b 6167
79072805 6168 case KEY_mkdir:
a0d0e21e 6169 LOP(OP_MKDIR,XTERM);
79072805
LW
6170
6171 case KEY_msgctl:
a0d0e21e 6172 LOP(OP_MSGCTL,XTERM);
79072805
LW
6173
6174 case KEY_msgget:
a0d0e21e 6175 LOP(OP_MSGGET,XTERM);
79072805
LW
6176
6177 case KEY_msgrcv:
a0d0e21e 6178 LOP(OP_MSGRCV,XTERM);
79072805
LW
6179
6180 case KEY_msgsnd:
a0d0e21e 6181 LOP(OP_MSGSND,XTERM);
79072805 6182
77ca0c92 6183 case KEY_our:
93a17b20 6184 case KEY_my:
952306ac 6185 case KEY_state:
77ca0c92 6186 PL_in_my = tmp;
29595ff2 6187 s = SKIPSPACE1(s);
7e2040f0 6188 if (isIDFIRST_lazy_if(s,UTF)) {
5db06880
NC
6189#ifdef PERL_MAD
6190 char* start = s;
6191#endif
3280af22 6192 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
09bef843
SB
6193 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
6194 goto really_sub;
def3634b 6195 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
3280af22 6196 if (!PL_in_my_stash) {
c750a3ec 6197 char tmpbuf[1024];
3280af22 6198 PL_bufptr = s;
d9fad198 6199 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
c750a3ec
MB
6200 yyerror(tmpbuf);
6201 }
5db06880
NC
6202#ifdef PERL_MAD
6203 if (PL_madskills) { /* just add type to declarator token */
cd81e915
NC
6204 sv_catsv(PL_thistoken, PL_nextwhite);
6205 PL_nextwhite = 0;
6206 sv_catpvn(PL_thistoken, start, s - start);
5db06880
NC
6207 }
6208#endif
c750a3ec 6209 }
09bef843 6210 yylval.ival = 1;
55497cff 6211 OPERATOR(MY);
93a17b20 6212
79072805 6213 case KEY_next:
a0d0e21e 6214 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
6215 LOOPX(OP_NEXT);
6216
6217 case KEY_ne:
6218 Eop(OP_SNE);
6219
a0d0e21e 6220 case KEY_no:
468aa647 6221 s = tokenize_use(0, s);
a0d0e21e
LW
6222 OPERATOR(USE);
6223
6224 case KEY_not:
29595ff2 6225 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
2d2e263d
LW
6226 FUN1(OP_NOT);
6227 else
6228 OPERATOR(NOTOP);
a0d0e21e 6229
79072805 6230 case KEY_open:
29595ff2 6231 s = SKIPSPACE1(s);
7e2040f0 6232 if (isIDFIRST_lazy_if(s,UTF)) {
f54cb97a 6233 const char *t;
c35e046a
AL
6234 for (d = s; isALNUM_lazy_if(d,UTF);)
6235 d++;
6236 for (t=d; isSPACE(*t);)
6237 t++;
e2ab214b 6238 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
66fbe8fb
HS
6239 /* [perl #16184] */
6240 && !(t[0] == '=' && t[1] == '>')
6241 ) {
5f66b61c 6242 int parms_len = (int)(d-s);
9014280d 6243 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
0453d815 6244 "Precedence problem: open %.*s should be open(%.*s)",
5f66b61c 6245 parms_len, s, parms_len, s);
66fbe8fb 6246 }
93a17b20 6247 }
a0d0e21e 6248 LOP(OP_OPEN,XTERM);
79072805 6249
463ee0b2 6250 case KEY_or:
a0d0e21e 6251 yylval.ival = OP_OR;
463ee0b2
LW
6252 OPERATOR(OROP);
6253
79072805
LW
6254 case KEY_ord:
6255 UNI(OP_ORD);
6256
6257 case KEY_oct:
6258 UNI(OP_OCT);
6259
6260 case KEY_opendir:
a0d0e21e 6261 LOP(OP_OPEN_DIR,XTERM);
79072805
LW
6262
6263 case KEY_print:
3280af22 6264 checkcomma(s,PL_tokenbuf,"filehandle");
a0d0e21e 6265 LOP(OP_PRINT,XREF);
79072805
LW
6266
6267 case KEY_printf:
3280af22 6268 checkcomma(s,PL_tokenbuf,"filehandle");
a0d0e21e 6269 LOP(OP_PRTF,XREF);
79072805 6270
c07a80fd 6271 case KEY_prototype:
6272 UNI(OP_PROTOTYPE);
6273
79072805 6274 case KEY_push:
a0d0e21e 6275 LOP(OP_PUSH,XTERM);
79072805
LW
6276
6277 case KEY_pop:
6f33ba73 6278 UNIDOR(OP_POP);
79072805 6279
a0d0e21e 6280 case KEY_pos:
6f33ba73 6281 UNIDOR(OP_POS);
4e553d73 6282
79072805 6283 case KEY_pack:
a0d0e21e 6284 LOP(OP_PACK,XTERM);
79072805
LW
6285
6286 case KEY_package:
a0d0e21e 6287 s = force_word(s,WORD,FALSE,TRUE,FALSE);
79072805
LW
6288 OPERATOR(PACKAGE);
6289
6290 case KEY_pipe:
a0d0e21e 6291 LOP(OP_PIPE_OP,XTERM);
79072805
LW
6292
6293 case KEY_q:
5db06880 6294 s = scan_str(s,!!PL_madskills,FALSE);
79072805 6295 if (!s)
d4c19fe8 6296 missingterm(NULL);
79072805
LW
6297 yylval.ival = OP_CONST;
6298 TERM(sublex_start());
6299
a0d0e21e
LW
6300 case KEY_quotemeta:
6301 UNI(OP_QUOTEMETA);
6302
8990e307 6303 case KEY_qw:
5db06880 6304 s = scan_str(s,!!PL_madskills,FALSE);
8990e307 6305 if (!s)
d4c19fe8 6306 missingterm(NULL);
3480a8d2 6307 PL_expect = XOPERATOR;
8127e0e3
GS
6308 force_next(')');
6309 if (SvCUR(PL_lex_stuff)) {
5f66b61c 6310 OP *words = NULL;
8127e0e3 6311 int warned = 0;
3280af22 6312 d = SvPV_force(PL_lex_stuff, len);
8127e0e3 6313 while (len) {
d4c19fe8
AL
6314 for (; isSPACE(*d) && len; --len, ++d)
6315 /**/;
8127e0e3 6316 if (len) {
d4c19fe8 6317 SV *sv;
f54cb97a 6318 const char *b = d;
e476b1b5 6319 if (!warned && ckWARN(WARN_QW)) {
8127e0e3
GS
6320 for (; !isSPACE(*d) && len; --len, ++d) {
6321 if (*d == ',') {
9014280d 6322 Perl_warner(aTHX_ packWARN(WARN_QW),
8127e0e3
GS
6323 "Possible attempt to separate words with commas");
6324 ++warned;
6325 }
6326 else if (*d == '#') {
9014280d 6327 Perl_warner(aTHX_ packWARN(WARN_QW),
8127e0e3
GS
6328 "Possible attempt to put comments in qw() list");
6329 ++warned;
6330 }
6331 }
6332 }
6333 else {
d4c19fe8
AL
6334 for (; !isSPACE(*d) && len; --len, ++d)
6335 /**/;
8127e0e3 6336 }
7948272d
NIS
6337 sv = newSVpvn(b, d-b);
6338 if (DO_UTF8(PL_lex_stuff))
6339 SvUTF8_on(sv);
8127e0e3 6340 words = append_elem(OP_LIST, words,
7948272d 6341 newSVOP(OP_CONST, 0, tokeq(sv)));
55497cff 6342 }
6343 }
8127e0e3 6344 if (words) {
cd81e915 6345 start_force(PL_curforce);
9ded7720 6346 NEXTVAL_NEXTTOKE.opval = words;
8127e0e3
GS
6347 force_next(THING);
6348 }
55497cff 6349 }
37fd879b 6350 if (PL_lex_stuff) {
8127e0e3 6351 SvREFCNT_dec(PL_lex_stuff);
a0714e2c 6352 PL_lex_stuff = NULL;
37fd879b 6353 }
3280af22 6354 PL_expect = XTERM;
8127e0e3 6355 TOKEN('(');
8990e307 6356
79072805 6357 case KEY_qq:
5db06880 6358 s = scan_str(s,!!PL_madskills,FALSE);
79072805 6359 if (!s)
d4c19fe8 6360 missingterm(NULL);
a0d0e21e 6361 yylval.ival = OP_STRINGIFY;
3280af22 6362 if (SvIVX(PL_lex_stuff) == '\'')
45977657 6363 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
79072805
LW
6364 TERM(sublex_start());
6365
8782bef2
GB
6366 case KEY_qr:
6367 s = scan_pat(s,OP_QR);
6368 TERM(sublex_start());
6369
79072805 6370 case KEY_qx:
5db06880 6371 s = scan_str(s,!!PL_madskills,FALSE);
79072805 6372 if (!s)
d4c19fe8 6373 missingterm(NULL);
9b201d7d 6374 readpipe_override();
79072805
LW
6375 TERM(sublex_start());
6376
6377 case KEY_return:
6378 OLDLOP(OP_RETURN);
6379
6380 case KEY_require:
29595ff2 6381 s = SKIPSPACE1(s);
e759cc13
RGS
6382 if (isDIGIT(*s)) {
6383 s = force_version(s, FALSE);
a7cb1f99 6384 }
e759cc13
RGS
6385 else if (*s != 'v' || !isDIGIT(s[1])
6386 || (s = force_version(s, TRUE), *s == 'v'))
6387 {
a7cb1f99
GS
6388 *PL_tokenbuf = '\0';
6389 s = force_word(s,WORD,TRUE,TRUE,FALSE);
7e2040f0 6390 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
da51bb9b 6391 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), GV_ADD);
a7cb1f99
GS
6392 else if (*s == '<')
6393 yyerror("<> should be quotes");
6394 }
a72a1c8b
RGS
6395 if (orig_keyword == KEY_require) {
6396 orig_keyword = 0;
6397 yylval.ival = 1;
6398 }
6399 else
6400 yylval.ival = 0;
6401 PL_expect = XTERM;
6402 PL_bufptr = s;
6403 PL_last_uni = PL_oldbufptr;
6404 PL_last_lop_op = OP_REQUIRE;
6405 s = skipspace(s);
6406 return REPORT( (int)REQUIRE );
79072805
LW
6407
6408 case KEY_reset:
6409 UNI(OP_RESET);
6410
6411 case KEY_redo:
a0d0e21e 6412 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
6413 LOOPX(OP_REDO);
6414
6415 case KEY_rename:
a0d0e21e 6416 LOP(OP_RENAME,XTERM);
79072805
LW
6417
6418 case KEY_rand:
6419 UNI(OP_RAND);
6420
6421 case KEY_rmdir:
6422 UNI(OP_RMDIR);
6423
6424 case KEY_rindex:
a0d0e21e 6425 LOP(OP_RINDEX,XTERM);
79072805
LW
6426
6427 case KEY_read:
a0d0e21e 6428 LOP(OP_READ,XTERM);
79072805
LW
6429
6430 case KEY_readdir:
6431 UNI(OP_READDIR);
6432
93a17b20
LW
6433 case KEY_readline:
6434 set_csh();
6f33ba73 6435 UNIDOR(OP_READLINE);
93a17b20
LW
6436
6437 case KEY_readpipe:
6438 set_csh();
0858480c 6439 UNIDOR(OP_BACKTICK);
93a17b20 6440
79072805
LW
6441 case KEY_rewinddir:
6442 UNI(OP_REWINDDIR);
6443
6444 case KEY_recv:
a0d0e21e 6445 LOP(OP_RECV,XTERM);
79072805
LW
6446
6447 case KEY_reverse:
a0d0e21e 6448 LOP(OP_REVERSE,XTERM);
79072805
LW
6449
6450 case KEY_readlink:
6f33ba73 6451 UNIDOR(OP_READLINK);
79072805
LW
6452
6453 case KEY_ref:
6454 UNI(OP_REF);
6455
6456 case KEY_s:
6457 s = scan_subst(s);
6458 if (yylval.opval)
6459 TERM(sublex_start());
6460 else
6461 TOKEN(1); /* force error */
6462
0d863452
RH
6463 case KEY_say:
6464 checkcomma(s,PL_tokenbuf,"filehandle");
6465 LOP(OP_SAY,XREF);
6466
a0d0e21e
LW
6467 case KEY_chomp:
6468 UNI(OP_CHOMP);
4e553d73 6469
79072805
LW
6470 case KEY_scalar:
6471 UNI(OP_SCALAR);
6472
6473 case KEY_select:
a0d0e21e 6474 LOP(OP_SELECT,XTERM);
79072805
LW
6475
6476 case KEY_seek:
a0d0e21e 6477 LOP(OP_SEEK,XTERM);
79072805
LW
6478
6479 case KEY_semctl:
a0d0e21e 6480 LOP(OP_SEMCTL,XTERM);
79072805
LW
6481
6482 case KEY_semget:
a0d0e21e 6483 LOP(OP_SEMGET,XTERM);
79072805
LW
6484
6485 case KEY_semop:
a0d0e21e 6486 LOP(OP_SEMOP,XTERM);
79072805
LW
6487
6488 case KEY_send:
a0d0e21e 6489 LOP(OP_SEND,XTERM);
79072805
LW
6490
6491 case KEY_setpgrp:
a0d0e21e 6492 LOP(OP_SETPGRP,XTERM);
79072805
LW
6493
6494 case KEY_setpriority:
a0d0e21e 6495 LOP(OP_SETPRIORITY,XTERM);
79072805
LW
6496
6497 case KEY_sethostent:
ff68c719 6498 UNI(OP_SHOSTENT);
79072805
LW
6499
6500 case KEY_setnetent:
ff68c719 6501 UNI(OP_SNETENT);
79072805
LW
6502
6503 case KEY_setservent:
ff68c719 6504 UNI(OP_SSERVENT);
79072805
LW
6505
6506 case KEY_setprotoent:
ff68c719 6507 UNI(OP_SPROTOENT);
79072805
LW
6508
6509 case KEY_setpwent:
6510 FUN0(OP_SPWENT);
6511
6512 case KEY_setgrent:
6513 FUN0(OP_SGRENT);
6514
6515 case KEY_seekdir:
a0d0e21e 6516 LOP(OP_SEEKDIR,XTERM);
79072805
LW
6517
6518 case KEY_setsockopt:
a0d0e21e 6519 LOP(OP_SSOCKOPT,XTERM);
79072805
LW
6520
6521 case KEY_shift:
6f33ba73 6522 UNIDOR(OP_SHIFT);
79072805
LW
6523
6524 case KEY_shmctl:
a0d0e21e 6525 LOP(OP_SHMCTL,XTERM);
79072805
LW
6526
6527 case KEY_shmget:
a0d0e21e 6528 LOP(OP_SHMGET,XTERM);
79072805
LW
6529
6530 case KEY_shmread:
a0d0e21e 6531 LOP(OP_SHMREAD,XTERM);
79072805
LW
6532
6533 case KEY_shmwrite:
a0d0e21e 6534 LOP(OP_SHMWRITE,XTERM);
79072805
LW
6535
6536 case KEY_shutdown:
a0d0e21e 6537 LOP(OP_SHUTDOWN,XTERM);
79072805
LW
6538
6539 case KEY_sin:
6540 UNI(OP_SIN);
6541
6542 case KEY_sleep:
6543 UNI(OP_SLEEP);
6544
6545 case KEY_socket:
a0d0e21e 6546 LOP(OP_SOCKET,XTERM);
79072805
LW
6547
6548 case KEY_socketpair:
a0d0e21e 6549 LOP(OP_SOCKPAIR,XTERM);
79072805
LW
6550
6551 case KEY_sort:
3280af22 6552 checkcomma(s,PL_tokenbuf,"subroutine name");
29595ff2 6553 s = SKIPSPACE1(s);
79072805 6554 if (*s == ';' || *s == ')') /* probably a close */
cea2e8a9 6555 Perl_croak(aTHX_ "sort is now a reserved word");
3280af22 6556 PL_expect = XTERM;
15f0808c 6557 s = force_word(s,WORD,TRUE,TRUE,FALSE);
a0d0e21e 6558 LOP(OP_SORT,XREF);
79072805
LW
6559
6560 case KEY_split:
a0d0e21e 6561 LOP(OP_SPLIT,XTERM);
79072805
LW
6562
6563 case KEY_sprintf:
a0d0e21e 6564 LOP(OP_SPRINTF,XTERM);
79072805
LW
6565
6566 case KEY_splice:
a0d0e21e 6567 LOP(OP_SPLICE,XTERM);
79072805
LW
6568
6569 case KEY_sqrt:
6570 UNI(OP_SQRT);
6571
6572 case KEY_srand:
6573 UNI(OP_SRAND);
6574
6575 case KEY_stat:
6576 UNI(OP_STAT);
6577
6578 case KEY_study:
79072805
LW
6579 UNI(OP_STUDY);
6580
6581 case KEY_substr:
a0d0e21e 6582 LOP(OP_SUBSTR,XTERM);
79072805
LW
6583
6584 case KEY_format:
6585 case KEY_sub:
93a17b20 6586 really_sub:
09bef843 6587 {
3280af22 6588 char tmpbuf[sizeof PL_tokenbuf];
9c5ffd7c 6589 SSize_t tboffset = 0;
09bef843 6590 expectation attrful;
28cc6278 6591 bool have_name, have_proto;
f54cb97a 6592 const int key = tmp;
09bef843 6593
5db06880
NC
6594#ifdef PERL_MAD
6595 SV *tmpwhite = 0;
6596
cd81e915 6597 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5db06880 6598 SV *subtoken = newSVpvn(tstart, s - tstart);
cd81e915 6599 PL_thistoken = 0;
5db06880
NC
6600
6601 d = s;
6602 s = SKIPSPACE2(s,tmpwhite);
6603#else
09bef843 6604 s = skipspace(s);
5db06880 6605#endif
09bef843 6606
7e2040f0 6607 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
09bef843
SB
6608 (*s == ':' && s[1] == ':'))
6609 {
5db06880
NC
6610#ifdef PERL_MAD
6611 SV *nametoke;
6612#endif
6613
09bef843
SB
6614 PL_expect = XBLOCK;
6615 attrful = XATTRBLOCK;
b1b65b59
JH
6616 /* remember buffer pos'n for later force_word */
6617 tboffset = s - PL_oldbufptr;
09bef843 6618 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5db06880
NC
6619#ifdef PERL_MAD
6620 if (PL_madskills)
6621 nametoke = newSVpvn(s, d - s);
6622#endif
6502358f
NC
6623 if (memchr(tmpbuf, ':', len))
6624 sv_setpvn(PL_subname, tmpbuf, len);
09bef843
SB
6625 else {
6626 sv_setsv(PL_subname,PL_curstname);
396482e1 6627 sv_catpvs(PL_subname,"::");
09bef843
SB
6628 sv_catpvn(PL_subname,tmpbuf,len);
6629 }
09bef843 6630 have_name = TRUE;
5db06880
NC
6631
6632#ifdef PERL_MAD
6633
6634 start_force(0);
6635 CURMAD('X', nametoke);
6636 CURMAD('_', tmpwhite);
6637 (void) force_word(PL_oldbufptr + tboffset, WORD,
6638 FALSE, TRUE, TRUE);
6639
6640 s = SKIPSPACE2(d,tmpwhite);
6641#else
6642 s = skipspace(d);
6643#endif
09bef843 6644 }
463ee0b2 6645 else {
09bef843
SB
6646 if (key == KEY_my)
6647 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6648 PL_expect = XTERMBLOCK;
6649 attrful = XATTRTERM;
c69006e4 6650 sv_setpvn(PL_subname,"?",1);
09bef843 6651 have_name = FALSE;
463ee0b2 6652 }
4633a7c4 6653
09bef843
SB
6654 if (key == KEY_format) {
6655 if (*s == '=')
6656 PL_lex_formbrack = PL_lex_brackets + 1;
5db06880 6657#ifdef PERL_MAD
cd81e915 6658 PL_thistoken = subtoken;
5db06880
NC
6659 s = d;
6660#else
09bef843 6661 if (have_name)
b1b65b59
JH
6662 (void) force_word(PL_oldbufptr + tboffset, WORD,
6663 FALSE, TRUE, TRUE);
5db06880 6664#endif
09bef843
SB
6665 OPERATOR(FORMAT);
6666 }
79072805 6667
09bef843
SB
6668 /* Look for a prototype */
6669 if (*s == '(') {
d9f2850e
RGS
6670 char *p;
6671 bool bad_proto = FALSE;
6672 const bool warnsyntax = ckWARN(WARN_SYNTAX);
09bef843 6673
5db06880 6674 s = scan_str(s,!!PL_madskills,FALSE);
37fd879b 6675 if (!s)
09bef843 6676 Perl_croak(aTHX_ "Prototype not terminated");
2f758a16 6677 /* strip spaces and check for bad characters */
09bef843
SB
6678 d = SvPVX(PL_lex_stuff);
6679 tmp = 0;
d9f2850e
RGS
6680 for (p = d; *p; ++p) {
6681 if (!isSPACE(*p)) {
6682 d[tmp++] = *p;
b13fd70a 6683 if (warnsyntax && !strchr("$@%*;[]&\\_", *p))
d9f2850e 6684 bad_proto = TRUE;
d37a9538 6685 }
09bef843 6686 }
d9f2850e
RGS
6687 d[tmp] = '\0';
6688 if (bad_proto)
6689 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6690 "Illegal character in prototype for %"SVf" : %s",
be2597df 6691 SVfARG(PL_subname), d);
b162af07 6692 SvCUR_set(PL_lex_stuff, tmp);
09bef843 6693 have_proto = TRUE;
68dc0745 6694
5db06880
NC
6695#ifdef PERL_MAD
6696 start_force(0);
cd81e915 6697 CURMAD('q', PL_thisopen);
5db06880 6698 CURMAD('_', tmpwhite);
cd81e915
NC
6699 CURMAD('=', PL_thisstuff);
6700 CURMAD('Q', PL_thisclose);
5db06880
NC
6701 NEXTVAL_NEXTTOKE.opval =
6702 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6703 PL_lex_stuff = Nullsv;
6704 force_next(THING);
6705
6706 s = SKIPSPACE2(s,tmpwhite);
6707#else
09bef843 6708 s = skipspace(s);
5db06880 6709#endif
4633a7c4 6710 }
09bef843
SB
6711 else
6712 have_proto = FALSE;
6713
6714 if (*s == ':' && s[1] != ':')
6715 PL_expect = attrful;
8e742a20
MHM
6716 else if (*s != '{' && key == KEY_sub) {
6717 if (!have_name)
6718 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6719 else if (*s != ';')
be2597df 6720 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, SVfARG(PL_subname));
8e742a20 6721 }
09bef843 6722
5db06880
NC
6723#ifdef PERL_MAD
6724 start_force(0);
6725 if (tmpwhite) {
6726 if (PL_madskills)
6b29d1f5 6727 curmad('^', newSVpvs(""));
5db06880
NC
6728 CURMAD('_', tmpwhite);
6729 }
6730 force_next(0);
6731
cd81e915 6732 PL_thistoken = subtoken;
5db06880 6733#else
09bef843 6734 if (have_proto) {
9ded7720 6735 NEXTVAL_NEXTTOKE.opval =
b1b65b59 6736 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
a0714e2c 6737 PL_lex_stuff = NULL;
09bef843 6738 force_next(THING);
68dc0745 6739 }
5db06880 6740#endif
09bef843 6741 if (!have_name) {
c99da370 6742 sv_setpv(PL_subname,
10edeb5d
JH
6743 (const char *)
6744 (PL_curstash ? "__ANON__" : "__ANON__::__ANON__"));
09bef843 6745 TOKEN(ANONSUB);
4633a7c4 6746 }
5db06880 6747#ifndef PERL_MAD
b1b65b59
JH
6748 (void) force_word(PL_oldbufptr + tboffset, WORD,
6749 FALSE, TRUE, TRUE);
5db06880 6750#endif
09bef843
SB
6751 if (key == KEY_my)
6752 TOKEN(MYSUB);
6753 TOKEN(SUB);
4633a7c4 6754 }
79072805
LW
6755
6756 case KEY_system:
6757 set_csh();
a0d0e21e 6758 LOP(OP_SYSTEM,XREF);
79072805
LW
6759
6760 case KEY_symlink:
a0d0e21e 6761 LOP(OP_SYMLINK,XTERM);
79072805
LW
6762
6763 case KEY_syscall:
a0d0e21e 6764 LOP(OP_SYSCALL,XTERM);
79072805 6765
c07a80fd 6766 case KEY_sysopen:
6767 LOP(OP_SYSOPEN,XTERM);
6768
137443ea 6769 case KEY_sysseek:
6770 LOP(OP_SYSSEEK,XTERM);
6771
79072805 6772 case KEY_sysread:
a0d0e21e 6773 LOP(OP_SYSREAD,XTERM);
79072805
LW
6774
6775 case KEY_syswrite:
a0d0e21e 6776 LOP(OP_SYSWRITE,XTERM);
79072805
LW
6777
6778 case KEY_tr:
6779 s = scan_trans(s);
6780 TERM(sublex_start());
6781
6782 case KEY_tell:
6783 UNI(OP_TELL);
6784
6785 case KEY_telldir:
6786 UNI(OP_TELLDIR);
6787
463ee0b2 6788 case KEY_tie:
a0d0e21e 6789 LOP(OP_TIE,XTERM);
463ee0b2 6790
c07a80fd 6791 case KEY_tied:
6792 UNI(OP_TIED);
6793
79072805
LW
6794 case KEY_time:
6795 FUN0(OP_TIME);
6796
6797 case KEY_times:
6798 FUN0(OP_TMS);
6799
6800 case KEY_truncate:
a0d0e21e 6801 LOP(OP_TRUNCATE,XTERM);
79072805
LW
6802
6803 case KEY_uc:
6804 UNI(OP_UC);
6805
6806 case KEY_ucfirst:
6807 UNI(OP_UCFIRST);
6808
463ee0b2
LW
6809 case KEY_untie:
6810 UNI(OP_UNTIE);
6811
79072805 6812 case KEY_until:
57843af0 6813 yylval.ival = CopLINE(PL_curcop);
79072805
LW
6814 OPERATOR(UNTIL);
6815
6816 case KEY_unless:
57843af0 6817 yylval.ival = CopLINE(PL_curcop);
79072805
LW
6818 OPERATOR(UNLESS);
6819
6820 case KEY_unlink:
a0d0e21e 6821 LOP(OP_UNLINK,XTERM);
79072805
LW
6822
6823 case KEY_undef:
6f33ba73 6824 UNIDOR(OP_UNDEF);
79072805
LW
6825
6826 case KEY_unpack:
a0d0e21e 6827 LOP(OP_UNPACK,XTERM);
79072805
LW
6828
6829 case KEY_utime:
a0d0e21e 6830 LOP(OP_UTIME,XTERM);
79072805
LW
6831
6832 case KEY_umask:
6f33ba73 6833 UNIDOR(OP_UMASK);
79072805
LW
6834
6835 case KEY_unshift:
a0d0e21e
LW
6836 LOP(OP_UNSHIFT,XTERM);
6837
6838 case KEY_use:
468aa647 6839 s = tokenize_use(1, s);
a0d0e21e 6840 OPERATOR(USE);
79072805
LW
6841
6842 case KEY_values:
6843 UNI(OP_VALUES);
6844
6845 case KEY_vec:
a0d0e21e 6846 LOP(OP_VEC,XTERM);
79072805 6847
0d863452
RH
6848 case KEY_when:
6849 yylval.ival = CopLINE(PL_curcop);
6850 OPERATOR(WHEN);
6851
79072805 6852 case KEY_while:
57843af0 6853 yylval.ival = CopLINE(PL_curcop);
79072805
LW
6854 OPERATOR(WHILE);
6855
6856 case KEY_warn:
3280af22 6857 PL_hints |= HINT_BLOCK_SCOPE;
a0d0e21e 6858 LOP(OP_WARN,XTERM);
79072805
LW
6859
6860 case KEY_wait:
6861 FUN0(OP_WAIT);
6862
6863 case KEY_waitpid:
a0d0e21e 6864 LOP(OP_WAITPID,XTERM);
79072805
LW
6865
6866 case KEY_wantarray:
6867 FUN0(OP_WANTARRAY);
6868
6869 case KEY_write:
9d116dd7
JH
6870#ifdef EBCDIC
6871 {
df3728a2
JH
6872 char ctl_l[2];
6873 ctl_l[0] = toCTRL('L');
6874 ctl_l[1] = '\0';
fafc274c 6875 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
9d116dd7
JH
6876 }
6877#else
fafc274c
NC
6878 /* Make sure $^L is defined */
6879 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
9d116dd7 6880#endif
79072805
LW
6881 UNI(OP_ENTERWRITE);
6882
6883 case KEY_x:
3280af22 6884 if (PL_expect == XOPERATOR)
79072805
LW
6885 Mop(OP_REPEAT);
6886 check_uni();
6887 goto just_a_word;
6888
a0d0e21e
LW
6889 case KEY_xor:
6890 yylval.ival = OP_XOR;
6891 OPERATOR(OROP);
6892
79072805
LW
6893 case KEY_y:
6894 s = scan_trans(s);
6895 TERM(sublex_start());
6896 }
49dc05e3 6897 }}
79072805 6898}
bf4acbe4
GS
6899#ifdef __SC__
6900#pragma segment Main
6901#endif
79072805 6902
e930465f
JH
6903static int
6904S_pending_ident(pTHX)
8eceec63 6905{
97aff369 6906 dVAR;
8eceec63 6907 register char *d;
bbd11bfc 6908 PADOFFSET tmp = 0;
8eceec63
SC
6909 /* pit holds the identifier we read and pending_ident is reset */
6910 char pit = PL_pending_ident;
6911 PL_pending_ident = 0;
6912
cd81e915 6913 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
8eceec63 6914 DEBUG_T({ PerlIO_printf(Perl_debug_log,
b6007c36 6915 "### Pending identifier '%s'\n", PL_tokenbuf); });
8eceec63
SC
6916
6917 /* if we're in a my(), we can't allow dynamics here.
6918 $foo'bar has already been turned into $foo::bar, so
6919 just check for colons.
6920
6921 if it's a legal name, the OP is a PADANY.
6922 */
6923 if (PL_in_my) {
6924 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
6925 if (strchr(PL_tokenbuf,':'))
6926 yyerror(Perl_form(aTHX_ "No package name allowed for "
6927 "variable %s in \"our\"",
6928 PL_tokenbuf));
dd2155a4 6929 tmp = allocmy(PL_tokenbuf);
8eceec63
SC
6930 }
6931 else {
6932 if (strchr(PL_tokenbuf,':'))
952306ac
RGS
6933 yyerror(Perl_form(aTHX_ PL_no_myglob,
6934 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
8eceec63
SC
6935
6936 yylval.opval = newOP(OP_PADANY, 0);
dd2155a4 6937 yylval.opval->op_targ = allocmy(PL_tokenbuf);
8eceec63
SC
6938 return PRIVATEREF;
6939 }
6940 }
6941
6942 /*
6943 build the ops for accesses to a my() variable.
6944
6945 Deny my($a) or my($b) in a sort block, *if* $a or $b is
6946 then used in a comparison. This catches most, but not
6947 all cases. For instance, it catches
6948 sort { my($a); $a <=> $b }
6949 but not
6950 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6951 (although why you'd do that is anyone's guess).
6952 */
6953
6954 if (!strchr(PL_tokenbuf,':')) {
8716503d
DM
6955 if (!PL_in_my)
6956 tmp = pad_findmy(PL_tokenbuf);
6957 if (tmp != NOT_IN_PAD) {
8eceec63 6958 /* might be an "our" variable" */
00b1698f 6959 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
8eceec63 6960 /* build ops for a bareword */
b64e5050
AL
6961 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
6962 HEK * const stashname = HvNAME_HEK(stash);
6963 SV * const sym = newSVhek(stashname);
396482e1 6964 sv_catpvs(sym, "::");
8eceec63
SC
6965 sv_catpv(sym, PL_tokenbuf+1);
6966 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6967 yylval.opval->op_private = OPpCONST_ENTERED;
7a5fd60d 6968 gv_fetchsv(sym,
8eceec63
SC
6969 (PL_in_eval
6970 ? (GV_ADDMULTI | GV_ADDINEVAL)
700078d2 6971 : GV_ADDMULTI
8eceec63
SC
6972 ),
6973 ((PL_tokenbuf[0] == '$') ? SVt_PV
6974 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6975 : SVt_PVHV));
6976 return WORD;
6977 }
6978
6979 /* if it's a sort block and they're naming $a or $b */
6980 if (PL_last_lop_op == OP_SORT &&
6981 PL_tokenbuf[0] == '$' &&
6982 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
6983 && !PL_tokenbuf[2])
6984 {
6985 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
6986 d < PL_bufend && *d != '\n';
6987 d++)
6988 {
6989 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
6990 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
6991 PL_tokenbuf);
6992 }
6993 }
6994 }
6995
6996 yylval.opval = newOP(OP_PADANY, 0);
6997 yylval.opval->op_targ = tmp;
6998 return PRIVATEREF;
6999 }
7000 }
7001
7002 /*
7003 Whine if they've said @foo in a doublequoted string,
7004 and @foo isn't a variable we can find in the symbol
7005 table.
7006 */
7007 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
f776e3cd 7008 GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
8eceec63 7009 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
e879d94f
RGS
7010 && ckWARN(WARN_AMBIGUOUS)
7011 /* DO NOT warn for @- and @+ */
7012 && !( PL_tokenbuf[2] == '\0' &&
7013 ( PL_tokenbuf[1] == '-' || PL_tokenbuf[1] == '+' ))
7014 )
8eceec63
SC
7015 {
7016 /* Downgraded from fatal to warning 20000522 mjd */
9014280d 7017 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
8eceec63
SC
7018 "Possible unintended interpolation of %s in string",
7019 PL_tokenbuf);
7020 }
7021 }
7022
7023 /* build ops for a bareword */
7024 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
7025 yylval.opval->op_private = OPpCONST_ENTERED;
adc51b97
RGS
7026 gv_fetchpv(
7027 PL_tokenbuf+1,
d6069db2
RGS
7028 /* If the identifier refers to a stash, don't autovivify it.
7029 * Change 24660 had the side effect of causing symbol table
7030 * hashes to always be defined, even if they were freshly
7031 * created and the only reference in the entire program was
7032 * the single statement with the defined %foo::bar:: test.
7033 * It appears that all code in the wild doing this actually
7034 * wants to know whether sub-packages have been loaded, so
7035 * by avoiding auto-vivifying symbol tables, we ensure that
7036 * defined %foo::bar:: continues to be false, and the existing
7037 * tests still give the expected answers, even though what
7038 * they're actually testing has now changed subtly.
7039 */
7040 (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
7041 ? 0
7042 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
adc51b97
RGS
7043 ((PL_tokenbuf[0] == '$') ? SVt_PV
7044 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
7045 : SVt_PVHV));
8eceec63
SC
7046 return WORD;
7047}
7048
4c3bbe0f
MHM
7049/*
7050 * The following code was generated by perl_keyword.pl.
7051 */
e2e1dd5a 7052
79072805 7053I32
5458a98a 7054Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
4c3bbe0f 7055{
952306ac 7056 dVAR;
4c3bbe0f
MHM
7057 switch (len)
7058 {
7059 case 1: /* 5 tokens of length 1 */
7060 switch (name[0])
e2e1dd5a 7061 {
4c3bbe0f
MHM
7062 case 'm':
7063 { /* m */
7064 return KEY_m;
7065 }
7066
4c3bbe0f
MHM
7067 case 'q':
7068 { /* q */
7069 return KEY_q;
7070 }
7071
4c3bbe0f
MHM
7072 case 's':
7073 { /* s */
7074 return KEY_s;
7075 }
7076
4c3bbe0f
MHM
7077 case 'x':
7078 { /* x */
7079 return -KEY_x;
7080 }
7081
4c3bbe0f
MHM
7082 case 'y':
7083 { /* y */
7084 return KEY_y;
7085 }
7086
4c3bbe0f
MHM
7087 default:
7088 goto unknown;
e2e1dd5a 7089 }
4c3bbe0f
MHM
7090
7091 case 2: /* 18 tokens of length 2 */
7092 switch (name[0])
e2e1dd5a 7093 {
4c3bbe0f
MHM
7094 case 'd':
7095 if (name[1] == 'o')
7096 { /* do */
7097 return KEY_do;
7098 }
7099
7100 goto unknown;
7101
7102 case 'e':
7103 if (name[1] == 'q')
7104 { /* eq */
7105 return -KEY_eq;
7106 }
7107
7108 goto unknown;
7109
7110 case 'g':
7111 switch (name[1])
7112 {
7113 case 'e':
7114 { /* ge */
7115 return -KEY_ge;
7116 }
7117
4c3bbe0f
MHM
7118 case 't':
7119 { /* gt */
7120 return -KEY_gt;
7121 }
7122
4c3bbe0f
MHM
7123 default:
7124 goto unknown;
7125 }
7126
7127 case 'i':
7128 if (name[1] == 'f')
7129 { /* if */
7130 return KEY_if;
7131 }
7132
7133 goto unknown;
7134
7135 case 'l':
7136 switch (name[1])
7137 {
7138 case 'c':
7139 { /* lc */
7140 return -KEY_lc;
7141 }
7142
4c3bbe0f
MHM
7143 case 'e':
7144 { /* le */
7145 return -KEY_le;
7146 }
7147
4c3bbe0f
MHM
7148 case 't':
7149 { /* lt */
7150 return -KEY_lt;
7151 }
7152
4c3bbe0f
MHM
7153 default:
7154 goto unknown;
7155 }
7156
7157 case 'm':
7158 if (name[1] == 'y')
7159 { /* my */
7160 return KEY_my;
7161 }
7162
7163 goto unknown;
7164
7165 case 'n':
7166 switch (name[1])
7167 {
7168 case 'e':
7169 { /* ne */
7170 return -KEY_ne;
7171 }
7172
4c3bbe0f
MHM
7173 case 'o':
7174 { /* no */
7175 return KEY_no;
7176 }
7177
4c3bbe0f
MHM
7178 default:
7179 goto unknown;
7180 }
7181
7182 case 'o':
7183 if (name[1] == 'r')
7184 { /* or */
7185 return -KEY_or;
7186 }
7187
7188 goto unknown;
7189
7190 case 'q':
7191 switch (name[1])
7192 {
7193 case 'q':
7194 { /* qq */
7195 return KEY_qq;
7196 }
7197
4c3bbe0f
MHM
7198 case 'r':
7199 { /* qr */
7200 return KEY_qr;
7201 }
7202
4c3bbe0f
MHM
7203 case 'w':
7204 { /* qw */
7205 return KEY_qw;
7206 }
7207
4c3bbe0f
MHM
7208 case 'x':
7209 { /* qx */
7210 return KEY_qx;
7211 }
7212
4c3bbe0f
MHM
7213 default:
7214 goto unknown;
7215 }
7216
7217 case 't':
7218 if (name[1] == 'r')
7219 { /* tr */
7220 return KEY_tr;
7221 }
7222
7223 goto unknown;
7224
7225 case 'u':
7226 if (name[1] == 'c')
7227 { /* uc */
7228 return -KEY_uc;
7229 }
7230
7231 goto unknown;
7232
7233 default:
7234 goto unknown;
e2e1dd5a 7235 }
4c3bbe0f 7236
0d863452 7237 case 3: /* 29 tokens of length 3 */
4c3bbe0f 7238 switch (name[0])
e2e1dd5a 7239 {
4c3bbe0f
MHM
7240 case 'E':
7241 if (name[1] == 'N' &&
7242 name[2] == 'D')
7243 { /* END */
7244 return KEY_END;
7245 }
7246
7247 goto unknown;
7248
7249 case 'a':
7250 switch (name[1])
7251 {
7252 case 'b':
7253 if (name[2] == 's')
7254 { /* abs */
7255 return -KEY_abs;
7256 }
7257
7258 goto unknown;
7259
7260 case 'n':
7261 if (name[2] == 'd')
7262 { /* and */
7263 return -KEY_and;
7264 }
7265
7266 goto unknown;
7267
7268 default:
7269 goto unknown;
7270 }
7271
7272 case 'c':
7273 switch (name[1])
7274 {
7275 case 'h':
7276 if (name[2] == 'r')
7277 { /* chr */
7278 return -KEY_chr;
7279 }
7280
7281 goto unknown;
7282
7283 case 'm':
7284 if (name[2] == 'p')
7285 { /* cmp */
7286 return -KEY_cmp;
7287 }
7288
7289 goto unknown;
7290
7291 case 'o':
7292 if (name[2] == 's')
7293 { /* cos */
7294 return -KEY_cos;
7295 }
7296
7297 goto unknown;
7298
7299 default:
7300 goto unknown;
7301 }
7302
7303 case 'd':
7304 if (name[1] == 'i' &&
7305 name[2] == 'e')
7306 { /* die */
7307 return -KEY_die;
7308 }
7309
7310 goto unknown;
7311
7312 case 'e':
7313 switch (name[1])
7314 {
7315 case 'o':
7316 if (name[2] == 'f')
7317 { /* eof */
7318 return -KEY_eof;
7319 }
7320
7321 goto unknown;
7322
7323 case 'r':
7324 if (name[2] == 'r')
7325 { /* err */
5458a98a 7326 return (all_keywords || FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
4c3bbe0f
MHM
7327 }
7328
7329 goto unknown;
7330
7331 case 'x':
7332 if (name[2] == 'p')
7333 { /* exp */
7334 return -KEY_exp;
7335 }
7336
7337 goto unknown;
7338
7339 default:
7340 goto unknown;
7341 }
7342
7343 case 'f':
7344 if (name[1] == 'o' &&
7345 name[2] == 'r')
7346 { /* for */
7347 return KEY_for;
7348 }
7349
7350 goto unknown;
7351
7352 case 'h':
7353 if (name[1] == 'e' &&
7354 name[2] == 'x')
7355 { /* hex */
7356 return -KEY_hex;
7357 }
7358
7359 goto unknown;
7360
7361 case 'i':
7362 if (name[1] == 'n' &&
7363 name[2] == 't')
7364 { /* int */
7365 return -KEY_int;
7366 }
7367
7368 goto unknown;
7369
7370 case 'l':
7371 if (name[1] == 'o' &&
7372 name[2] == 'g')
7373 { /* log */
7374 return -KEY_log;
7375 }
7376
7377 goto unknown;
7378
7379 case 'm':
7380 if (name[1] == 'a' &&
7381 name[2] == 'p')
7382 { /* map */
7383 return KEY_map;
7384 }
7385
7386 goto unknown;
7387
7388 case 'n':
7389 if (name[1] == 'o' &&
7390 name[2] == 't')
7391 { /* not */
7392 return -KEY_not;
7393 }
7394
7395 goto unknown;
7396
7397 case 'o':
7398 switch (name[1])
7399 {
7400 case 'c':
7401 if (name[2] == 't')
7402 { /* oct */
7403 return -KEY_oct;
7404 }
7405
7406 goto unknown;
7407
7408 case 'r':
7409 if (name[2] == 'd')
7410 { /* ord */
7411 return -KEY_ord;
7412 }
7413
7414 goto unknown;
7415
7416 case 'u':
7417 if (name[2] == 'r')
7418 { /* our */
7419 return KEY_our;
7420 }
7421
7422 goto unknown;
7423
7424 default:
7425 goto unknown;
7426 }
7427
7428 case 'p':
7429 if (name[1] == 'o')
7430 {
7431 switch (name[2])
7432 {
7433 case 'p':
7434 { /* pop */
7435 return -KEY_pop;
7436 }
7437
4c3bbe0f
MHM
7438 case 's':
7439 { /* pos */
7440 return KEY_pos;
7441 }
7442
4c3bbe0f
MHM
7443 default:
7444 goto unknown;
7445 }
7446 }
7447
7448 goto unknown;
7449
7450 case 'r':
7451 if (name[1] == 'e' &&
7452 name[2] == 'f')
7453 { /* ref */
7454 return -KEY_ref;
7455 }
7456
7457 goto unknown;
7458
7459 case 's':
7460 switch (name[1])
7461 {
0d863452
RH
7462 case 'a':
7463 if (name[2] == 'y')
7464 { /* say */
e3e804c9 7465 return (all_keywords || FEATURE_IS_ENABLED("say") ? KEY_say : 0);
0d863452
RH
7466 }
7467
7468 goto unknown;
7469
4c3bbe0f
MHM
7470 case 'i':
7471 if (name[2] == 'n')
7472 { /* sin */
7473 return -KEY_sin;
7474 }
7475
7476 goto unknown;
7477
7478 case 'u':
7479 if (name[2] == 'b')
7480 { /* sub */
7481 return KEY_sub;
7482 }
7483
7484 goto unknown;
7485
7486 default:
7487 goto unknown;
7488 }
7489
7490 case 't':
7491 if (name[1] == 'i' &&
7492 name[2] == 'e')
7493 { /* tie */
7494 return KEY_tie;
7495 }
7496
7497 goto unknown;
7498
7499 case 'u':
7500 if (name[1] == 's' &&
7501 name[2] == 'e')
7502 { /* use */
7503 return KEY_use;
7504 }
7505
7506 goto unknown;
7507
7508 case 'v':
7509 if (name[1] == 'e' &&
7510 name[2] == 'c')
7511 { /* vec */
7512 return -KEY_vec;
7513 }
7514
7515 goto unknown;
7516
7517 case 'x':
7518 if (name[1] == 'o' &&
7519 name[2] == 'r')
7520 { /* xor */
7521 return -KEY_xor;
7522 }
7523
7524 goto unknown;
7525
7526 default:
7527 goto unknown;
e2e1dd5a 7528 }
4c3bbe0f 7529
0d863452 7530 case 4: /* 41 tokens of length 4 */
4c3bbe0f 7531 switch (name[0])
e2e1dd5a 7532 {
4c3bbe0f
MHM
7533 case 'C':
7534 if (name[1] == 'O' &&
7535 name[2] == 'R' &&
7536 name[3] == 'E')
7537 { /* CORE */
7538 return -KEY_CORE;
7539 }
7540
7541 goto unknown;
7542
7543 case 'I':
7544 if (name[1] == 'N' &&
7545 name[2] == 'I' &&
7546 name[3] == 'T')
7547 { /* INIT */
7548 return KEY_INIT;
7549 }
7550
7551 goto unknown;
7552
7553 case 'b':
7554 if (name[1] == 'i' &&
7555 name[2] == 'n' &&
7556 name[3] == 'd')
7557 { /* bind */
7558 return -KEY_bind;
7559 }
7560
7561 goto unknown;
7562
7563 case 'c':
7564 if (name[1] == 'h' &&
7565 name[2] == 'o' &&
7566 name[3] == 'p')
7567 { /* chop */
7568 return -KEY_chop;
7569 }
7570
7571 goto unknown;
7572
7573 case 'd':
7574 if (name[1] == 'u' &&
7575 name[2] == 'm' &&
7576 name[3] == 'p')
7577 { /* dump */
7578 return -KEY_dump;
7579 }
7580
7581 goto unknown;
7582
7583 case 'e':
7584 switch (name[1])
7585 {
7586 case 'a':
7587 if (name[2] == 'c' &&
7588 name[3] == 'h')
7589 { /* each */
7590 return -KEY_each;
7591 }
7592
7593 goto unknown;
7594
7595 case 'l':
7596 if (name[2] == 's' &&
7597 name[3] == 'e')
7598 { /* else */
7599 return KEY_else;
7600 }
7601
7602 goto unknown;
7603
7604 case 'v':
7605 if (name[2] == 'a' &&
7606 name[3] == 'l')
7607 { /* eval */
7608 return KEY_eval;
7609 }
7610
7611 goto unknown;
7612
7613 case 'x':
7614 switch (name[2])
7615 {
7616 case 'e':
7617 if (name[3] == 'c')
7618 { /* exec */
7619 return -KEY_exec;
7620 }
7621
7622 goto unknown;
7623
7624 case 'i':
7625 if (name[3] == 't')
7626 { /* exit */
7627 return -KEY_exit;
7628 }
7629
7630 goto unknown;
7631
7632 default:
7633 goto unknown;
7634 }
7635
7636 default:
7637 goto unknown;
7638 }
7639
7640 case 'f':
7641 if (name[1] == 'o' &&
7642 name[2] == 'r' &&
7643 name[3] == 'k')
7644 { /* fork */
7645 return -KEY_fork;
7646 }
7647
7648 goto unknown;
7649
7650 case 'g':
7651 switch (name[1])
7652 {
7653 case 'e':
7654 if (name[2] == 't' &&
7655 name[3] == 'c')
7656 { /* getc */
7657 return -KEY_getc;
7658 }
7659
7660 goto unknown;
7661
7662 case 'l':
7663 if (name[2] == 'o' &&
7664 name[3] == 'b')
7665 { /* glob */
7666 return KEY_glob;
7667 }
7668
7669 goto unknown;
7670
7671 case 'o':
7672 if (name[2] == 't' &&
7673 name[3] == 'o')
7674 { /* goto */
7675 return KEY_goto;
7676 }
7677
7678 goto unknown;
7679
7680 case 'r':
7681 if (name[2] == 'e' &&
7682 name[3] == 'p')
7683 { /* grep */
7684 return KEY_grep;
7685 }
7686
7687 goto unknown;
7688
7689 default:
7690 goto unknown;
7691 }
7692
7693 case 'j':
7694 if (name[1] == 'o' &&
7695 name[2] == 'i' &&
7696 name[3] == 'n')
7697 { /* join */
7698 return -KEY_join;
7699 }
7700
7701 goto unknown;
7702
7703 case 'k':
7704 switch (name[1])
7705 {
7706 case 'e':
7707 if (name[2] == 'y' &&
7708 name[3] == 's')
7709 { /* keys */
7710 return -KEY_keys;
7711 }
7712
7713 goto unknown;
7714
7715 case 'i':
7716 if (name[2] == 'l' &&
7717 name[3] == 'l')
7718 { /* kill */
7719 return -KEY_kill;
7720 }
7721
7722 goto unknown;
7723
7724 default:
7725 goto unknown;
7726 }
7727
7728 case 'l':
7729 switch (name[1])
7730 {
7731 case 'a':
7732 if (name[2] == 's' &&
7733 name[3] == 't')
7734 { /* last */
7735 return KEY_last;
7736 }
7737
7738 goto unknown;
7739
7740 case 'i':
7741 if (name[2] == 'n' &&
7742 name[3] == 'k')
7743 { /* link */
7744 return -KEY_link;
7745 }
7746
7747 goto unknown;
7748
7749 case 'o':
7750 if (name[2] == 'c' &&
7751 name[3] == 'k')
7752 { /* lock */
7753 return -KEY_lock;
7754 }
7755
7756 goto unknown;
7757
7758 default:
7759 goto unknown;
7760 }
7761
7762 case 'n':
7763 if (name[1] == 'e' &&
7764 name[2] == 'x' &&
7765 name[3] == 't')
7766 { /* next */
7767 return KEY_next;
7768 }
7769
7770 goto unknown;
7771
7772 case 'o':
7773 if (name[1] == 'p' &&
7774 name[2] == 'e' &&
7775 name[3] == 'n')
7776 { /* open */
7777 return -KEY_open;
7778 }
7779
7780 goto unknown;
7781
7782 case 'p':
7783 switch (name[1])
7784 {
7785 case 'a':
7786 if (name[2] == 'c' &&
7787 name[3] == 'k')
7788 { /* pack */
7789 return -KEY_pack;
7790 }
7791
7792 goto unknown;
7793
7794 case 'i':
7795 if (name[2] == 'p' &&
7796 name[3] == 'e')
7797 { /* pipe */
7798 return -KEY_pipe;
7799 }
7800
7801 goto unknown;
7802
7803 case 'u':
7804 if (name[2] == 's' &&
7805 name[3] == 'h')
7806 { /* push */
7807 return -KEY_push;
7808 }
7809
7810 goto unknown;
7811
7812 default:
7813 goto unknown;
7814 }
7815
7816 case 'r':
7817 switch (name[1])
7818 {
7819 case 'a':
7820 if (name[2] == 'n' &&
7821 name[3] == 'd')
7822 { /* rand */
7823 return -KEY_rand;
7824 }
7825
7826 goto unknown;
7827
7828 case 'e':
7829 switch (name[2])
7830 {
7831 case 'a':
7832 if (name[3] == 'd')
7833 { /* read */
7834 return -KEY_read;
7835 }
7836
7837 goto unknown;
7838
7839 case 'c':
7840 if (name[3] == 'v')
7841 { /* recv */
7842 return -KEY_recv;
7843 }
7844
7845 goto unknown;
7846
7847 case 'd':
7848 if (name[3] == 'o')
7849 { /* redo */
7850 return KEY_redo;
7851 }
7852
7853 goto unknown;
7854
7855 default:
7856 goto unknown;
7857 }
7858
7859 default:
7860 goto unknown;
7861 }
7862
7863 case 's':
7864 switch (name[1])
7865 {
7866 case 'e':
7867 switch (name[2])
7868 {
7869 case 'e':
7870 if (name[3] == 'k')
7871 { /* seek */
7872 return -KEY_seek;
7873 }
7874
7875 goto unknown;
7876
7877 case 'n':
7878 if (name[3] == 'd')
7879 { /* send */
7880 return -KEY_send;
7881 }
7882
7883 goto unknown;
7884
7885 default:
7886 goto unknown;
7887 }
7888
7889 case 'o':
7890 if (name[2] == 'r' &&
7891 name[3] == 't')
7892 { /* sort */
7893 return KEY_sort;
7894 }
7895
7896 goto unknown;
7897
7898 case 'q':
7899 if (name[2] == 'r' &&
7900 name[3] == 't')
7901 { /* sqrt */
7902 return -KEY_sqrt;
7903 }
7904
7905 goto unknown;
7906
7907 case 't':
7908 if (name[2] == 'a' &&
7909 name[3] == 't')
7910 { /* stat */
7911 return -KEY_stat;
7912 }
7913
7914 goto unknown;
7915
7916 default:
7917 goto unknown;
7918 }
7919
7920 case 't':
7921 switch (name[1])
7922 {
7923 case 'e':
7924 if (name[2] == 'l' &&
7925 name[3] == 'l')
7926 { /* tell */
7927 return -KEY_tell;
7928 }
7929
7930 goto unknown;
7931
7932 case 'i':
7933 switch (name[2])
7934 {
7935 case 'e':
7936 if (name[3] == 'd')
7937 { /* tied */
7938 return KEY_tied;
7939 }
7940
7941 goto unknown;
7942
7943 case 'm':
7944 if (name[3] == 'e')
7945 { /* time */
7946 return -KEY_time;
7947 }
7948
7949 goto unknown;
7950
7951 default:
7952 goto unknown;
7953 }
7954
7955 default:
7956 goto unknown;
7957 }
7958
7959 case 'w':
0d863452 7960 switch (name[1])
4c3bbe0f 7961 {
0d863452 7962 case 'a':
952306ac
RGS
7963 switch (name[2])
7964 {
7965 case 'i':
7966 if (name[3] == 't')
7967 { /* wait */
7968 return -KEY_wait;
7969 }
4c3bbe0f 7970
952306ac 7971 goto unknown;
4c3bbe0f 7972
952306ac
RGS
7973 case 'r':
7974 if (name[3] == 'n')
7975 { /* warn */
7976 return -KEY_warn;
7977 }
4c3bbe0f 7978
952306ac 7979 goto unknown;
4c3bbe0f 7980
952306ac
RGS
7981 default:
7982 goto unknown;
7983 }
0d863452
RH
7984
7985 case 'h':
7986 if (name[2] == 'e' &&
7987 name[3] == 'n')
7988 { /* when */
5458a98a 7989 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
952306ac 7990 }
4c3bbe0f 7991
952306ac 7992 goto unknown;
4c3bbe0f 7993
952306ac
RGS
7994 default:
7995 goto unknown;
7996 }
4c3bbe0f 7997
0d863452
RH
7998 default:
7999 goto unknown;
8000 }
8001
952306ac 8002 case 5: /* 39 tokens of length 5 */
4c3bbe0f 8003 switch (name[0])
e2e1dd5a 8004 {
4c3bbe0f
MHM
8005 case 'B':
8006 if (name[1] == 'E' &&
8007 name[2] == 'G' &&
8008 name[3] == 'I' &&
8009 name[4] == 'N')
8010 { /* BEGIN */
8011 return KEY_BEGIN;
8012 }
8013
8014 goto unknown;
8015
8016 case 'C':
8017 if (name[1] == 'H' &&
8018 name[2] == 'E' &&
8019 name[3] == 'C' &&
8020 name[4] == 'K')
8021 { /* CHECK */
8022 return KEY_CHECK;
8023 }
8024
8025 goto unknown;
8026
8027 case 'a':
8028 switch (name[1])
8029 {
8030 case 'l':
8031 if (name[2] == 'a' &&
8032 name[3] == 'r' &&
8033 name[4] == 'm')
8034 { /* alarm */
8035 return -KEY_alarm;
8036 }
8037
8038 goto unknown;
8039
8040 case 't':
8041 if (name[2] == 'a' &&
8042 name[3] == 'n' &&
8043 name[4] == '2')
8044 { /* atan2 */
8045 return -KEY_atan2;
8046 }
8047
8048 goto unknown;
8049
8050 default:
8051 goto unknown;
8052 }
8053
8054 case 'b':
0d863452
RH
8055 switch (name[1])
8056 {
8057 case 'l':
8058 if (name[2] == 'e' &&
952306ac
RGS
8059 name[3] == 's' &&
8060 name[4] == 's')
8061 { /* bless */
8062 return -KEY_bless;
8063 }
4c3bbe0f 8064
952306ac 8065 goto unknown;
4c3bbe0f 8066
0d863452
RH
8067 case 'r':
8068 if (name[2] == 'e' &&
8069 name[3] == 'a' &&
8070 name[4] == 'k')
8071 { /* break */
5458a98a 8072 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
0d863452
RH
8073 }
8074
8075 goto unknown;
8076
8077 default:
8078 goto unknown;
8079 }
8080
4c3bbe0f
MHM
8081 case 'c':
8082 switch (name[1])
8083 {
8084 case 'h':
8085 switch (name[2])
8086 {
8087 case 'd':
8088 if (name[3] == 'i' &&
8089 name[4] == 'r')
8090 { /* chdir */
8091 return -KEY_chdir;
8092 }
8093
8094 goto unknown;
8095
8096 case 'm':
8097 if (name[3] == 'o' &&
8098 name[4] == 'd')
8099 { /* chmod */
8100 return -KEY_chmod;
8101 }
8102
8103 goto unknown;
8104
8105 case 'o':
8106 switch (name[3])
8107 {
8108 case 'm':
8109 if (name[4] == 'p')
8110 { /* chomp */
8111 return -KEY_chomp;
8112 }
8113
8114 goto unknown;
8115
8116 case 'w':
8117 if (name[4] == 'n')
8118 { /* chown */
8119 return -KEY_chown;
8120 }
8121
8122 goto unknown;
8123
8124 default:
8125 goto unknown;
8126 }
8127
8128 default:
8129 goto unknown;
8130 }
8131
8132 case 'l':
8133 if (name[2] == 'o' &&
8134 name[3] == 's' &&
8135 name[4] == 'e')
8136 { /* close */
8137 return -KEY_close;
8138 }
8139
8140 goto unknown;
8141
8142 case 'r':
8143 if (name[2] == 'y' &&
8144 name[3] == 'p' &&
8145 name[4] == 't')
8146 { /* crypt */
8147 return -KEY_crypt;
8148 }
8149
8150 goto unknown;
8151
8152 default:
8153 goto unknown;
8154 }
8155
8156 case 'e':
8157 if (name[1] == 'l' &&
8158 name[2] == 's' &&
8159 name[3] == 'i' &&
8160 name[4] == 'f')
8161 { /* elsif */
8162 return KEY_elsif;
8163 }
8164
8165 goto unknown;
8166
8167 case 'f':
8168 switch (name[1])
8169 {
8170 case 'c':
8171 if (name[2] == 'n' &&
8172 name[3] == 't' &&
8173 name[4] == 'l')
8174 { /* fcntl */
8175 return -KEY_fcntl;
8176 }
8177
8178 goto unknown;
8179
8180 case 'l':
8181 if (name[2] == 'o' &&
8182 name[3] == 'c' &&
8183 name[4] == 'k')
8184 { /* flock */
8185 return -KEY_flock;
8186 }
8187
8188 goto unknown;
8189
8190 default:
8191 goto unknown;
8192 }
8193
0d863452
RH
8194 case 'g':
8195 if (name[1] == 'i' &&
8196 name[2] == 'v' &&
8197 name[3] == 'e' &&
8198 name[4] == 'n')
8199 { /* given */
5458a98a 8200 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
0d863452
RH
8201 }
8202
8203 goto unknown;
8204
4c3bbe0f
MHM
8205 case 'i':
8206 switch (name[1])
8207 {
8208 case 'n':
8209 if (name[2] == 'd' &&
8210 name[3] == 'e' &&
8211 name[4] == 'x')
8212 { /* index */
8213 return -KEY_index;
8214 }
8215
8216 goto unknown;
8217
8218 case 'o':
8219 if (name[2] == 'c' &&
8220 name[3] == 't' &&
8221 name[4] == 'l')
8222 { /* ioctl */
8223 return -KEY_ioctl;
8224 }
8225
8226 goto unknown;
8227
8228 default:
8229 goto unknown;
8230 }
8231
8232 case 'l':
8233 switch (name[1])
8234 {
8235 case 'o':
8236 if (name[2] == 'c' &&
8237 name[3] == 'a' &&
8238 name[4] == 'l')
8239 { /* local */
8240 return KEY_local;
8241 }
8242
8243 goto unknown;
8244
8245 case 's':
8246 if (name[2] == 't' &&
8247 name[3] == 'a' &&
8248 name[4] == 't')
8249 { /* lstat */
8250 return -KEY_lstat;
8251 }
8252
8253 goto unknown;
8254
8255 default:
8256 goto unknown;
8257 }
8258
8259 case 'm':
8260 if (name[1] == 'k' &&
8261 name[2] == 'd' &&
8262 name[3] == 'i' &&
8263 name[4] == 'r')
8264 { /* mkdir */
8265 return -KEY_mkdir;
8266 }
8267
8268 goto unknown;
8269
8270 case 'p':
8271 if (name[1] == 'r' &&
8272 name[2] == 'i' &&
8273 name[3] == 'n' &&
8274 name[4] == 't')
8275 { /* print */
8276 return KEY_print;
8277 }
8278
8279 goto unknown;
8280
8281 case 'r':
8282 switch (name[1])
8283 {
8284 case 'e':
8285 if (name[2] == 's' &&
8286 name[3] == 'e' &&
8287 name[4] == 't')
8288 { /* reset */
8289 return -KEY_reset;
8290 }
8291
8292 goto unknown;
8293
8294 case 'm':
8295 if (name[2] == 'd' &&
8296 name[3] == 'i' &&
8297 name[4] == 'r')
8298 { /* rmdir */
8299 return -KEY_rmdir;
8300 }
8301
8302 goto unknown;
8303
8304 default:
8305 goto unknown;
8306 }
8307
8308 case 's':
8309 switch (name[1])
8310 {
8311 case 'e':
8312 if (name[2] == 'm' &&
8313 name[3] == 'o' &&
8314 name[4] == 'p')
8315 { /* semop */
8316 return -KEY_semop;
8317 }
8318
8319 goto unknown;
8320
8321 case 'h':
8322 if (name[2] == 'i' &&
8323 name[3] == 'f' &&
8324 name[4] == 't')
8325 { /* shift */
8326 return -KEY_shift;
8327 }
8328
8329 goto unknown;
8330
8331 case 'l':
8332 if (name[2] == 'e' &&
8333 name[3] == 'e' &&
8334 name[4] == 'p')
8335 { /* sleep */
8336 return -KEY_sleep;
8337 }
8338
8339 goto unknown;
8340
8341 case 'p':
8342 if (name[2] == 'l' &&
8343 name[3] == 'i' &&
8344 name[4] == 't')
8345 { /* split */
8346 return KEY_split;
8347 }
8348
8349 goto unknown;
8350
8351 case 'r':
8352 if (name[2] == 'a' &&
8353 name[3] == 'n' &&
8354 name[4] == 'd')
8355 { /* srand */
8356 return -KEY_srand;
8357 }
8358
8359 goto unknown;
8360
8361 case 't':
952306ac
RGS
8362 switch (name[2])
8363 {
8364 case 'a':
8365 if (name[3] == 't' &&
8366 name[4] == 'e')
8367 { /* state */
5458a98a 8368 return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
952306ac 8369 }
4c3bbe0f 8370
952306ac
RGS
8371 goto unknown;
8372
8373 case 'u':
8374 if (name[3] == 'd' &&
8375 name[4] == 'y')
8376 { /* study */
8377 return KEY_study;
8378 }
8379
8380 goto unknown;
8381
8382 default:
8383 goto unknown;
8384 }
4c3bbe0f
MHM
8385
8386 default:
8387 goto unknown;
8388 }
8389
8390 case 't':
8391 if (name[1] == 'i' &&
8392 name[2] == 'm' &&
8393 name[3] == 'e' &&
8394 name[4] == 's')
8395 { /* times */
8396 return -KEY_times;
8397 }
8398
8399 goto unknown;
8400
8401 case 'u':
8402 switch (name[1])
8403 {
8404 case 'm':
8405 if (name[2] == 'a' &&
8406 name[3] == 's' &&
8407 name[4] == 'k')
8408 { /* umask */
8409 return -KEY_umask;
8410 }
8411
8412 goto unknown;
8413
8414 case 'n':
8415 switch (name[2])
8416 {
8417 case 'd':
8418 if (name[3] == 'e' &&
8419 name[4] == 'f')
8420 { /* undef */
8421 return KEY_undef;
8422 }
8423
8424 goto unknown;
8425
8426 case 't':
8427 if (name[3] == 'i')
8428 {
8429 switch (name[4])
8430 {
8431 case 'e':
8432 { /* untie */
8433 return KEY_untie;
8434 }
8435
4c3bbe0f
MHM
8436 case 'l':
8437 { /* until */
8438 return KEY_until;
8439 }
8440
4c3bbe0f
MHM
8441 default:
8442 goto unknown;
8443 }
8444 }
8445
8446 goto unknown;
8447
8448 default:
8449 goto unknown;
8450 }
8451
8452 case 't':
8453 if (name[2] == 'i' &&
8454 name[3] == 'm' &&
8455 name[4] == 'e')
8456 { /* utime */
8457 return -KEY_utime;
8458 }
8459
8460 goto unknown;
8461
8462 default:
8463 goto unknown;
8464 }
8465
8466 case 'w':
8467 switch (name[1])
8468 {
8469 case 'h':
8470 if (name[2] == 'i' &&
8471 name[3] == 'l' &&
8472 name[4] == 'e')
8473 { /* while */
8474 return KEY_while;
8475 }
8476
8477 goto unknown;
8478
8479 case 'r':
8480 if (name[2] == 'i' &&
8481 name[3] == 't' &&
8482 name[4] == 'e')
8483 { /* write */
8484 return -KEY_write;
8485 }
8486
8487 goto unknown;
8488
8489 default:
8490 goto unknown;
8491 }
8492
8493 default:
8494 goto unknown;
e2e1dd5a 8495 }
4c3bbe0f
MHM
8496
8497 case 6: /* 33 tokens of length 6 */
8498 switch (name[0])
8499 {
8500 case 'a':
8501 if (name[1] == 'c' &&
8502 name[2] == 'c' &&
8503 name[3] == 'e' &&
8504 name[4] == 'p' &&
8505 name[5] == 't')
8506 { /* accept */
8507 return -KEY_accept;
8508 }
8509
8510 goto unknown;
8511
8512 case 'c':
8513 switch (name[1])
8514 {
8515 case 'a':
8516 if (name[2] == 'l' &&
8517 name[3] == 'l' &&
8518 name[4] == 'e' &&
8519 name[5] == 'r')
8520 { /* caller */
8521 return -KEY_caller;
8522 }
8523
8524 goto unknown;
8525
8526 case 'h':
8527 if (name[2] == 'r' &&
8528 name[3] == 'o' &&
8529 name[4] == 'o' &&
8530 name[5] == 't')
8531 { /* chroot */
8532 return -KEY_chroot;
8533 }
8534
8535 goto unknown;
8536
8537 default:
8538 goto unknown;
8539 }
8540
8541 case 'd':
8542 if (name[1] == 'e' &&
8543 name[2] == 'l' &&
8544 name[3] == 'e' &&
8545 name[4] == 't' &&
8546 name[5] == 'e')
8547 { /* delete */
8548 return KEY_delete;
8549 }
8550
8551 goto unknown;
8552
8553 case 'e':
8554 switch (name[1])
8555 {
8556 case 'l':
8557 if (name[2] == 's' &&
8558 name[3] == 'e' &&
8559 name[4] == 'i' &&
8560 name[5] == 'f')
8561 { /* elseif */
8562 if(ckWARN_d(WARN_SYNTAX))
8563 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8564 }
8565
8566 goto unknown;
8567
8568 case 'x':
8569 if (name[2] == 'i' &&
8570 name[3] == 's' &&
8571 name[4] == 't' &&
8572 name[5] == 's')
8573 { /* exists */
8574 return KEY_exists;
8575 }
8576
8577 goto unknown;
8578
8579 default:
8580 goto unknown;
8581 }
8582
8583 case 'f':
8584 switch (name[1])
8585 {
8586 case 'i':
8587 if (name[2] == 'l' &&
8588 name[3] == 'e' &&
8589 name[4] == 'n' &&
8590 name[5] == 'o')
8591 { /* fileno */
8592 return -KEY_fileno;
8593 }
8594
8595 goto unknown;
8596
8597 case 'o':
8598 if (name[2] == 'r' &&
8599 name[3] == 'm' &&
8600 name[4] == 'a' &&
8601 name[5] == 't')
8602 { /* format */
8603 return KEY_format;
8604 }
8605
8606 goto unknown;
8607
8608 default:
8609 goto unknown;
8610 }
8611
8612 case 'g':
8613 if (name[1] == 'm' &&
8614 name[2] == 't' &&
8615 name[3] == 'i' &&
8616 name[4] == 'm' &&
8617 name[5] == 'e')
8618 { /* gmtime */
8619 return -KEY_gmtime;
8620 }
8621
8622 goto unknown;
8623
8624 case 'l':
8625 switch (name[1])
8626 {
8627 case 'e':
8628 if (name[2] == 'n' &&
8629 name[3] == 'g' &&
8630 name[4] == 't' &&
8631 name[5] == 'h')
8632 { /* length */
8633 return -KEY_length;
8634 }
8635
8636 goto unknown;
8637
8638 case 'i':
8639 if (name[2] == 's' &&
8640 name[3] == 't' &&
8641 name[4] == 'e' &&
8642 name[5] == 'n')
8643 { /* listen */
8644 return -KEY_listen;
8645 }
8646
8647 goto unknown;
8648
8649 default:
8650 goto unknown;
8651 }
8652
8653 case 'm':
8654 if (name[1] == 's' &&
8655 name[2] == 'g')
8656 {
8657 switch (name[3])
8658 {
8659 case 'c':
8660 if (name[4] == 't' &&
8661 name[5] == 'l')
8662 { /* msgctl */
8663 return -KEY_msgctl;
8664 }
8665
8666 goto unknown;
8667
8668 case 'g':
8669 if (name[4] == 'e' &&
8670 name[5] == 't')
8671 { /* msgget */
8672 return -KEY_msgget;
8673 }
8674
8675 goto unknown;
8676
8677 case 'r':
8678 if (name[4] == 'c' &&
8679 name[5] == 'v')
8680 { /* msgrcv */
8681 return -KEY_msgrcv;
8682 }
8683
8684 goto unknown;
8685
8686 case 's':
8687 if (name[4] == 'n' &&
8688 name[5] == 'd')
8689 { /* msgsnd */
8690 return -KEY_msgsnd;
8691 }
8692
8693 goto unknown;
8694
8695 default:
8696 goto unknown;
8697 }
8698 }
8699
8700 goto unknown;
8701
8702 case 'p':
8703 if (name[1] == 'r' &&
8704 name[2] == 'i' &&
8705 name[3] == 'n' &&
8706 name[4] == 't' &&
8707 name[5] == 'f')
8708 { /* printf */
8709 return KEY_printf;
8710 }
8711
8712 goto unknown;
8713
8714 case 'r':
8715 switch (name[1])
8716 {
8717 case 'e':
8718 switch (name[2])
8719 {
8720 case 'n':
8721 if (name[3] == 'a' &&
8722 name[4] == 'm' &&
8723 name[5] == 'e')
8724 { /* rename */
8725 return -KEY_rename;
8726 }
8727
8728 goto unknown;
8729
8730 case 't':
8731 if (name[3] == 'u' &&
8732 name[4] == 'r' &&
8733 name[5] == 'n')
8734 { /* return */
8735 return KEY_return;
8736 }
8737
8738 goto unknown;
8739
8740 default:
8741 goto unknown;
8742 }
8743
8744 case 'i':
8745 if (name[2] == 'n' &&
8746 name[3] == 'd' &&
8747 name[4] == 'e' &&
8748 name[5] == 'x')
8749 { /* rindex */
8750 return -KEY_rindex;
8751 }
8752
8753 goto unknown;
8754
8755 default:
8756 goto unknown;
8757 }
8758
8759 case 's':
8760 switch (name[1])
8761 {
8762 case 'c':
8763 if (name[2] == 'a' &&
8764 name[3] == 'l' &&
8765 name[4] == 'a' &&
8766 name[5] == 'r')
8767 { /* scalar */
8768 return KEY_scalar;
8769 }
8770
8771 goto unknown;
8772
8773 case 'e':
8774 switch (name[2])
8775 {
8776 case 'l':
8777 if (name[3] == 'e' &&
8778 name[4] == 'c' &&
8779 name[5] == 't')
8780 { /* select */
8781 return -KEY_select;
8782 }
8783
8784 goto unknown;
8785
8786 case 'm':
8787 switch (name[3])
8788 {
8789 case 'c':
8790 if (name[4] == 't' &&
8791 name[5] == 'l')
8792 { /* semctl */
8793 return -KEY_semctl;
8794 }
8795
8796 goto unknown;
8797
8798 case 'g':
8799 if (name[4] == 'e' &&
8800 name[5] == 't')
8801 { /* semget */
8802 return -KEY_semget;
8803 }
8804
8805 goto unknown;
8806
8807 default:
8808 goto unknown;
8809 }
8810
8811 default:
8812 goto unknown;
8813 }
8814
8815 case 'h':
8816 if (name[2] == 'm')
8817 {
8818 switch (name[3])
8819 {
8820 case 'c':
8821 if (name[4] == 't' &&
8822 name[5] == 'l')
8823 { /* shmctl */
8824 return -KEY_shmctl;
8825 }
8826
8827 goto unknown;
8828
8829 case 'g':
8830 if (name[4] == 'e' &&
8831 name[5] == 't')
8832 { /* shmget */
8833 return -KEY_shmget;
8834 }
8835
8836 goto unknown;
8837
8838 default:
8839 goto unknown;
8840 }
8841 }
8842
8843 goto unknown;
8844
8845 case 'o':
8846 if (name[2] == 'c' &&
8847 name[3] == 'k' &&
8848 name[4] == 'e' &&
8849 name[5] == 't')
8850 { /* socket */
8851 return -KEY_socket;
8852 }
8853
8854 goto unknown;
8855
8856 case 'p':
8857 if (name[2] == 'l' &&
8858 name[3] == 'i' &&
8859 name[4] == 'c' &&
8860 name[5] == 'e')
8861 { /* splice */
8862 return -KEY_splice;
8863 }
8864
8865 goto unknown;
8866
8867 case 'u':
8868 if (name[2] == 'b' &&
8869 name[3] == 's' &&
8870 name[4] == 't' &&
8871 name[5] == 'r')
8872 { /* substr */
8873 return -KEY_substr;
8874 }
8875
8876 goto unknown;
8877
8878 case 'y':
8879 if (name[2] == 's' &&
8880 name[3] == 't' &&
8881 name[4] == 'e' &&
8882 name[5] == 'm')
8883 { /* system */
8884 return -KEY_system;
8885 }
8886
8887 goto unknown;
8888
8889 default:
8890 goto unknown;
8891 }
8892
8893 case 'u':
8894 if (name[1] == 'n')
8895 {
8896 switch (name[2])
8897 {
8898 case 'l':
8899 switch (name[3])
8900 {
8901 case 'e':
8902 if (name[4] == 's' &&
8903 name[5] == 's')
8904 { /* unless */
8905 return KEY_unless;
8906 }
8907
8908 goto unknown;
8909
8910 case 'i':
8911 if (name[4] == 'n' &&
8912 name[5] == 'k')
8913 { /* unlink */
8914 return -KEY_unlink;
8915 }
8916
8917 goto unknown;
8918
8919 default:
8920 goto unknown;
8921 }
8922
8923 case 'p':
8924 if (name[3] == 'a' &&
8925 name[4] == 'c' &&
8926 name[5] == 'k')
8927 { /* unpack */
8928 return -KEY_unpack;
8929 }
8930
8931 goto unknown;
8932
8933 default:
8934 goto unknown;
8935 }
8936 }
8937
8938 goto unknown;
8939
8940 case 'v':
8941 if (name[1] == 'a' &&
8942 name[2] == 'l' &&
8943 name[3] == 'u' &&
8944 name[4] == 'e' &&
8945 name[5] == 's')
8946 { /* values */
8947 return -KEY_values;
8948 }
8949
8950 goto unknown;
8951
8952 default:
8953 goto unknown;
e2e1dd5a 8954 }
4c3bbe0f 8955
0d863452 8956 case 7: /* 29 tokens of length 7 */
4c3bbe0f
MHM
8957 switch (name[0])
8958 {
8959 case 'D':
8960 if (name[1] == 'E' &&
8961 name[2] == 'S' &&
8962 name[3] == 'T' &&
8963 name[4] == 'R' &&
8964 name[5] == 'O' &&
8965 name[6] == 'Y')
8966 { /* DESTROY */
8967 return KEY_DESTROY;
8968 }
8969
8970 goto unknown;
8971
8972 case '_':
8973 if (name[1] == '_' &&
8974 name[2] == 'E' &&
8975 name[3] == 'N' &&
8976 name[4] == 'D' &&
8977 name[5] == '_' &&
8978 name[6] == '_')
8979 { /* __END__ */
8980 return KEY___END__;
8981 }
8982
8983 goto unknown;
8984
8985 case 'b':
8986 if (name[1] == 'i' &&
8987 name[2] == 'n' &&
8988 name[3] == 'm' &&
8989 name[4] == 'o' &&
8990 name[5] == 'd' &&
8991 name[6] == 'e')
8992 { /* binmode */
8993 return -KEY_binmode;
8994 }
8995
8996 goto unknown;
8997
8998 case 'c':
8999 if (name[1] == 'o' &&
9000 name[2] == 'n' &&
9001 name[3] == 'n' &&
9002 name[4] == 'e' &&
9003 name[5] == 'c' &&
9004 name[6] == 't')
9005 { /* connect */
9006 return -KEY_connect;
9007 }
9008
9009 goto unknown;
9010
9011 case 'd':
9012 switch (name[1])
9013 {
9014 case 'b':
9015 if (name[2] == 'm' &&
9016 name[3] == 'o' &&
9017 name[4] == 'p' &&
9018 name[5] == 'e' &&
9019 name[6] == 'n')
9020 { /* dbmopen */
9021 return -KEY_dbmopen;
9022 }
9023
9024 goto unknown;
9025
9026 case 'e':
0d863452
RH
9027 if (name[2] == 'f')
9028 {
9029 switch (name[3])
9030 {
9031 case 'a':
9032 if (name[4] == 'u' &&
9033 name[5] == 'l' &&
9034 name[6] == 't')
9035 { /* default */
5458a98a 9036 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
0d863452
RH
9037 }
9038
9039 goto unknown;
9040
9041 case 'i':
9042 if (name[4] == 'n' &&
952306ac
RGS
9043 name[5] == 'e' &&
9044 name[6] == 'd')
9045 { /* defined */
9046 return KEY_defined;
9047 }
4c3bbe0f 9048
952306ac 9049 goto unknown;
4c3bbe0f 9050
952306ac
RGS
9051 default:
9052 goto unknown;
9053 }
0d863452
RH
9054 }
9055
9056 goto unknown;
9057
9058 default:
9059 goto unknown;
9060 }
4c3bbe0f
MHM
9061
9062 case 'f':
9063 if (name[1] == 'o' &&
9064 name[2] == 'r' &&
9065 name[3] == 'e' &&
9066 name[4] == 'a' &&
9067 name[5] == 'c' &&
9068 name[6] == 'h')
9069 { /* foreach */
9070 return KEY_foreach;
9071 }
9072
9073 goto unknown;
9074
9075 case 'g':
9076 if (name[1] == 'e' &&
9077 name[2] == 't' &&
9078 name[3] == 'p')
9079 {
9080 switch (name[4])
9081 {
9082 case 'g':
9083 if (name[5] == 'r' &&
9084 name[6] == 'p')
9085 { /* getpgrp */
9086 return -KEY_getpgrp;
9087 }
9088
9089 goto unknown;
9090
9091 case 'p':
9092 if (name[5] == 'i' &&
9093 name[6] == 'd')
9094 { /* getppid */
9095 return -KEY_getppid;
9096 }
9097
9098 goto unknown;
9099
9100 default:
9101 goto unknown;
9102 }
9103 }
9104
9105 goto unknown;
9106
9107 case 'l':
9108 if (name[1] == 'c' &&
9109 name[2] == 'f' &&
9110 name[3] == 'i' &&
9111 name[4] == 'r' &&
9112 name[5] == 's' &&
9113 name[6] == 't')
9114 { /* lcfirst */
9115 return -KEY_lcfirst;
9116 }
9117
9118 goto unknown;
9119
9120 case 'o':
9121 if (name[1] == 'p' &&
9122 name[2] == 'e' &&
9123 name[3] == 'n' &&
9124 name[4] == 'd' &&
9125 name[5] == 'i' &&
9126 name[6] == 'r')
9127 { /* opendir */
9128 return -KEY_opendir;
9129 }
9130
9131 goto unknown;
9132
9133 case 'p':
9134 if (name[1] == 'a' &&
9135 name[2] == 'c' &&
9136 name[3] == 'k' &&
9137 name[4] == 'a' &&
9138 name[5] == 'g' &&
9139 name[6] == 'e')
9140 { /* package */
9141 return KEY_package;
9142 }
9143
9144 goto unknown;
9145
9146 case 'r':
9147 if (name[1] == 'e')
9148 {
9149 switch (name[2])
9150 {
9151 case 'a':
9152 if (name[3] == 'd' &&
9153 name[4] == 'd' &&
9154 name[5] == 'i' &&
9155 name[6] == 'r')
9156 { /* readdir */
9157 return -KEY_readdir;
9158 }
9159
9160 goto unknown;
9161
9162 case 'q':
9163 if (name[3] == 'u' &&
9164 name[4] == 'i' &&
9165 name[5] == 'r' &&
9166 name[6] == 'e')
9167 { /* require */
9168 return KEY_require;
9169 }
9170
9171 goto unknown;
9172
9173 case 'v':
9174 if (name[3] == 'e' &&
9175 name[4] == 'r' &&
9176 name[5] == 's' &&
9177 name[6] == 'e')
9178 { /* reverse */
9179 return -KEY_reverse;
9180 }
9181
9182 goto unknown;
9183
9184 default:
9185 goto unknown;
9186 }
9187 }
9188
9189 goto unknown;
9190
9191 case 's':
9192 switch (name[1])
9193 {
9194 case 'e':
9195 switch (name[2])
9196 {
9197 case 'e':
9198 if (name[3] == 'k' &&
9199 name[4] == 'd' &&
9200 name[5] == 'i' &&
9201 name[6] == 'r')
9202 { /* seekdir */
9203 return -KEY_seekdir;
9204 }
9205
9206 goto unknown;
9207
9208 case 't':
9209 if (name[3] == 'p' &&
9210 name[4] == 'g' &&
9211 name[5] == 'r' &&
9212 name[6] == 'p')
9213 { /* setpgrp */
9214 return -KEY_setpgrp;
9215 }
9216
9217 goto unknown;
9218
9219 default:
9220 goto unknown;
9221 }
9222
9223 case 'h':
9224 if (name[2] == 'm' &&
9225 name[3] == 'r' &&
9226 name[4] == 'e' &&
9227 name[5] == 'a' &&
9228 name[6] == 'd')
9229 { /* shmread */
9230 return -KEY_shmread;
9231 }
9232
9233 goto unknown;
9234
9235 case 'p':
9236 if (name[2] == 'r' &&
9237 name[3] == 'i' &&
9238 name[4] == 'n' &&
9239 name[5] == 't' &&
9240 name[6] == 'f')
9241 { /* sprintf */
9242 return -KEY_sprintf;
9243 }
9244
9245 goto unknown;
9246
9247 case 'y':
9248 switch (name[2])
9249 {
9250 case 'm':
9251 if (name[3] == 'l' &&
9252 name[4] == 'i' &&
9253 name[5] == 'n' &&
9254 name[6] == 'k')
9255 { /* symlink */
9256 return -KEY_symlink;
9257 }
9258
9259 goto unknown;
9260
9261 case 's':
9262 switch (name[3])
9263 {
9264 case 'c':
9265 if (name[4] == 'a' &&
9266 name[5] == 'l' &&
9267 name[6] == 'l')
9268 { /* syscall */
9269 return -KEY_syscall;
9270 }
9271
9272 goto unknown;
9273
9274 case 'o':
9275 if (name[4] == 'p' &&
9276 name[5] == 'e' &&
9277 name[6] == 'n')
9278 { /* sysopen */
9279 return -KEY_sysopen;
9280 }
9281
9282 goto unknown;
9283
9284 case 'r':
9285 if (name[4] == 'e' &&
9286 name[5] == 'a' &&
9287 name[6] == 'd')
9288 { /* sysread */
9289 return -KEY_sysread;
9290 }
9291
9292 goto unknown;
9293
9294 case 's':
9295 if (name[4] == 'e' &&
9296 name[5] == 'e' &&
9297 name[6] == 'k')
9298 { /* sysseek */
9299 return -KEY_sysseek;
9300 }
9301
9302 goto unknown;
9303
9304 default:
9305 goto unknown;
9306 }
9307
9308 default:
9309 goto unknown;
9310 }
9311
9312 default:
9313 goto unknown;
9314 }
9315
9316 case 't':
9317 if (name[1] == 'e' &&
9318 name[2] == 'l' &&
9319 name[3] == 'l' &&
9320 name[4] == 'd' &&
9321 name[5] == 'i' &&
9322 name[6] == 'r')
9323 { /* telldir */
9324 return -KEY_telldir;
9325 }
9326
9327 goto unknown;
9328
9329 case 'u':
9330 switch (name[1])
9331 {
9332 case 'c':
9333 if (name[2] == 'f' &&
9334 name[3] == 'i' &&
9335 name[4] == 'r' &&
9336 name[5] == 's' &&
9337 name[6] == 't')
9338 { /* ucfirst */
9339 return -KEY_ucfirst;
9340 }
9341
9342 goto unknown;
9343
9344 case 'n':
9345 if (name[2] == 's' &&
9346 name[3] == 'h' &&
9347 name[4] == 'i' &&
9348 name[5] == 'f' &&
9349 name[6] == 't')
9350 { /* unshift */
9351 return -KEY_unshift;
9352 }
9353
9354 goto unknown;
9355
9356 default:
9357 goto unknown;
9358 }
9359
9360 case 'w':
9361 if (name[1] == 'a' &&
9362 name[2] == 'i' &&
9363 name[3] == 't' &&
9364 name[4] == 'p' &&
9365 name[5] == 'i' &&
9366 name[6] == 'd')
9367 { /* waitpid */
9368 return -KEY_waitpid;
9369 }
9370
9371 goto unknown;
9372
9373 default:
9374 goto unknown;
9375 }
9376
9377 case 8: /* 26 tokens of length 8 */
9378 switch (name[0])
9379 {
9380 case 'A':
9381 if (name[1] == 'U' &&
9382 name[2] == 'T' &&
9383 name[3] == 'O' &&
9384 name[4] == 'L' &&
9385 name[5] == 'O' &&
9386 name[6] == 'A' &&
9387 name[7] == 'D')
9388 { /* AUTOLOAD */
9389 return KEY_AUTOLOAD;
9390 }
9391
9392 goto unknown;
9393
9394 case '_':
9395 if (name[1] == '_')
9396 {
9397 switch (name[2])
9398 {
9399 case 'D':
9400 if (name[3] == 'A' &&
9401 name[4] == 'T' &&
9402 name[5] == 'A' &&
9403 name[6] == '_' &&
9404 name[7] == '_')
9405 { /* __DATA__ */
9406 return KEY___DATA__;
9407 }
9408
9409 goto unknown;
9410
9411 case 'F':
9412 if (name[3] == 'I' &&
9413 name[4] == 'L' &&
9414 name[5] == 'E' &&
9415 name[6] == '_' &&
9416 name[7] == '_')
9417 { /* __FILE__ */
9418 return -KEY___FILE__;
9419 }
9420
9421 goto unknown;
9422
9423 case 'L':
9424 if (name[3] == 'I' &&
9425 name[4] == 'N' &&
9426 name[5] == 'E' &&
9427 name[6] == '_' &&
9428 name[7] == '_')
9429 { /* __LINE__ */
9430 return -KEY___LINE__;
9431 }
9432
9433 goto unknown;
9434
9435 default:
9436 goto unknown;
9437 }
9438 }
9439
9440 goto unknown;
9441
9442 case 'c':
9443 switch (name[1])
9444 {
9445 case 'l':
9446 if (name[2] == 'o' &&
9447 name[3] == 's' &&
9448 name[4] == 'e' &&
9449 name[5] == 'd' &&
9450 name[6] == 'i' &&
9451 name[7] == 'r')
9452 { /* closedir */
9453 return -KEY_closedir;
9454 }
9455
9456 goto unknown;
9457
9458 case 'o':
9459 if (name[2] == 'n' &&
9460 name[3] == 't' &&
9461 name[4] == 'i' &&
9462 name[5] == 'n' &&
9463 name[6] == 'u' &&
9464 name[7] == 'e')
9465 { /* continue */
9466 return -KEY_continue;
9467 }
9468
9469 goto unknown;
9470
9471 default:
9472 goto unknown;
9473 }
9474
9475 case 'd':
9476 if (name[1] == 'b' &&
9477 name[2] == 'm' &&
9478 name[3] == 'c' &&
9479 name[4] == 'l' &&
9480 name[5] == 'o' &&
9481 name[6] == 's' &&
9482 name[7] == 'e')
9483 { /* dbmclose */
9484 return -KEY_dbmclose;
9485 }
9486
9487 goto unknown;
9488
9489 case 'e':
9490 if (name[1] == 'n' &&
9491 name[2] == 'd')
9492 {
9493 switch (name[3])
9494 {
9495 case 'g':
9496 if (name[4] == 'r' &&
9497 name[5] == 'e' &&
9498 name[6] == 'n' &&
9499 name[7] == 't')
9500 { /* endgrent */
9501 return -KEY_endgrent;
9502 }
9503
9504 goto unknown;
9505
9506 case 'p':
9507 if (name[4] == 'w' &&
9508 name[5] == 'e' &&
9509 name[6] == 'n' &&
9510 name[7] == 't')
9511 { /* endpwent */
9512 return -KEY_endpwent;
9513 }
9514
9515 goto unknown;
9516
9517 default:
9518 goto unknown;
9519 }
9520 }
9521
9522 goto unknown;
9523
9524 case 'f':
9525 if (name[1] == 'o' &&
9526 name[2] == 'r' &&
9527 name[3] == 'm' &&
9528 name[4] == 'l' &&
9529 name[5] == 'i' &&
9530 name[6] == 'n' &&
9531 name[7] == 'e')
9532 { /* formline */
9533 return -KEY_formline;
9534 }
9535
9536 goto unknown;
9537
9538 case 'g':
9539 if (name[1] == 'e' &&
9540 name[2] == 't')
9541 {
9542 switch (name[3])
9543 {
9544 case 'g':
9545 if (name[4] == 'r')
9546 {
9547 switch (name[5])
9548 {
9549 case 'e':
9550 if (name[6] == 'n' &&
9551 name[7] == 't')
9552 { /* getgrent */
9553 return -KEY_getgrent;
9554 }
9555
9556 goto unknown;
9557
9558 case 'g':
9559 if (name[6] == 'i' &&
9560 name[7] == 'd')
9561 { /* getgrgid */
9562 return -KEY_getgrgid;
9563 }
9564
9565 goto unknown;
9566
9567 case 'n':
9568 if (name[6] == 'a' &&
9569 name[7] == 'm')
9570 { /* getgrnam */
9571 return -KEY_getgrnam;
9572 }
9573
9574 goto unknown;
9575
9576 default:
9577 goto unknown;
9578 }
9579 }
9580
9581 goto unknown;
9582
9583 case 'l':
9584 if (name[4] == 'o' &&
9585 name[5] == 'g' &&
9586 name[6] == 'i' &&
9587 name[7] == 'n')
9588 { /* getlogin */
9589 return -KEY_getlogin;
9590 }
9591
9592 goto unknown;
9593
9594 case 'p':
9595 if (name[4] == 'w')
9596 {
9597 switch (name[5])
9598 {
9599 case 'e':
9600 if (name[6] == 'n' &&
9601 name[7] == 't')
9602 { /* getpwent */
9603 return -KEY_getpwent;
9604 }
9605
9606 goto unknown;
9607
9608 case 'n':
9609 if (name[6] == 'a' &&
9610 name[7] == 'm')
9611 { /* getpwnam */
9612 return -KEY_getpwnam;
9613 }
9614
9615 goto unknown;
9616
9617 case 'u':
9618 if (name[6] == 'i' &&
9619 name[7] == 'd')
9620 { /* getpwuid */
9621 return -KEY_getpwuid;
9622 }
9623
9624 goto unknown;
9625
9626 default:
9627 goto unknown;
9628 }
9629 }
9630
9631 goto unknown;
9632
9633 default:
9634 goto unknown;
9635 }
9636 }
9637
9638 goto unknown;
9639
9640 case 'r':
9641 if (name[1] == 'e' &&
9642 name[2] == 'a' &&
9643 name[3] == 'd')
9644 {
9645 switch (name[4])
9646 {
9647 case 'l':
9648 if (name[5] == 'i' &&
9649 name[6] == 'n')
9650 {
9651 switch (name[7])
9652 {
9653 case 'e':
9654 { /* readline */
9655 return -KEY_readline;
9656 }
9657
4c3bbe0f
MHM
9658 case 'k':
9659 { /* readlink */
9660 return -KEY_readlink;
9661 }
9662
4c3bbe0f
MHM
9663 default:
9664 goto unknown;
9665 }
9666 }
9667
9668 goto unknown;
9669
9670 case 'p':
9671 if (name[5] == 'i' &&
9672 name[6] == 'p' &&
9673 name[7] == 'e')
9674 { /* readpipe */
9675 return -KEY_readpipe;
9676 }
9677
9678 goto unknown;
9679
9680 default:
9681 goto unknown;
9682 }
9683 }
9684
9685 goto unknown;
9686
9687 case 's':
9688 switch (name[1])
9689 {
9690 case 'e':
9691 if (name[2] == 't')
9692 {
9693 switch (name[3])
9694 {
9695 case 'g':
9696 if (name[4] == 'r' &&
9697 name[5] == 'e' &&
9698 name[6] == 'n' &&
9699 name[7] == 't')
9700 { /* setgrent */
9701 return -KEY_setgrent;
9702 }
9703
9704 goto unknown;
9705
9706 case 'p':
9707 if (name[4] == 'w' &&
9708 name[5] == 'e' &&
9709 name[6] == 'n' &&
9710 name[7] == 't')
9711 { /* setpwent */
9712 return -KEY_setpwent;
9713 }
9714
9715 goto unknown;
9716
9717 default:
9718 goto unknown;
9719 }
9720 }
9721
9722 goto unknown;
9723
9724 case 'h':
9725 switch (name[2])
9726 {
9727 case 'm':
9728 if (name[3] == 'w' &&
9729 name[4] == 'r' &&
9730 name[5] == 'i' &&
9731 name[6] == 't' &&
9732 name[7] == 'e')
9733 { /* shmwrite */
9734 return -KEY_shmwrite;
9735 }
9736
9737 goto unknown;
9738
9739 case 'u':
9740 if (name[3] == 't' &&
9741 name[4] == 'd' &&
9742 name[5] == 'o' &&
9743 name[6] == 'w' &&
9744 name[7] == 'n')
9745 { /* shutdown */
9746 return -KEY_shutdown;
9747 }
9748
9749 goto unknown;
9750
9751 default:
9752 goto unknown;
9753 }
9754
9755 case 'y':
9756 if (name[2] == 's' &&
9757 name[3] == 'w' &&
9758 name[4] == 'r' &&
9759 name[5] == 'i' &&
9760 name[6] == 't' &&
9761 name[7] == 'e')
9762 { /* syswrite */
9763 return -KEY_syswrite;
9764 }
9765
9766 goto unknown;
9767
9768 default:
9769 goto unknown;
9770 }
9771
9772 case 't':
9773 if (name[1] == 'r' &&
9774 name[2] == 'u' &&
9775 name[3] == 'n' &&
9776 name[4] == 'c' &&
9777 name[5] == 'a' &&
9778 name[6] == 't' &&
9779 name[7] == 'e')
9780 { /* truncate */
9781 return -KEY_truncate;
9782 }
9783
9784 goto unknown;
9785
9786 default:
9787 goto unknown;
9788 }
9789
3c10abe3 9790 case 9: /* 9 tokens of length 9 */
4c3bbe0f
MHM
9791 switch (name[0])
9792 {
3c10abe3
AG
9793 case 'U':
9794 if (name[1] == 'N' &&
9795 name[2] == 'I' &&
9796 name[3] == 'T' &&
9797 name[4] == 'C' &&
9798 name[5] == 'H' &&
9799 name[6] == 'E' &&
9800 name[7] == 'C' &&
9801 name[8] == 'K')
9802 { /* UNITCHECK */
9803 return KEY_UNITCHECK;
9804 }
9805
9806 goto unknown;
9807
4c3bbe0f
MHM
9808 case 'e':
9809 if (name[1] == 'n' &&
9810 name[2] == 'd' &&
9811 name[3] == 'n' &&
9812 name[4] == 'e' &&
9813 name[5] == 't' &&
9814 name[6] == 'e' &&
9815 name[7] == 'n' &&
9816 name[8] == 't')
9817 { /* endnetent */
9818 return -KEY_endnetent;
9819 }
9820
9821 goto unknown;
9822
9823 case 'g':
9824 if (name[1] == 'e' &&
9825 name[2] == 't' &&
9826 name[3] == 'n' &&
9827 name[4] == 'e' &&
9828 name[5] == 't' &&
9829 name[6] == 'e' &&
9830 name[7] == 'n' &&
9831 name[8] == 't')
9832 { /* getnetent */
9833 return -KEY_getnetent;
9834 }
9835
9836 goto unknown;
9837
9838 case 'l':
9839 if (name[1] == 'o' &&
9840 name[2] == 'c' &&
9841 name[3] == 'a' &&
9842 name[4] == 'l' &&
9843 name[5] == 't' &&
9844 name[6] == 'i' &&
9845 name[7] == 'm' &&
9846 name[8] == 'e')
9847 { /* localtime */
9848 return -KEY_localtime;
9849 }
9850
9851 goto unknown;
9852
9853 case 'p':
9854 if (name[1] == 'r' &&
9855 name[2] == 'o' &&
9856 name[3] == 't' &&
9857 name[4] == 'o' &&
9858 name[5] == 't' &&
9859 name[6] == 'y' &&
9860 name[7] == 'p' &&
9861 name[8] == 'e')
9862 { /* prototype */
9863 return KEY_prototype;
9864 }
9865
9866 goto unknown;
9867
9868 case 'q':
9869 if (name[1] == 'u' &&
9870 name[2] == 'o' &&
9871 name[3] == 't' &&
9872 name[4] == 'e' &&
9873 name[5] == 'm' &&
9874 name[6] == 'e' &&
9875 name[7] == 't' &&
9876 name[8] == 'a')
9877 { /* quotemeta */
9878 return -KEY_quotemeta;
9879 }
9880
9881 goto unknown;
9882
9883 case 'r':
9884 if (name[1] == 'e' &&
9885 name[2] == 'w' &&
9886 name[3] == 'i' &&
9887 name[4] == 'n' &&
9888 name[5] == 'd' &&
9889 name[6] == 'd' &&
9890 name[7] == 'i' &&
9891 name[8] == 'r')
9892 { /* rewinddir */
9893 return -KEY_rewinddir;
9894 }
9895
9896 goto unknown;
9897
9898 case 's':
9899 if (name[1] == 'e' &&
9900 name[2] == 't' &&
9901 name[3] == 'n' &&
9902 name[4] == 'e' &&
9903 name[5] == 't' &&
9904 name[6] == 'e' &&
9905 name[7] == 'n' &&
9906 name[8] == 't')
9907 { /* setnetent */
9908 return -KEY_setnetent;
9909 }
9910
9911 goto unknown;
9912
9913 case 'w':
9914 if (name[1] == 'a' &&
9915 name[2] == 'n' &&
9916 name[3] == 't' &&
9917 name[4] == 'a' &&
9918 name[5] == 'r' &&
9919 name[6] == 'r' &&
9920 name[7] == 'a' &&
9921 name[8] == 'y')
9922 { /* wantarray */
9923 return -KEY_wantarray;
9924 }
9925
9926 goto unknown;
9927
9928 default:
9929 goto unknown;
9930 }
9931
9932 case 10: /* 9 tokens of length 10 */
9933 switch (name[0])
9934 {
9935 case 'e':
9936 if (name[1] == 'n' &&
9937 name[2] == 'd')
9938 {
9939 switch (name[3])
9940 {
9941 case 'h':
9942 if (name[4] == 'o' &&
9943 name[5] == 's' &&
9944 name[6] == 't' &&
9945 name[7] == 'e' &&
9946 name[8] == 'n' &&
9947 name[9] == 't')
9948 { /* endhostent */
9949 return -KEY_endhostent;
9950 }
9951
9952 goto unknown;
9953
9954 case 's':
9955 if (name[4] == 'e' &&
9956 name[5] == 'r' &&
9957 name[6] == 'v' &&
9958 name[7] == 'e' &&
9959 name[8] == 'n' &&
9960 name[9] == 't')
9961 { /* endservent */
9962 return -KEY_endservent;
9963 }
9964
9965 goto unknown;
9966
9967 default:
9968 goto unknown;
9969 }
9970 }
9971
9972 goto unknown;
9973
9974 case 'g':
9975 if (name[1] == 'e' &&
9976 name[2] == 't')
9977 {
9978 switch (name[3])
9979 {
9980 case 'h':
9981 if (name[4] == 'o' &&
9982 name[5] == 's' &&
9983 name[6] == 't' &&
9984 name[7] == 'e' &&
9985 name[8] == 'n' &&
9986 name[9] == 't')
9987 { /* gethostent */
9988 return -KEY_gethostent;
9989 }
9990
9991 goto unknown;
9992
9993 case 's':
9994 switch (name[4])
9995 {
9996 case 'e':
9997 if (name[5] == 'r' &&
9998 name[6] == 'v' &&
9999 name[7] == 'e' &&
10000 name[8] == 'n' &&
10001 name[9] == 't')
10002 { /* getservent */
10003 return -KEY_getservent;
10004 }
10005
10006 goto unknown;
10007
10008 case 'o':
10009 if (name[5] == 'c' &&
10010 name[6] == 'k' &&
10011 name[7] == 'o' &&
10012 name[8] == 'p' &&
10013 name[9] == 't')
10014 { /* getsockopt */
10015 return -KEY_getsockopt;
10016 }
10017
10018 goto unknown;
10019
10020 default:
10021 goto unknown;
10022 }
10023
10024 default:
10025 goto unknown;
10026 }
10027 }
10028
10029 goto unknown;
10030
10031 case 's':
10032 switch (name[1])
10033 {
10034 case 'e':
10035 if (name[2] == 't')
10036 {
10037 switch (name[3])
10038 {
10039 case 'h':
10040 if (name[4] == 'o' &&
10041 name[5] == 's' &&
10042 name[6] == 't' &&
10043 name[7] == 'e' &&
10044 name[8] == 'n' &&
10045 name[9] == 't')
10046 { /* sethostent */
10047 return -KEY_sethostent;
10048 }
10049
10050 goto unknown;
10051
10052 case 's':
10053 switch (name[4])
10054 {
10055 case 'e':
10056 if (name[5] == 'r' &&
10057 name[6] == 'v' &&
10058 name[7] == 'e' &&
10059 name[8] == 'n' &&
10060 name[9] == 't')
10061 { /* setservent */
10062 return -KEY_setservent;
10063 }
10064
10065 goto unknown;
10066
10067 case 'o':
10068 if (name[5] == 'c' &&
10069 name[6] == 'k' &&
10070 name[7] == 'o' &&
10071 name[8] == 'p' &&
10072 name[9] == 't')
10073 { /* setsockopt */
10074 return -KEY_setsockopt;
10075 }
10076
10077 goto unknown;
10078
10079 default:
10080 goto unknown;
10081 }
10082
10083 default:
10084 goto unknown;
10085 }
10086 }
10087
10088 goto unknown;
10089
10090 case 'o':
10091 if (name[2] == 'c' &&
10092 name[3] == 'k' &&
10093 name[4] == 'e' &&
10094 name[5] == 't' &&
10095 name[6] == 'p' &&
10096 name[7] == 'a' &&
10097 name[8] == 'i' &&
10098 name[9] == 'r')
10099 { /* socketpair */
10100 return -KEY_socketpair;
10101 }
10102
10103 goto unknown;
10104
10105 default:
10106 goto unknown;
10107 }
10108
10109 default:
10110 goto unknown;
e2e1dd5a 10111 }
4c3bbe0f
MHM
10112
10113 case 11: /* 8 tokens of length 11 */
10114 switch (name[0])
10115 {
10116 case '_':
10117 if (name[1] == '_' &&
10118 name[2] == 'P' &&
10119 name[3] == 'A' &&
10120 name[4] == 'C' &&
10121 name[5] == 'K' &&
10122 name[6] == 'A' &&
10123 name[7] == 'G' &&
10124 name[8] == 'E' &&
10125 name[9] == '_' &&
10126 name[10] == '_')
10127 { /* __PACKAGE__ */
10128 return -KEY___PACKAGE__;
10129 }
10130
10131 goto unknown;
10132
10133 case 'e':
10134 if (name[1] == 'n' &&
10135 name[2] == 'd' &&
10136 name[3] == 'p' &&
10137 name[4] == 'r' &&
10138 name[5] == 'o' &&
10139 name[6] == 't' &&
10140 name[7] == 'o' &&
10141 name[8] == 'e' &&
10142 name[9] == 'n' &&
10143 name[10] == 't')
10144 { /* endprotoent */
10145 return -KEY_endprotoent;
10146 }
10147
10148 goto unknown;
10149
10150 case 'g':
10151 if (name[1] == 'e' &&
10152 name[2] == 't')
10153 {
10154 switch (name[3])
10155 {
10156 case 'p':
10157 switch (name[4])
10158 {
10159 case 'e':
10160 if (name[5] == 'e' &&
10161 name[6] == 'r' &&
10162 name[7] == 'n' &&
10163 name[8] == 'a' &&
10164 name[9] == 'm' &&
10165 name[10] == 'e')
10166 { /* getpeername */
10167 return -KEY_getpeername;
10168 }
10169
10170 goto unknown;
10171
10172 case 'r':
10173 switch (name[5])
10174 {
10175 case 'i':
10176 if (name[6] == 'o' &&
10177 name[7] == 'r' &&
10178 name[8] == 'i' &&
10179 name[9] == 't' &&
10180 name[10] == 'y')
10181 { /* getpriority */
10182 return -KEY_getpriority;
10183 }
10184
10185 goto unknown;
10186
10187 case 'o':
10188 if (name[6] == 't' &&
10189 name[7] == 'o' &&
10190 name[8] == 'e' &&
10191 name[9] == 'n' &&
10192 name[10] == 't')
10193 { /* getprotoent */
10194 return -KEY_getprotoent;
10195 }
10196
10197 goto unknown;
10198
10199 default:
10200 goto unknown;
10201 }
10202
10203 default:
10204 goto unknown;
10205 }
10206
10207 case 's':
10208 if (name[4] == 'o' &&
10209 name[5] == 'c' &&
10210 name[6] == 'k' &&
10211 name[7] == 'n' &&
10212 name[8] == 'a' &&
10213 name[9] == 'm' &&
10214 name[10] == 'e')
10215 { /* getsockname */
10216 return -KEY_getsockname;
10217 }
10218
10219 goto unknown;
10220
10221 default:
10222 goto unknown;
10223 }
10224 }
10225
10226 goto unknown;
10227
10228 case 's':
10229 if (name[1] == 'e' &&
10230 name[2] == 't' &&
10231 name[3] == 'p' &&
10232 name[4] == 'r')
10233 {
10234 switch (name[5])
10235 {
10236 case 'i':
10237 if (name[6] == 'o' &&
10238 name[7] == 'r' &&
10239 name[8] == 'i' &&
10240 name[9] == 't' &&
10241 name[10] == 'y')
10242 { /* setpriority */
10243 return -KEY_setpriority;
10244 }
10245
10246 goto unknown;
10247
10248 case 'o':
10249 if (name[6] == 't' &&
10250 name[7] == 'o' &&
10251 name[8] == 'e' &&
10252 name[9] == 'n' &&
10253 name[10] == 't')
10254 { /* setprotoent */
10255 return -KEY_setprotoent;
10256 }
10257
10258 goto unknown;
10259
10260 default:
10261 goto unknown;
10262 }
10263 }
10264
10265 goto unknown;
10266
10267 default:
10268 goto unknown;
e2e1dd5a 10269 }
4c3bbe0f
MHM
10270
10271 case 12: /* 2 tokens of length 12 */
10272 if (name[0] == 'g' &&
10273 name[1] == 'e' &&
10274 name[2] == 't' &&
10275 name[3] == 'n' &&
10276 name[4] == 'e' &&
10277 name[5] == 't' &&
10278 name[6] == 'b' &&
10279 name[7] == 'y')
10280 {
10281 switch (name[8])
10282 {
10283 case 'a':
10284 if (name[9] == 'd' &&
10285 name[10] == 'd' &&
10286 name[11] == 'r')
10287 { /* getnetbyaddr */
10288 return -KEY_getnetbyaddr;
10289 }
10290
10291 goto unknown;
10292
10293 case 'n':
10294 if (name[9] == 'a' &&
10295 name[10] == 'm' &&
10296 name[11] == 'e')
10297 { /* getnetbyname */
10298 return -KEY_getnetbyname;
10299 }
10300
10301 goto unknown;
10302
10303 default:
10304 goto unknown;
10305 }
e2e1dd5a 10306 }
4c3bbe0f
MHM
10307
10308 goto unknown;
10309
10310 case 13: /* 4 tokens of length 13 */
10311 if (name[0] == 'g' &&
10312 name[1] == 'e' &&
10313 name[2] == 't')
10314 {
10315 switch (name[3])
10316 {
10317 case 'h':
10318 if (name[4] == 'o' &&
10319 name[5] == 's' &&
10320 name[6] == 't' &&
10321 name[7] == 'b' &&
10322 name[8] == 'y')
10323 {
10324 switch (name[9])
10325 {
10326 case 'a':
10327 if (name[10] == 'd' &&
10328 name[11] == 'd' &&
10329 name[12] == 'r')
10330 { /* gethostbyaddr */
10331 return -KEY_gethostbyaddr;
10332 }
10333
10334 goto unknown;
10335
10336 case 'n':
10337 if (name[10] == 'a' &&
10338 name[11] == 'm' &&
10339 name[12] == 'e')
10340 { /* gethostbyname */
10341 return -KEY_gethostbyname;
10342 }
10343
10344 goto unknown;
10345
10346 default:
10347 goto unknown;
10348 }
10349 }
10350
10351 goto unknown;
10352
10353 case 's':
10354 if (name[4] == 'e' &&
10355 name[5] == 'r' &&
10356 name[6] == 'v' &&
10357 name[7] == 'b' &&
10358 name[8] == 'y')
10359 {
10360 switch (name[9])
10361 {
10362 case 'n':
10363 if (name[10] == 'a' &&
10364 name[11] == 'm' &&
10365 name[12] == 'e')
10366 { /* getservbyname */
10367 return -KEY_getservbyname;
10368 }
10369
10370 goto unknown;
10371
10372 case 'p':
10373 if (name[10] == 'o' &&
10374 name[11] == 'r' &&
10375 name[12] == 't')
10376 { /* getservbyport */
10377 return -KEY_getservbyport;
10378 }
10379
10380 goto unknown;
10381
10382 default:
10383 goto unknown;
10384 }
10385 }
10386
10387 goto unknown;
10388
10389 default:
10390 goto unknown;
10391 }
e2e1dd5a 10392 }
4c3bbe0f
MHM
10393
10394 goto unknown;
10395
10396 case 14: /* 1 tokens of length 14 */
10397 if (name[0] == 'g' &&
10398 name[1] == 'e' &&
10399 name[2] == 't' &&
10400 name[3] == 'p' &&
10401 name[4] == 'r' &&
10402 name[5] == 'o' &&
10403 name[6] == 't' &&
10404 name[7] == 'o' &&
10405 name[8] == 'b' &&
10406 name[9] == 'y' &&
10407 name[10] == 'n' &&
10408 name[11] == 'a' &&
10409 name[12] == 'm' &&
10410 name[13] == 'e')
10411 { /* getprotobyname */
10412 return -KEY_getprotobyname;
10413 }
10414
10415 goto unknown;
10416
10417 case 16: /* 1 tokens of length 16 */
10418 if (name[0] == 'g' &&
10419 name[1] == 'e' &&
10420 name[2] == 't' &&
10421 name[3] == 'p' &&
10422 name[4] == 'r' &&
10423 name[5] == 'o' &&
10424 name[6] == 't' &&
10425 name[7] == 'o' &&
10426 name[8] == 'b' &&
10427 name[9] == 'y' &&
10428 name[10] == 'n' &&
10429 name[11] == 'u' &&
10430 name[12] == 'm' &&
10431 name[13] == 'b' &&
10432 name[14] == 'e' &&
10433 name[15] == 'r')
10434 { /* getprotobynumber */
10435 return -KEY_getprotobynumber;
10436 }
10437
10438 goto unknown;
10439
10440 default:
10441 goto unknown;
e2e1dd5a 10442 }
4c3bbe0f
MHM
10443
10444unknown:
e2e1dd5a 10445 return 0;
a687059c
LW
10446}
10447
76e3520e 10448STATIC void
c94115d8 10449S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
a687059c 10450{
97aff369 10451 dVAR;
2f3197b3 10452
d008e5eb 10453 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
d008e5eb
GS
10454 if (ckWARN(WARN_SYNTAX)) {
10455 int level = 1;
26ff0806 10456 const char *w;
d008e5eb
GS
10457 for (w = s+2; *w && level; w++) {
10458 if (*w == '(')
10459 ++level;
10460 else if (*w == ')')
10461 --level;
10462 }
888fea98
NC
10463 while (isSPACE(*w))
10464 ++w;
b1439985
RGS
10465 /* the list of chars below is for end of statements or
10466 * block / parens, boolean operators (&&, ||, //) and branch
10467 * constructs (or, and, if, until, unless, while, err, for).
10468 * Not a very solid hack... */
10469 if (!*w || !strchr(";&/|})]oaiuwef!=", *w))
9014280d 10470 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
65cec589 10471 "%s (...) interpreted as function",name);
d008e5eb 10472 }
2f3197b3 10473 }
3280af22 10474 while (s < PL_bufend && isSPACE(*s))
2f3197b3 10475 s++;
a687059c
LW
10476 if (*s == '(')
10477 s++;
3280af22 10478 while (s < PL_bufend && isSPACE(*s))
a687059c 10479 s++;
7e2040f0 10480 if (isIDFIRST_lazy_if(s,UTF)) {
26ff0806 10481 const char * const w = s++;
7e2040f0 10482 while (isALNUM_lazy_if(s,UTF))
a687059c 10483 s++;
3280af22 10484 while (s < PL_bufend && isSPACE(*s))
a687059c 10485 s++;
e929a76b 10486 if (*s == ',') {
c94115d8 10487 GV* gv;
5458a98a 10488 if (keyword(w, s - w, 0))
e929a76b 10489 return;
c94115d8
NC
10490
10491 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10492 if (gv && GvCVu(gv))
abbb3198 10493 return;
cea2e8a9 10494 Perl_croak(aTHX_ "No comma allowed after %s", what);
463ee0b2
LW
10495 }
10496 }
10497}
10498
423cee85
JH
10499/* Either returns sv, or mortalizes sv and returns a new SV*.
10500 Best used as sv=new_constant(..., sv, ...).
10501 If s, pv are NULL, calls subroutine with one argument,
10502 and type is used with error messages only. */
10503
b3ac6de7 10504STATIC SV *
7fc63493 10505S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
9b0e499b 10506 const char *type)
b3ac6de7 10507{
27da23d5 10508 dVAR; dSP;
890ce7af 10509 HV * const table = GvHV(PL_hintgv); /* ^H */
b3ac6de7 10510 SV *res;
b3ac6de7
IZ
10511 SV **cvp;
10512 SV *cv, *typesv;
89e33a05 10513 const char *why1 = "", *why2 = "", *why3 = "";
4e553d73 10514
f0af216f 10515 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
423cee85
JH
10516 SV *msg;
10517
10edeb5d
JH
10518 why2 = (const char *)
10519 (strEQ(key,"charnames")
10520 ? "(possibly a missing \"use charnames ...\")"
10521 : "");
4e553d73 10522 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
41ab332f
JH
10523 (type ? type: "undef"), why2);
10524
10525 /* This is convoluted and evil ("goto considered harmful")
10526 * but I do not understand the intricacies of all the different
10527 * failure modes of %^H in here. The goal here is to make
10528 * the most probable error message user-friendly. --jhi */
10529
10530 goto msgdone;
10531
423cee85 10532 report:
4e553d73 10533 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
f0af216f 10534 (type ? type: "undef"), why1, why2, why3);
41ab332f 10535 msgdone:
95a20fc0 10536 yyerror(SvPVX_const(msg));
423cee85
JH
10537 SvREFCNT_dec(msg);
10538 return sv;
10539 }
b3ac6de7
IZ
10540 cvp = hv_fetch(table, key, strlen(key), FALSE);
10541 if (!cvp || !SvOK(*cvp)) {
423cee85
JH
10542 why1 = "$^H{";
10543 why2 = key;
f0af216f 10544 why3 = "} is not defined";
423cee85 10545 goto report;
b3ac6de7
IZ
10546 }
10547 sv_2mortal(sv); /* Parent created it permanently */
10548 cv = *cvp;
423cee85
JH
10549 if (!pv && s)
10550 pv = sv_2mortal(newSVpvn(s, len));
10551 if (type && pv)
10552 typesv = sv_2mortal(newSVpv(type, 0));
b3ac6de7 10553 else
423cee85 10554 typesv = &PL_sv_undef;
4e553d73 10555
e788e7d3 10556 PUSHSTACKi(PERLSI_OVERLOAD);
423cee85
JH
10557 ENTER ;
10558 SAVETMPS;
4e553d73 10559
423cee85 10560 PUSHMARK(SP) ;
a5845cb7 10561 EXTEND(sp, 3);
423cee85
JH
10562 if (pv)
10563 PUSHs(pv);
b3ac6de7 10564 PUSHs(sv);
423cee85
JH
10565 if (pv)
10566 PUSHs(typesv);
b3ac6de7 10567 PUTBACK;
423cee85 10568 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
4e553d73 10569
423cee85 10570 SPAGAIN ;
4e553d73 10571
423cee85 10572 /* Check the eval first */
9b0e499b 10573 if (!PL_in_eval && SvTRUE(ERRSV)) {
396482e1 10574 sv_catpvs(ERRSV, "Propagated");
8b6b16e7 10575 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
e1f15930 10576 (void)POPs;
b37c2d43 10577 res = SvREFCNT_inc_simple(sv);
423cee85
JH
10578 }
10579 else {
10580 res = POPs;
b37c2d43 10581 SvREFCNT_inc_simple_void(res);
423cee85 10582 }
4e553d73 10583
423cee85
JH
10584 PUTBACK ;
10585 FREETMPS ;
10586 LEAVE ;
b3ac6de7 10587 POPSTACK;
4e553d73 10588
b3ac6de7 10589 if (!SvOK(res)) {
423cee85
JH
10590 why1 = "Call to &{$^H{";
10591 why2 = key;
f0af216f 10592 why3 = "}} did not return a defined value";
423cee85
JH
10593 sv = res;
10594 goto report;
9b0e499b 10595 }
423cee85 10596
9b0e499b 10597 return res;
b3ac6de7 10598}
4e553d73 10599
d0a148a6
NC
10600/* Returns a NUL terminated string, with the length of the string written to
10601 *slp
10602 */
76e3520e 10603STATIC char *
cea2e8a9 10604S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
463ee0b2 10605{
97aff369 10606 dVAR;
463ee0b2 10607 register char *d = dest;
890ce7af 10608 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
463ee0b2 10609 for (;;) {
8903cb82 10610 if (d >= e)
cea2e8a9 10611 Perl_croak(aTHX_ ident_too_long);
834a4ddd 10612 if (isALNUM(*s)) /* UTF handled below */
463ee0b2 10613 *d++ = *s++;
c35e046a 10614 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
463ee0b2
LW
10615 *d++ = ':';
10616 *d++ = ':';
10617 s++;
10618 }
c35e046a 10619 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
463ee0b2
LW
10620 *d++ = *s++;
10621 *d++ = *s++;
10622 }
fd400ab9 10623 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
a0ed51b3 10624 char *t = s + UTF8SKIP(s);
c35e046a 10625 size_t len;
fd400ab9 10626 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
a0ed51b3 10627 t += UTF8SKIP(t);
c35e046a
AL
10628 len = t - s;
10629 if (d + len > e)
cea2e8a9 10630 Perl_croak(aTHX_ ident_too_long);
c35e046a
AL
10631 Copy(s, d, len, char);
10632 d += len;
a0ed51b3
LW
10633 s = t;
10634 }
463ee0b2
LW
10635 else {
10636 *d = '\0';
10637 *slp = d - dest;
10638 return s;
e929a76b 10639 }
378cc40b
LW
10640 }
10641}
10642
76e3520e 10643STATIC char *
f54cb97a 10644S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
378cc40b 10645{
97aff369 10646 dVAR;
6136c704 10647 char *bracket = NULL;
748a9306 10648 char funny = *s++;
6136c704
AL
10649 register char *d = dest;
10650 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
378cc40b 10651
a0d0e21e 10652 if (isSPACE(*s))
29595ff2 10653 s = PEEKSPACE(s);
de3bb511 10654 if (isDIGIT(*s)) {
8903cb82 10655 while (isDIGIT(*s)) {
10656 if (d >= e)
cea2e8a9 10657 Perl_croak(aTHX_ ident_too_long);
378cc40b 10658 *d++ = *s++;
8903cb82 10659 }
378cc40b
LW
10660 }
10661 else {
463ee0b2 10662 for (;;) {
8903cb82 10663 if (d >= e)
cea2e8a9 10664 Perl_croak(aTHX_ ident_too_long);
834a4ddd 10665 if (isALNUM(*s)) /* UTF handled below */
463ee0b2 10666 *d++ = *s++;
7e2040f0 10667 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
463ee0b2
LW
10668 *d++ = ':';
10669 *d++ = ':';
10670 s++;
10671 }
a0d0e21e 10672 else if (*s == ':' && s[1] == ':') {
463ee0b2
LW
10673 *d++ = *s++;
10674 *d++ = *s++;
10675 }
fd400ab9 10676 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
a0ed51b3 10677 char *t = s + UTF8SKIP(s);
fd400ab9 10678 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
a0ed51b3
LW
10679 t += UTF8SKIP(t);
10680 if (d + (t - s) > e)
cea2e8a9 10681 Perl_croak(aTHX_ ident_too_long);
a0ed51b3
LW
10682 Copy(s, d, t - s, char);
10683 d += t - s;
10684 s = t;
10685 }
463ee0b2
LW
10686 else
10687 break;
10688 }
378cc40b
LW
10689 }
10690 *d = '\0';
10691 d = dest;
79072805 10692 if (*d) {
3280af22
NIS
10693 if (PL_lex_state != LEX_NORMAL)
10694 PL_lex_state = LEX_INTERPENDMAYBE;
79072805 10695 return s;
378cc40b 10696 }
748a9306 10697 if (*s == '$' && s[1] &&
3792a11b 10698 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
5cd24f17 10699 {
4810e5ec 10700 return s;
5cd24f17 10701 }
79072805
LW
10702 if (*s == '{') {
10703 bracket = s;
10704 s++;
10705 }
10706 else if (ck_uni)
10707 check_uni();
93a17b20 10708 if (s < send)
79072805
LW
10709 *d = *s++;
10710 d[1] = '\0';
2b92dfce 10711 if (*d == '^' && *s && isCONTROLVAR(*s)) {
bbce6d69 10712 *d = toCTRL(*s);
10713 s++;
de3bb511 10714 }
79072805 10715 if (bracket) {
748a9306 10716 if (isSPACE(s[-1])) {
fa83b5b6 10717 while (s < send) {
f54cb97a 10718 const char ch = *s++;
bf4acbe4 10719 if (!SPACE_OR_TAB(ch)) {
fa83b5b6 10720 *d = ch;
10721 break;
10722 }
10723 }
748a9306 10724 }
7e2040f0 10725 if (isIDFIRST_lazy_if(d,UTF)) {
79072805 10726 d++;
a0ed51b3 10727 if (UTF) {
6136c704
AL
10728 char *end = s;
10729 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10730 end += UTF8SKIP(end);
10731 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10732 end += UTF8SKIP(end);
a0ed51b3 10733 }
6136c704
AL
10734 Copy(s, d, end - s, char);
10735 d += end - s;
10736 s = end;
a0ed51b3
LW
10737 }
10738 else {
2b92dfce 10739 while ((isALNUM(*s) || *s == ':') && d < e)
a0ed51b3 10740 *d++ = *s++;
2b92dfce 10741 if (d >= e)
cea2e8a9 10742 Perl_croak(aTHX_ ident_too_long);
a0ed51b3 10743 }
79072805 10744 *d = '\0';
c35e046a
AL
10745 while (s < send && SPACE_OR_TAB(*s))
10746 s++;
ff68c719 10747 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
5458a98a 10748 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
10edeb5d
JH
10749 const char * const brack =
10750 (const char *)
10751 ((*s == '[') ? "[...]" : "{...}");
9014280d 10752 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
599cee73 10753 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
748a9306
LW
10754 funny, dest, brack, funny, dest, brack);
10755 }
79072805 10756 bracket++;
a0be28da 10757 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
79072805
LW
10758 return s;
10759 }
4e553d73
NIS
10760 }
10761 /* Handle extended ${^Foo} variables
2b92dfce
GS
10762 * 1999-02-27 mjd-perl-patch@plover.com */
10763 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10764 && isALNUM(*s))
10765 {
10766 d++;
10767 while (isALNUM(*s) && d < e) {
10768 *d++ = *s++;
10769 }
10770 if (d >= e)
cea2e8a9 10771 Perl_croak(aTHX_ ident_too_long);
2b92dfce 10772 *d = '\0';
79072805
LW
10773 }
10774 if (*s == '}') {
10775 s++;
7df0d042 10776 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
3280af22 10777 PL_lex_state = LEX_INTERPEND;
7df0d042
AE
10778 PL_expect = XREF;
10779 }
d008e5eb 10780 if (PL_lex_state == LEX_NORMAL) {
d008e5eb 10781 if (ckWARN(WARN_AMBIGUOUS) &&
780a5241
NC
10782 (keyword(dest, d - dest, 0)
10783 || get_cvn_flags(dest, d - dest, 0)))
d008e5eb 10784 {
c35e046a
AL
10785 if (funny == '#')
10786 funny = '@';
9014280d 10787 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
d008e5eb
GS
10788 "Ambiguous use of %c{%s} resolved to %c%s",
10789 funny, dest, funny, dest);
10790 }
10791 }
79072805
LW
10792 }
10793 else {
10794 s = bracket; /* let the parser handle it */
93a17b20 10795 *dest = '\0';
79072805
LW
10796 }
10797 }
3280af22
NIS
10798 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10799 PL_lex_state = LEX_INTERPEND;
378cc40b
LW
10800 return s;
10801}
10802
cea2e8a9 10803void
2b36a5a0 10804Perl_pmflag(pTHX_ U32* pmfl, int ch)
a0d0e21e 10805{
96a5add6 10806 PERL_UNUSED_CONTEXT;
cde0cee5
YO
10807 if (ch<256) {
10808 char c = (char)ch;
10809 switch (c) {
10810 CASE_STD_PMMOD_FLAGS_PARSE_SET(pmfl);
a20207d7
YO
10811 case GLOBAL_PAT_MOD: *pmfl |= PMf_GLOBAL; break;
10812 case CONTINUE_PAT_MOD: *pmfl |= PMf_CONTINUE; break;
10813 case ONCE_PAT_MOD: *pmfl |= PMf_KEEP; break;
10814 case KEEPCOPY_PAT_MOD: *pmfl |= PMf_KEEPCOPY; break;
cde0cee5
YO
10815 }
10816 }
a0d0e21e 10817}
378cc40b 10818
76e3520e 10819STATIC char *
cea2e8a9 10820S_scan_pat(pTHX_ char *start, I32 type)
378cc40b 10821{
97aff369 10822 dVAR;
79072805 10823 PMOP *pm;
5db06880 10824 char *s = scan_str(start,!!PL_madskills,FALSE);
10edeb5d 10825 const char * const valid_flags =
a20207d7 10826 (const char *)((type == OP_QR) ? QR_PAT_MODS : M_PAT_MODS);
5db06880
NC
10827#ifdef PERL_MAD
10828 char *modstart;
10829#endif
10830
378cc40b 10831
25c09cbf 10832 if (!s) {
6136c704 10833 const char * const delimiter = skipspace(start);
10edeb5d
JH
10834 Perl_croak(aTHX_
10835 (const char *)
10836 (*delimiter == '?'
10837 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10838 : "Search pattern not terminated" ));
25c09cbf 10839 }
bbce6d69 10840
8782bef2 10841 pm = (PMOP*)newPMOP(type, 0);
3280af22 10842 if (PL_multi_open == '?')
79072805 10843 pm->op_pmflags |= PMf_ONCE;
5db06880
NC
10844#ifdef PERL_MAD
10845 modstart = s;
10846#endif
6136c704
AL
10847 while (*s && strchr(valid_flags, *s))
10848 pmflag(&pm->op_pmflags,*s++);
5db06880
NC
10849#ifdef PERL_MAD
10850 if (PL_madskills && modstart != s) {
10851 SV* tmptoken = newSVpvn(modstart, s - modstart);
10852 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10853 }
10854#endif
4ac733c9 10855 /* issue a warning if /c is specified,but /g is not */
041457d9
DM
10856 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10857 && ckWARN(WARN_REGEXP))
4ac733c9 10858 {
a20207d7
YO
10859 Perl_warner(aTHX_ packWARN(WARN_REGEXP),
10860 "Use of /c modifier is meaningless without /g" );
4ac733c9
MJD
10861 }
10862
3280af22 10863 PL_lex_op = (OP*)pm;
79072805 10864 yylval.ival = OP_MATCH;
378cc40b
LW
10865 return s;
10866}
10867
76e3520e 10868STATIC char *
cea2e8a9 10869S_scan_subst(pTHX_ char *start)
79072805 10870{
27da23d5 10871 dVAR;
a0d0e21e 10872 register char *s;
79072805 10873 register PMOP *pm;
4fdae800 10874 I32 first_start;
79072805 10875 I32 es = 0;
5db06880
NC
10876#ifdef PERL_MAD
10877 char *modstart;
10878#endif
79072805 10879
79072805
LW
10880 yylval.ival = OP_NULL;
10881
5db06880 10882 s = scan_str(start,!!PL_madskills,FALSE);
79072805 10883
37fd879b 10884 if (!s)
cea2e8a9 10885 Perl_croak(aTHX_ "Substitution pattern not terminated");
79072805 10886
3280af22 10887 if (s[-1] == PL_multi_open)
79072805 10888 s--;
5db06880
NC
10889#ifdef PERL_MAD
10890 if (PL_madskills) {
cd81e915
NC
10891 CURMAD('q', PL_thisopen);
10892 CURMAD('_', PL_thiswhite);
10893 CURMAD('E', PL_thisstuff);
10894 CURMAD('Q', PL_thisclose);
10895 PL_realtokenstart = s - SvPVX(PL_linestr);
5db06880
NC
10896 }
10897#endif
79072805 10898
3280af22 10899 first_start = PL_multi_start;
5db06880 10900 s = scan_str(s,!!PL_madskills,FALSE);
79072805 10901 if (!s) {
37fd879b 10902 if (PL_lex_stuff) {
3280af22 10903 SvREFCNT_dec(PL_lex_stuff);
a0714e2c 10904 PL_lex_stuff = NULL;
37fd879b 10905 }
cea2e8a9 10906 Perl_croak(aTHX_ "Substitution replacement not terminated");
a687059c 10907 }
3280af22 10908 PL_multi_start = first_start; /* so whole substitution is taken together */
2f3197b3 10909
79072805 10910 pm = (PMOP*)newPMOP(OP_SUBST, 0);
5db06880
NC
10911
10912#ifdef PERL_MAD
10913 if (PL_madskills) {
cd81e915
NC
10914 CURMAD('z', PL_thisopen);
10915 CURMAD('R', PL_thisstuff);
10916 CURMAD('Z', PL_thisclose);
5db06880
NC
10917 }
10918 modstart = s;
10919#endif
10920
48c036b1 10921 while (*s) {
a20207d7 10922 if (*s == EXEC_PAT_MOD) {
a687059c 10923 s++;
2f3197b3 10924 es++;
a687059c 10925 }
a20207d7 10926 else if (strchr(S_PAT_MODS, *s))
a0d0e21e 10927 pmflag(&pm->op_pmflags,*s++);
48c036b1
GS
10928 else
10929 break;
378cc40b 10930 }
79072805 10931
5db06880
NC
10932#ifdef PERL_MAD
10933 if (PL_madskills) {
10934 if (modstart != s)
10935 curmad('m', newSVpvn(modstart, s - modstart));
cd81e915
NC
10936 append_madprops(PL_thismad, (OP*)pm, 0);
10937 PL_thismad = 0;
5db06880
NC
10938 }
10939#endif
0bd48802
AL
10940 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10941 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
4ac733c9
MJD
10942 }
10943
79072805 10944 if (es) {
6136c704
AL
10945 SV * const repl = newSVpvs("");
10946
0244c3a4
GS
10947 PL_sublex_info.super_bufptr = s;
10948 PL_sublex_info.super_bufend = PL_bufend;
10949 PL_multi_end = 0;
79072805 10950 pm->op_pmflags |= PMf_EVAL;
463ee0b2 10951 while (es-- > 0)
10edeb5d 10952 sv_catpv(repl, (const char *)(es ? "eval " : "do "));
6f43d98f 10953 sv_catpvs(repl, "{");
3280af22 10954 sv_catsv(repl, PL_lex_repl);
9badc361
RGS
10955 if (strchr(SvPVX(PL_lex_repl), '#'))
10956 sv_catpvs(repl, "\n");
10957 sv_catpvs(repl, "}");
25da4f38 10958 SvEVALED_on(repl);
3280af22
NIS
10959 SvREFCNT_dec(PL_lex_repl);
10960 PL_lex_repl = repl;
378cc40b 10961 }
79072805 10962
3280af22 10963 PL_lex_op = (OP*)pm;
79072805 10964 yylval.ival = OP_SUBST;
378cc40b
LW
10965 return s;
10966}
10967
76e3520e 10968STATIC char *
cea2e8a9 10969S_scan_trans(pTHX_ char *start)
378cc40b 10970{
97aff369 10971 dVAR;
a0d0e21e 10972 register char* s;
11343788 10973 OP *o;
79072805
LW
10974 short *tbl;
10975 I32 squash;
a0ed51b3 10976 I32 del;
79072805 10977 I32 complement;
5db06880
NC
10978#ifdef PERL_MAD
10979 char *modstart;
10980#endif
79072805
LW
10981
10982 yylval.ival = OP_NULL;
10983
5db06880 10984 s = scan_str(start,!!PL_madskills,FALSE);
37fd879b 10985 if (!s)
cea2e8a9 10986 Perl_croak(aTHX_ "Transliteration pattern not terminated");
5db06880 10987
3280af22 10988 if (s[-1] == PL_multi_open)
2f3197b3 10989 s--;
5db06880
NC
10990#ifdef PERL_MAD
10991 if (PL_madskills) {
cd81e915
NC
10992 CURMAD('q', PL_thisopen);
10993 CURMAD('_', PL_thiswhite);
10994 CURMAD('E', PL_thisstuff);
10995 CURMAD('Q', PL_thisclose);
10996 PL_realtokenstart = s - SvPVX(PL_linestr);
5db06880
NC
10997 }
10998#endif
2f3197b3 10999
5db06880 11000 s = scan_str(s,!!PL_madskills,FALSE);
79072805 11001 if (!s) {
37fd879b 11002 if (PL_lex_stuff) {
3280af22 11003 SvREFCNT_dec(PL_lex_stuff);
a0714e2c 11004 PL_lex_stuff = NULL;
37fd879b 11005 }
cea2e8a9 11006 Perl_croak(aTHX_ "Transliteration replacement not terminated");
a687059c 11007 }
5db06880 11008 if (PL_madskills) {
cd81e915
NC
11009 CURMAD('z', PL_thisopen);
11010 CURMAD('R', PL_thisstuff);
11011 CURMAD('Z', PL_thisclose);
5db06880 11012 }
79072805 11013
a0ed51b3 11014 complement = del = squash = 0;
5db06880
NC
11015#ifdef PERL_MAD
11016 modstart = s;
11017#endif
7a1e2023
NC
11018 while (1) {
11019 switch (*s) {
11020 case 'c':
79072805 11021 complement = OPpTRANS_COMPLEMENT;
7a1e2023
NC
11022 break;
11023 case 'd':
a0ed51b3 11024 del = OPpTRANS_DELETE;
7a1e2023
NC
11025 break;
11026 case 's':
79072805 11027 squash = OPpTRANS_SQUASH;
7a1e2023
NC
11028 break;
11029 default:
11030 goto no_more;
11031 }
395c3793
LW
11032 s++;
11033 }
7a1e2023 11034 no_more:
8973db79 11035
aa1f7c5b 11036 tbl = (short *)PerlMemShared_calloc(complement&&!del?258:256, sizeof(short));
8973db79 11037 o = newPVOP(OP_TRANS, 0, (char*)tbl);
59f00321
RGS
11038 o->op_private &= ~OPpTRANS_ALL;
11039 o->op_private |= del|squash|complement|
7948272d
NIS
11040 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
11041 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
79072805 11042
3280af22 11043 PL_lex_op = o;
79072805 11044 yylval.ival = OP_TRANS;
5db06880
NC
11045
11046#ifdef PERL_MAD
11047 if (PL_madskills) {
11048 if (modstart != s)
11049 curmad('m', newSVpvn(modstart, s - modstart));
cd81e915
NC
11050 append_madprops(PL_thismad, o, 0);
11051 PL_thismad = 0;
5db06880
NC
11052 }
11053#endif
11054
79072805
LW
11055 return s;
11056}
11057
76e3520e 11058STATIC char *
cea2e8a9 11059S_scan_heredoc(pTHX_ register char *s)
79072805 11060{
97aff369 11061 dVAR;
79072805
LW
11062 SV *herewas;
11063 I32 op_type = OP_SCALAR;
11064 I32 len;
11065 SV *tmpstr;
11066 char term;
73d840c0 11067 const char *found_newline;
79072805 11068 register char *d;
fc36a67e 11069 register char *e;
4633a7c4 11070 char *peek;
f54cb97a 11071 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
5db06880
NC
11072#ifdef PERL_MAD
11073 I32 stuffstart = s - SvPVX(PL_linestr);
11074 char *tstart;
11075
cd81e915 11076 PL_realtokenstart = -1;
5db06880 11077#endif
79072805
LW
11078
11079 s += 2;
3280af22
NIS
11080 d = PL_tokenbuf;
11081 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
fd2d0953 11082 if (!outer)
79072805 11083 *d++ = '\n';
c35e046a
AL
11084 peek = s;
11085 while (SPACE_OR_TAB(*peek))
11086 peek++;
3792a11b 11087 if (*peek == '`' || *peek == '\'' || *peek =='"') {
4633a7c4 11088 s = peek;
79072805 11089 term = *s++;
3280af22 11090 s = delimcpy(d, e, s, PL_bufend, term, &len);
fc36a67e 11091 d += len;
3280af22 11092 if (s < PL_bufend)
79072805 11093 s++;
79072805
LW
11094 }
11095 else {
11096 if (*s == '\\')
11097 s++, term = '\'';
11098 else
11099 term = '"';
7e2040f0 11100 if (!isALNUM_lazy_if(s,UTF))
12bcd1a6 11101 deprecate_old("bare << to mean <<\"\"");
7e2040f0 11102 for (; isALNUM_lazy_if(s,UTF); s++) {
fc36a67e 11103 if (d < e)
11104 *d++ = *s;
11105 }
11106 }
3280af22 11107 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
cea2e8a9 11108 Perl_croak(aTHX_ "Delimiter for here document is too long");
79072805
LW
11109 *d++ = '\n';
11110 *d = '\0';
3280af22 11111 len = d - PL_tokenbuf;
5db06880
NC
11112
11113#ifdef PERL_MAD
11114 if (PL_madskills) {
11115 tstart = PL_tokenbuf + !outer;
cd81e915 11116 PL_thisclose = newSVpvn(tstart, len - !outer);
5db06880 11117 tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915 11118 PL_thisopen = newSVpvn(tstart, s - tstart);
5db06880
NC
11119 stuffstart = s - SvPVX(PL_linestr);
11120 }
11121#endif
6a27c188 11122#ifndef PERL_STRICT_CR
f63a84b2
LW
11123 d = strchr(s, '\r');
11124 if (d) {
b464bac0 11125 char * const olds = s;
f63a84b2 11126 s = d;
3280af22 11127 while (s < PL_bufend) {
f63a84b2
LW
11128 if (*s == '\r') {
11129 *d++ = '\n';
11130 if (*++s == '\n')
11131 s++;
11132 }
11133 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
11134 *d++ = *s++;
11135 s++;
11136 }
11137 else
11138 *d++ = *s++;
11139 }
11140 *d = '\0';
3280af22 11141 PL_bufend = d;
95a20fc0 11142 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
f63a84b2
LW
11143 s = olds;
11144 }
11145#endif
5db06880
NC
11146#ifdef PERL_MAD
11147 found_newline = 0;
11148#endif
10edeb5d 11149 if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
73d840c0
AL
11150 herewas = newSVpvn(s,PL_bufend-s);
11151 }
11152 else {
5db06880
NC
11153#ifdef PERL_MAD
11154 herewas = newSVpvn(s-1,found_newline-s+1);
11155#else
73d840c0
AL
11156 s--;
11157 herewas = newSVpvn(s,found_newline-s);
5db06880 11158#endif
73d840c0 11159 }
5db06880
NC
11160#ifdef PERL_MAD
11161 if (PL_madskills) {
11162 tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915
NC
11163 if (PL_thisstuff)
11164 sv_catpvn(PL_thisstuff, tstart, s - tstart);
5db06880 11165 else
cd81e915 11166 PL_thisstuff = newSVpvn(tstart, s - tstart);
5db06880
NC
11167 }
11168#endif
79072805 11169 s += SvCUR(herewas);
748a9306 11170
5db06880
NC
11171#ifdef PERL_MAD
11172 stuffstart = s - SvPVX(PL_linestr);
11173
11174 if (found_newline)
11175 s--;
11176#endif
11177
7d0a29fe
NC
11178 tmpstr = newSV_type(SVt_PVIV);
11179 SvGROW(tmpstr, 80);
748a9306 11180 if (term == '\'') {
79072805 11181 op_type = OP_CONST;
45977657 11182 SvIV_set(tmpstr, -1);
748a9306
LW
11183 }
11184 else if (term == '`') {
79072805 11185 op_type = OP_BACKTICK;
45977657 11186 SvIV_set(tmpstr, '\\');
748a9306 11187 }
79072805
LW
11188
11189 CLINE;
57843af0 11190 PL_multi_start = CopLINE(PL_curcop);
3280af22
NIS
11191 PL_multi_open = PL_multi_close = '<';
11192 term = *PL_tokenbuf;
0244c3a4 11193 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
6136c704
AL
11194 char * const bufptr = PL_sublex_info.super_bufptr;
11195 char * const bufend = PL_sublex_info.super_bufend;
b464bac0 11196 char * const olds = s - SvCUR(herewas);
0244c3a4
GS
11197 s = strchr(bufptr, '\n');
11198 if (!s)
11199 s = bufend;
11200 d = s;
11201 while (s < bufend &&
11202 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11203 if (*s++ == '\n')
57843af0 11204 CopLINE_inc(PL_curcop);
0244c3a4
GS
11205 }
11206 if (s >= bufend) {
eb160463 11207 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
0244c3a4
GS
11208 missingterm(PL_tokenbuf);
11209 }
11210 sv_setpvn(herewas,bufptr,d-bufptr+1);
11211 sv_setpvn(tmpstr,d+1,s-d);
11212 s += len - 1;
11213 sv_catpvn(herewas,s,bufend-s);
95a20fc0 11214 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
0244c3a4
GS
11215
11216 s = olds;
11217 goto retval;
11218 }
11219 else if (!outer) {
79072805 11220 d = s;
3280af22
NIS
11221 while (s < PL_bufend &&
11222 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
79072805 11223 if (*s++ == '\n')
57843af0 11224 CopLINE_inc(PL_curcop);
79072805 11225 }
3280af22 11226 if (s >= PL_bufend) {
eb160463 11227 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
3280af22 11228 missingterm(PL_tokenbuf);
79072805
LW
11229 }
11230 sv_setpvn(tmpstr,d+1,s-d);
5db06880
NC
11231#ifdef PERL_MAD
11232 if (PL_madskills) {
cd81e915
NC
11233 if (PL_thisstuff)
11234 sv_catpvn(PL_thisstuff, d + 1, s - d);
5db06880 11235 else
cd81e915 11236 PL_thisstuff = newSVpvn(d + 1, s - d);
5db06880
NC
11237 stuffstart = s - SvPVX(PL_linestr);
11238 }
11239#endif
79072805 11240 s += len - 1;
57843af0 11241 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
49d8d3a1 11242
3280af22
NIS
11243 sv_catpvn(herewas,s,PL_bufend-s);
11244 sv_setsv(PL_linestr,herewas);
11245 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11246 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 11247 PL_last_lop = PL_last_uni = NULL;
79072805
LW
11248 }
11249 else
11250 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
3280af22 11251 while (s >= PL_bufend) { /* multiple line string? */
5db06880
NC
11252#ifdef PERL_MAD
11253 if (PL_madskills) {
11254 tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915
NC
11255 if (PL_thisstuff)
11256 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
5db06880 11257 else
cd81e915 11258 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
5db06880
NC
11259 }
11260#endif
fd2d0953 11261 if (!outer ||
3280af22 11262 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
eb160463 11263 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
3280af22 11264 missingterm(PL_tokenbuf);
79072805 11265 }
5db06880
NC
11266#ifdef PERL_MAD
11267 stuffstart = s - SvPVX(PL_linestr);
11268#endif
57843af0 11269 CopLINE_inc(PL_curcop);
3280af22 11270 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 11271 PL_last_lop = PL_last_uni = NULL;
6a27c188 11272#ifndef PERL_STRICT_CR
3280af22 11273 if (PL_bufend - PL_linestart >= 2) {
a1529941
NIS
11274 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11275 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
c6f14548 11276 {
3280af22
NIS
11277 PL_bufend[-2] = '\n';
11278 PL_bufend--;
95a20fc0 11279 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
f63a84b2 11280 }
3280af22
NIS
11281 else if (PL_bufend[-1] == '\r')
11282 PL_bufend[-1] = '\n';
f63a84b2 11283 }
3280af22
NIS
11284 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11285 PL_bufend[-1] = '\n';
f63a84b2 11286#endif
80a702cd 11287 if (PERLDB_LINE && PL_curstash != PL_debstash)
5fa550fb 11288 update_debugger_info(PL_linestr, NULL, 0);
3280af22 11289 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
95a20fc0 11290 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
1de9afcd 11291 *(SvPVX(PL_linestr) + off ) = ' ';
3280af22
NIS
11292 sv_catsv(PL_linestr,herewas);
11293 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1de9afcd 11294 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
79072805
LW
11295 }
11296 else {
3280af22
NIS
11297 s = PL_bufend;
11298 sv_catsv(tmpstr,PL_linestr);
395c3793
LW
11299 }
11300 }
79072805 11301 s++;
0244c3a4 11302retval:
57843af0 11303 PL_multi_end = CopLINE(PL_curcop);
79072805 11304 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
1da4ca5f 11305 SvPV_shrink_to_cur(tmpstr);
79072805 11306 }
8990e307 11307 SvREFCNT_dec(herewas);
2f31ce75 11308 if (!IN_BYTES) {
95a20fc0 11309 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
2f31ce75
JH
11310 SvUTF8_on(tmpstr);
11311 else if (PL_encoding)
11312 sv_recode_to_utf8(tmpstr, PL_encoding);
11313 }
3280af22 11314 PL_lex_stuff = tmpstr;
79072805
LW
11315 yylval.ival = op_type;
11316 return s;
11317}
11318
02aa26ce
NT
11319/* scan_inputsymbol
11320 takes: current position in input buffer
11321 returns: new position in input buffer
11322 side-effects: yylval and lex_op are set.
11323
11324 This code handles:
11325
11326 <> read from ARGV
11327 <FH> read from filehandle
11328 <pkg::FH> read from package qualified filehandle
11329 <pkg'FH> read from package qualified filehandle
11330 <$fh> read from filehandle in $fh
11331 <*.h> filename glob
11332
11333*/
11334
76e3520e 11335STATIC char *
cea2e8a9 11336S_scan_inputsymbol(pTHX_ char *start)
79072805 11337{
97aff369 11338 dVAR;
02aa26ce 11339 register char *s = start; /* current position in buffer */
1b420867 11340 char *end;
79072805
LW
11341 I32 len;
11342
6136c704
AL
11343 char *d = PL_tokenbuf; /* start of temp holding space */
11344 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11345
1b420867
GS
11346 end = strchr(s, '\n');
11347 if (!end)
11348 end = PL_bufend;
11349 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
02aa26ce
NT
11350
11351 /* die if we didn't have space for the contents of the <>,
1b420867 11352 or if it didn't end, or if we see a newline
02aa26ce
NT
11353 */
11354
bb7a0f54 11355 if (len >= (I32)sizeof PL_tokenbuf)
cea2e8a9 11356 Perl_croak(aTHX_ "Excessively long <> operator");
1b420867 11357 if (s >= end)
cea2e8a9 11358 Perl_croak(aTHX_ "Unterminated <> operator");
02aa26ce 11359
fc36a67e 11360 s++;
02aa26ce
NT
11361
11362 /* check for <$fh>
11363 Remember, only scalar variables are interpreted as filehandles by
11364 this code. Anything more complex (e.g., <$fh{$num}>) will be
11365 treated as a glob() call.
11366 This code makes use of the fact that except for the $ at the front,
11367 a scalar variable and a filehandle look the same.
11368 */
4633a7c4 11369 if (*d == '$' && d[1]) d++;
02aa26ce
NT
11370
11371 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
7e2040f0 11372 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
79072805 11373 d++;
02aa26ce
NT
11374
11375 /* If we've tried to read what we allow filehandles to look like, and
11376 there's still text left, then it must be a glob() and not a getline.
11377 Use scan_str to pull out the stuff between the <> and treat it
11378 as nothing more than a string.
11379 */
11380
3280af22 11381 if (d - PL_tokenbuf != len) {
79072805
LW
11382 yylval.ival = OP_GLOB;
11383 set_csh();
5db06880 11384 s = scan_str(start,!!PL_madskills,FALSE);
79072805 11385 if (!s)
cea2e8a9 11386 Perl_croak(aTHX_ "Glob not terminated");
79072805
LW
11387 return s;
11388 }
395c3793 11389 else {
9b3023bc 11390 bool readline_overriden = FALSE;
6136c704 11391 GV *gv_readline;
9b3023bc 11392 GV **gvp;
02aa26ce 11393 /* we're in a filehandle read situation */
3280af22 11394 d = PL_tokenbuf;
02aa26ce
NT
11395
11396 /* turn <> into <ARGV> */
79072805 11397 if (!len)
689badd5 11398 Copy("ARGV",d,5,char);
02aa26ce 11399
9b3023bc 11400 /* Check whether readline() is overriden */
fafc274c 11401 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
6136c704 11402 if ((gv_readline
ba979b31 11403 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
9b3023bc 11404 ||
017a3ce5 11405 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
9e0d86f8 11406 && (gv_readline = *gvp) && isGV_with_GP(gv_readline)
ba979b31 11407 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
9b3023bc
RGS
11408 readline_overriden = TRUE;
11409
02aa26ce
NT
11410 /* if <$fh>, create the ops to turn the variable into a
11411 filehandle
11412 */
79072805 11413 if (*d == '$') {
02aa26ce
NT
11414 /* try to find it in the pad for this block, otherwise find
11415 add symbol table ops
11416 */
bbd11bfc
AL
11417 const PADOFFSET tmp = pad_findmy(d);
11418 if (tmp != NOT_IN_PAD) {
00b1698f 11419 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6136c704
AL
11420 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11421 HEK * const stashname = HvNAME_HEK(stash);
11422 SV * const sym = sv_2mortal(newSVhek(stashname));
396482e1 11423 sv_catpvs(sym, "::");
f558d5af
JH
11424 sv_catpv(sym, d+1);
11425 d = SvPVX(sym);
11426 goto intro_sym;
11427 }
11428 else {
6136c704 11429 OP * const o = newOP(OP_PADSV, 0);
f558d5af 11430 o->op_targ = tmp;
9b3023bc
RGS
11431 PL_lex_op = readline_overriden
11432 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11433 append_elem(OP_LIST, o,
11434 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11435 : (OP*)newUNOP(OP_READLINE, 0, o);
f558d5af 11436 }
a0d0e21e
LW
11437 }
11438 else {
f558d5af
JH
11439 GV *gv;
11440 ++d;
11441intro_sym:
11442 gv = gv_fetchpv(d,
11443 (PL_in_eval
11444 ? (GV_ADDMULTI | GV_ADDINEVAL)
bea70d1e 11445 : GV_ADDMULTI),
f558d5af 11446 SVt_PV);
9b3023bc
RGS
11447 PL_lex_op = readline_overriden
11448 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11449 append_elem(OP_LIST,
11450 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11451 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11452 : (OP*)newUNOP(OP_READLINE, 0,
11453 newUNOP(OP_RV2SV, 0,
11454 newGVOP(OP_GV, 0, gv)));
a0d0e21e 11455 }
7c6fadd6
RGS
11456 if (!readline_overriden)
11457 PL_lex_op->op_flags |= OPf_SPECIAL;
f5284f61 11458 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
79072805
LW
11459 yylval.ival = OP_NULL;
11460 }
02aa26ce
NT
11461
11462 /* If it's none of the above, it must be a literal filehandle
11463 (<Foo::BAR> or <FOO>) so build a simple readline OP */
79072805 11464 else {
6136c704 11465 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
9b3023bc
RGS
11466 PL_lex_op = readline_overriden
11467 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11468 append_elem(OP_LIST,
11469 newGVOP(OP_GV, 0, gv),
11470 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11471 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
79072805
LW
11472 yylval.ival = OP_NULL;
11473 }
11474 }
02aa26ce 11475
79072805
LW
11476 return s;
11477}
11478
02aa26ce
NT
11479
11480/* scan_str
11481 takes: start position in buffer
09bef843
SB
11482 keep_quoted preserve \ on the embedded delimiter(s)
11483 keep_delims preserve the delimiters around the string
02aa26ce
NT
11484 returns: position to continue reading from buffer
11485 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11486 updates the read buffer.
11487
11488 This subroutine pulls a string out of the input. It is called for:
11489 q single quotes q(literal text)
11490 ' single quotes 'literal text'
11491 qq double quotes qq(interpolate $here please)
11492 " double quotes "interpolate $here please"
11493 qx backticks qx(/bin/ls -l)
11494 ` backticks `/bin/ls -l`
11495 qw quote words @EXPORT_OK = qw( func() $spam )
11496 m// regexp match m/this/
11497 s/// regexp substitute s/this/that/
11498 tr/// string transliterate tr/this/that/
11499 y/// string transliterate y/this/that/
11500 ($*@) sub prototypes sub foo ($)
09bef843 11501 (stuff) sub attr parameters sub foo : attr(stuff)
02aa26ce
NT
11502 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11503
11504 In most of these cases (all but <>, patterns and transliterate)
11505 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11506 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11507 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11508 calls scan_str().
4e553d73 11509
02aa26ce
NT
11510 It skips whitespace before the string starts, and treats the first
11511 character as the delimiter. If the delimiter is one of ([{< then
11512 the corresponding "close" character )]}> is used as the closing
11513 delimiter. It allows quoting of delimiters, and if the string has
11514 balanced delimiters ([{<>}]) it allows nesting.
11515
37fd879b
HS
11516 On success, the SV with the resulting string is put into lex_stuff or,
11517 if that is already non-NULL, into lex_repl. The second case occurs only
11518 when parsing the RHS of the special constructs s/// and tr/// (y///).
11519 For convenience, the terminating delimiter character is stuffed into
11520 SvIVX of the SV.
02aa26ce
NT
11521*/
11522
76e3520e 11523STATIC char *
09bef843 11524S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
79072805 11525{
97aff369 11526 dVAR;
02aa26ce 11527 SV *sv; /* scalar value: string */
d3fcec1f 11528 const char *tmps; /* temp string, used for delimiter matching */
02aa26ce
NT
11529 register char *s = start; /* current position in the buffer */
11530 register char term; /* terminating character */
11531 register char *to; /* current position in the sv's data */
11532 I32 brackets = 1; /* bracket nesting level */
89491803 11533 bool has_utf8 = FALSE; /* is there any utf8 content? */
220e2d4e 11534 I32 termcode; /* terminating char. code */
89ebb4a3 11535 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
220e2d4e 11536 STRLEN termlen; /* length of terminating string */
0331ef07 11537 int last_off = 0; /* last position for nesting bracket */
5db06880
NC
11538#ifdef PERL_MAD
11539 int stuffstart;
11540 char *tstart;
11541#endif
02aa26ce
NT
11542
11543 /* skip space before the delimiter */
29595ff2
NC
11544 if (isSPACE(*s)) {
11545 s = PEEKSPACE(s);
11546 }
02aa26ce 11547
5db06880 11548#ifdef PERL_MAD
cd81e915
NC
11549 if (PL_realtokenstart >= 0) {
11550 stuffstart = PL_realtokenstart;
11551 PL_realtokenstart = -1;
5db06880
NC
11552 }
11553 else
11554 stuffstart = start - SvPVX(PL_linestr);
11555#endif
02aa26ce 11556 /* mark where we are, in case we need to report errors */
79072805 11557 CLINE;
02aa26ce
NT
11558
11559 /* after skipping whitespace, the next character is the terminator */
a0d0e21e 11560 term = *s;
220e2d4e
IH
11561 if (!UTF) {
11562 termcode = termstr[0] = term;
11563 termlen = 1;
11564 }
11565 else {
f3b9ce0f 11566 termcode = utf8_to_uvchr((U8*)s, &termlen);
220e2d4e
IH
11567 Copy(s, termstr, termlen, U8);
11568 if (!UTF8_IS_INVARIANT(term))
11569 has_utf8 = TRUE;
11570 }
b1c7b182 11571
02aa26ce 11572 /* mark where we are */
57843af0 11573 PL_multi_start = CopLINE(PL_curcop);
3280af22 11574 PL_multi_open = term;
02aa26ce
NT
11575
11576 /* find corresponding closing delimiter */
93a17b20 11577 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
220e2d4e
IH
11578 termcode = termstr[0] = term = tmps[5];
11579
3280af22 11580 PL_multi_close = term;
79072805 11581
561b68a9
SH
11582 /* create a new SV to hold the contents. 79 is the SV's initial length.
11583 What a random number. */
7d0a29fe
NC
11584 sv = newSV_type(SVt_PVIV);
11585 SvGROW(sv, 80);
45977657 11586 SvIV_set(sv, termcode);
a0d0e21e 11587 (void)SvPOK_only(sv); /* validate pointer */
02aa26ce
NT
11588
11589 /* move past delimiter and try to read a complete string */
09bef843 11590 if (keep_delims)
220e2d4e
IH
11591 sv_catpvn(sv, s, termlen);
11592 s += termlen;
5db06880
NC
11593#ifdef PERL_MAD
11594 tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915
NC
11595 if (!PL_thisopen && !keep_delims) {
11596 PL_thisopen = newSVpvn(tstart, s - tstart);
5db06880
NC
11597 stuffstart = s - SvPVX(PL_linestr);
11598 }
11599#endif
93a17b20 11600 for (;;) {
220e2d4e
IH
11601 if (PL_encoding && !UTF) {
11602 bool cont = TRUE;
11603
11604 while (cont) {
95a20fc0 11605 int offset = s - SvPVX_const(PL_linestr);
66a1b24b 11606 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
f3b9ce0f 11607 &offset, (char*)termstr, termlen);
6136c704
AL
11608 const char * const ns = SvPVX_const(PL_linestr) + offset;
11609 char * const svlast = SvEND(sv) - 1;
220e2d4e
IH
11610
11611 for (; s < ns; s++) {
11612 if (*s == '\n' && !PL_rsfp)
11613 CopLINE_inc(PL_curcop);
11614 }
11615 if (!found)
11616 goto read_more_line;
11617 else {
11618 /* handle quoted delimiters */
52327caf 11619 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
f54cb97a 11620 const char *t;
95a20fc0 11621 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
220e2d4e
IH
11622 t--;
11623 if ((svlast-1 - t) % 2) {
11624 if (!keep_quoted) {
11625 *(svlast-1) = term;
11626 *svlast = '\0';
11627 SvCUR_set(sv, SvCUR(sv) - 1);
11628 }
11629 continue;
11630 }
11631 }
11632 if (PL_multi_open == PL_multi_close) {
11633 cont = FALSE;
11634 }
11635 else {
f54cb97a
AL
11636 const char *t;
11637 char *w;
0331ef07 11638 for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
220e2d4e
IH
11639 /* At here, all closes are "was quoted" one,
11640 so we don't check PL_multi_close. */
11641 if (*t == '\\') {
11642 if (!keep_quoted && *(t+1) == PL_multi_open)
11643 t++;
11644 else
11645 *w++ = *t++;
11646 }
11647 else if (*t == PL_multi_open)
11648 brackets++;
11649
11650 *w = *t;
11651 }
11652 if (w < t) {
11653 *w++ = term;
11654 *w = '\0';
95a20fc0 11655 SvCUR_set(sv, w - SvPVX_const(sv));
220e2d4e 11656 }
0331ef07 11657 last_off = w - SvPVX(sv);
220e2d4e
IH
11658 if (--brackets <= 0)
11659 cont = FALSE;
11660 }
11661 }
11662 }
11663 if (!keep_delims) {
11664 SvCUR_set(sv, SvCUR(sv) - 1);
11665 *SvEND(sv) = '\0';
11666 }
11667 break;
11668 }
11669
02aa26ce 11670 /* extend sv if need be */
3280af22 11671 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
02aa26ce 11672 /* set 'to' to the next character in the sv's string */
463ee0b2 11673 to = SvPVX(sv)+SvCUR(sv);
09bef843 11674
02aa26ce 11675 /* if open delimiter is the close delimiter read unbridle */
3280af22
NIS
11676 if (PL_multi_open == PL_multi_close) {
11677 for (; s < PL_bufend; s++,to++) {
02aa26ce 11678 /* embedded newlines increment the current line number */
3280af22 11679 if (*s == '\n' && !PL_rsfp)
57843af0 11680 CopLINE_inc(PL_curcop);
02aa26ce 11681 /* handle quoted delimiters */
3280af22 11682 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
09bef843 11683 if (!keep_quoted && s[1] == term)
a0d0e21e 11684 s++;
02aa26ce 11685 /* any other quotes are simply copied straight through */
a0d0e21e
LW
11686 else
11687 *to++ = *s++;
11688 }
02aa26ce
NT
11689 /* terminate when run out of buffer (the for() condition), or
11690 have found the terminator */
220e2d4e
IH
11691 else if (*s == term) {
11692 if (termlen == 1)
11693 break;
f3b9ce0f 11694 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
220e2d4e
IH
11695 break;
11696 }
63cd0674 11697 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
89491803 11698 has_utf8 = TRUE;
93a17b20
LW
11699 *to = *s;
11700 }
11701 }
02aa26ce
NT
11702
11703 /* if the terminator isn't the same as the start character (e.g.,
11704 matched brackets), we have to allow more in the quoting, and
11705 be prepared for nested brackets.
11706 */
93a17b20 11707 else {
02aa26ce 11708 /* read until we run out of string, or we find the terminator */
3280af22 11709 for (; s < PL_bufend; s++,to++) {
02aa26ce 11710 /* embedded newlines increment the line count */
3280af22 11711 if (*s == '\n' && !PL_rsfp)
57843af0 11712 CopLINE_inc(PL_curcop);
02aa26ce 11713 /* backslashes can escape the open or closing characters */
3280af22 11714 if (*s == '\\' && s+1 < PL_bufend) {
09bef843
SB
11715 if (!keep_quoted &&
11716 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
a0d0e21e
LW
11717 s++;
11718 else
11719 *to++ = *s++;
11720 }
02aa26ce 11721 /* allow nested opens and closes */
3280af22 11722 else if (*s == PL_multi_close && --brackets <= 0)
93a17b20 11723 break;
3280af22 11724 else if (*s == PL_multi_open)
93a17b20 11725 brackets++;
63cd0674 11726 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
89491803 11727 has_utf8 = TRUE;
93a17b20
LW
11728 *to = *s;
11729 }
11730 }
02aa26ce 11731 /* terminate the copied string and update the sv's end-of-string */
93a17b20 11732 *to = '\0';
95a20fc0 11733 SvCUR_set(sv, to - SvPVX_const(sv));
93a17b20 11734
02aa26ce
NT
11735 /*
11736 * this next chunk reads more into the buffer if we're not done yet
11737 */
11738
b1c7b182
GS
11739 if (s < PL_bufend)
11740 break; /* handle case where we are done yet :-) */
79072805 11741
6a27c188 11742#ifndef PERL_STRICT_CR
95a20fc0 11743 if (to - SvPVX_const(sv) >= 2) {
c6f14548
GS
11744 if ((to[-2] == '\r' && to[-1] == '\n') ||
11745 (to[-2] == '\n' && to[-1] == '\r'))
11746 {
f63a84b2
LW
11747 to[-2] = '\n';
11748 to--;
95a20fc0 11749 SvCUR_set(sv, to - SvPVX_const(sv));
f63a84b2
LW
11750 }
11751 else if (to[-1] == '\r')
11752 to[-1] = '\n';
11753 }
95a20fc0 11754 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
f63a84b2
LW
11755 to[-1] = '\n';
11756#endif
11757
220e2d4e 11758 read_more_line:
02aa26ce
NT
11759 /* if we're out of file, or a read fails, bail and reset the current
11760 line marker so we can report where the unterminated string began
11761 */
5db06880
NC
11762#ifdef PERL_MAD
11763 if (PL_madskills) {
c35e046a 11764 char * const tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915
NC
11765 if (PL_thisstuff)
11766 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
5db06880 11767 else
cd81e915 11768 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
5db06880
NC
11769 }
11770#endif
3280af22
NIS
11771 if (!PL_rsfp ||
11772 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
c07a80fd 11773 sv_free(sv);
eb160463 11774 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
bd61b366 11775 return NULL;
79072805 11776 }
5db06880
NC
11777#ifdef PERL_MAD
11778 stuffstart = 0;
11779#endif
02aa26ce 11780 /* we read a line, so increment our line counter */
57843af0 11781 CopLINE_inc(PL_curcop);
a0ed51b3 11782
02aa26ce 11783 /* update debugger info */
80a702cd 11784 if (PERLDB_LINE && PL_curstash != PL_debstash)
5fa550fb 11785 update_debugger_info(PL_linestr, NULL, 0);
a0ed51b3 11786
3280af22
NIS
11787 /* having changed the buffer, we must update PL_bufend */
11788 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 11789 PL_last_lop = PL_last_uni = NULL;
378cc40b 11790 }
4e553d73 11791
02aa26ce
NT
11792 /* at this point, we have successfully read the delimited string */
11793
220e2d4e 11794 if (!PL_encoding || UTF) {
5db06880
NC
11795#ifdef PERL_MAD
11796 if (PL_madskills) {
c35e046a 11797 char * const tstart = SvPVX(PL_linestr) + stuffstart;
29522234 11798 const int len = s - tstart;
cd81e915 11799 if (PL_thisstuff)
c35e046a 11800 sv_catpvn(PL_thisstuff, tstart, len);
5db06880 11801 else
c35e046a 11802 PL_thisstuff = newSVpvn(tstart, len);
cd81e915
NC
11803 if (!PL_thisclose && !keep_delims)
11804 PL_thisclose = newSVpvn(s,termlen);
5db06880
NC
11805 }
11806#endif
11807
220e2d4e
IH
11808 if (keep_delims)
11809 sv_catpvn(sv, s, termlen);
11810 s += termlen;
11811 }
5db06880
NC
11812#ifdef PERL_MAD
11813 else {
11814 if (PL_madskills) {
c35e046a
AL
11815 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11816 const int len = s - tstart - termlen;
cd81e915 11817 if (PL_thisstuff)
c35e046a 11818 sv_catpvn(PL_thisstuff, tstart, len);
5db06880 11819 else
c35e046a 11820 PL_thisstuff = newSVpvn(tstart, len);
cd81e915
NC
11821 if (!PL_thisclose && !keep_delims)
11822 PL_thisclose = newSVpvn(s - termlen,termlen);
5db06880
NC
11823 }
11824 }
11825#endif
220e2d4e 11826 if (has_utf8 || PL_encoding)
b1c7b182 11827 SvUTF8_on(sv);
d0063567 11828
57843af0 11829 PL_multi_end = CopLINE(PL_curcop);
02aa26ce
NT
11830
11831 /* if we allocated too much space, give some back */
93a17b20
LW
11832 if (SvCUR(sv) + 5 < SvLEN(sv)) {
11833 SvLEN_set(sv, SvCUR(sv) + 1);
b7e9a5c2 11834 SvPV_renew(sv, SvLEN(sv));
79072805 11835 }
02aa26ce
NT
11836
11837 /* decide whether this is the first or second quoted string we've read
11838 for this op
11839 */
4e553d73 11840
3280af22
NIS
11841 if (PL_lex_stuff)
11842 PL_lex_repl = sv;
79072805 11843 else
3280af22 11844 PL_lex_stuff = sv;
378cc40b
LW
11845 return s;
11846}
11847
02aa26ce
NT
11848/*
11849 scan_num
11850 takes: pointer to position in buffer
11851 returns: pointer to new position in buffer
11852 side-effects: builds ops for the constant in yylval.op
11853
11854 Read a number in any of the formats that Perl accepts:
11855
7fd134d9
JH
11856 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
11857 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
24138b49
JH
11858 0b[01](_?[01])*
11859 0[0-7](_?[0-7])*
11860 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
02aa26ce 11861
3280af22 11862 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
02aa26ce
NT
11863 thing it reads.
11864
11865 If it reads a number without a decimal point or an exponent, it will
11866 try converting the number to an integer and see if it can do so
11867 without loss of precision.
11868*/
4e553d73 11869
378cc40b 11870char *
bfed75c6 11871Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
378cc40b 11872{
97aff369 11873 dVAR;
bfed75c6 11874 register const char *s = start; /* current position in buffer */
02aa26ce
NT
11875 register char *d; /* destination in temp buffer */
11876 register char *e; /* end of temp buffer */
86554af2 11877 NV nv; /* number read, as a double */
a0714e2c 11878 SV *sv = NULL; /* place to put the converted number */
a86a20aa 11879 bool floatit; /* boolean: int or float? */
cbbf8932 11880 const char *lastub = NULL; /* position of last underbar */
bfed75c6 11881 static char const number_too_long[] = "Number too long";
378cc40b 11882
02aa26ce
NT
11883 /* We use the first character to decide what type of number this is */
11884
378cc40b 11885 switch (*s) {
79072805 11886 default:
cea2e8a9 11887 Perl_croak(aTHX_ "panic: scan_num");
4e553d73 11888
02aa26ce 11889 /* if it starts with a 0, it could be an octal number, a decimal in
a7cb1f99 11890 0.13 disguise, or a hexadecimal number, or a binary number. */
378cc40b
LW
11891 case '0':
11892 {
02aa26ce
NT
11893 /* variables:
11894 u holds the "number so far"
4f19785b
WSI
11895 shift the power of 2 of the base
11896 (hex == 4, octal == 3, binary == 1)
02aa26ce
NT
11897 overflowed was the number more than we can hold?
11898
11899 Shift is used when we add a digit. It also serves as an "are
4f19785b
WSI
11900 we in octal/hex/binary?" indicator to disallow hex characters
11901 when in octal mode.
02aa26ce 11902 */
9e24b6e2
JH
11903 NV n = 0.0;
11904 UV u = 0;
79072805 11905 I32 shift;
9e24b6e2 11906 bool overflowed = FALSE;
61f33854 11907 bool just_zero = TRUE; /* just plain 0 or binary number? */
27da23d5
JH
11908 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11909 static const char* const bases[5] =
11910 { "", "binary", "", "octal", "hexadecimal" };
11911 static const char* const Bases[5] =
11912 { "", "Binary", "", "Octal", "Hexadecimal" };
11913 static const char* const maxima[5] =
11914 { "",
11915 "0b11111111111111111111111111111111",
11916 "",
11917 "037777777777",
11918 "0xffffffff" };
bfed75c6 11919 const char *base, *Base, *max;
378cc40b 11920
02aa26ce 11921 /* check for hex */
378cc40b
LW
11922 if (s[1] == 'x') {
11923 shift = 4;
11924 s += 2;
61f33854 11925 just_zero = FALSE;
4f19785b
WSI
11926 } else if (s[1] == 'b') {
11927 shift = 1;
11928 s += 2;
61f33854 11929 just_zero = FALSE;
378cc40b 11930 }
02aa26ce 11931 /* check for a decimal in disguise */
b78218b7 11932 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
378cc40b 11933 goto decimal;
02aa26ce 11934 /* so it must be octal */
928753ea 11935 else {
378cc40b 11936 shift = 3;
928753ea
JH
11937 s++;
11938 }
11939
11940 if (*s == '_') {
11941 if (ckWARN(WARN_SYNTAX))
9014280d 11942 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
928753ea
JH
11943 "Misplaced _ in number");
11944 lastub = s++;
11945 }
9e24b6e2
JH
11946
11947 base = bases[shift];
11948 Base = Bases[shift];
11949 max = maxima[shift];
02aa26ce 11950
4f19785b 11951 /* read the rest of the number */
378cc40b 11952 for (;;) {
9e24b6e2 11953 /* x is used in the overflow test,
893fe2c2 11954 b is the digit we're adding on. */
9e24b6e2 11955 UV x, b;
55497cff 11956
378cc40b 11957 switch (*s) {
02aa26ce
NT
11958
11959 /* if we don't mention it, we're done */
378cc40b
LW
11960 default:
11961 goto out;
02aa26ce 11962
928753ea 11963 /* _ are ignored -- but warned about if consecutive */
de3bb511 11964 case '_':
041457d9 11965 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
9014280d 11966 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
928753ea
JH
11967 "Misplaced _ in number");
11968 lastub = s++;
de3bb511 11969 break;
02aa26ce
NT
11970
11971 /* 8 and 9 are not octal */
378cc40b 11972 case '8': case '9':
4f19785b 11973 if (shift == 3)
cea2e8a9 11974 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
378cc40b 11975 /* FALL THROUGH */
02aa26ce
NT
11976
11977 /* octal digits */
4f19785b 11978 case '2': case '3': case '4':
378cc40b 11979 case '5': case '6': case '7':
4f19785b 11980 if (shift == 1)
cea2e8a9 11981 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
4f19785b
WSI
11982 /* FALL THROUGH */
11983
11984 case '0': case '1':
02aa26ce 11985 b = *s++ & 15; /* ASCII digit -> value of digit */
55497cff 11986 goto digit;
02aa26ce
NT
11987
11988 /* hex digits */
378cc40b
LW
11989 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
11990 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
02aa26ce 11991 /* make sure they said 0x */
378cc40b
LW
11992 if (shift != 4)
11993 goto out;
55497cff 11994 b = (*s++ & 7) + 9;
02aa26ce
NT
11995
11996 /* Prepare to put the digit we have onto the end
11997 of the number so far. We check for overflows.
11998 */
11999
55497cff 12000 digit:
61f33854 12001 just_zero = FALSE;
9e24b6e2
JH
12002 if (!overflowed) {
12003 x = u << shift; /* make room for the digit */
12004
12005 if ((x >> shift) != u
12006 && !(PL_hints & HINT_NEW_BINARY)) {
9e24b6e2
JH
12007 overflowed = TRUE;
12008 n = (NV) u;
767a6a26 12009 if (ckWARN_d(WARN_OVERFLOW))
9014280d 12010 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
9e24b6e2
JH
12011 "Integer overflow in %s number",
12012 base);
12013 } else
12014 u = x | b; /* add the digit to the end */
12015 }
12016 if (overflowed) {
12017 n *= nvshift[shift];
12018 /* If an NV has not enough bits in its
12019 * mantissa to represent an UV this summing of
12020 * small low-order numbers is a waste of time
12021 * (because the NV cannot preserve the
12022 * low-order bits anyway): we could just
12023 * remember when did we overflow and in the
12024 * end just multiply n by the right
12025 * amount. */
12026 n += (NV) b;
55497cff 12027 }
378cc40b
LW
12028 break;
12029 }
12030 }
02aa26ce
NT
12031
12032 /* if we get here, we had success: make a scalar value from
12033 the number.
12034 */
378cc40b 12035 out:
928753ea
JH
12036
12037 /* final misplaced underbar check */
12038 if (s[-1] == '_') {
12039 if (ckWARN(WARN_SYNTAX))
9014280d 12040 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
928753ea
JH
12041 }
12042
561b68a9 12043 sv = newSV(0);
9e24b6e2 12044 if (overflowed) {
041457d9 12045 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
9014280d 12046 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
9e24b6e2
JH
12047 "%s number > %s non-portable",
12048 Base, max);
12049 sv_setnv(sv, n);
12050 }
12051 else {
15041a67 12052#if UVSIZE > 4
041457d9 12053 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
9014280d 12054 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
9e24b6e2
JH
12055 "%s number > %s non-portable",
12056 Base, max);
2cc4c2dc 12057#endif
9e24b6e2
JH
12058 sv_setuv(sv, u);
12059 }
61f33854 12060 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
bfed75c6 12061 sv = new_constant(start, s - start, "integer",
a0714e2c 12062 sv, NULL, NULL);
61f33854 12063 else if (PL_hints & HINT_NEW_BINARY)
a0714e2c 12064 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
378cc40b
LW
12065 }
12066 break;
02aa26ce
NT
12067
12068 /*
12069 handle decimal numbers.
12070 we're also sent here when we read a 0 as the first digit
12071 */
378cc40b
LW
12072 case '1': case '2': case '3': case '4': case '5':
12073 case '6': case '7': case '8': case '9': case '.':
12074 decimal:
3280af22
NIS
12075 d = PL_tokenbuf;
12076 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
79072805 12077 floatit = FALSE;
02aa26ce
NT
12078
12079 /* read next group of digits and _ and copy into d */
de3bb511 12080 while (isDIGIT(*s) || *s == '_') {
4e553d73 12081 /* skip underscores, checking for misplaced ones
02aa26ce
NT
12082 if -w is on
12083 */
93a17b20 12084 if (*s == '_') {
041457d9 12085 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
9014280d 12086 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
928753ea
JH
12087 "Misplaced _ in number");
12088 lastub = s++;
93a17b20 12089 }
fc36a67e 12090 else {
02aa26ce 12091 /* check for end of fixed-length buffer */
fc36a67e 12092 if (d >= e)
cea2e8a9 12093 Perl_croak(aTHX_ number_too_long);
02aa26ce 12094 /* if we're ok, copy the character */
378cc40b 12095 *d++ = *s++;
fc36a67e 12096 }
378cc40b 12097 }
02aa26ce
NT
12098
12099 /* final misplaced underbar check */
928753ea 12100 if (lastub && s == lastub + 1) {
d008e5eb 12101 if (ckWARN(WARN_SYNTAX))
9014280d 12102 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
d008e5eb 12103 }
02aa26ce
NT
12104
12105 /* read a decimal portion if there is one. avoid
12106 3..5 being interpreted as the number 3. followed
12107 by .5
12108 */
2f3197b3 12109 if (*s == '.' && s[1] != '.') {
79072805 12110 floatit = TRUE;
378cc40b 12111 *d++ = *s++;
02aa26ce 12112
928753ea
JH
12113 if (*s == '_') {
12114 if (ckWARN(WARN_SYNTAX))
9014280d 12115 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
928753ea
JH
12116 "Misplaced _ in number");
12117 lastub = s;
12118 }
12119
12120 /* copy, ignoring underbars, until we run out of digits.
02aa26ce 12121 */
fc36a67e 12122 for (; isDIGIT(*s) || *s == '_'; s++) {
02aa26ce 12123 /* fixed length buffer check */
fc36a67e 12124 if (d >= e)
cea2e8a9 12125 Perl_croak(aTHX_ number_too_long);
928753ea 12126 if (*s == '_') {
041457d9 12127 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
9014280d 12128 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
928753ea
JH
12129 "Misplaced _ in number");
12130 lastub = s;
12131 }
12132 else
fc36a67e 12133 *d++ = *s;
378cc40b 12134 }
928753ea
JH
12135 /* fractional part ending in underbar? */
12136 if (s[-1] == '_') {
12137 if (ckWARN(WARN_SYNTAX))
9014280d 12138 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
928753ea
JH
12139 "Misplaced _ in number");
12140 }
dd629d5b
GS
12141 if (*s == '.' && isDIGIT(s[1])) {
12142 /* oops, it's really a v-string, but without the "v" */
f4758303 12143 s = start;
dd629d5b
GS
12144 goto vstring;
12145 }
378cc40b 12146 }
02aa26ce
NT
12147
12148 /* read exponent part, if present */
3792a11b 12149 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
79072805
LW
12150 floatit = TRUE;
12151 s++;
02aa26ce
NT
12152
12153 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
79072805 12154 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
02aa26ce 12155
7fd134d9
JH
12156 /* stray preinitial _ */
12157 if (*s == '_') {
12158 if (ckWARN(WARN_SYNTAX))
9014280d 12159 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
7fd134d9
JH
12160 "Misplaced _ in number");
12161 lastub = s++;
12162 }
12163
02aa26ce 12164 /* allow positive or negative exponent */
378cc40b
LW
12165 if (*s == '+' || *s == '-')
12166 *d++ = *s++;
02aa26ce 12167
7fd134d9
JH
12168 /* stray initial _ */
12169 if (*s == '_') {
12170 if (ckWARN(WARN_SYNTAX))
9014280d 12171 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
7fd134d9
JH
12172 "Misplaced _ in number");
12173 lastub = s++;
12174 }
12175
7fd134d9
JH
12176 /* read digits of exponent */
12177 while (isDIGIT(*s) || *s == '_') {
12178 if (isDIGIT(*s)) {
12179 if (d >= e)
12180 Perl_croak(aTHX_ number_too_long);
b3b48e3e 12181 *d++ = *s++;
7fd134d9
JH
12182 }
12183 else {
041457d9
DM
12184 if (((lastub && s == lastub + 1) ||
12185 (!isDIGIT(s[1]) && s[1] != '_'))
12186 && ckWARN(WARN_SYNTAX))
9014280d 12187 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
7fd134d9 12188 "Misplaced _ in number");
b3b48e3e 12189 lastub = s++;
7fd134d9 12190 }
7fd134d9 12191 }
378cc40b 12192 }
02aa26ce 12193
02aa26ce
NT
12194
12195 /* make an sv from the string */
561b68a9 12196 sv = newSV(0);
097ee67d 12197
0b7fceb9 12198 /*
58bb9ec3
NC
12199 We try to do an integer conversion first if no characters
12200 indicating "float" have been found.
0b7fceb9
MU
12201 */
12202
12203 if (!floatit) {
58bb9ec3 12204 UV uv;
6136c704 12205 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
58bb9ec3
NC
12206
12207 if (flags == IS_NUMBER_IN_UV) {
12208 if (uv <= IV_MAX)
86554af2 12209 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
58bb9ec3 12210 else
c239479b 12211 sv_setuv(sv, uv);
58bb9ec3
NC
12212 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
12213 if (uv <= (UV) IV_MIN)
12214 sv_setiv(sv, -(IV)uv);
12215 else
12216 floatit = TRUE;
12217 } else
12218 floatit = TRUE;
12219 }
0b7fceb9 12220 if (floatit) {
58bb9ec3
NC
12221 /* terminate the string */
12222 *d = '\0';
86554af2
JH
12223 nv = Atof(PL_tokenbuf);
12224 sv_setnv(sv, nv);
12225 }
86554af2 12226
b8403495
JH
12227 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
12228 (PL_hints & HINT_NEW_INTEGER) )
10edeb5d
JH
12229 sv = new_constant(PL_tokenbuf,
12230 d - PL_tokenbuf,
12231 (const char *)
b8403495 12232 (floatit ? "float" : "integer"),
a0714e2c 12233 sv, NULL, NULL);
378cc40b 12234 break;
0b7fceb9 12235
e312add1 12236 /* if it starts with a v, it could be a v-string */
a7cb1f99 12237 case 'v':
dd629d5b 12238vstring:
561b68a9 12239 sv = newSV(5); /* preallocate storage space */
65b06e02 12240 s = scan_vstring(s, PL_bufend, sv);
a7cb1f99 12241 break;
79072805 12242 }
a687059c 12243
02aa26ce
NT
12244 /* make the op for the constant and return */
12245
a86a20aa 12246 if (sv)
b73d6f50 12247 lvalp->opval = newSVOP(OP_CONST, 0, sv);
a7cb1f99 12248 else
5f66b61c 12249 lvalp->opval = NULL;
a687059c 12250
73d840c0 12251 return (char *)s;
378cc40b
LW
12252}
12253
76e3520e 12254STATIC char *
cea2e8a9 12255S_scan_formline(pTHX_ register char *s)
378cc40b 12256{
97aff369 12257 dVAR;
79072805 12258 register char *eol;
378cc40b 12259 register char *t;
6136c704 12260 SV * const stuff = newSVpvs("");
79072805 12261 bool needargs = FALSE;
c5ee2135 12262 bool eofmt = FALSE;
5db06880
NC
12263#ifdef PERL_MAD
12264 char *tokenstart = s;
12265 SV* savewhite;
12266
12267 if (PL_madskills) {
cd81e915
NC
12268 savewhite = PL_thiswhite;
12269 PL_thiswhite = 0;
5db06880
NC
12270 }
12271#endif
378cc40b 12272
79072805 12273 while (!needargs) {
a1b95068 12274 if (*s == '.') {
c35e046a 12275 t = s+1;
51882d45 12276#ifdef PERL_STRICT_CR
c35e046a
AL
12277 while (SPACE_OR_TAB(*t))
12278 t++;
51882d45 12279#else
c35e046a
AL
12280 while (SPACE_OR_TAB(*t) || *t == '\r')
12281 t++;
51882d45 12282#endif
c5ee2135
WL
12283 if (*t == '\n' || t == PL_bufend) {
12284 eofmt = TRUE;
79072805 12285 break;
c5ee2135 12286 }
79072805 12287 }
3280af22 12288 if (PL_in_eval && !PL_rsfp) {
07409e01 12289 eol = (char *) memchr(s,'\n',PL_bufend-s);
0f85fab0 12290 if (!eol++)
3280af22 12291 eol = PL_bufend;
0f85fab0
LW
12292 }
12293 else
3280af22 12294 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
79072805 12295 if (*s != '#') {
a0d0e21e
LW
12296 for (t = s; t < eol; t++) {
12297 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12298 needargs = FALSE;
12299 goto enough; /* ~~ must be first line in formline */
378cc40b 12300 }
a0d0e21e
LW
12301 if (*t == '@' || *t == '^')
12302 needargs = TRUE;
378cc40b 12303 }
7121b347
MG
12304 if (eol > s) {
12305 sv_catpvn(stuff, s, eol-s);
2dc4c65b 12306#ifndef PERL_STRICT_CR
7121b347
MG
12307 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12308 char *end = SvPVX(stuff) + SvCUR(stuff);
12309 end[-2] = '\n';
12310 end[-1] = '\0';
b162af07 12311 SvCUR_set(stuff, SvCUR(stuff) - 1);
7121b347 12312 }
2dc4c65b 12313#endif
7121b347
MG
12314 }
12315 else
12316 break;
79072805 12317 }
95a20fc0 12318 s = (char*)eol;
3280af22 12319 if (PL_rsfp) {
5db06880
NC
12320#ifdef PERL_MAD
12321 if (PL_madskills) {
cd81e915
NC
12322 if (PL_thistoken)
12323 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
5db06880 12324 else
cd81e915 12325 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
5db06880
NC
12326 }
12327#endif
3280af22 12328 s = filter_gets(PL_linestr, PL_rsfp, 0);
5db06880
NC
12329#ifdef PERL_MAD
12330 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12331#else
3280af22 12332 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
5db06880 12333#endif
3280af22 12334 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
bd61b366 12335 PL_last_lop = PL_last_uni = NULL;
79072805 12336 if (!s) {
3280af22 12337 s = PL_bufptr;
378cc40b
LW
12338 break;
12339 }
378cc40b 12340 }
463ee0b2 12341 incline(s);
79072805 12342 }
a0d0e21e
LW
12343 enough:
12344 if (SvCUR(stuff)) {
3280af22 12345 PL_expect = XTERM;
79072805 12346 if (needargs) {
3280af22 12347 PL_lex_state = LEX_NORMAL;
cd81e915 12348 start_force(PL_curforce);
9ded7720 12349 NEXTVAL_NEXTTOKE.ival = 0;
79072805
LW
12350 force_next(',');
12351 }
a0d0e21e 12352 else
3280af22 12353 PL_lex_state = LEX_FORMLINE;
1bd51a4c 12354 if (!IN_BYTES) {
95a20fc0 12355 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
1bd51a4c
IH
12356 SvUTF8_on(stuff);
12357 else if (PL_encoding)
12358 sv_recode_to_utf8(stuff, PL_encoding);
12359 }
cd81e915 12360 start_force(PL_curforce);
9ded7720 12361 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
79072805 12362 force_next(THING);
cd81e915 12363 start_force(PL_curforce);
9ded7720 12364 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
79072805 12365 force_next(LSTOP);
378cc40b 12366 }
79072805 12367 else {
8990e307 12368 SvREFCNT_dec(stuff);
c5ee2135
WL
12369 if (eofmt)
12370 PL_lex_formbrack = 0;
3280af22 12371 PL_bufptr = s;
79072805 12372 }
5db06880
NC
12373#ifdef PERL_MAD
12374 if (PL_madskills) {
cd81e915
NC
12375 if (PL_thistoken)
12376 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
5db06880 12377 else
cd81e915
NC
12378 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12379 PL_thiswhite = savewhite;
5db06880
NC
12380 }
12381#endif
79072805 12382 return s;
378cc40b 12383}
a687059c 12384
76e3520e 12385STATIC void
cea2e8a9 12386S_set_csh(pTHX)
a687059c 12387{
ae986130 12388#ifdef CSH
97aff369 12389 dVAR;
3280af22
NIS
12390 if (!PL_cshlen)
12391 PL_cshlen = strlen(PL_cshname);
5f66b61c 12392#else
b2675967 12393#if defined(USE_ITHREADS)
96a5add6 12394 PERL_UNUSED_CONTEXT;
ae986130 12395#endif
b2675967 12396#endif
a687059c 12397}
463ee0b2 12398
ba6d6ac9 12399I32
864dbfa3 12400Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
8990e307 12401{
97aff369 12402 dVAR;
a3b680e6 12403 const I32 oldsavestack_ix = PL_savestack_ix;
6136c704 12404 CV* const outsidecv = PL_compcv;
8990e307 12405
3280af22
NIS
12406 if (PL_compcv) {
12407 assert(SvTYPE(PL_compcv) == SVt_PVCV);
e9a444f0 12408 }
7766f137 12409 SAVEI32(PL_subline);
3280af22 12410 save_item(PL_subname);
3280af22 12411 SAVESPTR(PL_compcv);
3280af22 12412
b9f83d2f 12413 PL_compcv = (CV*)newSV_type(is_format ? SVt_PVFM : SVt_PVCV);
3280af22
NIS
12414 CvFLAGS(PL_compcv) |= flags;
12415
57843af0 12416 PL_subline = CopLINE(PL_curcop);
dd2155a4 12417 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
b37c2d43 12418 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
a3985cdc 12419 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
748a9306 12420
8990e307
LW
12421 return oldsavestack_ix;
12422}
12423
084592ab
CN
12424#ifdef __SC__
12425#pragma segment Perl_yylex
12426#endif
8990e307 12427int
bfed75c6 12428Perl_yywarn(pTHX_ const char *s)
8990e307 12429{
97aff369 12430 dVAR;
faef0170 12431 PL_in_eval |= EVAL_WARNONLY;
748a9306 12432 yyerror(s);
faef0170 12433 PL_in_eval &= ~EVAL_WARNONLY;
748a9306 12434 return 0;
8990e307
LW
12435}
12436
12437int
bfed75c6 12438Perl_yyerror(pTHX_ const char *s)
463ee0b2 12439{
97aff369 12440 dVAR;
bfed75c6
AL
12441 const char *where = NULL;
12442 const char *context = NULL;
68dc0745 12443 int contlen = -1;
46fc3d4c 12444 SV *msg;
5912531f 12445 int yychar = PL_parser->yychar;
463ee0b2 12446
3280af22 12447 if (!yychar || (yychar == ';' && !PL_rsfp))
54310121 12448 where = "at EOF";
8bcfe651
TM
12449 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12450 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12451 PL_oldbufptr != PL_bufptr) {
f355267c
JH
12452 /*
12453 Only for NetWare:
12454 The code below is removed for NetWare because it abends/crashes on NetWare
12455 when the script has error such as not having the closing quotes like:
12456 if ($var eq "value)
12457 Checking of white spaces is anyway done in NetWare code.
12458 */
12459#ifndef NETWARE
3280af22
NIS
12460 while (isSPACE(*PL_oldoldbufptr))
12461 PL_oldoldbufptr++;
f355267c 12462#endif
3280af22
NIS
12463 context = PL_oldoldbufptr;
12464 contlen = PL_bufptr - PL_oldoldbufptr;
463ee0b2 12465 }
8bcfe651
TM
12466 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12467 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
f355267c
JH
12468 /*
12469 Only for NetWare:
12470 The code below is removed for NetWare because it abends/crashes on NetWare
12471 when the script has error such as not having the closing quotes like:
12472 if ($var eq "value)
12473 Checking of white spaces is anyway done in NetWare code.
12474 */
12475#ifndef NETWARE
3280af22
NIS
12476 while (isSPACE(*PL_oldbufptr))
12477 PL_oldbufptr++;
f355267c 12478#endif
3280af22
NIS
12479 context = PL_oldbufptr;
12480 contlen = PL_bufptr - PL_oldbufptr;
463ee0b2
LW
12481 }
12482 else if (yychar > 255)
68dc0745 12483 where = "next token ???";
12fbd33b 12484 else if (yychar == -2) { /* YYEMPTY */
3280af22
NIS
12485 if (PL_lex_state == LEX_NORMAL ||
12486 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
68dc0745 12487 where = "at end of line";
3280af22 12488 else if (PL_lex_inpat)
68dc0745 12489 where = "within pattern";
463ee0b2 12490 else
68dc0745 12491 where = "within string";
463ee0b2 12492 }
46fc3d4c 12493 else {
6136c704 12494 SV * const where_sv = sv_2mortal(newSVpvs("next char "));
46fc3d4c 12495 if (yychar < 32)
cea2e8a9 12496 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
46fc3d4c 12497 else if (isPRINT_LC(yychar))
cea2e8a9 12498 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
463ee0b2 12499 else
cea2e8a9 12500 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
95a20fc0 12501 where = SvPVX_const(where_sv);
463ee0b2 12502 }
46fc3d4c 12503 msg = sv_2mortal(newSVpv(s, 0));
ed094faf 12504 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
248c2a4d 12505 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
68dc0745 12506 if (context)
cea2e8a9 12507 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
463ee0b2 12508 else
cea2e8a9 12509 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
57843af0 12510 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
cf2093f6 12511 Perl_sv_catpvf(aTHX_ msg,
57def98f 12512 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
cf2093f6 12513 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
3280af22 12514 PL_multi_end = 0;
a0d0e21e 12515 }
56da5a46 12516 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
be2597df 12517 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, SVfARG(msg));
463ee0b2 12518 else
5a844595 12519 qerror(msg);
c7d6bfb2
GS
12520 if (PL_error_count >= 10) {
12521 if (PL_in_eval && SvCUR(ERRSV))
d2560b70 12522 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
be2597df 12523 SVfARG(ERRSV), OutCopFILE(PL_curcop));
c7d6bfb2
GS
12524 else
12525 Perl_croak(aTHX_ "%s has too many errors.\n",
248c2a4d 12526 OutCopFILE(PL_curcop));
c7d6bfb2 12527 }
3280af22 12528 PL_in_my = 0;
5c284bb0 12529 PL_in_my_stash = NULL;
463ee0b2
LW
12530 return 0;
12531}
084592ab
CN
12532#ifdef __SC__
12533#pragma segment Main
12534#endif
4e35701f 12535
b250498f 12536STATIC char*
3ae08724 12537S_swallow_bom(pTHX_ U8 *s)
01ec43d0 12538{
97aff369 12539 dVAR;
f54cb97a 12540 const STRLEN slen = SvCUR(PL_linestr);
7aa207d6 12541 switch (s[0]) {
4e553d73
NIS
12542 case 0xFF:
12543 if (s[1] == 0xFE) {
7aa207d6 12544 /* UTF-16 little-endian? (or UTF32-LE?) */
3ae08724 12545 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
7aa207d6 12546 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
01ec43d0 12547#ifndef PERL_NO_UTF16_FILTER
7aa207d6 12548 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
3ae08724 12549 s += 2;
7aa207d6 12550 utf16le:
dea0fc0b
JH
12551 if (PL_bufend > (char*)s) {
12552 U8 *news;
12553 I32 newlen;
12554
12555 filter_add(utf16rev_textfilter, NULL);
a02a5408 12556 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
1de9afcd 12557 utf16_to_utf8_reversed(s, news,
aed58286 12558 PL_bufend - (char*)s - 1,
1de9afcd 12559 &newlen);
7aa207d6 12560 sv_setpvn(PL_linestr, (const char*)news, newlen);
5db06880
NC
12561#ifdef PERL_MAD
12562 s = (U8*)SvPVX(PL_linestr);
12563 Copy(news, s, newlen, U8);
12564 s[newlen] = '\0';
12565#endif
dea0fc0b 12566 Safefree(news);
7aa207d6
JH
12567 SvUTF8_on(PL_linestr);
12568 s = (U8*)SvPVX(PL_linestr);
5db06880
NC
12569#ifdef PERL_MAD
12570 /* FIXME - is this a general bug fix? */
12571 s[newlen] = '\0';
12572#endif
7aa207d6 12573 PL_bufend = SvPVX(PL_linestr) + newlen;
dea0fc0b 12574 }
b250498f 12575#else
7aa207d6 12576 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
b250498f 12577#endif
01ec43d0
GS
12578 }
12579 break;
78ae23f5 12580 case 0xFE:
7aa207d6 12581 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
01ec43d0 12582#ifndef PERL_NO_UTF16_FILTER
7aa207d6 12583 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
dea0fc0b 12584 s += 2;
7aa207d6 12585 utf16be:
dea0fc0b
JH
12586 if (PL_bufend > (char *)s) {
12587 U8 *news;
12588 I32 newlen;
12589
12590 filter_add(utf16_textfilter, NULL);
a02a5408 12591 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
1de9afcd
RGS
12592 utf16_to_utf8(s, news,
12593 PL_bufend - (char*)s,
12594 &newlen);
7aa207d6 12595 sv_setpvn(PL_linestr, (const char*)news, newlen);
dea0fc0b 12596 Safefree(news);
7aa207d6
JH
12597 SvUTF8_on(PL_linestr);
12598 s = (U8*)SvPVX(PL_linestr);
12599 PL_bufend = SvPVX(PL_linestr) + newlen;
dea0fc0b 12600 }
b250498f 12601#else
7aa207d6 12602 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
b250498f 12603#endif
01ec43d0
GS
12604 }
12605 break;
3ae08724
GS
12606 case 0xEF:
12607 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
7aa207d6 12608 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
01ec43d0
GS
12609 s += 3; /* UTF-8 */
12610 }
12611 break;
12612 case 0:
7aa207d6
JH
12613 if (slen > 3) {
12614 if (s[1] == 0) {
12615 if (s[2] == 0xFE && s[3] == 0xFF) {
12616 /* UTF-32 big-endian */
12617 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12618 }
12619 }
12620 else if (s[2] == 0 && s[3] != 0) {
12621 /* Leading bytes
12622 * 00 xx 00 xx
12623 * are a good indicator of UTF-16BE. */
12624 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12625 goto utf16be;
12626 }
01ec43d0 12627 }
e294cc5d
JH
12628#ifdef EBCDIC
12629 case 0xDD:
12630 if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
12631 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12632 s += 4; /* UTF-8 */
12633 }
12634 break;
12635#endif
12636
7aa207d6
JH
12637 default:
12638 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12639 /* Leading bytes
12640 * xx 00 xx 00
12641 * are a good indicator of UTF-16LE. */
12642 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12643 goto utf16le;
12644 }
01ec43d0 12645 }
b8f84bb2 12646 return (char*)s;
b250498f 12647}
4755096e 12648
4755096e
GS
12649/*
12650 * restore_rsfp
12651 * Restore a source filter.
12652 */
12653
12654static void
acfe0abc 12655restore_rsfp(pTHX_ void *f)
4755096e 12656{
97aff369 12657 dVAR;
0bd48802 12658 PerlIO * const fp = (PerlIO*)f;
4755096e
GS
12659
12660 if (PL_rsfp == PerlIO_stdin())
12661 PerlIO_clearerr(PL_rsfp);
12662 else if (PL_rsfp && (PL_rsfp != fp))
12663 PerlIO_close(PL_rsfp);
12664 PL_rsfp = fp;
12665}
6e3aabd6
GS
12666
12667#ifndef PERL_NO_UTF16_FILTER
12668static I32
acfe0abc 12669utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
6e3aabd6 12670{
97aff369 12671 dVAR;
f54cb97a
AL
12672 const STRLEN old = SvCUR(sv);
12673 const I32 count = FILTER_READ(idx+1, sv, maxlen);
1de9afcd
RGS
12674 DEBUG_P(PerlIO_printf(Perl_debug_log,
12675 "utf16_textfilter(%p): %d %d (%d)\n",
55662e27
JH
12676 FPTR2DPTR(void *, utf16_textfilter),
12677 idx, maxlen, (int) count));
6e3aabd6
GS
12678 if (count) {
12679 U8* tmps;
dea0fc0b 12680 I32 newlen;
a02a5408 12681 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
95a20fc0
SP
12682 Copy(SvPVX_const(sv), tmps, old, char);
12683 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
1de9afcd
RGS
12684 SvCUR(sv) - old, &newlen);
12685 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
6e3aabd6 12686 }
1de9afcd
RGS
12687 DEBUG_P({sv_dump(sv);});
12688 return SvCUR(sv);
6e3aabd6
GS
12689}
12690
12691static I32
acfe0abc 12692utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
6e3aabd6 12693{
97aff369 12694 dVAR;
f54cb97a
AL
12695 const STRLEN old = SvCUR(sv);
12696 const I32 count = FILTER_READ(idx+1, sv, maxlen);
1de9afcd
RGS
12697 DEBUG_P(PerlIO_printf(Perl_debug_log,
12698 "utf16rev_textfilter(%p): %d %d (%d)\n",
55662e27
JH
12699 FPTR2DPTR(void *, utf16rev_textfilter),
12700 idx, maxlen, (int) count));
6e3aabd6
GS
12701 if (count) {
12702 U8* tmps;
dea0fc0b 12703 I32 newlen;
a02a5408 12704 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
95a20fc0
SP
12705 Copy(SvPVX_const(sv), tmps, old, char);
12706 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
1de9afcd
RGS
12707 SvCUR(sv) - old, &newlen);
12708 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
6e3aabd6 12709 }
1de9afcd 12710 DEBUG_P({ sv_dump(sv); });
6e3aabd6
GS
12711 return count;
12712}
12713#endif
9f4817db 12714
f333445c
JP
12715/*
12716Returns a pointer to the next character after the parsed
12717vstring, as well as updating the passed in sv.
12718
12719Function must be called like
12720
561b68a9 12721 sv = newSV(5);
65b06e02 12722 s = scan_vstring(s,e,sv);
f333445c 12723
65b06e02 12724where s and e are the start and end of the string.
f333445c
JP
12725The sv should already be large enough to store the vstring
12726passed in, for performance reasons.
12727
12728*/
12729
12730char *
65b06e02 12731Perl_scan_vstring(pTHX_ const char *s, const char *e, SV *sv)
f333445c 12732{
97aff369 12733 dVAR;
bfed75c6
AL
12734 const char *pos = s;
12735 const char *start = s;
f333445c 12736 if (*pos == 'v') pos++; /* get past 'v' */
65b06e02 12737 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
3e884cbf 12738 pos++;
f333445c
JP
12739 if ( *pos != '.') {
12740 /* this may not be a v-string if followed by => */
bfed75c6 12741 const char *next = pos;
65b06e02 12742 while (next < e && isSPACE(*next))
8fc7bb1c 12743 ++next;
65b06e02 12744 if ((e - next) >= 2 && *next == '=' && next[1] == '>' ) {
f333445c
JP
12745 /* return string not v-string */
12746 sv_setpvn(sv,(char *)s,pos-s);
73d840c0 12747 return (char *)pos;
f333445c
JP
12748 }
12749 }
12750
12751 if (!isALPHA(*pos)) {
89ebb4a3 12752 U8 tmpbuf[UTF8_MAXBYTES+1];
f333445c 12753
d4c19fe8
AL
12754 if (*s == 'v')
12755 s++; /* get past 'v' */
f333445c
JP
12756
12757 sv_setpvn(sv, "", 0);
12758
12759 for (;;) {
d4c19fe8 12760 /* this is atoi() that tolerates underscores */
0bd48802
AL
12761 U8 *tmpend;
12762 UV rev = 0;
d4c19fe8
AL
12763 const char *end = pos;
12764 UV mult = 1;
12765 while (--end >= s) {
12766 if (*end != '_') {
12767 const UV orev = rev;
f333445c
JP
12768 rev += (*end - '0') * mult;
12769 mult *= 10;
12770 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12771 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12772 "Integer overflow in decimal number");
12773 }
12774 }
12775#ifdef EBCDIC
12776 if (rev > 0x7FFFFFFF)
12777 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12778#endif
12779 /* Append native character for the rev point */
12780 tmpend = uvchr_to_utf8(tmpbuf, rev);
12781 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12782 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12783 SvUTF8_on(sv);
65b06e02 12784 if (pos + 1 < e && *pos == '.' && isDIGIT(pos[1]))
f333445c
JP
12785 s = ++pos;
12786 else {
12787 s = pos;
12788 break;
12789 }
65b06e02 12790 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
f333445c
JP
12791 pos++;
12792 }
12793 SvPOK_on(sv);
12794 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12795 SvRMAGICAL_on(sv);
12796 }
73d840c0 12797 return (char *)s;
f333445c
JP
12798}
12799
1da4ca5f
NC
12800/*
12801 * Local variables:
12802 * c-indentation-style: bsd
12803 * c-basic-offset: 4
12804 * indent-tabs-mode: t
12805 * End:
12806 *
37442d52
RGS
12807 * ex: set ts=8 sts=4 sw=4 noet:
12808 */