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