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