3 * Copyright (c) 1991-1997, 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
17 static void check_uni _((void));
18 static void force_next _((I32 type));
19 static char *force_version _((char *start));
20 static char *force_word _((char *start, int token, int check_keyword, int allow_pack, int allow_tick));
21 static SV *q _((SV *sv));
22 static char *scan_const _((char *start));
23 static char *scan_formline _((char *s));
24 static char *scan_heredoc _((char *s));
25 static char *scan_ident _((char *s, char *send, char *dest, STRLEN destlen,
27 static char *scan_inputsymbol _((char *start));
28 static char *scan_pat _((char *start));
29 static char *scan_str _((char *start));
30 static char *scan_subst _((char *start));
31 static char *scan_trans _((char *start));
32 static char *scan_word _((char *s, char *dest, STRLEN destlen,
33 int allow_package, STRLEN *slp));
34 static char *skipspace _((char *s));
35 static void checkcomma _((char *s, char *name, char *what));
36 static void force_ident _((char *s, int kind));
37 static void incline _((char *s));
38 static int intuit_method _((char *s, GV *gv));
39 static int intuit_more _((char *s));
40 static I32 lop _((I32 f, expectation x, char *s));
41 static void missingterm _((char *s));
42 static void no_op _((char *what, char *s));
43 static void set_csh _((void));
44 static I32 sublex_done _((void));
45 static I32 sublex_push _((void));
46 static I32 sublex_start _((void));
48 static int uni _((I32 f, char *s));
50 static char * filter_gets _((SV *sv, PerlIO *fp, STRLEN append));
51 static void restore_rsfp _((void *f));
52 static void restore_expect _((void *e));
53 static void restore_lex_expect _((void *e));
55 static char ident_too_long[] = "Identifier too long";
57 static char *linestart; /* beg. of most recently read line */
59 static char pending_ident; /* pending identifier lookup */
62 I32 super_state; /* lexer state to save */
63 I32 sub_inwhat; /* "lex_inwhat" to use */
64 OP *sub_op; /* "lex_op" to use */
67 /* The following are arranged oddly so that the guard on the switch statement
68 * can get by with a single comparison (if the compiler is smart enough).
71 /* #define LEX_NOTPARSING 11 is done in perl.h. */
74 #define LEX_INTERPNORMAL 9
75 #define LEX_INTERPCASEMOD 8
76 #define LEX_INTERPPUSH 7
77 #define LEX_INTERPSTART 6
78 #define LEX_INTERPEND 5
79 #define LEX_INTERPENDMAYBE 4
80 #define LEX_INTERPCONCAT 3
81 #define LEX_INTERPCONST 2
82 #define LEX_FORMLINE 1
83 #define LEX_KNOWNEXT 0
92 /* XXX If this causes problems, set i_unistd=undef in the hint file. */
94 # include <unistd.h> /* Needed for execv() */
102 #include "keywords.h"
107 #define CLINE (copline = (curcop->cop_line < copline ? curcop->cop_line : copline))
109 #define TOKEN(retval) return (bufptr = s,(int)retval)
110 #define OPERATOR(retval) return (expect = XTERM,bufptr = s,(int)retval)
111 #define AOPERATOR(retval) return ao((expect = XTERM,bufptr = s,(int)retval))
112 #define PREBLOCK(retval) return (expect = XBLOCK,bufptr = s,(int)retval)
113 #define PRETERMBLOCK(retval) return (expect = XTERMBLOCK,bufptr = s,(int)retval)
114 #define PREREF(retval) return (expect = XREF,bufptr = s,(int)retval)
115 #define TERM(retval) return (CLINE, expect = XOPERATOR,bufptr = s,(int)retval)
116 #define LOOPX(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)LOOPEX)
117 #define FTST(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)UNIOP)
118 #define FUN0(f) return(yylval.ival = f,expect = XOPERATOR,bufptr = s,(int)FUNC0)
119 #define FUN1(f) return(yylval.ival = f,expect = XOPERATOR,bufptr = s,(int)FUNC1)
120 #define BOop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)BITOROP))
121 #define BAop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)BITANDOP))
122 #define SHop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)SHIFTOP))
123 #define PWop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)POWOP))
124 #define PMop(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)MATCHOP)
125 #define Aop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)ADDOP))
126 #define Mop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)MULOP))
127 #define Eop(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)EQOP)
128 #define Rop(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)RELOP)
130 /* This bit of chicanery makes a unary function followed by
131 * a parenthesis into a function with one argument, highest precedence.
133 #define UNI(f) return(yylval.ival = f, \
136 last_uni = oldbufptr, \
138 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
140 #define UNIBRACK(f) return(yylval.ival = f, \
142 last_uni = oldbufptr, \
143 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
145 /* grandfather return to old style */
146 #define OLDLOP(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)LSTOP)
151 if (*bufptr == '=') {
153 if (toketype == ANDAND)
154 yylval.ival = OP_ANDASSIGN;
155 else if (toketype == OROR)
156 yylval.ival = OP_ORASSIGN;
163 no_op(char *what, char *s)
165 char *oldbp = bufptr;
166 bool is_first = (oldbufptr == linestart);
169 yywarn(form("%s found where operator expected", what));
171 warn("\t(Missing semicolon on previous line?)\n");
172 else if (oldoldbufptr && isIDFIRST(*oldoldbufptr)) {
174 for (t = oldoldbufptr; *t && (isALNUM(*t) || *t == ':'); t++) ;
175 if (t < bufptr && isSPACE(*t))
176 warn("\t(Do you need to predeclare %.*s?)\n",
177 t - oldoldbufptr, oldoldbufptr);
181 warn("\t(Missing operator before %.*s?)\n", s - oldbp, oldbp);
191 char *nl = strrchr(s,'\n');
195 else if (multi_close < 32 || multi_close == 127) {
197 tmpbuf[1] = toCTRL(multi_close);
203 *tmpbuf = multi_close;
207 q = strchr(s,'"') ? '\'' : '"';
208 croak("Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
215 warn("Use of %s is deprecated", s);
221 deprecate("comma-less variable list");
227 win32_textfilter(int idx, SV *sv, int maxlen)
229 I32 count = FILTER_READ(idx+1, sv, maxlen);
230 if (count > 0 && !maxlen)
231 win32_strip_return(sv);
245 SAVEI32(lex_brackets);
246 SAVEI32(lex_fakebrack);
247 SAVEI32(lex_casemods);
252 SAVEI16(curcop->cop_line);
256 SAVEPPTR(oldoldbufptr);
259 SAVEPPTR(lex_brackstack);
260 SAVEPPTR(lex_casestack);
261 SAVEDESTRUCTOR(restore_rsfp, rsfp);
265 SAVEDESTRUCTOR(restore_expect, tokenbuf + expect); /* encode as pointer */
266 SAVEDESTRUCTOR(restore_lex_expect, tokenbuf + expect);
268 lex_state = LEX_NORMAL;
273 New(899, lex_brackstack, 120, char);
274 New(899, lex_casestack, 12, char);
275 SAVEFREEPV(lex_brackstack);
276 SAVEFREEPV(lex_casestack);
278 *lex_casestack = '\0';
286 if (SvREADONLY(linestr))
287 linestr = sv_2mortal(newSVsv(linestr));
288 s = SvPV(linestr, len);
289 if (len && s[len-1] != ';') {
290 if (!(SvFLAGS(linestr) & SVs_TEMP))
291 linestr = sv_2mortal(newSVsv(linestr));
292 sv_catpvn(linestr, "\n;", 2);
295 oldoldbufptr = oldbufptr = bufptr = linestart = SvPVX(linestr);
296 bufend = bufptr + SvCUR(linestr);
298 rs = newSVpv("\n", 1);
309 restore_rsfp(void *f)
311 PerlIO *fp = (PerlIO*)f;
313 if (rsfp == PerlIO_stdin())
314 PerlIO_clearerr(rsfp);
315 else if (rsfp && (rsfp != fp))
321 restore_expect(void *e)
323 /* a safe way to store a small integer in a pointer */
324 expect = (expectation)((char *)e - tokenbuf);
328 restore_lex_expect(void *e)
330 /* a safe way to store a small integer in a pointer */
331 lex_expect = (expectation)((char *)e - tokenbuf);
346 while (*s == ' ' || *s == '\t') s++;
347 if (strnEQ(s, "line ", 5)) {
356 while (*s == ' ' || *s == '\t')
358 if (*s == '"' && (t = strchr(s+1, '"')))
362 return; /* false alarm */
363 for (t = s; !isSPACE(*t); t++) ;
368 curcop->cop_filegv = gv_fetchfile(s);
370 curcop->cop_filegv = gv_fetchfile(origfilename);
372 curcop->cop_line = atoi(n)-1;
376 skipspace(register char *s)
379 if (lex_formbrack && lex_brackets <= lex_formbrack) {
380 while (s < bufend && (*s == ' ' || *s == '\t'))
386 while (s < bufend && isSPACE(*s))
388 if (s < bufend && *s == '#') {
389 while (s < bufend && *s != '\n')
394 if (s < bufend || !rsfp || lex_state != LEX_NORMAL)
396 if ((s = filter_gets(linestr, rsfp, (prevlen = SvCUR(linestr)))) == Nullch) {
397 if (minus_n || minus_p) {
398 sv_setpv(linestr,minus_p ?
399 ";}continue{print or die qq(-p destination: $!\\n)" :
401 sv_catpv(linestr,";}");
402 minus_n = minus_p = 0;
405 sv_setpv(linestr,";");
406 oldoldbufptr = oldbufptr = bufptr = s = linestart = SvPVX(linestr);
407 bufend = SvPVX(linestr) + SvCUR(linestr);
408 if (preprocess && !in_eval)
409 (void)PerlProc_pclose(rsfp);
410 else if ((PerlIO*)rsfp == PerlIO_stdin())
411 PerlIO_clearerr(rsfp);
413 (void)PerlIO_close(rsfp);
417 linestart = bufptr = s + prevlen;
418 bufend = s + SvCUR(linestr);
421 if (PERLDB_LINE && curstash != debstash) {
422 SV *sv = NEWSV(85,0);
424 sv_upgrade(sv, SVt_PVMG);
425 sv_setpvn(sv,bufptr,bufend-bufptr);
426 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
437 if (oldoldbufptr != last_uni)
439 while (isSPACE(*last_uni))
441 for (s = last_uni; isALNUM(*s) || *s == '-'; s++) ;
442 if ((t = strchr(s, '(')) && t < bufptr)
446 warn("Warning: Use of \"%s\" without parens is ambiguous", last_uni);
453 #define UNI(f) return uni(f,s)
461 last_uni = oldbufptr;
472 #endif /* CRIPPLED_CC */
474 #define LOP(f,x) return lop(f,x,s)
477 lop(I32 f, expectation x, char *s)
484 last_lop = oldbufptr;
500 nexttype[nexttoke] = type;
502 if (lex_state != LEX_KNOWNEXT) {
503 lex_defer = lex_state;
505 lex_state = LEX_KNOWNEXT;
510 force_word(register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
515 start = skipspace(start);
518 (allow_pack && *s == ':') ||
519 (allow_initial_tick && *s == '\'') )
521 s = scan_word(s, tokenbuf, sizeof tokenbuf, allow_pack, &len);
522 if (check_keyword && keyword(tokenbuf, len))
524 if (token == METHOD) {
534 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST,0, newSVpv(tokenbuf,0));
535 nextval[nexttoke].opval->op_private |= OPpCONST_BARE;
542 force_ident(register char *s, int kind)
545 OP* o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
546 nextval[nexttoke].opval = o;
549 dTHR; /* just for in_eval */
550 o->op_private = OPpCONST_ENTERED;
551 /* XXX see note in pp_entereval() for why we forgo typo
552 warnings if the symbol must be introduced in an eval.
554 gv_fetchpv(s, in_eval ? (GV_ADDMULTI | 8) : TRUE,
555 kind == '$' ? SVt_PV :
556 kind == '@' ? SVt_PVAV :
557 kind == '%' ? SVt_PVHV :
565 force_version(char *s)
567 OP *version = Nullop;
571 /* default VERSION number -- GBARR */
576 for( d=s, c = 1; isDIGIT(*d) || *d == '_' || (*d == '.' && c--); d++);
577 if((*d == ';' || isSPACE(*d)) && *(skipspace(d)) != ',') {
579 /* real VERSION number -- GBARR */
580 version = yylval.opval;
584 /* NOTE: The parser sees the package name and the VERSION swapped */
585 nextval[nexttoke].opval = version;
602 s = SvPV_force(sv, len);
606 while (s < send && *s != '\\')
613 if (s + 1 < send && (s[1] == '\\'))
614 s++; /* all that, just for this */
619 SvCUR_set(sv, d - SvPVX(sv));
627 register I32 op_type = yylval.ival;
629 if (op_type == OP_NULL) {
630 yylval.opval = lex_op;
634 if (op_type == OP_CONST || op_type == OP_READLINE) {
635 SV *sv = q(lex_stuff);
637 char *p = SvPV(sv, len);
638 yylval.opval = (OP*)newSVOP(op_type, 0, newSVpv(p, len));
644 sublex_info.super_state = lex_state;
645 sublex_info.sub_inwhat = op_type;
646 sublex_info.sub_op = lex_op;
647 lex_state = LEX_INTERPPUSH;
651 yylval.opval = lex_op;
665 lex_state = sublex_info.super_state;
667 SAVEI32(lex_brackets);
668 SAVEI32(lex_fakebrack);
669 SAVEI32(lex_casemods);
674 SAVEI16(curcop->cop_line);
677 SAVEPPTR(oldoldbufptr);
680 SAVEPPTR(lex_brackstack);
681 SAVEPPTR(lex_casestack);
686 bufend = bufptr = oldbufptr = oldoldbufptr = linestart = SvPVX(linestr);
687 bufend += SvCUR(linestr);
693 New(899, lex_brackstack, 120, char);
694 New(899, lex_casestack, 12, char);
695 SAVEFREEPV(lex_brackstack);
696 SAVEFREEPV(lex_casestack);
698 *lex_casestack = '\0';
700 lex_state = LEX_INTERPCONCAT;
701 curcop->cop_line = multi_start;
703 lex_inwhat = sublex_info.sub_inwhat;
704 if (lex_inwhat == OP_MATCH || lex_inwhat == OP_SUBST)
705 lex_inpat = sublex_info.sub_op;
717 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv("",0));
721 if (lex_casemods) { /* oops, we've got some unbalanced parens */
722 lex_state = LEX_INTERPCASEMOD;
726 /* Is there a right-hand side to take care of? */
727 if (lex_repl && (lex_inwhat == OP_SUBST || lex_inwhat == OP_TRANS)) {
730 bufend = bufptr = oldbufptr = oldoldbufptr = linestart = SvPVX(linestr);
731 bufend += SvCUR(linestr);
737 *lex_casestack = '\0';
739 if (SvCOMPILED(lex_repl)) {
740 lex_state = LEX_INTERPNORMAL;
744 lex_state = LEX_INTERPCONCAT;
750 bufend = SvPVX(linestr);
751 bufend += SvCUR(linestr);
760 Extracts a pattern, double-quoted string, or transliteration. This
763 It looks at lex_inwhat and lex_inpat to find out whether it's
764 processing a pattern (lex_inpat is true), a transliteration
765 (lex_inwhat & OP_TRANS is true), or a double-quoted string.
767 Returns a pointer to the character scanned up to. Iff this is
768 advanced from the start pointer supplied (ie if anything was
769 successfully parsed), will leave an OP for the substring scanned
770 in yylval. Caller must intuit reason for not parsing further
771 by looking at the next characters herself.
775 double-quoted style: \r and \n
776 regexp special ones: \D \s
778 backrefs: \1 (deprecated in substitution replacements)
779 case and quoting: \U \Q \E
780 stops on @ and $, but not for $ as tail anchor
783 characters are VERY literal, except for - not at the start or end
784 of the string, which indicates a range. scan_const expands the
785 range to the full set of intermediate characters.
787 In double-quoted strings:
789 double-quoted style: \r and \n
791 backrefs: \1 (deprecated)
792 case and quoting: \U \Q \E
795 scan_const does *not* construct ops to handle interpolated strings.
796 It stops processing as soon as it finds an embedded $ or @ variable
797 and leaves it to the caller to work out what's going on.
799 @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @:foo.
801 $ in pattern could be $foo or could be tail anchor. Assumption:
802 it's a tail anchor if $ is the last thing in the string, or if it's
803 followed by one of ")| \n\t"
805 \1 (backreferences) are turned into $1
807 The structure of the code is
808 while (there's a character to process) {
809 handle transliteration ranges
811 skip # initiated comments in //x patterns
812 check for embedded @foo
813 check for embedded scalars
815 leave intact backslashes from leave (below)
816 deprecate \1 in strings and sub replacements
817 handle string-changing backslashes \l \U \Q \E, etc.
818 switch (what was escaped) {
819 handle - in a transliteration (becomes a literal -)
820 handle \132 octal characters
821 handle 0x15 hex characters
822 handle \cV (control V)
823 handle printf backslashes (\f, \r, \n, etc)
826 } (end while character to read)
831 scan_const(char *start)
833 register char *send = bufend; /* end of the constant */
834 SV *sv = NEWSV(93, send - start); /* sv for the constant */
835 register char *s = start; /* start of the constant */
836 register char *d = SvPVX(sv); /* destination for copies */
837 bool dorange = FALSE; /* are we in a translit range? */
840 /* leaveit is the set of acceptably-backslashed characters */
843 ? "\\.^$@AGZdDwWsSbB+*?|()-nrtfeaxc0123456789[{]} \t\n\r\f\v#"
846 while (s < send || dorange) {
847 /* get transliterations out of the way (they're most literal) */
848 if (lex_inwhat == OP_TRANS) {
849 /* expand a range A-Z to the full set of characters. AIE! */
851 I32 i; /* current expanded character */
852 I32 max; /* last character in range */
854 i = d - SvPVX(sv); /* remember current offset */
855 SvGROW(sv, SvLEN(sv) + 256); /* expand the sv -- there'll never be more'n 256 chars in a range for it to grow by */
856 d = SvPVX(sv) + i; /* restore d after the grow potentially has changed the ptr */
857 d -= 2; /* eat the first char and the - */
859 max = (U8)d[1]; /* last char in range */
861 for (i = (U8)*d; i <= max; i++)
864 /* mark the range as done, and continue */
869 /* range begins (ignore - as first or last char) */
870 else if (*s == '-' && s+1 < send && s != start) {
876 /* if we get here, we're not doing a transliteration */
878 /* skip for regexp comments /(?#comment)/ */
879 else if (*s == '(' && lex_inpat && s[1] == '?') {
881 while (s < send && *s != ')')
883 } else if (s[2] == '{') { /* This should march regcomp.c */
885 char *regparse = s + 3;
888 while (count && (c = *regparse)) {
889 if (c == '\\' && regparse[1])
897 if (*regparse == ')')
900 yyerror("Sequence (?{...}) not terminated or not {}-balanced");
901 while (s < regparse && *s != ')')
906 /* likewise skip #-initiated comments in //x patterns */
907 else if (*s == '#' && lex_inpat &&
908 ((PMOP*)lex_inpat)->op_pmflags & PMf_EXTENDED) {
909 while (s+1 < send && *s != '\n')
913 /* check for embedded arrays (@foo, @:foo, @'foo, @{foo}, @$foo) */
914 else if (*s == '@' && s[1] && (isALNUM(s[1]) || strchr(":'{$", s[1])))
917 /* check for embedded scalars. only stop if we're sure it's a
920 else if (*s == '$') {
921 if (!lex_inpat) /* not a regexp, so $ must be var */
923 if (s + 1 < send && !strchr("()| \n\t", s[1]))
924 break; /* in regexp, $ might be tail anchor */
928 if (*s == '\\' && s+1 < send) {
931 /* some backslashes we leave behind */
932 if (*s && strchr(leaveit, *s)) {
938 /* deprecate \1 in strings and substitution replacements */
939 if (lex_inwhat == OP_SUBST && !lex_inpat &&
940 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
943 warn("\\%c better written as $%c", *s, *s);
948 /* string-change backslash escapes */
949 if (lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
954 /* if we get here, it's either a quoted -, or a digit */
957 /* quoted - in transliterations */
959 if (lex_inwhat == OP_TRANS) {
964 /* default action is to copy the quoted character */
969 /* \132 indicates an octal constant */
970 case '0': case '1': case '2': case '3':
971 case '4': case '5': case '6': case '7':
972 *d++ = scan_oct(s, 3, &len);
976 /* \x24 indicates a hex constant */
978 *d++ = scan_hex(++s, 2, &len);
982 /* \c is a control character */
989 /* printf-style backslashes, formfeeds, newlines, etc */
1015 } /* end if (backslash) */
1018 } /* while loop to process each character */
1020 /* terminate the string and set up the sv */
1022 SvCUR_set(sv, d - SvPVX(sv));
1025 /* shrink the sv if we allocated more than we used */
1026 if (SvCUR(sv) + 5 < SvLEN(sv)) {
1027 SvLEN_set(sv, SvCUR(sv) + 1);
1028 Renew(SvPVX(sv), SvLEN(sv), char);
1031 /* return the substring (via yylval) only if we parsed anything */
1033 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1039 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
1041 intuit_more(register char *s)
1045 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
1047 if (*s != '{' && *s != '[')
1052 /* In a pattern, so maybe we have {n,m}. */
1069 /* On the other hand, maybe we have a character class */
1072 if (*s == ']' || *s == '^')
1075 int weight = 2; /* let's weigh the evidence */
1077 unsigned char un_char = 255, last_un_char;
1078 char *send = strchr(s,']');
1079 char tmpbuf[sizeof tokenbuf * 4];
1081 if (!send) /* has to be an expression */
1084 Zero(seen,256,char);
1087 else if (isDIGIT(*s)) {
1089 if (isDIGIT(s[1]) && s[2] == ']')
1095 for (; s < send; s++) {
1096 last_un_char = un_char;
1097 un_char = (unsigned char)*s;
1102 weight -= seen[un_char] * 10;
1103 if (isALNUM(s[1])) {
1104 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
1105 if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV))
1110 else if (*s == '$' && s[1] &&
1111 strchr("[#!%*<>()-=",s[1])) {
1112 if (/*{*/ strchr("])} =",s[2]))
1121 if (strchr("wds]",s[1]))
1123 else if (seen['\''] || seen['"'])
1125 else if (strchr("rnftbxcav",s[1]))
1127 else if (isDIGIT(s[1])) {
1129 while (s[1] && isDIGIT(s[1]))
1139 if (strchr("aA01! ",last_un_char))
1141 if (strchr("zZ79~",s[1]))
1143 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
1144 weight -= 5; /* cope with negative subscript */
1147 if (!isALNUM(last_un_char) && !strchr("$@&",last_un_char) &&
1148 isALPHA(*s) && s[1] && isALPHA(s[1])) {
1153 if (keyword(tmpbuf, d - tmpbuf))
1156 if (un_char == last_un_char + 1)
1158 weight -= seen[un_char];
1163 if (weight >= 0) /* probably a character class */
1171 intuit_method(char *start, GV *gv)
1173 char *s = start + (*start == '$');
1174 char tmpbuf[sizeof tokenbuf];
1182 if ((cv = GvCVu(gv))) {
1183 char *proto = SvPVX(cv);
1193 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
1194 if (*start == '$') {
1195 if (gv || last_lop_op == OP_PRINT || isUPPER(*tokenbuf))
1200 return *s == '(' ? FUNCMETH : METHOD;
1202 if (!keyword(tmpbuf, len)) {
1203 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
1208 indirgv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
1209 if (indirgv && GvCVu(indirgv))
1211 /* filehandle or package name makes it a method */
1212 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
1214 if ((bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
1215 return 0; /* no assumptions -- "=>" quotes bearword */
1217 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0,
1219 nextval[nexttoke].opval->op_private = OPpCONST_BARE;
1223 return *s == '(' ? FUNCMETH : METHOD;
1233 char *pdb = PerlEnv_getenv("PERL5DB");
1237 SETERRNO(0,SS$_NORMAL);
1238 return "BEGIN { require 'perl5db.pl' }";
1244 /* Encoded script support. filter_add() effectively inserts a
1245 * 'pre-processing' function into the current source input stream.
1246 * Note that the filter function only applies to the current source file
1247 * (e.g., it will not affect files 'require'd or 'use'd by this one).
1249 * The datasv parameter (which may be NULL) can be used to pass
1250 * private data to this instance of the filter. The filter function
1251 * can recover the SV using the FILTER_DATA macro and use it to
1252 * store private buffers and state information.
1254 * The supplied datasv parameter is upgraded to a PVIO type
1255 * and the IoDIRP field is used to store the function pointer.
1256 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
1257 * private use must be set using malloc'd pointers.
1259 static int filter_debug = 0;
1262 filter_add(filter_t funcp, SV *datasv)
1264 if (!funcp){ /* temporary handy debugging hack to be deleted */
1265 filter_debug = atoi((char*)datasv);
1269 rsfp_filters = newAV();
1271 datasv = NEWSV(255,0);
1272 if (!SvUPGRADE(datasv, SVt_PVIO))
1273 die("Can't upgrade filter_add data to SVt_PVIO");
1274 IoDIRP(datasv) = (DIR*)funcp; /* stash funcp into spare field */
1276 warn("filter_add func %p (%s)", funcp, SvPV(datasv,na));
1277 av_unshift(rsfp_filters, 1);
1278 av_store(rsfp_filters, 0, datasv) ;
1283 /* Delete most recently added instance of this filter function. */
1285 filter_del(filter_t funcp)
1288 warn("filter_del func %p", funcp);
1289 if (!rsfp_filters || AvFILLp(rsfp_filters)<0)
1291 /* if filter is on top of stack (usual case) just pop it off */
1292 if (IoDIRP(FILTER_DATA(AvFILLp(rsfp_filters))) == (void*)funcp){
1293 sv_free(av_pop(rsfp_filters));
1297 /* we need to search for the correct entry and clear it */
1298 die("filter_del can only delete in reverse order (currently)");
1302 /* Invoke the n'th filter function for the current rsfp. */
1304 filter_read(int idx, SV *buf_sv, int maxlen)
1307 /* 0 = read one text line */
1314 if (idx > AvFILLp(rsfp_filters)){ /* Any more filters? */
1315 /* Provide a default input filter to make life easy. */
1316 /* Note that we append to the line. This is handy. */
1318 warn("filter_read %d: from rsfp\n", idx);
1322 int old_len = SvCUR(buf_sv) ;
1324 /* ensure buf_sv is large enough */
1325 SvGROW(buf_sv, old_len + maxlen) ;
1326 if ((len = PerlIO_read(rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
1327 if (PerlIO_error(rsfp))
1328 return -1; /* error */
1330 return 0 ; /* end of file */
1332 SvCUR_set(buf_sv, old_len + len) ;
1335 if (sv_gets(buf_sv, rsfp, SvCUR(buf_sv)) == NULL) {
1336 if (PerlIO_error(rsfp))
1337 return -1; /* error */
1339 return 0 ; /* end of file */
1342 return SvCUR(buf_sv);
1344 /* Skip this filter slot if filter has been deleted */
1345 if ( (datasv = FILTER_DATA(idx)) == &sv_undef){
1347 warn("filter_read %d: skipped (filter deleted)\n", idx);
1348 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
1350 /* Get function pointer hidden within datasv */
1351 funcp = (filter_t)IoDIRP(datasv);
1353 warn("filter_read %d: via function %p (%s)\n",
1354 idx, funcp, SvPV(datasv,na));
1355 /* Call function. The function is expected to */
1356 /* call "FILTER_READ(idx+1, buf_sv)" first. */
1357 /* Return: <0:error, =0:eof, >0:not eof */
1358 return (*funcp)(idx, buf_sv, maxlen);
1362 filter_gets(register SV *sv, register PerlIO *fp, STRLEN append)
1365 if (!rsfp_filters) {
1366 filter_add(win32_textfilter,NULL);
1372 SvCUR_set(sv, 0); /* start with empty line */
1373 if (FILTER_READ(0, sv, 0) > 0)
1374 return ( SvPVX(sv) ) ;
1379 return (sv_gets(sv, fp, append));
1384 static char* exp_name[] =
1385 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "TERMBLOCK" };
1388 EXT int yychar; /* last token */
1393 Works out what to call the token just pulled out of the input
1394 stream. The yacc parser takes care of taking the ops we return and
1395 stitching them into a tree.
1401 if read an identifier
1402 if we're in a my declaration
1403 croak if they tried to say my($foo::bar)
1404 build the ops for a my() declaration
1405 if it's an access to a my() variable
1406 are we in a sort block?
1407 croak if my($a); $a <=> $b
1408 build ops for access to a my() variable
1409 if in a dq string, and they've said @foo and we can't find @foo
1411 build ops for a bareword
1412 if we already built the token before, use it.
1426 /* check if there's an identifier for us to look at */
1427 if (pending_ident) {
1428 /* pit holds the identifier we read and pending_ident is reset */
1429 char pit = pending_ident;
1432 /* if we're in a my(), we can't allow dynamics here.
1433 $foo'bar has already been turned into $foo::bar, so
1434 just check for colons.
1436 if it's a legal name, the OP is a PADANY.
1439 if (strchr(tokenbuf,':'))
1440 croak(no_myglob,tokenbuf);
1442 yylval.opval = newOP(OP_PADANY, 0);
1443 yylval.opval->op_targ = pad_allocmy(tokenbuf);
1448 build the ops for accesses to a my() variable.
1450 Deny my($a) or my($b) in a sort block, *if* $a or $b is
1451 then used in a comparison. This catches most, but not
1452 all cases. For instance, it catches
1453 sort { my($a); $a <=> $b }
1455 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
1456 (although why you'd do that is anyone's guess).
1459 if (!strchr(tokenbuf,':')) {
1461 /* Check for single character per-thread SVs */
1462 if (tokenbuf[0] == '$' && tokenbuf[2] == '\0'
1463 && !isALPHA(tokenbuf[1]) /* Rule out obvious non-threadsvs */
1464 && (tmp = find_threadsv(&tokenbuf[1])) != NOT_IN_PAD)
1466 yylval.opval = newOP(OP_THREADSV, 0);
1467 yylval.opval->op_targ = tmp;
1470 #endif /* USE_THREADS */
1471 if ((tmp = pad_findmy(tokenbuf)) != NOT_IN_PAD) {
1472 /* if it's a sort block and they're naming $a or $b */
1473 if (last_lop_op == OP_SORT &&
1474 tokenbuf[0] == '$' &&
1475 (tokenbuf[1] == 'a' || tokenbuf[1] == 'b')
1478 for (d = in_eval ? oldoldbufptr : linestart;
1479 d < bufend && *d != '\n';
1482 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
1483 croak("Can't use \"my %s\" in sort comparison",
1489 yylval.opval = newOP(OP_PADANY, 0);
1490 yylval.opval->op_targ = tmp;
1496 Whine if they've said @foo in a doublequoted string,
1497 and @foo isn't a variable we can find in the symbol
1500 if (pit == '@' && lex_state != LEX_NORMAL && !lex_brackets) {
1501 GV *gv = gv_fetchpv(tokenbuf+1, FALSE, SVt_PVAV);
1502 if (!gv || ((tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
1503 yyerror(form("In string, %s now must be written as \\%s",
1504 tokenbuf, tokenbuf));
1507 /* build ops for a bareword */
1508 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf+1, 0));
1509 yylval.opval->op_private = OPpCONST_ENTERED;
1510 gv_fetchpv(tokenbuf+1, in_eval ? (GV_ADDMULTI | 8) : TRUE,
1511 ((tokenbuf[0] == '$') ? SVt_PV
1512 : (tokenbuf[0] == '@') ? SVt_PVAV
1517 /* no identifier pending identification */
1519 switch (lex_state) {
1521 case LEX_NORMAL: /* Some compilers will produce faster */
1522 case LEX_INTERPNORMAL: /* code if we comment these out. */
1526 /* when we're already built the next token, just pull it out the queue */
1529 yylval = nextval[nexttoke];
1531 lex_state = lex_defer;
1532 expect = lex_expect;
1533 lex_defer = LEX_NORMAL;
1535 return(nexttype[nexttoke]);
1537 /* interpolated case modifiers like \L \U, including \Q and \E.
1538 when we get here, bufptr is at the \
1540 case LEX_INTERPCASEMOD:
1542 if (bufptr != bufend && *bufptr != '\\')
1543 croak("panic: INTERPCASEMOD");
1545 /* handle \E or end of string */
1546 if (bufptr == bufend || bufptr[1] == 'E') {
1551 oldmod = lex_casestack[--lex_casemods];
1552 lex_casestack[lex_casemods] = '\0';
1554 if (bufptr != bufend && strchr("LUQ", oldmod)) {
1556 lex_state = LEX_INTERPCONCAT;
1560 if (bufptr != bufend)
1562 lex_state = LEX_INTERPCONCAT;
1567 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
1568 tmp = *s, *s = s[2], s[2] = tmp; /* misordered... */
1569 if (strchr("LU", *s) &&
1570 (strchr(lex_casestack, 'L') || strchr(lex_casestack, 'U')))
1572 lex_casestack[--lex_casemods] = '\0';
1575 if (lex_casemods > 10) {
1576 char* newlb = Renew(lex_casestack, lex_casemods + 2, char);
1577 if (newlb != lex_casestack) {
1579 lex_casestack = newlb;
1582 lex_casestack[lex_casemods++] = *s;
1583 lex_casestack[lex_casemods] = '\0';
1584 lex_state = LEX_INTERPCONCAT;
1585 nextval[nexttoke].ival = 0;
1588 nextval[nexttoke].ival = OP_LCFIRST;
1590 nextval[nexttoke].ival = OP_UCFIRST;
1592 nextval[nexttoke].ival = OP_LC;
1594 nextval[nexttoke].ival = OP_UC;
1596 nextval[nexttoke].ival = OP_QUOTEMETA;
1598 croak("panic: yylex");
1610 case LEX_INTERPPUSH:
1611 return sublex_push();
1613 case LEX_INTERPSTART:
1614 if (bufptr == bufend)
1615 return sublex_done();
1617 lex_dojoin = (*bufptr == '@');
1618 lex_state = LEX_INTERPNORMAL;
1620 nextval[nexttoke].ival = 0;
1623 nextval[nexttoke].opval = newOP(OP_THREADSV, 0);
1624 nextval[nexttoke].opval->op_targ = find_threadsv("\"");
1625 force_next(PRIVATEREF);
1627 force_ident("\"", '$');
1628 #endif /* USE_THREADS */
1629 nextval[nexttoke].ival = 0;
1631 nextval[nexttoke].ival = 0;
1633 nextval[nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
1642 case LEX_INTERPENDMAYBE:
1643 if (intuit_more(bufptr)) {
1644 lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
1652 lex_state = LEX_INTERPCONCAT;
1656 case LEX_INTERPCONCAT:
1659 croak("panic: INTERPCONCAT");
1661 if (bufptr == bufend)
1662 return sublex_done();
1664 if (SvIVX(linestr) == '\'') {
1665 SV *sv = newSVsv(linestr);
1668 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1672 s = scan_const(bufptr);
1674 lex_state = LEX_INTERPCASEMOD;
1676 lex_state = LEX_INTERPSTART;
1680 nextval[nexttoke] = yylval;
1693 lex_state = LEX_NORMAL;
1694 s = scan_formline(bufptr);
1701 oldoldbufptr = oldbufptr;
1704 PerlIO_printf(PerlIO_stderr(), "### Tokener expecting %s at %s\n", exp_name[expect], s);
1710 croak("Unrecognized character \\%03o", *s & 255);
1713 goto fake_eof; /* emulate EOF on ^D or ^Z */
1719 yyerror("Missing right bracket");
1723 goto retry; /* ignore stray nulls */
1726 if (!in_eval && !preambled) {
1728 sv_setpv(linestr,incl_perldb());
1730 sv_catpv(linestr,";");
1732 while(AvFILLp(preambleav) >= 0) {
1733 SV *tmpsv = av_shift(preambleav);
1734 sv_catsv(linestr, tmpsv);
1735 sv_catpv(linestr, ";");
1738 sv_free((SV*)preambleav);
1741 if (minus_n || minus_p) {
1742 sv_catpv(linestr, "LINE: while (<>) {");
1744 sv_catpv(linestr,"chomp;");
1746 GV* gv = gv_fetchpv("::F", TRUE, SVt_PVAV);
1748 GvIMPORTED_AV_on(gv);
1750 if (strchr("/'\"", *splitstr)
1751 && strchr(splitstr + 1, *splitstr))
1752 sv_catpvf(linestr, "@F=split(%s);", splitstr);
1755 s = "'~#\200\1'"; /* surely one char is unused...*/
1756 while (s[1] && strchr(splitstr, *s)) s++;
1758 sv_catpvf(linestr, "@F=split(%s%c",
1759 "q" + (delim == '\''), delim);
1760 for (s = splitstr; *s; s++) {
1762 sv_catpvn(linestr, "\\", 1);
1763 sv_catpvn(linestr, s, 1);
1765 sv_catpvf(linestr, "%c);", delim);
1769 sv_catpv(linestr,"@F=split(' ');");
1772 sv_catpv(linestr, "\n");
1773 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
1774 bufend = SvPVX(linestr) + SvCUR(linestr);
1775 if (PERLDB_LINE && curstash != debstash) {
1776 SV *sv = NEWSV(85,0);
1778 sv_upgrade(sv, SVt_PVMG);
1779 sv_setsv(sv,linestr);
1780 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
1785 if ((s = filter_gets(linestr, rsfp, 0)) == Nullch) {
1788 if (preprocess && !in_eval)
1789 (void)PerlProc_pclose(rsfp);
1790 else if ((PerlIO *)rsfp == PerlIO_stdin())
1791 PerlIO_clearerr(rsfp);
1793 (void)PerlIO_close(rsfp);
1796 if (!in_eval && (minus_n || minus_p)) {
1797 sv_setpv(linestr,minus_p ? ";}continue{print" : "");
1798 sv_catpv(linestr,";}");
1799 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
1800 bufend = SvPVX(linestr) + SvCUR(linestr);
1801 minus_n = minus_p = 0;
1804 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
1805 sv_setpv(linestr,"");
1806 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
1809 if (*s == '#' && s[1] == '!' && instr(s,"perl"))
1812 /* Incest with pod. */
1813 if (*s == '=' && strnEQ(s, "=cut", 4)) {
1814 sv_setpv(linestr, "");
1815 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
1816 bufend = SvPVX(linestr) + SvCUR(linestr);
1821 } while (doextract);
1822 oldoldbufptr = oldbufptr = bufptr = linestart = s;
1823 if (PERLDB_LINE && curstash != debstash) {
1824 SV *sv = NEWSV(85,0);
1826 sv_upgrade(sv, SVt_PVMG);
1827 sv_setsv(sv,linestr);
1828 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
1830 bufend = SvPVX(linestr) + SvCUR(linestr);
1831 if (curcop->cop_line == 1) {
1832 while (s < bufend && isSPACE(*s))
1834 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
1838 if (*s == '#' && *(s+1) == '!')
1840 #ifdef ALTERNATE_SHEBANG
1842 static char as[] = ALTERNATE_SHEBANG;
1843 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
1844 d = s + (sizeof(as) - 1);
1846 #endif /* ALTERNATE_SHEBANG */
1855 while (*d && !isSPACE(*d))
1859 #ifdef ARG_ZERO_IS_SCRIPT
1860 if (ipathend > ipath) {
1862 * HP-UX (at least) sets argv[0] to the script name,
1863 * which makes $^X incorrect. And Digital UNIX and Linux,
1864 * at least, set argv[0] to the basename of the Perl
1865 * interpreter. So, having found "#!", we'll set it right.
1867 SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV));
1868 assert(SvPOK(x) || SvGMAGICAL(x));
1869 if (sv_eq(x, GvSV(curcop->cop_filegv))) {
1870 sv_setpvn(x, ipath, ipathend - ipath);
1873 TAINT_NOT; /* $^X is always tainted, but that's OK */
1875 #endif /* ARG_ZERO_IS_SCRIPT */
1880 d = instr(s,"perl -");
1882 d = instr(s,"perl");
1883 #ifdef ALTERNATE_SHEBANG
1885 * If the ALTERNATE_SHEBANG on this system starts with a
1886 * character that can be part of a Perl expression, then if
1887 * we see it but not "perl", we're probably looking at the
1888 * start of Perl code, not a request to hand off to some
1889 * other interpreter. Similarly, if "perl" is there, but
1890 * not in the first 'word' of the line, we assume the line
1891 * contains the start of the Perl program.
1893 if (d && *s != '#') {
1895 while (*c && !strchr("; \t\r\n\f\v#", *c))
1898 d = Nullch; /* "perl" not in first word; ignore */
1900 *s = '#'; /* Don't try to parse shebang line */
1902 #endif /* ALTERNATE_SHEBANG */
1907 !instr(s,"indir") &&
1908 instr(origargv[0],"perl"))
1914 while (s < bufend && isSPACE(*s))
1917 Newz(899,newargv,origargc+3,char*);
1919 while (s < bufend && !isSPACE(*s))
1922 Copy(origargv+1, newargv+2, origargc+1, char*);
1927 execv(ipath, newargv);
1928 croak("Can't exec %s", ipath);
1931 U32 oldpdb = perldb;
1932 bool oldn = minus_n;
1933 bool oldp = minus_p;
1935 while (*d && !isSPACE(*d)) d++;
1936 while (*d == ' ' || *d == '\t') d++;
1940 if (*d == 'M' || *d == 'm') {
1942 while (*d && !isSPACE(*d)) d++;
1943 croak("Too late for \"-%.*s\" option",
1946 d = moreswitches(d);
1948 if (PERLDB_LINE && !oldpdb ||
1949 ( minus_n || minus_p ) && !(oldn || oldp) )
1950 /* if we have already added "LINE: while (<>) {",
1951 we must not do it again */
1953 sv_setpv(linestr, "");
1954 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
1955 bufend = SvPVX(linestr) + SvCUR(linestr);
1958 (void)gv_fetchfile(origfilename);
1965 if (lex_formbrack && lex_brackets <= lex_formbrack) {
1967 lex_state = LEX_FORMLINE;
1973 warn("Illegal character \\%03o (carriage return)", '\r');
1975 "(Maybe you didn't strip carriage returns after a network transfer?)\n");
1977 case ' ': case '\t': case '\f': case 013:
1982 if (lex_state != LEX_NORMAL || (in_eval && !rsfp)) {
1984 while (s < d && *s != '\n')
1989 if (lex_formbrack && lex_brackets <= lex_formbrack) {
1991 lex_state = LEX_FORMLINE;
2001 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
2006 while (s < bufend && (*s == ' ' || *s == '\t'))
2009 if (strnEQ(s,"=>",2)) {
2010 s = force_word(bufptr,WORD,FALSE,FALSE,FALSE);
2011 OPERATOR('-'); /* unary minus */
2013 last_uni = oldbufptr;
2014 last_lop_op = OP_FTEREAD; /* good enough */
2016 case 'r': FTST(OP_FTEREAD);
2017 case 'w': FTST(OP_FTEWRITE);
2018 case 'x': FTST(OP_FTEEXEC);
2019 case 'o': FTST(OP_FTEOWNED);
2020 case 'R': FTST(OP_FTRREAD);
2021 case 'W': FTST(OP_FTRWRITE);
2022 case 'X': FTST(OP_FTREXEC);
2023 case 'O': FTST(OP_FTROWNED);
2024 case 'e': FTST(OP_FTIS);
2025 case 'z': FTST(OP_FTZERO);
2026 case 's': FTST(OP_FTSIZE);
2027 case 'f': FTST(OP_FTFILE);
2028 case 'd': FTST(OP_FTDIR);
2029 case 'l': FTST(OP_FTLINK);
2030 case 'p': FTST(OP_FTPIPE);
2031 case 'S': FTST(OP_FTSOCK);
2032 case 'u': FTST(OP_FTSUID);
2033 case 'g': FTST(OP_FTSGID);
2034 case 'k': FTST(OP_FTSVTX);
2035 case 'b': FTST(OP_FTBLK);
2036 case 'c': FTST(OP_FTCHR);
2037 case 't': FTST(OP_FTTTY);
2038 case 'T': FTST(OP_FTTEXT);
2039 case 'B': FTST(OP_FTBINARY);
2040 case 'M': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTMTIME);
2041 case 'A': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTATIME);
2042 case 'C': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTCTIME);
2044 croak("Unrecognized file test: -%c", (int)tmp);
2051 if (expect == XOPERATOR)
2056 else if (*s == '>') {
2059 if (isIDFIRST(*s)) {
2060 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
2068 if (expect == XOPERATOR)
2071 if (isSPACE(*s) || !isSPACE(*bufptr))
2073 OPERATOR('-'); /* unary minus */
2080 if (expect == XOPERATOR)
2085 if (expect == XOPERATOR)
2088 if (isSPACE(*s) || !isSPACE(*bufptr))
2094 if (expect != XOPERATOR) {
2095 s = scan_ident(s, bufend, tokenbuf, sizeof tokenbuf, TRUE);
2097 force_ident(tokenbuf, '*');
2110 if (expect == XOPERATOR) {
2115 s = scan_ident(s, bufend, tokenbuf + 1, sizeof tokenbuf - 1, TRUE);
2118 yyerror("Final % should be \\% or %name");
2121 pending_ident = '%';
2143 if (last_lop == oldoldbufptr || last_uni == oldoldbufptr)
2144 oldbufptr = oldoldbufptr; /* allow print(STDOUT 123) */
2149 if (curcop->cop_line < copline)
2150 copline = curcop->cop_line;
2161 if (lex_brackets <= 0)
2162 yyerror("Unmatched right bracket");
2165 if (lex_state == LEX_INTERPNORMAL) {
2166 if (lex_brackets == 0) {
2167 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
2168 lex_state = LEX_INTERPEND;
2175 if (lex_brackets > 100) {
2176 char* newlb = Renew(lex_brackstack, lex_brackets + 1, char);
2177 if (newlb != lex_brackstack) {
2179 lex_brackstack = newlb;
2184 if (lex_formbrack) {
2188 if (oldoldbufptr == last_lop)
2189 lex_brackstack[lex_brackets++] = XTERM;
2191 lex_brackstack[lex_brackets++] = XOPERATOR;
2192 OPERATOR(HASHBRACK);
2194 while (s < bufend && (*s == ' ' || *s == '\t'))
2198 if (d < bufend && *d == '-') {
2201 while (d < bufend && (*d == ' ' || *d == '\t'))
2204 if (d < bufend && isIDFIRST(*d)) {
2205 d = scan_word(d, tokenbuf + 1, sizeof tokenbuf - 1,
2207 while (d < bufend && (*d == ' ' || *d == '\t'))
2210 char minus = (tokenbuf[0] == '-');
2211 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
2218 lex_brackstack[lex_brackets++] = XSTATE;
2222 lex_brackstack[lex_brackets++] = XOPERATOR;
2227 if (oldoldbufptr == last_lop)
2228 lex_brackstack[lex_brackets++] = XTERM;
2230 lex_brackstack[lex_brackets++] = XOPERATOR;
2233 OPERATOR(HASHBRACK);
2234 /* This hack serves to disambiguate a pair of curlies
2235 * as being a block or an anon hash. Normally, expectation
2236 * determines that, but in cases where we're not in a
2237 * position to expect anything in particular (like inside
2238 * eval"") we have to resolve the ambiguity. This code
2239 * covers the case where the first term in the curlies is a
2240 * quoted string. Most other cases need to be explicitly
2241 * disambiguated by prepending a `+' before the opening
2242 * curly in order to force resolution as an anon hash.
2244 * XXX should probably propagate the outer expectation
2245 * into eval"" to rely less on this hack, but that could
2246 * potentially break current behavior of eval"".
2250 if (*s == '\'' || *s == '"' || *s == '`') {
2251 /* common case: get past first string, handling escapes */
2252 for (t++; t < bufend && *t != *s;)
2253 if (*t++ == '\\' && (*t == '\\' || *t == *s))
2257 else if (*s == 'q') {
2260 || ((*t == 'q' || *t == 'x') && ++t < bufend
2261 && !isALNUM(*t)))) {
2263 char open, close, term;
2266 while (t < bufend && isSPACE(*t))
2270 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
2274 for (t++; t < bufend; t++) {
2275 if (*t == '\\' && t+1 < bufend && open != '\\')
2277 else if (*t == open)
2281 for (t++; t < bufend; t++) {
2282 if (*t == '\\' && t+1 < bufend)
2284 else if (*t == close && --brackets <= 0)
2286 else if (*t == open)
2292 else if (isALPHA(*s)) {
2293 for (t++; t < bufend && isALNUM(*t); t++) ;
2295 while (t < bufend && isSPACE(*t))
2297 /* if comma follows first term, call it an anon hash */
2298 /* XXX it could be a comma expression with loop modifiers */
2299 if (t < bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
2300 || (*t == '=' && t[1] == '>')))
2301 OPERATOR(HASHBRACK);
2305 lex_brackstack[lex_brackets-1] = XSTATE;
2311 yylval.ival = curcop->cop_line;
2312 if (isSPACE(*s) || *s == '#')
2313 copline = NOLINE; /* invalidate current command line number */
2318 if (lex_brackets <= 0)
2319 yyerror("Unmatched right bracket");
2321 expect = (expectation)lex_brackstack[--lex_brackets];
2322 if (lex_brackets < lex_formbrack)
2324 if (lex_state == LEX_INTERPNORMAL) {
2325 if (lex_brackets == 0) {
2326 if (lex_fakebrack) {
2327 lex_state = LEX_INTERPEND;
2329 return yylex(); /* ignore fake brackets */
2331 if (*s == '-' && s[1] == '>')
2332 lex_state = LEX_INTERPENDMAYBE;
2333 else if (*s != '[' && *s != '{')
2334 lex_state = LEX_INTERPEND;
2337 if (lex_brackets < lex_fakebrack) {
2340 return yylex(); /* ignore fake brackets */
2350 if (expect == XOPERATOR) {
2351 if (dowarn && isALPHA(*s) && bufptr == linestart) {
2359 s = scan_ident(s - 1, bufend, tokenbuf, sizeof tokenbuf, TRUE);
2362 force_ident(tokenbuf, '&');
2366 yylval.ival = (OPpENTERSUB_AMPER<<8);
2385 if (dowarn && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
2386 warn("Reversed %c= operator",(int)tmp);
2388 if (expect == XSTATE && isALPHA(tmp) &&
2389 (s == linestart+1 || s[-2] == '\n') )
2391 if (in_eval && !rsfp) {
2396 if (strnEQ(s,"=cut",4)) {
2413 if (lex_brackets < lex_formbrack) {
2415 for (t = s; *t == ' ' || *t == '\t'; t++) ;
2416 if (*t == '\n' || *t == '#') {
2434 if (expect != XOPERATOR) {
2435 if (s[1] != '<' && !strchr(s,'>'))
2438 s = scan_heredoc(s);
2440 s = scan_inputsymbol(s);
2441 TERM(sublex_start());
2446 SHop(OP_LEFT_SHIFT);
2460 SHop(OP_RIGHT_SHIFT);
2469 if (expect == XOPERATOR) {
2470 if (lex_formbrack && lex_brackets == lex_formbrack) {
2473 return ','; /* grandfather non-comma-format format */
2477 if (s[1] == '#' && (isALPHA(s[2]) || strchr("_{$:", s[2]))) {
2478 if (expect == XOPERATOR)
2479 no_op("Array length", bufptr);
2481 s = scan_ident(s + 1, bufend, tokenbuf + 1, sizeof tokenbuf - 1,
2486 pending_ident = '#';
2490 if (expect == XOPERATOR)
2491 no_op("Scalar", bufptr);
2493 s = scan_ident(s, bufend, tokenbuf + 1, sizeof tokenbuf - 1, FALSE);
2496 yyerror("Final $ should be \\$ or $name");
2500 /* This kludge not intended to be bulletproof. */
2501 if (tokenbuf[1] == '[' && !tokenbuf[2]) {
2502 yylval.opval = newSVOP(OP_CONST, 0,
2503 newSViv((IV)compiling.cop_arybase));
2504 yylval.opval->op_private = OPpCONST_ARYBASE;
2509 if (lex_state == LEX_NORMAL)
2512 if ((expect != XREF || oldoldbufptr == last_lop) && intuit_more(s)) {
2518 isSPACE(*t) || isALNUM(*t) || *t == '$';
2521 bufptr = skipspace(bufptr);
2522 while (t < bufend && *t != ']')
2524 warn("Multidimensional syntax %.*s not supported",
2525 (t - bufptr) + 1, bufptr);
2529 else if (*s == '{') {
2531 if (dowarn && strEQ(tokenbuf+1, "SIG") &&
2532 (t = strchr(s, '}')) && (t = strchr(t, '=')))
2534 char tmpbuf[sizeof tokenbuf];
2536 for (t++; isSPACE(*t); t++) ;
2537 if (isIDFIRST(*t)) {
2538 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
2539 if (*t != '(' && perl_get_cv(tmpbuf, FALSE))
2540 warn("You need to quote \"%s\"", tmpbuf);
2547 if (lex_state == LEX_NORMAL && isSPACE(*d)) {
2548 bool islop = (last_lop == oldoldbufptr);
2549 if (!islop || last_lop_op == OP_GREPSTART)
2551 else if (strchr("$@\"'`q", *s))
2552 expect = XTERM; /* e.g. print $fh "foo" */
2553 else if (strchr("&*<%", *s) && isIDFIRST(s[1]))
2554 expect = XTERM; /* e.g. print $fh &sub */
2555 else if (isIDFIRST(*s)) {
2556 char tmpbuf[sizeof tokenbuf];
2557 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2558 if (tmp = keyword(tmpbuf, len)) {
2559 /* binary operators exclude handle interpretations */
2571 expect = XTERM; /* e.g. print $fh length() */
2576 GV *gv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
2577 if (gv && GvCVu(gv))
2578 expect = XTERM; /* e.g. print $fh subr() */
2581 else if (isDIGIT(*s))
2582 expect = XTERM; /* e.g. print $fh 3 */
2583 else if (*s == '.' && isDIGIT(s[1]))
2584 expect = XTERM; /* e.g. print $fh .3 */
2585 else if (strchr("/?-+", *s) && !isSPACE(s[1]))
2586 expect = XTERM; /* e.g. print $fh -1 */
2587 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]))
2588 expect = XTERM; /* print $fh <<"EOF" */
2590 pending_ident = '$';
2594 if (expect == XOPERATOR)
2597 s = scan_ident(s, bufend, tokenbuf + 1, sizeof tokenbuf - 1, FALSE);
2600 yyerror("Final @ should be \\@ or @name");
2603 if (lex_state == LEX_NORMAL)
2605 if ((expect != XREF || oldoldbufptr == last_lop) && intuit_more(s)) {
2609 /* Warn about @ where they meant $. */
2611 if (*s == '[' || *s == '{') {
2613 while (*t && (isALNUM(*t) || strchr(" \t$#+-'\"", *t)))
2615 if (*t == '}' || *t == ']') {
2617 bufptr = skipspace(bufptr);
2618 warn("Scalar value %.*s better written as $%.*s",
2619 t-bufptr, bufptr, t-bufptr-1, bufptr+1);
2624 pending_ident = '@';
2627 case '/': /* may either be division or pattern */
2628 case '?': /* may either be conditional or pattern */
2629 if (expect != XOPERATOR) {
2630 /* Disable warning on "study /blah/" */
2631 if (oldoldbufptr == last_uni
2632 && (*last_uni != 's' || s - last_uni < 5
2633 || memNE(last_uni, "study", 5) || isALNUM(last_uni[5])))
2636 TERM(sublex_start());
2644 if (lex_formbrack && lex_brackets == lex_formbrack && s[1] == '\n' &&
2645 (s == linestart || s[-1] == '\n') ) {
2650 if (expect == XOPERATOR || !isDIGIT(s[1])) {
2656 yylval.ival = OPf_SPECIAL;
2662 if (expect != XOPERATOR)
2667 case '0': case '1': case '2': case '3': case '4':
2668 case '5': case '6': case '7': case '8': case '9':
2670 if (expect == XOPERATOR)
2676 if (expect == XOPERATOR) {
2677 if (lex_formbrack && lex_brackets == lex_formbrack) {
2680 return ','; /* grandfather non-comma-format format */
2686 missingterm((char*)0);
2687 yylval.ival = OP_CONST;
2688 TERM(sublex_start());
2692 if (expect == XOPERATOR) {
2693 if (lex_formbrack && lex_brackets == lex_formbrack) {
2696 return ','; /* grandfather non-comma-format format */
2702 missingterm((char*)0);
2703 yylval.ival = OP_CONST;
2704 for (d = SvPV(lex_stuff, len); len; len--, d++) {
2705 if (*d == '$' || *d == '@' || *d == '\\') {
2706 yylval.ival = OP_STRINGIFY;
2710 TERM(sublex_start());
2714 if (expect == XOPERATOR)
2715 no_op("Backticks",s);
2717 missingterm((char*)0);
2718 yylval.ival = OP_BACKTICK;
2720 TERM(sublex_start());
2724 if (dowarn && lex_inwhat && isDIGIT(*s))
2725 warn("Can't use \\%c to mean $%c in expression", *s, *s);
2726 if (expect == XOPERATOR)
2727 no_op("Backslash",s);
2731 if (isDIGIT(s[1]) && expect == XOPERATOR) {
2770 s = scan_word(s, tokenbuf, sizeof tokenbuf, FALSE, &len);
2772 /* Some keywords can be followed by any delimiter, including ':' */
2773 tmp = (len == 1 && strchr("msyq", tokenbuf[0]) ||
2774 len == 2 && ((tokenbuf[0] == 't' && tokenbuf[1] == 'r') ||
2775 (tokenbuf[0] == 'q' &&
2776 strchr("qwx", tokenbuf[1]))));
2778 /* x::* is just a word, unless x is "CORE" */
2779 if (!tmp && *s == ':' && s[1] == ':' && strNE(tokenbuf, "CORE"))
2783 while (d < bufend && isSPACE(*d))
2784 d++; /* no comments skipped here, or s### is misparsed */
2786 /* Is this a label? */
2787 if (!tmp && expect == XSTATE
2788 && d < bufend && *d == ':' && *(d + 1) != ':') {
2790 yylval.pval = savepv(tokenbuf);
2795 /* Check for keywords */
2796 tmp = keyword(tokenbuf, len);
2798 /* Is this a word before a => operator? */
2799 if (strnEQ(d,"=>",2)) {
2801 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf,0));
2802 yylval.opval->op_private = OPpCONST_BARE;
2806 if (tmp < 0) { /* second-class keyword? */
2807 if (expect != XOPERATOR && (*s != ':' || s[1] != ':') &&
2808 (((gv = gv_fetchpv(tokenbuf, FALSE, SVt_PVCV)) &&
2809 GvCVu(gv) && GvIMPORTED_CV(gv)) ||
2810 ((gvp = (GV**)hv_fetch(globalstash,tokenbuf,len,FALSE)) &&
2811 (gv = *gvp) != (GV*)&sv_undef &&
2812 GvCVu(gv) && GvIMPORTED_CV(gv))))
2814 tmp = 0; /* overridden by importation */
2817 && -tmp==KEY_lock /* XXX generalizable kludge */
2818 && !hv_fetch(GvHVn(incgv), "Thread.pm", 9, FALSE))
2820 tmp = 0; /* any sub overrides "weak" keyword */
2823 tmp = -tmp; gv = Nullgv; gvp = 0;
2830 default: /* not a keyword */
2833 char lastchar = (bufptr == oldoldbufptr ? 0 : bufptr[-1]);
2835 /* Get the rest if it looks like a package qualifier */
2837 if (*s == '\'' || *s == ':' && s[1] == ':') {
2839 s = scan_word(s, tokenbuf + len, sizeof tokenbuf - len,
2842 croak("Bad name after %s%s", tokenbuf,
2843 *s == '\'' ? "'" : "::");
2847 if (expect == XOPERATOR) {
2848 if (bufptr == linestart) {
2854 no_op("Bareword",s);
2857 /* Look for a subroutine with this name in current package,
2858 unless name is "Foo::", in which case Foo is a bearword
2859 (and a package name). */
2862 tokenbuf[len - 2] == ':' && tokenbuf[len - 1] == ':')
2864 if (dowarn && ! gv_fetchpv(tokenbuf, FALSE, SVt_PVHV))
2865 warn("Bareword \"%s\" refers to nonexistent package",
2868 tokenbuf[len] = '\0';
2875 gv = gv_fetchpv(tokenbuf, FALSE, SVt_PVCV);
2878 /* if we saw a global override before, get the right name */
2881 sv = newSVpv("CORE::GLOBAL::",14);
2882 sv_catpv(sv,tokenbuf);
2885 sv = newSVpv(tokenbuf,0);
2887 /* Presume this is going to be a bareword of some sort. */
2890 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2891 yylval.opval->op_private = OPpCONST_BARE;
2893 /* And if "Foo::", then that's what it certainly is. */
2898 /* See if it's the indirect object for a list operator. */
2901 oldoldbufptr < bufptr &&
2902 (oldoldbufptr == last_lop || oldoldbufptr == last_uni) &&
2903 /* NO SKIPSPACE BEFORE HERE! */
2905 ((opargs[last_lop_op] >> OASHIFT)& 7) == OA_FILEREF) )
2907 bool immediate_paren = *s == '(';
2909 /* (Now we can afford to cross potential line boundary.) */
2912 /* Two barewords in a row may indicate method call. */
2914 if ((isALPHA(*s) || *s == '$') && (tmp=intuit_method(s,gv)))
2917 /* If not a declared subroutine, it's an indirect object. */
2918 /* (But it's an indir obj regardless for sort.) */
2920 if ((last_lop_op == OP_SORT ||
2921 (!immediate_paren && (!gv || !GvCVu(gv))) ) &&
2922 (last_lop_op != OP_MAPSTART && last_lop_op != OP_GREPSTART)){
2923 expect = (last_lop == oldoldbufptr) ? XTERM : XOPERATOR;
2928 /* If followed by a paren, it's certainly a subroutine. */
2934 if (gv && GvCVu(gv)) {
2935 for (d = s + 1; *d == ' ' || *d == '\t'; d++) ;
2936 if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) {
2941 nextval[nexttoke].opval = yylval.opval;
2948 /* If followed by var or block, call it a method (unless sub) */
2950 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
2951 last_lop = oldbufptr;
2952 last_lop_op = OP_METHOD;
2956 /* If followed by a bareword, see if it looks like indir obj. */
2958 if ((isALPHA(*s) || *s == '$') && (tmp = intuit_method(s,gv)))
2961 /* Not a method, so call it a subroutine (if defined) */
2963 if (gv && GvCVu(gv)) {
2965 if (lastchar == '-')
2966 warn("Ambiguous use of -%s resolved as -&%s()",
2967 tokenbuf, tokenbuf);
2968 last_lop = oldbufptr;
2969 last_lop_op = OP_ENTERSUB;
2970 /* Check for a constant sub */
2972 if ((sv = cv_const_sv(cv))) {
2974 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
2975 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
2976 yylval.opval->op_private = 0;
2980 /* Resolve to GV now. */
2981 op_free(yylval.opval);
2982 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
2983 /* Is there a prototype? */
2986 char *proto = SvPV((SV*)cv, len);
2989 if (strEQ(proto, "$"))
2991 if (*proto == '&' && *s == '{') {
2992 sv_setpv(subname,"__ANON__");
2996 nextval[nexttoke].opval = yylval.opval;
3002 if (hints & HINT_STRICT_SUBS &&
3005 last_lop_op != OP_TRUNCATE && /* S/F prototype in opcode.pl */
3006 last_lop_op != OP_ACCEPT &&
3007 last_lop_op != OP_PIPE_OP &&
3008 last_lop_op != OP_SOCKPAIR)
3011 "Bareword \"%s\" not allowed while \"strict subs\" in use",
3016 /* Call it a bare word */
3020 if (lastchar != '-') {
3021 for (d = tokenbuf; *d && isLOWER(*d); d++) ;
3023 warn(warn_reserved, tokenbuf);
3028 if (lastchar && strchr("*%&", lastchar)) {
3029 warn("Operator or semicolon missing before %c%s",
3030 lastchar, tokenbuf);
3031 warn("Ambiguous use of %c resolved as operator %c",
3032 lastchar, lastchar);
3038 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
3039 newSVsv(GvSV(curcop->cop_filegv)));
3043 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
3044 newSVpvf("%ld", (long)curcop->cop_line));
3047 case KEY___PACKAGE__:
3048 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
3050 ? newSVsv(curstname)
3059 if (rsfp && (!in_eval || tokenbuf[2] == 'D')) {
3060 char *pname = "main";
3061 if (tokenbuf[2] == 'D')
3062 pname = HvNAME(curstash ? curstash : defstash);
3063 gv = gv_fetchpv(form("%s::DATA", pname), TRUE, SVt_PVIO);
3066 GvIOp(gv) = newIO();
3067 IoIFP(GvIOp(gv)) = rsfp;
3068 #if defined(HAS_FCNTL) && defined(F_SETFD)
3070 int fd = PerlIO_fileno(rsfp);
3071 fcntl(fd,F_SETFD,fd >= 3);
3074 /* Mark this internal pseudo-handle as clean */
3075 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
3077 IoTYPE(GvIOp(gv)) = '|';
3078 else if ((PerlIO*)rsfp == PerlIO_stdin())
3079 IoTYPE(GvIOp(gv)) = '-';
3081 IoTYPE(GvIOp(gv)) = '<';
3092 if (expect == XSTATE) {
3099 if (*s == ':' && s[1] == ':') {
3102 s = scan_word(s, tokenbuf, sizeof tokenbuf, FALSE, &len);
3103 tmp = keyword(tokenbuf, len);
3117 LOP(OP_ACCEPT,XTERM);
3123 LOP(OP_ATAN2,XTERM);
3132 LOP(OP_BLESS,XTERM);
3141 (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */
3161 LOP(OP_CRYPT,XTERM);
3165 for (d = s; d < bufend && (isSPACE(*d) || *d == '('); d++) ;
3166 if (*d != '0' && isDIGIT(*d))
3167 yywarn("chmod: mode argument is missing initial 0");
3169 LOP(OP_CHMOD,XTERM);
3172 LOP(OP_CHOWN,XTERM);
3175 LOP(OP_CONNECT,XTERM);
3191 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3195 hints |= HINT_BLOCK_SCOPE;
3205 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
3206 LOP(OP_DBMOPEN,XTERM);
3212 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3219 yylval.ival = curcop->cop_line;
3233 expect = (*s == '{') ? XTERMBLOCK : XTERM;
3234 UNIBRACK(OP_ENTEREVAL);
3249 case KEY_endhostent:
3255 case KEY_endservent:
3258 case KEY_endprotoent:
3269 yylval.ival = curcop->cop_line;
3271 if (expect == XSTATE && isIDFIRST(*s)) {
3273 if ((bufend - p) >= 3 &&
3274 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
3278 croak("Missing $ on loop variable");
3283 LOP(OP_FORMLINE,XTERM);
3289 LOP(OP_FCNTL,XTERM);
3295 LOP(OP_FLOCK,XTERM);
3304 LOP(OP_GREPSTART, *s == '(' ? XTERM : XREF);
3307 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3322 case KEY_getpriority:
3323 LOP(OP_GETPRIORITY,XTERM);
3325 case KEY_getprotobyname:
3328 case KEY_getprotobynumber:
3329 LOP(OP_GPBYNUMBER,XTERM);
3331 case KEY_getprotoent:
3343 case KEY_getpeername:
3344 UNI(OP_GETPEERNAME);
3346 case KEY_gethostbyname:
3349 case KEY_gethostbyaddr:
3350 LOP(OP_GHBYADDR,XTERM);
3352 case KEY_gethostent:
3355 case KEY_getnetbyname:
3358 case KEY_getnetbyaddr:
3359 LOP(OP_GNBYADDR,XTERM);
3364 case KEY_getservbyname:
3365 LOP(OP_GSBYNAME,XTERM);
3367 case KEY_getservbyport:
3368 LOP(OP_GSBYPORT,XTERM);
3370 case KEY_getservent:
3373 case KEY_getsockname:
3374 UNI(OP_GETSOCKNAME);
3376 case KEY_getsockopt:
3377 LOP(OP_GSOCKOPT,XTERM);
3399 yylval.ival = curcop->cop_line;
3403 LOP(OP_INDEX,XTERM);
3409 LOP(OP_IOCTL,XTERM);
3421 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3452 LOP(OP_LISTEN,XTERM);
3462 TERM(sublex_start());
3465 LOP(OP_MAPSTART,XREF);
3468 LOP(OP_MKDIR,XTERM);
3471 LOP(OP_MSGCTL,XTERM);
3474 LOP(OP_MSGGET,XTERM);
3477 LOP(OP_MSGRCV,XTERM);
3480 LOP(OP_MSGSND,XTERM);
3485 if (isIDFIRST(*s)) {
3486 s = scan_word(s, tokenbuf, sizeof tokenbuf, TRUE, &len);
3487 in_my_stash = gv_stashpv(tokenbuf, FALSE);
3491 sprintf(tmpbuf, "No such class %.1000s", tokenbuf);
3498 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3505 if (expect != XSTATE)
3506 yyerror("\"no\" not allowed in expression");
3507 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3508 s = force_version(s);
3517 if (isIDFIRST(*s)) {
3519 for (d = s; isALNUM(*d); d++) ;
3521 if (strchr("|&*+-=!?:.", *t))
3522 warn("Precedence problem: open %.*s should be open(%.*s)",
3528 yylval.ival = OP_OR;
3538 LOP(OP_OPEN_DIR,XTERM);
3541 checkcomma(s,tokenbuf,"filehandle");
3545 checkcomma(s,tokenbuf,"filehandle");
3564 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3568 LOP(OP_PIPE_OP,XTERM);
3573 missingterm((char*)0);
3574 yylval.ival = OP_CONST;
3575 TERM(sublex_start());
3583 missingterm((char*)0);
3584 if (dowarn && SvLEN(lex_stuff)) {
3585 d = SvPV_force(lex_stuff, len);
3586 for (; len; --len, ++d) {
3588 warn("Possible attempt to separate words with commas");
3592 warn("Possible attempt to put comments in qw() list");
3598 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, q(lex_stuff));
3602 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(" ",1));
3605 yylval.ival = OP_SPLIT;
3609 last_lop = oldbufptr;
3610 last_lop_op = OP_SPLIT;
3616 missingterm((char*)0);
3617 yylval.ival = OP_STRINGIFY;
3618 if (SvIVX(lex_stuff) == '\'')
3619 SvIVX(lex_stuff) = 0; /* qq'$foo' should intepolate */
3620 TERM(sublex_start());
3625 missingterm((char*)0);
3626 yylval.ival = OP_BACKTICK;
3628 TERM(sublex_start());
3635 s = force_word(s,WORD,TRUE,TRUE,FALSE);
3636 if (isIDFIRST(*tokenbuf))
3637 gv_stashpvn(tokenbuf, strlen(tokenbuf), TRUE);
3639 yyerror("<> should be quotes");
3646 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3650 LOP(OP_RENAME,XTERM);
3659 LOP(OP_RINDEX,XTERM);
3682 LOP(OP_REVERSE,XTERM);
3693 TERM(sublex_start());
3695 TOKEN(1); /* force error */
3704 LOP(OP_SELECT,XTERM);
3710 LOP(OP_SEMCTL,XTERM);
3713 LOP(OP_SEMGET,XTERM);
3716 LOP(OP_SEMOP,XTERM);
3722 LOP(OP_SETPGRP,XTERM);
3724 case KEY_setpriority:
3725 LOP(OP_SETPRIORITY,XTERM);
3727 case KEY_sethostent:
3733 case KEY_setservent:
3736 case KEY_setprotoent:
3746 LOP(OP_SEEKDIR,XTERM);
3748 case KEY_setsockopt:
3749 LOP(OP_SSOCKOPT,XTERM);
3755 LOP(OP_SHMCTL,XTERM);
3758 LOP(OP_SHMGET,XTERM);
3761 LOP(OP_SHMREAD,XTERM);
3764 LOP(OP_SHMWRITE,XTERM);
3767 LOP(OP_SHUTDOWN,XTERM);
3776 LOP(OP_SOCKET,XTERM);
3778 case KEY_socketpair:
3779 LOP(OP_SOCKPAIR,XTERM);
3782 checkcomma(s,tokenbuf,"subroutine name");
3784 if (*s == ';' || *s == ')') /* probably a close */
3785 croak("sort is now a reserved word");
3787 s = force_word(s,WORD,TRUE,TRUE,FALSE);
3791 LOP(OP_SPLIT,XTERM);
3794 LOP(OP_SPRINTF,XTERM);
3797 LOP(OP_SPLICE,XTERM);
3813 LOP(OP_SUBSTR,XTERM);
3820 if (isIDFIRST(*s) || *s == '\'' || *s == ':') {
3821 char tmpbuf[sizeof tokenbuf];
3823 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3824 if (strchr(tmpbuf, ':'))
3825 sv_setpv(subname, tmpbuf);
3827 sv_setsv(subname,curstname);
3828 sv_catpvn(subname,"::",2);
3829 sv_catpvn(subname,tmpbuf,len);
3831 s = force_word(s,WORD,FALSE,TRUE,TRUE);
3835 expect = XTERMBLOCK;
3836 sv_setpv(subname,"?");
3839 if (tmp == KEY_format) {
3842 lex_formbrack = lex_brackets + 1;
3846 /* Look for a prototype */
3853 SvREFCNT_dec(lex_stuff);
3855 croak("Prototype not terminated");
3858 d = SvPVX(lex_stuff);
3860 for (p = d; *p; ++p) {
3865 SvCUR(lex_stuff) = tmp;
3868 nextval[1] = nextval[0];
3869 nexttype[1] = nexttype[0];
3870 nextval[0].opval = (OP*)newSVOP(OP_CONST, 0, lex_stuff);
3871 nexttype[0] = THING;
3872 if (nexttoke == 1) {
3873 lex_defer = lex_state;
3874 lex_expect = expect;
3875 lex_state = LEX_KNOWNEXT;
3880 if (*SvPV(subname,na) == '?') {
3881 sv_setpv(subname,"__ANON__");
3888 LOP(OP_SYSTEM,XREF);
3891 LOP(OP_SYMLINK,XTERM);
3894 LOP(OP_SYSCALL,XTERM);
3897 LOP(OP_SYSOPEN,XTERM);
3900 LOP(OP_SYSSEEK,XTERM);
3903 LOP(OP_SYSREAD,XTERM);
3906 LOP(OP_SYSWRITE,XTERM);
3910 TERM(sublex_start());
3931 LOP(OP_TRUNCATE,XTERM);
3943 yylval.ival = curcop->cop_line;
3947 yylval.ival = curcop->cop_line;
3951 LOP(OP_UNLINK,XTERM);
3957 LOP(OP_UNPACK,XTERM);
3960 LOP(OP_UTIME,XTERM);
3964 for (d = s; d < bufend && (isSPACE(*d) || *d == '('); d++) ;
3965 if (*d != '0' && isDIGIT(*d))
3966 yywarn("umask: argument is missing initial 0");
3971 LOP(OP_UNSHIFT,XTERM);
3974 if (expect != XSTATE)
3975 yyerror("\"use\" not allowed in expression");
3978 s = force_version(s);
3979 if(*s == ';' || (s = skipspace(s), *s == ';')) {
3980 nextval[nexttoke].opval = Nullop;
3985 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3986 s = force_version(s);
3999 yylval.ival = curcop->cop_line;
4003 hints |= HINT_BLOCK_SCOPE;
4010 LOP(OP_WAITPID,XTERM);
4016 gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */
4020 if (expect == XOPERATOR)
4026 yylval.ival = OP_XOR;
4031 TERM(sublex_start());
4037 keyword(register char *d, I32 len)
4042 if (strEQ(d,"__FILE__")) return -KEY___FILE__;
4043 if (strEQ(d,"__LINE__")) return -KEY___LINE__;
4044 if (strEQ(d,"__PACKAGE__")) return -KEY___PACKAGE__;
4045 if (strEQ(d,"__DATA__")) return KEY___DATA__;
4046 if (strEQ(d,"__END__")) return KEY___END__;
4050 if (strEQ(d,"AUTOLOAD")) return KEY_AUTOLOAD;
4055 if (strEQ(d,"and")) return -KEY_and;
4056 if (strEQ(d,"abs")) return -KEY_abs;
4059 if (strEQ(d,"alarm")) return -KEY_alarm;
4060 if (strEQ(d,"atan2")) return -KEY_atan2;
4063 if (strEQ(d,"accept")) return -KEY_accept;
4068 if (strEQ(d,"BEGIN")) return KEY_BEGIN;
4071 if (strEQ(d,"bless")) return -KEY_bless;
4072 if (strEQ(d,"bind")) return -KEY_bind;
4073 if (strEQ(d,"binmode")) return -KEY_binmode;
4076 if (strEQ(d,"CORE")) return -KEY_CORE;
4081 if (strEQ(d,"cmp")) return -KEY_cmp;
4082 if (strEQ(d,"chr")) return -KEY_chr;
4083 if (strEQ(d,"cos")) return -KEY_cos;
4086 if (strEQ(d,"chop")) return KEY_chop;
4089 if (strEQ(d,"close")) return -KEY_close;
4090 if (strEQ(d,"chdir")) return -KEY_chdir;
4091 if (strEQ(d,"chomp")) return KEY_chomp;
4092 if (strEQ(d,"chmod")) return -KEY_chmod;
4093 if (strEQ(d,"chown")) return -KEY_chown;
4094 if (strEQ(d,"crypt")) return -KEY_crypt;
4097 if (strEQ(d,"chroot")) return -KEY_chroot;
4098 if (strEQ(d,"caller")) return -KEY_caller;
4101 if (strEQ(d,"connect")) return -KEY_connect;
4104 if (strEQ(d,"closedir")) return -KEY_closedir;
4105 if (strEQ(d,"continue")) return -KEY_continue;
4110 if (strEQ(d,"DESTROY")) return KEY_DESTROY;
4115 if (strEQ(d,"do")) return KEY_do;
4118 if (strEQ(d,"die")) return -KEY_die;
4121 if (strEQ(d,"dump")) return -KEY_dump;
4124 if (strEQ(d,"delete")) return KEY_delete;
4127 if (strEQ(d,"defined")) return KEY_defined;
4128 if (strEQ(d,"dbmopen")) return -KEY_dbmopen;
4131 if (strEQ(d,"dbmclose")) return -KEY_dbmclose;
4136 if (strEQ(d,"EQ")) { deprecate(d); return -KEY_eq;}
4137 if (strEQ(d,"END")) return KEY_END;
4142 if (strEQ(d,"eq")) return -KEY_eq;
4145 if (strEQ(d,"eof")) return -KEY_eof;
4146 if (strEQ(d,"exp")) return -KEY_exp;
4149 if (strEQ(d,"else")) return KEY_else;
4150 if (strEQ(d,"exit")) return -KEY_exit;
4151 if (strEQ(d,"eval")) return KEY_eval;
4152 if (strEQ(d,"exec")) return -KEY_exec;
4153 if (strEQ(d,"each")) return KEY_each;
4156 if (strEQ(d,"elsif")) return KEY_elsif;
4159 if (strEQ(d,"exists")) return KEY_exists;
4160 if (strEQ(d,"elseif")) warn("elseif should be elsif");
4163 if (strEQ(d,"endgrent")) return -KEY_endgrent;
4164 if (strEQ(d,"endpwent")) return -KEY_endpwent;
4167 if (strEQ(d,"endnetent")) return -KEY_endnetent;
4170 if (strEQ(d,"endhostent")) return -KEY_endhostent;
4171 if (strEQ(d,"endservent")) return -KEY_endservent;
4174 if (strEQ(d,"endprotoent")) return -KEY_endprotoent;
4181 if (strEQ(d,"for")) return KEY_for;
4184 if (strEQ(d,"fork")) return -KEY_fork;
4187 if (strEQ(d,"fcntl")) return -KEY_fcntl;
4188 if (strEQ(d,"flock")) return -KEY_flock;
4191 if (strEQ(d,"format")) return KEY_format;
4192 if (strEQ(d,"fileno")) return -KEY_fileno;
4195 if (strEQ(d,"foreach")) return KEY_foreach;
4198 if (strEQ(d,"formline")) return -KEY_formline;
4204 if (strEQ(d,"GT")) { deprecate(d); return -KEY_gt;}
4205 if (strEQ(d,"GE")) { deprecate(d); return -KEY_ge;}
4209 if (strnEQ(d,"get",3)) {
4214 if (strEQ(d,"ppid")) return -KEY_getppid;
4215 if (strEQ(d,"pgrp")) return -KEY_getpgrp;
4218 if (strEQ(d,"pwent")) return -KEY_getpwent;
4219 if (strEQ(d,"pwnam")) return -KEY_getpwnam;
4220 if (strEQ(d,"pwuid")) return -KEY_getpwuid;
4223 if (strEQ(d,"peername")) return -KEY_getpeername;
4224 if (strEQ(d,"protoent")) return -KEY_getprotoent;
4225 if (strEQ(d,"priority")) return -KEY_getpriority;
4228 if (strEQ(d,"protobyname")) return -KEY_getprotobyname;
4231 if (strEQ(d,"protobynumber"))return -KEY_getprotobynumber;
4235 else if (*d == 'h') {
4236 if (strEQ(d,"hostbyname")) return -KEY_gethostbyname;
4237 if (strEQ(d,"hostbyaddr")) return -KEY_gethostbyaddr;
4238 if (strEQ(d,"hostent")) return -KEY_gethostent;
4240 else if (*d == 'n') {
4241 if (strEQ(d,"netbyname")) return -KEY_getnetbyname;
4242 if (strEQ(d,"netbyaddr")) return -KEY_getnetbyaddr;
4243 if (strEQ(d,"netent")) return -KEY_getnetent;
4245 else if (*d == 's') {
4246 if (strEQ(d,"servbyname")) return -KEY_getservbyname;
4247 if (strEQ(d,"servbyport")) return -KEY_getservbyport;
4248 if (strEQ(d,"servent")) return -KEY_getservent;
4249 if (strEQ(d,"sockname")) return -KEY_getsockname;
4250 if (strEQ(d,"sockopt")) return -KEY_getsockopt;
4252 else if (*d == 'g') {
4253 if (strEQ(d,"grent")) return -KEY_getgrent;
4254 if (strEQ(d,"grnam")) return -KEY_getgrnam;
4255 if (strEQ(d,"grgid")) return -KEY_getgrgid;
4257 else if (*d == 'l') {
4258 if (strEQ(d,"login")) return -KEY_getlogin;
4260 else if (strEQ(d,"c")) return -KEY_getc;
4265 if (strEQ(d,"gt")) return -KEY_gt;
4266 if (strEQ(d,"ge")) return -KEY_ge;
4269 if (strEQ(d,"grep")) return KEY_grep;
4270 if (strEQ(d,"goto")) return KEY_goto;
4271 if (strEQ(d,"glob")) return KEY_glob;
4274 if (strEQ(d,"gmtime")) return -KEY_gmtime;
4279 if (strEQ(d,"hex")) return -KEY_hex;
4282 if (strEQ(d,"INIT")) return KEY_INIT;
4287 if (strEQ(d,"if")) return KEY_if;
4290 if (strEQ(d,"int")) return -KEY_int;
4293 if (strEQ(d,"index")) return -KEY_index;
4294 if (strEQ(d,"ioctl")) return -KEY_ioctl;
4299 if (strEQ(d,"join")) return -KEY_join;
4303 if (strEQ(d,"keys")) return KEY_keys;
4304 if (strEQ(d,"kill")) return -KEY_kill;
4309 if (strEQ(d,"LT")) { deprecate(d); return -KEY_lt;}
4310 if (strEQ(d,"LE")) { deprecate(d); return -KEY_le;}
4316 if (strEQ(d,"lt")) return -KEY_lt;
4317 if (strEQ(d,"le")) return -KEY_le;
4318 if (strEQ(d,"lc")) return -KEY_lc;
4321 if (strEQ(d,"log")) return -KEY_log;
4324 if (strEQ(d,"last")) return KEY_last;
4325 if (strEQ(d,"link")) return -KEY_link;
4326 if (strEQ(d,"lock")) return -KEY_lock;
4329 if (strEQ(d,"local")) return KEY_local;
4330 if (strEQ(d,"lstat")) return -KEY_lstat;
4333 if (strEQ(d,"length")) return -KEY_length;
4334 if (strEQ(d,"listen")) return -KEY_listen;
4337 if (strEQ(d,"lcfirst")) return -KEY_lcfirst;
4340 if (strEQ(d,"localtime")) return -KEY_localtime;
4346 case 1: return KEY_m;
4348 if (strEQ(d,"my")) return KEY_my;
4351 if (strEQ(d,"map")) return KEY_map;
4354 if (strEQ(d,"mkdir")) return -KEY_mkdir;
4357 if (strEQ(d,"msgctl")) return -KEY_msgctl;
4358 if (strEQ(d,"msgget")) return -KEY_msgget;
4359 if (strEQ(d,"msgrcv")) return -KEY_msgrcv;
4360 if (strEQ(d,"msgsnd")) return -KEY_msgsnd;
4365 if (strEQ(d,"NE")) { deprecate(d); return -KEY_ne;}
4368 if (strEQ(d,"next")) return KEY_next;
4369 if (strEQ(d,"ne")) return -KEY_ne;
4370 if (strEQ(d,"not")) return -KEY_not;
4371 if (strEQ(d,"no")) return KEY_no;
4376 if (strEQ(d,"or")) return -KEY_or;
4379 if (strEQ(d,"ord")) return -KEY_ord;
4380 if (strEQ(d,"oct")) return -KEY_oct;
4383 if (strEQ(d,"open")) return -KEY_open;
4386 if (strEQ(d,"opendir")) return -KEY_opendir;
4393 if (strEQ(d,"pop")) return KEY_pop;
4394 if (strEQ(d,"pos")) return KEY_pos;
4397 if (strEQ(d,"push")) return KEY_push;
4398 if (strEQ(d,"pack")) return -KEY_pack;
4399 if (strEQ(d,"pipe")) return -KEY_pipe;
4402 if (strEQ(d,"print")) return KEY_print;
4405 if (strEQ(d,"printf")) return KEY_printf;
4408 if (strEQ(d,"package")) return KEY_package;
4411 if (strEQ(d,"prototype")) return KEY_prototype;
4416 if (strEQ(d,"q")) return KEY_q;
4417 if (strEQ(d,"qq")) return KEY_qq;
4418 if (strEQ(d,"qw")) return KEY_qw;
4419 if (strEQ(d,"qx")) return KEY_qx;
4421 else if (strEQ(d,"quotemeta")) return -KEY_quotemeta;
4426 if (strEQ(d,"ref")) return -KEY_ref;
4429 if (strEQ(d,"read")) return -KEY_read;
4430 if (strEQ(d,"rand")) return -KEY_rand;
4431 if (strEQ(d,"recv")) return -KEY_recv;
4432 if (strEQ(d,"redo")) return KEY_redo;
4435 if (strEQ(d,"rmdir")) return -KEY_rmdir;
4436 if (strEQ(d,"reset")) return -KEY_reset;
4439 if (strEQ(d,"return")) return KEY_return;
4440 if (strEQ(d,"rename")) return -KEY_rename;
4441 if (strEQ(d,"rindex")) return -KEY_rindex;
4444 if (strEQ(d,"require")) return -KEY_require;
4445 if (strEQ(d,"reverse")) return -KEY_reverse;
4446 if (strEQ(d,"readdir")) return -KEY_readdir;
4449 if (strEQ(d,"readlink")) return -KEY_readlink;
4450 if (strEQ(d,"readline")) return -KEY_readline;
4451 if (strEQ(d,"readpipe")) return -KEY_readpipe;
4454 if (strEQ(d,"rewinddir")) return -KEY_rewinddir;
4460 case 0: return KEY_s;
4462 if (strEQ(d,"scalar")) return KEY_scalar;
4467 if (strEQ(d,"seek")) return -KEY_seek;
4468 if (strEQ(d,"send")) return -KEY_send;
4471 if (strEQ(d,"semop")) return -KEY_semop;
4474 if (strEQ(d,"select")) return -KEY_select;
4475 if (strEQ(d,"semctl")) return -KEY_semctl;
4476 if (strEQ(d,"semget")) return -KEY_semget;
4479 if (strEQ(d,"setpgrp")) return -KEY_setpgrp;
4480 if (strEQ(d,"seekdir")) return -KEY_seekdir;
4483 if (strEQ(d,"setpwent")) return -KEY_setpwent;
4484 if (strEQ(d,"setgrent")) return -KEY_setgrent;
4487 if (strEQ(d,"setnetent")) return -KEY_setnetent;
4490 if (strEQ(d,"setsockopt")) return -KEY_setsockopt;
4491 if (strEQ(d,"sethostent")) return -KEY_sethostent;
4492 if (strEQ(d,"setservent")) return -KEY_setservent;
4495 if (strEQ(d,"setpriority")) return -KEY_setpriority;
4496 if (strEQ(d,"setprotoent")) return -KEY_setprotoent;
4503 if (strEQ(d,"shift")) return KEY_shift;
4506 if (strEQ(d,"shmctl")) return -KEY_shmctl;
4507 if (strEQ(d,"shmget")) return -KEY_shmget;
4510 if (strEQ(d,"shmread")) return -KEY_shmread;
4513 if (strEQ(d,"shmwrite")) return -KEY_shmwrite;
4514 if (strEQ(d,"shutdown")) return -KEY_shutdown;
4519 if (strEQ(d,"sin")) return -KEY_sin;
4522 if (strEQ(d,"sleep")) return -KEY_sleep;
4525 if (strEQ(d,"sort")) return KEY_sort;
4526 if (strEQ(d,"socket")) return -KEY_socket;
4527 if (strEQ(d,"socketpair")) return -KEY_socketpair;
4530 if (strEQ(d,"split")) return KEY_split;
4531 if (strEQ(d,"sprintf")) return -KEY_sprintf;
4532 if (strEQ(d,"splice")) return KEY_splice;
4535 if (strEQ(d,"sqrt")) return -KEY_sqrt;
4538 if (strEQ(d,"srand")) return -KEY_srand;
4541 if (strEQ(d,"stat")) return -KEY_stat;
4542 if (strEQ(d,"study")) return KEY_study;
4545 if (strEQ(d,"substr")) return -KEY_substr;
4546 if (strEQ(d,"sub")) return KEY_sub;
4551 if (strEQ(d,"system")) return -KEY_system;
4554 if (strEQ(d,"symlink")) return -KEY_symlink;
4555 if (strEQ(d,"syscall")) return -KEY_syscall;
4556 if (strEQ(d,"sysopen")) return -KEY_sysopen;
4557 if (strEQ(d,"sysread")) return -KEY_sysread;
4558 if (strEQ(d,"sysseek")) return -KEY_sysseek;
4561 if (strEQ(d,"syswrite")) return -KEY_syswrite;
4570 if (strEQ(d,"tr")) return KEY_tr;
4573 if (strEQ(d,"tie")) return KEY_tie;
4576 if (strEQ(d,"tell")) return -KEY_tell;
4577 if (strEQ(d,"tied")) return KEY_tied;
4578 if (strEQ(d,"time")) return -KEY_time;
4581 if (strEQ(d,"times")) return -KEY_times;
4584 if (strEQ(d,"telldir")) return -KEY_telldir;
4587 if (strEQ(d,"truncate")) return -KEY_truncate;
4594 if (strEQ(d,"uc")) return -KEY_uc;
4597 if (strEQ(d,"use")) return KEY_use;
4600 if (strEQ(d,"undef")) return KEY_undef;
4601 if (strEQ(d,"until")) return KEY_until;
4602 if (strEQ(d,"untie")) return KEY_untie;
4603 if (strEQ(d,"utime")) return -KEY_utime;
4604 if (strEQ(d,"umask")) return -KEY_umask;
4607 if (strEQ(d,"unless")) return KEY_unless;
4608 if (strEQ(d,"unpack")) return -KEY_unpack;
4609 if (strEQ(d,"unlink")) return -KEY_unlink;
4612 if (strEQ(d,"unshift")) return KEY_unshift;
4613 if (strEQ(d,"ucfirst")) return -KEY_ucfirst;
4618 if (strEQ(d,"values")) return -KEY_values;
4619 if (strEQ(d,"vec")) return -KEY_vec;
4624 if (strEQ(d,"warn")) return -KEY_warn;
4625 if (strEQ(d,"wait")) return -KEY_wait;
4628 if (strEQ(d,"while")) return KEY_while;
4629 if (strEQ(d,"write")) return -KEY_write;
4632 if (strEQ(d,"waitpid")) return -KEY_waitpid;
4635 if (strEQ(d,"wantarray")) return -KEY_wantarray;
4640 if (len == 1) return -KEY_x;
4641 if (strEQ(d,"xor")) return -KEY_xor;
4644 if (len == 1) return KEY_y;
4653 checkcomma(register char *s, char *name, char *what)
4657 if (dowarn && *s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
4659 for (w = s+2; *w && level; w++) {
4666 for (; *w && isSPACE(*w); w++) ;
4667 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
4668 warn("%s (...) interpreted as function",name);
4670 while (s < bufend && isSPACE(*s))
4674 while (s < bufend && isSPACE(*s))
4676 if (isIDFIRST(*s)) {
4680 while (s < bufend && isSPACE(*s))
4685 kw = keyword(w, s - w) || perl_get_cv(w, FALSE) != 0;
4689 croak("No comma allowed after %s", what);
4695 scan_word(register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
4697 register char *d = dest;
4698 register char *e = d + destlen - 3; /* two-character token, ending NUL */
4701 croak(ident_too_long);
4704 else if (*s == '\'' && allow_package && isIDFIRST(s[1])) {
4709 else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') {
4722 scan_ident(register char *s, register char *send, char *dest, STRLEN destlen, I32 ck_uni)
4729 if (lex_brackets == 0)
4734 e = d + destlen - 3; /* two-character token, ending NUL */
4736 while (isDIGIT(*s)) {
4738 croak(ident_too_long);
4745 croak(ident_too_long);
4748 else if (*s == '\'' && isIDFIRST(s[1])) {
4753 else if (*s == ':' && s[1] == ':') {
4764 if (lex_state != LEX_NORMAL)
4765 lex_state = LEX_INTERPENDMAYBE;
4768 if (*s == '$' && s[1] &&
4769 (isALNUM(s[1]) || strchr("${", s[1]) || strnEQ(s+1,"::",2)) )
4771 if (isDIGIT(s[1]) && lex_state == LEX_INTERPNORMAL)
4772 deprecate("\"$$<digit>\" to mean \"${$}<digit>\"");
4785 if (*d == '^' && *s && (isUPPER(*s) || strchr("[\\]^_?", *s))) {
4790 if (isSPACE(s[-1])) {
4793 if (ch != ' ' && ch != '\t') {
4799 if (isIDFIRST(*d)) {
4801 while (isALNUM(*s) || *s == ':')
4804 while (s < send && (*s == ' ' || *s == '\t')) s++;
4805 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
4806 if (dowarn && keyword(dest, d - dest)) {
4807 char *brack = *s == '[' ? "[...]" : "{...}";
4808 warn("Ambiguous use of %c{%s%s} resolved to %c%s%s",
4809 funny, dest, brack, funny, dest, brack);
4811 lex_fakebrack = lex_brackets+1;
4813 lex_brackstack[lex_brackets++] = XOPERATOR;
4819 if (lex_state == LEX_INTERPNORMAL && !lex_brackets)
4820 lex_state = LEX_INTERPEND;
4823 if (dowarn && lex_state == LEX_NORMAL &&
4824 (keyword(dest, d - dest) || perl_get_cv(dest, FALSE)))
4825 warn("Ambiguous use of %c{%s} resolved to %c%s",
4826 funny, dest, funny, dest);
4829 s = bracket; /* let the parser handle it */
4833 else if (lex_state == LEX_INTERPNORMAL && !lex_brackets && !intuit_more(s))
4834 lex_state = LEX_INTERPEND;
4838 void pmflag(U16 *pmfl, int ch)
4843 *pmfl |= PMf_GLOBAL;
4845 *pmfl |= PMf_CONTINUE;
4849 *pmfl |= PMf_MULTILINE;
4851 *pmfl |= PMf_SINGLELINE;
4853 *pmfl |= PMf_TAINTMEM;
4855 *pmfl |= PMf_EXTENDED;
4859 scan_pat(char *start)
4864 s = scan_str(start);
4867 SvREFCNT_dec(lex_stuff);
4869 croak("Search pattern not terminated");
4872 pm = (PMOP*)newPMOP(OP_MATCH, 0);
4873 if (multi_open == '?')
4874 pm->op_pmflags |= PMf_ONCE;
4875 while (*s && strchr("iogcmstx", *s))
4876 pmflag(&pm->op_pmflags,*s++);
4877 pm->op_pmpermflags = pm->op_pmflags;
4880 yylval.ival = OP_MATCH;
4885 scan_subst(char *start)
4892 yylval.ival = OP_NULL;
4894 s = scan_str(start);
4898 SvREFCNT_dec(lex_stuff);
4900 croak("Substitution pattern not terminated");
4903 if (s[-1] == multi_open)
4906 first_start = multi_start;
4910 SvREFCNT_dec(lex_stuff);
4913 SvREFCNT_dec(lex_repl);
4915 croak("Substitution replacement not terminated");
4917 multi_start = first_start; /* so whole substitution is taken together */
4919 pm = (PMOP*)newPMOP(OP_SUBST, 0);
4925 else if (strchr("iogcmstx", *s))
4926 pmflag(&pm->op_pmflags,*s++);
4933 pm->op_pmflags |= PMf_EVAL;
4934 repl = newSVpv("",0);
4936 sv_catpv(repl, es ? "eval " : "do ");
4937 sv_catpvn(repl, "{ ", 2);
4938 sv_catsv(repl, lex_repl);
4939 sv_catpvn(repl, " };", 2);
4940 SvCOMPILED_on(repl);
4941 SvREFCNT_dec(lex_repl);
4945 pm->op_pmpermflags = pm->op_pmflags;
4947 yylval.ival = OP_SUBST;
4952 scan_trans(char *start)
4961 yylval.ival = OP_NULL;
4963 s = scan_str(start);
4966 SvREFCNT_dec(lex_stuff);
4968 croak("Transliteration pattern not terminated");
4970 if (s[-1] == multi_open)
4976 SvREFCNT_dec(lex_stuff);
4979 SvREFCNT_dec(lex_repl);
4981 croak("Transliteration replacement not terminated");
4984 New(803,tbl,256,short);
4985 o = newPVOP(OP_TRANS, 0, (char*)tbl);
4987 complement = Delete = squash = 0;
4988 while (*s == 'c' || *s == 'd' || *s == 's') {
4990 complement = OPpTRANS_COMPLEMENT;
4992 Delete = OPpTRANS_DELETE;
4994 squash = OPpTRANS_SQUASH;
4997 o->op_private = Delete|squash|complement;
5000 yylval.ival = OP_TRANS;
5005 scan_heredoc(register char *s)
5009 I32 op_type = OP_SCALAR;
5016 int outer = (rsfp && !(lex_inwhat == OP_SCALAR));
5020 e = tokenbuf + sizeof tokenbuf - 1;
5023 for (peek = s; *peek == ' ' || *peek == '\t'; peek++) ;
5024 if (*peek && strchr("`'\"",*peek)) {
5027 s = delimcpy(d, e, s, bufend, term, &len);
5038 deprecate("bare << to mean <<\"\"");
5039 for (; isALNUM(*s); s++) {
5044 if (d >= tokenbuf + sizeof tokenbuf - 1)
5045 croak("Delimiter for here document is too long");
5050 if (outer || !(d=ninstr(s,bufend,d,d+1)))
5051 herewas = newSVpv(s,bufend-s);
5053 s--, herewas = newSVpv(s,d-s);
5054 s += SvCUR(herewas);
5056 tmpstr = NEWSV(87,80);
5057 sv_upgrade(tmpstr, SVt_PVIV);
5062 else if (term == '`') {
5063 op_type = OP_BACKTICK;
5064 SvIVX(tmpstr) = '\\';
5068 multi_start = curcop->cop_line;
5069 multi_open = multi_close = '<';
5073 while (s < bufend &&
5074 (*s != term || memNE(s,tokenbuf,len)) ) {
5079 curcop->cop_line = multi_start;
5080 missingterm(tokenbuf);
5082 sv_setpvn(tmpstr,d+1,s-d);
5084 curcop->cop_line++; /* the preceding stmt passes a newline */
5086 sv_catpvn(herewas,s,bufend-s);
5087 sv_setsv(linestr,herewas);
5088 oldoldbufptr = oldbufptr = bufptr = s = linestart = SvPVX(linestr);
5089 bufend = SvPVX(linestr) + SvCUR(linestr);
5092 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
5093 while (s >= bufend) { /* multiple line string? */
5095 !(oldoldbufptr = oldbufptr = s = linestart = filter_gets(linestr, rsfp, 0))) {
5096 curcop->cop_line = multi_start;
5097 missingterm(tokenbuf);
5100 if (PERLDB_LINE && curstash != debstash) {
5101 SV *sv = NEWSV(88,0);
5103 sv_upgrade(sv, SVt_PVMG);
5104 sv_setsv(sv,linestr);
5105 av_store(GvAV(curcop->cop_filegv),
5106 (I32)curcop->cop_line,sv);
5108 bufend = SvPVX(linestr) + SvCUR(linestr);
5109 if (*s == term && memEQ(s,tokenbuf,len)) {
5112 sv_catsv(linestr,herewas);
5113 bufend = SvPVX(linestr) + SvCUR(linestr);
5117 sv_catsv(tmpstr,linestr);
5120 multi_end = curcop->cop_line;
5122 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
5123 SvLEN_set(tmpstr, SvCUR(tmpstr) + 1);
5124 Renew(SvPVX(tmpstr), SvLEN(tmpstr), char);
5126 SvREFCNT_dec(herewas);
5128 yylval.ival = op_type;
5133 takes: current position in input buffer
5134 returns: new position in input buffer
5135 side-effects: yylval and lex_op are set.
5140 <FH> read from filehandle
5141 <pkg::FH> read from package qualified filehandle
5142 <pkg'FH> read from package qualified filehandle
5143 <$fh> read from filehandle in $fh
5149 scan_inputsymbol(char *start)
5151 register char *s = start; /* current position in buffer */
5156 d = tokenbuf; /* start of temp holding space */
5157 e = tokenbuf + sizeof tokenbuf; /* end of temp holding space */
5158 s = delimcpy(d, e, s + 1, bufend, '>', &len); /* extract until > */
5160 /* die if we didn't have space for the contents of the <>,
5164 if (len >= sizeof tokenbuf)
5165 croak("Excessively long <> operator");
5167 croak("Unterminated <> operator");
5172 Remember, only scalar variables are interpreted as filehandles by
5173 this code. Anything more complex (e.g., <$fh{$num}>) will be
5174 treated as a glob() call.
5175 This code makes use of the fact that except for the $ at the front,
5176 a scalar variable and a filehandle look the same.
5178 if (*d == '$' && d[1]) d++;
5180 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
5181 while (*d && (isALNUM(*d) || *d == '\'' || *d == ':'))
5184 /* If we've tried to read what we allow filehandles to look like, and
5185 there's still text left, then it must be a glob() and not a getline.
5186 Use scan_str to pull out the stuff between the <> and treat it
5187 as nothing more than a string.
5190 if (d - tokenbuf != len) {
5191 yylval.ival = OP_GLOB;
5193 s = scan_str(start);
5195 croak("Glob not terminated");
5199 /* we're in a filehandle read situation */
5202 /* turn <> into <ARGV> */
5204 (void)strcpy(d,"ARGV");
5206 /* if <$fh>, create the ops to turn the variable into a
5212 /* try to find it in the pad for this block, otherwise find
5213 add symbol table ops
5215 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
5216 OP *o = newOP(OP_PADSV, 0);
5218 lex_op = (OP*)newUNOP(OP_READLINE, 0, newUNOP(OP_RV2GV, 0, o));
5221 GV *gv = gv_fetchpv(d+1,TRUE, SVt_PV);
5222 lex_op = (OP*)newUNOP(OP_READLINE, 0,
5223 newUNOP(OP_RV2GV, 0,
5224 newUNOP(OP_RV2SV, 0,
5225 newGVOP(OP_GV, 0, gv))));
5227 /* we created the ops in lex_op, so make yylval.ival a null op */
5228 yylval.ival = OP_NULL;
5231 /* If it's none of the above, it must be a literal filehandle
5232 (<Foo::BAR> or <FOO>) so build a simple readline OP */
5234 GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO);
5235 lex_op = (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
5236 yylval.ival = OP_NULL;
5245 takes: start position in buffer
5246 returns: position to continue reading from buffer
5247 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
5248 updates the read buffer.
5250 This subroutine pulls a string out of the input. It is called for:
5251 q single quotes q(literal text)
5252 ' single quotes 'literal text'
5253 qq double quotes qq(interpolate $here please)
5254 " double quotes "interpolate $here please"
5255 qx backticks qx(/bin/ls -l)
5256 ` backticks `/bin/ls -l`
5257 qw quote words @EXPORT_OK = qw( func() $spam )
5258 m// regexp match m/this/
5259 s/// regexp substitute s/this/that/
5260 tr/// string transliterate tr/this/that/
5261 y/// string transliterate y/this/that/
5262 ($*@) sub prototypes sub foo ($)
5263 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
5265 In most of these cases (all but <>, patterns and transliterate)
5266 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
5267 calls scan_str(). s/// makes yylex() call scan_subst() which calls
5268 scan_str(). tr/// and y/// make yylex() call scan_trans() which
5271 It skips whitespace before the string starts, and treats the first
5272 character as the delimiter. If the delimiter is one of ([{< then
5273 the corresponding "close" character )]}> is used as the closing
5274 delimiter. It allows quoting of delimiters, and if the string has
5275 balanced delimiters ([{<>}]) it allows nesting.
5277 The lexer always reads these strings into lex_stuff, except in the
5278 case of the operators which take *two* arguments (s/// and tr///)
5279 when it checks to see if lex_stuff is full (presumably with the 1st
5280 arg to s or tr) and if so puts the string into lex_repl.
5285 scan_str(char *start)
5288 SV *sv; /* scalar value: string */
5289 char *tmps; /* temp string, used for delimiter matching */
5290 register char *s = start; /* current position in the buffer */
5291 register char term; /* terminating character */
5292 register char *to; /* current position in the sv's data */
5293 I32 brackets = 1; /* bracket nesting level */
5295 /* skip space before the delimiter */
5299 /* mark where we are, in case we need to report errors */
5302 /* after skipping whitespace, the next character is the terminator */
5304 /* mark where we are */
5305 multi_start = curcop->cop_line;
5308 /* find corresponding closing delimiter */
5309 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
5313 /* create a new SV to hold the contents. 87 is leak category, I'm
5314 assuming. 80 is the SV's initial length. What a random number. */
5316 sv_upgrade(sv, SVt_PVIV);
5318 (void)SvPOK_only(sv); /* validate pointer */
5320 /* move past delimiter and try to read a complete string */
5323 /* extend sv if need be */
5324 SvGROW(sv, SvCUR(sv) + (bufend - s) + 1);
5325 /* set 'to' to the next character in the sv's string */
5326 to = SvPVX(sv)+SvCUR(sv);
5328 /* if open delimiter is the close delimiter read unbridle */
5329 if (multi_open == multi_close) {
5330 for (; s < bufend; s++,to++) {
5331 /* embedded newlines increment the current line number */
5332 if (*s == '\n' && !rsfp)
5334 /* handle quoted delimiters */
5335 if (*s == '\\' && s+1 < bufend && term != '\\') {
5338 /* any other quotes are simply copied straight through */
5342 /* terminate when run out of buffer (the for() condition), or
5343 have found the terminator */
5344 else if (*s == term)
5350 /* if the terminator isn't the same as the start character (e.g.,
5351 matched brackets), we have to allow more in the quoting, and
5352 be prepared for nested brackets.
5355 /* read until we run out of string, or we find the terminator */
5356 for (; s < bufend; s++,to++) {
5357 /* embedded newlines increment the line count */
5358 if (*s == '\n' && !rsfp)
5360 /* backslashes can escape the open or closing characters */
5361 if (*s == '\\' && s+1 < bufend) {
5362 if ((s[1] == multi_open) || (s[1] == multi_close))
5367 /* allow nested opens and closes */
5368 else if (*s == multi_close && --brackets <= 0)
5370 else if (*s == multi_open)
5375 /* terminate the copied string and update the sv's end-of-string */
5377 SvCUR_set(sv, to - SvPVX(sv));
5380 * this next chunk reads more into the buffer if we're not done yet
5383 if (s < bufend) break; /* handle case where we are done yet :-) */
5385 /* if we're out of file, or a read fails, bail and reset the current
5386 line marker so we can report where the unterminated string began
5389 !(oldoldbufptr = oldbufptr = s = linestart = filter_gets(linestr, rsfp, 0))) {
5391 curcop->cop_line = multi_start;
5394 /* we read a line, so increment our line counter */
5397 /* update debugger info */
5398 if (PERLDB_LINE && curstash != debstash) {
5399 SV *sv = NEWSV(88,0);
5401 sv_upgrade(sv, SVt_PVMG);
5402 sv_setsv(sv,linestr);
5403 av_store(GvAV(curcop->cop_filegv),
5404 (I32)curcop->cop_line, sv);
5407 /* having changed the buffer, we must update bufend */
5408 bufend = SvPVX(linestr) + SvCUR(linestr);
5411 /* at this point, we have successfully read the delimited string */
5413 multi_end = curcop->cop_line;
5416 /* if we allocated too much space, give some back */
5417 if (SvCUR(sv) + 5 < SvLEN(sv)) {
5418 SvLEN_set(sv, SvCUR(sv) + 1);
5419 Renew(SvPVX(sv), SvLEN(sv), char);
5422 /* decide whether this is the first or second quoted string we've read
5435 takes: pointer to position in buffer
5436 returns: pointer to new position in buffer
5437 side-effects: builds ops for the constant in yylval.op
5439 Read a number in any of the formats that Perl accepts:
5441 0(x[0-7A-F]+)|([0-7]+)
5442 [\d_]+(\.[\d_]*)?[Ee](\d+)
5444 Underbars (_) are allowed in decimal numbers. If -w is on,
5445 underbars before a decimal point must be at three digit intervals.
5447 Like most scan_ routines, it uses the tokenbuf buffer to hold the
5450 If it reads a number without a decimal point or an exponent, it will
5451 try converting the number to an integer and see if it can do so
5452 without loss of precision.
5456 scan_num(char *start)
5458 register char *s = start; /* current position in buffer */
5459 register char *d; /* destination in temp buffer */
5460 register char *e; /* end of temp buffer */
5461 I32 tryiv; /* used to see if it can be an int */
5462 double value; /* number read, as a double */
5463 SV *sv; /* place to put the converted number */
5464 I32 floatit; /* boolean: int or float? */
5465 char *lastub = 0; /* position of last underbar */
5466 static char number_too_long[] = "Number too long";
5468 /* We use the first character to decide what type of number this is */
5472 croak("panic: scan_num");
5474 /* if it starts with a 0, it could be an octal number, a decimal in
5475 0.13 disguise, or a hexadecimal number.
5480 u holds the "number so far"
5481 shift the power of 2 of the base (hex == 4, octal == 3)
5482 overflowed was the number more than we can hold?
5484 Shift is used when we add a digit. It also serves as an "are
5485 we in octal or hex?" indicator to disallow hex characters when
5490 bool overflowed = FALSE;
5497 /* check for a decimal in disguise */
5498 else if (s[1] == '.')
5500 /* so it must be octal */
5505 /* read the rest of the octal number */
5507 UV n, b; /* n is used in the overflow test, b is the digit we're adding on */
5511 /* if we don't mention it, we're done */
5520 /* 8 and 9 are not octal */
5523 yyerror("Illegal octal digit");
5527 case '0': case '1': case '2': case '3': case '4':
5528 case '5': case '6': case '7':
5529 b = *s++ & 15; /* ASCII digit -> value of digit */
5533 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
5534 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
5535 /* make sure they said 0x */
5540 /* Prepare to put the digit we have onto the end
5541 of the number so far. We check for overflows.
5545 n = u << shift; /* make room for the digit */
5546 if (!overflowed && (n >> shift) != u) {
5547 warn("Integer overflow in %s number",
5548 (shift == 4) ? "hex" : "octal");
5551 u = n | b; /* add the digit to the end */
5556 /* if we get here, we had success: make a scalar value from
5566 handle decimal numbers.
5567 we're also sent here when we read a 0 as the first digit
5569 case '1': case '2': case '3': case '4': case '5':
5570 case '6': case '7': case '8': case '9': case '.':
5573 e = tokenbuf + sizeof tokenbuf - 6; /* room for various punctuation */
5576 /* read next group of digits and _ and copy into d */
5577 while (isDIGIT(*s) || *s == '_') {
5578 /* skip underscores, checking for misplaced ones
5582 if (dowarn && lastub && s - lastub != 3)
5583 warn("Misplaced _ in number");
5587 /* check for end of fixed-length buffer */
5589 croak(number_too_long);
5590 /* if we're ok, copy the character */
5595 /* final misplaced underbar check */
5596 if (dowarn && lastub && s - lastub != 3)
5597 warn("Misplaced _ in number");
5599 /* read a decimal portion if there is one. avoid
5600 3..5 being interpreted as the number 3. followed
5603 if (*s == '.' && s[1] != '.') {
5607 /* copy, ignoring underbars, until we run out of
5608 digits. Note: no misplaced underbar checks!
5610 for (; isDIGIT(*s) || *s == '_'; s++) {
5611 /* fixed length buffer check */
5613 croak(number_too_long);
5619 /* read exponent part, if present */
5620 if (*s && strchr("eE",*s) && strchr("+-0123456789",s[1])) {
5624 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
5625 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
5627 /* allow positive or negative exponent */
5628 if (*s == '+' || *s == '-')
5631 /* read digits of exponent (no underbars :-) */
5632 while (isDIGIT(*s)) {
5634 croak(number_too_long);
5639 /* terminate the string */
5642 /* make an sv from the string */
5644 /* reset numeric locale in case we were earlier left in Swaziland */
5645 SET_NUMERIC_STANDARD();
5646 value = atof(tokenbuf);
5649 See if we can make do with an integer value without loss of
5650 precision. We use I_V to cast to an int, because some
5651 compilers have issues. Then we try casting it back and see
5652 if it was the same. We only do this if we know we
5653 specifically read an integer.
5655 Note: if floatit is true, then we don't need to do the
5659 if (!floatit && (double)tryiv == value)
5660 sv_setiv(sv, tryiv);
5662 sv_setnv(sv, value);
5666 /* make the op for the constant and return */
5668 yylval.opval = newSVOP(OP_CONST, 0, sv);
5674 scan_formline(register char *s)
5679 SV *stuff = newSVpv("",0);
5680 bool needargs = FALSE;
5683 if (*s == '.' || *s == '}') {
5685 for (t = s+1; *t == ' ' || *t == '\t'; t++) ;
5689 if (in_eval && !rsfp) {
5690 eol = strchr(s,'\n');
5695 eol = bufend = SvPVX(linestr) + SvCUR(linestr);
5697 for (t = s; t < eol; t++) {
5698 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
5700 goto enough; /* ~~ must be first line in formline */
5702 if (*t == '@' || *t == '^')
5705 sv_catpvn(stuff, s, eol-s);
5709 s = filter_gets(linestr, rsfp, 0);
5710 oldoldbufptr = oldbufptr = bufptr = linestart = SvPVX(linestr);
5711 bufend = bufptr + SvCUR(linestr);
5714 yyerror("Format not terminated");
5724 lex_state = LEX_NORMAL;
5725 nextval[nexttoke].ival = 0;
5729 lex_state = LEX_FORMLINE;
5730 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff);
5732 nextval[nexttoke].ival = OP_FORMLINE;
5736 SvREFCNT_dec(stuff);
5748 cshlen = strlen(cshname);
5753 start_subparse(I32 is_format, U32 flags)
5756 I32 oldsavestack_ix = savestack_ix;
5757 CV* outsidecv = compcv;
5761 assert(SvTYPE(compcv) == SVt_PVCV);
5768 SAVESPTR(comppad_name);
5770 SAVEI32(comppad_name_fill);
5771 SAVEI32(min_intro_pending);
5772 SAVEI32(max_intro_pending);
5773 SAVEI32(pad_reset_pending);
5775 compcv = (CV*)NEWSV(1104,0);
5776 sv_upgrade((SV *)compcv, is_format ? SVt_PVFM : SVt_PVCV);
5777 CvFLAGS(compcv) |= flags;
5780 av_push(comppad, Nullsv);
5781 curpad = AvARRAY(comppad);
5782 comppad_name = newAV();
5783 comppad_name_fill = 0;
5784 min_intro_pending = 0;
5786 subline = curcop->cop_line;
5788 av_store(comppad_name, 0, newSVpv("@_", 2));
5789 curpad[0] = (SV*)newAV();
5790 SvPADMY_on(curpad[0]); /* XXX Needed? */
5791 CvOWNER(compcv) = 0;
5792 New(666, CvMUTEXP(compcv), 1, perl_mutex);
5793 MUTEX_INIT(CvMUTEXP(compcv));
5794 #endif /* USE_THREADS */
5796 comppadlist = newAV();
5797 AvREAL_off(comppadlist);
5798 av_store(comppadlist, 0, (SV*)comppad_name);
5799 av_store(comppadlist, 1, (SV*)comppad);
5801 CvPADLIST(compcv) = comppadlist;
5802 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc(outsidecv);
5804 CvOWNER(compcv) = 0;
5805 New(666, CvMUTEXP(compcv), 1, perl_mutex);
5806 MUTEX_INIT(CvMUTEXP(compcv));
5807 #endif /* USE_THREADS */
5809 return oldsavestack_ix;
5828 char *context = NULL;
5832 if (!yychar || (yychar == ';' && !rsfp))
5834 else if (bufptr > oldoldbufptr && bufptr - oldoldbufptr < 200 &&
5835 oldoldbufptr != oldbufptr && oldbufptr != bufptr) {
5836 while (isSPACE(*oldoldbufptr))
5838 context = oldoldbufptr;
5839 contlen = bufptr - oldoldbufptr;
5841 else if (bufptr > oldbufptr && bufptr - oldbufptr < 200 &&
5842 oldbufptr != bufptr) {
5843 while (isSPACE(*oldbufptr))
5845 context = oldbufptr;
5846 contlen = bufptr - oldbufptr;
5848 else if (yychar > 255)
5849 where = "next token ???";
5850 else if ((yychar & 127) == 127) {
5851 if (lex_state == LEX_NORMAL ||
5852 (lex_state == LEX_KNOWNEXT && lex_defer == LEX_NORMAL))
5853 where = "at end of line";
5855 where = "within pattern";
5857 where = "within string";
5860 SV *where_sv = sv_2mortal(newSVpv("next char ", 0));
5862 sv_catpvf(where_sv, "^%c", toCTRL(yychar));
5863 else if (isPRINT_LC(yychar))
5864 sv_catpvf(where_sv, "%c", yychar);
5866 sv_catpvf(where_sv, "\\%03o", yychar & 255);
5867 where = SvPVX(where_sv);
5869 msg = sv_2mortal(newSVpv(s, 0));
5870 sv_catpvf(msg, " at %_ line %ld, ",
5871 GvSV(curcop->cop_filegv), (long)curcop->cop_line);
5873 sv_catpvf(msg, "near \"%.*s\"\n", contlen, context);
5875 sv_catpvf(msg, "%s\n", where);
5876 if (multi_start < multi_end && (U32)(curcop->cop_line - multi_end) <= 1) {
5878 " (Might be a runaway multi-line %c%c string starting on line %ld)\n",
5879 (int)multi_open,(int)multi_close,(long)multi_start);
5885 sv_catsv(ERRSV, msg);
5887 PerlIO_write(PerlIO_stderr(), SvPVX(msg), SvCUR(msg));
5888 if (++error_count >= 10)
5889 croak("%_ has too many errors.\n", GvSV(curcop->cop_filegv));
5891 in_my_stash = Nullhv;