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