ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/staticperl/perl/toke.c
Revision: 1.1
Committed: Thu Jun 30 14:26:43 2005 UTC (21 years, 3 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: PERL-5-8-7, HEAD
Branch point for: PERL
Log Message:
*** empty log message ***

File Contents

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