[DOC PATCH bleadperl] Two nits in perlhack.pod
[p5sagit/p5-mst-13.2.git] / toke.c
1 /*    toke.c
2  *
3  *    Copyright (c) 1991-2001, Larry Wall
4  *
5  *    You may distribute under the terms of either the GNU General Public
6  *    License or the Artistic License, as specified in the README file.
7  *
8  */
9
10 /*
11  *   "It all comes from here, the stench and the peril."  --Frodo
12  */
13
14 /*
15  * This file is the lexer for Perl.  It's closely linked to the
16  * parser, perly.y.
17  *
18  * The main routine is yylex(), which returns the next token.
19  */
20
21 #include "EXTERN.h"
22 #define PERL_IN_TOKE_C
23 #include "perl.h"
24
25 #define yychar  PL_yychar
26 #define yylval  PL_yylval
27
28 static char ident_too_long[] = "Identifier too long";
29
30 static void restore_rsfp(pTHXo_ void *f);
31 #ifndef PERL_NO_UTF16_FILTER
32 static I32 utf16_textfilter(pTHXo_ int idx, SV *sv, int maxlen);
33 static I32 utf16rev_textfilter(pTHXo_ int idx, SV *sv, int maxlen);
34 #endif
35
36 #define XFAKEBRACK 128
37 #define XENUMMASK 127
38
39 #ifdef EBCDIC
40 /* For now 'use utf8' does not affect tokenizer on EBCDIC */
41 #define UTF (PL_linestr && DO_UTF8(PL_linestr))
42 #else
43 #define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
44 #endif
45
46 /* In variables name $^X, these are the legal values for X.
47  * 1999-02-27 mjd-perl-patch@plover.com */
48 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
49
50 /* On MacOS, respect nonbreaking spaces */
51 #ifdef MACOS_TRADITIONAL
52 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
53 #else
54 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
55 #endif
56
57 /* LEX_* are values for PL_lex_state, the state of the lexer.
58  * They are arranged oddly so that the guard on the switch statement
59  * can get by with a single comparison (if the compiler is smart enough).
60  */
61
62 /* #define LEX_NOTPARSING               11 is done in perl.h. */
63
64 #define LEX_NORMAL              10
65 #define LEX_INTERPNORMAL         9
66 #define LEX_INTERPCASEMOD        8
67 #define LEX_INTERPPUSH           7
68 #define LEX_INTERPSTART          6
69 #define LEX_INTERPEND            5
70 #define LEX_INTERPENDMAYBE       4
71 #define LEX_INTERPCONCAT         3
72 #define LEX_INTERPCONST          2
73 #define LEX_FORMLINE             1
74 #define LEX_KNOWNEXT             0
75
76 #ifdef ff_next
77 #undef ff_next
78 #endif
79
80 #ifdef USE_PURE_BISON
81 #  ifndef YYMAXLEVEL
82 #    define YYMAXLEVEL 100
83 #  endif
84 YYSTYPE* yylval_pointer[YYMAXLEVEL];
85 int* yychar_pointer[YYMAXLEVEL];
86 int yyactlevel = -1;
87 #  undef yylval
88 #  undef yychar
89 #  define yylval (*yylval_pointer[yyactlevel])
90 #  define yychar (*yychar_pointer[yyactlevel])
91 #  define PERL_YYLEX_PARAM yylval_pointer[yyactlevel],yychar_pointer[yyactlevel]
92 #  undef yylex
93 #  define yylex()      Perl_yylex_r(aTHX_ yylval_pointer[yyactlevel],yychar_pointer[yyactlevel])
94 #endif
95
96 #include "keywords.h"
97
98 /* CLINE is a macro that ensures PL_copline has a sane value */
99
100 #ifdef CLINE
101 #undef CLINE
102 #endif
103 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
104
105 /*
106  * Convenience functions to return different tokens and prime the
107  * lexer for the next token.  They all take an argument.
108  *
109  * TOKEN        : generic token (used for '(', DOLSHARP, etc)
110  * OPERATOR     : generic operator
111  * AOPERATOR    : assignment operator
112  * PREBLOCK     : beginning the block after an if, while, foreach, ...
113  * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
114  * PREREF       : *EXPR where EXPR is not a simple identifier
115  * TERM         : expression term
116  * LOOPX        : loop exiting command (goto, last, dump, etc)
117  * FTST         : file test operator
118  * FUN0         : zero-argument function
119  * FUN1         : not used, except for not, which isn't a UNIOP
120  * BOop         : bitwise or or xor
121  * BAop         : bitwise and
122  * SHop         : shift operator
123  * PWop         : power operator
124  * PMop         : pattern-matching operator
125  * Aop          : addition-level operator
126  * Mop          : multiplication-level operator
127  * Eop          : equality-testing operator
128  * Rop          : relational operator <= != gt
129  *
130  * Also see LOP and lop() below.
131  */
132
133 /* Note that REPORT() and REPORT2() will be expressions that supply
134  * their own trailing comma, not suitable for statements as such. */
135 #ifdef DEBUGGING /* Serve -DT. */
136 #   define REPORT(x,retval) tokereport(x,s,(int)retval),
137 #   define REPORT2(x,retval) tokereport(x,s, yylval.ival),
138 #else
139 #   define REPORT(x,retval)
140 #   define REPORT2(x,retval)
141 #endif
142
143 #define TOKEN(retval) return (REPORT2("token",retval) PL_bufptr = s,(int)retval)
144 #define OPERATOR(retval) return (REPORT2("operator",retval) PL_expect = XTERM, PL_bufptr = s,(int)retval)
145 #define AOPERATOR(retval) return ao((REPORT2("aop",retval) PL_expect = XTERM, PL_bufptr = s,(int)retval))
146 #define PREBLOCK(retval) return (REPORT2("preblock",retval) PL_expect = XBLOCK,PL_bufptr = s,(int)retval)
147 #define PRETERMBLOCK(retval) return (REPORT2("pretermblock",retval) PL_expect = XTERMBLOCK,PL_bufptr = s,(int)retval)
148 #define PREREF(retval) return (REPORT2("preref",retval) PL_expect = XREF,PL_bufptr = s,(int)retval)
149 #define TERM(retval) return (CLINE, REPORT2("term",retval) PL_expect = XOPERATOR, PL_bufptr = s,(int)retval)
150 #define LOOPX(f) return(yylval.ival=f, REPORT("loopx",f) PL_expect = XTERM,PL_bufptr = s,(int)LOOPEX)
151 #define FTST(f) return(yylval.ival=f, REPORT("ftst",f) PL_expect = XTERM,PL_bufptr = s,(int)UNIOP)
152 #define FUN0(f) return(yylval.ival = f, REPORT("fun0",f) PL_expect = XOPERATOR,PL_bufptr = s,(int)FUNC0)
153 #define FUN1(f) return(yylval.ival = f, REPORT("fun1",f) PL_expect = XOPERATOR,PL_bufptr = s,(int)FUNC1)
154 #define BOop(f) return ao((yylval.ival=f, REPORT("bitorop",f) PL_expect = XTERM,PL_bufptr = s,(int)BITOROP))
155 #define BAop(f) return ao((yylval.ival=f, REPORT("bitandop",f) PL_expect = XTERM,PL_bufptr = s,(int)BITANDOP))
156 #define SHop(f) return ao((yylval.ival=f, REPORT("shiftop",f) PL_expect = XTERM,PL_bufptr = s,(int)SHIFTOP))
157 #define PWop(f) return ao((yylval.ival=f, REPORT("powop",f) PL_expect = XTERM,PL_bufptr = s,(int)POWOP))
158 #define PMop(f) return(yylval.ival=f, REPORT("matchop",f) PL_expect = XTERM,PL_bufptr = s,(int)MATCHOP)
159 #define Aop(f) return ao((yylval.ival=f, REPORT("add",f) PL_expect = XTERM,PL_bufptr = s,(int)ADDOP))
160 #define Mop(f) return ao((yylval.ival=f, REPORT("mul",f) PL_expect = XTERM,PL_bufptr = s,(int)MULOP))
161 #define Eop(f) return(yylval.ival=f, REPORT("eq",f) PL_expect = XTERM,PL_bufptr = s,(int)EQOP)
162 #define Rop(f) return(yylval.ival=f, REPORT("rel",f) PL_expect = XTERM,PL_bufptr = s,(int)RELOP)
163
164 /* This bit of chicanery makes a unary function followed by
165  * a parenthesis into a function with one argument, highest precedence.
166  */
167 #define UNI(f) return(yylval.ival = f, \
168         REPORT("uni",f) \
169         PL_expect = XTERM, \
170         PL_bufptr = s, \
171         PL_last_uni = PL_oldbufptr, \
172         PL_last_lop_op = f, \
173         (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
174
175 #define UNIBRACK(f) return(yylval.ival = f, \
176         REPORT("uni",f) \
177         PL_bufptr = s, \
178         PL_last_uni = PL_oldbufptr, \
179         (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
180
181 /* grandfather return to old style */
182 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
183
184 STATIC void
185 S_tokereport(pTHX_ char *thing, char* s, I32 rv)
186 {
187     SV *report;
188     DEBUG_T({
189         report = newSVpv(thing, 0);
190         Perl_sv_catpvf(aTHX_ report, ":line %d:%"IVdf":", CopLINE(PL_curcop),
191                 (IV)rv);
192
193         if (s - PL_bufptr > 0)
194             sv_catpvn(report, PL_bufptr, s - PL_bufptr);
195         else {
196             if (PL_oldbufptr && *PL_oldbufptr)
197                 sv_catpv(report, PL_tokenbuf);
198         }
199         PerlIO_printf(Perl_debug_log, "### %s\n", SvPV_nolen(report));
200     })
201 }
202
203 /*
204  * S_ao
205  *
206  * This subroutine detects &&= and ||= and turns an ANDAND or OROR
207  * into an OP_ANDASSIGN or OP_ORASSIGN
208  */
209
210 STATIC int
211 S_ao(pTHX_ int toketype)
212 {
213     if (*PL_bufptr == '=') {
214         PL_bufptr++;
215         if (toketype == ANDAND)
216             yylval.ival = OP_ANDASSIGN;
217         else if (toketype == OROR)
218             yylval.ival = OP_ORASSIGN;
219         toketype = ASSIGNOP;
220     }
221     return toketype;
222 }
223
224 /*
225  * S_no_op
226  * When Perl expects an operator and finds something else, no_op
227  * prints the warning.  It always prints "<something> found where
228  * operator expected.  It prints "Missing semicolon on previous line?"
229  * if the surprise occurs at the start of the line.  "do you need to
230  * predeclare ..." is printed out for code like "sub bar; foo bar $x"
231  * where the compiler doesn't know if foo is a method call or a function.
232  * It prints "Missing operator before end of line" if there's nothing
233  * after the missing operator, or "... before <...>" if there is something
234  * after the missing operator.
235  */
236
237 STATIC void
238 S_no_op(pTHX_ char *what, char *s)
239 {
240     char *oldbp = PL_bufptr;
241     bool is_first = (PL_oldbufptr == PL_linestart);
242
243     if (!s)
244         s = oldbp;
245     else
246         PL_bufptr = s;
247     yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
248     if (is_first)
249         Perl_warn(aTHX_ "\t(Missing semicolon on previous line?)\n");
250     else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
251         char *t;
252         for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ;
253         if (t < PL_bufptr && isSPACE(*t))
254             Perl_warn(aTHX_ "\t(Do you need to predeclare %.*s?)\n",
255                 t - PL_oldoldbufptr, PL_oldoldbufptr);
256     }
257     else {
258         assert(s >= oldbp);
259         Perl_warn(aTHX_ "\t(Missing operator before %.*s?)\n", s - oldbp, oldbp);
260     }
261     PL_bufptr = oldbp;
262 }
263
264 /*
265  * S_missingterm
266  * Complain about missing quote/regexp/heredoc terminator.
267  * If it's called with (char *)NULL then it cauterizes the line buffer.
268  * If we're in a delimited string and the delimiter is a control
269  * character, it's reformatted into a two-char sequence like ^C.
270  * This is fatal.
271  */
272
273 STATIC void
274 S_missingterm(pTHX_ char *s)
275 {
276     char tmpbuf[3];
277     char q;
278     if (s) {
279         char *nl = strrchr(s,'\n');
280         if (nl)
281             *nl = '\0';
282     }
283     else if (
284 #ifdef EBCDIC
285         iscntrl(PL_multi_close)
286 #else
287         PL_multi_close < 32 || PL_multi_close == 127
288 #endif
289         ) {
290         *tmpbuf = '^';
291         tmpbuf[1] = toCTRL(PL_multi_close);
292         s = "\\n";
293         tmpbuf[2] = '\0';
294         s = tmpbuf;
295     }
296     else {
297         *tmpbuf = PL_multi_close;
298         tmpbuf[1] = '\0';
299         s = tmpbuf;
300     }
301     q = strchr(s,'"') ? '\'' : '"';
302     Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
303 }
304
305 /*
306  * Perl_deprecate
307  */
308
309 void
310 Perl_deprecate(pTHX_ char *s)
311 {
312     if (ckWARN(WARN_DEPRECATED))
313         Perl_warner(aTHX_ WARN_DEPRECATED, "Use of %s is deprecated", s);
314 }
315
316 /*
317  * depcom
318  * Deprecate a comma-less variable list.
319  */
320
321 STATIC void
322 S_depcom(pTHX)
323 {
324     deprecate("comma-less variable list");
325 }
326
327 /*
328  * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
329  * utf16-to-utf8-reversed.
330  */
331
332 #ifdef PERL_CR_FILTER
333 static void
334 strip_return(SV *sv)
335 {
336     register char *s = SvPVX(sv);
337     register char *e = s + SvCUR(sv);
338     /* outer loop optimized to do nothing if there are no CR-LFs */
339     while (s < e) {
340         if (*s++ == '\r' && *s == '\n') {
341             /* hit a CR-LF, need to copy the rest */
342             register char *d = s - 1;
343             *d++ = *s++;
344             while (s < e) {
345                 if (*s == '\r' && s[1] == '\n')
346                     s++;
347                 *d++ = *s++;
348             }
349             SvCUR(sv) -= s - d;
350             return;
351         }
352     }
353 }
354
355 STATIC I32
356 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
357 {
358     I32 count = FILTER_READ(idx+1, sv, maxlen);
359     if (count > 0 && !maxlen)
360         strip_return(sv);
361     return count;
362 }
363 #endif
364
365 /*
366  * Perl_lex_start
367  * Initialize variables.  Uses the Perl save_stack to save its state (for
368  * recursive calls to the parser).
369  */
370
371 void
372 Perl_lex_start(pTHX_ SV *line)
373 {
374     char *s;
375     STRLEN len;
376
377     SAVEI32(PL_lex_dojoin);
378     SAVEI32(PL_lex_brackets);
379     SAVEI32(PL_lex_casemods);
380     SAVEI32(PL_lex_starts);
381     SAVEI32(PL_lex_state);
382     SAVEVPTR(PL_lex_inpat);
383     SAVEI32(PL_lex_inwhat);
384     if (PL_lex_state == LEX_KNOWNEXT) {
385         I32 toke = PL_nexttoke;
386         while (--toke >= 0) {
387             SAVEI32(PL_nexttype[toke]);
388             SAVEVPTR(PL_nextval[toke]);
389         }
390         SAVEI32(PL_nexttoke);
391     }
392     SAVECOPLINE(PL_curcop);
393     SAVEPPTR(PL_bufptr);
394     SAVEPPTR(PL_bufend);
395     SAVEPPTR(PL_oldbufptr);
396     SAVEPPTR(PL_oldoldbufptr);
397     SAVEPPTR(PL_last_lop);
398     SAVEPPTR(PL_last_uni);
399     SAVEPPTR(PL_linestart);
400     SAVESPTR(PL_linestr);
401     SAVEPPTR(PL_lex_brackstack);
402     SAVEPPTR(PL_lex_casestack);
403     SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
404     SAVESPTR(PL_lex_stuff);
405     SAVEI32(PL_lex_defer);
406     SAVEI32(PL_sublex_info.sub_inwhat);
407     SAVESPTR(PL_lex_repl);
408     SAVEINT(PL_expect);
409     SAVEINT(PL_lex_expect);
410
411     PL_lex_state = LEX_NORMAL;
412     PL_lex_defer = 0;
413     PL_expect = XSTATE;
414     PL_lex_brackets = 0;
415     New(899, PL_lex_brackstack, 120, char);
416     New(899, PL_lex_casestack, 12, char);
417     SAVEFREEPV(PL_lex_brackstack);
418     SAVEFREEPV(PL_lex_casestack);
419     PL_lex_casemods = 0;
420     *PL_lex_casestack = '\0';
421     PL_lex_dojoin = 0;
422     PL_lex_starts = 0;
423     PL_lex_stuff = Nullsv;
424     PL_lex_repl = Nullsv;
425     PL_lex_inpat = 0;
426     PL_nexttoke = 0;
427     PL_lex_inwhat = 0;
428     PL_sublex_info.sub_inwhat = 0;
429     PL_linestr = line;
430     if (SvREADONLY(PL_linestr))
431         PL_linestr = sv_2mortal(newSVsv(PL_linestr));
432     s = SvPV(PL_linestr, len);
433     if (len && s[len-1] != ';') {
434         if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
435             PL_linestr = sv_2mortal(newSVsv(PL_linestr));
436         sv_catpvn(PL_linestr, "\n;", 2);
437     }
438     SvTEMP_off(PL_linestr);
439     PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
440     PL_bufend = PL_bufptr + SvCUR(PL_linestr);
441     PL_last_lop = PL_last_uni = Nullch;
442     SvREFCNT_dec(PL_rs);
443     PL_rs = newSVpvn("\n", 1);
444     PL_rsfp = 0;
445 }
446
447 /*
448  * Perl_lex_end
449  * Finalizer for lexing operations.  Must be called when the parser is
450  * done with the lexer.
451  */
452
453 void
454 Perl_lex_end(pTHX)
455 {
456     PL_doextract = FALSE;
457 }
458
459 /*
460  * S_incline
461  * This subroutine has nothing to do with tilting, whether at windmills
462  * or pinball tables.  Its name is short for "increment line".  It
463  * increments the current line number in CopLINE(PL_curcop) and checks
464  * to see whether the line starts with a comment of the form
465  *    # line 500 "foo.pm"
466  * If so, it sets the current line number and file to the values in the comment.
467  */
468
469 STATIC void
470 S_incline(pTHX_ char *s)
471 {
472     char *t;
473     char *n;
474     char *e;
475     char ch;
476
477     CopLINE_inc(PL_curcop);
478     if (*s++ != '#')
479         return;
480     while (SPACE_OR_TAB(*s)) s++;
481     if (strnEQ(s, "line", 4))
482         s += 4;
483     else
484         return;
485     if (SPACE_OR_TAB(*s))
486         s++;
487     else
488         return;
489     while (SPACE_OR_TAB(*s)) s++;
490     if (!isDIGIT(*s))
491         return;
492     n = s;
493     while (isDIGIT(*s))
494         s++;
495     while (SPACE_OR_TAB(*s))
496         s++;
497     if (*s == '"' && (t = strchr(s+1, '"'))) {
498         s++;
499         e = t + 1;
500     }
501     else {
502         for (t = s; !isSPACE(*t); t++) ;
503         e = t;
504     }
505     while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
506         e++;
507     if (*e != '\n' && *e != '\0')
508         return;         /* false alarm */
509
510     ch = *t;
511     *t = '\0';
512     if (t - s > 0) {
513 #ifdef USE_ITHREADS
514         Safefree(CopFILE(PL_curcop));
515 #else
516         SvREFCNT_dec(CopFILEGV(PL_curcop));
517 #endif
518         CopFILE_set(PL_curcop, s);
519     }
520     *t = ch;
521     CopLINE_set(PL_curcop, atoi(n)-1);
522 }
523
524 /*
525  * S_skipspace
526  * Called to gobble the appropriate amount and type of whitespace.
527  * Skips comments as well.
528  */
529
530 STATIC char *
531 S_skipspace(pTHX_ register char *s)
532 {
533     if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
534         while (s < PL_bufend && SPACE_OR_TAB(*s))
535             s++;
536         return s;
537     }
538     for (;;) {
539         STRLEN prevlen;
540         SSize_t oldprevlen, oldoldprevlen;
541         SSize_t oldloplen, oldunilen;
542         while (s < PL_bufend && isSPACE(*s)) {
543             if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
544                 incline(s);
545         }
546
547         /* comment */
548         if (s < PL_bufend && *s == '#') {
549             while (s < PL_bufend && *s != '\n')
550                 s++;
551             if (s < PL_bufend) {
552                 s++;
553                 if (PL_in_eval && !PL_rsfp) {
554                     incline(s);
555                     continue;
556                 }
557             }
558         }
559
560         /* only continue to recharge the buffer if we're at the end
561          * of the buffer, we're not reading from a source filter, and
562          * we're in normal lexing mode
563          */
564         if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
565                 PL_lex_state == LEX_FORMLINE)
566             return s;
567
568         /* try to recharge the buffer */
569         if ((s = filter_gets(PL_linestr, PL_rsfp,
570                              (prevlen = SvCUR(PL_linestr)))) == Nullch)
571         {
572             /* end of file.  Add on the -p or -n magic */
573             if (PL_minus_n || PL_minus_p) {
574                 sv_setpv(PL_linestr,PL_minus_p ?
575                          ";}continue{print or die qq(-p destination: $!\\n)" :
576                          "");
577                 sv_catpv(PL_linestr,";}");
578                 PL_minus_n = PL_minus_p = 0;
579             }
580             else
581                 sv_setpv(PL_linestr,";");
582
583             /* reset variables for next time we lex */
584             PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
585                 = SvPVX(PL_linestr);
586             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
587             PL_last_lop = PL_last_uni = Nullch;
588
589             /* Close the filehandle.  Could be from -P preprocessor,
590              * STDIN, or a regular file.  If we were reading code from
591              * STDIN (because the commandline held no -e or filename)
592              * then we don't close it, we reset it so the code can
593              * read from STDIN too.
594              */
595
596             if (PL_preprocess && !PL_in_eval)
597                 (void)PerlProc_pclose(PL_rsfp);
598             else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
599                 PerlIO_clearerr(PL_rsfp);
600             else
601                 (void)PerlIO_close(PL_rsfp);
602             PL_rsfp = Nullfp;
603             return s;
604         }
605
606         /* not at end of file, so we only read another line */
607         /* make corresponding updates to old pointers, for yyerror() */
608         oldprevlen = PL_oldbufptr - PL_bufend;
609         oldoldprevlen = PL_oldoldbufptr - PL_bufend;
610         if (PL_last_uni)
611             oldunilen = PL_last_uni - PL_bufend;
612         if (PL_last_lop)
613             oldloplen = PL_last_lop - PL_bufend;
614         PL_linestart = PL_bufptr = s + prevlen;
615         PL_bufend = s + SvCUR(PL_linestr);
616         s = PL_bufptr;
617         PL_oldbufptr = s + oldprevlen;
618         PL_oldoldbufptr = s + oldoldprevlen;
619         if (PL_last_uni)
620             PL_last_uni = s + oldunilen;
621         if (PL_last_lop)
622             PL_last_lop = s + oldloplen;
623         incline(s);
624
625         /* debugger active and we're not compiling the debugger code,
626          * so store the line into the debugger's array of lines
627          */
628         if (PERLDB_LINE && PL_curstash != PL_debstash) {
629             SV *sv = NEWSV(85,0);
630
631             sv_upgrade(sv, SVt_PVMG);
632             sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
633             av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
634         }
635     }
636 }
637
638 /*
639  * S_check_uni
640  * Check the unary operators to ensure there's no ambiguity in how they're
641  * used.  An ambiguous piece of code would be:
642  *     rand + 5
643  * This doesn't mean rand() + 5.  Because rand() is a unary operator,
644  * the +5 is its argument.
645  */
646
647 STATIC void
648 S_check_uni(pTHX)
649 {
650     char *s;
651     char *t;
652
653     if (PL_oldoldbufptr != PL_last_uni)
654         return;
655     while (isSPACE(*PL_last_uni))
656         PL_last_uni++;
657     for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ;
658     if ((t = strchr(s, '(')) && t < PL_bufptr)
659         return;
660     if (ckWARN_d(WARN_AMBIGUOUS)){
661         char ch = *s;
662         *s = '\0';
663         Perl_warner(aTHX_ WARN_AMBIGUOUS,
664                    "Warning: Use of \"%s\" without parens is ambiguous",
665                    PL_last_uni);
666         *s = ch;
667     }
668 }
669
670 /* workaround to replace the UNI() macro with a function.  Only the
671  * hints/uts.sh file mentions this.  Other comments elsewhere in the
672  * source indicate Microport Unix might need it too.
673  */
674
675 #ifdef CRIPPLED_CC
676
677 #undef UNI
678 #define UNI(f) return uni(f,s)
679
680 STATIC int
681 S_uni(pTHX_ I32 f, char *s)
682 {
683     yylval.ival = f;
684     PL_expect = XTERM;
685     PL_bufptr = s;
686     PL_last_uni = PL_oldbufptr;
687     PL_last_lop_op = f;
688     if (*s == '(')
689         return FUNC1;
690     s = skipspace(s);
691     if (*s == '(')
692         return FUNC1;
693     else
694         return UNIOP;
695 }
696
697 #endif /* CRIPPLED_CC */
698
699 /*
700  * LOP : macro to build a list operator.  Its behaviour has been replaced
701  * with a subroutine, S_lop() for which LOP is just another name.
702  */
703
704 #define LOP(f,x) return lop(f,x,s)
705
706 /*
707  * S_lop
708  * Build a list operator (or something that might be one).  The rules:
709  *  - if we have a next token, then it's a list operator [why?]
710  *  - if the next thing is an opening paren, then it's a function
711  *  - else it's a list operator
712  */
713
714 STATIC I32
715 S_lop(pTHX_ I32 f, int x, char *s)
716 {
717     yylval.ival = f;
718     CLINE;
719     REPORT("lop", f)
720     PL_expect = x;
721     PL_bufptr = s;
722     PL_last_lop = PL_oldbufptr;
723     PL_last_lop_op = f;
724     if (PL_nexttoke)
725         return LSTOP;
726     if (*s == '(')
727         return FUNC;
728     s = skipspace(s);
729     if (*s == '(')
730         return FUNC;
731     else
732         return LSTOP;
733 }
734
735 /*
736  * S_force_next
737  * When the lexer realizes it knows the next token (for instance,
738  * it is reordering tokens for the parser) then it can call S_force_next
739  * to know what token to return the next time the lexer is called.  Caller
740  * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer
741  * handles the token correctly.
742  */
743
744 STATIC void
745 S_force_next(pTHX_ I32 type)
746 {
747     PL_nexttype[PL_nexttoke] = type;
748     PL_nexttoke++;
749     if (PL_lex_state != LEX_KNOWNEXT) {
750         PL_lex_defer = PL_lex_state;
751         PL_lex_expect = PL_expect;
752         PL_lex_state = LEX_KNOWNEXT;
753     }
754 }
755
756 /*
757  * S_force_word
758  * When the lexer knows the next thing is a word (for instance, it has
759  * just seen -> and it knows that the next char is a word char, then
760  * it calls S_force_word to stick the next word into the PL_next lookahead.
761  *
762  * Arguments:
763  *   char *start : buffer position (must be within PL_linestr)
764  *   int token   : PL_next will be this type of bare word (e.g., METHOD,WORD)
765  *   int check_keyword : if true, Perl checks to make sure the word isn't
766  *       a keyword (do this if the word is a label, e.g. goto FOO)
767  *   int allow_pack : if true, : characters will also be allowed (require,
768  *       use, etc. do this)
769  *   int allow_initial_tick : used by the "sub" lexer only.
770  */
771
772 STATIC char *
773 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
774 {
775     register char *s;
776     STRLEN len;
777
778     start = skipspace(start);
779     s = start;
780     if (isIDFIRST_lazy_if(s,UTF) ||
781         (allow_pack && *s == ':') ||
782         (allow_initial_tick && *s == '\'') )
783     {
784         s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
785         if (check_keyword && keyword(PL_tokenbuf, len))
786             return start;
787         if (token == METHOD) {
788             s = skipspace(s);
789             if (*s == '(')
790                 PL_expect = XTERM;
791             else {
792                 PL_expect = XOPERATOR;
793             }
794         }
795         PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST,0, newSVpv(PL_tokenbuf,0));
796         PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE;
797         force_next(token);
798     }
799     return s;
800 }
801
802 /*
803  * S_force_ident
804  * Called when the lexer wants $foo *foo &foo etc, but the program
805  * text only contains the "foo" portion.  The first argument is a pointer
806  * to the "foo", and the second argument is the type symbol to prefix.
807  * Forces the next token to be a "WORD".
808  * Creates the symbol if it didn't already exist (via gv_fetchpv()).
809  */
810
811 STATIC void
812 S_force_ident(pTHX_ register char *s, int kind)
813 {
814     if (s && *s) {
815         OP* o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
816         PL_nextval[PL_nexttoke].opval = o;
817         force_next(WORD);
818         if (kind) {
819             o->op_private = OPpCONST_ENTERED;
820             /* XXX see note in pp_entereval() for why we forgo typo
821                warnings if the symbol must be introduced in an eval.
822                GSAR 96-10-12 */
823             gv_fetchpv(s, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
824                 kind == '$' ? SVt_PV :
825                 kind == '@' ? SVt_PVAV :
826                 kind == '%' ? SVt_PVHV :
827                               SVt_PVGV
828                 );
829         }
830     }
831 }
832
833 NV
834 Perl_str_to_version(pTHX_ SV *sv)
835 {
836     NV retval = 0.0;
837     NV nshift = 1.0;
838     STRLEN len;
839     char *start = SvPVx(sv,len);
840     bool utf = SvUTF8(sv) ? TRUE : FALSE;
841     char *end = start + len;
842     while (start < end) {
843         STRLEN skip;
844         UV n;
845         if (utf)
846             n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
847         else {
848             n = *(U8*)start;
849             skip = 1;
850         }
851         retval += ((NV)n)/nshift;
852         start += skip;
853         nshift *= 1000;
854     }
855     return retval;
856 }
857
858 /*
859  * S_force_version
860  * Forces the next token to be a version number.
861  */
862
863 STATIC char *
864 S_force_version(pTHX_ char *s)
865 {
866     OP *version = Nullop;
867     char *d;
868
869     s = skipspace(s);
870
871     d = s;
872     if (*d == 'v')
873         d++;
874     if (isDIGIT(*d)) {
875         for (; isDIGIT(*d) || *d == '_' || *d == '.'; d++);
876         if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
877             SV *ver;
878             s = scan_num(s, &yylval);
879             version = yylval.opval;
880             ver = cSVOPx(version)->op_sv;
881             if (SvPOK(ver) && !SvNIOK(ver)) {
882                 (void)SvUPGRADE(ver, SVt_PVNV);
883                 SvNVX(ver) = str_to_version(ver);
884                 SvNOK_on(ver);          /* hint that it is a version */
885             }
886         }
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_oldbufptr);
1047     SAVEPPTR(PL_oldoldbufptr);
1048     SAVEPPTR(PL_last_lop);
1049     SAVEPPTR(PL_last_uni);
1050     SAVEPPTR(PL_linestart);
1051     SAVESPTR(PL_linestr);
1052     SAVEPPTR(PL_lex_brackstack);
1053     SAVEPPTR(PL_lex_casestack);
1054
1055     PL_linestr = PL_lex_stuff;
1056     PL_lex_stuff = Nullsv;
1057
1058     PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1059         = SvPVX(PL_linestr);
1060     PL_bufend += SvCUR(PL_linestr);
1061     PL_last_lop = PL_last_uni = Nullch;
1062     SAVEFREESV(PL_linestr);
1063
1064     PL_lex_dojoin = FALSE;
1065     PL_lex_brackets = 0;
1066     New(899, PL_lex_brackstack, 120, char);
1067     New(899, PL_lex_casestack, 12, char);
1068     SAVEFREEPV(PL_lex_brackstack);
1069     SAVEFREEPV(PL_lex_casestack);
1070     PL_lex_casemods = 0;
1071     *PL_lex_casestack = '\0';
1072     PL_lex_starts = 0;
1073     PL_lex_state = LEX_INTERPCONCAT;
1074     CopLINE_set(PL_curcop, PL_multi_start);
1075
1076     PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1077     if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1078         PL_lex_inpat = PL_sublex_info.sub_op;
1079     else
1080         PL_lex_inpat = Nullop;
1081
1082     return '(';
1083 }
1084
1085 /*
1086  * S_sublex_done
1087  * Restores lexer state after a S_sublex_push.
1088  */
1089
1090 STATIC I32
1091 S_sublex_done(pTHX)
1092 {
1093     if (!PL_lex_starts++) {
1094         SV *sv = newSVpvn("",0);
1095         if (SvUTF8(PL_linestr))
1096             SvUTF8_on(sv);
1097         PL_expect = XOPERATOR;
1098         yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1099         return THING;
1100     }
1101
1102     if (PL_lex_casemods) {              /* oops, we've got some unbalanced parens */
1103         PL_lex_state = LEX_INTERPCASEMOD;
1104         return yylex();
1105     }
1106
1107     /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1108     if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1109         PL_linestr = PL_lex_repl;
1110         PL_lex_inpat = 0;
1111         PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1112         PL_bufend += SvCUR(PL_linestr);
1113         PL_last_lop = PL_last_uni = Nullch;
1114         SAVEFREESV(PL_linestr);
1115         PL_lex_dojoin = FALSE;
1116         PL_lex_brackets = 0;
1117         PL_lex_casemods = 0;
1118         *PL_lex_casestack = '\0';
1119         PL_lex_starts = 0;
1120         if (SvEVALED(PL_lex_repl)) {
1121             PL_lex_state = LEX_INTERPNORMAL;
1122             PL_lex_starts++;
1123             /*  we don't clear PL_lex_repl here, so that we can check later
1124                 whether this is an evalled subst; that means we rely on the
1125                 logic to ensure sublex_done() is called again only via the
1126                 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1127         }
1128         else {
1129             PL_lex_state = LEX_INTERPCONCAT;
1130             PL_lex_repl = Nullsv;
1131         }
1132         return ',';
1133     }
1134     else {
1135         LEAVE;
1136         PL_bufend = SvPVX(PL_linestr);
1137         PL_bufend += SvCUR(PL_linestr);
1138         PL_expect = XOPERATOR;
1139         PL_sublex_info.sub_inwhat = 0;
1140         return ')';
1141     }
1142 }
1143
1144 /*
1145   scan_const
1146
1147   Extracts a pattern, double-quoted string, or transliteration.  This
1148   is terrifying code.
1149
1150   It looks at lex_inwhat and PL_lex_inpat to find out whether it's
1151   processing a pattern (PL_lex_inpat is true), a transliteration
1152   (lex_inwhat & OP_TRANS is true), or a double-quoted string.
1153
1154   Returns a pointer to the character scanned up to. Iff this is
1155   advanced from the start pointer supplied (ie if anything was
1156   successfully parsed), will leave an OP for the substring scanned
1157   in yylval. Caller must intuit reason for not parsing further
1158   by looking at the next characters herself.
1159
1160   In patterns:
1161     backslashes:
1162       double-quoted style: \r and \n
1163       regexp special ones: \D \s
1164       constants: \x3
1165       backrefs: \1 (deprecated in substitution replacements)
1166       case and quoting: \U \Q \E
1167     stops on @ and $, but not for $ as tail anchor
1168
1169   In transliterations:
1170     characters are VERY literal, except for - not at the start or end
1171     of the string, which indicates a range.  scan_const expands the
1172     range to the full set of intermediate characters.
1173
1174   In double-quoted strings:
1175     backslashes:
1176       double-quoted style: \r and \n
1177       constants: \x3
1178       backrefs: \1 (deprecated)
1179       case and quoting: \U \Q \E
1180     stops on @ and $
1181
1182   scan_const does *not* construct ops to handle interpolated strings.
1183   It stops processing as soon as it finds an embedded $ or @ variable
1184   and leaves it to the caller to work out what's going on.
1185
1186   @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @:foo.
1187
1188   $ in pattern could be $foo or could be tail anchor.  Assumption:
1189   it's a tail anchor if $ is the last thing in the string, or if it's
1190   followed by one of ")| \n\t"
1191
1192   \1 (backreferences) are turned into $1
1193
1194   The structure of the code is
1195       while (there's a character to process) {
1196           handle transliteration ranges
1197           skip regexp comments
1198           skip # initiated comments in //x patterns
1199           check for embedded @foo
1200           check for embedded scalars
1201           if (backslash) {
1202               leave intact backslashes from leave (below)
1203               deprecate \1 in strings and sub replacements
1204               handle string-changing backslashes \l \U \Q \E, etc.
1205               switch (what was escaped) {
1206                   handle - in a transliteration (becomes a literal -)
1207                   handle \132 octal characters
1208                   handle 0x15 hex characters
1209                   handle \cV (control V)
1210                   handle printf backslashes (\f, \r, \n, etc)
1211               } (end switch)
1212           } (end if backslash)
1213     } (end while character to read)
1214                 
1215 */
1216
1217 STATIC char *
1218 S_scan_const(pTHX_ char *start)
1219 {
1220     register char *send = PL_bufend;            /* end of the constant */
1221     SV *sv = NEWSV(93, send - start);           /* sv for the constant */
1222     register char *s = start;                   /* start of the constant */
1223     register char *d = SvPVX(sv);               /* destination for copies */
1224     bool dorange = FALSE;                       /* are we in a translit range? */
1225     bool didrange = FALSE;                      /* did we just finish a range? */
1226     I32  has_utf8 = FALSE;                      /* Output constant is UTF8 */
1227     I32  this_utf8 = UTF;                       /* The source string is assumed to be UTF8 */
1228     UV uv;
1229
1230     const char *leaveit =       /* set of acceptably-backslashed characters */
1231         PL_lex_inpat
1232             ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxcz0123456789[{]} \t\n\r\f\v#"
1233             : "";
1234
1235     if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1236         /* If we are doing a trans and we know we want UTF8 set expectation */
1237         has_utf8   = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1238         this_utf8  = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1239     }
1240
1241
1242     while (s < send || dorange) {
1243         /* get transliterations out of the way (they're most literal) */
1244         if (PL_lex_inwhat == OP_TRANS) {
1245             /* expand a range A-Z to the full set of characters.  AIE! */
1246             if (dorange) {
1247                 I32 i;                          /* current expanded character */
1248                 I32 min;                        /* first character in range */
1249                 I32 max;                        /* last character in range */
1250
1251                 if (has_utf8) {
1252                     char *c = (char*)utf8_hop((U8*)d, -1);
1253                     char *e = d++;
1254                     while (e-- > c)
1255                         *(e + 1) = *e;
1256                     *c = UTF_TO_NATIVE(0xff);
1257                     /* mark the range as done, and continue */
1258                     dorange = FALSE;
1259                     didrange = TRUE;
1260                     continue;
1261                 }
1262
1263                 i = d - SvPVX(sv);              /* remember current offset */
1264                 SvGROW(sv, SvLEN(sv) + 256);    /* never more than 256 chars in a range */
1265                 d = SvPVX(sv) + i;              /* refresh d after realloc */
1266                 d -= 2;                         /* eat the first char and the - */
1267
1268                 min = (U8)*d;                   /* first char in range */
1269                 max = (U8)d[1];                 /* last char in range  */
1270
1271                 if (min > max) {
1272                     Perl_croak(aTHX_
1273                                "Invalid [] range \"%c-%c\" in transliteration operator",
1274                                (char)min, (char)max);
1275                 }
1276
1277 #ifdef EBCDIC
1278                 if ((isLOWER(min) && isLOWER(max)) ||
1279                     (isUPPER(min) && isUPPER(max))) {
1280                     if (isLOWER(min)) {
1281                         for (i = min; i <= max; i++)
1282                             if (isLOWER(i))
1283                                 *d++ = NATIVE_TO_NEED(has_utf8,i);
1284                     } else {
1285                         for (i = min; i <= max; i++)
1286                             if (isUPPER(i))
1287                                 *d++ = NATIVE_TO_NEED(has_utf8,i);
1288                     }
1289                 }
1290                 else
1291 #endif
1292                     for (i = min; i <= max; i++)
1293                         *d++ = i;
1294
1295                 /* mark the range as done, and continue */
1296                 dorange = FALSE;
1297                 didrange = TRUE;
1298                 continue;
1299             }
1300
1301             /* range begins (ignore - as first or last char) */
1302             else if (*s == '-' && s+1 < send  && s != start) {
1303                 if (didrange) {
1304                     Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1305                 }
1306                 if (has_utf8) {
1307                     *d++ = UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
1308                     s++;
1309                     continue;
1310                 }
1311                 dorange = TRUE;
1312                 s++;
1313             }
1314             else {
1315                 didrange = FALSE;
1316             }
1317         }
1318
1319         /* if we get here, we're not doing a transliteration */
1320
1321         /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1322            except for the last char, which will be done separately. */
1323         else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1324             if (s[2] == '#') {
1325                 while (s < send && *s != ')')
1326                     *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1327             }
1328             else if (s[2] == '{' /* This should match regcomp.c */
1329                      || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1330             {
1331                 I32 count = 1;
1332                 char *regparse = s + (s[2] == '{' ? 3 : 4);
1333                 char c;
1334
1335                 while (count && (c = *regparse)) {
1336                     if (c == '\\' && regparse[1])
1337                         regparse++;
1338                     else if (c == '{')
1339                         count++;
1340                     else if (c == '}')
1341                         count--;
1342                     regparse++;
1343                 }
1344                 if (*regparse != ')') {
1345                     regparse--;         /* Leave one char for continuation. */
1346                     yyerror("Sequence (?{...}) not terminated or not {}-balanced");
1347                 }
1348                 while (s < regparse)
1349                     *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1350             }
1351         }
1352
1353         /* likewise skip #-initiated comments in //x patterns */
1354         else if (*s == '#' && PL_lex_inpat &&
1355           ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1356             while (s+1 < send && *s != '\n')
1357                 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1358         }
1359
1360         /* check for embedded arrays
1361            (@foo, @:foo, @'foo, @{foo}, @$foo, @+, @-)
1362            */
1363         else if (*s == '@' && s[1]
1364                  && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1])))
1365             break;
1366
1367         /* check for embedded scalars.  only stop if we're sure it's a
1368            variable.
1369         */
1370         else if (*s == '$') {
1371             if (!PL_lex_inpat)  /* not a regexp, so $ must be var */
1372                 break;
1373             if (s + 1 < send && !strchr("()| \n\t", s[1]))
1374                 break;          /* in regexp, $ might be tail anchor */
1375         }
1376
1377         /* End of else if chain - OP_TRANS rejoin rest */
1378
1379         /* backslashes */
1380         if (*s == '\\' && s+1 < send) {
1381             s++;
1382
1383             /* some backslashes we leave behind */
1384             if (*leaveit && *s && strchr(leaveit, *s)) {
1385                 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
1386                 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1387                 continue;
1388             }
1389
1390             /* deprecate \1 in strings and substitution replacements */
1391             if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
1392                 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
1393             {
1394                 if (ckWARN(WARN_SYNTAX))
1395                     Perl_warner(aTHX_ WARN_SYNTAX, "\\%c better written as $%c", *s, *s);
1396                 *--s = '$';
1397                 break;
1398             }
1399
1400             /* string-change backslash escapes */
1401             if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
1402                 --s;
1403                 break;
1404             }
1405
1406             /* if we get here, it's either a quoted -, or a digit */
1407             switch (*s) {
1408
1409             /* quoted - in transliterations */
1410             case '-':
1411                 if (PL_lex_inwhat == OP_TRANS) {
1412                     *d++ = *s++;
1413                     continue;
1414                 }
1415                 /* FALL THROUGH */
1416             default:
1417                 {
1418                     if (ckWARN(WARN_MISC) && isALNUM(*s))
1419                         Perl_warner(aTHX_ WARN_MISC,
1420                                "Unrecognized escape \\%c passed through",
1421                                *s);
1422                     /* default action is to copy the quoted character */
1423                     goto default_action;
1424                 }
1425
1426             /* \132 indicates an octal constant */
1427             case '0': case '1': case '2': case '3':
1428             case '4': case '5': case '6': case '7':
1429                 {
1430                     STRLEN len = 0;     /* disallow underscores */
1431                     uv = (UV)scan_oct(s, 3, &len);
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                     if (!e) {
1442                         yyerror("Missing right brace on \\x{}");
1443                         e = s;
1444                     }
1445                     else {
1446                         STRLEN len = 1;         /* allow underscores */
1447                         uv = (UV)scan_hex(s + 1, e - s - 1, &len);
1448                     }
1449                     s = e + 1;
1450                 }
1451                 else {
1452                     {
1453                         STRLEN len = 0;         /* disallow underscores */
1454                         uv = (UV)scan_hex(s, 2, &len);
1455                         s += len;
1456                     }
1457                 }
1458
1459               NUM_ESCAPE_INSERT:
1460                 /* Insert oct or hex escaped character.
1461                  * There will always enough room in sv since such
1462                  * escapes will be longer than any UTF-8 sequence
1463                  * they can end up as. */
1464                 
1465                 /* We need to map to chars to ASCII before doing the tests
1466                    to cover EBCDIC
1467                 */
1468                 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
1469                     if (!has_utf8 && uv > 255) {
1470                         /* Might need to recode whatever we have
1471                          * accumulated so far if it contains any
1472                          * hibit chars.
1473                          *
1474                          * (Can't we keep track of that and avoid
1475                          *  this rescan? --jhi)
1476                          */
1477                         int hicount = 0;
1478                         U8 *c;
1479                         for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
1480                             if (!NATIVE_IS_INVARIANT(*c)) {
1481                                 hicount++;
1482                             }
1483                         }
1484                         if (hicount) {
1485                             STRLEN offset = d - SvPVX(sv);
1486                             U8 *src, *dst;
1487                             d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
1488                             src = (U8 *)d - 1;
1489                             dst = src+hicount;
1490                             d  += hicount;
1491                             while (src >= (U8 *)SvPVX(sv)) {
1492                                 if (!NATIVE_IS_INVARIANT(*src)) {
1493                                     U8 ch = NATIVE_TO_ASCII(*src);
1494                                     *dst-- = UTF8_EIGHT_BIT_LO(ch);
1495                                     *dst-- = UTF8_EIGHT_BIT_HI(ch);
1496                                 }
1497                                 else {
1498                                     *dst-- = *src;
1499                                 }
1500                                 src--;
1501                             }
1502                         }
1503                     }
1504
1505                     if (has_utf8 || uv > 255) {
1506                         d = (char*)uvchr_to_utf8((U8*)d, uv);
1507                         has_utf8 = TRUE;
1508                         if (PL_lex_inwhat == OP_TRANS &&
1509                             PL_sublex_info.sub_op) {
1510                             PL_sublex_info.sub_op->op_private |=
1511                                 (PL_lex_repl ? OPpTRANS_FROM_UTF
1512                                              : OPpTRANS_TO_UTF);
1513                         }
1514                     }
1515                     else {
1516                         *d++ = (char)uv;
1517                     }
1518                 }
1519                 else {
1520                     *d++ = (char) uv;
1521                 }
1522                 continue;
1523
1524             /* \N{latin small letter a} is a named character */
1525             case 'N':
1526                 ++s;
1527                 if (*s == '{') {
1528                     char* e = strchr(s, '}');
1529                     SV *res;
1530                     STRLEN len;
1531                     char *str;
1532
1533                     if (!e) {
1534                         yyerror("Missing right brace on \\N{}");
1535                         e = s - 1;
1536                         goto cont_scan;
1537                     }
1538                     res = newSVpvn(s + 1, e - s - 1);
1539                     res = new_constant( Nullch, 0, "charnames",
1540                                         res, Nullsv, "\\N{...}" );
1541                     if (has_utf8)
1542                         sv_utf8_upgrade(res);
1543                     str = SvPV(res,len);
1544                     if (!has_utf8 && SvUTF8(res)) {
1545                         char *ostart = SvPVX(sv);
1546                         SvCUR_set(sv, d - ostart);
1547                         SvPOK_on(sv);
1548                         *d = '\0';
1549                         sv_utf8_upgrade(sv);
1550                         /* this just broke our allocation above... */
1551                         SvGROW(sv, send - start);
1552                         d = SvPVX(sv) + SvCUR(sv);
1553                         has_utf8 = TRUE;
1554                     }
1555                     if (len > e - s + 4) {
1556                         char *odest = SvPVX(sv);
1557
1558                         SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
1559                         d = SvPVX(sv) + (d - odest);
1560                     }
1561                     Copy(str, d, len, char);
1562                     d += len;
1563                     SvREFCNT_dec(res);
1564                   cont_scan:
1565                     s = e + 1;
1566                 }
1567                 else
1568                     yyerror("Missing braces on \\N{}");
1569                 continue;
1570
1571             /* \c is a control character */
1572             case 'c':
1573                 s++;
1574                 {
1575                     U8 c = *s++;
1576 #ifdef EBCDIC
1577                     if (isLOWER(c))
1578                         c = toUPPER(c);
1579 #endif
1580                     *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
1581                 }
1582                 continue;
1583
1584             /* printf-style backslashes, formfeeds, newlines, etc */
1585             case 'b':
1586                 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
1587                 break;
1588             case 'n':
1589                 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
1590                 break;
1591             case 'r':
1592                 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
1593                 break;
1594             case 'f':
1595                 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
1596                 break;
1597             case 't':
1598                 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
1599                 break;
1600             case 'e':
1601                 *d++ = ASCII_TO_NEED(has_utf8,'\033');
1602                 break;
1603             case 'a':
1604                 *d++ = ASCII_TO_NEED(has_utf8,'\007');
1605                 break;
1606             } /* end switch */
1607
1608             s++;
1609             continue;
1610         } /* end if (backslash) */
1611
1612     default_action:
1613         /* If we started with encoded form, or already know we want it
1614            and then encode the next character */
1615         if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
1616             STRLEN len  = 1;
1617             UV uv       = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
1618             STRLEN need = UNISKIP(NATIVE_TO_UNI(uv));
1619             s += len;
1620             if (need > len) {
1621                 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
1622                 STRLEN off = d - SvPVX(sv);
1623                 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
1624             }
1625             d = (char*)uvchr_to_utf8((U8*)d, uv);
1626             has_utf8 = TRUE;
1627         }
1628         else {
1629             *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1630         }
1631     } /* while loop to process each character */
1632
1633     /* terminate the string and set up the sv */
1634     *d = '\0';
1635     SvCUR_set(sv, d - SvPVX(sv));
1636     if (SvCUR(sv) >= SvLEN(sv))
1637       Perl_croak(aTHX_ "panic:constant overflowed allocated space");
1638
1639     SvPOK_on(sv);
1640     if (has_utf8) {
1641         SvUTF8_on(sv);
1642         if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1643                 PL_sublex_info.sub_op->op_private |=
1644                     (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1645         }
1646     }
1647
1648     /* shrink the sv if we allocated more than we used */
1649     if (SvCUR(sv) + 5 < SvLEN(sv)) {
1650         SvLEN_set(sv, SvCUR(sv) + 1);
1651         Renew(SvPVX(sv), SvLEN(sv), char);
1652     }
1653
1654     /* return the substring (via yylval) only if we parsed anything */
1655     if (s > PL_bufptr) {
1656         if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
1657             sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"),
1658                               sv, Nullsv,
1659                               ( PL_lex_inwhat == OP_TRANS
1660                                 ? "tr"
1661                                 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
1662                                     ? "s"
1663                                     : "qq")));
1664         yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1665     } else
1666         SvREFCNT_dec(sv);
1667     return s;
1668 }
1669
1670 /* S_intuit_more
1671  * Returns TRUE if there's more to the expression (e.g., a subscript),
1672  * FALSE otherwise.
1673  *
1674  * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
1675  *
1676  * ->[ and ->{ return TRUE
1677  * { and [ outside a pattern are always subscripts, so return TRUE
1678  * if we're outside a pattern and it's not { or [, then return FALSE
1679  * if we're in a pattern and the first char is a {
1680  *   {4,5} (any digits around the comma) returns FALSE
1681  * if we're in a pattern and the first char is a [
1682  *   [] returns FALSE
1683  *   [SOMETHING] has a funky algorithm to decide whether it's a
1684  *      character class or not.  It has to deal with things like
1685  *      /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
1686  * anything else returns TRUE
1687  */
1688
1689 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
1690
1691 STATIC int
1692 S_intuit_more(pTHX_ register char *s)
1693 {
1694     if (PL_lex_brackets)
1695         return TRUE;
1696     if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
1697         return TRUE;
1698     if (*s != '{' && *s != '[')
1699         return FALSE;
1700     if (!PL_lex_inpat)
1701         return TRUE;
1702
1703     /* In a pattern, so maybe we have {n,m}. */
1704     if (*s == '{') {
1705         s++;
1706         if (!isDIGIT(*s))
1707             return TRUE;
1708         while (isDIGIT(*s))
1709             s++;
1710         if (*s == ',')
1711             s++;
1712         while (isDIGIT(*s))
1713             s++;
1714         if (*s == '}')
1715             return FALSE;
1716         return TRUE;
1717         
1718     }
1719
1720     /* On the other hand, maybe we have a character class */
1721
1722     s++;
1723     if (*s == ']' || *s == '^')
1724         return FALSE;
1725     else {
1726         /* this is terrifying, and it works */
1727         int weight = 2;         /* let's weigh the evidence */
1728         char seen[256];
1729         unsigned char un_char = 255, last_un_char;
1730         char *send = strchr(s,']');
1731         char tmpbuf[sizeof PL_tokenbuf * 4];
1732
1733         if (!send)              /* has to be an expression */
1734             return TRUE;
1735
1736         Zero(seen,256,char);
1737         if (*s == '$')
1738             weight -= 3;
1739         else if (isDIGIT(*s)) {
1740             if (s[1] != ']') {
1741                 if (isDIGIT(s[1]) && s[2] == ']')
1742                     weight -= 10;
1743             }
1744             else
1745                 weight -= 100;
1746         }
1747         for (; s < send; s++) {
1748             last_un_char = un_char;
1749             un_char = (unsigned char)*s;
1750             switch (*s) {
1751             case '@':
1752             case '&':
1753             case '$':
1754                 weight -= seen[un_char] * 10;
1755                 if (isALNUM_lazy_if(s+1,UTF)) {
1756                     scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
1757                     if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV))
1758                         weight -= 100;
1759                     else
1760                         weight -= 10;
1761                 }
1762                 else if (*s == '$' && s[1] &&
1763                   strchr("[#!%*<>()-=",s[1])) {
1764                     if (/*{*/ strchr("])} =",s[2]))
1765                         weight -= 10;
1766                     else
1767                         weight -= 1;
1768                 }
1769                 break;
1770             case '\\':
1771                 un_char = 254;
1772                 if (s[1]) {
1773                     if (strchr("wds]",s[1]))
1774                         weight += 100;
1775                     else if (seen['\''] || seen['"'])
1776                         weight += 1;
1777                     else if (strchr("rnftbxcav",s[1]))
1778                         weight += 40;
1779                     else if (isDIGIT(s[1])) {
1780                         weight += 40;
1781                         while (s[1] && isDIGIT(s[1]))
1782                             s++;
1783                     }
1784                 }
1785                 else
1786                     weight += 100;
1787                 break;
1788             case '-':
1789                 if (s[1] == '\\')
1790                     weight += 50;
1791                 if (strchr("aA01! ",last_un_char))
1792                     weight += 30;
1793                 if (strchr("zZ79~",s[1]))
1794                     weight += 30;
1795                 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
1796                     weight -= 5;        /* cope with negative subscript */
1797                 break;
1798             default:
1799                 if (!isALNUM(last_un_char) && !strchr("$@&",last_un_char) &&
1800                         isALPHA(*s) && s[1] && isALPHA(s[1])) {
1801                     char *d = tmpbuf;
1802                     while (isALPHA(*s))
1803                         *d++ = *s++;
1804                     *d = '\0';
1805                     if (keyword(tmpbuf, d - tmpbuf))
1806                         weight -= 150;
1807                 }
1808                 if (un_char == last_un_char + 1)
1809                     weight += 5;
1810                 weight -= seen[un_char];
1811                 break;
1812             }
1813             seen[un_char]++;
1814         }
1815         if (weight >= 0)        /* probably a character class */
1816             return FALSE;
1817     }
1818
1819     return TRUE;
1820 }
1821
1822 /*
1823  * S_intuit_method
1824  *
1825  * Does all the checking to disambiguate
1826  *   foo bar
1827  * between foo(bar) and bar->foo.  Returns 0 if not a method, otherwise
1828  * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
1829  *
1830  * First argument is the stuff after the first token, e.g. "bar".
1831  *
1832  * Not a method if bar is a filehandle.
1833  * Not a method if foo is a subroutine prototyped to take a filehandle.
1834  * Not a method if it's really "Foo $bar"
1835  * Method if it's "foo $bar"
1836  * Not a method if it's really "print foo $bar"
1837  * Method if it's really "foo package::" (interpreted as package->foo)
1838  * Not a method if bar is known to be a subroutne ("sub bar; foo bar")
1839  * Not a method if bar is a filehandle or package, but is quoted with
1840  *   =>
1841  */
1842
1843 STATIC int
1844 S_intuit_method(pTHX_ char *start, GV *gv)
1845 {
1846     char *s = start + (*start == '$');
1847     char tmpbuf[sizeof PL_tokenbuf];
1848     STRLEN len;
1849     GV* indirgv;
1850
1851     if (gv) {
1852         CV *cv;
1853         if (GvIO(gv))
1854             return 0;
1855         if ((cv = GvCVu(gv))) {
1856             char *proto = SvPVX(cv);
1857             if (proto) {
1858                 if (*proto == ';')
1859                     proto++;
1860                 if (*proto == '*')
1861                     return 0;
1862             }
1863         } else
1864             gv = 0;
1865     }
1866     s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
1867     /* start is the beginning of the possible filehandle/object,
1868      * and s is the end of it
1869      * tmpbuf is a copy of it
1870      */
1871
1872     if (*start == '$') {
1873         if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
1874             return 0;
1875         s = skipspace(s);
1876         PL_bufptr = start;
1877         PL_expect = XREF;
1878         return *s == '(' ? FUNCMETH : METHOD;
1879     }
1880     if (!keyword(tmpbuf, len)) {
1881         if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
1882             len -= 2;
1883             tmpbuf[len] = '\0';
1884             goto bare_package;
1885         }
1886         indirgv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
1887         if (indirgv && GvCVu(indirgv))
1888             return 0;
1889         /* filehandle or package name makes it a method */
1890         if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
1891             s = skipspace(s);
1892             if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
1893                 return 0;       /* no assumptions -- "=>" quotes bearword */
1894       bare_package:
1895             PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0,
1896                                                    newSVpvn(tmpbuf,len));
1897             PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE;
1898             PL_expect = XTERM;
1899             force_next(WORD);
1900             PL_bufptr = s;
1901             return *s == '(' ? FUNCMETH : METHOD;
1902         }
1903     }
1904     return 0;
1905 }
1906
1907 /*
1908  * S_incl_perldb
1909  * Return a string of Perl code to load the debugger.  If PERL5DB
1910  * is set, it will return the contents of that, otherwise a
1911  * compile-time require of perl5db.pl.
1912  */
1913
1914 STATIC char*
1915 S_incl_perldb(pTHX)
1916 {
1917     if (PL_perldb) {
1918         char *pdb = PerlEnv_getenv("PERL5DB");
1919
1920         if (pdb)
1921             return pdb;
1922         SETERRNO(0,SS$_NORMAL);
1923         return "BEGIN { require 'perl5db.pl' }";
1924     }
1925     return "";
1926 }
1927
1928
1929 /* Encoded script support. filter_add() effectively inserts a
1930  * 'pre-processing' function into the current source input stream.
1931  * Note that the filter function only applies to the current source file
1932  * (e.g., it will not affect files 'require'd or 'use'd by this one).
1933  *
1934  * The datasv parameter (which may be NULL) can be used to pass
1935  * private data to this instance of the filter. The filter function
1936  * can recover the SV using the FILTER_DATA macro and use it to
1937  * store private buffers and state information.
1938  *
1939  * The supplied datasv parameter is upgraded to a PVIO type
1940  * and the IoDIRP/IoANY field is used to store the function pointer,
1941  * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
1942  * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
1943  * private use must be set using malloc'd pointers.
1944  */
1945
1946 SV *
1947 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
1948 {
1949     if (!funcp)
1950         return Nullsv;
1951
1952     if (!PL_rsfp_filters)
1953         PL_rsfp_filters = newAV();
1954     if (!datasv)
1955         datasv = NEWSV(255,0);
1956     if (!SvUPGRADE(datasv, SVt_PVIO))
1957         Perl_die(aTHX_ "Can't upgrade filter_add data to SVt_PVIO");
1958     IoANY(datasv) = (void *)funcp; /* stash funcp into spare field */
1959     IoFLAGS(datasv) |= IOf_FAKE_DIRP;
1960     DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
1961                           funcp, SvPV_nolen(datasv)));
1962     av_unshift(PL_rsfp_filters, 1);
1963     av_store(PL_rsfp_filters, 0, datasv) ;
1964     return(datasv);
1965 }
1966
1967
1968 /* Delete most recently added instance of this filter function. */
1969 void
1970 Perl_filter_del(pTHX_ filter_t funcp)
1971 {
1972     SV *datasv;
1973     DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", funcp));
1974     if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
1975         return;
1976     /* if filter is on top of stack (usual case) just pop it off */
1977     datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
1978     if (IoANY(datasv) == (void *)funcp) {
1979         IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
1980         IoANY(datasv) = (void *)NULL;
1981         sv_free(av_pop(PL_rsfp_filters));
1982
1983         return;
1984     }
1985     /* we need to search for the correct entry and clear it     */
1986     Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
1987 }
1988
1989
1990 /* Invoke the n'th filter function for the current rsfp.         */
1991 I32
1992 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
1993
1994
1995                         /* 0 = read one text line */
1996 {
1997     filter_t funcp;
1998     SV *datasv = NULL;
1999
2000     if (!PL_rsfp_filters)
2001         return -1;
2002     if (idx > AvFILLp(PL_rsfp_filters)){       /* Any more filters?     */
2003         /* Provide a default input filter to make life easy.    */
2004         /* Note that we append to the line. This is handy.      */
2005         DEBUG_P(PerlIO_printf(Perl_debug_log,
2006                               "filter_read %d: from rsfp\n", idx));
2007         if (maxlen) {
2008             /* Want a block */
2009             int len ;
2010             int old_len = SvCUR(buf_sv) ;
2011
2012             /* ensure buf_sv is large enough */
2013             SvGROW(buf_sv, old_len + maxlen) ;
2014             if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
2015                 if (PerlIO_error(PL_rsfp))
2016                     return -1;          /* error */
2017                 else
2018                     return 0 ;          /* end of file */
2019             }
2020             SvCUR_set(buf_sv, old_len + len) ;
2021         } else {
2022             /* Want a line */
2023             if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2024                 if (PerlIO_error(PL_rsfp))
2025                     return -1;          /* error */
2026                 else
2027                     return 0 ;          /* end of file */
2028             }
2029         }
2030         return SvCUR(buf_sv);
2031     }
2032     /* Skip this filter slot if filter has been deleted */
2033     if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef){
2034         DEBUG_P(PerlIO_printf(Perl_debug_log,
2035                               "filter_read %d: skipped (filter deleted)\n",
2036                               idx));
2037         return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
2038     }
2039     /* Get function pointer hidden within datasv        */
2040     funcp = (filter_t)IoANY(datasv);
2041     DEBUG_P(PerlIO_printf(Perl_debug_log,
2042                           "filter_read %d: via function %p (%s)\n",
2043                           idx, funcp, SvPV_nolen(datasv)));
2044     /* Call function. The function is expected to       */
2045     /* call "FILTER_READ(idx+1, buf_sv)" first.         */
2046     /* Return: <0:error, =0:eof, >0:not eof             */
2047     return (*funcp)(aTHXo_ idx, buf_sv, maxlen);
2048 }
2049
2050 STATIC char *
2051 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2052 {
2053 #ifdef PERL_CR_FILTER
2054     if (!PL_rsfp_filters) {
2055         filter_add(S_cr_textfilter,NULL);
2056     }
2057 #endif
2058     if (PL_rsfp_filters) {
2059
2060         if (!append)
2061             SvCUR_set(sv, 0);   /* start with empty line        */
2062         if (FILTER_READ(0, sv, 0) > 0)
2063             return ( SvPVX(sv) ) ;
2064         else
2065             return Nullch ;
2066     }
2067     else
2068         return (sv_gets(sv, fp, append));
2069 }
2070
2071 STATIC HV *
2072 S_find_in_my_stash(pTHX_ char *pkgname, I32 len)
2073 {
2074     GV *gv;
2075
2076     if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2077         return PL_curstash;
2078
2079     if (len > 2 &&
2080         (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2081         (gv = gv_fetchpv(pkgname, FALSE, SVt_PVHV)))
2082     {
2083         return GvHV(gv);                        /* Foo:: */
2084     }
2085
2086     /* use constant CLASS => 'MyClass' */
2087     if ((gv = gv_fetchpv(pkgname, FALSE, SVt_PVCV))) {
2088         SV *sv;
2089         if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) {
2090             pkgname = SvPV_nolen(sv);
2091         }
2092     }
2093
2094     return gv_stashpv(pkgname, FALSE);
2095 }
2096
2097 #ifdef DEBUGGING
2098     static char* exp_name[] =
2099         { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
2100           "ATTRTERM", "TERMBLOCK"
2101         };
2102 #endif
2103
2104 /*
2105   yylex
2106
2107   Works out what to call the token just pulled out of the input
2108   stream.  The yacc parser takes care of taking the ops we return and
2109   stitching them into a tree.
2110
2111   Returns:
2112     PRIVATEREF
2113
2114   Structure:
2115       if read an identifier
2116           if we're in a my declaration
2117               croak if they tried to say my($foo::bar)
2118               build the ops for a my() declaration
2119           if it's an access to a my() variable
2120               are we in a sort block?
2121                   croak if my($a); $a <=> $b
2122               build ops for access to a my() variable
2123           if in a dq string, and they've said @foo and we can't find @foo
2124               croak
2125           build ops for a bareword
2126       if we already built the token before, use it.
2127 */
2128
2129 #ifdef USE_PURE_BISON
2130 int
2131 Perl_yylex_r(pTHX_ YYSTYPE *lvalp, int *lcharp)
2132 {
2133     int r;
2134
2135     yyactlevel++;
2136     yylval_pointer[yyactlevel] = lvalp;
2137     yychar_pointer[yyactlevel] = lcharp;
2138     if (yyactlevel >= YYMAXLEVEL)
2139         Perl_croak(aTHX_ "panic: YYMAXLEVEL");
2140
2141     r = Perl_yylex(aTHX);
2142
2143     if (yyactlevel > 0)
2144        yyactlevel--;
2145
2146     return r;
2147 }
2148 #endif
2149
2150 #ifdef __SC__
2151 #pragma segment Perl_yylex
2152 #endif
2153 int
2154 Perl_yylex(pTHX)
2155 {
2156     register char *s;
2157     register char *d;
2158     register I32 tmp;
2159     STRLEN len;
2160     GV *gv = Nullgv;
2161     GV **gvp = 0;
2162     bool bof = FALSE;
2163
2164     /* check if there's an identifier for us to look at */
2165     if (PL_pending_ident) {
2166         /* pit holds the identifier we read and pending_ident is reset */
2167         char pit = PL_pending_ident;
2168         PL_pending_ident = 0;
2169
2170         DEBUG_T({ PerlIO_printf(Perl_debug_log,
2171               "### Tokener saw identifier '%s'\n", PL_tokenbuf); })
2172
2173         /* if we're in a my(), we can't allow dynamics here.
2174            $foo'bar has already been turned into $foo::bar, so
2175            just check for colons.
2176
2177            if it's a legal name, the OP is a PADANY.
2178         */
2179         if (PL_in_my) {
2180             if (PL_in_my == KEY_our) {  /* "our" is merely analogous to "my" */
2181                 if (strchr(PL_tokenbuf,':'))
2182                     yyerror(Perl_form(aTHX_ "No package name allowed for "
2183                                       "variable %s in \"our\"",
2184                                       PL_tokenbuf));
2185                 tmp = pad_allocmy(PL_tokenbuf);
2186             }
2187             else {
2188                 if (strchr(PL_tokenbuf,':'))
2189                     yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf));
2190
2191                 yylval.opval = newOP(OP_PADANY, 0);
2192                 yylval.opval->op_targ = pad_allocmy(PL_tokenbuf);
2193                 return PRIVATEREF;
2194             }
2195         }
2196
2197         /*
2198            build the ops for accesses to a my() variable.
2199
2200            Deny my($a) or my($b) in a sort block, *if* $a or $b is
2201            then used in a comparison.  This catches most, but not
2202            all cases.  For instance, it catches
2203                sort { my($a); $a <=> $b }
2204            but not
2205                sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
2206            (although why you'd do that is anyone's guess).
2207         */
2208
2209         if (!strchr(PL_tokenbuf,':')) {
2210 #ifdef USE_THREADS
2211             /* Check for single character per-thread SVs */
2212             if (PL_tokenbuf[0] == '$' && PL_tokenbuf[2] == '\0'
2213                 && !isALPHA(PL_tokenbuf[1]) /* Rule out obvious non-threadsvs */
2214                 && (tmp = find_threadsv(&PL_tokenbuf[1])) != NOT_IN_PAD)
2215             {
2216                 yylval.opval = newOP(OP_THREADSV, 0);
2217                 yylval.opval->op_targ = tmp;
2218                 return PRIVATEREF;
2219             }
2220 #endif /* USE_THREADS */
2221             if ((tmp = pad_findmy(PL_tokenbuf)) != NOT_IN_PAD) {
2222                 SV *namesv = AvARRAY(PL_comppad_name)[tmp];
2223                 /* might be an "our" variable" */
2224                 if (SvFLAGS(namesv) & SVpad_OUR) {
2225                     /* build ops for a bareword */
2226                     SV *sym = newSVpv(HvNAME(GvSTASH(namesv)),0);
2227                     sv_catpvn(sym, "::", 2);
2228                     sv_catpv(sym, PL_tokenbuf+1);
2229                     yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
2230                     yylval.opval->op_private = OPpCONST_ENTERED;
2231                     gv_fetchpv(SvPVX(sym),
2232                         (PL_in_eval
2233                             ? (GV_ADDMULTI | GV_ADDINEVAL)
2234                             : TRUE
2235                         ),
2236                         ((PL_tokenbuf[0] == '$') ? SVt_PV
2237                          : (PL_tokenbuf[0] == '@') ? SVt_PVAV
2238                          : SVt_PVHV));
2239                     return WORD;
2240                 }
2241
2242                 /* if it's a sort block and they're naming $a or $b */
2243                 if (PL_last_lop_op == OP_SORT &&
2244                     PL_tokenbuf[0] == '$' &&
2245                     (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
2246                     && !PL_tokenbuf[2])
2247                 {
2248                     for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
2249                          d < PL_bufend && *d != '\n';
2250                          d++)
2251                     {
2252                         if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
2253                             Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
2254                                   PL_tokenbuf);
2255                         }
2256                     }
2257                 }
2258
2259                 yylval.opval = newOP(OP_PADANY, 0);
2260                 yylval.opval->op_targ = tmp;
2261                 return PRIVATEREF;
2262             }
2263         }
2264
2265         /*
2266            Whine if they've said @foo in a doublequoted string,
2267            and @foo isn't a variable we can find in the symbol
2268            table.
2269         */
2270         if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
2271             GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV);
2272             if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
2273                  && ckWARN(WARN_AMBIGUOUS))
2274             {
2275                 /* Downgraded from fatal to warning 20000522 mjd */
2276                 Perl_warner(aTHX_ WARN_AMBIGUOUS,
2277                             "Possible unintended interpolation of %s in string",
2278                              PL_tokenbuf);
2279             }
2280         }
2281
2282         /* build ops for a bareword */
2283         yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
2284         yylval.opval->op_private = OPpCONST_ENTERED;
2285         gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
2286                    ((PL_tokenbuf[0] == '$') ? SVt_PV
2287                     : (PL_tokenbuf[0] == '@') ? SVt_PVAV
2288                     : SVt_PVHV));
2289         return WORD;
2290     }
2291
2292     /* no identifier pending identification */
2293
2294     switch (PL_lex_state) {
2295 #ifdef COMMENTARY
2296     case LEX_NORMAL:            /* Some compilers will produce faster */
2297     case LEX_INTERPNORMAL:      /* code if we comment these out. */
2298         break;
2299 #endif
2300
2301     /* when we've already built the next token, just pull it out of the queue */
2302     case LEX_KNOWNEXT:
2303         PL_nexttoke--;
2304         yylval = PL_nextval[PL_nexttoke];
2305         if (!PL_nexttoke) {
2306             PL_lex_state = PL_lex_defer;
2307             PL_expect = PL_lex_expect;
2308             PL_lex_defer = LEX_NORMAL;
2309         }
2310         DEBUG_T({ PerlIO_printf(Perl_debug_log,
2311               "### Next token after '%s' was known, type %"IVdf"\n", PL_bufptr,
2312               (IV)PL_nexttype[PL_nexttoke]); })
2313
2314         return(PL_nexttype[PL_nexttoke]);
2315
2316     /* interpolated case modifiers like \L \U, including \Q and \E.
2317        when we get here, PL_bufptr is at the \
2318     */
2319     case LEX_INTERPCASEMOD:
2320 #ifdef DEBUGGING
2321         if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
2322             Perl_croak(aTHX_ "panic: INTERPCASEMOD");
2323 #endif
2324         /* handle \E or end of string */
2325         if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
2326             char oldmod;
2327
2328             /* if at a \E */
2329             if (PL_lex_casemods) {
2330                 oldmod = PL_lex_casestack[--PL_lex_casemods];
2331                 PL_lex_casestack[PL_lex_casemods] = '\0';
2332
2333                 if (PL_bufptr != PL_bufend && strchr("LUQ", oldmod)) {
2334                     PL_bufptr += 2;
2335                     PL_lex_state = LEX_INTERPCONCAT;
2336                 }
2337                 return ')';
2338             }
2339             if (PL_bufptr != PL_bufend)
2340                 PL_bufptr += 2;
2341             PL_lex_state = LEX_INTERPCONCAT;
2342             return yylex();
2343         }
2344         else {
2345             DEBUG_T({ PerlIO_printf(Perl_debug_log,
2346               "### Saw case modifier at '%s'\n", PL_bufptr); })
2347             s = PL_bufptr + 1;
2348             if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
2349                 tmp = *s, *s = s[2], s[2] = tmp;        /* misordered... */
2350             if (strchr("LU", *s) &&
2351                 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U')))
2352             {
2353                 PL_lex_casestack[--PL_lex_casemods] = '\0';
2354                 return ')';
2355             }
2356             if (PL_lex_casemods > 10) {
2357                 char* newlb = Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
2358                 if (newlb != PL_lex_casestack) {
2359                     SAVEFREEPV(newlb);
2360                     PL_lex_casestack = newlb;
2361                 }
2362             }
2363             PL_lex_casestack[PL_lex_casemods++] = *s;
2364             PL_lex_casestack[PL_lex_casemods] = '\0';
2365             PL_lex_state = LEX_INTERPCONCAT;
2366             PL_nextval[PL_nexttoke].ival = 0;
2367             force_next('(');
2368             if (*s == 'l')
2369                 PL_nextval[PL_nexttoke].ival = OP_LCFIRST;
2370             else if (*s == 'u')
2371                 PL_nextval[PL_nexttoke].ival = OP_UCFIRST;
2372             else if (*s == 'L')
2373                 PL_nextval[PL_nexttoke].ival = OP_LC;
2374             else if (*s == 'U')
2375                 PL_nextval[PL_nexttoke].ival = OP_UC;
2376             else if (*s == 'Q')
2377                 PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA;
2378             else
2379                 Perl_croak(aTHX_ "panic: yylex");
2380             PL_bufptr = s + 1;
2381             force_next(FUNC);
2382             if (PL_lex_starts) {
2383                 s = PL_bufptr;
2384                 PL_lex_starts = 0;
2385                 Aop(OP_CONCAT);
2386             }
2387             else
2388                 return yylex();
2389         }
2390
2391     case LEX_INTERPPUSH:
2392         return sublex_push();
2393
2394     case LEX_INTERPSTART:
2395         if (PL_bufptr == PL_bufend)
2396             return sublex_done();
2397         DEBUG_T({ PerlIO_printf(Perl_debug_log,
2398               "### Interpolated variable at '%s'\n", PL_bufptr); })
2399         PL_expect = XTERM;
2400         PL_lex_dojoin = (*PL_bufptr == '@');
2401         PL_lex_state = LEX_INTERPNORMAL;
2402         if (PL_lex_dojoin) {
2403             PL_nextval[PL_nexttoke].ival = 0;
2404             force_next(',');
2405 #ifdef USE_THREADS
2406             PL_nextval[PL_nexttoke].opval = newOP(OP_THREADSV, 0);
2407             PL_nextval[PL_nexttoke].opval->op_targ = find_threadsv("\"");
2408             force_next(PRIVATEREF);
2409 #else
2410             force_ident("\"", '$');
2411 #endif /* USE_THREADS */
2412             PL_nextval[PL_nexttoke].ival = 0;
2413             force_next('$');
2414             PL_nextval[PL_nexttoke].ival = 0;
2415             force_next('(');
2416             PL_nextval[PL_nexttoke].ival = OP_JOIN;     /* emulate join($", ...) */
2417             force_next(FUNC);
2418         }
2419         if (PL_lex_starts++) {
2420             s = PL_bufptr;
2421             Aop(OP_CONCAT);
2422         }
2423         return yylex();
2424
2425     case LEX_INTERPENDMAYBE:
2426         if (intuit_more(PL_bufptr)) {
2427             PL_lex_state = LEX_INTERPNORMAL;    /* false alarm, more expr */
2428             break;
2429         }
2430         /* FALL THROUGH */
2431
2432     case LEX_INTERPEND:
2433         if (PL_lex_dojoin) {
2434             PL_lex_dojoin = FALSE;
2435             PL_lex_state = LEX_INTERPCONCAT;
2436             return ')';
2437         }
2438         if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
2439             && SvEVALED(PL_lex_repl))
2440         {
2441             if (PL_bufptr != PL_bufend)
2442                 Perl_croak(aTHX_ "Bad evalled substitution pattern");
2443             PL_lex_repl = Nullsv;
2444         }
2445         /* FALLTHROUGH */
2446     case LEX_INTERPCONCAT:
2447 #ifdef DEBUGGING
2448         if (PL_lex_brackets)
2449             Perl_croak(aTHX_ "panic: INTERPCONCAT");
2450 #endif
2451         if (PL_bufptr == PL_bufend)
2452             return sublex_done();
2453
2454         if (SvIVX(PL_linestr) == '\'') {
2455             SV *sv = newSVsv(PL_linestr);
2456             if (!PL_lex_inpat)
2457                 sv = tokeq(sv);
2458             else if ( PL_hints & HINT_NEW_RE )
2459                 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
2460             yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2461             s = PL_bufend;
2462         }
2463         else {
2464             s = scan_const(PL_bufptr);
2465             if (*s == '\\')
2466                 PL_lex_state = LEX_INTERPCASEMOD;
2467             else
2468                 PL_lex_state = LEX_INTERPSTART;
2469         }
2470
2471         if (s != PL_bufptr) {
2472             PL_nextval[PL_nexttoke] = yylval;
2473             PL_expect = XTERM;
2474             force_next(THING);
2475             if (PL_lex_starts++)
2476                 Aop(OP_CONCAT);
2477             else {
2478                 PL_bufptr = s;
2479                 return yylex();
2480             }
2481         }
2482
2483         return yylex();
2484     case LEX_FORMLINE:
2485         PL_lex_state = LEX_NORMAL;
2486         s = scan_formline(PL_bufptr);
2487         if (!PL_lex_formbrack)
2488             goto rightbracket;
2489         OPERATOR(';');
2490     }
2491
2492     s = PL_bufptr;
2493     PL_oldoldbufptr = PL_oldbufptr;
2494     PL_oldbufptr = s;
2495     DEBUG_T( {
2496         PerlIO_printf(Perl_debug_log, "### Tokener expecting %s at %s\n",
2497                       exp_name[PL_expect], s);
2498     } )
2499
2500   retry:
2501     switch (*s) {
2502     default:
2503         if (isIDFIRST_lazy_if(s,UTF))
2504             goto keylookup;
2505         Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
2506     case 4:
2507     case 26:
2508         goto fake_eof;                  /* emulate EOF on ^D or ^Z */
2509     case 0:
2510         if (!PL_rsfp) {
2511             PL_last_uni = 0;
2512             PL_last_lop = 0;
2513             if (PL_lex_brackets)
2514                 yyerror("Missing right curly or square bracket");
2515             DEBUG_T( { PerlIO_printf(Perl_debug_log,
2516                         "### Tokener got EOF\n");
2517             } )
2518             TOKEN(0);
2519         }
2520         if (s++ < PL_bufend)
2521             goto retry;                 /* ignore stray nulls */
2522         PL_last_uni = 0;
2523         PL_last_lop = 0;
2524         if (!PL_in_eval && !PL_preambled) {
2525             PL_preambled = TRUE;
2526             sv_setpv(PL_linestr,incl_perldb());
2527             if (SvCUR(PL_linestr))
2528                 sv_catpv(PL_linestr,";");
2529             if (PL_preambleav){
2530                 while(AvFILLp(PL_preambleav) >= 0) {
2531                     SV *tmpsv = av_shift(PL_preambleav);
2532                     sv_catsv(PL_linestr, tmpsv);
2533                     sv_catpv(PL_linestr, ";");
2534                     sv_free(tmpsv);
2535                 }
2536                 sv_free((SV*)PL_preambleav);
2537                 PL_preambleav = NULL;
2538             }
2539             if (PL_minus_n || PL_minus_p) {
2540                 sv_catpv(PL_linestr, "LINE: while (<>) {");
2541                 if (PL_minus_l)
2542                     sv_catpv(PL_linestr,"chomp;");
2543                 if (PL_minus_a) {
2544                     GV* gv = gv_fetchpv("::F", TRUE, SVt_PVAV);
2545                     if (gv)
2546                         GvIMPORTED_AV_on(gv);
2547                     if (PL_minus_F) {
2548                         if (strchr("/'\"", *PL_splitstr)
2549                               && strchr(PL_splitstr + 1, *PL_splitstr))
2550                             Perl_sv_catpvf(aTHX_ PL_linestr, "@F=split(%s);", PL_splitstr);
2551                         else {
2552                             char delim;
2553                             s = "'~#\200\1'"; /* surely one char is unused...*/
2554                             while (s[1] && strchr(PL_splitstr, *s))  s++;
2555                             delim = *s;
2556                             Perl_sv_catpvf(aTHX_ PL_linestr, "@F=split(%s%c",
2557                                       "q" + (delim == '\''), delim);
2558                             for (s = PL_splitstr; *s; s++) {
2559                                 if (*s == '\\')
2560                                     sv_catpvn(PL_linestr, "\\", 1);
2561                                 sv_catpvn(PL_linestr, s, 1);
2562                             }
2563                             Perl_sv_catpvf(aTHX_ PL_linestr, "%c);", delim);
2564                         }
2565                     }
2566                     else
2567                         sv_catpv(PL_linestr,"@F=split(' ');");
2568                 }
2569             }
2570             sv_catpv(PL_linestr, "\n");
2571             PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2572             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2573             PL_last_lop = PL_last_uni = Nullch;
2574             if (PERLDB_LINE && PL_curstash != PL_debstash) {
2575                 SV *sv = NEWSV(85,0);
2576
2577                 sv_upgrade(sv, SVt_PVMG);
2578                 sv_setsv(sv,PL_linestr);
2579                 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2580             }
2581             goto retry;
2582         }
2583         do {
2584             bof = PL_rsfp ? TRUE : FALSE;
2585             if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) {
2586               fake_eof:
2587                 if (PL_rsfp) {
2588                     if (PL_preprocess && !PL_in_eval)
2589                         (void)PerlProc_pclose(PL_rsfp);
2590                     else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
2591                         PerlIO_clearerr(PL_rsfp);
2592                     else
2593                         (void)PerlIO_close(PL_rsfp);
2594                     PL_rsfp = Nullfp;
2595                     PL_doextract = FALSE;
2596                 }
2597                 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
2598                     sv_setpv(PL_linestr,PL_minus_p ? ";}continue{print" : "");
2599                     sv_catpv(PL_linestr,";}");
2600                     PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2601                     PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2602                     PL_last_lop = PL_last_uni = Nullch;
2603                     PL_minus_n = PL_minus_p = 0;
2604                     goto retry;
2605                 }
2606                 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2607                 PL_last_lop = PL_last_uni = Nullch;
2608                 sv_setpv(PL_linestr,"");
2609                 TOKEN(';');     /* not infinite loop because rsfp is NULL now */
2610             }
2611             /* if it looks like the start of a BOM, check if it in fact is */
2612             else if (bof && (!*s || *(U8*)s == 0xEF || *(U8*)s >= 0xFE)) {
2613 #ifdef PERLIO_IS_STDIO
2614 #  ifdef __GNU_LIBRARY__
2615 #    if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
2616 #      define FTELL_FOR_PIPE_IS_BROKEN
2617 #    endif
2618 #  else
2619 #    ifdef __GLIBC__
2620 #      if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
2621 #        define FTELL_FOR_PIPE_IS_BROKEN
2622 #      endif
2623 #    endif
2624 #  endif
2625 #endif
2626 #ifdef FTELL_FOR_PIPE_IS_BROKEN
2627                 /* This loses the possibility to detect the bof
2628                  * situation on perl -P when the libc5 is being used.
2629                  * Workaround?  Maybe attach some extra state to PL_rsfp?
2630                  */
2631                 if (!PL_preprocess)
2632                     bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
2633 #else
2634                 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
2635 #endif
2636                 if (bof) {
2637                     PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2638                     s = swallow_bom((U8*)s);
2639                 }
2640             }
2641             if (PL_doextract) {
2642                 if (*s == '#' && s[1] == '!' && instr(s,"perl"))
2643                     PL_doextract = FALSE;
2644
2645                 /* Incest with pod. */
2646                 if (*s == '=' && strnEQ(s, "=cut", 4)) {
2647                     sv_setpv(PL_linestr, "");
2648                     PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2649                     PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2650                     PL_last_lop = PL_last_uni = Nullch;
2651                     PL_doextract = FALSE;
2652                 }
2653             }
2654             incline(s);
2655         } while (PL_doextract);
2656         PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
2657         if (PERLDB_LINE && PL_curstash != PL_debstash) {
2658             SV *sv = NEWSV(85,0);
2659
2660             sv_upgrade(sv, SVt_PVMG);
2661             sv_setsv(sv,PL_linestr);
2662             av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2663         }
2664         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2665         PL_last_lop = PL_last_uni = Nullch;
2666         if (CopLINE(PL_curcop) == 1) {
2667             while (s < PL_bufend && isSPACE(*s))
2668                 s++;
2669             if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
2670                 s++;
2671             d = Nullch;
2672             if (!PL_in_eval) {
2673                 if (*s == '#' && *(s+1) == '!')
2674                     d = s + 2;
2675 #ifdef ALTERNATE_SHEBANG
2676                 else {
2677                     static char as[] = ALTERNATE_SHEBANG;
2678                     if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
2679                         d = s + (sizeof(as) - 1);
2680                 }
2681 #endif /* ALTERNATE_SHEBANG */
2682             }
2683             if (d) {
2684                 char *ipath;
2685                 char *ipathend;
2686
2687                 while (isSPACE(*d))
2688                     d++;
2689                 ipath = d;
2690                 while (*d && !isSPACE(*d))
2691                     d++;
2692                 ipathend = d;
2693
2694 #ifdef ARG_ZERO_IS_SCRIPT
2695                 if (ipathend > ipath) {
2696                     /*
2697                      * HP-UX (at least) sets argv[0] to the script name,
2698                      * which makes $^X incorrect.  And Digital UNIX and Linux,
2699                      * at least, set argv[0] to the basename of the Perl
2700                      * interpreter. So, having found "#!", we'll set it right.
2701                      */
2702                     SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV));
2703                     assert(SvPOK(x) || SvGMAGICAL(x));
2704                     if (sv_eq(x, CopFILESV(PL_curcop))) {
2705                         sv_setpvn(x, ipath, ipathend - ipath);
2706                         SvSETMAGIC(x);
2707                     }
2708                     TAINT_NOT;  /* $^X is always tainted, but that's OK */
2709                 }
2710 #endif /* ARG_ZERO_IS_SCRIPT */
2711
2712                 /*
2713                  * Look for options.
2714                  */
2715                 d = instr(s,"perl -");
2716                 if (!d) {
2717                     d = instr(s,"perl");
2718 #if defined(DOSISH)
2719                     /* avoid getting into infinite loops when shebang
2720                      * line contains "Perl" rather than "perl" */
2721                     if (!d) {
2722                         for (d = ipathend-4; d >= ipath; --d) {
2723                             if ((*d == 'p' || *d == 'P')
2724                                 && !ibcmp(d, "perl", 4))
2725                             {
2726                                 break;
2727                             }
2728                         }
2729                         if (d < ipath)
2730                             d = Nullch;
2731                     }
2732 #endif
2733                 }
2734 #ifdef ALTERNATE_SHEBANG
2735                 /*
2736                  * If the ALTERNATE_SHEBANG on this system starts with a
2737                  * character that can be part of a Perl expression, then if
2738                  * we see it but not "perl", we're probably looking at the
2739                  * start of Perl code, not a request to hand off to some
2740                  * other interpreter.  Similarly, if "perl" is there, but
2741                  * not in the first 'word' of the line, we assume the line
2742                  * contains the start of the Perl program.
2743                  */
2744                 if (d && *s != '#') {
2745                     char *c = ipath;
2746                     while (*c && !strchr("; \t\r\n\f\v#", *c))
2747                         c++;
2748                     if (c < d)
2749                         d = Nullch;     /* "perl" not in first word; ignore */
2750                     else
2751                         *s = '#';       /* Don't try to parse shebang line */
2752                 }
2753 #endif /* ALTERNATE_SHEBANG */
2754 #ifndef MACOS_TRADITIONAL
2755                 if (!d &&
2756                     *s == '#' &&
2757                     ipathend > ipath &&
2758                     !PL_minus_c &&
2759                     !instr(s,"indir") &&
2760                     instr(PL_origargv[0],"perl"))
2761                 {
2762                     char **newargv;
2763
2764                     *ipathend = '\0';
2765                     s = ipathend + 1;
2766                     while (s < PL_bufend && isSPACE(*s))
2767                         s++;
2768                     if (s < PL_bufend) {
2769                         Newz(899,newargv,PL_origargc+3,char*);
2770                         newargv[1] = s;
2771                         while (s < PL_bufend && !isSPACE(*s))
2772                             s++;
2773                         *s = '\0';
2774                         Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
2775                     }
2776                     else
2777                         newargv = PL_origargv;
2778                     newargv[0] = ipath;
2779                     PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
2780                     Perl_croak(aTHX_ "Can't exec %s", ipath);
2781                 }
2782 #endif
2783                 if (d) {
2784                     U32 oldpdb = PL_perldb;
2785                     bool oldn = PL_minus_n;
2786                     bool oldp = PL_minus_p;
2787
2788                     while (*d && !isSPACE(*d)) d++;
2789                     while (SPACE_OR_TAB(*d)) d++;
2790
2791                     if (*d++ == '-') {
2792                         do {
2793                             if (*d == 'M' || *d == 'm') {
2794                                 char *m = d;
2795                                 while (*d && !isSPACE(*d)) d++;
2796                                 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
2797                                       (int)(d - m), m);
2798                             }
2799                             d = moreswitches(d);
2800                         } while (d);
2801                         if ((PERLDB_LINE && !oldpdb) ||
2802                             ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
2803                               /* if we have already added "LINE: while (<>) {",
2804                                  we must not do it again */
2805                         {
2806                             sv_setpv(PL_linestr, "");
2807                             PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2808                             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2809                             PL_last_lop = PL_last_uni = Nullch;
2810                             PL_preambled = FALSE;
2811                             if (PERLDB_LINE)
2812                                 (void)gv_fetchfile(PL_origfilename);
2813                             goto retry;
2814                         }
2815                     }
2816                 }
2817             }
2818         }
2819         if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2820             PL_bufptr = s;
2821             PL_lex_state = LEX_FORMLINE;
2822             return yylex();
2823         }
2824         goto retry;
2825     case '\r':
2826 #ifdef PERL_STRICT_CR
2827         Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
2828         Perl_croak(aTHX_
2829       "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
2830 #endif
2831     case ' ': case '\t': case '\f': case 013:
2832 #ifdef MACOS_TRADITIONAL
2833     case '\312':
2834 #endif
2835         s++;
2836         goto retry;
2837     case '#':
2838     case '\n':
2839         if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
2840             if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
2841                 /* handle eval qq[#line 1 "foo"\n ...] */
2842                 CopLINE_dec(PL_curcop);
2843                 incline(s);
2844             }
2845             d = PL_bufend;
2846             while (s < d && *s != '\n')
2847                 s++;
2848             if (s < d)
2849                 s++;
2850             incline(s);
2851             if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2852                 PL_bufptr = s;
2853                 PL_lex_state = LEX_FORMLINE;
2854                 return yylex();
2855             }
2856         }
2857         else {
2858             *s = '\0';
2859             PL_bufend = s;
2860         }
2861         goto retry;
2862     case '-':
2863         if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
2864             I32 ftst = 0;
2865
2866             s++;
2867             PL_bufptr = s;
2868             tmp = *s++;
2869
2870             while (s < PL_bufend && SPACE_OR_TAB(*s))
2871                 s++;
2872
2873             if (strnEQ(s,"=>",2)) {
2874                 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
2875                 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2876                             "### Saw unary minus before =>, forcing word '%s'\n", s);
2877                 } )
2878                 OPERATOR('-');          /* unary minus */
2879             }
2880             PL_last_uni = PL_oldbufptr;
2881             switch (tmp) {
2882             case 'r': ftst = OP_FTEREAD;        break;
2883             case 'w': ftst = OP_FTEWRITE;       break;
2884             case 'x': ftst = OP_FTEEXEC;        break;
2885             case 'o': ftst = OP_FTEOWNED;       break;
2886             case 'R': ftst = OP_FTRREAD;        break;
2887             case 'W': ftst = OP_FTRWRITE;       break;
2888             case 'X': ftst = OP_FTREXEC;        break;
2889             case 'O': ftst = OP_FTROWNED;       break;
2890             case 'e': ftst = OP_FTIS;           break;
2891             case 'z': ftst = OP_FTZERO;         break;
2892             case 's': ftst = OP_FTSIZE;         break;
2893             case 'f': ftst = OP_FTFILE;         break;
2894             case 'd': ftst = OP_FTDIR;          break;
2895             case 'l': ftst = OP_FTLINK;         break;
2896             case 'p': ftst = OP_FTPIPE;         break;
2897             case 'S': ftst = OP_FTSOCK;         break;
2898             case 'u': ftst = OP_FTSUID;         break;
2899             case 'g': ftst = OP_FTSGID;         break;
2900             case 'k': ftst = OP_FTSVTX;         break;
2901             case 'b': ftst = OP_FTBLK;          break;
2902             case 'c': ftst = OP_FTCHR;          break;
2903             case 't': ftst = OP_FTTTY;          break;
2904             case 'T': ftst = OP_FTTEXT;         break;
2905             case 'B': ftst = OP_FTBINARY;       break;
2906             case 'M': case 'A': case 'C':
2907                 gv_fetchpv("\024",TRUE, SVt_PV);
2908                 switch (tmp) {
2909                 case 'M': ftst = OP_FTMTIME;    break;
2910                 case 'A': ftst = OP_FTATIME;    break;
2911                 case 'C': ftst = OP_FTCTIME;    break;
2912                 default:                        break;
2913                 }
2914                 break;
2915             default:
2916                 break;
2917             }
2918             if (ftst) {
2919                 PL_last_lop_op = ftst;
2920                 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2921                         "### Saw file test %c\n", (int)ftst);
2922                 } )
2923                 FTST(ftst);
2924             }
2925             else {
2926                 /* Assume it was a minus followed by a one-letter named
2927                  * subroutine call (or a -bareword), then. */
2928                 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2929                         "### %c looked like a file test but was not\n",
2930                         (int)ftst);
2931                 } )
2932                 s -= 2;
2933             }
2934         }
2935         tmp = *s++;
2936         if (*s == tmp) {
2937             s++;
2938             if (PL_expect == XOPERATOR)
2939                 TERM(POSTDEC);
2940             else
2941                 OPERATOR(PREDEC);
2942         }
2943         else if (*s == '>') {
2944             s++;
2945             s = skipspace(s);
2946             if (isIDFIRST_lazy_if(s,UTF)) {
2947                 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
2948                 TOKEN(ARROW);
2949             }
2950             else if (*s == '$')
2951                 OPERATOR(ARROW);
2952             else
2953                 TERM(ARROW);
2954         }
2955         if (PL_expect == XOPERATOR)
2956             Aop(OP_SUBTRACT);
2957         else {
2958             if (isSPACE(*s) || !isSPACE(*PL_bufptr))
2959                 check_uni();
2960             OPERATOR('-');              /* unary minus */
2961         }
2962
2963     case '+':
2964         tmp = *s++;
2965         if (*s == tmp) {
2966             s++;
2967             if (PL_expect == XOPERATOR)
2968                 TERM(POSTINC);
2969             else
2970                 OPERATOR(PREINC);
2971         }
2972         if (PL_expect == XOPERATOR)
2973             Aop(OP_ADD);
2974         else {
2975             if (isSPACE(*s) || !isSPACE(*PL_bufptr))
2976                 check_uni();
2977             OPERATOR('+');
2978         }
2979
2980     case '*':
2981         if (PL_expect != XOPERATOR) {
2982             s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
2983             PL_expect = XOPERATOR;
2984             force_ident(PL_tokenbuf, '*');
2985             if (!*PL_tokenbuf)
2986                 PREREF('*');
2987             TERM('*');
2988         }
2989         s++;
2990         if (*s == '*') {
2991             s++;
2992             PWop(OP_POW);
2993         }
2994         Mop(OP_MULTIPLY);
2995
2996     case '%':
2997         if (PL_expect == XOPERATOR) {
2998             ++s;
2999             Mop(OP_MODULO);
3000         }
3001         PL_tokenbuf[0] = '%';
3002         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
3003         if (!PL_tokenbuf[1]) {
3004             if (s == PL_bufend)
3005                 yyerror("Final % should be \\% or %name");
3006             PREREF('%');
3007         }
3008         PL_pending_ident = '%';
3009         TERM('%');
3010
3011     case '^':
3012         s++;
3013         BOop(OP_BIT_XOR);
3014     case '[':
3015         PL_lex_brackets++;
3016         /* FALL THROUGH */
3017     case '~':
3018     case ',':
3019         tmp = *s++;
3020         OPERATOR(tmp);
3021     case ':':
3022         if (s[1] == ':') {
3023             len = 0;
3024             goto just_a_word;
3025         }
3026         s++;
3027         switch (PL_expect) {
3028             OP *attrs;
3029         case XOPERATOR:
3030             if (!PL_in_my || PL_lex_state != LEX_NORMAL)
3031                 break;
3032             PL_bufptr = s;      /* update in case we back off */
3033             goto grabattrs;
3034         case XATTRBLOCK:
3035             PL_expect = XBLOCK;
3036             goto grabattrs;
3037         case XATTRTERM:
3038             PL_expect = XTERMBLOCK;
3039          grabattrs:
3040             s = skipspace(s);
3041             attrs = Nullop;
3042             while (isIDFIRST_lazy_if(s,UTF)) {
3043                 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3044                 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) {
3045                     if (tmp < 0) tmp = -tmp;
3046                     switch (tmp) {
3047                     case KEY_or:
3048                     case KEY_and:
3049                     case KEY_for:
3050                     case KEY_unless:
3051                     case KEY_if:
3052                     case KEY_while:
3053                     case KEY_until:
3054                         goto got_attrs;
3055                     default:
3056                         break;
3057                     }
3058                 }
3059                 if (*d == '(') {
3060                     d = scan_str(d,TRUE,TRUE);
3061                     if (!d) {
3062                         /* MUST advance bufptr here to avoid bogus
3063                            "at end of line" context messages from yyerror().
3064                          */
3065                         PL_bufptr = s + len;
3066                         yyerror("Unterminated attribute parameter in attribute list");
3067                         if (attrs)
3068                             op_free(attrs);
3069                         return 0;       /* EOF indicator */
3070                     }
3071                 }
3072                 if (PL_lex_stuff) {
3073                     SV *sv = newSVpvn(s, len);
3074                     sv_catsv(sv, PL_lex_stuff);
3075                     attrs = append_elem(OP_LIST, attrs,
3076                                         newSVOP(OP_CONST, 0, sv));
3077                     SvREFCNT_dec(PL_lex_stuff);
3078                     PL_lex_stuff = Nullsv;
3079                 }
3080                 else {
3081                     if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len))
3082                         CvLVALUE_on(PL_compcv);
3083                     else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len))
3084                         CvLOCKED_on(PL_compcv);
3085                     else if (!PL_in_my && len == 6 && strnEQ(s, "method", len))
3086                         CvMETHOD_on(PL_compcv);
3087 #ifdef USE_ITHREADS
3088                     else if (PL_in_my == KEY_our && len == 6 && strnEQ(s, "shared", len))
3089                         GvSHARED_on(cGVOPx_gv(yylval.opval));
3090 #endif
3091                     /* After we've set the flags, it could be argued that
3092                        we don't need to do the attributes.pm-based setting
3093                        process, and shouldn't bother appending recognized
3094                        flags. To experiment with that, uncomment the
3095                        following "else": */
3096                     else
3097                         attrs = append_elem(OP_LIST, attrs,
3098                                             newSVOP(OP_CONST, 0,
3099                                                     newSVpvn(s, len)));
3100                 }
3101                 s = skipspace(d);
3102                 if (*s == ':' && s[1] != ':')
3103                     s = skipspace(s+1);
3104                 else if (s == d)
3105                     break;      /* require real whitespace or :'s */
3106             }
3107             tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
3108             if (*s != ';' && *s != tmp && (tmp != '=' || *s != ')')) {
3109                 char q = ((*s == '\'') ? '"' : '\'');
3110                 /* If here for an expression, and parsed no attrs, back off. */
3111                 if (tmp == '=' && !attrs) {
3112                     s = PL_bufptr;
3113                     break;
3114                 }
3115                 /* MUST advance bufptr here to avoid bogus "at end of line"
3116                    context messages from yyerror().
3117                  */
3118                 PL_bufptr = s;
3119                 if (!*s)
3120                     yyerror("Unterminated attribute list");
3121                 else
3122                     yyerror(Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list",
3123                                       q, *s, q));
3124                 if (attrs)
3125                     op_free(attrs);
3126                 OPERATOR(':');
3127             }
3128         got_attrs:
3129             if (attrs) {
3130                 PL_nextval[PL_nexttoke].opval = attrs;
3131                 force_next(THING);
3132             }
3133             TOKEN(COLONATTR);
3134         }
3135         OPERATOR(':');
3136     case '(':
3137         s++;
3138         if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
3139             PL_oldbufptr = PL_oldoldbufptr;             /* allow print(STDOUT 123) */
3140         else
3141             PL_expect = XTERM;
3142         TOKEN('(');
3143     case ';':
3144         CLINE;
3145         tmp = *s++;
3146         OPERATOR(tmp);
3147     case ')':
3148         tmp = *s++;
3149         s = skipspace(s);
3150         if (*s == '{')
3151             PREBLOCK(tmp);
3152         TERM(tmp);
3153     case ']':
3154         s++;
3155         if (PL_lex_brackets <= 0)
3156             yyerror("Unmatched right square bracket");
3157         else
3158             --PL_lex_brackets;
3159         if (PL_lex_state == LEX_INTERPNORMAL) {
3160             if (PL_lex_brackets == 0) {
3161                 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
3162                     PL_lex_state = LEX_INTERPEND;
3163             }
3164         }
3165         TERM(']');
3166     case '{':
3167       leftbracket:
3168         s++;
3169         if (PL_lex_brackets > 100) {
3170             char* newlb = Renew(PL_lex_brackstack, PL_lex_brackets + 1, char);
3171             if (newlb != PL_lex_brackstack) {
3172                 SAVEFREEPV(newlb);
3173                 PL_lex_brackstack = newlb;
3174             }
3175         }
3176         switch (PL_expect) {
3177         case XTERM:
3178             if (PL_lex_formbrack) {
3179                 s--;
3180                 PRETERMBLOCK(DO);
3181             }
3182             if (PL_oldoldbufptr == PL_last_lop)
3183                 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3184             else
3185                 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3186             OPERATOR(HASHBRACK);
3187         case XOPERATOR:
3188             while (s < PL_bufend && SPACE_OR_TAB(*s))
3189                 s++;
3190             d = s;
3191             PL_tokenbuf[0] = '\0';
3192             if (d < PL_bufend && *d == '-') {
3193                 PL_tokenbuf[0] = '-';
3194                 d++;
3195                 while (d < PL_bufend && SPACE_OR_TAB(*d))
3196                     d++;
3197             }
3198             if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
3199                 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
3200                               FALSE, &len);
3201                 while (d < PL_bufend && SPACE_OR_TAB(*d))
3202                     d++;
3203                 if (*d == '}') {
3204                     char minus = (PL_tokenbuf[0] == '-');
3205                     s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
3206                     if (minus)
3207                         force_next('-');
3208                 }
3209             }
3210             /* FALL THROUGH */
3211         case XATTRBLOCK:
3212         case XBLOCK:
3213             PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
3214             PL_expect = XSTATE;
3215             break;
3216         case XATTRTERM:
3217         case XTERMBLOCK:
3218             PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3219             PL_expect = XSTATE;
3220             break;
3221         default: {
3222                 char *t;
3223                 if (PL_oldoldbufptr == PL_last_lop)
3224                     PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3225                 else
3226                     PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3227                 s = skipspace(s);
3228                 if (*s == '}')
3229                     OPERATOR(HASHBRACK);
3230                 /* This hack serves to disambiguate a pair of curlies
3231                  * as being a block or an anon hash.  Normally, expectation
3232                  * determines that, but in cases where we're not in a
3233                  * position to expect anything in particular (like inside
3234                  * eval"") we have to resolve the ambiguity.  This code
3235                  * covers the case where the first term in the curlies is a
3236                  * quoted string.  Most other cases need to be explicitly
3237                  * disambiguated by prepending a `+' before the opening
3238                  * curly in order to force resolution as an anon hash.
3239                  *
3240                  * XXX should probably propagate the outer expectation
3241                  * into eval"" to rely less on this hack, but that could
3242                  * potentially break current behavior of eval"".
3243                  * GSAR 97-07-21
3244                  */
3245                 t = s;
3246                 if (*s == '\'' || *s == '"' || *s == '`') {
3247                     /* common case: get past first string, handling escapes */
3248                     for (t++; t < PL_bufend && *t != *s;)
3249                         if (*t++ == '\\' && (*t == '\\' || *t == *s))
3250                             t++;
3251                     t++;
3252                 }
3253                 else if (*s == 'q') {
3254                     if (++t < PL_bufend
3255                         && (!isALNUM(*t)
3256                             || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
3257                                 && !isALNUM(*t))))
3258                     {
3259                         char *tmps;
3260                         char open, close, term;
3261                         I32 brackets = 1;
3262
3263                         while (t < PL_bufend && isSPACE(*t))
3264                             t++;
3265                         term = *t;
3266                         open = term;
3267                         if (term && (tmps = strchr("([{< )]}> )]}>",term)))
3268                             term = tmps[5];
3269                         close = term;
3270                         if (open == close)
3271                             for (t++; t < PL_bufend; t++) {
3272                                 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
3273                                     t++;
3274                                 else if (*t == open)
3275                                     break;
3276                             }
3277                         else
3278                             for (t++; t < PL_bufend; t++) {
3279                                 if (*t == '\\' && t+1 < PL_bufend)
3280                                     t++;
3281                                 else if (*t == close && --brackets <= 0)
3282                                     break;
3283                                 else if (*t == open)
3284                                     brackets++;
3285                             }
3286                     }
3287                     t++;
3288                 }
3289                 else if (isALNUM_lazy_if(t,UTF)) {
3290                     t += UTF8SKIP(t);
3291                     while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3292                          t += UTF8SKIP(t);
3293                 }
3294                 while (t < PL_bufend && isSPACE(*t))
3295                     t++;
3296                 /* if comma follows first term, call it an anon hash */
3297                 /* XXX it could be a comma expression with loop modifiers */
3298                 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
3299                                    || (*t == '=' && t[1] == '>')))
3300                     OPERATOR(HASHBRACK);
3301                 if (PL_expect == XREF)
3302                     PL_expect = XTERM;
3303                 else {
3304                     PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
3305                     PL_expect = XSTATE;
3306                 }
3307             }
3308             break;
3309         }
3310         yylval.ival = CopLINE(PL_curcop);
3311         if (isSPACE(*s) || *s == '#')
3312             PL_copline = NOLINE;   /* invalidate current command line number */
3313         TOKEN('{');
3314     case '}':
3315       rightbracket:
3316         s++;
3317         if (PL_lex_brackets <= 0)
3318             yyerror("Unmatched right curly bracket");
3319         else
3320             PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
3321         if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
3322             PL_lex_formbrack = 0;
3323         if (PL_lex_state == LEX_INTERPNORMAL) {
3324             if (PL_lex_brackets == 0) {
3325                 if (PL_expect & XFAKEBRACK) {
3326                     PL_expect &= XENUMMASK;
3327                     PL_lex_state = LEX_INTERPEND;
3328                     PL_bufptr = s;
3329                     return yylex();     /* ignore fake brackets */
3330                 }
3331                 if (*s == '-' && s[1] == '>')
3332                     PL_lex_state = LEX_INTERPENDMAYBE;
3333                 else if (*s != '[' && *s != '{')
3334                     PL_lex_state = LEX_INTERPEND;
3335             }
3336         }
3337         if (PL_expect & XFAKEBRACK) {
3338             PL_expect &= XENUMMASK;
3339             PL_bufptr = s;
3340             return yylex();             /* ignore fake brackets */
3341         }
3342         force_next('}');
3343         TOKEN(';');
3344     case '&':
3345         s++;
3346         tmp = *s++;
3347         if (tmp == '&')
3348             AOPERATOR(ANDAND);
3349         s--;
3350         if (PL_expect == XOPERATOR) {
3351             if (ckWARN(WARN_SEMICOLON)
3352                 && isIDFIRST_lazy_if(s,UTF) && PL_bufptr == PL_linestart)
3353             {
3354                 CopLINE_dec(PL_curcop);
3355                 Perl_warner(aTHX_ WARN_SEMICOLON, PL_warn_nosemi);
3356                 CopLINE_inc(PL_curcop);
3357             }
3358             BAop(OP_BIT_AND);
3359         }
3360
3361         s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3362         if (*PL_tokenbuf) {
3363             PL_expect = XOPERATOR;
3364             force_ident(PL_tokenbuf, '&');
3365         }
3366         else
3367             PREREF('&');
3368         yylval.ival = (OPpENTERSUB_AMPER<<8);
3369         TERM('&');
3370
3371     case '|':
3372         s++;
3373         tmp = *s++;
3374         if (tmp == '|')
3375             AOPERATOR(OROR);
3376         s--;
3377         BOop(OP_BIT_OR);
3378     case '=':
3379         s++;
3380         tmp = *s++;
3381         if (tmp == '=')
3382             Eop(OP_EQ);
3383         if (tmp == '>')
3384             OPERATOR(',');
3385         if (tmp == '~')
3386             PMop(OP_MATCH);
3387         if (ckWARN(WARN_SYNTAX) && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
3388             Perl_warner(aTHX_ WARN_SYNTAX, "Reversed %c= operator",(int)tmp);
3389         s--;
3390         if (PL_expect == XSTATE && isALPHA(tmp) &&
3391                 (s == PL_linestart+1 || s[-2] == '\n') )
3392         {
3393             if (PL_in_eval && !PL_rsfp) {
3394                 d = PL_bufend;
3395                 while (s < d) {
3396                     if (*s++ == '\n') {
3397                         incline(s);
3398                         if (strnEQ(s,"=cut",4)) {
3399                             s = strchr(s,'\n');
3400                             if (s)
3401                                 s++;
3402                             else
3403                                 s = d;
3404                             incline(s);
3405                             goto retry;
3406                         }
3407                     }
3408                 }
3409                 goto retry;
3410             }
3411             s = PL_bufend;
3412             PL_doextract = TRUE;
3413             goto retry;
3414         }
3415         if (PL_lex_brackets < PL_lex_formbrack) {
3416             char *t;
3417 #ifdef PERL_STRICT_CR
3418             for (t = s; SPACE_OR_TAB(*t); t++) ;
3419 #else
3420             for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
3421 #endif
3422             if (*t == '\n' || *t == '#') {
3423                 s--;
3424                 PL_expect = XBLOCK;
3425                 goto leftbracket;
3426             }
3427         }
3428         yylval.ival = 0;
3429         OPERATOR(ASSIGNOP);
3430     case '!':
3431         s++;
3432         tmp = *s++;
3433         if (tmp == '=')
3434             Eop(OP_NE);
3435         if (tmp == '~')
3436             PMop(OP_NOT);
3437         s--;
3438         OPERATOR('!');
3439     case '<':
3440         if (PL_expect != XOPERATOR) {
3441             if (s[1] != '<' && !strchr(s,'>'))
3442                 check_uni();
3443             if (s[1] == '<')
3444                 s = scan_heredoc(s);
3445             else
3446                 s = scan_inputsymbol(s);
3447             TERM(sublex_start());
3448         }
3449         s++;
3450         tmp = *s++;
3451         if (tmp == '<')
3452             SHop(OP_LEFT_SHIFT);
3453         if (tmp == '=') {
3454             tmp = *s++;
3455             if (tmp == '>')
3456                 Eop(OP_NCMP);
3457             s--;
3458             Rop(OP_LE);
3459         }
3460         s--;
3461         Rop(OP_LT);
3462     case '>':
3463         s++;
3464         tmp = *s++;
3465         if (tmp == '>')
3466             SHop(OP_RIGHT_SHIFT);
3467         if (tmp == '=')
3468             Rop(OP_GE);
3469         s--;
3470         Rop(OP_GT);
3471
3472     case '$':
3473         CLINE;
3474
3475         if (PL_expect == XOPERATOR) {
3476             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3477                 PL_expect = XTERM;
3478                 depcom();
3479                 return ','; /* grandfather non-comma-format format */
3480             }
3481         }
3482
3483         if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
3484             PL_tokenbuf[0] = '@';
3485             s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
3486                            sizeof PL_tokenbuf - 1, FALSE);
3487             if (PL_expect == XOPERATOR)
3488                 no_op("Array length", s);
3489             if (!PL_tokenbuf[1])
3490                 PREREF(DOLSHARP);
3491             PL_expect = XOPERATOR;
3492             PL_pending_ident = '#';
3493             TOKEN(DOLSHARP);
3494         }
3495
3496         PL_tokenbuf[0] = '$';
3497         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
3498                        sizeof PL_tokenbuf - 1, FALSE);
3499         if (PL_expect == XOPERATOR)
3500             no_op("Scalar", s);
3501         if (!PL_tokenbuf[1]) {
3502             if (s == PL_bufend)
3503                 yyerror("Final $ should be \\$ or $name");
3504             PREREF('$');
3505         }
3506
3507         /* This kludge not intended to be bulletproof. */
3508         if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
3509             yylval.opval = newSVOP(OP_CONST, 0,
3510                                    newSViv(PL_compiling.cop_arybase));
3511             yylval.opval->op_private = OPpCONST_ARYBASE;
3512             TERM(THING);
3513         }
3514
3515         d = s;
3516         tmp = (I32)*s;
3517         if (PL_lex_state == LEX_NORMAL)
3518             s = skipspace(s);
3519
3520         if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3521             char *t;
3522             if (*s == '[') {
3523                 PL_tokenbuf[0] = '@';
3524                 if (ckWARN(WARN_SYNTAX)) {
3525                     for(t = s + 1;
3526                         isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$';
3527                         t++) ;
3528                     if (*t++ == ',') {
3529                         PL_bufptr = skipspace(PL_bufptr);
3530                         while (t < PL_bufend && *t != ']')
3531                             t++;
3532                         Perl_warner(aTHX_ WARN_SYNTAX,
3533                                 "Multidimensional syntax %.*s not supported",
3534                                 (t - PL_bufptr) + 1, PL_bufptr);
3535                     }
3536                 }
3537             }
3538             else if (*s == '{') {
3539                 PL_tokenbuf[0] = '%';
3540                 if (ckWARN(WARN_SYNTAX) && strEQ(PL_tokenbuf+1, "SIG") &&
3541                     (t = strchr(s, '}')) && (t = strchr(t, '=')))
3542                 {
3543                     char tmpbuf[sizeof PL_tokenbuf];
3544                     STRLEN len;
3545                     for (t++; isSPACE(*t); t++) ;
3546                     if (isIDFIRST_lazy_if(t,UTF)) {
3547                         t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
3548                         for (; isSPACE(*t); t++) ;
3549                         if (*t == ';' && get_cv(tmpbuf, FALSE))
3550                             Perl_warner(aTHX_ WARN_SYNTAX,
3551                                 "You need to quote \"%s\"", tmpbuf);
3552                     }
3553                 }
3554             }
3555         }
3556
3557         PL_expect = XOPERATOR;
3558         if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
3559             bool islop = (PL_last_lop == PL_oldoldbufptr);
3560             if (!islop || PL_last_lop_op == OP_GREPSTART)
3561                 PL_expect = XOPERATOR;
3562             else if (strchr("$@\"'`q", *s))
3563                 PL_expect = XTERM;              /* e.g. print $fh "foo" */
3564             else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
3565                 PL_expect = XTERM;              /* e.g. print $fh &sub */
3566             else if (isIDFIRST_lazy_if(s,UTF)) {
3567                 char tmpbuf[sizeof PL_tokenbuf];
3568                 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3569                 if ((tmp = keyword(tmpbuf, len))) {
3570                     /* binary operators exclude handle interpretations */
3571                     switch (tmp) {
3572                     case -KEY_x:
3573                     case -KEY_eq:
3574                     case -KEY_ne:
3575                     case -KEY_gt:
3576                     case -KEY_lt:
3577                     case -KEY_ge:
3578                     case -KEY_le:
3579                     case -KEY_cmp:
3580                         break;
3581                     default:
3582                         PL_expect = XTERM;      /* e.g. print $fh length() */
3583                         break;
3584                     }
3585                 }
3586                 else {
3587                     GV *gv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
3588                     if (gv && GvCVu(gv))
3589                         PL_expect = XTERM;      /* e.g. print $fh subr() */
3590                 }
3591             }
3592             else if (isDIGIT(*s))
3593                 PL_expect = XTERM;              /* e.g. print $fh 3 */
3594             else if (*s == '.' && isDIGIT(s[1]))
3595                 PL_expect = XTERM;              /* e.g. print $fh .3 */
3596             else if (strchr("/?-+", *s) && !isSPACE(s[1]) && s[1] != '=')
3597                 PL_expect = XTERM;              /* e.g. print $fh -1 */
3598             else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=')
3599                 PL_expect = XTERM;              /* print $fh <<"EOF" */
3600         }
3601         PL_pending_ident = '$';
3602         TOKEN('$');
3603
3604     case '@':
3605         if (PL_expect == XOPERATOR)
3606             no_op("Array", s);
3607         PL_tokenbuf[0] = '@';
3608         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
3609         if (!PL_tokenbuf[1]) {
3610             if (s == PL_bufend)
3611                 yyerror("Final @ should be \\@ or @name");
3612             PREREF('@');
3613         }
3614         if (PL_lex_state == LEX_NORMAL)
3615             s = skipspace(s);
3616         if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3617             if (*s == '{')
3618                 PL_tokenbuf[0] = '%';
3619
3620             /* Warn about @ where they meant $. */
3621             if (ckWARN(WARN_SYNTAX)) {
3622                 if (*s == '[' || *s == '{') {
3623                     char *t = s + 1;
3624                     while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
3625                         t++;
3626                     if (*t == '}' || *t == ']') {
3627                         t++;
3628                         PL_bufptr = skipspace(PL_bufptr);
3629                         Perl_warner(aTHX_ WARN_SYNTAX,
3630                             "Scalar value %.*s better written as $%.*s",
3631                             t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1);
3632                     }
3633                 }
3634             }
3635         }
3636         PL_pending_ident = '@';
3637         TERM('@');
3638
3639     case '/':                   /* may either be division or pattern */
3640     case '?':                   /* may either be conditional or pattern */
3641         if (PL_expect != XOPERATOR) {
3642             /* Disable warning on "study /blah/" */
3643             if (PL_oldoldbufptr == PL_last_uni
3644                 && (*PL_last_uni != 's' || s - PL_last_uni < 5
3645                     || memNE(PL_last_uni, "study", 5)
3646                     || isALNUM_lazy_if(PL_last_uni+5,UTF)))
3647                 check_uni();
3648             s = scan_pat(s,OP_MATCH);
3649             TERM(sublex_start());
3650         }
3651         tmp = *s++;
3652         if (tmp == '/')
3653             Mop(OP_DIVIDE);
3654         OPERATOR(tmp);
3655
3656     case '.':
3657         if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
3658 #ifdef PERL_STRICT_CR
3659             && s[1] == '\n'
3660 #else
3661             && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
3662 #endif
3663             && (s == PL_linestart || s[-1] == '\n') )
3664         {
3665             PL_lex_formbrack = 0;
3666             PL_expect = XSTATE;
3667             goto rightbracket;
3668         }
3669         if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
3670             tmp = *s++;
3671             if (*s == tmp) {
3672                 s++;
3673                 if (*s == tmp) {
3674                     s++;
3675                     yylval.ival = OPf_SPECIAL;
3676                 }
3677                 else
3678                     yylval.ival = 0;
3679                 OPERATOR(DOTDOT);
3680             }
3681             if (PL_expect != XOPERATOR)
3682                 check_uni();
3683             Aop(OP_CONCAT);
3684         }
3685         /* FALL THROUGH */
3686     case '0': case '1': case '2': case '3': case '4':
3687     case '5': case '6': case '7': case '8': case '9':
3688         s = scan_num(s, &yylval);
3689         DEBUG_T( { PerlIO_printf(Perl_debug_log,
3690                     "### Saw number in '%s'\n", s);
3691         } )
3692         if (PL_expect == XOPERATOR)
3693             no_op("Number",s);
3694         TERM(THING);
3695
3696     case '\'':
3697         s = scan_str(s,FALSE,FALSE);
3698         DEBUG_T( { PerlIO_printf(Perl_debug_log,
3699                     "### Saw string before '%s'\n", s);
3700         } )
3701         if (PL_expect == XOPERATOR) {
3702             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3703                 PL_expect = XTERM;
3704                 depcom();
3705                 return ',';     /* grandfather non-comma-format format */
3706             }
3707             else
3708                 no_op("String",s);
3709         }
3710         if (!s)
3711             missingterm((char*)0);
3712         yylval.ival = OP_CONST;
3713         TERM(sublex_start());
3714
3715     case '"':
3716         s = scan_str(s,FALSE,FALSE);
3717         DEBUG_T( { PerlIO_printf(Perl_debug_log,
3718                     "### Saw string before '%s'\n", s);
3719         } )
3720         if (PL_expect == XOPERATOR) {
3721             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3722                 PL_expect = XTERM;
3723                 depcom();
3724                 return ',';     /* grandfather non-comma-format format */
3725             }
3726             else
3727                 no_op("String",s);
3728         }
3729         if (!s)
3730             missingterm((char*)0);
3731         yylval.ival = OP_CONST;
3732         for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
3733             if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
3734                 yylval.ival = OP_STRINGIFY;
3735                 break;
3736             }
3737         }
3738         TERM(sublex_start());
3739
3740     case '`':
3741         s = scan_str(s,FALSE,FALSE);
3742         DEBUG_T( { PerlIO_printf(Perl_debug_log,
3743                     "### Saw backtick string before '%s'\n", s);
3744         } )
3745         if (PL_expect == XOPERATOR)
3746             no_op("Backticks",s);
3747         if (!s)
3748             missingterm((char*)0);
3749         yylval.ival = OP_BACKTICK;
3750         set_csh();
3751         TERM(sublex_start());
3752
3753     case '\\':
3754         s++;
3755         if (ckWARN(WARN_SYNTAX) && PL_lex_inwhat && isDIGIT(*s))
3756             Perl_warner(aTHX_ WARN_SYNTAX,"Can't use \\%c to mean $%c in expression",
3757                         *s, *s);
3758         if (PL_expect == XOPERATOR)
3759             no_op("Backslash",s);
3760         OPERATOR(REFGEN);
3761
3762     case 'v':
3763         if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
3764             char *start = s;
3765             start++;
3766             start++;
3767             while (isDIGIT(*start) || *start == '_')
3768                 start++;
3769             if (*start == '.' && isDIGIT(start[1])) {
3770                 s = scan_num(s, &yylval);
3771                 TERM(THING);
3772             }
3773             /* avoid v123abc() or $h{v1}, allow C<print v10;> */
3774             else if (!isALPHA(*start) && (PL_expect == XTERM || PL_expect == XREF)) {
3775                 char c = *start;
3776                 GV *gv;
3777                 *start = '\0';
3778                 gv = gv_fetchpv(s, FALSE, SVt_PVCV);
3779                 *start = c;
3780                 if (!gv) {
3781                     s = scan_num(s, &yylval);
3782                     TERM(THING);
3783                 }
3784             }
3785         }
3786         goto keylookup;
3787     case 'x':
3788         if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
3789             s++;
3790             Mop(OP_REPEAT);
3791         }
3792         goto keylookup;
3793
3794     case '_':
3795     case 'a': case 'A':
3796     case 'b': case 'B':
3797     case 'c': case 'C':
3798     case 'd': case 'D':
3799     case 'e': case 'E':
3800     case 'f': case 'F':
3801     case 'g': case 'G':
3802     case 'h': case 'H':
3803     case 'i': case 'I':
3804     case 'j': case 'J':
3805     case 'k': case 'K':
3806     case 'l': case 'L':
3807     case 'm': case 'M':
3808     case 'n': case 'N':
3809     case 'o': case 'O':
3810     case 'p': case 'P':
3811     case 'q': case 'Q':
3812     case 'r': case 'R':
3813     case 's': case 'S':
3814     case 't': case 'T':
3815     case 'u': case 'U':
3816               case 'V':
3817     case 'w': case 'W':
3818               case 'X':
3819     case 'y': case 'Y':
3820     case 'z': case 'Z':
3821
3822       keylookup: {
3823         gv = Nullgv;
3824         gvp = 0;
3825
3826         PL_bufptr = s;
3827         s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3828
3829         /* Some keywords can be followed by any delimiter, including ':' */
3830         tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
3831                (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
3832                              (PL_tokenbuf[0] == 'q' &&
3833                               strchr("qwxr", PL_tokenbuf[1])))));
3834
3835         /* x::* is just a word, unless x is "CORE" */
3836         if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
3837             goto just_a_word;
3838
3839         d = s;
3840         while (d < PL_bufend && isSPACE(*d))
3841                 d++;    /* no comments skipped here, or s### is misparsed */
3842
3843         /* Is this a label? */
3844         if (!tmp && PL_expect == XSTATE
3845               && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
3846             s = d + 1;
3847             yylval.pval = savepv(PL_tokenbuf);
3848             CLINE;
3849             TOKEN(LABEL);
3850         }
3851
3852         /* Check for keywords */
3853         tmp = keyword(PL_tokenbuf, len);
3854
3855         /* Is this a word before a => operator? */
3856         if (*d == '=' && d[1] == '>') {
3857             CLINE;
3858             yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf,0));
3859             yylval.opval->op_private = OPpCONST_BARE;
3860             if (UTF && !IN_BYTE && is_utf8_string((U8*)PL_tokenbuf, len))
3861               SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
3862             TERM(WORD);
3863         }
3864
3865         if (tmp < 0) {                  /* second-class keyword? */
3866             GV *ogv = Nullgv;   /* override (winner) */
3867             GV *hgv = Nullgv;   /* hidden (loser) */
3868             if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
3869                 CV *cv;
3870                 if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) &&
3871                     (cv = GvCVu(gv)))
3872                 {
3873                     if (GvIMPORTED_CV(gv))
3874                         ogv = gv;
3875                     else if (! CvMETHOD(cv))
3876                         hgv = gv;
3877                 }
3878                 if (!ogv &&
3879                     (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
3880                     (gv = *gvp) != (GV*)&PL_sv_undef &&
3881                     GvCVu(gv) && GvIMPORTED_CV(gv))
3882                 {
3883                     ogv = gv;
3884                 }
3885             }
3886             if (ogv) {
3887                 tmp = 0;                /* overridden by import or by GLOBAL */
3888             }
3889             else if (gv && !gvp
3890                      && -tmp==KEY_lock  /* XXX generalizable kludge */
3891                      && GvCVu(gv)
3892                      && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE))
3893             {
3894                 tmp = 0;                /* any sub overrides "weak" keyword */
3895             }
3896             else {                      /* no override */
3897                 tmp = -tmp;
3898                 gv = Nullgv;
3899                 gvp = 0;
3900                 if (ckWARN(WARN_AMBIGUOUS) && hgv
3901                     && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */
3902                     Perl_warner(aTHX_ WARN_AMBIGUOUS,
3903                         "Ambiguous call resolved as CORE::%s(), %s",
3904                          GvENAME(hgv), "qualify as such or use &");
3905             }
3906         }
3907
3908       reserved_word:
3909         switch (tmp) {
3910
3911         default:                        /* not a keyword */
3912           just_a_word: {
3913                 SV *sv;
3914                 char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
3915
3916                 /* Get the rest if it looks like a package qualifier */
3917
3918                 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
3919                     STRLEN morelen;
3920                     s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
3921                                   TRUE, &morelen);
3922                     if (!morelen)
3923                         Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
3924                                 *s == '\'' ? "'" : "::");
3925                     len += morelen;
3926                 }
3927
3928                 if (PL_expect == XOPERATOR) {
3929                     if (PL_bufptr == PL_linestart) {
3930                         CopLINE_dec(PL_curcop);
3931                         Perl_warner(aTHX_ WARN_SEMICOLON, PL_warn_nosemi);
3932                         CopLINE_inc(PL_curcop);
3933                     }
3934                     else
3935                         no_op("Bareword",s);
3936                 }
3937
3938                 /* Look for a subroutine with this name in current package,
3939                    unless name is "Foo::", in which case Foo is a bearword
3940                    (and a package name). */
3941
3942                 if (len > 2 &&
3943                     PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
3944                 {
3945                     if (ckWARN(WARN_BAREWORD) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV))
3946                         Perl_warner(aTHX_ WARN_BAREWORD,
3947                             "Bareword \"%s\" refers to nonexistent package",
3948                              PL_tokenbuf);
3949                     len -= 2;
3950                     PL_tokenbuf[len] = '\0';
3951                     gv = Nullgv;
3952                     gvp = 0;
3953                 }
3954                 else {
3955                     len = 0;
3956                     if (!gv)
3957                         gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV);
3958                 }
3959
3960                 /* if we saw a global override before, get the right name */
3961
3962                 if (gvp) {
3963                     sv = newSVpvn("CORE::GLOBAL::",14);
3964                     sv_catpv(sv,PL_tokenbuf);
3965                 }
3966                 else
3967                     sv = newSVpv(PL_tokenbuf,0);
3968
3969                 /* Presume this is going to be a bareword of some sort. */
3970
3971                 CLINE;
3972                 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3973                 yylval.opval->op_private = OPpCONST_BARE;
3974
3975                 /* And if "Foo::", then that's what it certainly is. */
3976
3977                 if (len)
3978                     goto safe_bareword;
3979
3980                 /* See if it's the indirect object for a list operator. */
3981
3982                 if (PL_oldoldbufptr &&
3983                     PL_oldoldbufptr < PL_bufptr &&
3984                     (PL_oldoldbufptr == PL_last_lop
3985                      || PL_oldoldbufptr == PL_last_uni) &&
3986                     /* NO SKIPSPACE BEFORE HERE! */
3987                     (PL_expect == XREF ||
3988                      ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
3989                 {
3990                     bool immediate_paren = *s == '(';
3991
3992                     /* (Now we can afford to cross potential line boundary.) */
3993                     s = skipspace(s);
3994
3995                     /* Two barewords in a row may indicate method call. */
3996
3997                     if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp=intuit_method(s,gv)))
3998                         return tmp;
3999
4000                     /* If not a declared subroutine, it's an indirect object. */
4001                     /* (But it's an indir obj regardless for sort.) */
4002
4003                     if ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
4004                          ((!gv || !GvCVu(gv)) &&
4005                         (PL_last_lop_op != OP_MAPSTART &&
4006                          PL_last_lop_op != OP_GREPSTART))))
4007                     {
4008                         PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
4009                         goto bareword;
4010                     }
4011                 }
4012
4013
4014                 PL_expect = XOPERATOR;
4015                 s = skipspace(s);
4016
4017                 /* Is this a word before a => operator? */
4018                 if (*s == '=' && s[1] == '>') {
4019                     CLINE;
4020                     sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
4021                     if (UTF && !IN_BYTE && is_utf8_string((U8*)PL_tokenbuf, len))
4022                       SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
4023                     TERM(WORD);
4024                 }
4025
4026                 /* If followed by a paren, it's certainly a subroutine. */
4027                 if (*s == '(') {
4028                     CLINE;
4029                     if (gv && GvCVu(gv)) {
4030                         for (d = s + 1; SPACE_OR_TAB(*d); d++) ;
4031                         if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) {
4032                             s = d + 1;
4033                             goto its_constant;
4034                         }
4035                     }
4036                     PL_nextval[PL_nexttoke].opval = yylval.opval;
4037                     PL_expect = XOPERATOR;
4038                     force_next(WORD);
4039                     yylval.ival = 0;
4040                     TOKEN('&');
4041                 }
4042
4043                 /* If followed by var or block, call it a method (unless sub) */
4044
4045                 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
4046                     PL_last_lop = PL_oldbufptr;
4047                     PL_last_lop_op = OP_METHOD;
4048                     PREBLOCK(METHOD);
4049                 }
4050
4051                 /* If followed by a bareword, see if it looks like indir obj. */
4052
4053                 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp = intuit_method(s,gv)))
4054                     return tmp;
4055
4056                 /* Not a method, so call it a subroutine (if defined) */
4057
4058                 if (gv && GvCVu(gv)) {
4059                     CV* cv;
4060                     if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
4061                         Perl_warner(aTHX_ WARN_AMBIGUOUS,
4062                                 "Ambiguous use of -%s resolved as -&%s()",
4063                                 PL_tokenbuf, PL_tokenbuf);
4064                     /* Check for a constant sub */
4065                     cv = GvCV(gv);
4066                     if ((sv = cv_const_sv(cv))) {
4067                   its_constant:
4068                         SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
4069                         ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
4070                         yylval.opval->op_private = 0;
4071                         TOKEN(WORD);
4072                     }
4073
4074                     /* Resolve to GV now. */
4075                     op_free(yylval.opval);
4076                     yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
4077                     yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
4078                     PL_last_lop = PL_oldbufptr;
4079                     PL_last_lop_op = OP_ENTERSUB;
4080                     /* Is there a prototype? */
4081                     if (SvPOK(cv)) {
4082                         STRLEN len;
4083                         char *proto = SvPV((SV*)cv, len);
4084                         if (!len)
4085                             TERM(FUNC0SUB);
4086                         if (strEQ(proto, "$"))
4087                             OPERATOR(UNIOPSUB);
4088                         if (*proto == '&' && *s == '{') {
4089                             sv_setpv(PL_subname,"__ANON__");
4090                             PREBLOCK(LSTOPSUB);
4091                         }
4092                     }
4093                     PL_nextval[PL_nexttoke].opval = yylval.opval;
4094                     PL_expect = XTERM;
4095                     force_next(WORD);
4096                     TOKEN(NOAMP);
4097                 }
4098
4099                 /* Call it a bare word */
4100
4101                 if (PL_hints & HINT_STRICT_SUBS)
4102                     yylval.opval->op_private |= OPpCONST_STRICT;
4103                 else {
4104                 bareword:
4105                     if (ckWARN(WARN_RESERVED)) {
4106                         if (lastchar != '-') {
4107                             for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ;
4108                             if (!*d)
4109                                 Perl_warner(aTHX_ WARN_RESERVED, PL_warn_reserved,
4110                                        PL_tokenbuf);
4111                         }
4112                     }
4113                 }
4114
4115             safe_bareword:
4116                 if (lastchar && strchr("*%&", lastchar) && ckWARN_d(WARN_AMBIGUOUS)) {
4117                     Perl_warner(aTHX_ WARN_AMBIGUOUS,
4118                         "Operator or semicolon missing before %c%s",
4119                         lastchar, PL_tokenbuf);
4120                     Perl_warner(aTHX_ WARN_AMBIGUOUS,
4121                         "Ambiguous use of %c resolved as operator %c",
4122                         lastchar, lastchar);
4123                 }
4124                 TOKEN(WORD);
4125             }
4126
4127         case KEY___FILE__:
4128             yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4129                                         newSVpv(CopFILE(PL_curcop),0));
4130             TERM(THING);
4131
4132         case KEY___LINE__:
4133             yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4134                                     Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
4135             TERM(THING);
4136
4137         case KEY___PACKAGE__:
4138             yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4139                                         (PL_curstash
4140                                          ? newSVsv(PL_curstname)
4141                                          : &PL_sv_undef));
4142             TERM(THING);
4143
4144         case KEY___DATA__:
4145         case KEY___END__: {
4146             GV *gv;
4147
4148             /*SUPPRESS 560*/
4149             if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
4150                 char *pname = "main";
4151                 if (PL_tokenbuf[2] == 'D')
4152                     pname = HvNAME(PL_curstash ? PL_curstash : PL_defstash);
4153                 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO);
4154                 GvMULTI_on(gv);
4155                 if (!GvIO(gv))
4156                     GvIOp(gv) = newIO();
4157                 IoIFP(GvIOp(gv)) = PL_rsfp;
4158 #if defined(HAS_FCNTL) && defined(F_SETFD)
4159                 {
4160                     int fd = PerlIO_fileno(PL_rsfp);
4161                     fcntl(fd,F_SETFD,fd >= 3);
4162                 }
4163 #endif
4164                 /* Mark this internal pseudo-handle as clean */
4165                 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
4166                 if (PL_preprocess)
4167                     IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
4168                 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
4169                     IoTYPE(GvIOp(gv)) = IoTYPE_STD;
4170                 else
4171                     IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
4172 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
4173                 /* if the script was opened in binmode, we need to revert
4174                  * it to text mode for compatibility; but only iff it has CRs
4175                  * XXX this is a questionable hack at best. */
4176                 if (PL_bufend-PL_bufptr > 2
4177                     && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
4178                 {
4179                     Off_t loc = 0;
4180                     if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
4181                         loc = PerlIO_tell(PL_rsfp);
4182                         (void)PerlIO_seek(PL_rsfp, 0L, 0);
4183                     }
4184                     if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
4185                         if (loc > 0)
4186                             PerlIO_seek(PL_rsfp, loc, 0);
4187                     }
4188                 }
4189 #endif
4190 #ifdef PERLIO_LAYERS
4191                 if (UTF && !IN_BYTE)
4192                     PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
4193 #endif
4194                 PL_rsfp = Nullfp;
4195             }
4196             goto fake_eof;
4197         }
4198
4199         case KEY_AUTOLOAD:
4200         case KEY_DESTROY:
4201         case KEY_BEGIN:
4202         case KEY_CHECK:
4203         case KEY_INIT:
4204         case KEY_END:
4205             if (PL_expect == XSTATE) {
4206                 s = PL_bufptr;
4207                 goto really_sub;
4208             }
4209             goto just_a_word;
4210
4211         case KEY_CORE:
4212             if (*s == ':' && s[1] == ':') {
4213                 s += 2;
4214                 d = s;
4215                 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4216                 if (!(tmp = keyword(PL_tokenbuf, len)))
4217                     Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
4218                 if (tmp < 0)
4219                     tmp = -tmp;
4220                 goto reserved_word;
4221             }
4222             goto just_a_word;
4223
4224         case KEY_abs:
4225             UNI(OP_ABS);
4226
4227         case KEY_alarm:
4228             UNI(OP_ALARM);
4229
4230         case KEY_accept:
4231             LOP(OP_ACCEPT,XTERM);
4232
4233         case KEY_and:
4234             OPERATOR(ANDOP);
4235
4236         case KEY_atan2:
4237             LOP(OP_ATAN2,XTERM);
4238
4239         case KEY_bind:
4240             LOP(OP_BIND,XTERM);
4241
4242         case KEY_binmode:
4243             LOP(OP_BINMODE,XTERM);
4244
4245         case KEY_bless:
4246             LOP(OP_BLESS,XTERM);
4247
4248         case KEY_chop:
4249             UNI(OP_CHOP);
4250
4251         case KEY_continue:
4252             PREBLOCK(CONTINUE);
4253
4254         case KEY_chdir:
4255             (void)gv_fetchpv("ENV",TRUE, SVt_PVHV);     /* may use HOME */
4256             UNI(OP_CHDIR);
4257
4258         case KEY_close:
4259             UNI(OP_CLOSE);
4260
4261         case KEY_closedir:
4262             UNI(OP_CLOSEDIR);
4263
4264         case KEY_cmp:
4265             Eop(OP_SCMP);
4266
4267         case KEY_caller:
4268             UNI(OP_CALLER);
4269
4270         case KEY_crypt:
4271 #ifdef FCRYPT
4272             if (!PL_cryptseen) {
4273                 PL_cryptseen = TRUE;
4274                 init_des();
4275             }
4276 #endif
4277             LOP(OP_CRYPT,XTERM);
4278
4279         case KEY_chmod:
4280             if (ckWARN(WARN_CHMOD)) {
4281                 for (d = s; d < PL_bufend && (isSPACE(*d) || *d == '('); d++) ;
4282                 if (*d != '0' && isDIGIT(*d))
4283                     Perl_warner(aTHX_ WARN_CHMOD,
4284                                 "chmod() mode argument is missing initial 0");
4285             }
4286             LOP(OP_CHMOD,XTERM);
4287
4288         case KEY_chown:
4289             LOP(OP_CHOWN,XTERM);
4290
4291         case KEY_connect:
4292             LOP(OP_CONNECT,XTERM);
4293
4294         case KEY_chr:
4295             UNI(OP_CHR);
4296
4297         case KEY_cos:
4298             UNI(OP_COS);
4299
4300         case KEY_chroot:
4301             UNI(OP_CHROOT);
4302
4303         case KEY_do:
4304             s = skipspace(s);
4305             if (*s == '{')
4306                 PRETERMBLOCK(DO);
4307             if (*s != '\'')
4308                 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4309             OPERATOR(DO);
4310
4311         case KEY_die:
4312             PL_hints |= HINT_BLOCK_SCOPE;
4313             LOP(OP_DIE,XTERM);
4314
4315         case KEY_defined:
4316             UNI(OP_DEFINED);
4317
4318         case KEY_delete:
4319             UNI(OP_DELETE);
4320
4321         case KEY_dbmopen:
4322             gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
4323             LOP(OP_DBMOPEN,XTERM);
4324
4325         case KEY_dbmclose:
4326             UNI(OP_DBMCLOSE);
4327
4328         case KEY_dump:
4329             s = force_word(s,WORD,TRUE,FALSE,FALSE);
4330             LOOPX(OP_DUMP);
4331
4332         case KEY_else:
4333             PREBLOCK(ELSE);
4334
4335         case KEY_elsif:
4336             yylval.ival = CopLINE(PL_curcop);
4337             OPERATOR(ELSIF);
4338
4339         case KEY_eq:
4340             Eop(OP_SEQ);
4341
4342         case KEY_exists:
4343             UNI(OP_EXISTS);
4344         
4345         case KEY_exit:
4346             UNI(OP_EXIT);
4347
4348         case KEY_eval:
4349             s = skipspace(s);
4350             PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
4351             UNIBRACK(OP_ENTEREVAL);
4352
4353         case KEY_eof:
4354             UNI(OP_EOF);
4355
4356         case KEY_exp:
4357             UNI(OP_EXP);
4358
4359         case KEY_each:
4360             UNI(OP_EACH);
4361
4362         case KEY_exec:
4363             set_csh();
4364             LOP(OP_EXEC,XREF);
4365
4366         case KEY_endhostent:
4367             FUN0(OP_EHOSTENT);
4368
4369         case KEY_endnetent:
4370             FUN0(OP_ENETENT);
4371
4372         case KEY_endservent:
4373             FUN0(OP_ESERVENT);
4374
4375         case KEY_endprotoent:
4376             FUN0(OP_EPROTOENT);
4377
4378         case KEY_endpwent:
4379             FUN0(OP_EPWENT);
4380
4381         case KEY_endgrent:
4382             FUN0(OP_EGRENT);
4383
4384         case KEY_for:
4385         case KEY_foreach:
4386             yylval.ival = CopLINE(PL_curcop);
4387             s = skipspace(s);
4388             if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
4389                 char *p = s;
4390                 if ((PL_bufend - p) >= 3 &&
4391                     strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
4392                     p += 2;
4393                 else if ((PL_bufend - p) >= 4 &&
4394                     strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
4395                     p += 3;
4396                 p = skipspace(p);
4397                 if (isIDFIRST_lazy_if(p,UTF)) {
4398                     p = scan_ident(p, PL_bufend,
4399                         PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4400                     p = skipspace(p);
4401                 }
4402                 if (*p != '$')
4403                     Perl_croak(aTHX_ "Missing $ on loop variable");
4404             }
4405             OPERATOR(FOR);
4406
4407         case KEY_formline:
4408             LOP(OP_FORMLINE,XTERM);
4409
4410         case KEY_fork:
4411             FUN0(OP_FORK);
4412
4413         case KEY_fcntl:
4414             LOP(OP_FCNTL,XTERM);
4415
4416         case KEY_fileno:
4417             UNI(OP_FILENO);
4418
4419         case KEY_flock:
4420             LOP(OP_FLOCK,XTERM);
4421
4422         case KEY_gt:
4423             Rop(OP_SGT);
4424
4425         case KEY_ge:
4426             Rop(OP_SGE);
4427
4428         case KEY_grep:
4429             LOP(OP_GREPSTART, XREF);
4430
4431         case KEY_goto:
4432             s = force_word(s,WORD,TRUE,FALSE,FALSE);
4433             LOOPX(OP_GOTO);
4434
4435         case KEY_gmtime:
4436             UNI(OP_GMTIME);
4437
4438         case KEY_getc:
4439             UNI(OP_GETC);
4440
4441         case KEY_getppid:
4442             FUN0(OP_GETPPID);
4443
4444         case KEY_getpgrp:
4445             UNI(OP_GETPGRP);
4446
4447         case KEY_getpriority:
4448             LOP(OP_GETPRIORITY,XTERM);
4449
4450         case KEY_getprotobyname:
4451             UNI(OP_GPBYNAME);
4452
4453         case KEY_getprotobynumber:
4454             LOP(OP_GPBYNUMBER,XTERM);
4455
4456         case KEY_getprotoent:
4457             FUN0(OP_GPROTOENT);
4458
4459         case KEY_getpwent:
4460             FUN0(OP_GPWENT);
4461
4462         case KEY_getpwnam:
4463             UNI(OP_GPWNAM);
4464
4465         case KEY_getpwuid:
4466             UNI(OP_GPWUID);
4467
4468         case KEY_getpeername:
4469             UNI(OP_GETPEERNAME);
4470
4471         case KEY_gethostbyname:
4472             UNI(OP_GHBYNAME);
4473
4474         case KEY_gethostbyaddr:
4475             LOP(OP_GHBYADDR,XTERM);
4476
4477         case KEY_gethostent:
4478             FUN0(OP_GHOSTENT);
4479
4480         case KEY_getnetbyname:
4481             UNI(OP_GNBYNAME);
4482
4483         case KEY_getnetbyaddr:
4484             LOP(OP_GNBYADDR,XTERM);
4485
4486         case KEY_getnetent:
4487             FUN0(OP_GNETENT);
4488
4489         case KEY_getservbyname:
4490             LOP(OP_GSBYNAME,XTERM);
4491
4492         case KEY_getservbyport:
4493             LOP(OP_GSBYPORT,XTERM);
4494
4495         case KEY_getservent:
4496             FUN0(OP_GSERVENT);
4497
4498         case KEY_getsockname:
4499             UNI(OP_GETSOCKNAME);
4500
4501         case KEY_getsockopt:
4502             LOP(OP_GSOCKOPT,XTERM);
4503
4504         case KEY_getgrent:
4505             FUN0(OP_GGRENT);
4506
4507         case KEY_getgrnam:
4508             UNI(OP_GGRNAM);
4509
4510         case KEY_getgrgid:
4511             UNI(OP_GGRGID);
4512
4513         case KEY_getlogin:
4514             FUN0(OP_GETLOGIN);
4515
4516         case KEY_glob:
4517             set_csh();
4518             LOP(OP_GLOB,XTERM);
4519
4520         case KEY_hex:
4521             UNI(OP_HEX);
4522
4523         case KEY_if:
4524             yylval.ival = CopLINE(PL_curcop);
4525             OPERATOR(IF);
4526
4527         case KEY_index:
4528             LOP(OP_INDEX,XTERM);
4529
4530         case KEY_int:
4531             UNI(OP_INT);
4532
4533         case KEY_ioctl:
4534             LOP(OP_IOCTL,XTERM);
4535
4536         case KEY_join:
4537             LOP(OP_JOIN,XTERM);
4538
4539         case KEY_keys:
4540             UNI(OP_KEYS);
4541
4542         case KEY_kill:
4543             LOP(OP_KILL,XTERM);
4544
4545         case KEY_last:
4546             s = force_word(s,WORD,TRUE,FALSE,FALSE);
4547             LOOPX(OP_LAST);
4548         
4549         case KEY_lc:
4550             UNI(OP_LC);
4551
4552         case KEY_lcfirst:
4553             UNI(OP_LCFIRST);
4554
4555         case KEY_local:
4556             yylval.ival = 0;
4557             OPERATOR(LOCAL);
4558
4559         case KEY_length:
4560             UNI(OP_LENGTH);
4561
4562         case KEY_lt:
4563             Rop(OP_SLT);
4564
4565         case KEY_le:
4566             Rop(OP_SLE);
4567
4568         case KEY_localtime:
4569             UNI(OP_LOCALTIME);
4570
4571         case KEY_log:
4572             UNI(OP_LOG);
4573
4574         case KEY_link:
4575             LOP(OP_LINK,XTERM);
4576
4577         case KEY_listen:
4578             LOP(OP_LISTEN,XTERM);
4579
4580         case KEY_lock:
4581             UNI(OP_LOCK);
4582
4583         case KEY_lstat:
4584             UNI(OP_LSTAT);
4585
4586         case KEY_m:
4587             s = scan_pat(s,OP_MATCH);
4588             TERM(sublex_start());
4589
4590         case KEY_map:
4591             LOP(OP_MAPSTART, XREF);
4592
4593         case KEY_mkdir:
4594             LOP(OP_MKDIR,XTERM);
4595
4596         case KEY_msgctl:
4597             LOP(OP_MSGCTL,XTERM);
4598
4599         case KEY_msgget:
4600             LOP(OP_MSGGET,XTERM);
4601
4602         case KEY_msgrcv:
4603             LOP(OP_MSGRCV,XTERM);
4604
4605         case KEY_msgsnd:
4606             LOP(OP_MSGSND,XTERM);
4607
4608         case KEY_our:
4609         case KEY_my:
4610             PL_in_my = tmp;
4611             s = skipspace(s);
4612             if (isIDFIRST_lazy_if(s,UTF)) {
4613                 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
4614                 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
4615                     goto really_sub;
4616                 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
4617                 if (!PL_in_my_stash) {
4618                     char tmpbuf[1024];
4619                     PL_bufptr = s;
4620                     sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
4621                     yyerror(tmpbuf);
4622                 }
4623             }
4624             yylval.ival = 1;
4625             OPERATOR(MY);
4626
4627         case KEY_next:
4628             s = force_word(s,WORD,TRUE,FALSE,FALSE);
4629             LOOPX(OP_NEXT);
4630
4631         case KEY_ne:
4632             Eop(OP_SNE);
4633
4634         case KEY_no:
4635             if (PL_expect != XSTATE)
4636                 yyerror("\"no\" not allowed in expression");
4637             s = force_word(s,WORD,FALSE,TRUE,FALSE);
4638             s = force_version(s);
4639             yylval.ival = 0;
4640             OPERATOR(USE);
4641
4642         case KEY_not:
4643             if (*s == '(' || (s = skipspace(s), *s == '('))
4644                 FUN1(OP_NOT);
4645             else
4646                 OPERATOR(NOTOP);
4647
4648         case KEY_open:
4649             s = skipspace(s);
4650             if (isIDFIRST_lazy_if(s,UTF)) {
4651                 char *t;
4652                 for (d = s; isALNUM_lazy_if(d,UTF); d++) ;
4653                 t = skipspace(d);
4654                 if (strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE))
4655                     Perl_warner(aTHX_ WARN_PRECEDENCE,
4656                            "Precedence problem: open %.*s should be open(%.*s)",
4657                             d-s,s, d-s,s);
4658             }
4659             LOP(OP_OPEN,XTERM);
4660
4661         case KEY_or:
4662             yylval.ival = OP_OR;
4663             OPERATOR(OROP);
4664
4665         case KEY_ord:
4666             UNI(OP_ORD);
4667
4668         case KEY_oct:
4669             UNI(OP_OCT);
4670
4671         case KEY_opendir:
4672             LOP(OP_OPEN_DIR,XTERM);
4673
4674         case KEY_print:
4675             checkcomma(s,PL_tokenbuf,"filehandle");
4676             LOP(OP_PRINT,XREF);
4677
4678         case KEY_printf:
4679             checkcomma(s,PL_tokenbuf,"filehandle");
4680             LOP(OP_PRTF,XREF);
4681
4682         case KEY_prototype:
4683             UNI(OP_PROTOTYPE);
4684
4685         case KEY_push:
4686             LOP(OP_PUSH,XTERM);
4687
4688         case KEY_pop:
4689             UNI(OP_POP);
4690
4691         case KEY_pos:
4692             UNI(OP_POS);
4693         
4694         case KEY_pack:
4695             LOP(OP_PACK,XTERM);
4696
4697         case KEY_package:
4698             s = force_word(s,WORD,FALSE,TRUE,FALSE);
4699             OPERATOR(PACKAGE);
4700
4701         case KEY_pipe:
4702             LOP(OP_PIPE_OP,XTERM);
4703
4704         case KEY_q:
4705             s = scan_str(s,FALSE,FALSE);
4706             if (!s)
4707                 missingterm((char*)0);
4708             yylval.ival = OP_CONST;
4709             TERM(sublex_start());
4710
4711         case KEY_quotemeta:
4712             UNI(OP_QUOTEMETA);
4713
4714         case KEY_qw:
4715             s = scan_str(s,FALSE,FALSE);
4716             if (!s)
4717                 missingterm((char*)0);
4718             force_next(')');
4719             if (SvCUR(PL_lex_stuff)) {
4720                 OP *words = Nullop;
4721                 int warned = 0;
4722                 d = SvPV_force(PL_lex_stuff, len);
4723                 while (len) {
4724                     SV *sv;
4725                     for (; isSPACE(*d) && len; --len, ++d) ;
4726                     if (len) {
4727                         char *b = d;
4728                         if (!warned && ckWARN(WARN_QW)) {
4729                             for (; !isSPACE(*d) && len; --len, ++d) {
4730                                 if (*d == ',') {
4731                                     Perl_warner(aTHX_ WARN_QW,
4732                                         "Possible attempt to separate words with commas");
4733                                     ++warned;
4734                                 }
4735                                 else if (*d == '#') {
4736                                     Perl_warner(aTHX_ WARN_QW,
4737                                         "Possible attempt to put comments in qw() list");
4738                                     ++warned;
4739                                 }
4740                             }
4741                         }
4742                         else {
4743                             for (; !isSPACE(*d) && len; --len, ++d) ;
4744                         }
4745                         sv = newSVpvn(b, d-b);
4746                         if (DO_UTF8(PL_lex_stuff))
4747                             SvUTF8_on(sv);
4748                         words = append_elem(OP_LIST, words,
4749                                             newSVOP(OP_CONST, 0, tokeq(sv)));
4750                     }
4751                 }
4752                 if (words) {
4753                     PL_nextval[PL_nexttoke].opval = words;
4754                     force_next(THING);
4755                 }
4756             }
4757             if (PL_lex_stuff) {
4758                 SvREFCNT_dec(PL_lex_stuff);
4759                 PL_lex_stuff = Nullsv;
4760             }
4761             PL_expect = XTERM;
4762             TOKEN('(');
4763
4764         case KEY_qq:
4765             s = scan_str(s,FALSE,FALSE);
4766             if (!s)
4767                 missingterm((char*)0);
4768             yylval.ival = OP_STRINGIFY;
4769             if (SvIVX(PL_lex_stuff) == '\'')
4770                 SvIVX(PL_lex_stuff) = 0;        /* qq'$foo' should intepolate */
4771             TERM(sublex_start());
4772
4773         case KEY_qr:
4774             s = scan_pat(s,OP_QR);
4775             TERM(sublex_start());
4776
4777         case KEY_qx:
4778             s = scan_str(s,FALSE,FALSE);
4779             if (!s)
4780                 missingterm((char*)0);
4781             yylval.ival = OP_BACKTICK;
4782             set_csh();
4783             TERM(sublex_start());
4784
4785         case KEY_return:
4786             OLDLOP(OP_RETURN);
4787
4788         case KEY_require:
4789             s = skipspace(s);
4790             if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
4791                 s = force_version(s);
4792             }
4793             else {
4794                 *PL_tokenbuf = '\0';
4795                 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4796                 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
4797                     gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
4798                 else if (*s == '<')
4799                     yyerror("<> should be quotes");
4800             }
4801             UNI(OP_REQUIRE);
4802
4803         case KEY_reset:
4804             UNI(OP_RESET);
4805
4806         case KEY_redo:
4807             s = force_word(s,WORD,TRUE,FALSE,FALSE);
4808             LOOPX(OP_REDO);
4809
4810         case KEY_rename:
4811             LOP(OP_RENAME,XTERM);
4812
4813         case KEY_rand:
4814             UNI(OP_RAND);
4815
4816         case KEY_rmdir:
4817             UNI(OP_RMDIR);
4818
4819         case KEY_rindex:
4820             LOP(OP_RINDEX,XTERM);
4821
4822         case KEY_read:
4823             LOP(OP_READ,XTERM);
4824
4825         case KEY_readdir:
4826             UNI(OP_READDIR);
4827
4828         case KEY_readline:
4829             set_csh();
4830             UNI(OP_READLINE);
4831
4832         case KEY_readpipe:
4833             set_csh();
4834             UNI(OP_BACKTICK);
4835
4836         case KEY_rewinddir:
4837             UNI(OP_REWINDDIR);
4838
4839         case KEY_recv:
4840             LOP(OP_RECV,XTERM);
4841
4842         case KEY_reverse:
4843             LOP(OP_REVERSE,XTERM);
4844
4845         case KEY_readlink:
4846             UNI(OP_READLINK);
4847
4848         case KEY_ref:
4849             UNI(OP_REF);
4850
4851         case KEY_s:
4852             s = scan_subst(s);
4853             if (yylval.opval)
4854                 TERM(sublex_start());
4855             else
4856                 TOKEN(1);       /* force error */
4857
4858         case KEY_chomp:
4859             UNI(OP_CHOMP);
4860         
4861         case KEY_scalar:
4862             UNI(OP_SCALAR);
4863
4864         case KEY_select:
4865             LOP(OP_SELECT,XTERM);
4866
4867         case KEY_seek:
4868             LOP(OP_SEEK,XTERM);
4869
4870         case KEY_semctl:
4871             LOP(OP_SEMCTL,XTERM);
4872
4873         case KEY_semget:
4874             LOP(OP_SEMGET,XTERM);
4875
4876         case KEY_semop:
4877             LOP(OP_SEMOP,XTERM);
4878
4879         case KEY_send:
4880             LOP(OP_SEND,XTERM);
4881
4882         case KEY_setpgrp:
4883             LOP(OP_SETPGRP,XTERM);
4884
4885         case KEY_setpriority:
4886             LOP(OP_SETPRIORITY,XTERM);
4887
4888         case KEY_sethostent:
4889             UNI(OP_SHOSTENT);
4890
4891         case KEY_setnetent:
4892             UNI(OP_SNETENT);
4893
4894         case KEY_setservent:
4895             UNI(OP_SSERVENT);
4896
4897         case KEY_setprotoent:
4898             UNI(OP_SPROTOENT);
4899
4900         case KEY_setpwent:
4901             FUN0(OP_SPWENT);
4902
4903         case KEY_setgrent:
4904             FUN0(OP_SGRENT);
4905
4906         case KEY_seekdir:
4907             LOP(OP_SEEKDIR,XTERM);
4908
4909         case KEY_setsockopt:
4910             LOP(OP_SSOCKOPT,XTERM);
4911
4912         case KEY_shift:
4913             UNI(OP_SHIFT);
4914
4915         case KEY_shmctl:
4916             LOP(OP_SHMCTL,XTERM);
4917
4918         case KEY_shmget:
4919             LOP(OP_SHMGET,XTERM);
4920
4921         case KEY_shmread:
4922             LOP(OP_SHMREAD,XTERM);
4923
4924         case KEY_shmwrite:
4925             LOP(OP_SHMWRITE,XTERM);
4926
4927         case KEY_shutdown:
4928             LOP(OP_SHUTDOWN,XTERM);
4929
4930         case KEY_sin:
4931             UNI(OP_SIN);
4932
4933         case KEY_sleep:
4934             UNI(OP_SLEEP);
4935
4936         case KEY_socket:
4937             LOP(OP_SOCKET,XTERM);
4938
4939         case KEY_socketpair:
4940             LOP(OP_SOCKPAIR,XTERM);
4941
4942         case KEY_sort:
4943             checkcomma(s,PL_tokenbuf,"subroutine name");
4944             s = skipspace(s);
4945             if (*s == ';' || *s == ')')         /* probably a close */
4946                 Perl_croak(aTHX_ "sort is now a reserved word");
4947             PL_expect = XTERM;
4948             s = force_word(s,WORD,TRUE,TRUE,FALSE);
4949             LOP(OP_SORT,XREF);
4950
4951         case KEY_split:
4952             LOP(OP_SPLIT,XTERM);
4953
4954         case KEY_sprintf:
4955             LOP(OP_SPRINTF,XTERM);
4956
4957         case KEY_splice:
4958             LOP(OP_SPLICE,XTERM);
4959
4960         case KEY_sqrt:
4961             UNI(OP_SQRT);
4962
4963         case KEY_srand:
4964             UNI(OP_SRAND);
4965
4966         case KEY_stat:
4967             UNI(OP_STAT);
4968
4969         case KEY_study:
4970             UNI(OP_STUDY);
4971
4972         case KEY_substr:
4973             LOP(OP_SUBSTR,XTERM);
4974
4975         case KEY_format:
4976         case KEY_sub:
4977           really_sub:
4978             {
4979                 char tmpbuf[sizeof PL_tokenbuf];
4980                 SSize_t tboffset;
4981                 expectation attrful;
4982                 bool have_name, have_proto;
4983                 int key = tmp;
4984
4985                 s = skipspace(s);
4986
4987                 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
4988                     (*s == ':' && s[1] == ':'))
4989                 {
4990                     PL_expect = XBLOCK;
4991                     attrful = XATTRBLOCK;
4992                     /* remember buffer pos'n for later force_word */
4993                     tboffset = s - PL_oldbufptr;
4994                     d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4995                     if (strchr(tmpbuf, ':'))
4996                         sv_setpv(PL_subname, tmpbuf);
4997                     else {
4998                         sv_setsv(PL_subname,PL_curstname);
4999                         sv_catpvn(PL_subname,"::",2);
5000                         sv_catpvn(PL_subname,tmpbuf,len);
5001                     }
5002                     s = skipspace(d);
5003                     have_name = TRUE;
5004                 }
5005                 else {
5006                     if (key == KEY_my)
5007                         Perl_croak(aTHX_ "Missing name in \"my sub\"");
5008                     PL_expect = XTERMBLOCK;
5009                     attrful = XATTRTERM;
5010                     sv_setpv(PL_subname,"?");
5011                     have_name = FALSE;
5012                 }
5013
5014                 if (key == KEY_format) {
5015                     if (*s == '=')
5016                         PL_lex_formbrack = PL_lex_brackets + 1;
5017                     if (have_name)
5018                         (void) force_word(PL_oldbufptr + tboffset, WORD,
5019                                           FALSE, TRUE, TRUE);
5020                     OPERATOR(FORMAT);
5021                 }
5022
5023                 /* Look for a prototype */
5024                 if (*s == '(') {
5025                     char *p;
5026
5027                     s = scan_str(s,FALSE,FALSE);
5028                     if (!s)
5029                         Perl_croak(aTHX_ "Prototype not terminated");
5030                     /* strip spaces */
5031                     d = SvPVX(PL_lex_stuff);
5032                     tmp = 0;
5033                     for (p = d; *p; ++p) {
5034                         if (!isSPACE(*p))
5035                             d[tmp++] = *p;
5036                     }
5037                     d[tmp] = '\0';
5038                     SvCUR(PL_lex_stuff) = tmp;
5039                     have_proto = TRUE;
5040
5041                     s = skipspace(s);
5042                 }
5043                 else
5044                     have_proto = FALSE;
5045
5046                 if (*s == ':' && s[1] != ':')
5047                     PL_expect = attrful;
5048
5049                 if (have_proto) {
5050                     PL_nextval[PL_nexttoke].opval =
5051                         (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
5052                     PL_lex_stuff = Nullsv;
5053                     force_next(THING);
5054                 }
5055                 if (!have_name) {
5056                     sv_setpv(PL_subname,"__ANON__");
5057                     TOKEN(ANONSUB);
5058                 }
5059                 (void) force_word(PL_oldbufptr + tboffset, WORD,
5060                                   FALSE, TRUE, TRUE);
5061                 if (key == KEY_my)
5062                     TOKEN(MYSUB);
5063                 TOKEN(SUB);
5064             }
5065
5066         case KEY_system:
5067             set_csh();
5068             LOP(OP_SYSTEM,XREF);
5069
5070         case KEY_symlink:
5071             LOP(OP_SYMLINK,XTERM);
5072
5073         case KEY_syscall:
5074             LOP(OP_SYSCALL,XTERM);
5075
5076         case KEY_sysopen:
5077             LOP(OP_SYSOPEN,XTERM);
5078
5079         case KEY_sysseek:
5080             LOP(OP_SYSSEEK,XTERM);
5081
5082         case KEY_sysread:
5083             LOP(OP_SYSREAD,XTERM);
5084
5085         case KEY_syswrite:
5086             LOP(OP_SYSWRITE,XTERM);
5087
5088         case KEY_tr:
5089             s = scan_trans(s);
5090             TERM(sublex_start());
5091
5092         case KEY_tell:
5093             UNI(OP_TELL);
5094
5095         case KEY_telldir:
5096             UNI(OP_TELLDIR);
5097
5098         case KEY_tie:
5099             LOP(OP_TIE,XTERM);
5100
5101         case KEY_tied:
5102             UNI(OP_TIED);
5103
5104         case KEY_time:
5105             FUN0(OP_TIME);
5106
5107         case KEY_times:
5108             FUN0(OP_TMS);
5109
5110         case KEY_truncate:
5111             LOP(OP_TRUNCATE,XTERM);
5112
5113         case KEY_uc:
5114             UNI(OP_UC);
5115
5116         case KEY_ucfirst:
5117             UNI(OP_UCFIRST);
5118
5119         case KEY_untie:
5120             UNI(OP_UNTIE);
5121
5122         case KEY_until:
5123             yylval.ival = CopLINE(PL_curcop);
5124             OPERATOR(UNTIL);
5125
5126         case KEY_unless:
5127             yylval.ival = CopLINE(PL_curcop);
5128             OPERATOR(UNLESS);
5129
5130         case KEY_unlink:
5131             LOP(OP_UNLINK,XTERM);
5132
5133         case KEY_undef:
5134             UNI(OP_UNDEF);
5135
5136         case KEY_unpack:
5137             LOP(OP_UNPACK,XTERM);
5138
5139         case KEY_utime:
5140             LOP(OP_UTIME,XTERM);
5141
5142         case KEY_umask:
5143             if (ckWARN(WARN_UMASK)) {
5144                 for (d = s; d < PL_bufend && (isSPACE(*d) || *d == '('); d++) ;
5145                 if (*d != '0' && isDIGIT(*d))
5146                     Perl_warner(aTHX_ WARN_UMASK,
5147                                 "umask: argument is missing initial 0");
5148             }
5149             UNI(OP_UMASK);
5150
5151         case KEY_unshift:
5152             LOP(OP_UNSHIFT,XTERM);
5153
5154         case KEY_use:
5155             if (PL_expect != XSTATE)
5156                 yyerror("\"use\" not allowed in expression");
5157             s = skipspace(s);
5158             if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
5159                 s = force_version(s);
5160                 if (*s == ';' || (s = skipspace(s), *s == ';')) {
5161                     PL_nextval[PL_nexttoke].opval = Nullop;
5162                     force_next(WORD);
5163                 }
5164             }
5165             else {
5166                 s = force_word(s,WORD,FALSE,TRUE,FALSE);
5167                 s = force_version(s);
5168             }
5169             yylval.ival = 1;
5170             OPERATOR(USE);
5171
5172         case KEY_values:
5173             UNI(OP_VALUES);
5174
5175         case KEY_vec:
5176             LOP(OP_VEC,XTERM);
5177
5178         case KEY_while:
5179             yylval.ival = CopLINE(PL_curcop);
5180             OPERATOR(WHILE);
5181
5182         case KEY_warn:
5183             PL_hints |= HINT_BLOCK_SCOPE;
5184             LOP(OP_WARN,XTERM);
5185
5186         case KEY_wait:
5187             FUN0(OP_WAIT);
5188
5189         case KEY_waitpid:
5190             LOP(OP_WAITPID,XTERM);
5191
5192         case KEY_wantarray:
5193             FUN0(OP_WANTARRAY);
5194
5195         case KEY_write:
5196 #ifdef EBCDIC
5197         {
5198             static char ctl_l[2];
5199
5200             if (ctl_l[0] == '\0')
5201                 ctl_l[0] = toCTRL('L');
5202             gv_fetchpv(ctl_l,TRUE, SVt_PV);
5203         }
5204 #else
5205             gv_fetchpv("\f",TRUE, SVt_PV);      /* Make sure $^L is defined */
5206 #endif
5207             UNI(OP_ENTERWRITE);
5208
5209         case KEY_x:
5210             if (PL_expect == XOPERATOR)
5211                 Mop(OP_REPEAT);
5212             check_uni();
5213             goto just_a_word;
5214
5215         case KEY_xor:
5216             yylval.ival = OP_XOR;
5217             OPERATOR(OROP);
5218
5219         case KEY_y:
5220             s = scan_trans(s);
5221             TERM(sublex_start());
5222         }
5223     }}
5224 }
5225 #ifdef __SC__
5226 #pragma segment Main
5227 #endif
5228
5229 I32
5230 Perl_keyword(pTHX_ register char *d, I32 len)
5231 {
5232     switch (*d) {
5233     case '_':
5234         if (d[1] == '_') {
5235             if (strEQ(d,"__FILE__"))            return -KEY___FILE__;
5236             if (strEQ(d,"__LINE__"))            return -KEY___LINE__;
5237             if (strEQ(d,"__PACKAGE__"))         return -KEY___PACKAGE__;
5238             if (strEQ(d,"__DATA__"))            return KEY___DATA__;
5239             if (strEQ(d,"__END__"))             return KEY___END__;
5240         }
5241         break;
5242     case 'A':
5243         if (strEQ(d,"AUTOLOAD"))                return KEY_AUTOLOAD;
5244         break;
5245     case 'a':
5246         switch (len) {
5247         case 3:
5248             if (strEQ(d,"and"))                 return -KEY_and;
5249             if (strEQ(d,"abs"))                 return -KEY_abs;
5250             break;
5251         case 5:
5252             if (strEQ(d,"alarm"))               return -KEY_alarm;
5253             if (strEQ(d,"atan2"))               return -KEY_atan2;
5254             break;
5255         case 6:
5256             if (strEQ(d,"accept"))              return -KEY_accept;
5257             break;
5258         }
5259         break;
5260     case 'B':
5261         if (strEQ(d,"BEGIN"))                   return KEY_BEGIN;
5262         break;
5263     case 'b':
5264         if (strEQ(d,"bless"))                   return -KEY_bless;
5265         if (strEQ(d,"bind"))                    return -KEY_bind;
5266         if (strEQ(d,"binmode"))                 return -KEY_binmode;
5267         break;
5268     case 'C':
5269         if (strEQ(d,"CORE"))                    return -KEY_CORE;
5270         if (strEQ(d,"CHECK"))                   return KEY_CHECK;
5271         break;
5272     case 'c':
5273         switch (len) {
5274         case 3:
5275             if (strEQ(d,"cmp"))                 return -KEY_cmp;
5276             if (strEQ(d,"chr"))                 return -KEY_chr;
5277             if (strEQ(d,"cos"))                 return -KEY_cos;
5278             break;
5279         case 4:
5280             if (strEQ(d,"chop"))                return -KEY_chop;
5281             break;
5282         case 5:
5283             if (strEQ(d,"close"))               return -KEY_close;
5284             if (strEQ(d,"chdir"))               return -KEY_chdir;
5285             if (strEQ(d,"chomp"))               return -KEY_chomp;
5286             if (strEQ(d,"chmod"))               return -KEY_chmod;
5287             if (strEQ(d,"chown"))               return -KEY_chown;
5288             if (strEQ(d,"crypt"))               return -KEY_crypt;
5289             break;
5290         case 6:
5291             if (strEQ(d,"chroot"))              return -KEY_chroot;
5292             if (strEQ(d,"caller"))              return -KEY_caller;
5293             break;
5294         case 7:
5295             if (strEQ(d,"connect"))             return -KEY_connect;
5296             break;
5297         case 8:
5298             if (strEQ(d,"closedir"))            return -KEY_closedir;
5299             if (strEQ(d,"continue"))            return -KEY_continue;
5300             break;
5301         }
5302         break;
5303     case 'D':
5304         if (strEQ(d,"DESTROY"))                 return KEY_DESTROY;
5305         break;
5306     case 'd':
5307         switch (len) {
5308         case 2:
5309             if (strEQ(d,"do"))                  return KEY_do;
5310             break;
5311         case 3:
5312             if (strEQ(d,"die"))                 return -KEY_die;
5313             break;
5314         case 4:
5315             if (strEQ(d,"dump"))                return -KEY_dump;
5316             break;
5317         case 6:
5318             if (strEQ(d,"delete"))              return KEY_delete;
5319             break;
5320         case 7:
5321             if (strEQ(d,"defined"))             return KEY_defined;
5322             if (strEQ(d,"dbmopen"))             return -KEY_dbmopen;
5323             break;
5324         case 8:
5325             if (strEQ(d,"dbmclose"))            return -KEY_dbmclose;
5326             break;
5327         }
5328         break;
5329     case 'E':
5330         if (strEQ(d,"END"))                     return KEY_END;
5331         break;
5332     case 'e':
5333         switch (len) {
5334         case 2:
5335             if (strEQ(d,"eq"))                  return -KEY_eq;
5336             break;
5337         case 3:
5338             if (strEQ(d,"eof"))                 return -KEY_eof;
5339             if (strEQ(d,"exp"))                 return -KEY_exp;
5340             break;
5341         case 4:
5342             if (strEQ(d,"else"))                return KEY_else;
5343             if (strEQ(d,"exit"))                return -KEY_exit;
5344             if (strEQ(d,"eval"))                return KEY_eval;
5345             if (strEQ(d,"exec"))                return -KEY_exec;
5346            if (strEQ(d,"each"))                return -KEY_each;
5347             break;
5348         case 5:
5349             if (strEQ(d,"elsif"))               return KEY_elsif;
5350             break;
5351         case 6:
5352             if (strEQ(d,"exists"))              return KEY_exists;
5353             if (strEQ(d,"elseif")) Perl_warn(aTHX_ "elseif should be elsif");
5354             break;
5355         case 8:
5356             if (strEQ(d,"endgrent"))            return -KEY_endgrent;
5357             if (strEQ(d,"endpwent"))            return -KEY_endpwent;
5358             break;
5359         case 9:
5360             if (strEQ(d,"endnetent"))           return -KEY_endnetent;
5361             break;
5362         case 10:
5363             if (strEQ(d,"endhostent"))          return -KEY_endhostent;
5364             if (strEQ(d,"endservent"))          return -KEY_endservent;
5365             break;
5366         case 11:
5367             if (strEQ(d,"endprotoent"))         return -KEY_endprotoent;
5368             break;
5369         }
5370         break;
5371     case 'f':
5372         switch (len) {
5373         case 3:
5374             if (strEQ(d,"for"))                 return KEY_for;
5375             break;
5376         case 4:
5377             if (strEQ(d,"fork"))                return -KEY_fork;
5378             break;
5379         case 5:
5380             if (strEQ(d,"fcntl"))               return -KEY_fcntl;
5381             if (strEQ(d,"flock"))               return -KEY_flock;
5382             break;
5383         case 6:
5384             if (strEQ(d,"format"))              return KEY_format;
5385             if (strEQ(d,"fileno"))              return -KEY_fileno;
5386             break;
5387         case 7:
5388             if (strEQ(d,"foreach"))             return KEY_foreach;
5389             break;
5390         case 8:
5391             if (strEQ(d,"formline"))            return -KEY_formline;
5392             break;
5393         }
5394         break;
5395     case 'g':
5396         if (strnEQ(d,"get",3)) {
5397             d += 3;
5398             if (*d == 'p') {
5399                 switch (len) {
5400                 case 7:
5401                     if (strEQ(d,"ppid"))        return -KEY_getppid;
5402                     if (strEQ(d,"pgrp"))        return -KEY_getpgrp;
5403                     break;
5404                 case 8:
5405                     if (strEQ(d,"pwent"))       return -KEY_getpwent;
5406                     if (strEQ(d,"pwnam"))       return -KEY_getpwnam;
5407                     if (strEQ(d,"pwuid"))       return -KEY_getpwuid;
5408                     break;
5409                 case 11:
5410                     if (strEQ(d,"peername"))    return -KEY_getpeername;
5411                     if (strEQ(d,"protoent"))    return -KEY_getprotoent;
5412                     if (strEQ(d,"priority"))    return -KEY_getpriority;
5413                     break;
5414                 case 14:
5415                     if (strEQ(d,"protobyname")) return -KEY_getprotobyname;
5416                     break;
5417                 case 16:
5418                     if (strEQ(d,"protobynumber"))return -KEY_getprotobynumber;
5419                     break;
5420                 }
5421             }
5422             else if (*d == 'h') {
5423                 if (strEQ(d,"hostbyname"))      return -KEY_gethostbyname;
5424                 if (strEQ(d,"hostbyaddr"))      return -KEY_gethostbyaddr;
5425                 if (strEQ(d,"hostent"))         return -KEY_gethostent;
5426             }
5427             else if (*d == 'n') {
5428                 if (strEQ(d,"netbyname"))       return -KEY_getnetbyname;
5429                 if (strEQ(d,"netbyaddr"))       return -KEY_getnetbyaddr;
5430                 if (strEQ(d,"netent"))          return -KEY_getnetent;
5431             }
5432             else if (*d == 's') {
5433                 if (strEQ(d,"servbyname"))      return -KEY_getservbyname;
5434                 if (strEQ(d,"servbyport"))      return -KEY_getservbyport;
5435                 if (strEQ(d,"servent"))         return -KEY_getservent;
5436                 if (strEQ(d,"sockname"))        return -KEY_getsockname;
5437                 if (strEQ(d,"sockopt"))         return -KEY_getsockopt;
5438             }
5439             else if (*d == 'g') {
5440                 if (strEQ(d,"grent"))           return -KEY_getgrent;
5441                 if (strEQ(d,"grnam"))           return -KEY_getgrnam;
5442                 if (strEQ(d,"grgid"))           return -KEY_getgrgid;
5443             }
5444             else if (*d == 'l') {
5445                 if (strEQ(d,"login"))           return -KEY_getlogin;
5446             }
5447             else if (strEQ(d,"c"))              return -KEY_getc;
5448             break;
5449         }
5450         switch (len) {
5451         case 2:
5452             if (strEQ(d,"gt"))                  return -KEY_gt;
5453             if (strEQ(d,"ge"))                  return -KEY_ge;
5454             break;
5455         case 4:
5456             if (strEQ(d,"grep"))                return KEY_grep;
5457             if (strEQ(d,"goto"))                return KEY_goto;
5458             if (strEQ(d,"glob"))                return KEY_glob;
5459             break;
5460         case 6:
5461             if (strEQ(d,"gmtime"))              return -KEY_gmtime;
5462             break;
5463         }
5464         break;
5465     case 'h':
5466         if (strEQ(d,"hex"))                     return -KEY_hex;
5467         break;
5468     case 'I':
5469         if (strEQ(d,"INIT"))                    return KEY_INIT;
5470         break;
5471     case 'i':
5472         switch (len) {
5473         case 2:
5474             if (strEQ(d,"if"))                  return KEY_if;
5475             break;
5476         case 3:
5477             if (strEQ(d,"int"))                 return -KEY_int;
5478             break;
5479         case 5:
5480             if (strEQ(d,"index"))               return -KEY_index;
5481             if (strEQ(d,"ioctl"))               return -KEY_ioctl;
5482             break;
5483         }
5484         break;
5485     case 'j':
5486         if (strEQ(d,"join"))                    return -KEY_join;
5487         break;
5488     case 'k':
5489         if (len == 4) {
5490            if (strEQ(d,"keys"))                return -KEY_keys;
5491             if (strEQ(d,"kill"))                return -KEY_kill;
5492         }
5493         break;
5494     case 'l':
5495         switch (len) {
5496         case 2:
5497             if (strEQ(d,"lt"))                  return -KEY_lt;
5498             if (strEQ(d,"le"))                  return -KEY_le;
5499             if (strEQ(d,"lc"))                  return -KEY_lc;
5500             break;
5501         case 3:
5502             if (strEQ(d,"log"))                 return -KEY_log;
5503             break;
5504         case 4:
5505             if (strEQ(d,"last"))                return KEY_last;
5506             if (strEQ(d,"link"))                return -KEY_link;
5507             if (strEQ(d,"lock"))                return -KEY_lock;
5508             break;
5509         case 5:
5510             if (strEQ(d,"local"))               return KEY_local;
5511             if (strEQ(d,"lstat"))               return -KEY_lstat;
5512             break;
5513         case 6:
5514             if (strEQ(d,"length"))              return -KEY_length;
5515             if (strEQ(d,"listen"))              return -KEY_listen;
5516             break;
5517         case 7:
5518             if (strEQ(d,"lcfirst"))             return -KEY_lcfirst;
5519             break;
5520         case 9:
5521             if (strEQ(d,"localtime"))           return -KEY_localtime;
5522             break;
5523         }
5524         break;
5525     case 'm':
5526         switch (len) {
5527         case 1:                                 return KEY_m;
5528         case 2:
5529             if (strEQ(d,"my"))                  return KEY_my;
5530             break;
5531         case 3:
5532             if (strEQ(d,"map"))                 return KEY_map;
5533             break;
5534         case 5:
5535             if (strEQ(d,"mkdir"))               return -KEY_mkdir;
5536             break;
5537         case 6:
5538             if (strEQ(d,"msgctl"))              return -KEY_msgctl;
5539             if (strEQ(d,"msgget"))              return -KEY_msgget;
5540             if (strEQ(d,"msgrcv"))              return -KEY_msgrcv;
5541             if (strEQ(d,"msgsnd"))              return -KEY_msgsnd;
5542             break;
5543         }
5544         break;
5545     case 'n':
5546         if (strEQ(d,"next"))                    return KEY_next;
5547         if (strEQ(d,"ne"))                      return -KEY_ne;
5548         if (strEQ(d,"not"))                     return -KEY_not;
5549         if (strEQ(d,"no"))                      return KEY_no;
5550         break;
5551     case 'o':
5552         switch (len) {
5553         case 2:
5554             if (strEQ(d,"or"))                  return -KEY_or;
5555             break;
5556         case 3:
5557             if (strEQ(d,"ord"))                 return -KEY_ord;
5558             if (strEQ(d,"oct"))                 return -KEY_oct;
5559             if (strEQ(d,"our"))                 return KEY_our;
5560             break;
5561         case 4:
5562             if (strEQ(d,"open"))                return -KEY_open;
5563             break;
5564         case 7:
5565             if (strEQ(d,"opendir"))             return -KEY_opendir;
5566             break;
5567         }
5568         break;
5569     case 'p':
5570         switch (len) {
5571         case 3:
5572            if (strEQ(d,"pop"))                 return -KEY_pop;
5573             if (strEQ(d,"pos"))                 return KEY_pos;
5574             break;
5575         case 4:
5576            if (strEQ(d,"push"))                return -KEY_push;
5577             if (strEQ(d,"pack"))                return -KEY_pack;
5578             if (strEQ(d,"pipe"))                return -KEY_pipe;
5579             break;
5580         case 5:
5581             if (strEQ(d,"print"))               return KEY_print;
5582             break;
5583         case 6:
5584             if (strEQ(d,"printf"))              return KEY_printf;
5585             break;
5586         case 7:
5587             if (strEQ(d,"package"))             return KEY_package;
5588             break;
5589         case 9:
5590             if (strEQ(d,"prototype"))           return KEY_prototype;
5591         }
5592         break;
5593     case 'q':
5594         if (len <= 2) {
5595             if (strEQ(d,"q"))                   return KEY_q;
5596             if (strEQ(d,"qr"))                  return KEY_qr;
5597             if (strEQ(d,"qq"))                  return KEY_qq;
5598             if (strEQ(d,"qw"))                  return KEY_qw;
5599             if (strEQ(d,"qx"))                  return KEY_qx;
5600         }
5601         else if (strEQ(d,"quotemeta"))          return -KEY_quotemeta;
5602         break;
5603     case 'r':
5604         switch (len) {
5605         case 3:
5606             if (strEQ(d,"ref"))                 return -KEY_ref;
5607             break;
5608         case 4:
5609             if (strEQ(d,"read"))                return -KEY_read;
5610             if (strEQ(d,"rand"))                return -KEY_rand;
5611             if (strEQ(d,"recv"))                return -KEY_recv;
5612             if (strEQ(d,"redo"))                return KEY_redo;
5613             break;
5614         case 5:
5615             if (strEQ(d,"rmdir"))               return -KEY_rmdir;
5616             if (strEQ(d,"reset"))               return -KEY_reset;
5617             break;
5618         case 6:
5619             if (strEQ(d,"return"))              return KEY_return;
5620             if (strEQ(d,"rename"))              return -KEY_rename;
5621             if (strEQ(d,"rindex"))              return -KEY_rindex;
5622             break;
5623         case 7:
5624             if (strEQ(d,"require"))             return -KEY_require;
5625             if (strEQ(d,"reverse"))             return -KEY_reverse;
5626             if (strEQ(d,"readdir"))             return -KEY_readdir;
5627             break;
5628         case 8:
5629             if (strEQ(d,"readlink"))            return -KEY_readlink;
5630             if (strEQ(d,"readline"))            return -KEY_readline;
5631             if (strEQ(d,"readpipe"))            return -KEY_readpipe;
5632             break;
5633         case 9:
5634             if (strEQ(d,"rewinddir"))           return -KEY_rewinddir;
5635             break;
5636         }
5637         break;
5638     case 's':
5639         switch (d[1]) {
5640         case 0:                                 return KEY_s;
5641         case 'c':
5642             if (strEQ(d,"scalar"))              return KEY_scalar;
5643             break;
5644         case 'e':
5645             switch (len) {
5646             case 4:
5647                 if (strEQ(d,"seek"))            return -KEY_seek;
5648                 if (strEQ(d,"send"))            return -KEY_send;
5649                 break;
5650             case 5:
5651                 if (strEQ(d,"semop"))           return -KEY_semop;
5652                 break;
5653             case 6:
5654                 if (strEQ(d,"select"))          return -KEY_select;
5655                 if (strEQ(d,"semctl"))          return -KEY_semctl;
5656                 if (strEQ(d,"semget"))          return -KEY_semget;
5657                 break;
5658             case 7:
5659                 if (strEQ(d,"setpgrp"))         return -KEY_setpgrp;
5660                 if (strEQ(d,"seekdir"))         return -KEY_seekdir;
5661                 break;
5662             case 8:
5663                 if (strEQ(d,"setpwent"))        return -KEY_setpwent;
5664                 if (strEQ(d,"setgrent"))        return -KEY_setgrent;
5665                 break;
5666             case 9:
5667                 if (strEQ(d,"setnetent"))       return -KEY_setnetent;
5668                 break;
5669             case 10:
5670                 if (strEQ(d,"setsockopt"))      return -KEY_setsockopt;
5671                 if (strEQ(d,"sethostent"))      return -KEY_sethostent;
5672                 if (strEQ(d,"setservent"))      return -KEY_setservent;
5673                 break;
5674             case 11:
5675                 if (strEQ(d,"setpriority"))     return -KEY_setpriority;
5676                 if (strEQ(d,"setprotoent"))     return -KEY_setprotoent;
5677                 break;
5678             }
5679             break;
5680         case 'h':
5681             switch (len) {
5682             case 5:
5683                if (strEQ(d,"shift"))           return -KEY_shift;
5684                 break;
5685             case 6:
5686                 if (strEQ(d,"shmctl"))          return -KEY_shmctl;
5687                 if (strEQ(d,"shmget"))          return -KEY_shmget;
5688                 break;
5689             case 7:
5690                 if (strEQ(d,"shmread"))         return -KEY_shmread;
5691                 break;
5692             case 8:
5693                 if (strEQ(d,"shmwrite"))        return -KEY_shmwrite;
5694                 if (strEQ(d,"shutdown"))        return -KEY_shutdown;
5695                 break;
5696             }
5697             break;
5698         case 'i':
5699             if (strEQ(d,"sin"))                 return -KEY_sin;
5700             break;
5701         case 'l':
5702             if (strEQ(d,"sleep"))               return -KEY_sleep;
5703             break;
5704         case 'o':
5705             if (strEQ(d,"sort"))                return KEY_sort;
5706             if (strEQ(d,"socket"))              return -KEY_socket;
5707             if (strEQ(d,"socketpair"))          return -KEY_socketpair;
5708             break;
5709         case 'p':
5710             if (strEQ(d,"split"))               return KEY_split;
5711             if (strEQ(d,"sprintf"))             return -KEY_sprintf;
5712            if (strEQ(d,"splice"))              return -KEY_splice;
5713             break;
5714         case 'q':
5715             if (strEQ(d,"sqrt"))                return -KEY_sqrt;
5716             break;
5717         case 'r':
5718             if (strEQ(d,"srand"))               return -KEY_srand;
5719             break;
5720         case 't':
5721             if (strEQ(d,"stat"))                return -KEY_stat;
5722             if (strEQ(d,"study"))               return KEY_study;
5723             break;
5724         case 'u':
5725             if (strEQ(d,"substr"))              return -KEY_substr;
5726             if (strEQ(d,"sub"))                 return KEY_sub;
5727             break;
5728         case 'y':
5729             switch (len) {
5730             case 6:
5731                 if (strEQ(d,"system"))          return -KEY_system;
5732                 break;
5733             case 7:
5734                 if (strEQ(d,"symlink"))         return -KEY_symlink;
5735                 if (strEQ(d,"syscall"))         return -KEY_syscall;
5736                 if (strEQ(d,"sysopen"))         return -KEY_sysopen;
5737                 if (strEQ(d,"sysread"))         return -KEY_sysread;
5738                 if (strEQ(d,"sysseek"))         return -KEY_sysseek;
5739                 break;
5740             case 8:
5741                 if (strEQ(d,"syswrite"))        return -KEY_syswrite;
5742                 break;
5743             }
5744             break;
5745         }
5746         break;
5747     case 't':
5748         switch (len) {
5749         case 2:
5750             if (strEQ(d,"tr"))                  return KEY_tr;
5751             break;
5752         case 3:
5753             if (strEQ(d,"tie"))                 return KEY_tie;
5754             break;
5755         case 4:
5756             if (strEQ(d,"tell"))                return -KEY_tell;
5757             if (strEQ(d,"tied"))                return KEY_tied;
5758             if (strEQ(d,"time"))                return -KEY_time;
5759             break;
5760         case 5:
5761             if (strEQ(d,"times"))               return -KEY_times;
5762             break;
5763         case 7:
5764             if (strEQ(d,"telldir"))             return -KEY_telldir;
5765             break;
5766         case 8:
5767             if (strEQ(d,"truncate"))            return -KEY_truncate;
5768             break;
5769         }
5770         break;
5771     case 'u':
5772         switch (len) {
5773         case 2:
5774             if (strEQ(d,"uc"))                  return -KEY_uc;
5775             break;
5776         case 3:
5777             if (strEQ(d,"use"))                 return KEY_use;
5778             break;
5779         case 5:
5780             if (strEQ(d,"undef"))               return KEY_undef;
5781             if (strEQ(d,"until"))               return KEY_until;
5782             if (strEQ(d,"untie"))               return KEY_untie;
5783             if (strEQ(d,"utime"))               return -KEY_utime;
5784             if (strEQ(d,"umask"))               return -KEY_umask;
5785             break;
5786         case 6:
5787             if (strEQ(d,"unless"))              return KEY_unless;
5788             if (strEQ(d,"unpack"))              return -KEY_unpack;
5789             if (strEQ(d,"unlink"))              return -KEY_unlink;
5790             break;
5791         case 7:
5792            if (strEQ(d,"unshift"))             return -KEY_unshift;
5793             if (strEQ(d,"ucfirst"))             return -KEY_ucfirst;
5794             break;
5795         }
5796         break;
5797     case 'v':
5798         if (strEQ(d,"values"))                  return -KEY_values;
5799         if (strEQ(d,"vec"))                     return -KEY_vec;
5800         break;
5801     case 'w':
5802         switch (len) {
5803         case 4:
5804             if (strEQ(d,"warn"))                return -KEY_warn;
5805             if (strEQ(d,"wait"))                return -KEY_wait;
5806             break;
5807         case 5:
5808             if (strEQ(d,"while"))               return KEY_while;
5809             if (strEQ(d,"write"))               return -KEY_write;
5810             break;
5811         case 7:
5812             if (strEQ(d,"waitpid"))             return -KEY_waitpid;
5813             break;
5814         case 9:
5815             if (strEQ(d,"wantarray"))           return -KEY_wantarray;
5816             break;
5817         }
5818         break;
5819     case 'x':
5820         if (len == 1)                           return -KEY_x;
5821         if (strEQ(d,"xor"))                     return -KEY_xor;
5822         break;
5823     case 'y':
5824         if (len == 1)                           return KEY_y;
5825         break;
5826     case 'z':
5827         break;
5828     }
5829     return 0;
5830 }
5831
5832 STATIC void
5833 S_checkcomma(pTHX_ register char *s, char *name, char *what)
5834 {
5835     char *w;
5836
5837     if (*s == ' ' && s[1] == '(') {     /* XXX gotta be a better way */
5838         if (ckWARN(WARN_SYNTAX)) {
5839             int level = 1;
5840             for (w = s+2; *w && level; w++) {
5841                 if (*w == '(')
5842                     ++level;
5843                 else if (*w == ')')
5844                     --level;
5845             }
5846             if (*w)
5847                 for (; *w && isSPACE(*w); w++) ;
5848             if (!*w || !strchr(";|})]oaiuw!=", *w))     /* an advisory hack only... */
5849                 Perl_warner(aTHX_ WARN_SYNTAX,
5850                             "%s (...) interpreted as function",name);
5851         }
5852     }
5853     while (s < PL_bufend && isSPACE(*s))
5854         s++;
5855     if (*s == '(')
5856         s++;
5857     while (s < PL_bufend && isSPACE(*s))
5858         s++;
5859     if (isIDFIRST_lazy_if(s,UTF)) {
5860         w = s++;
5861         while (isALNUM_lazy_if(s,UTF))
5862             s++;
5863         while (s < PL_bufend && isSPACE(*s))
5864             s++;
5865         if (*s == ',') {
5866             int kw;
5867             *s = '\0';
5868             kw = keyword(w, s - w) || get_cv(w, FALSE) != 0;
5869             *s = ',';
5870             if (kw)
5871                 return;
5872             Perl_croak(aTHX_ "No comma allowed after %s", what);
5873         }
5874     }
5875 }
5876
5877 /* Either returns sv, or mortalizes sv and returns a new SV*.
5878    Best used as sv=new_constant(..., sv, ...).
5879    If s, pv are NULL, calls subroutine with one argument,
5880    and type is used with error messages only. */
5881
5882 STATIC SV *
5883 S_new_constant(pTHX_ char *s, STRLEN len, const char *key, SV *sv, SV *pv,
5884                const char *type)
5885 {
5886     dSP;
5887     HV *table = GvHV(PL_hintgv);                 /* ^H */
5888     SV *res;
5889     SV **cvp;
5890     SV *cv, *typesv;
5891     const char *why1, *why2, *why3;
5892
5893     if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
5894         SV *msg;
5895         
5896         why2 = strEQ(key,"charnames")
5897                ? "(possibly a missing \"use charnames ...\")"
5898                : "";
5899         msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
5900                             (type ? type: "undef"), why2);
5901
5902         /* This is convoluted and evil ("goto considered harmful")
5903          * but I do not understand the intricacies of all the different
5904          * failure modes of %^H in here.  The goal here is to make
5905          * the most probable error message user-friendly. --jhi */
5906
5907         goto msgdone;
5908
5909     report:
5910         msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
5911                             (type ? type: "undef"), why1, why2, why3);
5912     msgdone:
5913         yyerror(SvPVX(msg));
5914         SvREFCNT_dec(msg);
5915         return sv;
5916     }
5917     cvp = hv_fetch(table, key, strlen(key), FALSE);
5918     if (!cvp || !SvOK(*cvp)) {
5919         why1 = "$^H{";
5920         why2 = key;
5921         why3 = "} is not defined";
5922         goto report;
5923     }
5924     sv_2mortal(sv);                     /* Parent created it permanently */
5925     cv = *cvp;
5926     if (!pv && s)
5927         pv = sv_2mortal(newSVpvn(s, len));
5928     if (type && pv)
5929         typesv = sv_2mortal(newSVpv(type, 0));
5930     else
5931         typesv = &PL_sv_undef;
5932
5933     PUSHSTACKi(PERLSI_OVERLOAD);
5934     ENTER ;
5935     SAVETMPS;
5936
5937     PUSHMARK(SP) ;
5938     EXTEND(sp, 3);
5939     if (pv)
5940         PUSHs(pv);
5941     PUSHs(sv);
5942     if (pv)
5943         PUSHs(typesv);
5944     PUTBACK;
5945     call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
5946
5947     SPAGAIN ;
5948
5949     /* Check the eval first */
5950     if (!PL_in_eval && SvTRUE(ERRSV)) {
5951         STRLEN n_a;
5952         sv_catpv(ERRSV, "Propagated");
5953         yyerror(SvPV(ERRSV, n_a)); /* Duplicates the message inside eval */
5954         (void)POPs;
5955         res = SvREFCNT_inc(sv);
5956     }
5957     else {
5958         res = POPs;
5959         (void)SvREFCNT_inc(res);
5960     }
5961
5962     PUTBACK ;
5963     FREETMPS ;
5964     LEAVE ;
5965     POPSTACK;
5966
5967     if (!SvOK(res)) {
5968         why1 = "Call to &{$^H{";
5969         why2 = key;
5970         why3 = "}} did not return a defined value";
5971         sv = res;
5972         goto report;
5973     }
5974
5975     return res;
5976 }
5977
5978 STATIC char *
5979 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
5980 {
5981     register char *d = dest;
5982     register char *e = d + destlen - 3;  /* two-character token, ending NUL */
5983     for (;;) {
5984         if (d >= e)
5985             Perl_croak(aTHX_ ident_too_long);
5986         if (isALNUM(*s))        /* UTF handled below */
5987             *d++ = *s++;
5988         else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) {
5989             *d++ = ':';
5990             *d++ = ':';
5991             s++;
5992         }
5993         else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') {
5994             *d++ = *s++;
5995             *d++ = *s++;
5996         }
5997         else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
5998             char *t = s + UTF8SKIP(s);
5999             while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
6000                 t += UTF8SKIP(t);
6001             if (d + (t - s) > e)
6002                 Perl_croak(aTHX_ ident_too_long);
6003             Copy(s, d, t - s, char);
6004             d += t - s;
6005             s = t;
6006         }
6007         else {
6008             *d = '\0';
6009             *slp = d - dest;
6010             return s;
6011         }
6012     }
6013 }
6014
6015 STATIC char *
6016 S_scan_ident(pTHX_ register char *s, register char *send, char *dest, STRLEN destlen, I32 ck_uni)
6017 {
6018     register char *d;
6019     register char *e;
6020     char *bracket = 0;
6021     char funny = *s++;
6022
6023     if (isSPACE(*s))
6024         s = skipspace(s);
6025     d = dest;
6026     e = d + destlen - 3;        /* two-character token, ending NUL */
6027     if (isDIGIT(*s)) {
6028         while (isDIGIT(*s)) {
6029             if (d >= e)
6030                 Perl_croak(aTHX_ ident_too_long);
6031             *d++ = *s++;
6032         }
6033     }
6034     else {
6035         for (;;) {
6036             if (d >= e)
6037                 Perl_croak(aTHX_ ident_too_long);
6038             if (isALNUM(*s))    /* UTF handled below */
6039                 *d++ = *s++;
6040             else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
6041                 *d++ = ':';
6042                 *d++ = ':';
6043                 s++;
6044             }
6045             else if (*s == ':' && s[1] == ':') {
6046                 *d++ = *s++;
6047                 *d++ = *s++;
6048             }
6049             else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
6050                 char *t = s + UTF8SKIP(s);
6051                 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
6052                     t += UTF8SKIP(t);
6053                 if (d + (t - s) > e)
6054                     Perl_croak(aTHX_ ident_too_long);
6055                 Copy(s, d, t - s, char);
6056                 d += t - s;
6057                 s = t;
6058             }
6059             else
6060                 break;
6061         }
6062     }
6063     *d = '\0';
6064     d = dest;
6065     if (*d) {
6066         if (PL_lex_state != LEX_NORMAL)
6067             PL_lex_state = LEX_INTERPENDMAYBE;
6068         return s;
6069     }
6070     if (*s == '$' && s[1] &&
6071         (isALNUM_lazy_if(s+1,UTF) || strchr("${", s[1]) || strnEQ(s+1,"::",2)) )
6072     {
6073         return s;
6074     }
6075     if (*s == '{') {
6076         bracket = s;
6077         s++;
6078     }
6079     else if (ck_uni)
6080         check_uni();
6081     if (s < send)
6082         *d = *s++;
6083     d[1] = '\0';
6084     if (*d == '^' && *s && isCONTROLVAR(*s)) {
6085         *d = toCTRL(*s);
6086         s++;
6087     }
6088     if (bracket) {
6089         if (isSPACE(s[-1])) {
6090             while (s < send) {
6091                 char ch = *s++;
6092                 if (!SPACE_OR_TAB(ch)) {
6093                     *d = ch;
6094                     break;
6095                 }
6096             }
6097         }
6098         if (isIDFIRST_lazy_if(d,UTF)) {
6099             d++;
6100             if (UTF) {
6101                 e = s;
6102                 while ((e < send && isALNUM_lazy_if(e,UTF)) || *e == ':') {
6103                     e += UTF8SKIP(e);
6104                     while (e < send && UTF8_IS_CONTINUED(*e) && is_utf8_mark((U8*)e))
6105                         e += UTF8SKIP(e);
6106                 }
6107                 Copy(s, d, e - s, char);
6108                 d += e - s;
6109                 s = e;
6110             }
6111             else {
6112                 while ((isALNUM(*s) || *s == ':') && d < e)
6113                     *d++ = *s++;
6114                 if (d >= e)
6115                     Perl_croak(aTHX_ ident_too_long);
6116             }
6117             *d = '\0';
6118             while (s < send && SPACE_OR_TAB(*s)) s++;
6119             if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
6120                 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
6121                     const char *brack = *s == '[' ? "[...]" : "{...}";
6122                     Perl_warner(aTHX_ WARN_AMBIGUOUS,
6123                         "Ambiguous use of %c{%s%s} resolved to %c%s%s",
6124                         funny, dest, brack, funny, dest, brack);
6125                 }
6126                 bracket++;
6127                 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
6128                 return s;
6129             }
6130         }
6131         /* Handle extended ${^Foo} variables
6132          * 1999-02-27 mjd-perl-patch@plover.com */
6133         else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
6134                  && isALNUM(*s))
6135         {
6136             d++;
6137             while (isALNUM(*s) && d < e) {
6138                 *d++ = *s++;
6139             }
6140             if (d >= e)
6141                 Perl_croak(aTHX_ ident_too_long);
6142             *d = '\0';
6143         }
6144         if (*s == '}') {
6145             s++;
6146             if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets)
6147                 PL_lex_state = LEX_INTERPEND;
6148             if (funny == '#')
6149                 funny = '@';
6150             if (PL_lex_state == LEX_NORMAL) {
6151                 if (ckWARN(WARN_AMBIGUOUS) &&
6152                     (keyword(dest, d - dest) || get_cv(dest, FALSE)))
6153                 {
6154                     Perl_warner(aTHX_ WARN_AMBIGUOUS,
6155                         "Ambiguous use of %c{%s} resolved to %c%s",
6156                         funny, dest, funny, dest);
6157                 }
6158             }
6159         }
6160         else {
6161             s = bracket;                /* let the parser handle it */
6162             *dest = '\0';
6163         }
6164     }
6165     else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
6166         PL_lex_state = LEX_INTERPEND;
6167     return s;
6168 }
6169
6170 void
6171 Perl_pmflag(pTHX_ U16 *pmfl, int ch)
6172 {
6173     if (ch == 'i')
6174         *pmfl |= PMf_FOLD;
6175     else if (ch == 'g')
6176         *pmfl |= PMf_GLOBAL;
6177     else if (ch == 'c')
6178         *pmfl |= PMf_CONTINUE;
6179     else if (ch == 'o')
6180         *pmfl |= PMf_KEEP;
6181     else if (ch == 'm')
6182         *pmfl |= PMf_MULTILINE;
6183     else if (ch == 's')
6184         *pmfl |= PMf_SINGLELINE;
6185     else if (ch == 'x')
6186         *pmfl |= PMf_EXTENDED;
6187 }
6188
6189 STATIC char *
6190 S_scan_pat(pTHX_ char *start, I32 type)
6191 {
6192     PMOP *pm;
6193     char *s;
6194
6195     s = scan_str(start,FALSE,FALSE);
6196     if (!s)
6197         Perl_croak(aTHX_ "Search pattern not terminated");
6198
6199     pm = (PMOP*)newPMOP(type, 0);
6200     if (PL_multi_open == '?')
6201         pm->op_pmflags |= PMf_ONCE;
6202     if(type == OP_QR) {
6203         while (*s && strchr("iomsx", *s))
6204             pmflag(&pm->op_pmflags,*s++);
6205     }
6206     else {
6207         while (*s && strchr("iogcmsx", *s))
6208             pmflag(&pm->op_pmflags,*s++);
6209     }
6210     pm->op_pmpermflags = pm->op_pmflags;
6211
6212     PL_lex_op = (OP*)pm;
6213     yylval.ival = OP_MATCH;
6214     return s;
6215 }
6216
6217 STATIC char *
6218 S_scan_subst(pTHX_ char *start)
6219 {
6220     register char *s;
6221     register PMOP *pm;
6222     I32 first_start;
6223     I32 es = 0;
6224
6225     yylval.ival = OP_NULL;
6226
6227     s = scan_str(start,FALSE,FALSE);
6228
6229     if (!s)
6230         Perl_croak(aTHX_ "Substitution pattern not terminated");
6231
6232     if (s[-1] == PL_multi_open)
6233         s--;
6234
6235     first_start = PL_multi_start;
6236     s = scan_str(s,FALSE,FALSE);
6237     if (!s) {
6238         if (PL_lex_stuff) {
6239             SvREFCNT_dec(PL_lex_stuff);
6240             PL_lex_stuff = Nullsv;
6241         }
6242         Perl_croak(aTHX_ "Substitution replacement not terminated");
6243     }
6244     PL_multi_start = first_start;       /* so whole substitution is taken together */
6245
6246     pm = (PMOP*)newPMOP(OP_SUBST, 0);
6247     while (*s) {
6248         if (*s == 'e') {
6249             s++;
6250             es++;
6251         }
6252         else if (strchr("iogcmsx", *s))
6253             pmflag(&pm->op_pmflags,*s++);
6254         else
6255             break;
6256     }
6257
6258     if (es) {
6259         SV *repl;
6260         PL_sublex_info.super_bufptr = s;
6261         PL_sublex_info.super_bufend = PL_bufend;
6262         PL_multi_end = 0;
6263         pm->op_pmflags |= PMf_EVAL;
6264         repl = newSVpvn("",0);
6265         while (es-- > 0)
6266             sv_catpv(repl, es ? "eval " : "do ");
6267         sv_catpvn(repl, "{ ", 2);
6268         sv_catsv(repl, PL_lex_repl);
6269         sv_catpvn(repl, " };", 2);
6270         SvEVALED_on(repl);
6271         SvREFCNT_dec(PL_lex_repl);
6272         PL_lex_repl = repl;
6273     }
6274
6275     pm->op_pmpermflags = pm->op_pmflags;
6276     PL_lex_op = (OP*)pm;
6277     yylval.ival = OP_SUBST;
6278     return s;
6279 }
6280
6281 STATIC char *
6282 S_scan_trans(pTHX_ char *start)
6283 {
6284     register char* s;
6285     OP *o;
6286     short *tbl;
6287     I32 squash;
6288     I32 del;
6289     I32 complement;
6290
6291     yylval.ival = OP_NULL;
6292
6293     s = scan_str(start,FALSE,FALSE);
6294     if (!s)
6295         Perl_croak(aTHX_ "Transliteration pattern not terminated");
6296     if (s[-1] == PL_multi_open)
6297         s--;
6298
6299     s = scan_str(s,FALSE,FALSE);
6300     if (!s) {
6301         if (PL_lex_stuff) {
6302             SvREFCNT_dec(PL_lex_stuff);
6303             PL_lex_stuff = Nullsv;
6304         }
6305         Perl_croak(aTHX_ "Transliteration replacement not terminated");
6306     }
6307
6308     complement = del = squash = 0;
6309     while (strchr("cds", *s)) {
6310         if (*s == 'c')
6311             complement = OPpTRANS_COMPLEMENT;
6312         else if (*s == 'd')
6313             del = OPpTRANS_DELETE;
6314         else if (*s == 's')
6315             squash = OPpTRANS_SQUASH;
6316         s++;
6317     }
6318
6319     New(803, tbl, complement&&!del?258:256, short);
6320     o = newPVOP(OP_TRANS, 0, (char*)tbl);
6321     o->op_private = del|squash|complement|
6322       (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
6323       (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF   : 0);
6324
6325     PL_lex_op = o;
6326     yylval.ival = OP_TRANS;
6327     return s;
6328 }
6329
6330 STATIC char *
6331 S_scan_heredoc(pTHX_ register char *s)
6332 {
6333     SV *herewas;
6334     I32 op_type = OP_SCALAR;
6335     I32 len;
6336     SV *tmpstr;
6337     char term;
6338     register char *d;
6339     register char *e;
6340     char *peek;
6341     int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
6342
6343     s += 2;
6344     d = PL_tokenbuf;
6345     e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
6346     if (!outer)
6347         *d++ = '\n';
6348     for (peek = s; SPACE_OR_TAB(*peek); peek++) ;
6349     if (*peek && strchr("`'\"",*peek)) {
6350         s = peek;
6351         term = *s++;
6352         s = delimcpy(d, e, s, PL_bufend, term, &len);
6353         d += len;
6354         if (s < PL_bufend)
6355             s++;
6356     }
6357     else {
6358         if (*s == '\\')
6359             s++, term = '\'';
6360         else
6361             term = '"';
6362         if (!isALNUM_lazy_if(s,UTF))
6363             deprecate("bare << to mean <<\"\"");
6364         for (; isALNUM_lazy_if(s,UTF); s++) {
6365             if (d < e)
6366                 *d++ = *s;
6367         }
6368     }
6369     if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
6370         Perl_croak(aTHX_ "Delimiter for here document is too long");
6371     *d++ = '\n';
6372     *d = '\0';
6373     len = d - PL_tokenbuf;
6374 #ifndef PERL_STRICT_CR
6375     d = strchr(s, '\r');
6376     if (d) {
6377         char *olds = s;
6378         s = d;
6379         while (s < PL_bufend) {
6380             if (*s == '\r') {
6381                 *d++ = '\n';
6382                 if (*++s == '\n')
6383                     s++;
6384             }
6385             else if (*s == '\n' && s[1] == '\r') {      /* \015\013 on a mac? */
6386                 *d++ = *s++;
6387                 s++;
6388             }
6389             else
6390                 *d++ = *s++;
6391         }
6392         *d = '\0';
6393         PL_bufend = d;
6394         SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
6395         s = olds;
6396     }
6397 #endif
6398     d = "\n";
6399     if (outer || !(d=ninstr(s,PL_bufend,d,d+1)))
6400         herewas = newSVpvn(s,PL_bufend-s);
6401     else
6402         s--, herewas = newSVpvn(s,d-s);
6403     s += SvCUR(herewas);
6404
6405     tmpstr = NEWSV(87,79);
6406     sv_upgrade(tmpstr, SVt_PVIV);
6407     if (term == '\'') {
6408         op_type = OP_CONST;
6409         SvIVX(tmpstr) = -1;
6410     }
6411     else if (term == '`') {
6412         op_type = OP_BACKTICK;
6413         SvIVX(tmpstr) = '\\';
6414     }
6415
6416     CLINE;
6417     PL_multi_start = CopLINE(PL_curcop);
6418     PL_multi_open = PL_multi_close = '<';
6419     term = *PL_tokenbuf;
6420     if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
6421         char *bufptr = PL_sublex_info.super_bufptr;
6422         char *bufend = PL_sublex_info.super_bufend;
6423         char *olds = s - SvCUR(herewas);
6424         s = strchr(bufptr, '\n');
6425         if (!s)
6426             s = bufend;
6427         d = s;
6428         while (s < bufend &&
6429           (*s != term || memNE(s,PL_tokenbuf,len)) ) {
6430             if (*s++ == '\n')
6431                 CopLINE_inc(PL_curcop);
6432         }
6433         if (s >= bufend) {
6434             CopLINE_set(PL_curcop, PL_multi_start);
6435             missingterm(PL_tokenbuf);
6436         }
6437         sv_setpvn(herewas,bufptr,d-bufptr+1);
6438         sv_setpvn(tmpstr,d+1,s-d);
6439         s += len - 1;
6440         sv_catpvn(herewas,s,bufend-s);
6441         (void)strcpy(bufptr,SvPVX(herewas));
6442
6443         s = olds;
6444         goto retval;
6445     }
6446     else if (!outer) {
6447         d = s;
6448         while (s < PL_bufend &&
6449           (*s != term || memNE(s,PL_tokenbuf,len)) ) {
6450             if (*s++ == '\n')
6451                 CopLINE_inc(PL_curcop);
6452         }
6453         if (s >= PL_bufend) {
6454             CopLINE_set(PL_curcop, PL_multi_start);
6455             missingterm(PL_tokenbuf);
6456         }
6457         sv_setpvn(tmpstr,d+1,s-d);
6458         s += len - 1;
6459         CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
6460
6461         sv_catpvn(herewas,s,PL_bufend-s);
6462         sv_setsv(PL_linestr,herewas);
6463         PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
6464         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6465         PL_last_lop = PL_last_uni = Nullch;
6466     }
6467     else
6468         sv_setpvn(tmpstr,"",0);   /* avoid "uninitialized" warning */
6469     while (s >= PL_bufend) {    /* multiple line string? */
6470         if (!outer ||
6471          !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
6472             CopLINE_set(PL_curcop, PL_multi_start);
6473             missingterm(PL_tokenbuf);
6474         }
6475         CopLINE_inc(PL_curcop);
6476         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6477         PL_last_lop = PL_last_uni = Nullch;
6478 #ifndef PERL_STRICT_CR
6479         if (PL_bufend - PL_linestart >= 2) {
6480             if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
6481                 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
6482             {
6483                 PL_bufend[-2] = '\n';
6484                 PL_bufend--;
6485                 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
6486             }
6487             else if (PL_bufend[-1] == '\r')
6488                 PL_bufend[-1] = '\n';
6489         }
6490         else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
6491             PL_bufend[-1] = '\n';
6492 #endif
6493         if (PERLDB_LINE && PL_curstash != PL_debstash) {
6494             SV *sv = NEWSV(88,0);
6495
6496             sv_upgrade(sv, SVt_PVMG);
6497             sv_setsv(sv,PL_linestr);
6498             av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv);
6499         }
6500         if (*s == term && memEQ(s,PL_tokenbuf,len)) {
6501             s = PL_bufend - 1;
6502             *s = ' ';
6503             sv_catsv(PL_linestr,herewas);
6504             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6505         }
6506         else {
6507             s = PL_bufend;
6508             sv_catsv(tmpstr,PL_linestr);
6509         }
6510     }
6511     s++;
6512 retval:
6513     PL_multi_end = CopLINE(PL_curcop);
6514     if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
6515         SvLEN_set(tmpstr, SvCUR(tmpstr) + 1);
6516         Renew(SvPVX(tmpstr), SvLEN(tmpstr), char);
6517     }
6518     SvREFCNT_dec(herewas);
6519     if (UTF && !IN_BYTE && is_utf8_string((U8*)SvPVX(tmpstr), SvCUR(tmpstr)))
6520         SvUTF8_on(tmpstr);
6521     PL_lex_stuff = tmpstr;
6522     yylval.ival = op_type;
6523     return s;
6524 }
6525
6526 /* scan_inputsymbol
6527    takes: current position in input buffer
6528    returns: new position in input buffer
6529    side-effects: yylval and lex_op are set.
6530
6531    This code handles:
6532
6533    <>           read from ARGV
6534    <FH>         read from filehandle
6535    <pkg::FH>    read from package qualified filehandle
6536    <pkg'FH>     read from package qualified filehandle
6537    <$fh>        read from filehandle in $fh
6538    <*.h>        filename glob
6539
6540 */
6541
6542 STATIC char *
6543 S_scan_inputsymbol(pTHX_ char *start)
6544 {
6545     register char *s = start;           /* current position in buffer */
6546     register char *d;
6547     register char *e;
6548     char *end;
6549     I32 len;
6550
6551     d = PL_tokenbuf;                    /* start of temp holding space */
6552     e = PL_tokenbuf + sizeof PL_tokenbuf;       /* end of temp holding space */
6553     end = strchr(s, '\n');
6554     if (!end)
6555         end = PL_bufend;
6556     s = delimcpy(d, e, s + 1, end, '>', &len);  /* extract until > */
6557
6558     /* die if we didn't have space for the contents of the <>,
6559        or if it didn't end, or if we see a newline
6560     */
6561
6562     if (len >= sizeof PL_tokenbuf)
6563         Perl_croak(aTHX_ "Excessively long <> operator");
6564     if (s >= end)
6565         Perl_croak(aTHX_ "Unterminated <> operator");
6566
6567     s++;
6568
6569     /* check for <$fh>
6570        Remember, only scalar variables are interpreted as filehandles by
6571        this code.  Anything more complex (e.g., <$fh{$num}>) will be
6572        treated as a glob() call.
6573        This code makes use of the fact that except for the $ at the front,
6574        a scalar variable and a filehandle look the same.
6575     */
6576     if (*d == '$' && d[1]) d++;
6577
6578     /* allow <Pkg'VALUE> or <Pkg::VALUE> */
6579     while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
6580         d++;
6581
6582     /* If we've tried to read what we allow filehandles to look like, and
6583        there's still text left, then it must be a glob() and not a getline.
6584        Use scan_str to pull out the stuff between the <> and treat it
6585        as nothing more than a string.
6586     */
6587
6588     if (d - PL_tokenbuf != len) {
6589         yylval.ival = OP_GLOB;
6590         set_csh();
6591         s = scan_str(start,FALSE,FALSE);
6592         if (!s)
6593            Perl_croak(aTHX_ "Glob not terminated");
6594         return s;
6595     }
6596     else {
6597         /* we're in a filehandle read situation */
6598         d = PL_tokenbuf;
6599
6600         /* turn <> into <ARGV> */
6601         if (!len)
6602             (void)strcpy(d,"ARGV");
6603
6604         /* if <$fh>, create the ops to turn the variable into a
6605            filehandle
6606         */
6607         if (*d == '$') {
6608             I32 tmp;
6609
6610             /* try to find it in the pad for this block, otherwise find
6611                add symbol table ops
6612             */
6613             if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
6614                 OP *o = newOP(OP_PADSV, 0);
6615                 o->op_targ = tmp;
6616                 PL_lex_op = (OP*)newUNOP(OP_READLINE, 0, o);
6617             }
6618             else {
6619                 GV *gv = gv_fetchpv(d+1,TRUE, SVt_PV);
6620                 PL_lex_op = (OP*)newUNOP(OP_READLINE, 0,
6621                                             newUNOP(OP_RV2SV, 0,
6622                                                 newGVOP(OP_GV, 0, gv)));
6623             }
6624             PL_lex_op->op_flags |= OPf_SPECIAL;
6625             /* we created the ops in PL_lex_op, so make yylval.ival a null op */
6626             yylval.ival = OP_NULL;
6627         }
6628
6629         /* If it's none of the above, it must be a literal filehandle
6630            (<Foo::BAR> or <FOO>) so build a simple readline OP */
6631         else {
6632             GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO);
6633             PL_lex_op = (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
6634             yylval.ival = OP_NULL;
6635         }
6636     }
6637
6638     return s;
6639 }
6640
6641
6642 /* scan_str
6643    takes: start position in buffer
6644           keep_quoted preserve \ on the embedded delimiter(s)
6645           keep_delims preserve the delimiters around the string
6646    returns: position to continue reading from buffer
6647    side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
6648         updates the read buffer.
6649
6650    This subroutine pulls a string out of the input.  It is called for:
6651         q               single quotes           q(literal text)
6652         '               single quotes           'literal text'
6653         qq              double quotes           qq(interpolate $here please)
6654         "               double quotes           "interpolate $here please"
6655         qx              backticks               qx(/bin/ls -l)
6656         `               backticks               `/bin/ls -l`
6657         qw              quote words             @EXPORT_OK = qw( func() $spam )
6658         m//             regexp match            m/this/
6659         s///            regexp substitute       s/this/that/
6660         tr///           string transliterate    tr/this/that/
6661         y///            string transliterate    y/this/that/
6662         ($*@)           sub prototypes          sub foo ($)
6663         (stuff)         sub attr parameters     sub foo : attr(stuff)
6664         <>              readline or globs       <FOO>, <>, <$fh>, or <*.c>
6665         
6666    In most of these cases (all but <>, patterns and transliterate)
6667    yylex() calls scan_str().  m// makes yylex() call scan_pat() which
6668    calls scan_str().  s/// makes yylex() call scan_subst() which calls
6669    scan_str().  tr/// and y/// make yylex() call scan_trans() which
6670    calls scan_str().
6671
6672    It skips whitespace before the string starts, and treats the first
6673    character as the delimiter.  If the delimiter is one of ([{< then
6674    the corresponding "close" character )]}> is used as the closing
6675    delimiter.  It allows quoting of delimiters, and if the string has
6676    balanced delimiters ([{<>}]) it allows nesting.
6677
6678    On success, the SV with the resulting string is put into lex_stuff or,
6679    if that is already non-NULL, into lex_repl. The second case occurs only
6680    when parsing the RHS of the special constructs s/// and tr/// (y///).
6681    For convenience, the terminating delimiter character is stuffed into
6682    SvIVX of the SV.
6683 */
6684
6685 STATIC char *
6686 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
6687 {
6688     SV *sv;                             /* scalar value: string */
6689     char *tmps;                         /* temp string, used for delimiter matching */
6690     register char *s = start;           /* current position in the buffer */
6691     register char term;                 /* terminating character */
6692     register char *to;                  /* current position in the sv's data */
6693     I32 brackets = 1;                   /* bracket nesting level */
6694     bool has_utf8 = FALSE;              /* is there any utf8 content? */
6695
6696     /* skip space before the delimiter */
6697     if (isSPACE(*s))
6698         s = skipspace(s);
6699
6700     /* mark where we are, in case we need to report errors */
6701     CLINE;
6702
6703     /* after skipping whitespace, the next character is the terminator */
6704     term = *s;
6705     if (!UTF8_IS_INVARIANT((U8)term) && UTF)
6706         has_utf8 = TRUE;
6707
6708     /* mark where we are */
6709     PL_multi_start = CopLINE(PL_curcop);
6710     PL_multi_open = term;
6711
6712     /* find corresponding closing delimiter */
6713     if (term && (tmps = strchr("([{< )]}> )]}>",term)))
6714         term = tmps[5];
6715     PL_multi_close = term;
6716
6717     /* create a new SV to hold the contents.  87 is leak category, I'm
6718        assuming.  79 is the SV's initial length.  What a random number. */
6719     sv = NEWSV(87,79);
6720     sv_upgrade(sv, SVt_PVIV);
6721     SvIVX(sv) = term;
6722     (void)SvPOK_only(sv);               /* validate pointer */
6723
6724     /* move past delimiter and try to read a complete string */
6725     if (keep_delims)
6726         sv_catpvn(sv, s, 1);
6727     s++;
6728     for (;;) {
6729         /* extend sv if need be */
6730         SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
6731         /* set 'to' to the next character in the sv's string */
6732         to = SvPVX(sv)+SvCUR(sv);
6733
6734         /* if open delimiter is the close delimiter read unbridle */
6735         if (PL_multi_open == PL_multi_close) {
6736             for (; s < PL_bufend; s++,to++) {
6737                 /* embedded newlines increment the current line number */
6738                 if (*s == '\n' && !PL_rsfp)
6739                     CopLINE_inc(PL_curcop);
6740                 /* handle quoted delimiters */
6741                 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
6742                     if (!keep_quoted && s[1] == term)
6743                         s++;
6744                 /* any other quotes are simply copied straight through */
6745                     else
6746                         *to++ = *s++;
6747                 }
6748                 /* terminate when run out of buffer (the for() condition), or
6749                    have found the terminator */
6750                 else if (*s == term)
6751                     break;
6752                 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
6753                     has_utf8 = TRUE;
6754                 *to = *s;
6755             }
6756         }
6757         
6758         /* if the terminator isn't the same as the start character (e.g.,
6759            matched brackets), we have to allow more in the quoting, and
6760            be prepared for nested brackets.
6761         */
6762         else {
6763             /* read until we run out of string, or we find the terminator */
6764             for (; s < PL_bufend; s++,to++) {
6765                 /* embedded newlines increment the line count */
6766                 if (*s == '\n' && !PL_rsfp)
6767                     CopLINE_inc(PL_curcop);
6768                 /* backslashes can escape the open or closing characters */
6769                 if (*s == '\\' && s+1 < PL_bufend) {
6770                     if (!keep_quoted &&
6771                         ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
6772                         s++;
6773                     else
6774                         *to++ = *s++;
6775                 }
6776                 /* allow nested opens and closes */
6777                 else if (*s == PL_multi_close && --brackets <= 0)
6778                     break;
6779                 else if (*s == PL_multi_open)
6780                     brackets++;
6781                 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
6782                     has_utf8 = TRUE;
6783                 *to = *s;
6784             }
6785         }
6786         /* terminate the copied string and update the sv's end-of-string */
6787         *to = '\0';
6788         SvCUR_set(sv, to - SvPVX(sv));
6789
6790         /*
6791          * this next chunk reads more into the buffer if we're not done yet
6792          */
6793
6794         if (s < PL_bufend)
6795             break;              /* handle case where we are done yet :-) */
6796
6797 #ifndef PERL_STRICT_CR
6798         if (to - SvPVX(sv) >= 2) {
6799             if ((to[-2] == '\r' && to[-1] == '\n') ||
6800                 (to[-2] == '\n' && to[-1] == '\r'))
6801             {
6802                 to[-2] = '\n';
6803                 to--;
6804                 SvCUR_set(sv, to - SvPVX(sv));
6805             }
6806             else if (to[-1] == '\r')
6807                 to[-1] = '\n';
6808         }
6809         else if (to - SvPVX(sv) == 1 && to[-1] == '\r')
6810             to[-1] = '\n';
6811 #endif
6812         
6813         /* if we're out of file, or a read fails, bail and reset the current
6814            line marker so we can report where the unterminated string began
6815         */
6816         if (!PL_rsfp ||
6817          !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
6818             sv_free(sv);
6819             CopLINE_set(PL_curcop, PL_multi_start);
6820             return Nullch;
6821         }
6822         /* we read a line, so increment our line counter */
6823         CopLINE_inc(PL_curcop);
6824
6825         /* update debugger info */
6826         if (PERLDB_LINE && PL_curstash != PL_debstash) {
6827             SV *sv = NEWSV(88,0);
6828
6829             sv_upgrade(sv, SVt_PVMG);
6830             sv_setsv(sv,PL_linestr);
6831             av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv);
6832         }
6833
6834         /* having changed the buffer, we must update PL_bufend */
6835         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6836         PL_last_lop = PL_last_uni = Nullch;
6837     }
6838
6839     /* at this point, we have successfully read the delimited string */
6840
6841     if (keep_delims)
6842         sv_catpvn(sv, s, 1);
6843     if (has_utf8)
6844         SvUTF8_on(sv);
6845     PL_multi_end = CopLINE(PL_curcop);
6846     s++;
6847
6848     /* if we allocated too much space, give some back */
6849     if (SvCUR(sv) + 5 < SvLEN(sv)) {
6850         SvLEN_set(sv, SvCUR(sv) + 1);
6851         Renew(SvPVX(sv), SvLEN(sv), char);
6852     }
6853
6854     /* decide whether this is the first or second quoted string we've read
6855        for this op
6856     */
6857
6858     if (PL_lex_stuff)
6859         PL_lex_repl = sv;
6860     else
6861         PL_lex_stuff = sv;
6862     return s;
6863 }
6864
6865 /*
6866   scan_num
6867   takes: pointer to position in buffer
6868   returns: pointer to new position in buffer
6869   side-effects: builds ops for the constant in yylval.op
6870
6871   Read a number in any of the formats that Perl accepts:
6872
6873   0(x[0-7A-F]+)|([0-7]+)|(b[01])
6874   [\d_]+(\.[\d_]*)?[Ee](\d+)
6875
6876   Underbars (_) are allowed in decimal numbers.  If -w is on,
6877   underbars before a decimal point must be at three digit intervals.
6878
6879   Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
6880   thing it reads.
6881
6882   If it reads a number without a decimal point or an exponent, it will
6883   try converting the number to an integer and see if it can do so
6884   without loss of precision.
6885 */
6886
6887 char *
6888 Perl_scan_num(pTHX_ char *start, YYSTYPE* lvalp)
6889 {
6890     register char *s = start;           /* current position in buffer */
6891     register char *d;                   /* destination in temp buffer */
6892     register char *e;                   /* end of temp buffer */
6893     NV nv;                              /* number read, as a double */
6894     SV *sv = Nullsv;                    /* place to put the converted number */
6895     bool floatit;                       /* boolean: int or float? */
6896     char *lastub = 0;                   /* position of last underbar */
6897     static char number_too_long[] = "Number too long";
6898
6899     /* We use the first character to decide what type of number this is */
6900
6901     switch (*s) {
6902     default:
6903       Perl_croak(aTHX_ "panic: scan_num");
6904
6905     /* if it starts with a 0, it could be an octal number, a decimal in
6906        0.13 disguise, or a hexadecimal number, or a binary number. */
6907     case '0':
6908         {
6909           /* variables:
6910              u          holds the "number so far"
6911              shift      the power of 2 of the base
6912                         (hex == 4, octal == 3, binary == 1)
6913              overflowed was the number more than we can hold?
6914
6915              Shift is used when we add a digit.  It also serves as an "are
6916              we in octal/hex/binary?" indicator to disallow hex characters
6917              when in octal mode.
6918            */
6919             NV n = 0.0;
6920             UV u = 0;
6921             I32 shift;
6922             bool overflowed = FALSE;
6923             static NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
6924             static char* bases[5] = { "", "binary", "", "octal",
6925                                       "hexadecimal" };
6926             static char* Bases[5] = { "", "Binary", "", "Octal",
6927                                       "Hexadecimal" };
6928             static char *maxima[5] = { "",
6929                                        "0b11111111111111111111111111111111",
6930                                        "",
6931                                        "037777777777",
6932                                        "0xffffffff" };
6933             char *base, *Base, *max;
6934
6935             /* check for hex */
6936             if (s[1] == 'x') {
6937                 shift = 4;
6938                 s += 2;
6939             } else if (s[1] == 'b') {
6940                 shift = 1;
6941                 s += 2;
6942             }
6943             /* check for a decimal in disguise */
6944             else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
6945                 goto decimal;
6946             /* so it must be octal */
6947             else
6948                 shift = 3;
6949
6950             base = bases[shift];
6951             Base = Bases[shift];
6952             max  = maxima[shift];
6953
6954             /* read the rest of the number */
6955             for (;;) {
6956                 /* x is used in the overflow test,
6957                    b is the digit we're adding on. */
6958                 UV x, b;
6959
6960                 switch (*s) {
6961
6962                 /* if we don't mention it, we're done */
6963                 default:
6964                     goto out;
6965
6966                 /* _ are ignored */
6967                 case '_':
6968                     s++;
6969                     break;
6970
6971                 /* 8 and 9 are not octal */
6972                 case '8': case '9':
6973                     if (shift == 3)
6974                         yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
6975                     /* FALL THROUGH */
6976
6977                 /* octal digits */
6978                 case '2': case '3': case '4':
6979                 case '5': case '6': case '7':
6980                     if (shift == 1)
6981                         yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
6982                     /* FALL THROUGH */
6983
6984                 case '0': case '1':
6985                     b = *s++ & 15;              /* ASCII digit -> value of digit */
6986                     goto digit;
6987
6988                 /* hex digits */
6989                 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
6990                 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
6991                     /* make sure they said 0x */
6992                     if (shift != 4)
6993                         goto out;
6994                     b = (*s++ & 7) + 9;
6995
6996                     /* Prepare to put the digit we have onto the end
6997                        of the number so far.  We check for overflows.
6998                     */
6999
7000                   digit:
7001                     if (!overflowed) {
7002                         x = u << shift; /* make room for the digit */
7003
7004                         if ((x >> shift) != u
7005                             && !(PL_hints & HINT_NEW_BINARY)) {
7006                             overflowed = TRUE;
7007                             n = (NV) u;
7008                             if (ckWARN_d(WARN_OVERFLOW))
7009                                 Perl_warner(aTHX_ WARN_OVERFLOW,
7010                                             "Integer overflow in %s number",
7011                                             base);
7012                         } else
7013                             u = x | b;          /* add the digit to the end */
7014                     }
7015                     if (overflowed) {
7016                         n *= nvshift[shift];
7017                         /* If an NV has not enough bits in its
7018                          * mantissa to represent an UV this summing of
7019                          * small low-order numbers is a waste of time
7020                          * (because the NV cannot preserve the
7021                          * low-order bits anyway): we could just
7022                          * remember when did we overflow and in the
7023                          * end just multiply n by the right
7024                          * amount. */
7025                         n += (NV) b;
7026                     }
7027                     break;
7028                 }
7029             }
7030
7031           /* if we get here, we had success: make a scalar value from
7032              the number.
7033           */
7034           out:
7035             sv = NEWSV(92,0);
7036             if (overflowed) {
7037                 if (ckWARN(WARN_PORTABLE) && n > 4294967295.0)
7038                     Perl_warner(aTHX_ WARN_PORTABLE,
7039                                 "%s number > %s non-portable",
7040                                 Base, max);
7041                 sv_setnv(sv, n);
7042             }
7043             else {
7044 #if UVSIZE > 4
7045                 if (ckWARN(WARN_PORTABLE) && u > 0xffffffff)
7046                     Perl_warner(aTHX_ WARN_PORTABLE,
7047                                 "%s number > %s non-portable",
7048                                 Base, max);
7049 #endif
7050                 sv_setuv(sv, u);
7051             }
7052             if (PL_hints & HINT_NEW_BINARY)
7053                 sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL);
7054         }
7055         break;
7056
7057     /*
7058       handle decimal numbers.
7059       we're also sent here when we read a 0 as the first digit
7060     */
7061     case '1': case '2': case '3': case '4': case '5':
7062     case '6': case '7': case '8': case '9': case '.':
7063       decimal:
7064         d = PL_tokenbuf;
7065         e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
7066         floatit = FALSE;
7067
7068         /* read next group of digits and _ and copy into d */
7069         while (isDIGIT(*s) || *s == '_') {
7070             /* skip underscores, checking for misplaced ones
7071                if -w is on
7072             */
7073             if (*s == '_') {
7074                 if (ckWARN(WARN_SYNTAX) && lastub && s - lastub != 3)
7075                     Perl_warner(aTHX_ WARN_SYNTAX, "Misplaced _ in number");
7076                 lastub = ++s;
7077             }
7078             else {
7079                 /* check for end of fixed-length buffer */
7080                 if (d >= e)
7081                     Perl_croak(aTHX_ number_too_long);
7082                 /* if we're ok, copy the character */
7083                 *d++ = *s++;
7084             }
7085         }
7086
7087         /* final misplaced underbar check */
7088         if (lastub && s - lastub != 3) {
7089             if (ckWARN(WARN_SYNTAX))
7090                 Perl_warner(aTHX_ WARN_SYNTAX, "Misplaced _ in number");
7091         }
7092
7093         /* read a decimal portion if there is one.  avoid
7094            3..5 being interpreted as the number 3. followed
7095            by .5
7096         */
7097         if (*s == '.' && s[1] != '.') {
7098             floatit = TRUE;
7099             *d++ = *s++;
7100
7101             /* copy, ignoring underbars, until we run out of
7102                digits.  Note: no misplaced underbar checks!
7103             */
7104             for (; isDIGIT(*s) || *s == '_'; s++) {
7105                 /* fixed length buffer check */
7106                 if (d >= e)
7107                     Perl_croak(aTHX_ number_too_long);
7108                 if (*s != '_')
7109                     *d++ = *s;
7110             }
7111             if (*s == '.' && isDIGIT(s[1])) {
7112                 /* oops, it's really a v-string, but without the "v" */
7113                 s = start - 1;
7114                 goto vstring;
7115             }
7116         }
7117
7118         /* read exponent part, if present */
7119         if (*s && strchr("eE",*s) && strchr("+-0123456789",s[1])) {
7120             floatit = TRUE;
7121             s++;
7122
7123             /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
7124             *d++ = 'e';         /* At least some Mach atof()s don't grok 'E' */
7125
7126             /* allow positive or negative exponent */
7127             if (*s == '+' || *s == '-')
7128                 *d++ = *s++;
7129
7130             /* read digits of exponent (no underbars :-) */
7131             while (isDIGIT(*s)) {
7132                 if (d >= e)
7133                     Perl_croak(aTHX_ number_too_long);
7134                 *d++ = *s++;
7135             }
7136         }
7137
7138         /* terminate the string */
7139         *d = '\0';
7140
7141         /* make an sv from the string */
7142         sv = NEWSV(92,0);
7143
7144 #if defined(Strtol) && defined(Strtoul)
7145
7146         /*
7147            strtol/strtoll sets errno to ERANGE if the number is too big
7148            for an integer. We try to do an integer conversion first
7149            if no characters indicating "float" have been found.
7150          */
7151
7152         if (!floatit) {
7153             IV iv;
7154             UV uv;
7155             errno = 0;
7156             if (*PL_tokenbuf == '-')
7157                 iv = Strtol(PL_tokenbuf, (char**)NULL, 10);
7158             else
7159                 uv = Strtoul(PL_tokenbuf, (char**)NULL, 10);
7160             if (errno)
7161                 floatit = TRUE; /* Probably just too large. */
7162             else if (*PL_tokenbuf == '-')
7163                 sv_setiv(sv, iv);
7164             else if (uv <= IV_MAX)
7165                 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
7166             else
7167                 sv_setuv(sv, uv);
7168         }
7169         if (floatit) {
7170             nv = Atof(PL_tokenbuf);
7171             sv_setnv(sv, nv);
7172         }
7173 #else
7174         /*
7175            No working strtou?ll?.
7176
7177            Unfortunately atol() doesn't do range checks (returning
7178            LONG_MIN/LONG_MAX, and setting errno to ERANGE on overflows)
7179            everywhere [1], so we cannot use use atol() (or atoll()).
7180            If we could, they would be used, as Atol(), very much like
7181            Strtol() and Strtoul() are used above.
7182
7183            [1] XXX Configure test needed to check for atol()
7184                    (and atoll()) overflow behaviour XXX
7185
7186            --jhi
7187
7188            We need to do this the hard way.  */
7189
7190         nv = Atof(PL_tokenbuf);
7191
7192         /* See if we can make do with an integer value without loss of
7193            precision.  We use U_V to cast to a UV, because some
7194            compilers have issues.  Then we try casting it back and see
7195            if it was the same [1].  We only do this if we know we
7196            specifically read an integer.  If floatit is true, then we
7197            don't need to do the conversion at all.
7198
7199            [1] Note that this is lossy if our NVs cannot preserve our
7200            UVs.  There are metaconfig defines NV_PRESERVES_UV (a boolean)
7201            and NV_PRESERVES_UV_BITS (a number), but in general we really
7202            do hope all such potentially lossy platforms have strtou?ll?
7203            to do a lossless IV/UV conversion.
7204
7205            Maybe could do some tricks with DBL_DIG, LDBL_DIG and
7206            DBL_MANT_DIG and LDBL_MANT_DIG (these are already available
7207            as NV_DIG and NV_MANT_DIG)?
7208         
7209            --jhi
7210            */
7211         {
7212             UV uv = U_V(nv);
7213             if (!floatit && (NV)uv == nv) {
7214                 if (uv <= IV_MAX)
7215                     sv_setiv(sv, uv); /* Prefer IVs over UVs. */
7216                 else
7217                     sv_setuv(sv, uv);
7218             }
7219             else
7220                 sv_setnv(sv, nv);
7221         }
7222 #endif
7223         if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
7224                        (PL_hints & HINT_NEW_INTEGER) )
7225             sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
7226                               (floatit ? "float" : "integer"),
7227                               sv, Nullsv, NULL);
7228         break;
7229
7230     /* if it starts with a v, it could be a v-string */
7231     case 'v':
7232 vstring:
7233         {
7234             char *pos = s;
7235             pos++;
7236             while (isDIGIT(*pos) || *pos == '_')
7237                 pos++;
7238             if (!isALPHA(*pos)) {
7239                 UV rev;
7240                 U8 tmpbuf[UTF8_MAXLEN+1];
7241                 U8 *tmpend;
7242                 s++;                            /* get past 'v' */
7243
7244                 sv = NEWSV(92,5);
7245                 sv_setpvn(sv, "", 0);
7246
7247                 for (;;) {
7248                     if (*s == '0' && isDIGIT(s[1]))
7249                         yyerror("Octal number in vector unsupported");
7250                     rev = 0;
7251                     {
7252                         /* this is atoi() that tolerates underscores */
7253                         char *end = pos;
7254                         UV mult = 1;
7255                         while (--end >= s) {
7256                             UV orev;
7257                             if (*end == '_')
7258                                 continue;
7259                             orev = rev;
7260                             rev += (*end - '0') * mult;
7261                             mult *= 10;
7262                             if (orev > rev && ckWARN_d(WARN_OVERFLOW))
7263                                 Perl_warner(aTHX_ WARN_OVERFLOW,
7264                                             "Integer overflow in decimal number");
7265                         }
7266                     }
7267                     /* Append native character for the rev point */
7268                     tmpend = uvchr_to_utf8(tmpbuf, rev);
7269                     sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
7270                     if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
7271                         SvUTF8_on(sv);
7272                     if (*pos == '.' && isDIGIT(pos[1]))
7273                         s = ++pos;
7274                     else {
7275                         s = pos;
7276                         break;
7277                     }
7278                     while (isDIGIT(*pos) || *pos == '_')
7279                         pos++;
7280                 }
7281                 SvPOK_on(sv);
7282                 SvREADONLY_on(sv);
7283             }
7284         }
7285         break;
7286     }
7287
7288     /* make the op for the constant and return */
7289
7290     if (sv)
7291         lvalp->opval = newSVOP(OP_CONST, 0, sv);
7292     else
7293         lvalp->opval = Nullop;
7294
7295     return s;
7296 }
7297
7298 STATIC char *
7299 S_scan_formline(pTHX_ register char *s)
7300 {
7301     register char *eol;
7302     register char *t;
7303     SV *stuff = newSVpvn("",0);
7304     bool needargs = FALSE;
7305
7306     while (!needargs) {
7307         if (*s == '.' || *s == /*{*/'}') {
7308             /*SUPPRESS 530*/
7309 #ifdef PERL_STRICT_CR
7310             for (t = s+1;SPACE_OR_TAB(*t); t++) ;
7311 #else
7312             for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
7313 #endif
7314             if (*t == '\n' || t == PL_bufend)
7315                 break;
7316         }
7317         if (PL_in_eval && !PL_rsfp) {
7318             eol = strchr(s,'\n');
7319             if (!eol++)
7320                 eol = PL_bufend;
7321         }
7322         else
7323             eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
7324         if (*s != '#') {
7325             for (t = s; t < eol; t++) {
7326                 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
7327                     needargs = FALSE;
7328                     goto enough;        /* ~~ must be first line in formline */
7329                 }
7330                 if (*t == '@' || *t == '^')
7331                     needargs = TRUE;
7332             }
7333             sv_catpvn(stuff, s, eol-s);
7334 #ifndef PERL_STRICT_CR
7335             if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
7336                 char *end = SvPVX(stuff) + SvCUR(stuff);
7337                 end[-2] = '\n';
7338                 end[-1] = '\0';
7339                 SvCUR(stuff)--;
7340             }
7341 #endif
7342         }
7343         s = eol;
7344         if (PL_rsfp) {
7345             s = filter_gets(PL_linestr, PL_rsfp, 0);
7346             PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
7347             PL_bufend = PL_bufptr + SvCUR(PL_linestr);
7348             PL_last_lop = PL_last_uni = Nullch;
7349             if (!s) {
7350                 s = PL_bufptr;
7351                 yyerror("Format not terminated");
7352                 break;
7353             }
7354         }
7355         incline(s);
7356     }
7357   enough:
7358     if (SvCUR(stuff)) {
7359         PL_expect = XTERM;
7360         if (needargs) {
7361             PL_lex_state = LEX_NORMAL;
7362             PL_nextval[PL_nexttoke].ival = 0;
7363             force_next(',');
7364         }
7365         else
7366             PL_lex_state = LEX_FORMLINE;
7367         PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff);
7368         force_next(THING);
7369         PL_nextval[PL_nexttoke].ival = OP_FORMLINE;
7370         force_next(LSTOP);
7371     }
7372     else {
7373         SvREFCNT_dec(stuff);
7374         PL_lex_formbrack = 0;
7375         PL_bufptr = s;
7376     }
7377     return s;
7378 }
7379
7380 STATIC void
7381 S_set_csh(pTHX)
7382 {
7383 #ifdef CSH
7384     if (!PL_cshlen)
7385         PL_cshlen = strlen(PL_cshname);
7386 #endif
7387 }
7388
7389 I32
7390 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
7391 {
7392     I32 oldsavestack_ix = PL_savestack_ix;
7393     CV* outsidecv = PL_compcv;
7394     AV* comppadlist;
7395
7396     if (PL_compcv) {
7397         assert(SvTYPE(PL_compcv) == SVt_PVCV);
7398     }
7399     SAVEI32(PL_subline);
7400     save_item(PL_subname);
7401     SAVEI32(PL_padix);
7402     SAVECOMPPAD();
7403     SAVESPTR(PL_comppad_name);
7404     SAVESPTR(PL_compcv);
7405     SAVEI32(PL_comppad_name_fill);
7406     SAVEI32(PL_min_intro_pending);
7407     SAVEI32(PL_max_intro_pending);
7408     SAVEI32(PL_pad_reset_pending);
7409
7410     PL_compcv = (CV*)NEWSV(1104,0);
7411     sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
7412     CvFLAGS(PL_compcv) |= flags;
7413
7414     PL_comppad = newAV();
7415     av_push(PL_comppad, Nullsv);
7416     PL_curpad = AvARRAY(PL_comppad);
7417     PL_comppad_name = newAV();
7418     PL_comppad_name_fill = 0;
7419     PL_min_intro_pending = 0;
7420     PL_padix = 0;
7421     PL_subline = CopLINE(PL_curcop);
7422 #ifdef USE_THREADS
7423     av_store(PL_comppad_name, 0, newSVpvn("@_", 2));
7424     PL_curpad[0] = (SV*)newAV();
7425     SvPADMY_on(PL_curpad[0]);   /* XXX Needed? */
7426 #endif /* USE_THREADS */
7427
7428     comppadlist = newAV();
7429     AvREAL_off(comppadlist);
7430     av_store(comppadlist, 0, (SV*)PL_comppad_name);
7431     av_store(comppadlist, 1, (SV*)PL_comppad);
7432
7433     CvPADLIST(PL_compcv) = comppadlist;
7434     CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv);
7435 #ifdef USE_THREADS
7436     CvOWNER(PL_compcv) = 0;
7437     New(666, CvMUTEXP(PL_compcv), 1, perl_mutex);
7438     MUTEX_INIT(CvMUTEXP(PL_compcv));
7439 #endif /* USE_THREADS */
7440
7441     return oldsavestack_ix;
7442 }
7443
7444 #ifdef __SC__
7445 #pragma segment Perl_yylex
7446 #endif
7447 int
7448 Perl_yywarn(pTHX_ char *s)
7449 {
7450     PL_in_eval |= EVAL_WARNONLY;
7451     yyerror(s);
7452     PL_in_eval &= ~EVAL_WARNONLY;
7453     return 0;
7454 }
7455
7456 int
7457 Perl_yyerror(pTHX_ char *s)
7458 {
7459     char *where = NULL;
7460     char *context = NULL;
7461     int contlen = -1;
7462     SV *msg;
7463
7464     if (!yychar || (yychar == ';' && !PL_rsfp))
7465         where = "at EOF";
7466     else if (PL_bufptr > PL_oldoldbufptr && PL_bufptr - PL_oldoldbufptr < 200 &&
7467       PL_oldoldbufptr != PL_oldbufptr && PL_oldbufptr != PL_bufptr) {
7468         while (isSPACE(*PL_oldoldbufptr))
7469             PL_oldoldbufptr++;
7470         context = PL_oldoldbufptr;
7471         contlen = PL_bufptr - PL_oldoldbufptr;
7472     }
7473     else if (PL_bufptr > PL_oldbufptr && PL_bufptr - PL_oldbufptr < 200 &&
7474       PL_oldbufptr != PL_bufptr) {
7475         while (isSPACE(*PL_oldbufptr))
7476             PL_oldbufptr++;
7477         context = PL_oldbufptr;
7478         contlen = PL_bufptr - PL_oldbufptr;
7479     }
7480     else if (yychar > 255)
7481         where = "next token ???";
7482 #ifdef USE_PURE_BISON
7483 /*  GNU Bison sets the value -2 */
7484     else if (yychar == -2) {
7485 #else
7486     else if ((yychar & 127) == 127) {
7487 #endif
7488         if (PL_lex_state == LEX_NORMAL ||
7489            (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
7490             where = "at end of line";
7491         else if (PL_lex_inpat)
7492             where = "within pattern";
7493         else
7494             where = "within string";
7495     }
7496     else {
7497         SV *where_sv = sv_2mortal(newSVpvn("next char ", 10));
7498         if (yychar < 32)
7499             Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
7500         else if (isPRINT_LC(yychar))
7501             Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
7502         else
7503             Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
7504         where = SvPVX(where_sv);
7505     }
7506     msg = sv_2mortal(newSVpv(s, 0));
7507     Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
7508                    CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
7509     if (context)
7510         Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
7511     else
7512         Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
7513     if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
7514         Perl_sv_catpvf(aTHX_ msg,
7515         "  (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
7516                 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
7517         PL_multi_end = 0;
7518     }
7519     if (PL_in_eval & EVAL_WARNONLY)
7520         Perl_warn(aTHX_ "%"SVf, msg);
7521     else
7522         qerror(msg);
7523     if (PL_error_count >= 10) {
7524         if (PL_in_eval && SvCUR(ERRSV))
7525             Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
7526                        ERRSV, CopFILE(PL_curcop));
7527         else
7528             Perl_croak(aTHX_ "%s has too many errors.\n",
7529                        CopFILE(PL_curcop));
7530     }
7531     PL_in_my = 0;
7532     PL_in_my_stash = Nullhv;
7533     return 0;
7534 }
7535 #ifdef __SC__
7536 #pragma segment Main
7537 #endif
7538
7539 STATIC char*
7540 S_swallow_bom(pTHX_ U8 *s)
7541 {
7542     STRLEN slen;
7543     slen = SvCUR(PL_linestr);
7544     switch (*s) {
7545     case 0xFF:
7546         if (s[1] == 0xFE) {
7547             /* UTF-16 little-endian */
7548             if (s[2] == 0 && s[3] == 0)  /* UTF-32 little-endian */
7549                 Perl_croak(aTHX_ "Unsupported script encoding");
7550 #ifndef PERL_NO_UTF16_FILTER
7551             DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-LE script encoding\n"));
7552             s += 2;
7553             if (PL_bufend > (char*)s) {
7554                 U8 *news;
7555                 I32 newlen;
7556
7557                 filter_add(utf16rev_textfilter, NULL);
7558                 New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
7559                 PL_bufend = (char*)utf16_to_utf8_reversed(s, news,
7560                                                  PL_bufend - (char*)s - 1,
7561                                                  &newlen);
7562                 Copy(news, s, newlen, U8);
7563                 SvCUR_set(PL_linestr, newlen);
7564                 PL_bufend = SvPVX(PL_linestr) + newlen;
7565                 news[newlen++] = '\0';
7566                 Safefree(news);
7567             }
7568 #else
7569             Perl_croak(aTHX_ "Unsupported script encoding");
7570 #endif
7571         }
7572         break;
7573     case 0xFE:
7574         if (s[1] == 0xFF) {   /* UTF-16 big-endian */
7575 #ifndef PERL_NO_UTF16_FILTER
7576             DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding\n"));
7577             s += 2;
7578             if (PL_bufend > (char *)s) {
7579                 U8 *news;
7580                 I32 newlen;
7581
7582                 filter_add(utf16_textfilter, NULL);
7583                 New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
7584                 PL_bufend = (char*)utf16_to_utf8(s, news,
7585                                                  PL_bufend - (char*)s,
7586                                                  &newlen);
7587                 Copy(news, s, newlen, U8);
7588                 SvCUR_set(PL_linestr, newlen);
7589                 PL_bufend = SvPVX(PL_linestr) + newlen;
7590                 news[newlen++] = '\0';
7591                 Safefree(news);
7592             }
7593 #else
7594             Perl_croak(aTHX_ "Unsupported script encoding");
7595 #endif
7596         }
7597         break;
7598     case 0xEF:
7599         if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
7600             DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-8 script encoding\n"));
7601             s += 3;                      /* UTF-8 */
7602         }
7603         break;
7604     case 0:
7605         if (slen > 3 && s[1] == 0 &&  /* UTF-32 big-endian */
7606             s[2] == 0xFE && s[3] == 0xFF)
7607         {
7608             Perl_croak(aTHX_ "Unsupported script encoding");
7609         }
7610     }
7611     return (char*)s;
7612 }
7613
7614 #ifdef PERL_OBJECT
7615 #include "XSUB.h"
7616 #endif
7617
7618 /*
7619  * restore_rsfp
7620  * Restore a source filter.
7621  */
7622
7623 static void
7624 restore_rsfp(pTHXo_ void *f)
7625 {
7626     PerlIO *fp = (PerlIO*)f;
7627
7628     if (PL_rsfp == PerlIO_stdin())
7629         PerlIO_clearerr(PL_rsfp);
7630     else if (PL_rsfp && (PL_rsfp != fp))
7631         PerlIO_close(PL_rsfp);
7632     PL_rsfp = fp;
7633 }
7634
7635 #ifndef PERL_NO_UTF16_FILTER
7636 static I32
7637 utf16_textfilter(pTHXo_ int idx, SV *sv, int maxlen)
7638 {
7639     I32 count = FILTER_READ(idx+1, sv, maxlen);
7640     if (count) {
7641         U8* tmps;
7642         U8* tend;
7643         I32 newlen;
7644         New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
7645         if (!*SvPV_nolen(sv))
7646         /* Game over, but don't feed an odd-length string to utf16_to_utf8 */
7647         return count;
7648
7649         tend = utf16_to_utf8((U8*)SvPVX(sv), tmps, SvCUR(sv), &newlen);
7650         sv_usepvn(sv, (char*)tmps, tend - tmps);
7651     }
7652     return count;
7653 }
7654
7655 static I32
7656 utf16rev_textfilter(pTHXo_ int idx, SV *sv, int maxlen)
7657 {
7658     I32 count = FILTER_READ(idx+1, sv, maxlen);
7659     if (count) {
7660         U8* tmps;
7661         U8* tend;
7662         I32 newlen;
7663         if (!*SvPV_nolen(sv))
7664         /* Game over, but don't feed an odd-length string to utf16_to_utf8 */
7665         return count;
7666
7667         New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
7668         tend = utf16_to_utf8_reversed((U8*)SvPVX(sv), tmps, SvCUR(sv), &newlen);
7669         sv_usepvn(sv, (char*)tmps, tend - tmps);
7670     }
7671     return count;
7672 }
7673 #endif