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