3 * Copyright (c) 1991-2001, Larry Wall
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.
11 * "It all comes from here, the stench and the peril." --Frodo
15 * This file is the lexer for Perl. It's closely linked to the
18 * The main routine is yylex(), which returns the next token.
22 #define PERL_IN_TOKE_C
25 #define yychar PL_yychar
26 #define yylval PL_yylval
28 static char ident_too_long[] = "Identifier too long";
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);
36 #define XFAKEBRACK 128
39 /*#define UTF (SvUTF8(PL_linestr) && !(PL_hints & HINT_BYTE))*/
40 #define UTF (PL_hints & HINT_UTF8)
42 /* In variables name $^X, these are the legal values for X.
43 * 1999-02-27 mjd-perl-patch@plover.com */
44 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
46 /* On MacOS, respect nonbreaking spaces */
47 #ifdef MACOS_TRADITIONAL
48 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
50 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
53 /* LEX_* are values for PL_lex_state, the state of the lexer.
54 * They are arranged oddly so that the guard on the switch statement
55 * can get by with a single comparison (if the compiler is smart enough).
58 /* #define LEX_NOTPARSING 11 is done in perl.h. */
61 #define LEX_INTERPNORMAL 9
62 #define LEX_INTERPCASEMOD 8
63 #define LEX_INTERPPUSH 7
64 #define LEX_INTERPSTART 6
65 #define LEX_INTERPEND 5
66 #define LEX_INTERPENDMAYBE 4
67 #define LEX_INTERPCONCAT 3
68 #define LEX_INTERPCONST 2
69 #define LEX_FORMLINE 1
70 #define LEX_KNOWNEXT 0
78 # define YYMAXLEVEL 100
80 YYSTYPE* yylval_pointer[YYMAXLEVEL];
81 int* yychar_pointer[YYMAXLEVEL];
85 # define yylval (*yylval_pointer[yyactlevel])
86 # define yychar (*yychar_pointer[yyactlevel])
87 # define PERL_YYLEX_PARAM yylval_pointer[yyactlevel],yychar_pointer[yyactlevel]
89 # define yylex() Perl_yylex_r(aTHX_ yylval_pointer[yyactlevel],yychar_pointer[yyactlevel])
94 /* CLINE is a macro that ensures PL_copline has a sane value */
99 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
102 * Convenience functions to return different tokens and prime the
103 * lexer for the next token. They all take an argument.
105 * TOKEN : generic token (used for '(', DOLSHARP, etc)
106 * OPERATOR : generic operator
107 * AOPERATOR : assignment operator
108 * PREBLOCK : beginning the block after an if, while, foreach, ...
109 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
110 * PREREF : *EXPR where EXPR is not a simple identifier
111 * TERM : expression term
112 * LOOPX : loop exiting command (goto, last, dump, etc)
113 * FTST : file test operator
114 * FUN0 : zero-argument function
115 * FUN1 : not used, except for not, which isn't a UNIOP
116 * BOop : bitwise or or xor
118 * SHop : shift operator
119 * PWop : power operator
120 * PMop : pattern-matching operator
121 * Aop : addition-level operator
122 * Mop : multiplication-level operator
123 * Eop : equality-testing operator
124 * Rop : relational operator <= != gt
126 * Also see LOP and lop() below.
129 #define TOKEN(retval) return (PL_bufptr = s,(int)retval)
130 #define OPERATOR(retval) return (PL_expect = XTERM,PL_bufptr = s,(int)retval)
131 #define AOPERATOR(retval) return ao((PL_expect = XTERM,PL_bufptr = s,(int)retval))
132 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s,(int)retval)
133 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s,(int)retval)
134 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s,(int)retval)
135 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR,PL_bufptr = s,(int)retval)
136 #define LOOPX(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LOOPEX)
137 #define FTST(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)UNIOP)
138 #define FUN0(f) return(yylval.ival = f,PL_expect = XOPERATOR,PL_bufptr = s,(int)FUNC0)
139 #define FUN1(f) return(yylval.ival = f,PL_expect = XOPERATOR,PL_bufptr = s,(int)FUNC1)
140 #define BOop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)BITOROP))
141 #define BAop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)BITANDOP))
142 #define SHop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)SHIFTOP))
143 #define PWop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)POWOP))
144 #define PMop(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)MATCHOP)
145 #define Aop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)ADDOP))
146 #define Mop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)MULOP))
147 #define Eop(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)EQOP)
148 #define Rop(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)RELOP)
150 /* This bit of chicanery makes a unary function followed by
151 * a parenthesis into a function with one argument, highest precedence.
153 #define UNI(f) return(yylval.ival = f, \
156 PL_last_uni = PL_oldbufptr, \
157 PL_last_lop_op = f, \
158 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
160 #define UNIBRACK(f) return(yylval.ival = f, \
162 PL_last_uni = PL_oldbufptr, \
163 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
165 /* grandfather return to old style */
166 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
171 * This subroutine detects &&= and ||= and turns an ANDAND or OROR
172 * into an OP_ANDASSIGN or OP_ORASSIGN
176 S_ao(pTHX_ int toketype)
178 if (*PL_bufptr == '=') {
180 if (toketype == ANDAND)
181 yylval.ival = OP_ANDASSIGN;
182 else if (toketype == OROR)
183 yylval.ival = OP_ORASSIGN;
191 * When Perl expects an operator and finds something else, no_op
192 * prints the warning. It always prints "<something> found where
193 * operator expected. It prints "Missing semicolon on previous line?"
194 * if the surprise occurs at the start of the line. "do you need to
195 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
196 * where the compiler doesn't know if foo is a method call or a function.
197 * It prints "Missing operator before end of line" if there's nothing
198 * after the missing operator, or "... before <...>" if there is something
199 * after the missing operator.
203 S_no_op(pTHX_ char *what, char *s)
205 char *oldbp = PL_bufptr;
206 bool is_first = (PL_oldbufptr == PL_linestart);
212 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
214 Perl_warn(aTHX_ "\t(Missing semicolon on previous line?)\n");
215 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
217 for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ;
218 if (t < PL_bufptr && isSPACE(*t))
219 Perl_warn(aTHX_ "\t(Do you need to predeclare %.*s?)\n",
220 t - PL_oldoldbufptr, PL_oldoldbufptr);
224 Perl_warn(aTHX_ "\t(Missing operator before %.*s?)\n", s - oldbp, oldbp);
231 * Complain about missing quote/regexp/heredoc terminator.
232 * If it's called with (char *)NULL then it cauterizes the line buffer.
233 * If we're in a delimited string and the delimiter is a control
234 * character, it's reformatted into a two-char sequence like ^C.
239 S_missingterm(pTHX_ char *s)
244 char *nl = strrchr(s,'\n');
250 iscntrl(PL_multi_close)
252 PL_multi_close < 32 || PL_multi_close == 127
256 tmpbuf[1] = toCTRL(PL_multi_close);
262 *tmpbuf = PL_multi_close;
266 q = strchr(s,'"') ? '\'' : '"';
267 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
275 Perl_deprecate(pTHX_ char *s)
277 if (ckWARN(WARN_DEPRECATED))
278 Perl_warner(aTHX_ WARN_DEPRECATED, "Use of %s is deprecated", s);
283 * Deprecate a comma-less variable list.
289 deprecate("comma-less variable list");
293 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
294 * utf16-to-utf8-reversed.
297 #ifdef PERL_CR_FILTER
301 register char *s = SvPVX(sv);
302 register char *e = s + SvCUR(sv);
303 /* outer loop optimized to do nothing if there are no CR-LFs */
305 if (*s++ == '\r' && *s == '\n') {
306 /* hit a CR-LF, need to copy the rest */
307 register char *d = s - 1;
310 if (*s == '\r' && s[1] == '\n')
321 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
323 I32 count = FILTER_READ(idx+1, sv, maxlen);
324 if (count > 0 && !maxlen)
332 * Initialize variables. Uses the Perl save_stack to save its state (for
333 * recursive calls to the parser).
337 Perl_lex_start(pTHX_ SV *line)
342 SAVEI32(PL_lex_dojoin);
343 SAVEI32(PL_lex_brackets);
344 SAVEI32(PL_lex_casemods);
345 SAVEI32(PL_lex_starts);
346 SAVEI32(PL_lex_state);
347 SAVEVPTR(PL_lex_inpat);
348 SAVEI32(PL_lex_inwhat);
349 if (PL_lex_state == LEX_KNOWNEXT) {
350 I32 toke = PL_nexttoke;
351 while (--toke >= 0) {
352 SAVEI32(PL_nexttype[toke]);
353 SAVEVPTR(PL_nextval[toke]);
355 SAVEI32(PL_nexttoke);
357 SAVECOPLINE(PL_curcop);
360 SAVEPPTR(PL_oldbufptr);
361 SAVEPPTR(PL_oldoldbufptr);
362 SAVEPPTR(PL_last_lop);
363 SAVEPPTR(PL_last_uni);
364 SAVEPPTR(PL_linestart);
365 SAVESPTR(PL_linestr);
366 SAVEPPTR(PL_lex_brackstack);
367 SAVEPPTR(PL_lex_casestack);
368 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
369 SAVESPTR(PL_lex_stuff);
370 SAVEI32(PL_lex_defer);
371 SAVEI32(PL_sublex_info.sub_inwhat);
372 SAVESPTR(PL_lex_repl);
374 SAVEINT(PL_lex_expect);
376 PL_lex_state = LEX_NORMAL;
380 New(899, PL_lex_brackstack, 120, char);
381 New(899, PL_lex_casestack, 12, char);
382 SAVEFREEPV(PL_lex_brackstack);
383 SAVEFREEPV(PL_lex_casestack);
385 *PL_lex_casestack = '\0';
388 PL_lex_stuff = Nullsv;
389 PL_lex_repl = Nullsv;
393 PL_sublex_info.sub_inwhat = 0;
395 if (SvREADONLY(PL_linestr))
396 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
397 s = SvPV(PL_linestr, len);
398 if (len && s[len-1] != ';') {
399 if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
400 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
401 sv_catpvn(PL_linestr, "\n;", 2);
403 SvTEMP_off(PL_linestr);
404 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
405 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
406 PL_last_lop = PL_last_uni = Nullch;
408 PL_rs = newSVpvn("\n", 1);
414 * Finalizer for lexing operations. Must be called when the parser is
415 * done with the lexer.
421 PL_doextract = FALSE;
426 * This subroutine has nothing to do with tilting, whether at windmills
427 * or pinball tables. Its name is short for "increment line". It
428 * increments the current line number in CopLINE(PL_curcop) and checks
429 * to see whether the line starts with a comment of the form
430 * # line 500 "foo.pm"
431 * If so, it sets the current line number and file to the values in the comment.
435 S_incline(pTHX_ char *s)
442 CopLINE_inc(PL_curcop);
445 while (SPACE_OR_TAB(*s)) s++;
446 if (strnEQ(s, "line", 4))
450 if (SPACE_OR_TAB(*s))
454 while (SPACE_OR_TAB(*s)) s++;
460 while (SPACE_OR_TAB(*s))
462 if (*s == '"' && (t = strchr(s+1, '"'))) {
467 for (t = s; !isSPACE(*t); t++) ;
470 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
472 if (*e != '\n' && *e != '\0')
473 return; /* false alarm */
479 Safefree(CopFILE(PL_curcop));
481 SvREFCNT_dec(CopFILEGV(PL_curcop));
483 CopFILE_set(PL_curcop, s);
486 CopLINE_set(PL_curcop, atoi(n)-1);
491 * Called to gobble the appropriate amount and type of whitespace.
492 * Skips comments as well.
496 S_skipspace(pTHX_ register char *s)
498 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
499 while (s < PL_bufend && SPACE_OR_TAB(*s))
505 SSize_t oldprevlen, oldoldprevlen;
506 SSize_t oldloplen, oldunilen;
507 while (s < PL_bufend && isSPACE(*s)) {
508 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
513 if (s < PL_bufend && *s == '#') {
514 while (s < PL_bufend && *s != '\n')
518 if (PL_in_eval && !PL_rsfp) {
525 /* only continue to recharge the buffer if we're at the end
526 * of the buffer, we're not reading from a source filter, and
527 * we're in normal lexing mode
529 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
530 PL_lex_state == LEX_FORMLINE)
533 /* try to recharge the buffer */
534 if ((s = filter_gets(PL_linestr, PL_rsfp,
535 (prevlen = SvCUR(PL_linestr)))) == Nullch)
537 /* end of file. Add on the -p or -n magic */
538 if (PL_minus_n || PL_minus_p) {
539 sv_setpv(PL_linestr,PL_minus_p ?
540 ";}continue{print or die qq(-p destination: $!\\n)" :
542 sv_catpv(PL_linestr,";}");
543 PL_minus_n = PL_minus_p = 0;
546 sv_setpv(PL_linestr,";");
548 /* reset variables for next time we lex */
549 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
551 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
552 PL_last_lop = PL_last_uni = Nullch;
554 /* Close the filehandle. Could be from -P preprocessor,
555 * STDIN, or a regular file. If we were reading code from
556 * STDIN (because the commandline held no -e or filename)
557 * then we don't close it, we reset it so the code can
558 * read from STDIN too.
561 if (PL_preprocess && !PL_in_eval)
562 (void)PerlProc_pclose(PL_rsfp);
563 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
564 PerlIO_clearerr(PL_rsfp);
566 (void)PerlIO_close(PL_rsfp);
571 /* not at end of file, so we only read another line */
572 /* make corresponding updates to old pointers, for yyerror() */
573 oldprevlen = PL_oldbufptr - PL_bufend;
574 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
576 oldunilen = PL_last_uni - PL_bufend;
578 oldloplen = PL_last_lop - PL_bufend;
579 PL_linestart = PL_bufptr = s + prevlen;
580 PL_bufend = s + SvCUR(PL_linestr);
582 PL_oldbufptr = s + oldprevlen;
583 PL_oldoldbufptr = s + oldoldprevlen;
585 PL_last_uni = s + oldunilen;
587 PL_last_lop = s + oldloplen;
590 /* debugger active and we're not compiling the debugger code,
591 * so store the line into the debugger's array of lines
593 if (PERLDB_LINE && PL_curstash != PL_debstash) {
594 SV *sv = NEWSV(85,0);
596 sv_upgrade(sv, SVt_PVMG);
597 sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
598 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
605 * Check the unary operators to ensure there's no ambiguity in how they're
606 * used. An ambiguous piece of code would be:
608 * This doesn't mean rand() + 5. Because rand() is a unary operator,
609 * the +5 is its argument.
618 if (PL_oldoldbufptr != PL_last_uni)
620 while (isSPACE(*PL_last_uni))
622 for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ;
623 if ((t = strchr(s, '(')) && t < PL_bufptr)
625 if (ckWARN_d(WARN_AMBIGUOUS)){
628 Perl_warner(aTHX_ WARN_AMBIGUOUS,
629 "Warning: Use of \"%s\" without parens is ambiguous",
635 /* workaround to replace the UNI() macro with a function. Only the
636 * hints/uts.sh file mentions this. Other comments elsewhere in the
637 * source indicate Microport Unix might need it too.
643 #define UNI(f) return uni(f,s)
646 S_uni(pTHX_ I32 f, char *s)
651 PL_last_uni = PL_oldbufptr;
662 #endif /* CRIPPLED_CC */
665 * LOP : macro to build a list operator. Its behaviour has been replaced
666 * with a subroutine, S_lop() for which LOP is just another name.
669 #define LOP(f,x) return lop(f,x,s)
673 * Build a list operator (or something that might be one). The rules:
674 * - if we have a next token, then it's a list operator [why?]
675 * - if the next thing is an opening paren, then it's a function
676 * - else it's a list operator
680 S_lop(pTHX_ I32 f, int x, char *s)
686 PL_last_lop = PL_oldbufptr;
701 * When the lexer realizes it knows the next token (for instance,
702 * it is reordering tokens for the parser) then it can call S_force_next
703 * to know what token to return the next time the lexer is called. Caller
704 * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer
705 * handles the token correctly.
709 S_force_next(pTHX_ I32 type)
711 PL_nexttype[PL_nexttoke] = type;
713 if (PL_lex_state != LEX_KNOWNEXT) {
714 PL_lex_defer = PL_lex_state;
715 PL_lex_expect = PL_expect;
716 PL_lex_state = LEX_KNOWNEXT;
722 * When the lexer knows the next thing is a word (for instance, it has
723 * just seen -> and it knows that the next char is a word char, then
724 * it calls S_force_word to stick the next word into the PL_next lookahead.
727 * char *start : buffer position (must be within PL_linestr)
728 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
729 * int check_keyword : if true, Perl checks to make sure the word isn't
730 * a keyword (do this if the word is a label, e.g. goto FOO)
731 * int allow_pack : if true, : characters will also be allowed (require,
733 * int allow_initial_tick : used by the "sub" lexer only.
737 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
742 start = skipspace(start);
744 if (isIDFIRST_lazy_if(s,UTF) ||
745 (allow_pack && *s == ':') ||
746 (allow_initial_tick && *s == '\'') )
748 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
749 if (check_keyword && keyword(PL_tokenbuf, len))
751 if (token == METHOD) {
756 PL_expect = XOPERATOR;
759 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST,0, newSVpv(PL_tokenbuf,0));
760 PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE;
768 * Called when the lexer wants $foo *foo &foo etc, but the program
769 * text only contains the "foo" portion. The first argument is a pointer
770 * to the "foo", and the second argument is the type symbol to prefix.
771 * Forces the next token to be a "WORD".
772 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
776 S_force_ident(pTHX_ register char *s, int kind)
779 OP* o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
780 PL_nextval[PL_nexttoke].opval = o;
783 o->op_private = OPpCONST_ENTERED;
784 /* XXX see note in pp_entereval() for why we forgo typo
785 warnings if the symbol must be introduced in an eval.
787 gv_fetchpv(s, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
788 kind == '$' ? SVt_PV :
789 kind == '@' ? SVt_PVAV :
790 kind == '%' ? SVt_PVHV :
798 Perl_str_to_version(pTHX_ SV *sv)
803 char *start = SvPVx(sv,len);
804 bool utf = SvUTF8(sv) ? TRUE : FALSE;
805 char *end = start + len;
806 while (start < end) {
810 n = utf8_to_uv((U8*)start, len, &skip, 0);
815 retval += ((NV)n)/nshift;
824 * Forces the next token to be a version number.
828 S_force_version(pTHX_ char *s)
830 OP *version = Nullop;
839 for (; isDIGIT(*d) || *d == '_' || *d == '.'; d++);
840 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
842 s = scan_num(s, &yylval);
843 version = yylval.opval;
844 ver = cSVOPx(version)->op_sv;
845 if (SvPOK(ver) && !SvNIOK(ver)) {
846 (void)SvUPGRADE(ver, SVt_PVNV);
847 SvNVX(ver) = str_to_version(ver);
848 SvNOK_on(ver); /* hint that it is a version */
853 /* NOTE: The parser sees the package name and the VERSION swapped */
854 PL_nextval[PL_nexttoke].opval = version;
862 * Tokenize a quoted string passed in as an SV. It finds the next
863 * chunk, up to end of string or a backslash. It may make a new
864 * SV containing that chunk (if HINT_NEW_STRING is on). It also
869 S_tokeq(pTHX_ SV *sv)
880 s = SvPV_force(sv, len);
881 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
884 while (s < send && *s != '\\')
889 if ( PL_hints & HINT_NEW_STRING )
890 pv = sv_2mortal(newSVpvn(SvPVX(pv), len));
893 if (s + 1 < send && (s[1] == '\\'))
894 s++; /* all that, just for this */
899 SvCUR_set(sv, d - SvPVX(sv));
901 if ( PL_hints & HINT_NEW_STRING )
902 return new_constant(NULL, 0, "q", sv, pv, "q");
907 * Now come three functions related to double-quote context,
908 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
909 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
910 * interact with PL_lex_state, and create fake ( ... ) argument lists
911 * to handle functions and concatenation.
912 * They assume that whoever calls them will be setting up a fake
913 * join call, because each subthing puts a ',' after it. This lets
916 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
918 * (I'm not sure whether the spurious commas at the end of lcfirst's
919 * arguments and join's arguments are created or not).
924 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
926 * Pattern matching will set PL_lex_op to the pattern-matching op to
927 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
929 * OP_CONST and OP_READLINE are easy--just make the new op and return.
931 * Everything else becomes a FUNC.
933 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
934 * had an OP_CONST or OP_READLINE). This just sets us up for a
935 * call to S_sublex_push().
941 register I32 op_type = yylval.ival;
943 if (op_type == OP_NULL) {
944 yylval.opval = PL_lex_op;
948 if (op_type == OP_CONST || op_type == OP_READLINE) {
949 SV *sv = tokeq(PL_lex_stuff);
951 if (SvTYPE(sv) == SVt_PVIV) {
952 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
958 nsv = newSVpvn(p, len);
964 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
965 PL_lex_stuff = Nullsv;
969 PL_sublex_info.super_state = PL_lex_state;
970 PL_sublex_info.sub_inwhat = op_type;
971 PL_sublex_info.sub_op = PL_lex_op;
972 PL_lex_state = LEX_INTERPPUSH;
976 yylval.opval = PL_lex_op;
986 * Create a new scope to save the lexing state. The scope will be
987 * ended in S_sublex_done. Returns a '(', starting the function arguments
988 * to the uc, lc, etc. found before.
989 * Sets PL_lex_state to LEX_INTERPCONCAT.
997 PL_lex_state = PL_sublex_info.super_state;
998 SAVEI32(PL_lex_dojoin);
999 SAVEI32(PL_lex_brackets);
1000 SAVEI32(PL_lex_casemods);
1001 SAVEI32(PL_lex_starts);
1002 SAVEI32(PL_lex_state);
1003 SAVEVPTR(PL_lex_inpat);
1004 SAVEI32(PL_lex_inwhat);
1005 SAVECOPLINE(PL_curcop);
1006 SAVEPPTR(PL_bufptr);
1007 SAVEPPTR(PL_oldbufptr);
1008 SAVEPPTR(PL_oldoldbufptr);
1009 SAVEPPTR(PL_last_lop);
1010 SAVEPPTR(PL_last_uni);
1011 SAVEPPTR(PL_linestart);
1012 SAVESPTR(PL_linestr);
1013 SAVEPPTR(PL_lex_brackstack);
1014 SAVEPPTR(PL_lex_casestack);
1016 PL_linestr = PL_lex_stuff;
1017 PL_lex_stuff = Nullsv;
1019 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1020 = SvPVX(PL_linestr);
1021 PL_bufend += SvCUR(PL_linestr);
1022 PL_last_lop = PL_last_uni = Nullch;
1023 SAVEFREESV(PL_linestr);
1025 PL_lex_dojoin = FALSE;
1026 PL_lex_brackets = 0;
1027 New(899, PL_lex_brackstack, 120, char);
1028 New(899, PL_lex_casestack, 12, char);
1029 SAVEFREEPV(PL_lex_brackstack);
1030 SAVEFREEPV(PL_lex_casestack);
1031 PL_lex_casemods = 0;
1032 *PL_lex_casestack = '\0';
1034 PL_lex_state = LEX_INTERPCONCAT;
1035 CopLINE_set(PL_curcop, PL_multi_start);
1037 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1038 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1039 PL_lex_inpat = PL_sublex_info.sub_op;
1041 PL_lex_inpat = Nullop;
1048 * Restores lexer state after a S_sublex_push.
1054 if (!PL_lex_starts++) {
1055 SV *sv = newSVpvn("",0);
1056 if (SvUTF8(PL_linestr))
1058 PL_expect = XOPERATOR;
1059 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1063 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1064 PL_lex_state = LEX_INTERPCASEMOD;
1068 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1069 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1070 PL_linestr = PL_lex_repl;
1072 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1073 PL_bufend += SvCUR(PL_linestr);
1074 PL_last_lop = PL_last_uni = Nullch;
1075 SAVEFREESV(PL_linestr);
1076 PL_lex_dojoin = FALSE;
1077 PL_lex_brackets = 0;
1078 PL_lex_casemods = 0;
1079 *PL_lex_casestack = '\0';
1081 if (SvEVALED(PL_lex_repl)) {
1082 PL_lex_state = LEX_INTERPNORMAL;
1084 /* we don't clear PL_lex_repl here, so that we can check later
1085 whether this is an evalled subst; that means we rely on the
1086 logic to ensure sublex_done() is called again only via the
1087 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1090 PL_lex_state = LEX_INTERPCONCAT;
1091 PL_lex_repl = Nullsv;
1097 PL_bufend = SvPVX(PL_linestr);
1098 PL_bufend += SvCUR(PL_linestr);
1099 PL_expect = XOPERATOR;
1100 PL_sublex_info.sub_inwhat = 0;
1108 Extracts a pattern, double-quoted string, or transliteration. This
1111 It looks at lex_inwhat and PL_lex_inpat to find out whether it's
1112 processing a pattern (PL_lex_inpat is true), a transliteration
1113 (lex_inwhat & OP_TRANS is true), or a double-quoted string.
1115 Returns a pointer to the character scanned up to. Iff this is
1116 advanced from the start pointer supplied (ie if anything was
1117 successfully parsed), will leave an OP for the substring scanned
1118 in yylval. Caller must intuit reason for not parsing further
1119 by looking at the next characters herself.
1123 double-quoted style: \r and \n
1124 regexp special ones: \D \s
1126 backrefs: \1 (deprecated in substitution replacements)
1127 case and quoting: \U \Q \E
1128 stops on @ and $, but not for $ as tail anchor
1130 In transliterations:
1131 characters are VERY literal, except for - not at the start or end
1132 of the string, which indicates a range. scan_const expands the
1133 range to the full set of intermediate characters.
1135 In double-quoted strings:
1137 double-quoted style: \r and \n
1139 backrefs: \1 (deprecated)
1140 case and quoting: \U \Q \E
1143 scan_const does *not* construct ops to handle interpolated strings.
1144 It stops processing as soon as it finds an embedded $ or @ variable
1145 and leaves it to the caller to work out what's going on.
1147 @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @:foo.
1149 $ in pattern could be $foo or could be tail anchor. Assumption:
1150 it's a tail anchor if $ is the last thing in the string, or if it's
1151 followed by one of ")| \n\t"
1153 \1 (backreferences) are turned into $1
1155 The structure of the code is
1156 while (there's a character to process) {
1157 handle transliteration ranges
1158 skip regexp comments
1159 skip # initiated comments in //x patterns
1160 check for embedded @foo
1161 check for embedded scalars
1163 leave intact backslashes from leave (below)
1164 deprecate \1 in strings and sub replacements
1165 handle string-changing backslashes \l \U \Q \E, etc.
1166 switch (what was escaped) {
1167 handle - in a transliteration (becomes a literal -)
1168 handle \132 octal characters
1169 handle 0x15 hex characters
1170 handle \cV (control V)
1171 handle printf backslashes (\f, \r, \n, etc)
1173 } (end if backslash)
1174 } (end while character to read)
1179 S_scan_const(pTHX_ char *start)
1181 register char *send = PL_bufend; /* end of the constant */
1182 SV *sv = NEWSV(93, send - start); /* sv for the constant */
1183 register char *s = start; /* start of the constant */
1184 register char *d = SvPVX(sv); /* destination for copies */
1185 bool dorange = FALSE; /* are we in a translit range? */
1186 bool has_utf8 = FALSE; /* embedded \x{} */
1189 I32 utf = (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op)
1190 ? (PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF))
1192 I32 this_utf8 = (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op)
1193 ? (PL_sublex_info.sub_op->op_private & (PL_lex_repl ?
1194 OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF))
1196 const char *leaveit = /* set of acceptably-backslashed characters */
1198 ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxcz0123456789[{]} \t\n\r\f\v#"
1201 while (s < send || dorange) {
1202 /* get transliterations out of the way (they're most literal) */
1203 if (PL_lex_inwhat == OP_TRANS) {
1204 /* expand a range A-Z to the full set of characters. AIE! */
1206 I32 i; /* current expanded character */
1207 I32 min; /* first character in range */
1208 I32 max; /* last character in range */
1210 i = d - SvPVX(sv); /* remember current offset */
1211 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1212 d = SvPVX(sv) + i; /* refresh d after realloc */
1213 d -= 2; /* eat the first char and the - */
1215 min = (U8)*d; /* first char in range */
1216 max = (U8)d[1]; /* last char in range */
1219 if ((isLOWER(min) && isLOWER(max)) ||
1220 (isUPPER(min) && isUPPER(max))) {
1222 for (i = min; i <= max; i++)
1226 for (i = min; i <= max; i++)
1233 for (i = min; i <= max; i++)
1236 /* mark the range as done, and continue */
1241 /* range begins (ignore - as first or last char) */
1242 else if (*s == '-' && s+1 < send && s != start) {
1244 *d++ = (char)0xff; /* use illegal utf8 byte--see pmtrans */
1253 /* if we get here, we're not doing a transliteration */
1255 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1256 except for the last char, which will be done separately. */
1257 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1259 while (s < send && *s != ')')
1262 else if (s[2] == '{' /* This should match regcomp.c */
1263 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1266 char *regparse = s + (s[2] == '{' ? 3 : 4);
1269 while (count && (c = *regparse)) {
1270 if (c == '\\' && regparse[1])
1278 if (*regparse != ')') {
1279 regparse--; /* Leave one char for continuation. */
1280 yyerror("Sequence (?{...}) not terminated or not {}-balanced");
1282 while (s < regparse)
1287 /* likewise skip #-initiated comments in //x patterns */
1288 else if (*s == '#' && PL_lex_inpat &&
1289 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1290 while (s+1 < send && *s != '\n')
1294 /* check for embedded arrays (@foo, @:foo, @'foo, @{foo}, @$foo) */
1295 else if (*s == '@' && s[1]
1296 && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$", s[1])))
1299 /* check for embedded scalars. only stop if we're sure it's a
1302 else if (*s == '$') {
1303 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
1305 if (s + 1 < send && !strchr("()| \n\t", s[1]))
1306 break; /* in regexp, $ might be tail anchor */
1310 if (*s == '\\' && s+1 < send) {
1311 bool to_be_utf8 = FALSE;
1315 /* some backslashes we leave behind */
1316 if (*leaveit && *s && strchr(leaveit, *s)) {
1322 /* deprecate \1 in strings and substitution replacements */
1323 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
1324 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
1326 if (ckWARN(WARN_SYNTAX))
1327 Perl_warner(aTHX_ WARN_SYNTAX, "\\%c better written as $%c", *s, *s);
1332 /* string-change backslash escapes */
1333 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
1338 /* if we get here, it's either a quoted -, or a digit */
1341 /* quoted - in transliterations */
1343 if (PL_lex_inwhat == OP_TRANS) {
1350 if (ckWARN(WARN_MISC) && isALPHA(*s))
1351 Perl_warner(aTHX_ WARN_MISC,
1352 "Unrecognized escape \\%c passed through",
1354 /* default action is to copy the quoted character */
1355 goto default_action;
1358 /* \132 indicates an octal constant */
1359 case '0': case '1': case '2': case '3':
1360 case '4': case '5': case '6': case '7':
1362 STRLEN len = 0; /* disallow underscores */
1363 uv = (UV)scan_oct(s, 3, &len);
1366 goto NUM_ESCAPE_INSERT;
1368 /* \x24 indicates a hex constant */
1372 char* e = strchr(s, '}');
1374 yyerror("Missing right brace on \\x{}");
1378 STRLEN len = 1; /* allow underscores */
1379 uv = (UV)scan_hex(s + 1, e - s - 1, &len);
1386 STRLEN len = 0; /* disallow underscores */
1387 uv = (UV)scan_hex(s, 2, &len);
1393 /* Insert oct or hex escaped character.
1394 * There will always enough room in sv since such
1395 * escapes will be longer than any UT-F8 sequence
1396 * they can end up as. */
1398 /* This spot is wrong for EBCDIC. Characters like
1399 * the lowercase letters and digits are >127 in EBCDIC,
1400 * so here they would need to be mapped to the Unicode
1401 * repertoire. --jhi */
1404 if (!has_utf8 && (to_be_utf8 || uv > 255)) {
1405 /* Might need to recode whatever we have
1406 * accumulated so far if it contains any
1409 * (Can't we keep track of that and avoid
1410 * this rescan? --jhi)
1415 for (c = SvPVX(sv); c < d; c++) {
1416 if (UTF8_IS_CONTINUED(*c))
1420 char *old_pvx = SvPVX(sv);
1424 SvCUR(sv) + hicount + 1) +
1432 if (UTF8_IS_CONTINUED(*src)) {
1433 *dst-- = UTF8_EIGHT_BIT_LO(*src);
1434 *dst-- = UTF8_EIGHT_BIT_HI(*src--);
1443 if (to_be_utf8 || has_utf8 || uv > 255) {
1444 d = (char*)uv_to_utf8((U8*)d, uv);
1446 if (PL_lex_inwhat == OP_TRANS &&
1447 PL_sublex_info.sub_op) {
1448 PL_sublex_info.sub_op->op_private |=
1449 (PL_lex_repl ? OPpTRANS_FROM_UTF
1463 /* \N{latin small letter a} is a named character */
1467 char* e = strchr(s, '}');
1473 yyerror("Missing right brace on \\N{}");
1477 res = newSVpvn(s + 1, e - s - 1);
1478 res = new_constant( Nullch, 0, "charnames",
1479 res, Nullsv, "\\N{...}" );
1481 sv_utf8_upgrade(res);
1482 str = SvPV(res,len);
1483 if (!has_utf8 && SvUTF8(res)) {
1484 char *ostart = SvPVX(sv);
1485 SvCUR_set(sv, d - ostart);
1488 sv_utf8_upgrade(sv);
1489 /* this just broke our allocation above... */
1490 SvGROW(sv, send - start);
1491 d = SvPVX(sv) + SvCUR(sv);
1494 if (len > e - s + 4) {
1495 char *odest = SvPVX(sv);
1497 SvGROW(sv, (SvCUR(sv) + len - (e - s + 4)));
1498 d = SvPVX(sv) + (d - odest);
1500 Copy(str, d, len, char);
1507 yyerror("Missing braces on \\N{}");
1510 /* \c is a control character */
1527 /* printf-style backslashes, formfeeds, newlines, etc */
1545 *d++ = '\047'; /* CP 1047 */
1548 *d++ = '\057'; /* CP 1047 */
1562 } /* end if (backslash) */
1565 if (UTF8_IS_CONTINUED(*s) && (this_utf8 || has_utf8)) {
1566 STRLEN len = (STRLEN) -1;
1569 uv = utf8_to_uv((U8*)s, send - s, &len, 0);
1571 if (len == (STRLEN)-1) {
1572 /* Illegal UTF8 (a high-bit byte), make it valid. */
1573 char *old_pvx = SvPVX(sv);
1574 /* need space for one extra char (NOTE: SvCUR() not set here) */
1575 d = SvGROW(sv, SvLEN(sv) + 1) + (d - old_pvx);
1576 d = (char*)uv_to_utf8((U8*)d, (U8)*s++);
1583 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1584 PL_sublex_info.sub_op->op_private |=
1585 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1592 } /* while loop to process each character */
1594 /* terminate the string and set up the sv */
1596 SvCUR_set(sv, d - SvPVX(sv));
1601 /* shrink the sv if we allocated more than we used */
1602 if (SvCUR(sv) + 5 < SvLEN(sv)) {
1603 SvLEN_set(sv, SvCUR(sv) + 1);
1604 Renew(SvPVX(sv), SvLEN(sv), char);
1607 /* return the substring (via yylval) only if we parsed anything */
1608 if (s > PL_bufptr) {
1609 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
1610 sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"),
1612 ( PL_lex_inwhat == OP_TRANS
1614 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
1617 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1624 * Returns TRUE if there's more to the expression (e.g., a subscript),
1627 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
1629 * ->[ and ->{ return TRUE
1630 * { and [ outside a pattern are always subscripts, so return TRUE
1631 * if we're outside a pattern and it's not { or [, then return FALSE
1632 * if we're in a pattern and the first char is a {
1633 * {4,5} (any digits around the comma) returns FALSE
1634 * if we're in a pattern and the first char is a [
1636 * [SOMETHING] has a funky algorithm to decide whether it's a
1637 * character class or not. It has to deal with things like
1638 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
1639 * anything else returns TRUE
1642 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
1645 S_intuit_more(pTHX_ register char *s)
1647 if (PL_lex_brackets)
1649 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
1651 if (*s != '{' && *s != '[')
1656 /* In a pattern, so maybe we have {n,m}. */
1673 /* On the other hand, maybe we have a character class */
1676 if (*s == ']' || *s == '^')
1679 /* this is terrifying, and it works */
1680 int weight = 2; /* let's weigh the evidence */
1682 unsigned char un_char = 255, last_un_char;
1683 char *send = strchr(s,']');
1684 char tmpbuf[sizeof PL_tokenbuf * 4];
1686 if (!send) /* has to be an expression */
1689 Zero(seen,256,char);
1692 else if (isDIGIT(*s)) {
1694 if (isDIGIT(s[1]) && s[2] == ']')
1700 for (; s < send; s++) {
1701 last_un_char = un_char;
1702 un_char = (unsigned char)*s;
1707 weight -= seen[un_char] * 10;
1708 if (isALNUM_lazy_if(s+1,UTF)) {
1709 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
1710 if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV))
1715 else if (*s == '$' && s[1] &&
1716 strchr("[#!%*<>()-=",s[1])) {
1717 if (/*{*/ strchr("])} =",s[2]))
1726 if (strchr("wds]",s[1]))
1728 else if (seen['\''] || seen['"'])
1730 else if (strchr("rnftbxcav",s[1]))
1732 else if (isDIGIT(s[1])) {
1734 while (s[1] && isDIGIT(s[1]))
1744 if (strchr("aA01! ",last_un_char))
1746 if (strchr("zZ79~",s[1]))
1748 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
1749 weight -= 5; /* cope with negative subscript */
1752 if (!isALNUM(last_un_char) && !strchr("$@&",last_un_char) &&
1753 isALPHA(*s) && s[1] && isALPHA(s[1])) {
1758 if (keyword(tmpbuf, d - tmpbuf))
1761 if (un_char == last_un_char + 1)
1763 weight -= seen[un_char];
1768 if (weight >= 0) /* probably a character class */
1778 * Does all the checking to disambiguate
1780 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
1781 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
1783 * First argument is the stuff after the first token, e.g. "bar".
1785 * Not a method if bar is a filehandle.
1786 * Not a method if foo is a subroutine prototyped to take a filehandle.
1787 * Not a method if it's really "Foo $bar"
1788 * Method if it's "foo $bar"
1789 * Not a method if it's really "print foo $bar"
1790 * Method if it's really "foo package::" (interpreted as package->foo)
1791 * Not a method if bar is known to be a subroutne ("sub bar; foo bar")
1792 * Not a method if bar is a filehandle or package, but is quoted with
1797 S_intuit_method(pTHX_ char *start, GV *gv)
1799 char *s = start + (*start == '$');
1800 char tmpbuf[sizeof PL_tokenbuf];
1808 if ((cv = GvCVu(gv))) {
1809 char *proto = SvPVX(cv);
1819 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
1820 /* start is the beginning of the possible filehandle/object,
1821 * and s is the end of it
1822 * tmpbuf is a copy of it
1825 if (*start == '$') {
1826 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
1831 return *s == '(' ? FUNCMETH : METHOD;
1833 if (!keyword(tmpbuf, len)) {
1834 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
1839 indirgv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
1840 if (indirgv && GvCVu(indirgv))
1842 /* filehandle or package name makes it a method */
1843 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
1845 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
1846 return 0; /* no assumptions -- "=>" quotes bearword */
1848 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0,
1849 newSVpvn(tmpbuf,len));
1850 PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE;
1854 return *s == '(' ? FUNCMETH : METHOD;
1862 * Return a string of Perl code to load the debugger. If PERL5DB
1863 * is set, it will return the contents of that, otherwise a
1864 * compile-time require of perl5db.pl.
1871 char *pdb = PerlEnv_getenv("PERL5DB");
1875 SETERRNO(0,SS$_NORMAL);
1876 return "BEGIN { require 'perl5db.pl' }";
1882 /* Encoded script support. filter_add() effectively inserts a
1883 * 'pre-processing' function into the current source input stream.
1884 * Note that the filter function only applies to the current source file
1885 * (e.g., it will not affect files 'require'd or 'use'd by this one).
1887 * The datasv parameter (which may be NULL) can be used to pass
1888 * private data to this instance of the filter. The filter function
1889 * can recover the SV using the FILTER_DATA macro and use it to
1890 * store private buffers and state information.
1892 * The supplied datasv parameter is upgraded to a PVIO type
1893 * and the IoDIRP/IoANY field is used to store the function pointer,
1894 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
1895 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
1896 * private use must be set using malloc'd pointers.
1900 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
1905 if (!PL_rsfp_filters)
1906 PL_rsfp_filters = newAV();
1908 datasv = NEWSV(255,0);
1909 if (!SvUPGRADE(datasv, SVt_PVIO))
1910 Perl_die(aTHX_ "Can't upgrade filter_add data to SVt_PVIO");
1911 IoANY(datasv) = (void *)funcp; /* stash funcp into spare field */
1912 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
1913 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
1914 funcp, SvPV_nolen(datasv)));
1915 av_unshift(PL_rsfp_filters, 1);
1916 av_store(PL_rsfp_filters, 0, datasv) ;
1921 /* Delete most recently added instance of this filter function. */
1923 Perl_filter_del(pTHX_ filter_t funcp)
1926 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", funcp));
1927 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
1929 /* if filter is on top of stack (usual case) just pop it off */
1930 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
1931 if (IoANY(datasv) == (void *)funcp) {
1932 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
1933 IoANY(datasv) = (void *)NULL;
1934 sv_free(av_pop(PL_rsfp_filters));
1938 /* we need to search for the correct entry and clear it */
1939 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
1943 /* Invoke the n'th filter function for the current rsfp. */
1945 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
1948 /* 0 = read one text line */
1953 if (!PL_rsfp_filters)
1955 if (idx > AvFILLp(PL_rsfp_filters)){ /* Any more filters? */
1956 /* Provide a default input filter to make life easy. */
1957 /* Note that we append to the line. This is handy. */
1958 DEBUG_P(PerlIO_printf(Perl_debug_log,
1959 "filter_read %d: from rsfp\n", idx));
1963 int old_len = SvCUR(buf_sv) ;
1965 /* ensure buf_sv is large enough */
1966 SvGROW(buf_sv, old_len + maxlen) ;
1967 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
1968 if (PerlIO_error(PL_rsfp))
1969 return -1; /* error */
1971 return 0 ; /* end of file */
1973 SvCUR_set(buf_sv, old_len + len) ;
1976 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
1977 if (PerlIO_error(PL_rsfp))
1978 return -1; /* error */
1980 return 0 ; /* end of file */
1983 return SvCUR(buf_sv);
1985 /* Skip this filter slot if filter has been deleted */
1986 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef){
1987 DEBUG_P(PerlIO_printf(Perl_debug_log,
1988 "filter_read %d: skipped (filter deleted)\n",
1990 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
1992 /* Get function pointer hidden within datasv */
1993 funcp = (filter_t)IoANY(datasv);
1994 DEBUG_P(PerlIO_printf(Perl_debug_log,
1995 "filter_read %d: via function %p (%s)\n",
1996 idx, funcp, SvPV_nolen(datasv)));
1997 /* Call function. The function is expected to */
1998 /* call "FILTER_READ(idx+1, buf_sv)" first. */
1999 /* Return: <0:error, =0:eof, >0:not eof */
2000 return (*funcp)(aTHXo_ idx, buf_sv, maxlen);
2004 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2006 #ifdef PERL_CR_FILTER
2007 if (!PL_rsfp_filters) {
2008 filter_add(S_cr_textfilter,NULL);
2011 if (PL_rsfp_filters) {
2014 SvCUR_set(sv, 0); /* start with empty line */
2015 if (FILTER_READ(0, sv, 0) > 0)
2016 return ( SvPVX(sv) ) ;
2021 return (sv_gets(sv, fp, append));
2025 S_find_in_my_stash(pTHX_ char *pkgname, I32 len)
2029 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2033 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2034 (gv = gv_fetchpv(pkgname, FALSE, SVt_PVHV)))
2036 return GvHV(gv); /* Foo:: */
2039 /* use constant CLASS => 'MyClass' */
2040 if ((gv = gv_fetchpv(pkgname, FALSE, SVt_PVCV))) {
2042 if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) {
2043 pkgname = SvPV_nolen(sv);
2047 return gv_stashpv(pkgname, FALSE);
2051 static char* exp_name[] =
2052 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
2053 "ATTRTERM", "TERMBLOCK"
2060 Works out what to call the token just pulled out of the input
2061 stream. The yacc parser takes care of taking the ops we return and
2062 stitching them into a tree.
2068 if read an identifier
2069 if we're in a my declaration
2070 croak if they tried to say my($foo::bar)
2071 build the ops for a my() declaration
2072 if it's an access to a my() variable
2073 are we in a sort block?
2074 croak if my($a); $a <=> $b
2075 build ops for access to a my() variable
2076 if in a dq string, and they've said @foo and we can't find @foo
2078 build ops for a bareword
2079 if we already built the token before, use it.
2082 #ifdef USE_PURE_BISON
2084 Perl_yylex_r(pTHX_ YYSTYPE *lvalp, int *lcharp)
2089 yylval_pointer[yyactlevel] = lvalp;
2090 yychar_pointer[yyactlevel] = lcharp;
2091 if (yyactlevel >= YYMAXLEVEL)
2092 Perl_croak(aTHX_ "panic: YYMAXLEVEL");
2094 r = Perl_yylex(aTHX);
2103 #pragma segment Perl_yylex
2116 /* check if there's an identifier for us to look at */
2117 if (PL_pending_ident) {
2118 /* pit holds the identifier we read and pending_ident is reset */
2119 char pit = PL_pending_ident;
2120 PL_pending_ident = 0;
2122 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2123 "### Tokener saw identifier '%s'\n", PL_tokenbuf); })
2125 /* if we're in a my(), we can't allow dynamics here.
2126 $foo'bar has already been turned into $foo::bar, so
2127 just check for colons.
2129 if it's a legal name, the OP is a PADANY.
2132 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
2133 if (strchr(PL_tokenbuf,':'))
2134 yyerror(Perl_form(aTHX_ "No package name allowed for "
2135 "variable %s in \"our\"",
2137 tmp = pad_allocmy(PL_tokenbuf);
2140 if (strchr(PL_tokenbuf,':'))
2141 yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf));
2143 yylval.opval = newOP(OP_PADANY, 0);
2144 yylval.opval->op_targ = pad_allocmy(PL_tokenbuf);
2150 build the ops for accesses to a my() variable.
2152 Deny my($a) or my($b) in a sort block, *if* $a or $b is
2153 then used in a comparison. This catches most, but not
2154 all cases. For instance, it catches
2155 sort { my($a); $a <=> $b }
2157 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
2158 (although why you'd do that is anyone's guess).
2161 if (!strchr(PL_tokenbuf,':')) {
2163 /* Check for single character per-thread SVs */
2164 if (PL_tokenbuf[0] == '$' && PL_tokenbuf[2] == '\0'
2165 && !isALPHA(PL_tokenbuf[1]) /* Rule out obvious non-threadsvs */
2166 && (tmp = find_threadsv(&PL_tokenbuf[1])) != NOT_IN_PAD)
2168 yylval.opval = newOP(OP_THREADSV, 0);
2169 yylval.opval->op_targ = tmp;
2172 #endif /* USE_THREADS */
2173 if ((tmp = pad_findmy(PL_tokenbuf)) != NOT_IN_PAD) {
2174 SV *namesv = AvARRAY(PL_comppad_name)[tmp];
2175 /* might be an "our" variable" */
2176 if (SvFLAGS(namesv) & SVpad_OUR) {
2177 /* build ops for a bareword */
2178 SV *sym = newSVpv(HvNAME(GvSTASH(namesv)),0);
2179 sv_catpvn(sym, "::", 2);
2180 sv_catpv(sym, PL_tokenbuf+1);
2181 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
2182 yylval.opval->op_private = OPpCONST_ENTERED;
2183 gv_fetchpv(SvPVX(sym),
2185 ? (GV_ADDMULTI | GV_ADDINEVAL)
2188 ((PL_tokenbuf[0] == '$') ? SVt_PV
2189 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
2194 /* if it's a sort block and they're naming $a or $b */
2195 if (PL_last_lop_op == OP_SORT &&
2196 PL_tokenbuf[0] == '$' &&
2197 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
2200 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
2201 d < PL_bufend && *d != '\n';
2204 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
2205 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
2211 yylval.opval = newOP(OP_PADANY, 0);
2212 yylval.opval->op_targ = tmp;
2218 Whine if they've said @foo in a doublequoted string,
2219 and @foo isn't a variable we can find in the symbol
2222 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
2223 GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV);
2224 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
2225 && ckWARN(WARN_AMBIGUOUS))
2227 /* Downgraded from fatal to warning 20000522 mjd */
2228 Perl_warner(aTHX_ WARN_AMBIGUOUS,
2229 "Possible unintended interpolation of %s in string",
2234 /* build ops for a bareword */
2235 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
2236 yylval.opval->op_private = OPpCONST_ENTERED;
2237 gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
2238 ((PL_tokenbuf[0] == '$') ? SVt_PV
2239 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
2244 /* no identifier pending identification */
2246 switch (PL_lex_state) {
2248 case LEX_NORMAL: /* Some compilers will produce faster */
2249 case LEX_INTERPNORMAL: /* code if we comment these out. */
2253 /* when we've already built the next token, just pull it out of the queue */
2256 yylval = PL_nextval[PL_nexttoke];
2258 PL_lex_state = PL_lex_defer;
2259 PL_expect = PL_lex_expect;
2260 PL_lex_defer = LEX_NORMAL;
2262 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2263 "### Next token after '%s' was known, type %"IVdf"\n", PL_bufptr,
2264 (IV)PL_nexttype[PL_nexttoke]); })
2266 return(PL_nexttype[PL_nexttoke]);
2268 /* interpolated case modifiers like \L \U, including \Q and \E.
2269 when we get here, PL_bufptr is at the \
2271 case LEX_INTERPCASEMOD:
2273 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
2274 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
2276 /* handle \E or end of string */
2277 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
2281 if (PL_lex_casemods) {
2282 oldmod = PL_lex_casestack[--PL_lex_casemods];
2283 PL_lex_casestack[PL_lex_casemods] = '\0';
2285 if (PL_bufptr != PL_bufend && strchr("LUQ", oldmod)) {
2287 PL_lex_state = LEX_INTERPCONCAT;
2291 if (PL_bufptr != PL_bufend)
2293 PL_lex_state = LEX_INTERPCONCAT;
2297 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2298 "### Saw case modifier at '%s'\n", PL_bufptr); })
2300 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
2301 tmp = *s, *s = s[2], s[2] = tmp; /* misordered... */
2302 if (strchr("LU", *s) &&
2303 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U')))
2305 PL_lex_casestack[--PL_lex_casemods] = '\0';
2308 if (PL_lex_casemods > 10) {
2309 char* newlb = Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
2310 if (newlb != PL_lex_casestack) {
2312 PL_lex_casestack = newlb;
2315 PL_lex_casestack[PL_lex_casemods++] = *s;
2316 PL_lex_casestack[PL_lex_casemods] = '\0';
2317 PL_lex_state = LEX_INTERPCONCAT;
2318 PL_nextval[PL_nexttoke].ival = 0;
2321 PL_nextval[PL_nexttoke].ival = OP_LCFIRST;
2323 PL_nextval[PL_nexttoke].ival = OP_UCFIRST;
2325 PL_nextval[PL_nexttoke].ival = OP_LC;
2327 PL_nextval[PL_nexttoke].ival = OP_UC;
2329 PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA;
2331 Perl_croak(aTHX_ "panic: yylex");
2334 if (PL_lex_starts) {
2343 case LEX_INTERPPUSH:
2344 return sublex_push();
2346 case LEX_INTERPSTART:
2347 if (PL_bufptr == PL_bufend)
2348 return sublex_done();
2349 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2350 "### Interpolated variable at '%s'\n", PL_bufptr); })
2352 PL_lex_dojoin = (*PL_bufptr == '@');
2353 PL_lex_state = LEX_INTERPNORMAL;
2354 if (PL_lex_dojoin) {
2355 PL_nextval[PL_nexttoke].ival = 0;
2358 PL_nextval[PL_nexttoke].opval = newOP(OP_THREADSV, 0);
2359 PL_nextval[PL_nexttoke].opval->op_targ = find_threadsv("\"");
2360 force_next(PRIVATEREF);
2362 force_ident("\"", '$');
2363 #endif /* USE_THREADS */
2364 PL_nextval[PL_nexttoke].ival = 0;
2366 PL_nextval[PL_nexttoke].ival = 0;
2368 PL_nextval[PL_nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
2371 if (PL_lex_starts++) {
2377 case LEX_INTERPENDMAYBE:
2378 if (intuit_more(PL_bufptr)) {
2379 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
2385 if (PL_lex_dojoin) {
2386 PL_lex_dojoin = FALSE;
2387 PL_lex_state = LEX_INTERPCONCAT;
2390 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
2391 && SvEVALED(PL_lex_repl))
2393 if (PL_bufptr != PL_bufend)
2394 Perl_croak(aTHX_ "Bad evalled substitution pattern");
2395 PL_lex_repl = Nullsv;
2398 case LEX_INTERPCONCAT:
2400 if (PL_lex_brackets)
2401 Perl_croak(aTHX_ "panic: INTERPCONCAT");
2403 if (PL_bufptr == PL_bufend)
2404 return sublex_done();
2406 if (SvIVX(PL_linestr) == '\'') {
2407 SV *sv = newSVsv(PL_linestr);
2410 else if ( PL_hints & HINT_NEW_RE )
2411 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
2412 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2416 s = scan_const(PL_bufptr);
2418 PL_lex_state = LEX_INTERPCASEMOD;
2420 PL_lex_state = LEX_INTERPSTART;
2423 if (s != PL_bufptr) {
2424 PL_nextval[PL_nexttoke] = yylval;
2427 if (PL_lex_starts++)
2437 PL_lex_state = LEX_NORMAL;
2438 s = scan_formline(PL_bufptr);
2439 if (!PL_lex_formbrack)
2445 PL_oldoldbufptr = PL_oldbufptr;
2448 PerlIO_printf(Perl_debug_log, "### Tokener expecting %s at %s\n",
2449 exp_name[PL_expect], s);
2455 if (isIDFIRST_lazy_if(s,UTF))
2457 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
2460 goto fake_eof; /* emulate EOF on ^D or ^Z */
2465 if (PL_lex_brackets)
2466 yyerror("Missing right curly or square bracket");
2467 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2468 "### Tokener got EOF\n");
2472 if (s++ < PL_bufend)
2473 goto retry; /* ignore stray nulls */
2476 if (!PL_in_eval && !PL_preambled) {
2477 PL_preambled = TRUE;
2478 sv_setpv(PL_linestr,incl_perldb());
2479 if (SvCUR(PL_linestr))
2480 sv_catpv(PL_linestr,";");
2482 while(AvFILLp(PL_preambleav) >= 0) {
2483 SV *tmpsv = av_shift(PL_preambleav);
2484 sv_catsv(PL_linestr, tmpsv);
2485 sv_catpv(PL_linestr, ";");
2488 sv_free((SV*)PL_preambleav);
2489 PL_preambleav = NULL;
2491 if (PL_minus_n || PL_minus_p) {
2492 sv_catpv(PL_linestr, "LINE: while (<>) {");
2494 sv_catpv(PL_linestr,"chomp;");
2496 GV* gv = gv_fetchpv("::F", TRUE, SVt_PVAV);
2498 GvIMPORTED_AV_on(gv);
2500 if (strchr("/'\"", *PL_splitstr)
2501 && strchr(PL_splitstr + 1, *PL_splitstr))
2502 Perl_sv_catpvf(aTHX_ PL_linestr, "@F=split(%s);", PL_splitstr);
2505 s = "'~#\200\1'"; /* surely one char is unused...*/
2506 while (s[1] && strchr(PL_splitstr, *s)) s++;
2508 Perl_sv_catpvf(aTHX_ PL_linestr, "@F=split(%s%c",
2509 "q" + (delim == '\''), delim);
2510 for (s = PL_splitstr; *s; s++) {
2512 sv_catpvn(PL_linestr, "\\", 1);
2513 sv_catpvn(PL_linestr, s, 1);
2515 Perl_sv_catpvf(aTHX_ PL_linestr, "%c);", delim);
2519 sv_catpv(PL_linestr,"@F=split(' ');");
2522 sv_catpv(PL_linestr, "\n");
2523 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2524 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2525 PL_last_lop = PL_last_uni = Nullch;
2526 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2527 SV *sv = NEWSV(85,0);
2529 sv_upgrade(sv, SVt_PVMG);
2530 sv_setsv(sv,PL_linestr);
2531 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2536 bof = PL_rsfp ? TRUE : FALSE;
2537 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) {
2540 if (PL_preprocess && !PL_in_eval)
2541 (void)PerlProc_pclose(PL_rsfp);
2542 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
2543 PerlIO_clearerr(PL_rsfp);
2545 (void)PerlIO_close(PL_rsfp);
2547 PL_doextract = FALSE;
2549 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
2550 sv_setpv(PL_linestr,PL_minus_p ? ";}continue{print" : "");
2551 sv_catpv(PL_linestr,";}");
2552 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2553 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2554 PL_last_lop = PL_last_uni = Nullch;
2555 PL_minus_n = PL_minus_p = 0;
2558 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2559 PL_last_lop = PL_last_uni = Nullch;
2560 sv_setpv(PL_linestr,"");
2561 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
2563 /* if it looks like the start of a BOM, check if it in fact is */
2564 else if (bof && (!*s || *(U8*)s == 0xEF || *(U8*)s >= 0xFE)) {
2565 #ifdef PERLIO_IS_STDIO
2566 # ifdef __GNU_LIBRARY__
2567 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
2568 # define FTELL_FOR_PIPE_IS_BROKEN
2572 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
2573 # define FTELL_FOR_PIPE_IS_BROKEN
2578 #ifdef FTELL_FOR_PIPE_IS_BROKEN
2579 /* This loses the possibility to detect the bof
2580 * situation on perl -P when the libc5 is being used.
2581 * Workaround? Maybe attach some extra state to PL_rsfp?
2584 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
2586 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
2589 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2590 s = swallow_bom((U8*)s);
2594 if (*s == '#' && s[1] == '!' && instr(s,"perl"))
2595 PL_doextract = FALSE;
2597 /* Incest with pod. */
2598 if (*s == '=' && strnEQ(s, "=cut", 4)) {
2599 sv_setpv(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_doextract = FALSE;
2607 } while (PL_doextract);
2608 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
2609 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2610 SV *sv = NEWSV(85,0);
2612 sv_upgrade(sv, SVt_PVMG);
2613 sv_setsv(sv,PL_linestr);
2614 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2616 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2617 PL_last_lop = PL_last_uni = Nullch;
2618 if (CopLINE(PL_curcop) == 1) {
2619 while (s < PL_bufend && isSPACE(*s))
2621 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
2625 if (*s == '#' && *(s+1) == '!')
2627 #ifdef ALTERNATE_SHEBANG
2629 static char as[] = ALTERNATE_SHEBANG;
2630 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
2631 d = s + (sizeof(as) - 1);
2633 #endif /* ALTERNATE_SHEBANG */
2642 while (*d && !isSPACE(*d))
2646 #ifdef ARG_ZERO_IS_SCRIPT
2647 if (ipathend > ipath) {
2649 * HP-UX (at least) sets argv[0] to the script name,
2650 * which makes $^X incorrect. And Digital UNIX and Linux,
2651 * at least, set argv[0] to the basename of the Perl
2652 * interpreter. So, having found "#!", we'll set it right.
2654 SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV));
2655 assert(SvPOK(x) || SvGMAGICAL(x));
2656 if (sv_eq(x, CopFILESV(PL_curcop))) {
2657 sv_setpvn(x, ipath, ipathend - ipath);
2660 TAINT_NOT; /* $^X is always tainted, but that's OK */
2662 #endif /* ARG_ZERO_IS_SCRIPT */
2667 d = instr(s,"perl -");
2669 d = instr(s,"perl");
2671 /* avoid getting into infinite loops when shebang
2672 * line contains "Perl" rather than "perl" */
2674 for (d = ipathend-4; d >= ipath; --d) {
2675 if ((*d == 'p' || *d == 'P')
2676 && !ibcmp(d, "perl", 4))
2686 #ifdef ALTERNATE_SHEBANG
2688 * If the ALTERNATE_SHEBANG on this system starts with a
2689 * character that can be part of a Perl expression, then if
2690 * we see it but not "perl", we're probably looking at the
2691 * start of Perl code, not a request to hand off to some
2692 * other interpreter. Similarly, if "perl" is there, but
2693 * not in the first 'word' of the line, we assume the line
2694 * contains the start of the Perl program.
2696 if (d && *s != '#') {
2698 while (*c && !strchr("; \t\r\n\f\v#", *c))
2701 d = Nullch; /* "perl" not in first word; ignore */
2703 *s = '#'; /* Don't try to parse shebang line */
2705 #endif /* ALTERNATE_SHEBANG */
2706 #ifndef MACOS_TRADITIONAL
2711 !instr(s,"indir") &&
2712 instr(PL_origargv[0],"perl"))
2718 while (s < PL_bufend && isSPACE(*s))
2720 if (s < PL_bufend) {
2721 Newz(899,newargv,PL_origargc+3,char*);
2723 while (s < PL_bufend && !isSPACE(*s))
2726 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
2729 newargv = PL_origargv;
2731 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
2732 Perl_croak(aTHX_ "Can't exec %s", ipath);
2736 U32 oldpdb = PL_perldb;
2737 bool oldn = PL_minus_n;
2738 bool oldp = PL_minus_p;
2740 while (*d && !isSPACE(*d)) d++;
2741 while (SPACE_OR_TAB(*d)) d++;
2745 if (*d == 'M' || *d == 'm') {
2747 while (*d && !isSPACE(*d)) d++;
2748 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
2751 d = moreswitches(d);
2753 if ((PERLDB_LINE && !oldpdb) ||
2754 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
2755 /* if we have already added "LINE: while (<>) {",
2756 we must not do it again */
2758 sv_setpv(PL_linestr, "");
2759 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2760 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2761 PL_last_lop = PL_last_uni = Nullch;
2762 PL_preambled = FALSE;
2764 (void)gv_fetchfile(PL_origfilename);
2771 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2773 PL_lex_state = LEX_FORMLINE;
2778 #ifdef PERL_STRICT_CR
2779 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
2781 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
2783 case ' ': case '\t': case '\f': case 013:
2784 #ifdef MACOS_TRADITIONAL
2791 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
2792 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
2793 /* handle eval qq[#line 1 "foo"\n ...] */
2794 CopLINE_dec(PL_curcop);
2798 while (s < d && *s != '\n')
2803 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2805 PL_lex_state = LEX_FORMLINE;
2815 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
2822 while (s < PL_bufend && SPACE_OR_TAB(*s))
2825 if (strnEQ(s,"=>",2)) {
2826 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
2827 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2828 "### Saw unary minus before =>, forcing word '%s'\n", s);
2830 OPERATOR('-'); /* unary minus */
2832 PL_last_uni = PL_oldbufptr;
2834 case 'r': ftst = OP_FTEREAD; break;
2835 case 'w': ftst = OP_FTEWRITE; break;
2836 case 'x': ftst = OP_FTEEXEC; break;
2837 case 'o': ftst = OP_FTEOWNED; break;
2838 case 'R': ftst = OP_FTRREAD; break;
2839 case 'W': ftst = OP_FTRWRITE; break;
2840 case 'X': ftst = OP_FTREXEC; break;
2841 case 'O': ftst = OP_FTROWNED; break;
2842 case 'e': ftst = OP_FTIS; break;
2843 case 'z': ftst = OP_FTZERO; break;
2844 case 's': ftst = OP_FTSIZE; break;
2845 case 'f': ftst = OP_FTFILE; break;
2846 case 'd': ftst = OP_FTDIR; break;
2847 case 'l': ftst = OP_FTLINK; break;
2848 case 'p': ftst = OP_FTPIPE; break;
2849 case 'S': ftst = OP_FTSOCK; break;
2850 case 'u': ftst = OP_FTSUID; break;
2851 case 'g': ftst = OP_FTSGID; break;
2852 case 'k': ftst = OP_FTSVTX; break;
2853 case 'b': ftst = OP_FTBLK; break;
2854 case 'c': ftst = OP_FTCHR; break;
2855 case 't': ftst = OP_FTTTY; break;
2856 case 'T': ftst = OP_FTTEXT; break;
2857 case 'B': ftst = OP_FTBINARY; break;
2858 case 'M': case 'A': case 'C':
2859 gv_fetchpv("\024",TRUE, SVt_PV);
2861 case 'M': ftst = OP_FTMTIME; break;
2862 case 'A': ftst = OP_FTATIME; break;
2863 case 'C': ftst = OP_FTCTIME; break;
2868 Perl_croak(aTHX_ "Unrecognized file test: -%c", (int)tmp);
2871 PL_last_lop_op = ftst;
2872 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2873 "### Saw file test %c\n", (int)ftst);
2880 if (PL_expect == XOPERATOR)
2885 else if (*s == '>') {
2888 if (isIDFIRST_lazy_if(s,UTF)) {
2889 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
2897 if (PL_expect == XOPERATOR)
2900 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
2902 OPERATOR('-'); /* unary minus */
2909 if (PL_expect == XOPERATOR)
2914 if (PL_expect == XOPERATOR)
2917 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
2923 if (PL_expect != XOPERATOR) {
2924 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
2925 PL_expect = XOPERATOR;
2926 force_ident(PL_tokenbuf, '*');
2939 if (PL_expect == XOPERATOR) {
2943 PL_tokenbuf[0] = '%';
2944 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
2945 if (!PL_tokenbuf[1]) {
2947 yyerror("Final % should be \\% or %name");
2950 PL_pending_ident = '%';
2969 switch (PL_expect) {
2972 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
2974 PL_bufptr = s; /* update in case we back off */
2980 PL_expect = XTERMBLOCK;
2984 while (isIDFIRST_lazy_if(s,UTF)) {
2985 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
2986 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) {
2987 if (tmp < 0) tmp = -tmp;
3002 d = scan_str(d,TRUE,TRUE);
3004 /* MUST advance bufptr here to avoid bogus
3005 "at end of line" context messages from yyerror().
3007 PL_bufptr = s + len;
3008 yyerror("Unterminated attribute parameter in attribute list");
3011 return 0; /* EOF indicator */
3015 SV *sv = newSVpvn(s, len);
3016 sv_catsv(sv, PL_lex_stuff);
3017 attrs = append_elem(OP_LIST, attrs,
3018 newSVOP(OP_CONST, 0, sv));
3019 SvREFCNT_dec(PL_lex_stuff);
3020 PL_lex_stuff = Nullsv;
3023 if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len))
3024 CvLVALUE_on(PL_compcv);
3025 else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len))
3026 CvLOCKED_on(PL_compcv);
3027 else if (!PL_in_my && len == 6 && strnEQ(s, "method", len))
3028 CvMETHOD_on(PL_compcv);
3029 /* After we've set the flags, it could be argued that
3030 we don't need to do the attributes.pm-based setting
3031 process, and shouldn't bother appending recognized
3032 flags. To experiment with that, uncomment the
3033 following "else": */
3035 attrs = append_elem(OP_LIST, attrs,
3036 newSVOP(OP_CONST, 0,
3040 if (*s == ':' && s[1] != ':')
3043 break; /* require real whitespace or :'s */
3045 tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
3046 if (*s != ';' && *s != tmp && (tmp != '=' || *s != ')')) {
3047 char q = ((*s == '\'') ? '"' : '\'');
3048 /* If here for an expression, and parsed no attrs, back off. */
3049 if (tmp == '=' && !attrs) {
3053 /* MUST advance bufptr here to avoid bogus "at end of line"
3054 context messages from yyerror().
3058 yyerror("Unterminated attribute list");
3060 yyerror(Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list",
3068 PL_nextval[PL_nexttoke].opval = attrs;
3076 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
3077 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
3093 if (PL_lex_brackets <= 0)
3094 yyerror("Unmatched right square bracket");
3097 if (PL_lex_state == LEX_INTERPNORMAL) {
3098 if (PL_lex_brackets == 0) {
3099 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
3100 PL_lex_state = LEX_INTERPEND;
3107 if (PL_lex_brackets > 100) {
3108 char* newlb = Renew(PL_lex_brackstack, PL_lex_brackets + 1, char);
3109 if (newlb != PL_lex_brackstack) {
3111 PL_lex_brackstack = newlb;
3114 switch (PL_expect) {
3116 if (PL_lex_formbrack) {
3120 if (PL_oldoldbufptr == PL_last_lop)
3121 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3123 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3124 OPERATOR(HASHBRACK);
3126 while (s < PL_bufend && SPACE_OR_TAB(*s))
3129 PL_tokenbuf[0] = '\0';
3130 if (d < PL_bufend && *d == '-') {
3131 PL_tokenbuf[0] = '-';
3133 while (d < PL_bufend && SPACE_OR_TAB(*d))
3136 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
3137 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
3139 while (d < PL_bufend && SPACE_OR_TAB(*d))
3142 char minus = (PL_tokenbuf[0] == '-');
3143 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
3144 if (UTF && !IN_BYTE && is_utf8_string((U8*)PL_tokenbuf, 0) &&
3145 PL_nextval[PL_nexttoke-1].opval)
3146 SvUTF8_on(((SVOP*)PL_nextval[PL_nexttoke-1].opval)->op_sv);
3154 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
3159 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3164 if (PL_oldoldbufptr == PL_last_lop)
3165 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3167 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3170 OPERATOR(HASHBRACK);
3171 /* This hack serves to disambiguate a pair of curlies
3172 * as being a block or an anon hash. Normally, expectation
3173 * determines that, but in cases where we're not in a
3174 * position to expect anything in particular (like inside
3175 * eval"") we have to resolve the ambiguity. This code
3176 * covers the case where the first term in the curlies is a
3177 * quoted string. Most other cases need to be explicitly
3178 * disambiguated by prepending a `+' before the opening
3179 * curly in order to force resolution as an anon hash.
3181 * XXX should probably propagate the outer expectation
3182 * into eval"" to rely less on this hack, but that could
3183 * potentially break current behavior of eval"".
3187 if (*s == '\'' || *s == '"' || *s == '`') {
3188 /* common case: get past first string, handling escapes */
3189 for (t++; t < PL_bufend && *t != *s;)
3190 if (*t++ == '\\' && (*t == '\\' || *t == *s))
3194 else if (*s == 'q') {
3197 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
3201 char open, close, term;
3204 while (t < PL_bufend && isSPACE(*t))
3208 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
3212 for (t++; t < PL_bufend; t++) {
3213 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
3215 else if (*t == open)
3219 for (t++; t < PL_bufend; t++) {
3220 if (*t == '\\' && t+1 < PL_bufend)
3222 else if (*t == close && --brackets <= 0)
3224 else if (*t == open)
3230 else if (isALNUM_lazy_if(t,UTF)) {
3232 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3235 while (t < PL_bufend && isSPACE(*t))
3237 /* if comma follows first term, call it an anon hash */
3238 /* XXX it could be a comma expression with loop modifiers */
3239 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
3240 || (*t == '=' && t[1] == '>')))
3241 OPERATOR(HASHBRACK);
3242 if (PL_expect == XREF)
3245 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
3251 yylval.ival = CopLINE(PL_curcop);
3252 if (isSPACE(*s) || *s == '#')
3253 PL_copline = NOLINE; /* invalidate current command line number */
3258 if (PL_lex_brackets <= 0)
3259 yyerror("Unmatched right curly bracket");
3261 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
3262 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
3263 PL_lex_formbrack = 0;
3264 if (PL_lex_state == LEX_INTERPNORMAL) {
3265 if (PL_lex_brackets == 0) {
3266 if (PL_expect & XFAKEBRACK) {
3267 PL_expect &= XENUMMASK;
3268 PL_lex_state = LEX_INTERPEND;
3270 return yylex(); /* ignore fake brackets */
3272 if (*s == '-' && s[1] == '>')
3273 PL_lex_state = LEX_INTERPENDMAYBE;
3274 else if (*s != '[' && *s != '{')
3275 PL_lex_state = LEX_INTERPEND;
3278 if (PL_expect & XFAKEBRACK) {
3279 PL_expect &= XENUMMASK;
3281 return yylex(); /* ignore fake brackets */
3291 if (PL_expect == XOPERATOR) {
3292 if (ckWARN(WARN_SEMICOLON)
3293 && isIDFIRST_lazy_if(s,UTF) && PL_bufptr == PL_linestart)
3295 CopLINE_dec(PL_curcop);
3296 Perl_warner(aTHX_ WARN_SEMICOLON, PL_warn_nosemi);
3297 CopLINE_inc(PL_curcop);
3302 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3304 PL_expect = XOPERATOR;
3305 force_ident(PL_tokenbuf, '&');
3309 yylval.ival = (OPpENTERSUB_AMPER<<8);
3328 if (ckWARN(WARN_SYNTAX) && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
3329 Perl_warner(aTHX_ WARN_SYNTAX, "Reversed %c= operator",(int)tmp);
3331 if (PL_expect == XSTATE && isALPHA(tmp) &&
3332 (s == PL_linestart+1 || s[-2] == '\n') )
3334 if (PL_in_eval && !PL_rsfp) {
3339 if (strnEQ(s,"=cut",4)) {
3353 PL_doextract = TRUE;
3356 if (PL_lex_brackets < PL_lex_formbrack) {
3358 #ifdef PERL_STRICT_CR
3359 for (t = s; SPACE_OR_TAB(*t); t++) ;
3361 for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
3363 if (*t == '\n' || *t == '#') {
3381 if (PL_expect != XOPERATOR) {
3382 if (s[1] != '<' && !strchr(s,'>'))
3385 s = scan_heredoc(s);
3387 s = scan_inputsymbol(s);
3388 TERM(sublex_start());
3393 SHop(OP_LEFT_SHIFT);
3407 SHop(OP_RIGHT_SHIFT);
3416 if (PL_expect == XOPERATOR) {
3417 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3420 return ','; /* grandfather non-comma-format format */
3424 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
3425 PL_tokenbuf[0] = '@';
3426 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
3427 sizeof PL_tokenbuf - 1, FALSE);
3428 if (PL_expect == XOPERATOR)
3429 no_op("Array length", s);
3430 if (!PL_tokenbuf[1])
3432 PL_expect = XOPERATOR;
3433 PL_pending_ident = '#';
3437 PL_tokenbuf[0] = '$';
3438 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
3439 sizeof PL_tokenbuf - 1, FALSE);
3440 if (PL_expect == XOPERATOR)
3442 if (!PL_tokenbuf[1]) {
3444 yyerror("Final $ should be \\$ or $name");
3448 /* This kludge not intended to be bulletproof. */
3449 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
3450 yylval.opval = newSVOP(OP_CONST, 0,
3451 newSViv(PL_compiling.cop_arybase));
3452 yylval.opval->op_private = OPpCONST_ARYBASE;
3458 if (PL_lex_state == LEX_NORMAL)
3461 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3464 PL_tokenbuf[0] = '@';
3465 if (ckWARN(WARN_SYNTAX)) {
3467 isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$';
3470 PL_bufptr = skipspace(PL_bufptr);
3471 while (t < PL_bufend && *t != ']')
3473 Perl_warner(aTHX_ WARN_SYNTAX,
3474 "Multidimensional syntax %.*s not supported",
3475 (t - PL_bufptr) + 1, PL_bufptr);
3479 else if (*s == '{') {
3480 PL_tokenbuf[0] = '%';
3481 if (ckWARN(WARN_SYNTAX) && strEQ(PL_tokenbuf+1, "SIG") &&
3482 (t = strchr(s, '}')) && (t = strchr(t, '=')))
3484 char tmpbuf[sizeof PL_tokenbuf];
3486 for (t++; isSPACE(*t); t++) ;
3487 if (isIDFIRST_lazy_if(t,UTF)) {
3488 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
3489 for (; isSPACE(*t); t++) ;
3490 if (*t == ';' && get_cv(tmpbuf, FALSE))
3491 Perl_warner(aTHX_ WARN_SYNTAX,
3492 "You need to quote \"%s\"", tmpbuf);
3498 PL_expect = XOPERATOR;
3499 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
3500 bool islop = (PL_last_lop == PL_oldoldbufptr);
3501 if (!islop || PL_last_lop_op == OP_GREPSTART)
3502 PL_expect = XOPERATOR;
3503 else if (strchr("$@\"'`q", *s))
3504 PL_expect = XTERM; /* e.g. print $fh "foo" */
3505 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
3506 PL_expect = XTERM; /* e.g. print $fh &sub */
3507 else if (isIDFIRST_lazy_if(s,UTF)) {
3508 char tmpbuf[sizeof PL_tokenbuf];
3509 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3510 if ((tmp = keyword(tmpbuf, len))) {
3511 /* binary operators exclude handle interpretations */
3523 PL_expect = XTERM; /* e.g. print $fh length() */
3528 GV *gv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
3529 if (gv && GvCVu(gv))
3530 PL_expect = XTERM; /* e.g. print $fh subr() */
3533 else if (isDIGIT(*s))
3534 PL_expect = XTERM; /* e.g. print $fh 3 */
3535 else if (*s == '.' && isDIGIT(s[1]))
3536 PL_expect = XTERM; /* e.g. print $fh .3 */
3537 else if (strchr("/?-+", *s) && !isSPACE(s[1]) && s[1] != '=')
3538 PL_expect = XTERM; /* e.g. print $fh -1 */
3539 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=')
3540 PL_expect = XTERM; /* print $fh <<"EOF" */
3542 PL_pending_ident = '$';
3546 if (PL_expect == XOPERATOR)
3548 PL_tokenbuf[0] = '@';
3549 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
3550 if (!PL_tokenbuf[1]) {
3552 yyerror("Final @ should be \\@ or @name");
3555 if (PL_lex_state == LEX_NORMAL)
3557 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3559 PL_tokenbuf[0] = '%';
3561 /* Warn about @ where they meant $. */
3562 if (ckWARN(WARN_SYNTAX)) {
3563 if (*s == '[' || *s == '{') {
3565 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
3567 if (*t == '}' || *t == ']') {
3569 PL_bufptr = skipspace(PL_bufptr);
3570 Perl_warner(aTHX_ WARN_SYNTAX,
3571 "Scalar value %.*s better written as $%.*s",
3572 t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1);
3577 PL_pending_ident = '@';
3580 case '/': /* may either be division or pattern */
3581 case '?': /* may either be conditional or pattern */
3582 if (PL_expect != XOPERATOR) {
3583 /* Disable warning on "study /blah/" */
3584 if (PL_oldoldbufptr == PL_last_uni
3585 && (*PL_last_uni != 's' || s - PL_last_uni < 5
3586 || memNE(PL_last_uni, "study", 5)
3587 || isALNUM_lazy_if(PL_last_uni+5,UTF)))
3589 s = scan_pat(s,OP_MATCH);
3590 TERM(sublex_start());
3598 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
3599 #ifdef PERL_STRICT_CR
3602 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
3604 && (s == PL_linestart || s[-1] == '\n') )
3606 PL_lex_formbrack = 0;
3610 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
3616 yylval.ival = OPf_SPECIAL;
3622 if (PL_expect != XOPERATOR)
3627 case '0': case '1': case '2': case '3': case '4':
3628 case '5': case '6': case '7': case '8': case '9':
3629 s = scan_num(s, &yylval);
3630 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3631 "### Saw number in '%s'\n", s);
3633 if (PL_expect == XOPERATOR)
3638 s = scan_str(s,FALSE,FALSE);
3639 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3640 "### Saw string before '%s'\n", s);
3642 if (PL_expect == XOPERATOR) {
3643 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3646 return ','; /* grandfather non-comma-format format */
3652 missingterm((char*)0);
3653 yylval.ival = OP_CONST;
3654 TERM(sublex_start());
3657 s = scan_str(s,FALSE,FALSE);
3658 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3659 "### Saw string before '%s'\n", s);
3661 if (PL_expect == XOPERATOR) {
3662 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3665 return ','; /* grandfather non-comma-format format */
3671 missingterm((char*)0);
3672 yylval.ival = OP_CONST;
3673 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
3674 if (*d == '$' || *d == '@' || *d == '\\' || UTF8_IS_CONTINUED(*d)) {
3675 yylval.ival = OP_STRINGIFY;
3679 TERM(sublex_start());
3682 s = scan_str(s,FALSE,FALSE);
3683 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3684 "### Saw backtick string before '%s'\n", s);
3686 if (PL_expect == XOPERATOR)
3687 no_op("Backticks",s);
3689 missingterm((char*)0);
3690 yylval.ival = OP_BACKTICK;
3692 TERM(sublex_start());
3696 if (ckWARN(WARN_SYNTAX) && PL_lex_inwhat && isDIGIT(*s))
3697 Perl_warner(aTHX_ WARN_SYNTAX,"Can't use \\%c to mean $%c in expression",
3699 if (PL_expect == XOPERATOR)
3700 no_op("Backslash",s);
3704 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
3708 while (isDIGIT(*start) || *start == '_')
3710 if (*start == '.' && isDIGIT(start[1])) {
3711 s = scan_num(s, &yylval);
3714 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
3715 else if (!isALPHA(*start) && (PL_expect == XTERM || PL_expect == XREF)) {
3719 gv = gv_fetchpv(s, FALSE, SVt_PVCV);
3722 s = scan_num(s, &yylval);
3729 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
3768 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3770 /* Some keywords can be followed by any delimiter, including ':' */
3771 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
3772 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
3773 (PL_tokenbuf[0] == 'q' &&
3774 strchr("qwxr", PL_tokenbuf[1])))));
3776 /* x::* is just a word, unless x is "CORE" */
3777 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
3781 while (d < PL_bufend && isSPACE(*d))
3782 d++; /* no comments skipped here, or s### is misparsed */
3784 /* Is this a label? */
3785 if (!tmp && PL_expect == XSTATE
3786 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
3788 yylval.pval = savepv(PL_tokenbuf);
3793 /* Check for keywords */
3794 tmp = keyword(PL_tokenbuf, len);
3796 /* Is this a word before a => operator? */
3797 if (*d == '=' && d[1] == '>') {
3799 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf,0));
3800 yylval.opval->op_private = OPpCONST_BARE;
3801 if (UTF && !IN_BYTE && is_utf8_string((U8*)PL_tokenbuf, len))
3802 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
3806 if (tmp < 0) { /* second-class keyword? */
3807 GV *ogv = Nullgv; /* override (winner) */
3808 GV *hgv = Nullgv; /* hidden (loser) */
3809 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
3811 if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) &&
3814 if (GvIMPORTED_CV(gv))
3816 else if (! CvMETHOD(cv))
3820 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
3821 (gv = *gvp) != (GV*)&PL_sv_undef &&
3822 GvCVu(gv) && GvIMPORTED_CV(gv))
3828 tmp = 0; /* overridden by import or by GLOBAL */
3831 && -tmp==KEY_lock /* XXX generalizable kludge */
3833 && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE))
3835 tmp = 0; /* any sub overrides "weak" keyword */
3837 else { /* no override */
3841 if (ckWARN(WARN_AMBIGUOUS) && hgv
3842 && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */
3843 Perl_warner(aTHX_ WARN_AMBIGUOUS,
3844 "Ambiguous call resolved as CORE::%s(), %s",
3845 GvENAME(hgv), "qualify as such or use &");
3852 default: /* not a keyword */
3855 char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
3857 /* Get the rest if it looks like a package qualifier */
3859 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
3861 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
3864 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
3865 *s == '\'' ? "'" : "::");
3869 if (PL_expect == XOPERATOR) {
3870 if (PL_bufptr == PL_linestart) {
3871 CopLINE_dec(PL_curcop);
3872 Perl_warner(aTHX_ WARN_SEMICOLON, PL_warn_nosemi);
3873 CopLINE_inc(PL_curcop);
3876 no_op("Bareword",s);
3879 /* Look for a subroutine with this name in current package,
3880 unless name is "Foo::", in which case Foo is a bearword
3881 (and a package name). */
3884 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
3886 if (ckWARN(WARN_BAREWORD) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV))
3887 Perl_warner(aTHX_ WARN_BAREWORD,
3888 "Bareword \"%s\" refers to nonexistent package",
3891 PL_tokenbuf[len] = '\0';
3898 gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV);
3901 /* if we saw a global override before, get the right name */
3904 sv = newSVpvn("CORE::GLOBAL::",14);
3905 sv_catpv(sv,PL_tokenbuf);
3908 sv = newSVpv(PL_tokenbuf,0);
3910 /* Presume this is going to be a bareword of some sort. */
3913 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3914 yylval.opval->op_private = OPpCONST_BARE;
3916 /* And if "Foo::", then that's what it certainly is. */
3921 /* See if it's the indirect object for a list operator. */
3923 if (PL_oldoldbufptr &&
3924 PL_oldoldbufptr < PL_bufptr &&
3925 (PL_oldoldbufptr == PL_last_lop
3926 || PL_oldoldbufptr == PL_last_uni) &&
3927 /* NO SKIPSPACE BEFORE HERE! */
3928 (PL_expect == XREF ||
3929 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
3931 bool immediate_paren = *s == '(';
3933 /* (Now we can afford to cross potential line boundary.) */
3936 /* Two barewords in a row may indicate method call. */
3938 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp=intuit_method(s,gv)))
3941 /* If not a declared subroutine, it's an indirect object. */
3942 /* (But it's an indir obj regardless for sort.) */
3944 if ((PL_last_lop_op == OP_SORT ||
3945 (!immediate_paren && (!gv || !GvCVu(gv)))) &&
3946 (PL_last_lop_op != OP_MAPSTART &&
3947 PL_last_lop_op != OP_GREPSTART))
3949 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
3955 PL_expect = XOPERATOR;
3958 /* Is this a word before a => operator? */
3959 if (*s == '=' && s[1] == '>') {
3961 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
3962 if (UTF && !IN_BYTE && is_utf8_string((U8*)PL_tokenbuf, len))
3963 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
3967 /* If followed by a paren, it's certainly a subroutine. */
3970 if (gv && GvCVu(gv)) {
3971 for (d = s + 1; SPACE_OR_TAB(*d); d++) ;
3972 if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) {
3977 PL_nextval[PL_nexttoke].opval = yylval.opval;
3978 PL_expect = XOPERATOR;
3984 /* If followed by var or block, call it a method (unless sub) */
3986 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
3987 PL_last_lop = PL_oldbufptr;
3988 PL_last_lop_op = OP_METHOD;
3992 /* If followed by a bareword, see if it looks like indir obj. */
3994 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp = intuit_method(s,gv)))
3997 /* Not a method, so call it a subroutine (if defined) */
3999 if (gv && GvCVu(gv)) {
4001 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
4002 Perl_warner(aTHX_ WARN_AMBIGUOUS,
4003 "Ambiguous use of -%s resolved as -&%s()",
4004 PL_tokenbuf, PL_tokenbuf);
4005 /* Check for a constant sub */
4007 if ((sv = cv_const_sv(cv))) {
4009 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
4010 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
4011 yylval.opval->op_private = 0;
4015 /* Resolve to GV now. */
4016 op_free(yylval.opval);
4017 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
4018 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
4019 PL_last_lop = PL_oldbufptr;
4020 PL_last_lop_op = OP_ENTERSUB;
4021 /* Is there a prototype? */
4024 char *proto = SvPV((SV*)cv, len);
4027 if (strEQ(proto, "$"))
4029 if (*proto == '&' && *s == '{') {
4030 sv_setpv(PL_subname,"__ANON__");
4034 PL_nextval[PL_nexttoke].opval = yylval.opval;
4040 /* Call it a bare word */
4042 if (PL_hints & HINT_STRICT_SUBS)
4043 yylval.opval->op_private |= OPpCONST_STRICT;
4046 if (ckWARN(WARN_RESERVED)) {
4047 if (lastchar != '-') {
4048 for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ;
4050 Perl_warner(aTHX_ WARN_RESERVED, PL_warn_reserved,
4057 if (lastchar && strchr("*%&", lastchar) && ckWARN_d(WARN_AMBIGUOUS)) {
4058 Perl_warner(aTHX_ WARN_AMBIGUOUS,
4059 "Operator or semicolon missing before %c%s",
4060 lastchar, PL_tokenbuf);
4061 Perl_warner(aTHX_ WARN_AMBIGUOUS,
4062 "Ambiguous use of %c resolved as operator %c",
4063 lastchar, lastchar);
4069 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4070 newSVpv(CopFILE(PL_curcop),0));
4074 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4075 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
4078 case KEY___PACKAGE__:
4079 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4081 ? newSVsv(PL_curstname)
4090 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
4091 char *pname = "main";
4092 if (PL_tokenbuf[2] == 'D')
4093 pname = HvNAME(PL_curstash ? PL_curstash : PL_defstash);
4094 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO);
4097 GvIOp(gv) = newIO();
4098 IoIFP(GvIOp(gv)) = PL_rsfp;
4099 #if defined(HAS_FCNTL) && defined(F_SETFD)
4101 int fd = PerlIO_fileno(PL_rsfp);
4102 fcntl(fd,F_SETFD,fd >= 3);
4105 /* Mark this internal pseudo-handle as clean */
4106 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
4108 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
4109 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
4110 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
4112 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
4113 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
4114 /* if the script was opened in binmode, we need to revert
4115 * it to text mode for compatibility; but only iff it has CRs
4116 * XXX this is a questionable hack at best. */
4117 if (PL_bufend-PL_bufptr > 2
4118 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
4121 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
4122 loc = PerlIO_tell(PL_rsfp);
4123 (void)PerlIO_seek(PL_rsfp, 0L, 0);
4125 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
4126 #if defined(__BORLANDC__)
4127 /* XXX see note in do_binmode() */
4128 ((FILE*)PL_rsfp)->flags |= _F_BIN;
4131 PerlIO_seek(PL_rsfp, loc, 0);
4146 if (PL_expect == XSTATE) {
4153 if (*s == ':' && s[1] == ':') {
4156 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4157 if (!(tmp = keyword(PL_tokenbuf, len)))
4158 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
4172 LOP(OP_ACCEPT,XTERM);
4178 LOP(OP_ATAN2,XTERM);
4184 LOP(OP_BINMODE,XTERM);
4187 LOP(OP_BLESS,XTERM);
4196 (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */
4213 if (!PL_cryptseen) {
4214 PL_cryptseen = TRUE;
4218 LOP(OP_CRYPT,XTERM);
4221 if (ckWARN(WARN_CHMOD)) {
4222 for (d = s; d < PL_bufend && (isSPACE(*d) || *d == '('); d++) ;
4223 if (*d != '0' && isDIGIT(*d))
4224 Perl_warner(aTHX_ WARN_CHMOD,
4225 "chmod() mode argument is missing initial 0");
4227 LOP(OP_CHMOD,XTERM);
4230 LOP(OP_CHOWN,XTERM);
4233 LOP(OP_CONNECT,XTERM);
4249 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4253 PL_hints |= HINT_BLOCK_SCOPE;
4263 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
4264 LOP(OP_DBMOPEN,XTERM);
4270 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4277 yylval.ival = CopLINE(PL_curcop);
4291 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
4292 UNIBRACK(OP_ENTEREVAL);
4307 case KEY_endhostent:
4313 case KEY_endservent:
4316 case KEY_endprotoent:
4327 yylval.ival = CopLINE(PL_curcop);
4329 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
4331 if ((PL_bufend - p) >= 3 &&
4332 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
4334 else if ((PL_bufend - p) >= 4 &&
4335 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
4338 if (isIDFIRST_lazy_if(p,UTF)) {
4339 p = scan_ident(p, PL_bufend,
4340 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4344 Perl_croak(aTHX_ "Missing $ on loop variable");
4349 LOP(OP_FORMLINE,XTERM);
4355 LOP(OP_FCNTL,XTERM);
4361 LOP(OP_FLOCK,XTERM);
4370 LOP(OP_GREPSTART, XREF);
4373 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4388 case KEY_getpriority:
4389 LOP(OP_GETPRIORITY,XTERM);
4391 case KEY_getprotobyname:
4394 case KEY_getprotobynumber:
4395 LOP(OP_GPBYNUMBER,XTERM);
4397 case KEY_getprotoent:
4409 case KEY_getpeername:
4410 UNI(OP_GETPEERNAME);
4412 case KEY_gethostbyname:
4415 case KEY_gethostbyaddr:
4416 LOP(OP_GHBYADDR,XTERM);
4418 case KEY_gethostent:
4421 case KEY_getnetbyname:
4424 case KEY_getnetbyaddr:
4425 LOP(OP_GNBYADDR,XTERM);
4430 case KEY_getservbyname:
4431 LOP(OP_GSBYNAME,XTERM);
4433 case KEY_getservbyport:
4434 LOP(OP_GSBYPORT,XTERM);
4436 case KEY_getservent:
4439 case KEY_getsockname:
4440 UNI(OP_GETSOCKNAME);
4442 case KEY_getsockopt:
4443 LOP(OP_GSOCKOPT,XTERM);
4465 yylval.ival = CopLINE(PL_curcop);
4469 LOP(OP_INDEX,XTERM);
4475 LOP(OP_IOCTL,XTERM);
4487 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4519 LOP(OP_LISTEN,XTERM);
4528 s = scan_pat(s,OP_MATCH);
4529 TERM(sublex_start());
4532 LOP(OP_MAPSTART, XREF);
4535 LOP(OP_MKDIR,XTERM);
4538 LOP(OP_MSGCTL,XTERM);
4541 LOP(OP_MSGGET,XTERM);
4544 LOP(OP_MSGRCV,XTERM);
4547 LOP(OP_MSGSND,XTERM);
4553 if (isIDFIRST_lazy_if(s,UTF)) {
4554 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
4555 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
4557 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
4558 if (!PL_in_my_stash) {
4561 sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
4569 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4576 if (PL_expect != XSTATE)
4577 yyerror("\"no\" not allowed in expression");
4578 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4579 s = force_version(s);
4584 if (*s == '(' || (s = skipspace(s), *s == '('))
4591 if (isIDFIRST_lazy_if(s,UTF)) {
4593 for (d = s; isALNUM_lazy_if(d,UTF); d++) ;
4595 if (strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE))
4596 Perl_warner(aTHX_ WARN_PRECEDENCE,
4597 "Precedence problem: open %.*s should be open(%.*s)",
4603 yylval.ival = OP_OR;
4613 LOP(OP_OPEN_DIR,XTERM);
4616 checkcomma(s,PL_tokenbuf,"filehandle");
4620 checkcomma(s,PL_tokenbuf,"filehandle");
4639 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4643 LOP(OP_PIPE_OP,XTERM);
4646 s = scan_str(s,FALSE,FALSE);
4648 missingterm((char*)0);
4649 yylval.ival = OP_CONST;
4650 TERM(sublex_start());
4656 s = scan_str(s,FALSE,FALSE);
4658 missingterm((char*)0);
4660 if (SvCUR(PL_lex_stuff)) {
4663 d = SvPV_force(PL_lex_stuff, len);
4666 for (; isSPACE(*d) && len; --len, ++d) ;
4669 if (!warned && ckWARN(WARN_QW)) {
4670 for (; !isSPACE(*d) && len; --len, ++d) {
4672 Perl_warner(aTHX_ WARN_QW,
4673 "Possible attempt to separate words with commas");
4676 else if (*d == '#') {
4677 Perl_warner(aTHX_ WARN_QW,
4678 "Possible attempt to put comments in qw() list");
4684 for (; !isSPACE(*d) && len; --len, ++d) ;
4686 sv = newSVpvn(b, d-b);
4687 if (DO_UTF8(PL_lex_stuff))
4689 words = append_elem(OP_LIST, words,
4690 newSVOP(OP_CONST, 0, tokeq(sv)));
4694 PL_nextval[PL_nexttoke].opval = words;
4699 SvREFCNT_dec(PL_lex_stuff);
4700 PL_lex_stuff = Nullsv;
4706 s = scan_str(s,FALSE,FALSE);
4708 missingterm((char*)0);
4709 yylval.ival = OP_STRINGIFY;
4710 if (SvIVX(PL_lex_stuff) == '\'')
4711 SvIVX(PL_lex_stuff) = 0; /* qq'$foo' should intepolate */
4712 TERM(sublex_start());
4715 s = scan_pat(s,OP_QR);
4716 TERM(sublex_start());
4719 s = scan_str(s,FALSE,FALSE);
4721 missingterm((char*)0);
4722 yylval.ival = OP_BACKTICK;
4724 TERM(sublex_start());
4731 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
4732 s = force_version(s);
4735 *PL_tokenbuf = '\0';
4736 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4737 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
4738 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
4740 yyerror("<> should be quotes");
4748 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4752 LOP(OP_RENAME,XTERM);
4761 LOP(OP_RINDEX,XTERM);
4784 LOP(OP_REVERSE,XTERM);
4795 TERM(sublex_start());
4797 TOKEN(1); /* force error */
4806 LOP(OP_SELECT,XTERM);
4812 LOP(OP_SEMCTL,XTERM);
4815 LOP(OP_SEMGET,XTERM);
4818 LOP(OP_SEMOP,XTERM);
4824 LOP(OP_SETPGRP,XTERM);
4826 case KEY_setpriority:
4827 LOP(OP_SETPRIORITY,XTERM);
4829 case KEY_sethostent:
4835 case KEY_setservent:
4838 case KEY_setprotoent:
4848 LOP(OP_SEEKDIR,XTERM);
4850 case KEY_setsockopt:
4851 LOP(OP_SSOCKOPT,XTERM);
4857 LOP(OP_SHMCTL,XTERM);
4860 LOP(OP_SHMGET,XTERM);
4863 LOP(OP_SHMREAD,XTERM);
4866 LOP(OP_SHMWRITE,XTERM);
4869 LOP(OP_SHUTDOWN,XTERM);
4878 LOP(OP_SOCKET,XTERM);
4880 case KEY_socketpair:
4881 LOP(OP_SOCKPAIR,XTERM);
4884 checkcomma(s,PL_tokenbuf,"subroutine name");
4886 if (*s == ';' || *s == ')') /* probably a close */
4887 Perl_croak(aTHX_ "sort is now a reserved word");
4889 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4893 LOP(OP_SPLIT,XTERM);
4896 LOP(OP_SPRINTF,XTERM);
4899 LOP(OP_SPLICE,XTERM);
4914 LOP(OP_SUBSTR,XTERM);
4920 char tmpbuf[sizeof PL_tokenbuf];
4922 expectation attrful;
4923 bool have_name, have_proto;
4928 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
4929 (*s == ':' && s[1] == ':'))
4932 attrful = XATTRBLOCK;
4933 /* remember buffer pos'n for later force_word */
4934 tboffset = s - PL_oldbufptr;
4935 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4936 if (strchr(tmpbuf, ':'))
4937 sv_setpv(PL_subname, tmpbuf);
4939 sv_setsv(PL_subname,PL_curstname);
4940 sv_catpvn(PL_subname,"::",2);
4941 sv_catpvn(PL_subname,tmpbuf,len);
4948 Perl_croak(aTHX_ "Missing name in \"my sub\"");
4949 PL_expect = XTERMBLOCK;
4950 attrful = XATTRTERM;
4951 sv_setpv(PL_subname,"?");
4955 if (key == KEY_format) {
4957 PL_lex_formbrack = PL_lex_brackets + 1;
4959 (void) force_word(PL_oldbufptr + tboffset, WORD,
4964 /* Look for a prototype */
4968 s = scan_str(s,FALSE,FALSE);
4970 Perl_croak(aTHX_ "Prototype not terminated");
4972 d = SvPVX(PL_lex_stuff);
4974 for (p = d; *p; ++p) {
4979 SvCUR(PL_lex_stuff) = tmp;
4987 if (*s == ':' && s[1] != ':')
4988 PL_expect = attrful;
4991 PL_nextval[PL_nexttoke].opval =
4992 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
4993 PL_lex_stuff = Nullsv;
4997 sv_setpv(PL_subname,"__ANON__");
5000 (void) force_word(PL_oldbufptr + tboffset, WORD,
5009 LOP(OP_SYSTEM,XREF);
5012 LOP(OP_SYMLINK,XTERM);
5015 LOP(OP_SYSCALL,XTERM);
5018 LOP(OP_SYSOPEN,XTERM);
5021 LOP(OP_SYSSEEK,XTERM);
5024 LOP(OP_SYSREAD,XTERM);
5027 LOP(OP_SYSWRITE,XTERM);
5031 TERM(sublex_start());
5052 LOP(OP_TRUNCATE,XTERM);
5064 yylval.ival = CopLINE(PL_curcop);
5068 yylval.ival = CopLINE(PL_curcop);
5072 LOP(OP_UNLINK,XTERM);
5078 LOP(OP_UNPACK,XTERM);
5081 LOP(OP_UTIME,XTERM);
5084 if (ckWARN(WARN_UMASK)) {
5085 for (d = s; d < PL_bufend && (isSPACE(*d) || *d == '('); d++) ;
5086 if (*d != '0' && isDIGIT(*d))
5087 Perl_warner(aTHX_ WARN_UMASK,
5088 "umask: argument is missing initial 0");
5093 LOP(OP_UNSHIFT,XTERM);
5096 if (PL_expect != XSTATE)
5097 yyerror("\"use\" not allowed in expression");
5099 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
5100 s = force_version(s);
5101 if (*s == ';' || (s = skipspace(s), *s == ';')) {
5102 PL_nextval[PL_nexttoke].opval = Nullop;
5107 s = force_word(s,WORD,FALSE,TRUE,FALSE);
5108 s = force_version(s);
5120 yylval.ival = CopLINE(PL_curcop);
5124 PL_hints |= HINT_BLOCK_SCOPE;
5131 LOP(OP_WAITPID,XTERM);
5139 static char ctl_l[2];
5141 if (ctl_l[0] == '\0')
5142 ctl_l[0] = toCTRL('L');
5143 gv_fetchpv(ctl_l,TRUE, SVt_PV);
5146 gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */
5151 if (PL_expect == XOPERATOR)
5157 yylval.ival = OP_XOR;
5162 TERM(sublex_start());
5167 #pragma segment Main
5171 Perl_keyword(pTHX_ register char *d, I32 len)
5176 if (strEQ(d,"__FILE__")) return -KEY___FILE__;
5177 if (strEQ(d,"__LINE__")) return -KEY___LINE__;
5178 if (strEQ(d,"__PACKAGE__")) return -KEY___PACKAGE__;
5179 if (strEQ(d,"__DATA__")) return KEY___DATA__;
5180 if (strEQ(d,"__END__")) return KEY___END__;
5184 if (strEQ(d,"AUTOLOAD")) return KEY_AUTOLOAD;
5189 if (strEQ(d,"and")) return -KEY_and;
5190 if (strEQ(d,"abs")) return -KEY_abs;
5193 if (strEQ(d,"alarm")) return -KEY_alarm;
5194 if (strEQ(d,"atan2")) return -KEY_atan2;
5197 if (strEQ(d,"accept")) return -KEY_accept;
5202 if (strEQ(d,"BEGIN")) return KEY_BEGIN;
5205 if (strEQ(d,"bless")) return -KEY_bless;
5206 if (strEQ(d,"bind")) return -KEY_bind;
5207 if (strEQ(d,"binmode")) return -KEY_binmode;
5210 if (strEQ(d,"CORE")) return -KEY_CORE;
5211 if (strEQ(d,"CHECK")) return KEY_CHECK;
5216 if (strEQ(d,"cmp")) return -KEY_cmp;
5217 if (strEQ(d,"chr")) return -KEY_chr;
5218 if (strEQ(d,"cos")) return -KEY_cos;
5221 if (strEQ(d,"chop")) return -KEY_chop;
5224 if (strEQ(d,"close")) return -KEY_close;
5225 if (strEQ(d,"chdir")) return -KEY_chdir;
5226 if (strEQ(d,"chomp")) return -KEY_chomp;
5227 if (strEQ(d,"chmod")) return -KEY_chmod;
5228 if (strEQ(d,"chown")) return -KEY_chown;
5229 if (strEQ(d,"crypt")) return -KEY_crypt;
5232 if (strEQ(d,"chroot")) return -KEY_chroot;
5233 if (strEQ(d,"caller")) return -KEY_caller;
5236 if (strEQ(d,"connect")) return -KEY_connect;
5239 if (strEQ(d,"closedir")) return -KEY_closedir;
5240 if (strEQ(d,"continue")) return -KEY_continue;
5245 if (strEQ(d,"DESTROY")) return KEY_DESTROY;
5250 if (strEQ(d,"do")) return KEY_do;
5253 if (strEQ(d,"die")) return -KEY_die;
5256 if (strEQ(d,"dump")) return -KEY_dump;
5259 if (strEQ(d,"delete")) return KEY_delete;
5262 if (strEQ(d,"defined")) return KEY_defined;
5263 if (strEQ(d,"dbmopen")) return -KEY_dbmopen;
5266 if (strEQ(d,"dbmclose")) return -KEY_dbmclose;
5271 if (strEQ(d,"EQ")) { deprecate(d); return -KEY_eq;}
5272 if (strEQ(d,"END")) return KEY_END;
5277 if (strEQ(d,"eq")) return -KEY_eq;
5280 if (strEQ(d,"eof")) return -KEY_eof;
5281 if (strEQ(d,"exp")) return -KEY_exp;
5284 if (strEQ(d,"else")) return KEY_else;
5285 if (strEQ(d,"exit")) return -KEY_exit;
5286 if (strEQ(d,"eval")) return KEY_eval;
5287 if (strEQ(d,"exec")) return -KEY_exec;
5288 if (strEQ(d,"each")) return -KEY_each;
5291 if (strEQ(d,"elsif")) return KEY_elsif;
5294 if (strEQ(d,"exists")) return KEY_exists;
5295 if (strEQ(d,"elseif")) Perl_warn(aTHX_ "elseif should be elsif");
5298 if (strEQ(d,"endgrent")) return -KEY_endgrent;
5299 if (strEQ(d,"endpwent")) return -KEY_endpwent;
5302 if (strEQ(d,"endnetent")) return -KEY_endnetent;
5305 if (strEQ(d,"endhostent")) return -KEY_endhostent;
5306 if (strEQ(d,"endservent")) return -KEY_endservent;
5309 if (strEQ(d,"endprotoent")) return -KEY_endprotoent;
5316 if (strEQ(d,"for")) return KEY_for;
5319 if (strEQ(d,"fork")) return -KEY_fork;
5322 if (strEQ(d,"fcntl")) return -KEY_fcntl;
5323 if (strEQ(d,"flock")) return -KEY_flock;
5326 if (strEQ(d,"format")) return KEY_format;
5327 if (strEQ(d,"fileno")) return -KEY_fileno;
5330 if (strEQ(d,"foreach")) return KEY_foreach;
5333 if (strEQ(d,"formline")) return -KEY_formline;
5339 if (strEQ(d,"GT")) { deprecate(d); return -KEY_gt;}
5340 if (strEQ(d,"GE")) { deprecate(d); return -KEY_ge;}
5344 if (strnEQ(d,"get",3)) {
5349 if (strEQ(d,"ppid")) return -KEY_getppid;
5350 if (strEQ(d,"pgrp")) return -KEY_getpgrp;
5353 if (strEQ(d,"pwent")) return -KEY_getpwent;
5354 if (strEQ(d,"pwnam")) return -KEY_getpwnam;
5355 if (strEQ(d,"pwuid")) return -KEY_getpwuid;
5358 if (strEQ(d,"peername")) return -KEY_getpeername;
5359 if (strEQ(d,"protoent")) return -KEY_getprotoent;
5360 if (strEQ(d,"priority")) return -KEY_getpriority;
5363 if (strEQ(d,"protobyname")) return -KEY_getprotobyname;
5366 if (strEQ(d,"protobynumber"))return -KEY_getprotobynumber;
5370 else if (*d == 'h') {
5371 if (strEQ(d,"hostbyname")) return -KEY_gethostbyname;
5372 if (strEQ(d,"hostbyaddr")) return -KEY_gethostbyaddr;
5373 if (strEQ(d,"hostent")) return -KEY_gethostent;
5375 else if (*d == 'n') {
5376 if (strEQ(d,"netbyname")) return -KEY_getnetbyname;
5377 if (strEQ(d,"netbyaddr")) return -KEY_getnetbyaddr;
5378 if (strEQ(d,"netent")) return -KEY_getnetent;
5380 else if (*d == 's') {
5381 if (strEQ(d,"servbyname")) return -KEY_getservbyname;
5382 if (strEQ(d,"servbyport")) return -KEY_getservbyport;
5383 if (strEQ(d,"servent")) return -KEY_getservent;
5384 if (strEQ(d,"sockname")) return -KEY_getsockname;
5385 if (strEQ(d,"sockopt")) return -KEY_getsockopt;
5387 else if (*d == 'g') {
5388 if (strEQ(d,"grent")) return -KEY_getgrent;
5389 if (strEQ(d,"grnam")) return -KEY_getgrnam;
5390 if (strEQ(d,"grgid")) return -KEY_getgrgid;
5392 else if (*d == 'l') {
5393 if (strEQ(d,"login")) return -KEY_getlogin;
5395 else if (strEQ(d,"c")) return -KEY_getc;
5400 if (strEQ(d,"gt")) return -KEY_gt;
5401 if (strEQ(d,"ge")) return -KEY_ge;
5404 if (strEQ(d,"grep")) return KEY_grep;
5405 if (strEQ(d,"goto")) return KEY_goto;
5406 if (strEQ(d,"glob")) return KEY_glob;
5409 if (strEQ(d,"gmtime")) return -KEY_gmtime;
5414 if (strEQ(d,"hex")) return -KEY_hex;
5417 if (strEQ(d,"INIT")) return KEY_INIT;
5422 if (strEQ(d,"if")) return KEY_if;
5425 if (strEQ(d,"int")) return -KEY_int;
5428 if (strEQ(d,"index")) return -KEY_index;
5429 if (strEQ(d,"ioctl")) return -KEY_ioctl;
5434 if (strEQ(d,"join")) return -KEY_join;
5438 if (strEQ(d,"keys")) return -KEY_keys;
5439 if (strEQ(d,"kill")) return -KEY_kill;
5444 if (strEQ(d,"LT")) { deprecate(d); return -KEY_lt;}
5445 if (strEQ(d,"LE")) { deprecate(d); return -KEY_le;}
5451 if (strEQ(d,"lt")) return -KEY_lt;
5452 if (strEQ(d,"le")) return -KEY_le;
5453 if (strEQ(d,"lc")) return -KEY_lc;
5456 if (strEQ(d,"log")) return -KEY_log;
5459 if (strEQ(d,"last")) return KEY_last;
5460 if (strEQ(d,"link")) return -KEY_link;
5461 if (strEQ(d,"lock")) return -KEY_lock;
5464 if (strEQ(d,"local")) return KEY_local;
5465 if (strEQ(d,"lstat")) return -KEY_lstat;
5468 if (strEQ(d,"length")) return -KEY_length;
5469 if (strEQ(d,"listen")) return -KEY_listen;
5472 if (strEQ(d,"lcfirst")) return -KEY_lcfirst;
5475 if (strEQ(d,"localtime")) return -KEY_localtime;
5481 case 1: return KEY_m;
5483 if (strEQ(d,"my")) return KEY_my;
5486 if (strEQ(d,"map")) return KEY_map;
5489 if (strEQ(d,"mkdir")) return -KEY_mkdir;
5492 if (strEQ(d,"msgctl")) return -KEY_msgctl;
5493 if (strEQ(d,"msgget")) return -KEY_msgget;
5494 if (strEQ(d,"msgrcv")) return -KEY_msgrcv;
5495 if (strEQ(d,"msgsnd")) return -KEY_msgsnd;
5500 if (strEQ(d,"NE")) { deprecate(d); return -KEY_ne;}
5503 if (strEQ(d,"next")) return KEY_next;
5504 if (strEQ(d,"ne")) return -KEY_ne;
5505 if (strEQ(d,"not")) return -KEY_not;
5506 if (strEQ(d,"no")) return KEY_no;
5511 if (strEQ(d,"or")) return -KEY_or;
5514 if (strEQ(d,"ord")) return -KEY_ord;
5515 if (strEQ(d,"oct")) return -KEY_oct;
5516 if (strEQ(d,"our")) return KEY_our;
5519 if (strEQ(d,"open")) return -KEY_open;
5522 if (strEQ(d,"opendir")) return -KEY_opendir;
5529 if (strEQ(d,"pop")) return -KEY_pop;
5530 if (strEQ(d,"pos")) return KEY_pos;
5533 if (strEQ(d,"push")) return -KEY_push;
5534 if (strEQ(d,"pack")) return -KEY_pack;
5535 if (strEQ(d,"pipe")) return -KEY_pipe;
5538 if (strEQ(d,"print")) return KEY_print;
5541 if (strEQ(d,"printf")) return KEY_printf;
5544 if (strEQ(d,"package")) return KEY_package;
5547 if (strEQ(d,"prototype")) return KEY_prototype;
5552 if (strEQ(d,"q")) return KEY_q;
5553 if (strEQ(d,"qr")) return KEY_qr;
5554 if (strEQ(d,"qq")) return KEY_qq;
5555 if (strEQ(d,"qw")) return KEY_qw;
5556 if (strEQ(d,"qx")) return KEY_qx;
5558 else if (strEQ(d,"quotemeta")) return -KEY_quotemeta;
5563 if (strEQ(d,"ref")) return -KEY_ref;
5566 if (strEQ(d,"read")) return -KEY_read;
5567 if (strEQ(d,"rand")) return -KEY_rand;
5568 if (strEQ(d,"recv")) return -KEY_recv;
5569 if (strEQ(d,"redo")) return KEY_redo;
5572 if (strEQ(d,"rmdir")) return -KEY_rmdir;
5573 if (strEQ(d,"reset")) return -KEY_reset;
5576 if (strEQ(d,"return")) return KEY_return;
5577 if (strEQ(d,"rename")) return -KEY_rename;
5578 if (strEQ(d,"rindex")) return -KEY_rindex;
5581 if (strEQ(d,"require")) return -KEY_require;
5582 if (strEQ(d,"reverse")) return -KEY_reverse;
5583 if (strEQ(d,"readdir")) return -KEY_readdir;
5586 if (strEQ(d,"readlink")) return -KEY_readlink;
5587 if (strEQ(d,"readline")) return -KEY_readline;
5588 if (strEQ(d,"readpipe")) return -KEY_readpipe;
5591 if (strEQ(d,"rewinddir")) return -KEY_rewinddir;
5597 case 0: return KEY_s;
5599 if (strEQ(d,"scalar")) return KEY_scalar;
5604 if (strEQ(d,"seek")) return -KEY_seek;
5605 if (strEQ(d,"send")) return -KEY_send;
5608 if (strEQ(d,"semop")) return -KEY_semop;
5611 if (strEQ(d,"select")) return -KEY_select;
5612 if (strEQ(d,"semctl")) return -KEY_semctl;
5613 if (strEQ(d,"semget")) return -KEY_semget;
5616 if (strEQ(d,"setpgrp")) return -KEY_setpgrp;
5617 if (strEQ(d,"seekdir")) return -KEY_seekdir;
5620 if (strEQ(d,"setpwent")) return -KEY_setpwent;
5621 if (strEQ(d,"setgrent")) return -KEY_setgrent;
5624 if (strEQ(d,"setnetent")) return -KEY_setnetent;
5627 if (strEQ(d,"setsockopt")) return -KEY_setsockopt;
5628 if (strEQ(d,"sethostent")) return -KEY_sethostent;
5629 if (strEQ(d,"setservent")) return -KEY_setservent;
5632 if (strEQ(d,"setpriority")) return -KEY_setpriority;
5633 if (strEQ(d,"setprotoent")) return -KEY_setprotoent;
5640 if (strEQ(d,"shift")) return -KEY_shift;
5643 if (strEQ(d,"shmctl")) return -KEY_shmctl;
5644 if (strEQ(d,"shmget")) return -KEY_shmget;
5647 if (strEQ(d,"shmread")) return -KEY_shmread;
5650 if (strEQ(d,"shmwrite")) return -KEY_shmwrite;
5651 if (strEQ(d,"shutdown")) return -KEY_shutdown;
5656 if (strEQ(d,"sin")) return -KEY_sin;
5659 if (strEQ(d,"sleep")) return -KEY_sleep;
5662 if (strEQ(d,"sort")) return KEY_sort;
5663 if (strEQ(d,"socket")) return -KEY_socket;
5664 if (strEQ(d,"socketpair")) return -KEY_socketpair;
5667 if (strEQ(d,"split")) return KEY_split;
5668 if (strEQ(d,"sprintf")) return -KEY_sprintf;
5669 if (strEQ(d,"splice")) return -KEY_splice;
5672 if (strEQ(d,"sqrt")) return -KEY_sqrt;
5675 if (strEQ(d,"srand")) return -KEY_srand;
5678 if (strEQ(d,"stat")) return -KEY_stat;
5679 if (strEQ(d,"study")) return KEY_study;
5682 if (strEQ(d,"substr")) return -KEY_substr;
5683 if (strEQ(d,"sub")) return KEY_sub;
5688 if (strEQ(d,"system")) return -KEY_system;
5691 if (strEQ(d,"symlink")) return -KEY_symlink;
5692 if (strEQ(d,"syscall")) return -KEY_syscall;
5693 if (strEQ(d,"sysopen")) return -KEY_sysopen;
5694 if (strEQ(d,"sysread")) return -KEY_sysread;
5695 if (strEQ(d,"sysseek")) return -KEY_sysseek;
5698 if (strEQ(d,"syswrite")) return -KEY_syswrite;
5707 if (strEQ(d,"tr")) return KEY_tr;
5710 if (strEQ(d,"tie")) return KEY_tie;
5713 if (strEQ(d,"tell")) return -KEY_tell;
5714 if (strEQ(d,"tied")) return KEY_tied;
5715 if (strEQ(d,"time")) return -KEY_time;
5718 if (strEQ(d,"times")) return -KEY_times;
5721 if (strEQ(d,"telldir")) return -KEY_telldir;
5724 if (strEQ(d,"truncate")) return -KEY_truncate;
5731 if (strEQ(d,"uc")) return -KEY_uc;
5734 if (strEQ(d,"use")) return KEY_use;
5737 if (strEQ(d,"undef")) return KEY_undef;
5738 if (strEQ(d,"until")) return KEY_until;
5739 if (strEQ(d,"untie")) return KEY_untie;
5740 if (strEQ(d,"utime")) return -KEY_utime;
5741 if (strEQ(d,"umask")) return -KEY_umask;
5744 if (strEQ(d,"unless")) return KEY_unless;
5745 if (strEQ(d,"unpack")) return -KEY_unpack;
5746 if (strEQ(d,"unlink")) return -KEY_unlink;
5749 if (strEQ(d,"unshift")) return -KEY_unshift;
5750 if (strEQ(d,"ucfirst")) return -KEY_ucfirst;
5755 if (strEQ(d,"values")) return -KEY_values;
5756 if (strEQ(d,"vec")) return -KEY_vec;
5761 if (strEQ(d,"warn")) return -KEY_warn;
5762 if (strEQ(d,"wait")) return -KEY_wait;
5765 if (strEQ(d,"while")) return KEY_while;
5766 if (strEQ(d,"write")) return -KEY_write;
5769 if (strEQ(d,"waitpid")) return -KEY_waitpid;
5772 if (strEQ(d,"wantarray")) return -KEY_wantarray;
5777 if (len == 1) return -KEY_x;
5778 if (strEQ(d,"xor")) return -KEY_xor;
5781 if (len == 1) return KEY_y;
5790 S_checkcomma(pTHX_ register char *s, char *name, char *what)
5794 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
5795 if (ckWARN(WARN_SYNTAX)) {
5797 for (w = s+2; *w && level; w++) {
5804 for (; *w && isSPACE(*w); w++) ;
5805 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
5806 Perl_warner(aTHX_ WARN_SYNTAX,
5807 "%s (...) interpreted as function",name);
5810 while (s < PL_bufend && isSPACE(*s))
5814 while (s < PL_bufend && isSPACE(*s))
5816 if (isIDFIRST_lazy_if(s,UTF)) {
5818 while (isALNUM_lazy_if(s,UTF))
5820 while (s < PL_bufend && isSPACE(*s))
5825 kw = keyword(w, s - w) || get_cv(w, FALSE) != 0;
5829 Perl_croak(aTHX_ "No comma allowed after %s", what);
5834 /* Either returns sv, or mortalizes sv and returns a new SV*.
5835 Best used as sv=new_constant(..., sv, ...).
5836 If s, pv are NULL, calls subroutine with one argument,
5837 and type is used with error messages only. */
5840 S_new_constant(pTHX_ char *s, STRLEN len, const char *key, SV *sv, SV *pv,
5844 HV *table = GvHV(PL_hintgv); /* ^H */
5848 const char *why1, *why2, *why3;
5850 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
5853 why2 = strEQ(key,"charnames")
5854 ? "(possibly a missing \"use charnames ...\")"
5856 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
5857 (type ? type: "undef"), why2);
5859 /* This is convoluted and evil ("goto considered harmful")
5860 * but I do not understand the intricacies of all the different
5861 * failure modes of %^H in here. The goal here is to make
5862 * the most probable error message user-friendly. --jhi */
5867 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
5868 (type ? type: "undef"), why1, why2, why3);
5870 yyerror(SvPVX(msg));
5874 cvp = hv_fetch(table, key, strlen(key), FALSE);
5875 if (!cvp || !SvOK(*cvp)) {
5878 why3 = "} is not defined";
5881 sv_2mortal(sv); /* Parent created it permanently */
5884 pv = sv_2mortal(newSVpvn(s, len));
5886 typesv = sv_2mortal(newSVpv(type, 0));
5888 typesv = &PL_sv_undef;
5890 PUSHSTACKi(PERLSI_OVERLOAD);
5902 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
5906 /* Check the eval first */
5907 if (!PL_in_eval && SvTRUE(ERRSV)) {
5909 sv_catpv(ERRSV, "Propagated");
5910 yyerror(SvPV(ERRSV, n_a)); /* Duplicates the message inside eval */
5912 res = SvREFCNT_inc(sv);
5916 (void)SvREFCNT_inc(res);
5925 why1 = "Call to &{$^H{";
5927 why3 = "}} did not return a defined value";
5936 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
5938 register char *d = dest;
5939 register char *e = d + destlen - 3; /* two-character token, ending NUL */
5942 Perl_croak(aTHX_ ident_too_long);
5943 if (isALNUM(*s)) /* UTF handled below */
5945 else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) {
5950 else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') {
5954 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
5955 char *t = s + UTF8SKIP(s);
5956 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
5958 if (d + (t - s) > e)
5959 Perl_croak(aTHX_ ident_too_long);
5960 Copy(s, d, t - s, char);
5973 S_scan_ident(pTHX_ register char *s, register char *send, char *dest, STRLEN destlen, I32 ck_uni)
5983 e = d + destlen - 3; /* two-character token, ending NUL */
5985 while (isDIGIT(*s)) {
5987 Perl_croak(aTHX_ ident_too_long);
5994 Perl_croak(aTHX_ ident_too_long);
5995 if (isALNUM(*s)) /* UTF handled below */
5997 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
6002 else if (*s == ':' && s[1] == ':') {
6006 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
6007 char *t = s + UTF8SKIP(s);
6008 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
6010 if (d + (t - s) > e)
6011 Perl_croak(aTHX_ ident_too_long);
6012 Copy(s, d, t - s, char);
6023 if (PL_lex_state != LEX_NORMAL)
6024 PL_lex_state = LEX_INTERPENDMAYBE;
6027 if (*s == '$' && s[1] &&
6028 (isALNUM_lazy_if(s+1,UTF) || strchr("${", s[1]) || strnEQ(s+1,"::",2)) )
6041 if (*d == '^' && *s && isCONTROLVAR(*s)) {
6046 if (isSPACE(s[-1])) {
6049 if (!SPACE_OR_TAB(ch)) {
6055 if (isIDFIRST_lazy_if(d,UTF)) {
6059 while ((e < send && isALNUM_lazy_if(e,UTF)) || *e == ':') {
6061 while (e < send && UTF8_IS_CONTINUED(*e) && is_utf8_mark((U8*)e))
6064 Copy(s, d, e - s, char);
6069 while ((isALNUM(*s) || *s == ':') && d < e)
6072 Perl_croak(aTHX_ ident_too_long);
6075 while (s < send && SPACE_OR_TAB(*s)) s++;
6076 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
6077 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
6078 const char *brack = *s == '[' ? "[...]" : "{...}";
6079 Perl_warner(aTHX_ WARN_AMBIGUOUS,
6080 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
6081 funny, dest, brack, funny, dest, brack);
6084 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
6088 /* Handle extended ${^Foo} variables
6089 * 1999-02-27 mjd-perl-patch@plover.com */
6090 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
6094 while (isALNUM(*s) && d < e) {
6098 Perl_croak(aTHX_ ident_too_long);
6103 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets)
6104 PL_lex_state = LEX_INTERPEND;
6107 if (PL_lex_state == LEX_NORMAL) {
6108 if (ckWARN(WARN_AMBIGUOUS) &&
6109 (keyword(dest, d - dest) || get_cv(dest, FALSE)))
6111 Perl_warner(aTHX_ WARN_AMBIGUOUS,
6112 "Ambiguous use of %c{%s} resolved to %c%s",
6113 funny, dest, funny, dest);
6118 s = bracket; /* let the parser handle it */
6122 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
6123 PL_lex_state = LEX_INTERPEND;
6128 Perl_pmflag(pTHX_ U16 *pmfl, int ch)
6133 *pmfl |= PMf_GLOBAL;
6135 *pmfl |= PMf_CONTINUE;
6139 *pmfl |= PMf_MULTILINE;
6141 *pmfl |= PMf_SINGLELINE;
6143 *pmfl |= PMf_EXTENDED;
6147 S_scan_pat(pTHX_ char *start, I32 type)
6152 s = scan_str(start,FALSE,FALSE);
6154 Perl_croak(aTHX_ "Search pattern not terminated");
6156 pm = (PMOP*)newPMOP(type, 0);
6157 if (PL_multi_open == '?')
6158 pm->op_pmflags |= PMf_ONCE;
6160 while (*s && strchr("iomsx", *s))
6161 pmflag(&pm->op_pmflags,*s++);
6164 while (*s && strchr("iogcmsx", *s))
6165 pmflag(&pm->op_pmflags,*s++);
6167 pm->op_pmpermflags = pm->op_pmflags;
6169 PL_lex_op = (OP*)pm;
6170 yylval.ival = OP_MATCH;
6175 S_scan_subst(pTHX_ char *start)
6182 yylval.ival = OP_NULL;
6184 s = scan_str(start,FALSE,FALSE);
6187 Perl_croak(aTHX_ "Substitution pattern not terminated");
6189 if (s[-1] == PL_multi_open)
6192 first_start = PL_multi_start;
6193 s = scan_str(s,FALSE,FALSE);
6196 SvREFCNT_dec(PL_lex_stuff);
6197 PL_lex_stuff = Nullsv;
6199 Perl_croak(aTHX_ "Substitution replacement not terminated");
6201 PL_multi_start = first_start; /* so whole substitution is taken together */
6203 pm = (PMOP*)newPMOP(OP_SUBST, 0);
6209 else if (strchr("iogcmsx", *s))
6210 pmflag(&pm->op_pmflags,*s++);
6217 PL_sublex_info.super_bufptr = s;
6218 PL_sublex_info.super_bufend = PL_bufend;
6220 pm->op_pmflags |= PMf_EVAL;
6221 repl = newSVpvn("",0);
6223 sv_catpv(repl, es ? "eval " : "do ");
6224 sv_catpvn(repl, "{ ", 2);
6225 sv_catsv(repl, PL_lex_repl);
6226 sv_catpvn(repl, " };", 2);
6228 SvREFCNT_dec(PL_lex_repl);
6232 pm->op_pmpermflags = pm->op_pmflags;
6233 PL_lex_op = (OP*)pm;
6234 yylval.ival = OP_SUBST;
6239 S_scan_trans(pTHX_ char *start)
6250 yylval.ival = OP_NULL;
6252 s = scan_str(start,FALSE,FALSE);
6254 Perl_croak(aTHX_ "Transliteration pattern not terminated");
6255 if (s[-1] == PL_multi_open)
6258 s = scan_str(s,FALSE,FALSE);
6261 SvREFCNT_dec(PL_lex_stuff);
6262 PL_lex_stuff = Nullsv;
6264 Perl_croak(aTHX_ "Transliteration replacement not terminated");
6267 New(803,tbl,256,short);
6268 o = newPVOP(OP_TRANS, 0, (char*)tbl);
6270 complement = del = squash = 0;
6271 while (strchr("cds", *s)) {
6273 complement = OPpTRANS_COMPLEMENT;
6275 del = OPpTRANS_DELETE;
6277 squash = OPpTRANS_SQUASH;
6280 o->op_private = del|squash|complement|
6281 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
6282 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
6285 yylval.ival = OP_TRANS;
6290 S_scan_heredoc(pTHX_ register char *s)
6293 I32 op_type = OP_SCALAR;
6300 int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
6304 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
6307 for (peek = s; SPACE_OR_TAB(*peek); peek++) ;
6308 if (*peek && strchr("`'\"",*peek)) {
6311 s = delimcpy(d, e, s, PL_bufend, term, &len);
6321 if (!isALNUM_lazy_if(s,UTF))
6322 deprecate("bare << to mean <<\"\"");
6323 for (; isALNUM_lazy_if(s,UTF); s++) {
6328 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
6329 Perl_croak(aTHX_ "Delimiter for here document is too long");
6332 len = d - PL_tokenbuf;
6333 #ifndef PERL_STRICT_CR
6334 d = strchr(s, '\r');
6338 while (s < PL_bufend) {
6344 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
6353 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
6358 if (outer || !(d=ninstr(s,PL_bufend,d,d+1)))
6359 herewas = newSVpvn(s,PL_bufend-s);
6361 s--, herewas = newSVpvn(s,d-s);
6362 s += SvCUR(herewas);
6364 tmpstr = NEWSV(87,79);
6365 sv_upgrade(tmpstr, SVt_PVIV);
6370 else if (term == '`') {
6371 op_type = OP_BACKTICK;
6372 SvIVX(tmpstr) = '\\';
6376 PL_multi_start = CopLINE(PL_curcop);
6377 PL_multi_open = PL_multi_close = '<';
6378 term = *PL_tokenbuf;
6379 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
6380 char *bufptr = PL_sublex_info.super_bufptr;
6381 char *bufend = PL_sublex_info.super_bufend;
6382 char *olds = s - SvCUR(herewas);
6383 s = strchr(bufptr, '\n');
6387 while (s < bufend &&
6388 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
6390 CopLINE_inc(PL_curcop);
6393 CopLINE_set(PL_curcop, PL_multi_start);
6394 missingterm(PL_tokenbuf);
6396 sv_setpvn(herewas,bufptr,d-bufptr+1);
6397 sv_setpvn(tmpstr,d+1,s-d);
6399 sv_catpvn(herewas,s,bufend-s);
6400 (void)strcpy(bufptr,SvPVX(herewas));
6407 while (s < PL_bufend &&
6408 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
6410 CopLINE_inc(PL_curcop);
6412 if (s >= PL_bufend) {
6413 CopLINE_set(PL_curcop, PL_multi_start);
6414 missingterm(PL_tokenbuf);
6416 sv_setpvn(tmpstr,d+1,s-d);
6418 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
6420 sv_catpvn(herewas,s,PL_bufend-s);
6421 sv_setsv(PL_linestr,herewas);
6422 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
6423 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6424 PL_last_lop = PL_last_uni = Nullch;
6427 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
6428 while (s >= PL_bufend) { /* multiple line string? */
6430 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
6431 CopLINE_set(PL_curcop, PL_multi_start);
6432 missingterm(PL_tokenbuf);
6434 CopLINE_inc(PL_curcop);
6435 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6436 PL_last_lop = PL_last_uni = Nullch;
6437 #ifndef PERL_STRICT_CR
6438 if (PL_bufend - PL_linestart >= 2) {
6439 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
6440 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
6442 PL_bufend[-2] = '\n';
6444 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
6446 else if (PL_bufend[-1] == '\r')
6447 PL_bufend[-1] = '\n';
6449 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
6450 PL_bufend[-1] = '\n';
6452 if (PERLDB_LINE && PL_curstash != PL_debstash) {
6453 SV *sv = NEWSV(88,0);
6455 sv_upgrade(sv, SVt_PVMG);
6456 sv_setsv(sv,PL_linestr);
6457 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv);
6459 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
6462 sv_catsv(PL_linestr,herewas);
6463 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6467 sv_catsv(tmpstr,PL_linestr);
6472 PL_multi_end = CopLINE(PL_curcop);
6473 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
6474 SvLEN_set(tmpstr, SvCUR(tmpstr) + 1);
6475 Renew(SvPVX(tmpstr), SvLEN(tmpstr), char);
6477 SvREFCNT_dec(herewas);
6478 if (UTF && !IN_BYTE && is_utf8_string((U8*)SvPVX(tmpstr), SvCUR(tmpstr)))
6480 PL_lex_stuff = tmpstr;
6481 yylval.ival = op_type;
6486 takes: current position in input buffer
6487 returns: new position in input buffer
6488 side-effects: yylval and lex_op are set.
6493 <FH> read from filehandle
6494 <pkg::FH> read from package qualified filehandle
6495 <pkg'FH> read from package qualified filehandle
6496 <$fh> read from filehandle in $fh
6502 S_scan_inputsymbol(pTHX_ char *start)
6504 register char *s = start; /* current position in buffer */
6510 d = PL_tokenbuf; /* start of temp holding space */
6511 e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
6512 end = strchr(s, '\n');
6515 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
6517 /* die if we didn't have space for the contents of the <>,
6518 or if it didn't end, or if we see a newline
6521 if (len >= sizeof PL_tokenbuf)
6522 Perl_croak(aTHX_ "Excessively long <> operator");
6524 Perl_croak(aTHX_ "Unterminated <> operator");
6529 Remember, only scalar variables are interpreted as filehandles by
6530 this code. Anything more complex (e.g., <$fh{$num}>) will be
6531 treated as a glob() call.
6532 This code makes use of the fact that except for the $ at the front,
6533 a scalar variable and a filehandle look the same.
6535 if (*d == '$' && d[1]) d++;
6537 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
6538 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
6541 /* If we've tried to read what we allow filehandles to look like, and
6542 there's still text left, then it must be a glob() and not a getline.
6543 Use scan_str to pull out the stuff between the <> and treat it
6544 as nothing more than a string.
6547 if (d - PL_tokenbuf != len) {
6548 yylval.ival = OP_GLOB;
6550 s = scan_str(start,FALSE,FALSE);
6552 Perl_croak(aTHX_ "Glob not terminated");
6556 /* we're in a filehandle read situation */
6559 /* turn <> into <ARGV> */
6561 (void)strcpy(d,"ARGV");
6563 /* if <$fh>, create the ops to turn the variable into a
6569 /* try to find it in the pad for this block, otherwise find
6570 add symbol table ops
6572 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
6573 OP *o = newOP(OP_PADSV, 0);
6575 PL_lex_op = (OP*)newUNOP(OP_READLINE, 0, o);
6578 GV *gv = gv_fetchpv(d+1,TRUE, SVt_PV);
6579 PL_lex_op = (OP*)newUNOP(OP_READLINE, 0,
6580 newUNOP(OP_RV2SV, 0,
6581 newGVOP(OP_GV, 0, gv)));
6583 PL_lex_op->op_flags |= OPf_SPECIAL;
6584 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
6585 yylval.ival = OP_NULL;
6588 /* If it's none of the above, it must be a literal filehandle
6589 (<Foo::BAR> or <FOO>) so build a simple readline OP */
6591 GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO);
6592 PL_lex_op = (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
6593 yylval.ival = OP_NULL;
6602 takes: start position in buffer
6603 keep_quoted preserve \ on the embedded delimiter(s)
6604 keep_delims preserve the delimiters around the string
6605 returns: position to continue reading from buffer
6606 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
6607 updates the read buffer.
6609 This subroutine pulls a string out of the input. It is called for:
6610 q single quotes q(literal text)
6611 ' single quotes 'literal text'
6612 qq double quotes qq(interpolate $here please)
6613 " double quotes "interpolate $here please"
6614 qx backticks qx(/bin/ls -l)
6615 ` backticks `/bin/ls -l`
6616 qw quote words @EXPORT_OK = qw( func() $spam )
6617 m// regexp match m/this/
6618 s/// regexp substitute s/this/that/
6619 tr/// string transliterate tr/this/that/
6620 y/// string transliterate y/this/that/
6621 ($*@) sub prototypes sub foo ($)
6622 (stuff) sub attr parameters sub foo : attr(stuff)
6623 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
6625 In most of these cases (all but <>, patterns and transliterate)
6626 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
6627 calls scan_str(). s/// makes yylex() call scan_subst() which calls
6628 scan_str(). tr/// and y/// make yylex() call scan_trans() which
6631 It skips whitespace before the string starts, and treats the first
6632 character as the delimiter. If the delimiter is one of ([{< then
6633 the corresponding "close" character )]}> is used as the closing
6634 delimiter. It allows quoting of delimiters, and if the string has
6635 balanced delimiters ([{<>}]) it allows nesting.
6637 On success, the SV with the resulting string is put into lex_stuff or,
6638 if that is already non-NULL, into lex_repl. The second case occurs only
6639 when parsing the RHS of the special constructs s/// and tr/// (y///).
6640 For convenience, the terminating delimiter character is stuffed into
6645 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
6647 SV *sv; /* scalar value: string */
6648 char *tmps; /* temp string, used for delimiter matching */
6649 register char *s = start; /* current position in the buffer */
6650 register char term; /* terminating character */
6651 register char *to; /* current position in the sv's data */
6652 I32 brackets = 1; /* bracket nesting level */
6653 bool has_utf8 = FALSE; /* is there any utf8 content? */
6655 /* skip space before the delimiter */
6659 /* mark where we are, in case we need to report errors */
6662 /* after skipping whitespace, the next character is the terminator */
6664 if (UTF8_IS_CONTINUED(term) && UTF)
6667 /* mark where we are */
6668 PL_multi_start = CopLINE(PL_curcop);
6669 PL_multi_open = term;
6671 /* find corresponding closing delimiter */
6672 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
6674 PL_multi_close = term;
6676 /* create a new SV to hold the contents. 87 is leak category, I'm
6677 assuming. 79 is the SV's initial length. What a random number. */
6679 sv_upgrade(sv, SVt_PVIV);
6681 (void)SvPOK_only(sv); /* validate pointer */
6683 /* move past delimiter and try to read a complete string */
6685 sv_catpvn(sv, s, 1);
6688 /* extend sv if need be */
6689 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
6690 /* set 'to' to the next character in the sv's string */
6691 to = SvPVX(sv)+SvCUR(sv);
6693 /* if open delimiter is the close delimiter read unbridle */
6694 if (PL_multi_open == PL_multi_close) {
6695 for (; s < PL_bufend; s++,to++) {
6696 /* embedded newlines increment the current line number */
6697 if (*s == '\n' && !PL_rsfp)
6698 CopLINE_inc(PL_curcop);
6699 /* handle quoted delimiters */
6700 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
6701 if (!keep_quoted && s[1] == term)
6703 /* any other quotes are simply copied straight through */
6707 /* terminate when run out of buffer (the for() condition), or
6708 have found the terminator */
6709 else if (*s == term)
6711 else if (!has_utf8 && UTF8_IS_CONTINUED(*s) && UTF)
6717 /* if the terminator isn't the same as the start character (e.g.,
6718 matched brackets), we have to allow more in the quoting, and
6719 be prepared for nested brackets.
6722 /* read until we run out of string, or we find the terminator */
6723 for (; s < PL_bufend; s++,to++) {
6724 /* embedded newlines increment the line count */
6725 if (*s == '\n' && !PL_rsfp)
6726 CopLINE_inc(PL_curcop);
6727 /* backslashes can escape the open or closing characters */
6728 if (*s == '\\' && s+1 < PL_bufend) {
6730 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
6735 /* allow nested opens and closes */
6736 else if (*s == PL_multi_close && --brackets <= 0)
6738 else if (*s == PL_multi_open)
6740 else if (!has_utf8 && UTF8_IS_CONTINUED(*s) && UTF)
6745 /* terminate the copied string and update the sv's end-of-string */
6747 SvCUR_set(sv, to - SvPVX(sv));
6750 * this next chunk reads more into the buffer if we're not done yet
6754 break; /* handle case where we are done yet :-) */
6756 #ifndef PERL_STRICT_CR
6757 if (to - SvPVX(sv) >= 2) {
6758 if ((to[-2] == '\r' && to[-1] == '\n') ||
6759 (to[-2] == '\n' && to[-1] == '\r'))
6763 SvCUR_set(sv, to - SvPVX(sv));
6765 else if (to[-1] == '\r')
6768 else if (to - SvPVX(sv) == 1 && to[-1] == '\r')
6772 /* if we're out of file, or a read fails, bail and reset the current
6773 line marker so we can report where the unterminated string began
6776 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
6778 CopLINE_set(PL_curcop, PL_multi_start);
6781 /* we read a line, so increment our line counter */
6782 CopLINE_inc(PL_curcop);
6784 /* update debugger info */
6785 if (PERLDB_LINE && PL_curstash != PL_debstash) {
6786 SV *sv = NEWSV(88,0);
6788 sv_upgrade(sv, SVt_PVMG);
6789 sv_setsv(sv,PL_linestr);
6790 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv);
6793 /* having changed the buffer, we must update PL_bufend */
6794 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6795 PL_last_lop = PL_last_uni = Nullch;
6798 /* at this point, we have successfully read the delimited string */
6801 sv_catpvn(sv, s, 1);
6804 PL_multi_end = CopLINE(PL_curcop);
6807 /* if we allocated too much space, give some back */
6808 if (SvCUR(sv) + 5 < SvLEN(sv)) {
6809 SvLEN_set(sv, SvCUR(sv) + 1);
6810 Renew(SvPVX(sv), SvLEN(sv), char);
6813 /* decide whether this is the first or second quoted string we've read
6826 takes: pointer to position in buffer
6827 returns: pointer to new position in buffer
6828 side-effects: builds ops for the constant in yylval.op
6830 Read a number in any of the formats that Perl accepts:
6832 0(x[0-7A-F]+)|([0-7]+)|(b[01])
6833 [\d_]+(\.[\d_]*)?[Ee](\d+)
6835 Underbars (_) are allowed in decimal numbers. If -w is on,
6836 underbars before a decimal point must be at three digit intervals.
6838 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
6841 If it reads a number without a decimal point or an exponent, it will
6842 try converting the number to an integer and see if it can do so
6843 without loss of precision.
6847 Perl_scan_num(pTHX_ char *start, YYSTYPE* lvalp)
6849 register char *s = start; /* current position in buffer */
6850 register char *d; /* destination in temp buffer */
6851 register char *e; /* end of temp buffer */
6852 NV nv; /* number read, as a double */
6853 SV *sv = Nullsv; /* place to put the converted number */
6854 bool floatit; /* boolean: int or float? */
6855 char *lastub = 0; /* position of last underbar */
6856 static char number_too_long[] = "Number too long";
6858 /* We use the first character to decide what type of number this is */
6862 Perl_croak(aTHX_ "panic: scan_num");
6864 /* if it starts with a 0, it could be an octal number, a decimal in
6865 0.13 disguise, or a hexadecimal number, or a binary number. */
6869 u holds the "number so far"
6870 shift the power of 2 of the base
6871 (hex == 4, octal == 3, binary == 1)
6872 overflowed was the number more than we can hold?
6874 Shift is used when we add a digit. It also serves as an "are
6875 we in octal/hex/binary?" indicator to disallow hex characters
6881 bool overflowed = FALSE;
6882 static NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
6883 static char* bases[5] = { "", "binary", "", "octal",
6885 static char* Bases[5] = { "", "Binary", "", "Octal",
6887 static char *maxima[5] = { "",
6888 "0b11111111111111111111111111111111",
6892 char *base, *Base, *max;
6898 } else if (s[1] == 'b') {
6902 /* check for a decimal in disguise */
6903 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
6905 /* so it must be octal */
6909 base = bases[shift];
6910 Base = Bases[shift];
6911 max = maxima[shift];
6913 /* read the rest of the number */
6915 /* x is used in the overflow test,
6916 b is the digit we're adding on. */
6921 /* if we don't mention it, we're done */
6930 /* 8 and 9 are not octal */
6933 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
6937 case '2': case '3': case '4':
6938 case '5': case '6': case '7':
6940 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
6944 b = *s++ & 15; /* ASCII digit -> value of digit */
6948 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
6949 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
6950 /* make sure they said 0x */
6955 /* Prepare to put the digit we have onto the end
6956 of the number so far. We check for overflows.
6961 x = u << shift; /* make room for the digit */
6963 if ((x >> shift) != u
6964 && !(PL_hints & HINT_NEW_BINARY)) {
6967 if (ckWARN_d(WARN_OVERFLOW))
6968 Perl_warner(aTHX_ WARN_OVERFLOW,
6969 "Integer overflow in %s number",
6972 u = x | b; /* add the digit to the end */
6975 n *= nvshift[shift];
6976 /* If an NV has not enough bits in its
6977 * mantissa to represent an UV this summing of
6978 * small low-order numbers is a waste of time
6979 * (because the NV cannot preserve the
6980 * low-order bits anyway): we could just
6981 * remember when did we overflow and in the
6982 * end just multiply n by the right
6990 /* if we get here, we had success: make a scalar value from
6996 if (ckWARN(WARN_PORTABLE) && n > 4294967295.0)
6997 Perl_warner(aTHX_ WARN_PORTABLE,
6998 "%s number > %s non-portable",
7004 if (ckWARN(WARN_PORTABLE) && u > 0xffffffff)
7005 Perl_warner(aTHX_ WARN_PORTABLE,
7006 "%s number > %s non-portable",
7011 if (PL_hints & HINT_NEW_BINARY)
7012 sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL);
7017 handle decimal numbers.
7018 we're also sent here when we read a 0 as the first digit
7020 case '1': case '2': case '3': case '4': case '5':
7021 case '6': case '7': case '8': case '9': case '.':
7024 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
7027 /* read next group of digits and _ and copy into d */
7028 while (isDIGIT(*s) || *s == '_') {
7029 /* skip underscores, checking for misplaced ones
7033 if (ckWARN(WARN_SYNTAX) && lastub && s - lastub != 3)
7034 Perl_warner(aTHX_ WARN_SYNTAX, "Misplaced _ in number");
7038 /* check for end of fixed-length buffer */
7040 Perl_croak(aTHX_ number_too_long);
7041 /* if we're ok, copy the character */
7046 /* final misplaced underbar check */
7047 if (lastub && s - lastub != 3) {
7048 if (ckWARN(WARN_SYNTAX))
7049 Perl_warner(aTHX_ WARN_SYNTAX, "Misplaced _ in number");
7052 /* read a decimal portion if there is one. avoid
7053 3..5 being interpreted as the number 3. followed
7056 if (*s == '.' && s[1] != '.') {
7060 /* copy, ignoring underbars, until we run out of
7061 digits. Note: no misplaced underbar checks!
7063 for (; isDIGIT(*s) || *s == '_'; s++) {
7064 /* fixed length buffer check */
7066 Perl_croak(aTHX_ number_too_long);
7070 if (*s == '.' && isDIGIT(s[1])) {
7071 /* oops, it's really a v-string, but without the "v" */
7077 /* read exponent part, if present */
7078 if (*s && strchr("eE",*s) && strchr("+-0123456789",s[1])) {
7082 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
7083 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
7085 /* allow positive or negative exponent */
7086 if (*s == '+' || *s == '-')
7089 /* read digits of exponent (no underbars :-) */
7090 while (isDIGIT(*s)) {
7092 Perl_croak(aTHX_ number_too_long);
7097 /* terminate the string */
7100 /* make an sv from the string */
7103 #if defined(Strtol) && defined(Strtoul)
7106 strtol/strtoll sets errno to ERANGE if the number is too big
7107 for an integer. We try to do an integer conversion first
7108 if no characters indicating "float" have been found.
7115 if (*PL_tokenbuf == '-')
7116 iv = Strtol(PL_tokenbuf, (char**)NULL, 10);
7118 uv = Strtoul(PL_tokenbuf, (char**)NULL, 10);
7120 floatit = TRUE; /* Probably just too large. */
7121 else if (*PL_tokenbuf == '-')
7123 else if (uv <= IV_MAX)
7124 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
7129 nv = Atof(PL_tokenbuf);
7134 No working strtou?ll?.
7136 Unfortunately atol() doesn't do range checks (returning
7137 LONG_MIN/LONG_MAX, and setting errno to ERANGE on overflows)
7138 everywhere [1], so we cannot use use atol() (or atoll()).
7139 If we could, they would be used, as Atol(), very much like
7140 Strtol() and Strtoul() are used above.
7142 [1] XXX Configure test needed to check for atol()
7143 (and atoll()) overflow behaviour XXX
7147 We need to do this the hard way. */
7149 nv = Atof(PL_tokenbuf);
7151 /* See if we can make do with an integer value without loss of
7152 precision. We use U_V to cast to a UV, because some
7153 compilers have issues. Then we try casting it back and see
7154 if it was the same [1]. We only do this if we know we
7155 specifically read an integer. If floatit is true, then we
7156 don't need to do the conversion at all.
7158 [1] Note that this is lossy if our NVs cannot preserve our
7159 UVs. There are metaconfig defines NV_PRESERVES_UV (a boolean)
7160 and NV_PRESERVES_UV_BITS (a number), but in general we really
7161 do hope all such potentially lossy platforms have strtou?ll?
7162 to do a lossless IV/UV conversion.
7164 Maybe could do some tricks with DBL_DIG, LDBL_DIG and
7165 DBL_MANT_DIG and LDBL_MANT_DIG (these are already available
7166 as NV_DIG and NV_MANT_DIG)?
7172 if (!floatit && (NV)uv == nv) {
7174 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
7182 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
7183 (PL_hints & HINT_NEW_INTEGER) )
7184 sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
7185 (floatit ? "float" : "integer"),
7189 /* if it starts with a v, it could be a v-string */
7195 while (isDIGIT(*pos) || *pos == '_')
7197 if (!isALPHA(*pos)) {
7199 U8 tmpbuf[UTF8_MAXLEN+1];
7202 s++; /* get past 'v' */
7205 sv_setpvn(sv, "", 0);
7208 if (*s == '0' && isDIGIT(s[1]))
7209 yyerror("Octal number in vector unsupported");
7212 /* this is atoi() that tolerates underscores */
7215 while (--end >= s) {
7220 rev += (*end - '0') * mult;
7222 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
7223 Perl_warner(aTHX_ WARN_OVERFLOW,
7224 "Integer overflow in decimal number");
7227 tmpend = uv_to_utf8(tmpbuf, rev);
7228 utf8 = utf8 || rev > 127;
7229 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
7230 if (*pos == '.' && isDIGIT(pos[1]))
7236 while (isDIGIT(*pos) || *pos == '_')
7245 sv_utf8_downgrade(sv, TRUE);
7252 /* make the op for the constant and return */
7255 lvalp->opval = newSVOP(OP_CONST, 0, sv);
7257 lvalp->opval = Nullop;
7263 S_scan_formline(pTHX_ register char *s)
7267 SV *stuff = newSVpvn("",0);
7268 bool needargs = FALSE;
7271 if (*s == '.' || *s == /*{*/'}') {
7273 #ifdef PERL_STRICT_CR
7274 for (t = s+1;SPACE_OR_TAB(*t); t++) ;
7276 for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
7278 if (*t == '\n' || t == PL_bufend)
7281 if (PL_in_eval && !PL_rsfp) {
7282 eol = strchr(s,'\n');
7287 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
7289 for (t = s; t < eol; t++) {
7290 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
7292 goto enough; /* ~~ must be first line in formline */
7294 if (*t == '@' || *t == '^')
7297 sv_catpvn(stuff, s, eol-s);
7298 #ifndef PERL_STRICT_CR
7299 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
7300 char *end = SvPVX(stuff) + SvCUR(stuff);
7309 s = filter_gets(PL_linestr, PL_rsfp, 0);
7310 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
7311 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
7312 PL_last_lop = PL_last_uni = Nullch;
7315 yyerror("Format not terminated");
7325 PL_lex_state = LEX_NORMAL;
7326 PL_nextval[PL_nexttoke].ival = 0;
7330 PL_lex_state = LEX_FORMLINE;
7331 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff);
7333 PL_nextval[PL_nexttoke].ival = OP_FORMLINE;
7337 SvREFCNT_dec(stuff);
7338 PL_lex_formbrack = 0;
7349 PL_cshlen = strlen(PL_cshname);
7354 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
7356 I32 oldsavestack_ix = PL_savestack_ix;
7357 CV* outsidecv = PL_compcv;
7361 assert(SvTYPE(PL_compcv) == SVt_PVCV);
7363 SAVEI32(PL_subline);
7364 save_item(PL_subname);
7367 SAVESPTR(PL_comppad_name);
7368 SAVESPTR(PL_compcv);
7369 SAVEI32(PL_comppad_name_fill);
7370 SAVEI32(PL_min_intro_pending);
7371 SAVEI32(PL_max_intro_pending);
7372 SAVEI32(PL_pad_reset_pending);
7374 PL_compcv = (CV*)NEWSV(1104,0);
7375 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
7376 CvFLAGS(PL_compcv) |= flags;
7378 PL_comppad = newAV();
7379 av_push(PL_comppad, Nullsv);
7380 PL_curpad = AvARRAY(PL_comppad);
7381 PL_comppad_name = newAV();
7382 PL_comppad_name_fill = 0;
7383 PL_min_intro_pending = 0;
7385 PL_subline = CopLINE(PL_curcop);
7387 av_store(PL_comppad_name, 0, newSVpvn("@_", 2));
7388 PL_curpad[0] = (SV*)newAV();
7389 SvPADMY_on(PL_curpad[0]); /* XXX Needed? */
7390 #endif /* USE_THREADS */
7392 comppadlist = newAV();
7393 AvREAL_off(comppadlist);
7394 av_store(comppadlist, 0, (SV*)PL_comppad_name);
7395 av_store(comppadlist, 1, (SV*)PL_comppad);
7397 CvPADLIST(PL_compcv) = comppadlist;
7398 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv);
7400 CvOWNER(PL_compcv) = 0;
7401 New(666, CvMUTEXP(PL_compcv), 1, perl_mutex);
7402 MUTEX_INIT(CvMUTEXP(PL_compcv));
7403 #endif /* USE_THREADS */
7405 return oldsavestack_ix;
7409 #pragma segment Perl_yylex
7412 Perl_yywarn(pTHX_ char *s)
7414 PL_in_eval |= EVAL_WARNONLY;
7416 PL_in_eval &= ~EVAL_WARNONLY;
7421 Perl_yyerror(pTHX_ char *s)
7424 char *context = NULL;
7428 if (!yychar || (yychar == ';' && !PL_rsfp))
7430 else if (PL_bufptr > PL_oldoldbufptr && PL_bufptr - PL_oldoldbufptr < 200 &&
7431 PL_oldoldbufptr != PL_oldbufptr && PL_oldbufptr != PL_bufptr) {
7432 while (isSPACE(*PL_oldoldbufptr))
7434 context = PL_oldoldbufptr;
7435 contlen = PL_bufptr - PL_oldoldbufptr;
7437 else if (PL_bufptr > PL_oldbufptr && PL_bufptr - PL_oldbufptr < 200 &&
7438 PL_oldbufptr != PL_bufptr) {
7439 while (isSPACE(*PL_oldbufptr))
7441 context = PL_oldbufptr;
7442 contlen = PL_bufptr - PL_oldbufptr;
7444 else if (yychar > 255)
7445 where = "next token ???";
7446 #ifdef USE_PURE_BISON
7447 /* GNU Bison sets the value -2 */
7448 else if (yychar == -2) {
7450 else if ((yychar & 127) == 127) {
7452 if (PL_lex_state == LEX_NORMAL ||
7453 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
7454 where = "at end of line";
7455 else if (PL_lex_inpat)
7456 where = "within pattern";
7458 where = "within string";
7461 SV *where_sv = sv_2mortal(newSVpvn("next char ", 10));
7463 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
7464 else if (isPRINT_LC(yychar))
7465 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
7467 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
7468 where = SvPVX(where_sv);
7470 msg = sv_2mortal(newSVpv(s, 0));
7471 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
7472 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
7474 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
7476 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
7477 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
7478 Perl_sv_catpvf(aTHX_ msg,
7479 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
7480 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
7483 if (PL_in_eval & EVAL_WARNONLY)
7484 Perl_warn(aTHX_ "%"SVf, msg);
7487 if (PL_error_count >= 10) {
7488 if (PL_in_eval && SvCUR(ERRSV))
7489 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
7490 ERRSV, CopFILE(PL_curcop));
7492 Perl_croak(aTHX_ "%s has too many errors.\n",
7493 CopFILE(PL_curcop));
7496 PL_in_my_stash = Nullhv;
7500 #pragma segment Main
7504 S_swallow_bom(pTHX_ U8 *s)
7507 slen = SvCUR(PL_linestr);
7511 /* UTF-16 little-endian */
7512 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
7513 Perl_croak(aTHX_ "Unsupported script encoding");
7514 #ifndef PERL_NO_UTF16_FILTER
7515 DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-LE script encoding\n"));
7517 if (PL_bufend > (char*)s) {
7521 filter_add(utf16rev_textfilter, NULL);
7522 New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
7523 PL_bufend = (char*)utf16_to_utf8_reversed(s, news,
7524 PL_bufend - (char*)s - 1,
7526 Copy(news, s, newlen, U8);
7527 SvCUR_set(PL_linestr, newlen);
7528 PL_bufend = SvPVX(PL_linestr) + newlen;
7529 news[newlen++] = '\0';
7533 Perl_croak(aTHX_ "Unsupported script encoding");
7539 if (s[1] == 0xFF) { /* UTF-16 big-endian */
7540 #ifndef PERL_NO_UTF16_FILTER
7541 DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding\n"));
7543 if (PL_bufend > (char *)s) {
7547 filter_add(utf16_textfilter, NULL);
7548 New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
7549 PL_bufend = (char*)utf16_to_utf8(s, news,
7550 PL_bufend - (char*)s,
7552 Copy(news, s, newlen, U8);
7553 SvCUR_set(PL_linestr, newlen);
7554 PL_bufend = SvPVX(PL_linestr) + newlen;
7555 news[newlen++] = '\0';
7559 Perl_croak(aTHX_ "Unsupported script encoding");
7565 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
7566 DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-8 script encoding\n"));
7571 if (slen > 3 && s[1] == 0 && /* UTF-32 big-endian */
7572 s[2] == 0xFE && s[3] == 0xFF)
7574 Perl_croak(aTHX_ "Unsupported script encoding");
7586 * Restore a source filter.
7590 restore_rsfp(pTHXo_ void *f)
7592 PerlIO *fp = (PerlIO*)f;
7594 if (PL_rsfp == PerlIO_stdin())
7595 PerlIO_clearerr(PL_rsfp);
7596 else if (PL_rsfp && (PL_rsfp != fp))
7597 PerlIO_close(PL_rsfp);
7601 #ifndef PERL_NO_UTF16_FILTER
7603 utf16_textfilter(pTHXo_ int idx, SV *sv, int maxlen)
7605 I32 count = FILTER_READ(idx+1, sv, maxlen);
7610 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
7611 if (!*SvPV_nolen(sv))
7612 /* Game over, but don't feed an odd-length string to utf16_to_utf8 */
7615 tend = utf16_to_utf8((U8*)SvPVX(sv), tmps, SvCUR(sv), &newlen);
7616 sv_usepvn(sv, (char*)tmps, tend - tmps);
7622 utf16rev_textfilter(pTHXo_ int idx, SV *sv, int maxlen)
7624 I32 count = FILTER_READ(idx+1, sv, maxlen);
7629 if (!*SvPV_nolen(sv))
7630 /* Game over, but don't feed an odd-length string to utf16_to_utf8 */
7633 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
7634 tend = utf16_to_utf8_reversed((U8*)SvPVX(sv), tmps, SvCUR(sv), &newlen);
7635 sv_usepvn(sv, (char*)tmps, tend - tmps);