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))
324 /* a safe way to store a small integer in a pointer */
325 expect = (expectation)((char *)e - tokenbuf);
329 restore_lex_expect(e)
332 /* a safe way to store a small integer in a pointer */
333 lex_expect = (expectation)((char *)e - tokenbuf);
348 while (*s == ' ' || *s == '\t') s++;
349 if (strnEQ(s, "line ", 5)) {
358 while (*s == ' ' || *s == '\t')
360 if (*s == '"' && (t = strchr(s+1, '"')))
364 return; /* false alarm */
365 for (t = s; !isSPACE(*t); t++) ;
370 curcop->cop_filegv = gv_fetchfile(s);
372 curcop->cop_filegv = gv_fetchfile(origfilename);
374 curcop->cop_line = atoi(n)-1;
378 skipspace(register char *s)
381 if (lex_formbrack && lex_brackets <= lex_formbrack) {
382 while (s < bufend && (*s == ' ' || *s == '\t'))
388 while (s < bufend && isSPACE(*s))
390 if (s < bufend && *s == '#') {
391 while (s < bufend && *s != '\n')
396 if (s < bufend || !rsfp || lex_state != LEX_NORMAL)
398 if ((s = filter_gets(linestr, rsfp, (prevlen = SvCUR(linestr)))) == Nullch) {
399 if (minus_n || minus_p) {
400 sv_setpv(linestr,minus_p ?
401 ";}continue{print or die qq(-p destination: $!\\n)" :
403 sv_catpv(linestr,";}");
404 minus_n = minus_p = 0;
407 sv_setpv(linestr,";");
408 oldoldbufptr = oldbufptr = bufptr = s = linestart = SvPVX(linestr);
409 bufend = SvPVX(linestr) + SvCUR(linestr);
410 if (preprocess && !in_eval)
411 (void)PerlProc_pclose(rsfp);
412 else if ((PerlIO*)rsfp == PerlIO_stdin())
413 PerlIO_clearerr(rsfp);
415 (void)PerlIO_close(rsfp);
421 linestart = bufptr = s + prevlen;
422 bufend = s + SvCUR(linestr);
425 if (PERLDB_LINE && curstash != debstash) {
426 SV *sv = NEWSV(85,0);
428 sv_upgrade(sv, SVt_PVMG);
429 sv_setpvn(sv,bufptr,bufend-bufptr);
430 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
441 if (oldoldbufptr != last_uni)
443 while (isSPACE(*last_uni))
445 for (s = last_uni; isALNUM(*s) || *s == '-'; s++) ;
446 if ((t = strchr(s, '(')) && t < bufptr)
450 warn("Warning: Use of \"%s\" without parens is ambiguous", last_uni);
457 #define UNI(f) return uni(f,s)
465 last_uni = oldbufptr;
476 #endif /* CRIPPLED_CC */
478 #define LOP(f,x) return lop(f,x,s)
481 lop(I32 f, expectation x, char *s)
488 last_lop = oldbufptr;
504 nexttype[nexttoke] = type;
506 if (lex_state != LEX_KNOWNEXT) {
507 lex_defer = lex_state;
509 lex_state = LEX_KNOWNEXT;
514 force_word(register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
519 start = skipspace(start);
522 (allow_pack && *s == ':') ||
523 (allow_initial_tick && *s == '\'') )
525 s = scan_word(s, tokenbuf, sizeof tokenbuf, allow_pack, &len);
526 if (check_keyword && keyword(tokenbuf, len))
528 if (token == METHOD) {
538 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST,0, newSVpv(tokenbuf,0));
539 nextval[nexttoke].opval->op_private |= OPpCONST_BARE;
546 force_ident(register char *s, int kind)
549 OP* o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
550 nextval[nexttoke].opval = o;
553 dTHR; /* just for in_eval */
554 o->op_private = OPpCONST_ENTERED;
555 /* XXX see note in pp_entereval() for why we forgo typo
556 warnings if the symbol must be introduced in an eval.
558 gv_fetchpv(s, in_eval ? GV_ADDMULTI : TRUE,
559 kind == '$' ? SVt_PV :
560 kind == '@' ? SVt_PVAV :
561 kind == '%' ? SVt_PVHV :
569 force_version(char *s)
571 OP *version = Nullop;
575 /* default VERSION number -- GBARR */
580 for( d=s, c = 1; isDIGIT(*d) || *d == '_' || (*d == '.' && c--); d++);
581 if((*d == ';' || isSPACE(*d)) && *(skipspace(d)) != ',') {
583 /* real VERSION number -- GBARR */
584 version = yylval.opval;
588 /* NOTE: The parser sees the package name and the VERSION swapped */
589 nextval[nexttoke].opval = version;
606 s = SvPV_force(sv, len);
610 while (s < send && *s != '\\')
617 if (s + 1 < send && (s[1] == '\\'))
618 s++; /* all that, just for this */
623 SvCUR_set(sv, d - SvPVX(sv));
631 register I32 op_type = yylval.ival;
633 if (op_type == OP_NULL) {
634 yylval.opval = lex_op;
638 if (op_type == OP_CONST || op_type == OP_READLINE) {
639 SV *sv = q(lex_stuff);
641 char *p = SvPV(sv, len);
642 yylval.opval = (OP*)newSVOP(op_type, 0, newSVpv(p, len));
648 sublex_info.super_state = lex_state;
649 sublex_info.sub_inwhat = op_type;
650 sublex_info.sub_op = lex_op;
651 lex_state = LEX_INTERPPUSH;
655 yylval.opval = lex_op;
669 lex_state = sublex_info.super_state;
671 SAVEI32(lex_brackets);
672 SAVEI32(lex_fakebrack);
673 SAVEI32(lex_casemods);
678 SAVEI16(curcop->cop_line);
681 SAVEPPTR(oldoldbufptr);
684 SAVEPPTR(lex_brackstack);
685 SAVEPPTR(lex_casestack);
690 bufend = bufptr = oldbufptr = oldoldbufptr = linestart = SvPVX(linestr);
691 bufend += SvCUR(linestr);
697 New(899, lex_brackstack, 120, char);
698 New(899, lex_casestack, 12, char);
699 SAVEFREEPV(lex_brackstack);
700 SAVEFREEPV(lex_casestack);
702 *lex_casestack = '\0';
704 lex_state = LEX_INTERPCONCAT;
705 curcop->cop_line = multi_start;
707 lex_inwhat = sublex_info.sub_inwhat;
708 if (lex_inwhat == OP_MATCH || lex_inwhat == OP_SUBST)
709 lex_inpat = sublex_info.sub_op;
721 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv("",0));
725 if (lex_casemods) { /* oops, we've got some unbalanced parens */
726 lex_state = LEX_INTERPCASEMOD;
730 /* Is there a right-hand side to take care of? */
731 if (lex_repl && (lex_inwhat == OP_SUBST || lex_inwhat == OP_TRANS)) {
734 bufend = bufptr = oldbufptr = oldoldbufptr = linestart = SvPVX(linestr);
735 bufend += SvCUR(linestr);
741 *lex_casestack = '\0';
743 if (SvCOMPILED(lex_repl)) {
744 lex_state = LEX_INTERPNORMAL;
748 lex_state = LEX_INTERPCONCAT;
754 bufend = SvPVX(linestr);
755 bufend += SvCUR(linestr);
762 scan_const(char *start)
764 register char *send = bufend;
765 SV *sv = NEWSV(93, send - start);
766 register char *s = start;
767 register char *d = SvPVX(sv);
768 bool dorange = FALSE;
772 ? "\\.^$@AGZdDwWsSbB+*?|()-nrtfeaxc0123456789[{]} \t\n\r\f\v#"
773 : (lex_inwhat & OP_TRANS)
777 while (s < send || dorange) {
778 if (lex_inwhat == OP_TRANS) {
783 SvGROW(sv, SvLEN(sv) + 256);
787 for (i = (U8)*d; i <= max; i++)
792 else if (*s == '-' && s+1 < send && s != start) {
797 else if (*s == '(' && lex_inpat && s[1] == '?') {
799 while (s < send && *s != ')')
801 } else if (s[2] == '{') { /* This should march regcomp.c */
803 char *regparse = s + 3;
806 while (count && (c = *regparse)) {
807 if (c == '\\' && regparse[1])
815 if (*regparse == ')')
818 yyerror("Sequence (?{...}) not terminated or not {}-balanced");
819 while (s < regparse && *s != ')')
823 else if (*s == '#' && lex_inpat &&
824 ((PMOP*)lex_inpat)->op_pmflags & PMf_EXTENDED) {
825 while (s+1 < send && *s != '\n')
828 else if (*s == '@' && s[1] && (isALNUM(s[1]) || strchr(":'{$", s[1])))
830 else if (*s == '$') {
831 if (!lex_inpat) /* not a regexp, so $ must be var */
833 if (s + 1 < send && !strchr("()| \n\t", s[1]))
834 break; /* in regexp, $ might be tail anchor */
836 if (*s == '\\' && s+1 < send) {
838 if (*s && strchr(leaveit, *s)) {
843 if (lex_inwhat == OP_SUBST && !lex_inpat &&
844 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
847 warn("\\%c better written as $%c", *s, *s);
851 if (lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
857 if (lex_inwhat == OP_TRANS) {
865 case '0': case '1': case '2': case '3':
866 case '4': case '5': case '6': case '7':
867 *d++ = scan_oct(s, 3, &len);
871 *d++ = scan_hex(++s, 2, &len);
907 SvCUR_set(sv, d - SvPVX(sv));
910 if (SvCUR(sv) + 5 < SvLEN(sv)) {
911 SvLEN_set(sv, SvCUR(sv) + 1);
912 Renew(SvPVX(sv), SvLEN(sv), char);
915 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
921 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
923 intuit_more(register char *s)
927 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
929 if (*s != '{' && *s != '[')
934 /* In a pattern, so maybe we have {n,m}. */
951 /* On the other hand, maybe we have a character class */
954 if (*s == ']' || *s == '^')
957 int weight = 2; /* let's weigh the evidence */
959 unsigned char un_char = 0, last_un_char;
960 char *send = strchr(s,']');
961 char tmpbuf[sizeof tokenbuf * 4];
963 if (!send) /* has to be an expression */
969 else if (isDIGIT(*s)) {
971 if (isDIGIT(s[1]) && s[2] == ']')
977 for (; s < send; s++) {
978 last_un_char = un_char;
979 un_char = (unsigned char)*s;
984 weight -= seen[un_char] * 10;
986 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
987 if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV))
992 else if (*s == '$' && s[1] &&
993 strchr("[#!%*<>()-=",s[1])) {
994 if (/*{*/ strchr("])} =",s[2]))
1003 if (strchr("wds]",s[1]))
1005 else if (seen['\''] || seen['"'])
1007 else if (strchr("rnftbxcav",s[1]))
1009 else if (isDIGIT(s[1])) {
1011 while (s[1] && isDIGIT(s[1]))
1021 if (strchr("aA01! ",last_un_char))
1023 if (strchr("zZ79~",s[1]))
1027 if (!isALNUM(last_un_char) && !strchr("$@&",last_un_char) &&
1028 isALPHA(*s) && s[1] && isALPHA(s[1])) {
1033 if (keyword(tmpbuf, d - tmpbuf))
1036 if (un_char == last_un_char + 1)
1038 weight -= seen[un_char];
1043 if (weight >= 0) /* probably a character class */
1051 intuit_method(char *start, GV *gv)
1053 char *s = start + (*start == '$');
1054 char tmpbuf[sizeof tokenbuf];
1062 if ((cv = GvCVu(gv))) {
1063 char *proto = SvPVX(cv);
1073 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
1074 if (*start == '$') {
1075 if (gv || last_lop_op == OP_PRINT || isUPPER(*tokenbuf))
1080 return *s == '(' ? FUNCMETH : METHOD;
1082 if (!keyword(tmpbuf, len)) {
1083 indirgv = gv_fetchpv(tmpbuf,FALSE, SVt_PVCV);
1084 if (indirgv && GvCVu(indirgv))
1086 /* filehandle or package name makes it a method */
1087 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
1089 if ((bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
1090 return 0; /* no assumptions -- "=>" quotes bearword */
1091 nextval[nexttoke].opval =
1092 (OP*)newSVOP(OP_CONST, 0,
1094 nextval[nexttoke].opval->op_private =
1099 return *s == '(' ? FUNCMETH : METHOD;
1109 char *pdb = PerlEnv_getenv("PERL5DB");
1113 SETERRNO(0,SS$_NORMAL);
1114 return "BEGIN { require 'perl5db.pl' }";
1120 /* Encoded script support. filter_add() effectively inserts a
1121 * 'pre-processing' function into the current source input stream.
1122 * Note that the filter function only applies to the current source file
1123 * (e.g., it will not affect files 'require'd or 'use'd by this one).
1125 * The datasv parameter (which may be NULL) can be used to pass
1126 * private data to this instance of the filter. The filter function
1127 * can recover the SV using the FILTER_DATA macro and use it to
1128 * store private buffers and state information.
1130 * The supplied datasv parameter is upgraded to a PVIO type
1131 * and the IoDIRP field is used to store the function pointer.
1132 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
1133 * private use must be set using malloc'd pointers.
1135 static int filter_debug = 0;
1138 filter_add(filter_t funcp, SV *datasv)
1140 if (!funcp){ /* temporary handy debugging hack to be deleted */
1141 filter_debug = atoi((char*)datasv);
1145 rsfp_filters = newAV();
1147 datasv = NEWSV(255,0);
1148 if (!SvUPGRADE(datasv, SVt_PVIO))
1149 die("Can't upgrade filter_add data to SVt_PVIO");
1150 IoDIRP(datasv) = (DIR*)funcp; /* stash funcp into spare field */
1152 warn("filter_add func %p (%s)", funcp, SvPV(datasv,na));
1153 av_unshift(rsfp_filters, 1);
1154 av_store(rsfp_filters, 0, datasv) ;
1159 /* Delete most recently added instance of this filter function. */
1161 filter_del(filter_t funcp)
1164 warn("filter_del func %p", funcp);
1165 if (!rsfp_filters || AvFILLp(rsfp_filters)<0)
1167 /* if filter is on top of stack (usual case) just pop it off */
1168 if (IoDIRP(FILTER_DATA(AvFILLp(rsfp_filters))) == (void*)funcp){
1169 sv_free(av_pop(rsfp_filters));
1173 /* we need to search for the correct entry and clear it */
1174 die("filter_del can only delete in reverse order (currently)");
1178 /* Invoke the n'th filter function for the current rsfp. */
1180 filter_read(int idx, SV *buf_sv, int maxlen)
1183 /* 0 = read one text line */
1190 if (idx > AvFILLp(rsfp_filters)){ /* Any more filters? */
1191 /* Provide a default input filter to make life easy. */
1192 /* Note that we append to the line. This is handy. */
1194 warn("filter_read %d: from rsfp\n", idx);
1198 int old_len = SvCUR(buf_sv) ;
1200 /* ensure buf_sv is large enough */
1201 SvGROW(buf_sv, old_len + maxlen) ;
1202 if ((len = PerlIO_read(rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
1203 if (PerlIO_error(rsfp))
1204 return -1; /* error */
1206 return 0 ; /* end of file */
1208 SvCUR_set(buf_sv, old_len + len) ;
1211 if (sv_gets(buf_sv, rsfp, SvCUR(buf_sv)) == NULL) {
1212 if (PerlIO_error(rsfp))
1213 return -1; /* error */
1215 return 0 ; /* end of file */
1219 return SvCUR(buf_sv);
1221 /* Skip this filter slot if filter has been deleted */
1222 if ( (datasv = FILTER_DATA(idx)) == &sv_undef){
1224 warn("filter_read %d: skipped (filter deleted)\n", idx);
1225 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
1227 /* Get function pointer hidden within datasv */
1228 funcp = (filter_t)IoDIRP(datasv);
1230 warn("filter_read %d: via function %p (%s)\n",
1231 idx, funcp, SvPV(datasv,na));
1232 /* Call function. The function is expected to */
1233 /* call "FILTER_READ(idx+1, buf_sv)" first. */
1234 /* Return: <0:error, =0:eof, >0:not eof */
1235 return (*funcp)(idx, buf_sv, maxlen);
1240 filter_gets(register SV *sv, register PerlIO *fp, STRLEN append)
1243 if (!rsfp_filters) {
1244 filter_add(win32_textfilter,NULL);
1250 SvCUR_set(sv, 0); /* start with empty line */
1251 if (FILTER_READ(0, sv, 0) > 0)
1252 return ( SvPVX(sv) ) ;
1257 return (sv_gets(sv, fp, append));
1262 static char* exp_name[] =
1263 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "TERMBLOCK" };
1266 EXT int yychar; /* last token */
1279 if (pending_ident) {
1280 char pit = pending_ident;
1284 if (strchr(tokenbuf,':'))
1285 croak(no_myglob,tokenbuf);
1286 yylval.opval = newOP(OP_PADANY, 0);
1287 yylval.opval->op_targ = pad_allocmy(tokenbuf);
1291 if (!strchr(tokenbuf,':')) {
1293 /* Check for single character per-thread SVs */
1294 if (tokenbuf[0] == '$' && tokenbuf[2] == '\0'
1295 && !isALPHA(tokenbuf[1]) /* Rule out obvious non-threadsvs */
1296 && (tmp = find_threadsv(&tokenbuf[1])) != NOT_IN_PAD)
1298 yylval.opval = newOP(OP_THREADSV, 0);
1299 yylval.opval->op_targ = tmp;
1302 #endif /* USE_THREADS */
1303 if ((tmp = pad_findmy(tokenbuf)) != NOT_IN_PAD) {
1304 if (last_lop_op == OP_SORT &&
1305 tokenbuf[0] == '$' &&
1306 (tokenbuf[1] == 'a' || tokenbuf[1] == 'b')
1309 for (d = in_eval ? oldoldbufptr : linestart;
1310 d < bufend && *d != '\n';
1313 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
1314 croak("Can't use \"my %s\" in sort comparison",
1320 yylval.opval = newOP(OP_PADANY, 0);
1321 yylval.opval->op_targ = tmp;
1326 /* Force them to make up their mind on "@foo". */
1327 if (pit == '@' && lex_state != LEX_NORMAL && !lex_brackets) {
1328 GV *gv = gv_fetchpv(tokenbuf+1, FALSE, SVt_PVAV);
1329 if (!gv || ((tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
1330 yyerror(form("In string, %s now must be written as \\%s",
1331 tokenbuf, tokenbuf));
1334 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf+1, 0));
1335 yylval.opval->op_private = OPpCONST_ENTERED;
1336 gv_fetchpv(tokenbuf+1, in_eval ? GV_ADDMULTI : TRUE,
1337 ((tokenbuf[0] == '$') ? SVt_PV
1338 : (tokenbuf[0] == '@') ? SVt_PVAV
1343 switch (lex_state) {
1345 case LEX_NORMAL: /* Some compilers will produce faster */
1346 case LEX_INTERPNORMAL: /* code if we comment these out. */
1352 yylval = nextval[nexttoke];
1354 lex_state = lex_defer;
1355 expect = lex_expect;
1356 lex_defer = LEX_NORMAL;
1358 return(nexttype[nexttoke]);
1360 case LEX_INTERPCASEMOD:
1362 if (bufptr != bufend && *bufptr != '\\')
1363 croak("panic: INTERPCASEMOD");
1365 if (bufptr == bufend || bufptr[1] == 'E') {
1368 oldmod = lex_casestack[--lex_casemods];
1369 lex_casestack[lex_casemods] = '\0';
1370 if (bufptr != bufend && strchr("LUQ", oldmod)) {
1372 lex_state = LEX_INTERPCONCAT;
1376 if (bufptr != bufend)
1378 lex_state = LEX_INTERPCONCAT;
1383 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
1384 tmp = *s, *s = s[2], s[2] = tmp; /* misordered... */
1385 if (strchr("LU", *s) &&
1386 (strchr(lex_casestack, 'L') || strchr(lex_casestack, 'U')))
1388 lex_casestack[--lex_casemods] = '\0';
1391 if (lex_casemods > 10) {
1392 char* newlb = Renew(lex_casestack, lex_casemods + 2, char);
1393 if (newlb != lex_casestack) {
1395 lex_casestack = newlb;
1398 lex_casestack[lex_casemods++] = *s;
1399 lex_casestack[lex_casemods] = '\0';
1400 lex_state = LEX_INTERPCONCAT;
1401 nextval[nexttoke].ival = 0;
1404 nextval[nexttoke].ival = OP_LCFIRST;
1406 nextval[nexttoke].ival = OP_UCFIRST;
1408 nextval[nexttoke].ival = OP_LC;
1410 nextval[nexttoke].ival = OP_UC;
1412 nextval[nexttoke].ival = OP_QUOTEMETA;
1414 croak("panic: yylex");
1426 case LEX_INTERPPUSH:
1427 return sublex_push();
1429 case LEX_INTERPSTART:
1430 if (bufptr == bufend)
1431 return sublex_done();
1433 lex_dojoin = (*bufptr == '@');
1434 lex_state = LEX_INTERPNORMAL;
1436 nextval[nexttoke].ival = 0;
1439 nextval[nexttoke].opval = newOP(OP_THREADSV, 0);
1440 nextval[nexttoke].opval->op_targ = find_threadsv("\"");
1441 force_next(PRIVATEREF);
1443 force_ident("\"", '$');
1444 #endif /* USE_THREADS */
1445 nextval[nexttoke].ival = 0;
1447 nextval[nexttoke].ival = 0;
1449 nextval[nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
1458 case LEX_INTERPENDMAYBE:
1459 if (intuit_more(bufptr)) {
1460 lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
1468 lex_state = LEX_INTERPCONCAT;
1472 case LEX_INTERPCONCAT:
1475 croak("panic: INTERPCONCAT");
1477 if (bufptr == bufend)
1478 return sublex_done();
1480 if (SvIVX(linestr) == '\'') {
1481 SV *sv = newSVsv(linestr);
1484 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1488 s = scan_const(bufptr);
1490 lex_state = LEX_INTERPCASEMOD;
1492 lex_state = LEX_INTERPSTART;
1496 nextval[nexttoke] = yylval;
1509 lex_state = LEX_NORMAL;
1510 s = scan_formline(bufptr);
1517 oldoldbufptr = oldbufptr;
1520 PerlIO_printf(PerlIO_stderr(), "### Tokener expecting %s at %s\n", exp_name[expect], s);
1526 croak("Unrecognized character \\%03o", *s & 255);
1529 goto fake_eof; /* emulate EOF on ^D or ^Z */
1535 yyerror("Missing right bracket");
1539 goto retry; /* ignore stray nulls */
1542 if (!in_eval && !preambled) {
1544 sv_setpv(linestr,incl_perldb());
1546 sv_catpv(linestr,";");
1548 while(AvFILLp(preambleav) >= 0) {
1549 SV *tmpsv = av_shift(preambleav);
1550 sv_catsv(linestr, tmpsv);
1551 sv_catpv(linestr, ";");
1554 sv_free((SV*)preambleav);
1557 if (minus_n || minus_p) {
1558 sv_catpv(linestr, "LINE: while (<>) {");
1560 sv_catpv(linestr,"chomp;");
1562 GV* gv = gv_fetchpv("::F", TRUE, SVt_PVAV);
1564 GvIMPORTED_AV_on(gv);
1566 if (strchr("/'\"", *splitstr)
1567 && strchr(splitstr + 1, *splitstr))
1568 sv_catpvf(linestr, "@F=split(%s);", splitstr);
1571 s = "'~#\200\1'"; /* surely one char is unused...*/
1572 while (s[1] && strchr(splitstr, *s)) s++;
1574 sv_catpvf(linestr, "@F=split(%s%c",
1575 "q" + (delim == '\''), delim);
1576 for (s = splitstr; *s; s++) {
1578 sv_catpvn(linestr, "\\", 1);
1579 sv_catpvn(linestr, s, 1);
1581 sv_catpvf(linestr, "%c);", delim);
1585 sv_catpv(linestr,"@F=split(' ');");
1588 sv_catpv(linestr, "\n");
1589 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
1590 bufend = SvPVX(linestr) + SvCUR(linestr);
1591 if (PERLDB_LINE && curstash != debstash) {
1592 SV *sv = NEWSV(85,0);
1594 sv_upgrade(sv, SVt_PVMG);
1595 sv_setsv(sv,linestr);
1596 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
1601 if ((s = filter_gets(linestr, rsfp, 0)) == Nullch) {
1604 if (preprocess && !in_eval)
1605 (void)PerlProc_pclose(rsfp);
1606 else if ((PerlIO *)rsfp == PerlIO_stdin())
1607 PerlIO_clearerr(rsfp);
1609 (void)PerlIO_close(rsfp);
1614 if (!in_eval && (minus_n || minus_p)) {
1615 sv_setpv(linestr,minus_p ? ";}continue{print" : "");
1616 sv_catpv(linestr,";}");
1617 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
1618 bufend = SvPVX(linestr) + SvCUR(linestr);
1619 minus_n = minus_p = 0;
1622 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
1623 sv_setpv(linestr,"");
1624 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
1627 if (*s == '#' && s[1] == '!' && instr(s,"perl"))
1630 /* Incest with pod. */
1631 if (*s == '=' && strnEQ(s, "=cut", 4)) {
1632 sv_setpv(linestr, "");
1633 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
1634 bufend = SvPVX(linestr) + SvCUR(linestr);
1639 } while (doextract);
1640 oldoldbufptr = oldbufptr = bufptr = linestart = s;
1641 if (PERLDB_LINE && curstash != debstash) {
1642 SV *sv = NEWSV(85,0);
1644 sv_upgrade(sv, SVt_PVMG);
1645 sv_setsv(sv,linestr);
1646 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
1648 bufend = SvPVX(linestr) + SvCUR(linestr);
1649 if (curcop->cop_line == 1) {
1650 while (s < bufend && isSPACE(*s))
1652 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
1656 if (*s == '#' && *(s+1) == '!')
1658 #ifdef ALTERNATE_SHEBANG
1660 static char as[] = ALTERNATE_SHEBANG;
1661 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
1662 d = s + (sizeof(as) - 1);
1664 #endif /* ALTERNATE_SHEBANG */
1673 while (*d && !isSPACE(*d))
1677 #ifdef ARG_ZERO_IS_SCRIPT
1678 if (ipathend > ipath) {
1680 * HP-UX (at least) sets argv[0] to the script name,
1681 * which makes $^X incorrect. And Digital UNIX and Linux,
1682 * at least, set argv[0] to the basename of the Perl
1683 * interpreter. So, having found "#!", we'll set it right.
1685 SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV));
1686 assert(SvPOK(x) || SvGMAGICAL(x));
1687 if (sv_eq(x, GvSV(curcop->cop_filegv))) {
1688 sv_setpvn(x, ipath, ipathend - ipath);
1691 TAINT_NOT; /* $^X is always tainted, but that's OK */
1693 #endif /* ARG_ZERO_IS_SCRIPT */
1698 d = instr(s,"perl -");
1700 d = instr(s,"perl");
1701 #ifdef ALTERNATE_SHEBANG
1703 * If the ALTERNATE_SHEBANG on this system starts with a
1704 * character that can be part of a Perl expression, then if
1705 * we see it but not "perl", we're probably looking at the
1706 * start of Perl code, not a request to hand off to some
1707 * other interpreter. Similarly, if "perl" is there, but
1708 * not in the first 'word' of the line, we assume the line
1709 * contains the start of the Perl program.
1711 if (d && *s != '#') {
1713 while (*c && !strchr("; \t\r\n\f\v#", *c))
1716 d = Nullch; /* "perl" not in first word; ignore */
1718 *s = '#'; /* Don't try to parse shebang line */
1720 #endif /* ALTERNATE_SHEBANG */
1725 !instr(s,"indir") &&
1726 instr(origargv[0],"perl"))
1732 while (s < bufend && isSPACE(*s))
1735 Newz(899,newargv,origargc+3,char*);
1737 while (s < bufend && !isSPACE(*s))
1740 Copy(origargv+1, newargv+2, origargc+1, char*);
1745 execv(ipath, newargv);
1746 croak("Can't exec %s", ipath);
1749 U32 oldpdb = perldb;
1750 bool oldn = minus_n;
1751 bool oldp = minus_p;
1753 while (*d && !isSPACE(*d)) d++;
1754 while (*d == ' ' || *d == '\t') d++;
1758 if (*d == 'M' || *d == 'm') {
1760 while (*d && !isSPACE(*d)) d++;
1761 croak("Too late for \"-%.*s\" option",
1764 d = moreswitches(d);
1766 if (PERLDB_LINE && !oldpdb ||
1767 ( minus_n || minus_p ) && !(oldn || oldp) )
1768 /* if we have already added "LINE: while (<>) {",
1769 we must not do it again */
1771 sv_setpv(linestr, "");
1772 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
1773 bufend = SvPVX(linestr) + SvCUR(linestr);
1776 (void)gv_fetchfile(origfilename);
1783 if (lex_formbrack && lex_brackets <= lex_formbrack) {
1785 lex_state = LEX_FORMLINE;
1791 warn("Illegal character \\%03o (carriage return)", '\r');
1793 "(Maybe you didn't strip carriage returns after a network transfer?)\n");
1795 case ' ': case '\t': case '\f': case 013:
1800 if (lex_state != LEX_NORMAL || (in_eval && !rsfp)) {
1802 while (s < d && *s != '\n')
1807 if (lex_formbrack && lex_brackets <= lex_formbrack) {
1809 lex_state = LEX_FORMLINE;
1819 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
1824 while (s < bufend && (*s == ' ' || *s == '\t'))
1827 if (strnEQ(s,"=>",2)) {
1829 warn("Ambiguous use of -%c => resolved to \"-%c\" =>",
1830 (int)tmp, (int)tmp);
1831 s = force_word(bufptr,WORD,FALSE,FALSE,FALSE);
1832 OPERATOR('-'); /* unary minus */
1834 last_uni = oldbufptr;
1835 last_lop_op = OP_FTEREAD; /* good enough */
1837 case 'r': FTST(OP_FTEREAD);
1838 case 'w': FTST(OP_FTEWRITE);
1839 case 'x': FTST(OP_FTEEXEC);
1840 case 'o': FTST(OP_FTEOWNED);
1841 case 'R': FTST(OP_FTRREAD);
1842 case 'W': FTST(OP_FTRWRITE);
1843 case 'X': FTST(OP_FTREXEC);
1844 case 'O': FTST(OP_FTROWNED);
1845 case 'e': FTST(OP_FTIS);
1846 case 'z': FTST(OP_FTZERO);
1847 case 's': FTST(OP_FTSIZE);
1848 case 'f': FTST(OP_FTFILE);
1849 case 'd': FTST(OP_FTDIR);
1850 case 'l': FTST(OP_FTLINK);
1851 case 'p': FTST(OP_FTPIPE);
1852 case 'S': FTST(OP_FTSOCK);
1853 case 'u': FTST(OP_FTSUID);
1854 case 'g': FTST(OP_FTSGID);
1855 case 'k': FTST(OP_FTSVTX);
1856 case 'b': FTST(OP_FTBLK);
1857 case 'c': FTST(OP_FTCHR);
1858 case 't': FTST(OP_FTTTY);
1859 case 'T': FTST(OP_FTTEXT);
1860 case 'B': FTST(OP_FTBINARY);
1861 case 'M': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTMTIME);
1862 case 'A': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTATIME);
1863 case 'C': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTCTIME);
1865 croak("Unrecognized file test: -%c", (int)tmp);
1872 if (expect == XOPERATOR)
1877 else if (*s == '>') {
1880 if (isIDFIRST(*s)) {
1881 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
1889 if (expect == XOPERATOR)
1892 if (isSPACE(*s) || !isSPACE(*bufptr))
1894 OPERATOR('-'); /* unary minus */
1901 if (expect == XOPERATOR)
1906 if (expect == XOPERATOR)
1909 if (isSPACE(*s) || !isSPACE(*bufptr))
1915 if (expect != XOPERATOR) {
1916 s = scan_ident(s, bufend, tokenbuf, sizeof tokenbuf, TRUE);
1918 force_ident(tokenbuf, '*');
1931 if (expect == XOPERATOR) {
1936 s = scan_ident(s, bufend, tokenbuf + 1, sizeof tokenbuf - 1, TRUE);
1939 yyerror("Final % should be \\% or %name");
1942 pending_ident = '%';
1964 if (last_lop == oldoldbufptr || last_uni == oldoldbufptr)
1965 oldbufptr = oldoldbufptr; /* allow print(STDOUT 123) */
1970 if (curcop->cop_line < copline)
1971 copline = curcop->cop_line;
1982 if (lex_brackets <= 0)
1983 yyerror("Unmatched right bracket");
1986 if (lex_state == LEX_INTERPNORMAL) {
1987 if (lex_brackets == 0) {
1988 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
1989 lex_state = LEX_INTERPEND;
1996 if (lex_brackets > 100) {
1997 char* newlb = Renew(lex_brackstack, lex_brackets + 1, char);
1998 if (newlb != lex_brackstack) {
2000 lex_brackstack = newlb;
2005 if (lex_formbrack) {
2009 if (oldoldbufptr == last_lop)
2010 lex_brackstack[lex_brackets++] = XTERM;
2012 lex_brackstack[lex_brackets++] = XOPERATOR;
2013 OPERATOR(HASHBRACK);
2015 while (s < bufend && (*s == ' ' || *s == '\t'))
2019 if (d < bufend && *d == '-') {
2022 while (d < bufend && (*d == ' ' || *d == '\t'))
2025 if (d < bufend && isIDFIRST(*d)) {
2026 d = scan_word(d, tokenbuf + 1, sizeof tokenbuf - 1,
2028 while (d < bufend && (*d == ' ' || *d == '\t'))
2031 char minus = (tokenbuf[0] == '-');
2033 (keyword(tokenbuf + 1, len) ||
2034 (minus && len == 1 && isALPHA(tokenbuf[1])) ||
2035 perl_get_cv(tokenbuf + 1, FALSE) ))
2036 warn("Ambiguous use of {%s} resolved to {\"%s\"}",
2037 tokenbuf + !minus, tokenbuf + !minus);
2038 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
2045 lex_brackstack[lex_brackets++] = XSTATE;
2049 lex_brackstack[lex_brackets++] = XOPERATOR;
2054 if (oldoldbufptr == last_lop)
2055 lex_brackstack[lex_brackets++] = XTERM;
2057 lex_brackstack[lex_brackets++] = XOPERATOR;
2060 if (expect == XSTATE) {
2061 lex_brackstack[lex_brackets-1] = XSTATE;
2064 OPERATOR(HASHBRACK);
2066 /* This hack serves to disambiguate a pair of curlies
2067 * as being a block or an anon hash. Normally, expectation
2068 * determines that, but in cases where we're not in a
2069 * position to expect anything in particular (like inside
2070 * eval"") we have to resolve the ambiguity. This code
2071 * covers the case where the first term in the curlies is a
2072 * quoted string. Most other cases need to be explicitly
2073 * disambiguated by prepending a `+' before the opening
2074 * curly in order to force resolution as an anon hash.
2076 * XXX should probably propagate the outer expectation
2077 * into eval"" to rely less on this hack, but that could
2078 * potentially break current behavior of eval"".
2082 if (*s == '\'' || *s == '"' || *s == '`') {
2083 /* common case: get past first string, handling escapes */
2084 for (t++; t < bufend && *t != *s;)
2085 if (*t++ == '\\' && (*t == '\\' || *t == *s))
2089 else if (*s == 'q') {
2092 || ((*t == 'q' || *t == 'x') && ++t < bufend
2093 && !isALNUM(*t)))) {
2095 char open, close, term;
2098 while (t < bufend && isSPACE(*t))
2102 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
2106 for (t++; t < bufend; t++) {
2107 if (*t == '\\' && t+1 < bufend && open != '\\')
2109 else if (*t == open)
2113 for (t++; t < bufend; t++) {
2114 if (*t == '\\' && t+1 < bufend)
2116 else if (*t == close && --brackets <= 0)
2118 else if (*t == open)
2124 else if (isALPHA(*s)) {
2125 for (t++; t < bufend && isALNUM(*t); t++) ;
2127 while (t < bufend && isSPACE(*t))
2129 /* if comma follows first term, call it an anon hash */
2130 /* XXX it could be a comma expression with loop modifiers */
2131 if (t < bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
2132 || (*t == '=' && t[1] == '>')))
2133 OPERATOR(HASHBRACK);
2137 lex_brackstack[lex_brackets-1] = XSTATE;
2143 yylval.ival = curcop->cop_line;
2144 if (isSPACE(*s) || *s == '#')
2145 copline = NOLINE; /* invalidate current command line number */
2150 if (lex_brackets <= 0)
2151 yyerror("Unmatched right bracket");
2153 expect = (expectation)lex_brackstack[--lex_brackets];
2154 if (lex_brackets < lex_formbrack)
2156 if (lex_state == LEX_INTERPNORMAL) {
2157 if (lex_brackets == 0) {
2158 if (lex_fakebrack) {
2159 lex_state = LEX_INTERPEND;
2161 return yylex(); /* ignore fake brackets */
2163 if (*s == '-' && s[1] == '>')
2164 lex_state = LEX_INTERPENDMAYBE;
2165 else if (*s != '[' && *s != '{')
2166 lex_state = LEX_INTERPEND;
2169 if (lex_brackets < lex_fakebrack) {
2172 return yylex(); /* ignore fake brackets */
2182 if (expect == XOPERATOR) {
2183 if (dowarn && isALPHA(*s) && bufptr == linestart) {
2191 s = scan_ident(s - 1, bufend, tokenbuf, sizeof tokenbuf, TRUE);
2194 force_ident(tokenbuf, '&');
2198 yylval.ival = (OPpENTERSUB_AMPER<<8);
2217 if (dowarn && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
2218 warn("Reversed %c= operator",(int)tmp);
2220 if (expect == XSTATE && isALPHA(tmp) &&
2221 (s == linestart+1 || s[-2] == '\n') )
2223 if (in_eval && !rsfp) {
2228 if (strnEQ(s,"=cut",4)) {
2245 if (lex_brackets < lex_formbrack) {
2247 for (t = s; *t == ' ' || *t == '\t'; t++) ;
2248 if (*t == '\n' || *t == '#') {
2266 if (expect != XOPERATOR) {
2267 if (s[1] != '<' && !strchr(s,'>'))
2270 s = scan_heredoc(s);
2272 s = scan_inputsymbol(s);
2273 TERM(sublex_start());
2278 SHop(OP_LEFT_SHIFT);
2292 SHop(OP_RIGHT_SHIFT);
2301 if (expect == XOPERATOR) {
2302 if (lex_formbrack && lex_brackets == lex_formbrack) {
2305 return ','; /* grandfather non-comma-format format */
2309 if (s[1] == '#' && (isALPHA(s[2]) || strchr("_{$:", s[2]))) {
2310 if (expect == XOPERATOR)
2311 no_op("Array length", bufptr);
2313 s = scan_ident(s + 1, bufend, tokenbuf + 1, sizeof tokenbuf - 1,
2318 pending_ident = '#';
2322 if (expect == XOPERATOR)
2323 no_op("Scalar", bufptr);
2325 s = scan_ident(s, bufend, tokenbuf + 1, sizeof tokenbuf - 1, FALSE);
2328 yyerror("Final $ should be \\$ or $name");
2332 /* This kludge not intended to be bulletproof. */
2333 if (tokenbuf[1] == '[' && !tokenbuf[2]) {
2334 yylval.opval = newSVOP(OP_CONST, 0,
2335 newSViv((IV)compiling.cop_arybase));
2336 yylval.opval->op_private = OPpCONST_ARYBASE;
2341 if (lex_state == LEX_NORMAL)
2344 if ((expect != XREF || oldoldbufptr == last_lop) && intuit_more(s)) {
2350 isSPACE(*t) || isALNUM(*t) || *t == '$';
2353 bufptr = skipspace(bufptr);
2354 while (t < bufend && *t != ']')
2356 warn("Multidimensional syntax %.*s not supported",
2357 (t - bufptr) + 1, bufptr);
2361 else if (*s == '{') {
2363 if (dowarn && strEQ(tokenbuf+1, "SIG") &&
2364 (t = strchr(s, '}')) && (t = strchr(t, '=')))
2366 char tmpbuf[sizeof tokenbuf];
2368 for (t++; isSPACE(*t); t++) ;
2369 if (isIDFIRST(*t)) {
2370 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
2371 if (*t != '(' && perl_get_cv(tmpbuf, FALSE))
2372 warn("You need to quote \"%s\"", tmpbuf);
2379 if (lex_state == LEX_NORMAL && isSPACE(*d)) {
2380 bool islop = (last_lop == oldoldbufptr);
2381 if (!islop || last_lop_op == OP_GREPSTART)
2383 else if (strchr("$@\"'`q", *s))
2384 expect = XTERM; /* e.g. print $fh "foo" */
2385 else if (strchr("&*<%", *s) && isIDFIRST(s[1]))
2386 expect = XTERM; /* e.g. print $fh &sub */
2387 else if (isIDFIRST(*s)) {
2388 char tmpbuf[sizeof tokenbuf];
2389 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2390 if (tmp = keyword(tmpbuf, len)) {
2391 /* binary operators exclude handle interpretations */
2403 expect = XTERM; /* e.g. print $fh length() */
2408 GV *gv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
2409 if (gv && GvCVu(gv))
2410 expect = XTERM; /* e.g. print $fh subr() */
2413 else if (isDIGIT(*s))
2414 expect = XTERM; /* e.g. print $fh 3 */
2415 else if (*s == '.' && isDIGIT(s[1]))
2416 expect = XTERM; /* e.g. print $fh .3 */
2417 else if (strchr("/?-+", *s) && !isSPACE(s[1]))
2418 expect = XTERM; /* e.g. print $fh -1 */
2419 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]))
2420 expect = XTERM; /* print $fh <<"EOF" */
2422 pending_ident = '$';
2426 if (expect == XOPERATOR)
2429 s = scan_ident(s, bufend, tokenbuf + 1, sizeof tokenbuf - 1, FALSE);
2432 yyerror("Final @ should be \\@ or @name");
2435 if (lex_state == LEX_NORMAL)
2437 if ((expect != XREF || oldoldbufptr == last_lop) && intuit_more(s)) {
2441 /* Warn about @ where they meant $. */
2443 if (*s == '[' || *s == '{') {
2445 while (*t && (isALNUM(*t) || strchr(" \t$#+-'\"", *t)))
2447 if (*t == '}' || *t == ']') {
2449 bufptr = skipspace(bufptr);
2450 warn("Scalar value %.*s better written as $%.*s",
2451 t-bufptr, bufptr, t-bufptr-1, bufptr+1);
2456 pending_ident = '@';
2459 case '/': /* may either be division or pattern */
2460 case '?': /* may either be conditional or pattern */
2461 if (expect != XOPERATOR) {
2462 /* Disable warning on "study /blah/" */
2463 if (oldoldbufptr == last_uni
2464 && (*last_uni != 's' || s - last_uni < 5
2465 || memNE(last_uni, "study", 5) || isALNUM(last_uni[5])))
2468 TERM(sublex_start());
2476 if (lex_formbrack && lex_brackets == lex_formbrack && s[1] == '\n' &&
2477 (s == linestart || s[-1] == '\n') ) {
2482 if (expect == XOPERATOR || !isDIGIT(s[1])) {
2488 yylval.ival = OPf_SPECIAL;
2494 if (expect != XOPERATOR)
2499 case '0': case '1': case '2': case '3': case '4':
2500 case '5': case '6': case '7': case '8': case '9':
2502 if (expect == XOPERATOR)
2508 if (expect == XOPERATOR) {
2509 if (lex_formbrack && lex_brackets == lex_formbrack) {
2512 return ','; /* grandfather non-comma-format format */
2518 missingterm((char*)0);
2519 yylval.ival = OP_CONST;
2520 TERM(sublex_start());
2524 if (expect == XOPERATOR) {
2525 if (lex_formbrack && lex_brackets == lex_formbrack) {
2528 return ','; /* grandfather non-comma-format format */
2534 missingterm((char*)0);
2535 yylval.ival = OP_CONST;
2536 for (d = SvPV(lex_stuff, len); len; len--, d++) {
2537 if (*d == '$' || *d == '@' || *d == '\\') {
2538 yylval.ival = OP_STRINGIFY;
2542 TERM(sublex_start());
2546 if (expect == XOPERATOR)
2547 no_op("Backticks",s);
2549 missingterm((char*)0);
2550 yylval.ival = OP_BACKTICK;
2552 TERM(sublex_start());
2556 if (dowarn && lex_inwhat && isDIGIT(*s))
2557 warn("Can't use \\%c to mean $%c in expression", *s, *s);
2558 if (expect == XOPERATOR)
2559 no_op("Backslash",s);
2563 if (isDIGIT(s[1]) && expect == XOPERATOR) {
2602 s = scan_word(s, tokenbuf, sizeof tokenbuf, FALSE, &len);
2604 /* Some keywords can be followed by any delimiter, including ':' */
2605 tmp = (len == 1 && strchr("msyq", tokenbuf[0]) ||
2606 len == 2 && ((tokenbuf[0] == 't' && tokenbuf[1] == 'r') ||
2607 (tokenbuf[0] == 'q' &&
2608 strchr("qwx", tokenbuf[1]))));
2610 /* x::* is just a word, unless x is "CORE" */
2611 if (!tmp && *s == ':' && s[1] == ':' && strNE(tokenbuf, "CORE"))
2615 while (d < bufend && isSPACE(*d))
2616 d++; /* no comments skipped here, or s### is misparsed */
2618 /* Is this a label? */
2619 if (!tmp && expect == XSTATE
2620 && d < bufend && *d == ':' && *(d + 1) != ':') {
2622 yylval.pval = savepv(tokenbuf);
2627 /* Check for keywords */
2628 tmp = keyword(tokenbuf, len);
2630 /* Is this a word before a => operator? */
2631 if (strnEQ(d,"=>",2)) {
2633 if (dowarn && (tmp || perl_get_cv(tokenbuf, FALSE)))
2634 warn("Ambiguous use of %s => resolved to \"%s\" =>",
2635 tokenbuf, tokenbuf);
2636 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf,0));
2637 yylval.opval->op_private = OPpCONST_BARE;
2641 if (tmp < 0) { /* second-class keyword? */
2642 if (expect != XOPERATOR && (*s != ':' || s[1] != ':') &&
2643 (((gv = gv_fetchpv(tokenbuf, FALSE, SVt_PVCV)) &&
2644 GvCVu(gv) && GvIMPORTED_CV(gv)) ||
2645 ((gvp = (GV**)hv_fetch(globalstash,tokenbuf,len,FALSE)) &&
2646 (gv = *gvp) != (GV*)&sv_undef &&
2647 GvCVu(gv) && GvIMPORTED_CV(gv))))
2649 tmp = 0; /* overridden by importation */
2652 && -tmp==KEY_lock /* XXX generalizable kludge */
2653 && !hv_fetch(GvHVn(incgv), "Thread.pm", 9, FALSE))
2655 tmp = 0; /* any sub overrides "weak" keyword */
2658 tmp = -tmp; gv = Nullgv; gvp = 0;
2665 default: /* not a keyword */
2668 char lastchar = (bufptr == oldoldbufptr ? 0 : bufptr[-1]);
2670 /* Get the rest if it looks like a package qualifier */
2672 if (*s == '\'' || *s == ':' && s[1] == ':') {
2673 s = scan_word(s, tokenbuf + len, sizeof tokenbuf - len,
2676 croak("Bad name after %s::", tokenbuf);
2679 if (expect == XOPERATOR) {
2680 if (bufptr == linestart) {
2686 no_op("Bareword",s);
2689 /* Look for a subroutine with this name in current package. */
2692 sv = newSVpv("CORE::GLOBAL::",14);
2693 sv_catpv(sv,tokenbuf);
2696 sv = newSVpv(tokenbuf,0);
2698 gv = gv_fetchpv(tokenbuf,FALSE, SVt_PVCV);
2700 /* Presume this is going to be a bareword of some sort. */
2703 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2704 yylval.opval->op_private = OPpCONST_BARE;
2706 /* See if it's the indirect object for a list operator. */
2709 oldoldbufptr < bufptr &&
2710 (oldoldbufptr == last_lop || oldoldbufptr == last_uni) &&
2711 /* NO SKIPSPACE BEFORE HERE! */
2713 ((opargs[last_lop_op] >> OASHIFT)& 7) == OA_FILEREF) )
2715 bool immediate_paren = *s == '(';
2717 /* (Now we can afford to cross potential line boundary.) */
2720 /* Two barewords in a row may indicate method call. */
2722 if ((isALPHA(*s) || *s == '$') && (tmp=intuit_method(s,gv)))
2725 /* If not a declared subroutine, it's an indirect object. */
2726 /* (But it's an indir obj regardless for sort.) */
2728 if ((last_lop_op == OP_SORT ||
2729 (!immediate_paren && (!gv || !GvCVu(gv))) ) &&
2730 (last_lop_op != OP_MAPSTART && last_lop_op != OP_GREPSTART)){
2731 expect = (last_lop == oldoldbufptr) ? XTERM : XOPERATOR;
2736 /* If followed by a paren, it's certainly a subroutine. */
2742 if (gv && GvCVu(gv)) {
2743 for (d = s + 1; *d == ' ' || *d == '\t'; d++) ;
2744 if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) {
2749 nextval[nexttoke].opval = yylval.opval;
2756 /* If followed by var or block, call it a method (unless sub) */
2758 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
2759 last_lop = oldbufptr;
2760 last_lop_op = OP_METHOD;
2764 /* If followed by a bareword, see if it looks like indir obj. */
2766 if ((isALPHA(*s) || *s == '$') && (tmp = intuit_method(s,gv)))
2769 /* Not a method, so call it a subroutine (if defined) */
2771 if (gv && GvCVu(gv)) {
2773 if (lastchar == '-')
2774 warn("Ambiguous use of -%s resolved as -&%s()",
2775 tokenbuf, tokenbuf);
2776 last_lop = oldbufptr;
2777 last_lop_op = OP_ENTERSUB;
2778 /* Check for a constant sub */
2780 if ((sv = cv_const_sv(cv))) {
2782 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
2783 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
2784 yylval.opval->op_private = 0;
2788 /* Resolve to GV now. */
2789 op_free(yylval.opval);
2790 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
2791 /* Is there a prototype? */
2794 char *proto = SvPV((SV*)cv, len);
2797 if (strEQ(proto, "$"))
2799 if (*proto == '&' && *s == '{') {
2800 sv_setpv(subname,"__ANON__");
2804 nextval[nexttoke].opval = yylval.opval;
2810 if (hints & HINT_STRICT_SUBS &&
2813 last_lop_op != OP_TRUNCATE && /* S/F prototype in opcode.pl */
2814 last_lop_op != OP_ACCEPT &&
2815 last_lop_op != OP_PIPE_OP &&
2816 last_lop_op != OP_SOCKPAIR)
2819 "Bareword \"%s\" not allowed while \"strict subs\" in use",
2824 /* Call it a bare word */
2828 if (lastchar != '-') {
2829 for (d = tokenbuf; *d && isLOWER(*d); d++) ;
2831 warn(warn_reserved, tokenbuf);
2834 if (lastchar && strchr("*%&", lastchar)) {
2835 warn("Operator or semicolon missing before %c%s",
2836 lastchar, tokenbuf);
2837 warn("Ambiguous use of %c resolved as operator %c",
2838 lastchar, lastchar);
2844 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
2845 newSVsv(GvSV(curcop->cop_filegv)));
2849 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
2850 newSVpvf("%ld", (long)curcop->cop_line));
2853 case KEY___PACKAGE__:
2854 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
2856 ? newSVsv(curstname)
2865 if (rsfp && (!in_eval || tokenbuf[2] == 'D')) {
2866 char *pname = "main";
2867 if (tokenbuf[2] == 'D')
2868 pname = HvNAME(curstash ? curstash : defstash);
2869 gv = gv_fetchpv(form("%s::DATA", pname), TRUE, SVt_PVIO);
2872 GvIOp(gv) = newIO();
2873 IoIFP(GvIOp(gv)) = rsfp;
2874 #if defined(HAS_FCNTL) && defined(F_SETFD)
2876 int fd = PerlIO_fileno(rsfp);
2877 fcntl(fd,F_SETFD,fd >= 3);
2880 /* Mark this internal pseudo-handle as clean */
2881 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
2883 IoTYPE(GvIOp(gv)) = '|';
2884 else if ((PerlIO*)rsfp == PerlIO_stdin())
2885 IoTYPE(GvIOp(gv)) = '-';
2887 IoTYPE(GvIOp(gv)) = '<';
2898 if (expect == XSTATE) {
2905 if (*s == ':' && s[1] == ':') {
2908 s = scan_word(s, tokenbuf, sizeof tokenbuf, FALSE, &len);
2909 tmp = keyword(tokenbuf, len);
2923 LOP(OP_ACCEPT,XTERM);
2929 LOP(OP_ATAN2,XTERM);
2938 LOP(OP_BLESS,XTERM);
2947 (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */
2967 LOP(OP_CRYPT,XTERM);
2971 for (d = s; d < bufend && (isSPACE(*d) || *d == '('); d++) ;
2972 if (*d != '0' && isDIGIT(*d))
2973 yywarn("chmod: mode argument is missing initial 0");
2975 LOP(OP_CHMOD,XTERM);
2978 LOP(OP_CHOWN,XTERM);
2981 LOP(OP_CONNECT,XTERM);
2997 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3001 hints |= HINT_BLOCK_SCOPE;
3011 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
3012 LOP(OP_DBMOPEN,XTERM);
3018 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3025 yylval.ival = curcop->cop_line;
3039 expect = (*s == '{') ? XTERMBLOCK : XTERM;
3040 UNIBRACK(OP_ENTEREVAL);
3055 case KEY_endhostent:
3061 case KEY_endservent:
3064 case KEY_endprotoent:
3075 yylval.ival = curcop->cop_line;
3077 if (isIDFIRST(*s)) {
3079 if ((bufend - p) >= 3 &&
3080 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
3084 croak("Missing $ on loop variable");
3089 LOP(OP_FORMLINE,XTERM);
3095 LOP(OP_FCNTL,XTERM);
3101 LOP(OP_FLOCK,XTERM);
3110 LOP(OP_GREPSTART, *s == '(' ? XTERM : XREF);
3113 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3128 case KEY_getpriority:
3129 LOP(OP_GETPRIORITY,XTERM);
3131 case KEY_getprotobyname:
3134 case KEY_getprotobynumber:
3135 LOP(OP_GPBYNUMBER,XTERM);
3137 case KEY_getprotoent:
3149 case KEY_getpeername:
3150 UNI(OP_GETPEERNAME);
3152 case KEY_gethostbyname:
3155 case KEY_gethostbyaddr:
3156 LOP(OP_GHBYADDR,XTERM);
3158 case KEY_gethostent:
3161 case KEY_getnetbyname:
3164 case KEY_getnetbyaddr:
3165 LOP(OP_GNBYADDR,XTERM);
3170 case KEY_getservbyname:
3171 LOP(OP_GSBYNAME,XTERM);
3173 case KEY_getservbyport:
3174 LOP(OP_GSBYPORT,XTERM);
3176 case KEY_getservent:
3179 case KEY_getsockname:
3180 UNI(OP_GETSOCKNAME);
3182 case KEY_getsockopt:
3183 LOP(OP_GSOCKOPT,XTERM);
3205 yylval.ival = curcop->cop_line;
3209 LOP(OP_INDEX,XTERM);
3215 LOP(OP_IOCTL,XTERM);
3227 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3258 LOP(OP_LISTEN,XTERM);
3268 TERM(sublex_start());
3271 LOP(OP_MAPSTART,XREF);
3274 LOP(OP_MKDIR,XTERM);
3277 LOP(OP_MSGCTL,XTERM);
3280 LOP(OP_MSGGET,XTERM);
3283 LOP(OP_MSGRCV,XTERM);
3286 LOP(OP_MSGSND,XTERM);
3291 if (isIDFIRST(*s)) {
3292 s = scan_word(s, tokenbuf, sizeof tokenbuf, TRUE, &len);
3293 in_my_stash = gv_stashpv(tokenbuf, FALSE);
3297 sprintf(tmpbuf, "No such class %.1000s", tokenbuf);
3304 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3311 if (expect != XSTATE)
3312 yyerror("\"no\" not allowed in expression");
3313 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3314 s = force_version(s);
3323 if (isIDFIRST(*s)) {
3325 for (d = s; isALNUM(*d); d++) ;
3327 if (strchr("|&*+-=!?:.", *t))
3328 warn("Precedence problem: open %.*s should be open(%.*s)",
3334 yylval.ival = OP_OR;
3344 LOP(OP_OPEN_DIR,XTERM);
3347 checkcomma(s,tokenbuf,"filehandle");
3351 checkcomma(s,tokenbuf,"filehandle");
3370 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3374 LOP(OP_PIPE_OP,XTERM);
3379 missingterm((char*)0);
3380 yylval.ival = OP_CONST;
3381 TERM(sublex_start());
3389 missingterm((char*)0);
3390 if (dowarn && SvLEN(lex_stuff)) {
3391 d = SvPV_force(lex_stuff, len);
3392 for (; len; --len, ++d) {
3394 warn("Possible attempt to separate words with commas");
3398 warn("Possible attempt to put comments in qw() list");
3404 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, q(lex_stuff));
3408 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(" ",1));
3411 yylval.ival = OP_SPLIT;
3415 last_lop = oldbufptr;
3416 last_lop_op = OP_SPLIT;
3422 missingterm((char*)0);
3423 yylval.ival = OP_STRINGIFY;
3424 if (SvIVX(lex_stuff) == '\'')
3425 SvIVX(lex_stuff) = 0; /* qq'$foo' should intepolate */
3426 TERM(sublex_start());
3431 missingterm((char*)0);
3432 yylval.ival = OP_BACKTICK;
3434 TERM(sublex_start());
3441 s = force_word(s,WORD,TRUE,TRUE,FALSE);
3442 if (isIDFIRST(*tokenbuf))
3443 gv_stashpvn(tokenbuf, strlen(tokenbuf), TRUE);
3445 yyerror("<> should be quotes");
3452 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3456 LOP(OP_RENAME,XTERM);
3465 LOP(OP_RINDEX,XTERM);
3488 LOP(OP_REVERSE,XTERM);
3499 TERM(sublex_start());
3501 TOKEN(1); /* force error */
3510 LOP(OP_SELECT,XTERM);
3516 LOP(OP_SEMCTL,XTERM);
3519 LOP(OP_SEMGET,XTERM);
3522 LOP(OP_SEMOP,XTERM);
3528 LOP(OP_SETPGRP,XTERM);
3530 case KEY_setpriority:
3531 LOP(OP_SETPRIORITY,XTERM);
3533 case KEY_sethostent:
3539 case KEY_setservent:
3542 case KEY_setprotoent:
3552 LOP(OP_SEEKDIR,XTERM);
3554 case KEY_setsockopt:
3555 LOP(OP_SSOCKOPT,XTERM);
3561 LOP(OP_SHMCTL,XTERM);
3564 LOP(OP_SHMGET,XTERM);
3567 LOP(OP_SHMREAD,XTERM);
3570 LOP(OP_SHMWRITE,XTERM);
3573 LOP(OP_SHUTDOWN,XTERM);
3582 LOP(OP_SOCKET,XTERM);
3584 case KEY_socketpair:
3585 LOP(OP_SOCKPAIR,XTERM);
3588 checkcomma(s,tokenbuf,"subroutine name");
3590 if (*s == ';' || *s == ')') /* probably a close */
3591 croak("sort is now a reserved word");
3593 s = force_word(s,WORD,TRUE,TRUE,FALSE);
3597 LOP(OP_SPLIT,XTERM);
3600 LOP(OP_SPRINTF,XTERM);
3603 LOP(OP_SPLICE,XTERM);
3619 LOP(OP_SUBSTR,XTERM);
3626 if (isIDFIRST(*s) || *s == '\'' || *s == ':') {
3627 char tmpbuf[sizeof tokenbuf];
3629 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3630 if (strchr(tmpbuf, ':'))
3631 sv_setpv(subname, tmpbuf);
3633 sv_setsv(subname,curstname);
3634 sv_catpvn(subname,"::",2);
3635 sv_catpvn(subname,tmpbuf,len);
3637 s = force_word(s,WORD,FALSE,TRUE,TRUE);
3641 expect = XTERMBLOCK;
3642 sv_setpv(subname,"?");
3645 if (tmp == KEY_format) {
3648 lex_formbrack = lex_brackets + 1;
3652 /* Look for a prototype */
3659 SvREFCNT_dec(lex_stuff);
3661 croak("Prototype not terminated");
3664 d = SvPVX(lex_stuff);
3666 for (p = d; *p; ++p) {
3671 SvCUR(lex_stuff) = tmp;
3674 nextval[1] = nextval[0];
3675 nexttype[1] = nexttype[0];
3676 nextval[0].opval = (OP*)newSVOP(OP_CONST, 0, lex_stuff);
3677 nexttype[0] = THING;
3678 if (nexttoke == 1) {
3679 lex_defer = lex_state;
3680 lex_expect = expect;
3681 lex_state = LEX_KNOWNEXT;
3686 if (*SvPV(subname,na) == '?') {
3687 sv_setpv(subname,"__ANON__");
3694 LOP(OP_SYSTEM,XREF);
3697 LOP(OP_SYMLINK,XTERM);
3700 LOP(OP_SYSCALL,XTERM);
3703 LOP(OP_SYSOPEN,XTERM);
3706 LOP(OP_SYSSEEK,XTERM);
3709 LOP(OP_SYSREAD,XTERM);
3712 LOP(OP_SYSWRITE,XTERM);
3716 TERM(sublex_start());
3737 LOP(OP_TRUNCATE,XTERM);
3749 yylval.ival = curcop->cop_line;
3753 yylval.ival = curcop->cop_line;
3757 LOP(OP_UNLINK,XTERM);
3763 LOP(OP_UNPACK,XTERM);
3766 LOP(OP_UTIME,XTERM);
3770 for (d = s; d < bufend && (isSPACE(*d) || *d == '('); d++) ;
3771 if (*d != '0' && isDIGIT(*d))
3772 yywarn("umask: argument is missing initial 0");
3777 LOP(OP_UNSHIFT,XTERM);
3780 if (expect != XSTATE)
3781 yyerror("\"use\" not allowed in expression");
3784 s = force_version(s);
3785 if(*s == ';' || (s = skipspace(s), *s == ';')) {
3786 nextval[nexttoke].opval = Nullop;
3791 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3792 s = force_version(s);
3805 yylval.ival = curcop->cop_line;
3809 hints |= HINT_BLOCK_SCOPE;
3816 LOP(OP_WAITPID,XTERM);
3822 gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */
3826 if (expect == XOPERATOR)
3832 yylval.ival = OP_XOR;
3837 TERM(sublex_start());
3843 keyword(register char *d, I32 len)
3848 if (strEQ(d,"__FILE__")) return -KEY___FILE__;
3849 if (strEQ(d,"__LINE__")) return -KEY___LINE__;
3850 if (strEQ(d,"__PACKAGE__")) return -KEY___PACKAGE__;
3851 if (strEQ(d,"__DATA__")) return KEY___DATA__;
3852 if (strEQ(d,"__END__")) return KEY___END__;
3856 if (strEQ(d,"AUTOLOAD")) return KEY_AUTOLOAD;
3861 if (strEQ(d,"and")) return -KEY_and;
3862 if (strEQ(d,"abs")) return -KEY_abs;
3865 if (strEQ(d,"alarm")) return -KEY_alarm;
3866 if (strEQ(d,"atan2")) return -KEY_atan2;
3869 if (strEQ(d,"accept")) return -KEY_accept;
3874 if (strEQ(d,"BEGIN")) return KEY_BEGIN;
3877 if (strEQ(d,"bless")) return -KEY_bless;
3878 if (strEQ(d,"bind")) return -KEY_bind;
3879 if (strEQ(d,"binmode")) return -KEY_binmode;
3882 if (strEQ(d,"CORE")) return -KEY_CORE;
3887 if (strEQ(d,"cmp")) return -KEY_cmp;
3888 if (strEQ(d,"chr")) return -KEY_chr;
3889 if (strEQ(d,"cos")) return -KEY_cos;
3892 if (strEQ(d,"chop")) return KEY_chop;
3895 if (strEQ(d,"close")) return -KEY_close;
3896 if (strEQ(d,"chdir")) return -KEY_chdir;
3897 if (strEQ(d,"chomp")) return KEY_chomp;
3898 if (strEQ(d,"chmod")) return -KEY_chmod;
3899 if (strEQ(d,"chown")) return -KEY_chown;
3900 if (strEQ(d,"crypt")) return -KEY_crypt;
3903 if (strEQ(d,"chroot")) return -KEY_chroot;
3904 if (strEQ(d,"caller")) return -KEY_caller;
3907 if (strEQ(d,"connect")) return -KEY_connect;
3910 if (strEQ(d,"closedir")) return -KEY_closedir;
3911 if (strEQ(d,"continue")) return -KEY_continue;
3916 if (strEQ(d,"DESTROY")) return KEY_DESTROY;
3921 if (strEQ(d,"do")) return KEY_do;
3924 if (strEQ(d,"die")) return -KEY_die;
3927 if (strEQ(d,"dump")) return -KEY_dump;
3930 if (strEQ(d,"delete")) return KEY_delete;
3933 if (strEQ(d,"defined")) return KEY_defined;
3934 if (strEQ(d,"dbmopen")) return -KEY_dbmopen;
3937 if (strEQ(d,"dbmclose")) return -KEY_dbmclose;
3942 if (strEQ(d,"EQ")) { deprecate(d); return -KEY_eq;}
3943 if (strEQ(d,"END")) return KEY_END;
3948 if (strEQ(d,"eq")) return -KEY_eq;
3951 if (strEQ(d,"eof")) return -KEY_eof;
3952 if (strEQ(d,"exp")) return -KEY_exp;
3955 if (strEQ(d,"else")) return KEY_else;
3956 if (strEQ(d,"exit")) return -KEY_exit;
3957 if (strEQ(d,"eval")) return KEY_eval;
3958 if (strEQ(d,"exec")) return -KEY_exec;
3959 if (strEQ(d,"each")) return KEY_each;
3962 if (strEQ(d,"elsif")) return KEY_elsif;
3965 if (strEQ(d,"exists")) return KEY_exists;
3966 if (strEQ(d,"elseif")) warn("elseif should be elsif");
3969 if (strEQ(d,"endgrent")) return -KEY_endgrent;
3970 if (strEQ(d,"endpwent")) return -KEY_endpwent;
3973 if (strEQ(d,"endnetent")) return -KEY_endnetent;
3976 if (strEQ(d,"endhostent")) return -KEY_endhostent;
3977 if (strEQ(d,"endservent")) return -KEY_endservent;
3980 if (strEQ(d,"endprotoent")) return -KEY_endprotoent;
3987 if (strEQ(d,"for")) return KEY_for;
3990 if (strEQ(d,"fork")) return -KEY_fork;
3993 if (strEQ(d,"fcntl")) return -KEY_fcntl;
3994 if (strEQ(d,"flock")) return -KEY_flock;
3997 if (strEQ(d,"format")) return KEY_format;
3998 if (strEQ(d,"fileno")) return -KEY_fileno;
4001 if (strEQ(d,"foreach")) return KEY_foreach;
4004 if (strEQ(d,"formline")) return -KEY_formline;
4010 if (strEQ(d,"GT")) { deprecate(d); return -KEY_gt;}
4011 if (strEQ(d,"GE")) { deprecate(d); return -KEY_ge;}
4015 if (strnEQ(d,"get",3)) {
4020 if (strEQ(d,"ppid")) return -KEY_getppid;
4021 if (strEQ(d,"pgrp")) return -KEY_getpgrp;
4024 if (strEQ(d,"pwent")) return -KEY_getpwent;
4025 if (strEQ(d,"pwnam")) return -KEY_getpwnam;
4026 if (strEQ(d,"pwuid")) return -KEY_getpwuid;
4029 if (strEQ(d,"peername")) return -KEY_getpeername;
4030 if (strEQ(d,"protoent")) return -KEY_getprotoent;
4031 if (strEQ(d,"priority")) return -KEY_getpriority;
4034 if (strEQ(d,"protobyname")) return -KEY_getprotobyname;
4037 if (strEQ(d,"protobynumber"))return -KEY_getprotobynumber;
4041 else if (*d == 'h') {
4042 if (strEQ(d,"hostbyname")) return -KEY_gethostbyname;
4043 if (strEQ(d,"hostbyaddr")) return -KEY_gethostbyaddr;
4044 if (strEQ(d,"hostent")) return -KEY_gethostent;
4046 else if (*d == 'n') {
4047 if (strEQ(d,"netbyname")) return -KEY_getnetbyname;
4048 if (strEQ(d,"netbyaddr")) return -KEY_getnetbyaddr;
4049 if (strEQ(d,"netent")) return -KEY_getnetent;
4051 else if (*d == 's') {
4052 if (strEQ(d,"servbyname")) return -KEY_getservbyname;
4053 if (strEQ(d,"servbyport")) return -KEY_getservbyport;
4054 if (strEQ(d,"servent")) return -KEY_getservent;
4055 if (strEQ(d,"sockname")) return -KEY_getsockname;
4056 if (strEQ(d,"sockopt")) return -KEY_getsockopt;
4058 else if (*d == 'g') {
4059 if (strEQ(d,"grent")) return -KEY_getgrent;
4060 if (strEQ(d,"grnam")) return -KEY_getgrnam;
4061 if (strEQ(d,"grgid")) return -KEY_getgrgid;
4063 else if (*d == 'l') {
4064 if (strEQ(d,"login")) return -KEY_getlogin;
4066 else if (strEQ(d,"c")) return -KEY_getc;
4071 if (strEQ(d,"gt")) return -KEY_gt;
4072 if (strEQ(d,"ge")) return -KEY_ge;
4075 if (strEQ(d,"grep")) return KEY_grep;
4076 if (strEQ(d,"goto")) return KEY_goto;
4077 if (strEQ(d,"glob")) return KEY_glob;
4080 if (strEQ(d,"gmtime")) return -KEY_gmtime;
4085 if (strEQ(d,"hex")) return -KEY_hex;
4088 if (strEQ(d,"INIT")) return KEY_INIT;
4093 if (strEQ(d,"if")) return KEY_if;
4096 if (strEQ(d,"int")) return -KEY_int;
4099 if (strEQ(d,"index")) return -KEY_index;
4100 if (strEQ(d,"ioctl")) return -KEY_ioctl;
4105 if (strEQ(d,"join")) return -KEY_join;
4109 if (strEQ(d,"keys")) return KEY_keys;
4110 if (strEQ(d,"kill")) return -KEY_kill;
4115 if (strEQ(d,"LT")) { deprecate(d); return -KEY_lt;}
4116 if (strEQ(d,"LE")) { deprecate(d); return -KEY_le;}
4122 if (strEQ(d,"lt")) return -KEY_lt;
4123 if (strEQ(d,"le")) return -KEY_le;
4124 if (strEQ(d,"lc")) return -KEY_lc;
4127 if (strEQ(d,"log")) return -KEY_log;
4130 if (strEQ(d,"last")) return KEY_last;
4131 if (strEQ(d,"link")) return -KEY_link;
4132 if (strEQ(d,"lock")) return -KEY_lock;
4135 if (strEQ(d,"local")) return KEY_local;
4136 if (strEQ(d,"lstat")) return -KEY_lstat;
4139 if (strEQ(d,"length")) return -KEY_length;
4140 if (strEQ(d,"listen")) return -KEY_listen;
4143 if (strEQ(d,"lcfirst")) return -KEY_lcfirst;
4146 if (strEQ(d,"localtime")) return -KEY_localtime;
4152 case 1: return KEY_m;
4154 if (strEQ(d,"my")) return KEY_my;
4157 if (strEQ(d,"map")) return KEY_map;
4160 if (strEQ(d,"mkdir")) return -KEY_mkdir;
4163 if (strEQ(d,"msgctl")) return -KEY_msgctl;
4164 if (strEQ(d,"msgget")) return -KEY_msgget;
4165 if (strEQ(d,"msgrcv")) return -KEY_msgrcv;
4166 if (strEQ(d,"msgsnd")) return -KEY_msgsnd;
4171 if (strEQ(d,"NE")) { deprecate(d); return -KEY_ne;}
4174 if (strEQ(d,"next")) return KEY_next;
4175 if (strEQ(d,"ne")) return -KEY_ne;
4176 if (strEQ(d,"not")) return -KEY_not;
4177 if (strEQ(d,"no")) return KEY_no;
4182 if (strEQ(d,"or")) return -KEY_or;
4185 if (strEQ(d,"ord")) return -KEY_ord;
4186 if (strEQ(d,"oct")) return -KEY_oct;
4189 if (strEQ(d,"open")) return -KEY_open;
4192 if (strEQ(d,"opendir")) return -KEY_opendir;
4199 if (strEQ(d,"pop")) return KEY_pop;
4200 if (strEQ(d,"pos")) return KEY_pos;
4203 if (strEQ(d,"push")) return KEY_push;
4204 if (strEQ(d,"pack")) return -KEY_pack;
4205 if (strEQ(d,"pipe")) return -KEY_pipe;
4208 if (strEQ(d,"print")) return KEY_print;
4211 if (strEQ(d,"printf")) return KEY_printf;
4214 if (strEQ(d,"package")) return KEY_package;
4217 if (strEQ(d,"prototype")) return KEY_prototype;
4222 if (strEQ(d,"q")) return KEY_q;
4223 if (strEQ(d,"qq")) return KEY_qq;
4224 if (strEQ(d,"qw")) return KEY_qw;
4225 if (strEQ(d,"qx")) return KEY_qx;
4227 else if (strEQ(d,"quotemeta")) return -KEY_quotemeta;
4232 if (strEQ(d,"ref")) return -KEY_ref;
4235 if (strEQ(d,"read")) return -KEY_read;
4236 if (strEQ(d,"rand")) return -KEY_rand;
4237 if (strEQ(d,"recv")) return -KEY_recv;
4238 if (strEQ(d,"redo")) return KEY_redo;
4241 if (strEQ(d,"rmdir")) return -KEY_rmdir;
4242 if (strEQ(d,"reset")) return -KEY_reset;
4245 if (strEQ(d,"return")) return KEY_return;
4246 if (strEQ(d,"rename")) return -KEY_rename;
4247 if (strEQ(d,"rindex")) return -KEY_rindex;
4250 if (strEQ(d,"require")) return -KEY_require;
4251 if (strEQ(d,"reverse")) return -KEY_reverse;
4252 if (strEQ(d,"readdir")) return -KEY_readdir;
4255 if (strEQ(d,"readlink")) return -KEY_readlink;
4256 if (strEQ(d,"readline")) return -KEY_readline;
4257 if (strEQ(d,"readpipe")) return -KEY_readpipe;
4260 if (strEQ(d,"rewinddir")) return -KEY_rewinddir;
4266 case 0: return KEY_s;
4268 if (strEQ(d,"scalar")) return KEY_scalar;
4273 if (strEQ(d,"seek")) return -KEY_seek;
4274 if (strEQ(d,"send")) return -KEY_send;
4277 if (strEQ(d,"semop")) return -KEY_semop;
4280 if (strEQ(d,"select")) return -KEY_select;
4281 if (strEQ(d,"semctl")) return -KEY_semctl;
4282 if (strEQ(d,"semget")) return -KEY_semget;
4285 if (strEQ(d,"setpgrp")) return -KEY_setpgrp;
4286 if (strEQ(d,"seekdir")) return -KEY_seekdir;
4289 if (strEQ(d,"setpwent")) return -KEY_setpwent;
4290 if (strEQ(d,"setgrent")) return -KEY_setgrent;
4293 if (strEQ(d,"setnetent")) return -KEY_setnetent;
4296 if (strEQ(d,"setsockopt")) return -KEY_setsockopt;
4297 if (strEQ(d,"sethostent")) return -KEY_sethostent;
4298 if (strEQ(d,"setservent")) return -KEY_setservent;
4301 if (strEQ(d,"setpriority")) return -KEY_setpriority;
4302 if (strEQ(d,"setprotoent")) return -KEY_setprotoent;
4309 if (strEQ(d,"shift")) return KEY_shift;
4312 if (strEQ(d,"shmctl")) return -KEY_shmctl;
4313 if (strEQ(d,"shmget")) return -KEY_shmget;
4316 if (strEQ(d,"shmread")) return -KEY_shmread;
4319 if (strEQ(d,"shmwrite")) return -KEY_shmwrite;
4320 if (strEQ(d,"shutdown")) return -KEY_shutdown;
4325 if (strEQ(d,"sin")) return -KEY_sin;
4328 if (strEQ(d,"sleep")) return -KEY_sleep;
4331 if (strEQ(d,"sort")) return KEY_sort;
4332 if (strEQ(d,"socket")) return -KEY_socket;
4333 if (strEQ(d,"socketpair")) return -KEY_socketpair;
4336 if (strEQ(d,"split")) return KEY_split;
4337 if (strEQ(d,"sprintf")) return -KEY_sprintf;
4338 if (strEQ(d,"splice")) return KEY_splice;
4341 if (strEQ(d,"sqrt")) return -KEY_sqrt;
4344 if (strEQ(d,"srand")) return -KEY_srand;
4347 if (strEQ(d,"stat")) return -KEY_stat;
4348 if (strEQ(d,"study")) return KEY_study;
4351 if (strEQ(d,"substr")) return -KEY_substr;
4352 if (strEQ(d,"sub")) return KEY_sub;
4357 if (strEQ(d,"system")) return -KEY_system;
4360 if (strEQ(d,"symlink")) return -KEY_symlink;
4361 if (strEQ(d,"syscall")) return -KEY_syscall;
4362 if (strEQ(d,"sysopen")) return -KEY_sysopen;
4363 if (strEQ(d,"sysread")) return -KEY_sysread;
4364 if (strEQ(d,"sysseek")) return -KEY_sysseek;
4367 if (strEQ(d,"syswrite")) return -KEY_syswrite;
4376 if (strEQ(d,"tr")) return KEY_tr;
4379 if (strEQ(d,"tie")) return KEY_tie;
4382 if (strEQ(d,"tell")) return -KEY_tell;
4383 if (strEQ(d,"tied")) return KEY_tied;
4384 if (strEQ(d,"time")) return -KEY_time;
4387 if (strEQ(d,"times")) return -KEY_times;
4390 if (strEQ(d,"telldir")) return -KEY_telldir;
4393 if (strEQ(d,"truncate")) return -KEY_truncate;
4400 if (strEQ(d,"uc")) return -KEY_uc;
4403 if (strEQ(d,"use")) return KEY_use;
4406 if (strEQ(d,"undef")) return KEY_undef;
4407 if (strEQ(d,"until")) return KEY_until;
4408 if (strEQ(d,"untie")) return KEY_untie;
4409 if (strEQ(d,"utime")) return -KEY_utime;
4410 if (strEQ(d,"umask")) return -KEY_umask;
4413 if (strEQ(d,"unless")) return KEY_unless;
4414 if (strEQ(d,"unpack")) return -KEY_unpack;
4415 if (strEQ(d,"unlink")) return -KEY_unlink;
4418 if (strEQ(d,"unshift")) return KEY_unshift;
4419 if (strEQ(d,"ucfirst")) return -KEY_ucfirst;
4424 if (strEQ(d,"values")) return -KEY_values;
4425 if (strEQ(d,"vec")) return -KEY_vec;
4430 if (strEQ(d,"warn")) return -KEY_warn;
4431 if (strEQ(d,"wait")) return -KEY_wait;
4434 if (strEQ(d,"while")) return KEY_while;
4435 if (strEQ(d,"write")) return -KEY_write;
4438 if (strEQ(d,"waitpid")) return -KEY_waitpid;
4441 if (strEQ(d,"wantarray")) return -KEY_wantarray;
4446 if (len == 1) return -KEY_x;
4447 if (strEQ(d,"xor")) return -KEY_xor;
4450 if (len == 1) return KEY_y;
4459 checkcomma(register char *s, char *name, char *what)
4463 if (dowarn && *s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
4465 for (w = s+2; *w && level; w++) {
4472 for (; *w && isSPACE(*w); w++) ;
4473 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
4474 warn("%s (...) interpreted as function",name);
4476 while (s < bufend && isSPACE(*s))
4480 while (s < bufend && isSPACE(*s))
4482 if (isIDFIRST(*s)) {
4486 while (s < bufend && isSPACE(*s))
4491 kw = keyword(w, s - w) || perl_get_cv(w, FALSE) != 0;
4495 croak("No comma allowed after %s", what);
4501 scan_word(register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
4503 register char *d = dest;
4504 register char *e = d + destlen - 3; /* two-character token, ending NUL */
4507 croak(ident_too_long);
4510 else if (*s == '\'' && allow_package && isIDFIRST(s[1])) {
4515 else if (*s == ':' && s[1] == ':' && allow_package && isIDFIRST(s[2])) {
4528 scan_ident(register char *s, register char *send, char *dest, STRLEN destlen, I32 ck_uni)
4535 if (lex_brackets == 0)
4540 e = d + destlen - 3; /* two-character token, ending NUL */
4542 while (isDIGIT(*s)) {
4544 croak(ident_too_long);
4551 croak(ident_too_long);
4554 else if (*s == '\'' && isIDFIRST(s[1])) {
4559 else if (*s == ':' && s[1] == ':') {
4570 if (lex_state != LEX_NORMAL)
4571 lex_state = LEX_INTERPENDMAYBE;
4574 if (*s == '$' && s[1] &&
4575 (isALNUM(s[1]) || strchr("${", s[1]) || strnEQ(s+1,"::",2)) )
4577 if (isDIGIT(s[1]) && lex_state == LEX_INTERPNORMAL)
4578 deprecate("\"$$<digit>\" to mean \"${$}<digit>\"");
4591 if (*d == '^' && *s && (isUPPER(*s) || strchr("[\\]^_?", *s))) {
4596 if (isSPACE(s[-1])) {
4599 if (ch != ' ' && ch != '\t') {
4605 if (isIDFIRST(*d)) {
4607 while (isALNUM(*s) || *s == ':')
4610 while (s < send && (*s == ' ' || *s == '\t')) s++;
4611 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
4612 if (dowarn && keyword(dest, d - dest)) {
4613 char *brack = *s == '[' ? "[...]" : "{...}";
4614 warn("Ambiguous use of %c{%s%s} resolved to %c%s%s",
4615 funny, dest, brack, funny, dest, brack);
4617 lex_fakebrack = lex_brackets+1;
4619 lex_brackstack[lex_brackets++] = XOPERATOR;
4625 if (lex_state == LEX_INTERPNORMAL && !lex_brackets)
4626 lex_state = LEX_INTERPEND;
4629 if (dowarn && lex_state == LEX_NORMAL &&
4630 (keyword(dest, d - dest) || perl_get_cv(dest, FALSE)))
4631 warn("Ambiguous use of %c{%s} resolved to %c%s",
4632 funny, dest, funny, dest);
4635 s = bracket; /* let the parser handle it */
4639 else if (lex_state == LEX_INTERPNORMAL && !lex_brackets && !intuit_more(s))
4640 lex_state = LEX_INTERPEND;
4644 void pmflag(U16 *pmfl, int ch)
4649 *pmfl |= PMf_GLOBAL;
4651 *pmfl |= PMf_CONTINUE;
4655 *pmfl |= PMf_MULTILINE;
4657 *pmfl |= PMf_SINGLELINE;
4659 *pmfl |= PMf_EXTENDED;
4663 scan_pat(char *start)
4668 s = scan_str(start);
4671 SvREFCNT_dec(lex_stuff);
4673 croak("Search pattern not terminated");
4676 pm = (PMOP*)newPMOP(OP_MATCH, 0);
4677 if (multi_open == '?')
4678 pm->op_pmflags |= PMf_ONCE;
4679 while (*s && strchr("iogcmsx", *s))
4680 pmflag(&pm->op_pmflags,*s++);
4681 pm->op_pmpermflags = pm->op_pmflags;
4684 yylval.ival = OP_MATCH;
4689 scan_subst(char *start)
4696 yylval.ival = OP_NULL;
4698 s = scan_str(start);
4702 SvREFCNT_dec(lex_stuff);
4704 croak("Substitution pattern not terminated");
4707 if (s[-1] == multi_open)
4710 first_start = multi_start;
4714 SvREFCNT_dec(lex_stuff);
4717 SvREFCNT_dec(lex_repl);
4719 croak("Substitution replacement not terminated");
4721 multi_start = first_start; /* so whole substitution is taken together */
4723 pm = (PMOP*)newPMOP(OP_SUBST, 0);
4724 while (*s && strchr("iogcmsex", *s)) {
4730 pmflag(&pm->op_pmflags,*s++);
4735 pm->op_pmflags |= PMf_EVAL;
4736 repl = newSVpv("",0);
4738 sv_catpv(repl, es ? "eval " : "do ");
4739 sv_catpvn(repl, "{ ", 2);
4740 sv_catsv(repl, lex_repl);
4741 sv_catpvn(repl, " };", 2);
4742 SvCOMPILED_on(repl);
4743 SvREFCNT_dec(lex_repl);
4747 pm->op_pmpermflags = pm->op_pmflags;
4749 yylval.ival = OP_SUBST;
4754 scan_trans(char *start)
4763 yylval.ival = OP_NULL;
4765 s = scan_str(start);
4768 SvREFCNT_dec(lex_stuff);
4770 croak("Translation pattern not terminated");
4772 if (s[-1] == multi_open)
4778 SvREFCNT_dec(lex_stuff);
4781 SvREFCNT_dec(lex_repl);
4783 croak("Translation replacement not terminated");
4786 New(803,tbl,256,short);
4787 o = newPVOP(OP_TRANS, 0, (char*)tbl);
4789 complement = Delete = squash = 0;
4790 while (*s == 'c' || *s == 'd' || *s == 's') {
4792 complement = OPpTRANS_COMPLEMENT;
4794 Delete = OPpTRANS_DELETE;
4796 squash = OPpTRANS_SQUASH;
4799 o->op_private = Delete|squash|complement;
4802 yylval.ival = OP_TRANS;
4807 scan_heredoc(register char *s)
4811 I32 op_type = OP_SCALAR;
4818 int outer = (rsfp && !lex_inwhat);
4822 e = tokenbuf + sizeof tokenbuf - 1;
4825 for (peek = s; *peek == ' ' || *peek == '\t'; peek++) ;
4826 if (*peek && strchr("`'\"",*peek)) {
4829 s = delimcpy(d, e, s, bufend, term, &len);
4840 deprecate("bare << to mean <<\"\"");
4841 for (; isALNUM(*s); s++) {
4846 if (d >= tokenbuf + sizeof tokenbuf - 1)
4847 croak("Delimiter for here document is too long");
4852 if (outer || !(d=ninstr(s,bufend,d,d+1)))
4853 herewas = newSVpv(s,bufend-s);
4855 s--, herewas = newSVpv(s,d-s);
4856 s += SvCUR(herewas);
4858 tmpstr = NEWSV(87,80);
4859 sv_upgrade(tmpstr, SVt_PVIV);
4864 else if (term == '`') {
4865 op_type = OP_BACKTICK;
4866 SvIVX(tmpstr) = '\\';
4870 multi_start = curcop->cop_line;
4871 multi_open = multi_close = '<';
4875 while (s < bufend &&
4876 (*s != term || memNE(s,tokenbuf,len)) ) {
4881 curcop->cop_line = multi_start;
4882 missingterm(tokenbuf);
4884 sv_setpvn(tmpstr,d+1,s-d);
4886 curcop->cop_line++; /* the preceding stmt passes a newline */
4888 sv_catpvn(herewas,s,bufend-s);
4889 sv_setsv(linestr,herewas);
4890 oldoldbufptr = oldbufptr = bufptr = s = linestart = SvPVX(linestr);
4891 bufend = SvPVX(linestr) + SvCUR(linestr);
4894 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
4895 while (s >= bufend) { /* multiple line string? */
4897 !(oldoldbufptr = oldbufptr = s = linestart = filter_gets(linestr, rsfp, 0))) {
4898 curcop->cop_line = multi_start;
4899 missingterm(tokenbuf);
4902 if (PERLDB_LINE && curstash != debstash) {
4903 SV *sv = NEWSV(88,0);
4905 sv_upgrade(sv, SVt_PVMG);
4906 sv_setsv(sv,linestr);
4907 av_store(GvAV(curcop->cop_filegv),
4908 (I32)curcop->cop_line,sv);
4910 bufend = SvPVX(linestr) + SvCUR(linestr);
4911 if (*s == term && memEQ(s,tokenbuf,len)) {
4914 sv_catsv(linestr,herewas);
4915 bufend = SvPVX(linestr) + SvCUR(linestr);
4919 sv_catsv(tmpstr,linestr);
4922 multi_end = curcop->cop_line;
4924 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
4925 SvLEN_set(tmpstr, SvCUR(tmpstr) + 1);
4926 Renew(SvPVX(tmpstr), SvLEN(tmpstr), char);
4928 SvREFCNT_dec(herewas);
4930 yylval.ival = op_type;
4935 scan_inputsymbol(char *start)
4937 register char *s = start;
4943 e = tokenbuf + sizeof tokenbuf;
4944 s = delimcpy(d, e, s + 1, bufend, '>', &len);
4945 if (len >= sizeof tokenbuf)
4946 croak("Excessively long <> operator");
4948 croak("Unterminated <> operator");
4950 if (*d == '$' && d[1]) d++;
4951 while (*d && (isALNUM(*d) || *d == '\'' || *d == ':'))
4953 if (d - tokenbuf != len) {
4954 yylval.ival = OP_GLOB;
4956 s = scan_str(start);
4958 croak("Glob not terminated");
4964 (void)strcpy(d,"ARGV");
4967 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
4968 OP *o = newOP(OP_PADSV, 0);
4970 lex_op = (OP*)newUNOP(OP_READLINE, 0, newUNOP(OP_RV2GV, 0, o));
4973 GV *gv = gv_fetchpv(d+1,TRUE, SVt_PV);
4974 lex_op = (OP*)newUNOP(OP_READLINE, 0,
4975 newUNOP(OP_RV2GV, 0,
4976 newUNOP(OP_RV2SV, 0,
4977 newGVOP(OP_GV, 0, gv))));
4979 yylval.ival = OP_NULL;
4982 GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO);
4983 lex_op = (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
4984 yylval.ival = OP_NULL;
4991 scan_str(char *start)
4996 register char *s = start;
5005 multi_start = curcop->cop_line;
5007 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
5012 sv_upgrade(sv, SVt_PVIV);
5014 (void)SvPOK_only(sv); /* validate pointer */
5017 SvGROW(sv, SvCUR(sv) + (bufend - s) + 1);
5018 to = SvPVX(sv)+SvCUR(sv);
5019 if (multi_open == multi_close) {
5020 for (; s < bufend; s++,to++) {
5021 if (*s == '\n' && !rsfp)
5023 if (*s == '\\' && s+1 < bufend && term != '\\') {
5029 else if (*s == term)
5035 for (; s < bufend; s++,to++) {
5036 if (*s == '\n' && !rsfp)
5038 if (*s == '\\' && s+1 < bufend) {
5039 if ((s[1] == multi_open) || (s[1] == multi_close))
5044 else if (*s == multi_close && --brackets <= 0)
5046 else if (*s == multi_open)
5052 SvCUR_set(sv, to - SvPVX(sv));
5054 if (s < bufend) break; /* string ends on this line? */
5057 !(oldoldbufptr = oldbufptr = s = linestart = filter_gets(linestr, rsfp, 0))) {
5059 curcop->cop_line = multi_start;
5063 if (PERLDB_LINE && curstash != debstash) {
5064 SV *sv = NEWSV(88,0);
5066 sv_upgrade(sv, SVt_PVMG);
5067 sv_setsv(sv,linestr);
5068 av_store(GvAV(curcop->cop_filegv),
5069 (I32)curcop->cop_line, sv);
5071 bufend = SvPVX(linestr) + SvCUR(linestr);
5073 multi_end = curcop->cop_line;
5075 if (SvCUR(sv) + 5 < SvLEN(sv)) {
5076 SvLEN_set(sv, SvCUR(sv) + 1);
5077 Renew(SvPVX(sv), SvLEN(sv), char);
5087 scan_num(char *start)
5089 register char *s = start;
5097 static char number_too_long[] = "Number too long";
5101 croak("panic: scan_num");
5106 bool overflowed = FALSE;
5112 else if (s[1] == '.')
5128 yyerror("Illegal octal digit");
5130 case '0': case '1': case '2': case '3': case '4':
5131 case '5': case '6': case '7':
5134 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
5135 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
5141 if (!overflowed && (n >> shift) != u) {
5142 warn("Integer overflow in %s number",
5143 (shift == 4) ? "hex" : "octal");
5155 case '1': case '2': case '3': case '4': case '5':
5156 case '6': case '7': case '8': case '9': case '.':
5159 e = tokenbuf + sizeof tokenbuf - 6; /* room for various punctuation */
5161 while (isDIGIT(*s) || *s == '_') {
5163 if (dowarn && lastub && s - lastub != 3)
5164 warn("Misplaced _ in number");
5169 croak(number_too_long);
5173 if (dowarn && lastub && s - lastub != 3)
5174 warn("Misplaced _ in number");
5175 if (*s == '.' && s[1] != '.') {
5178 for (; isDIGIT(*s) || *s == '_'; s++) {
5180 croak(number_too_long);
5185 if (*s && strchr("eE",*s) && strchr("+-0123456789",s[1])) {
5188 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
5189 if (*s == '+' || *s == '-')
5191 while (isDIGIT(*s)) {
5193 croak(number_too_long);
5199 SET_NUMERIC_STANDARD();
5200 value = atof(tokenbuf);
5202 if (!floatit && (double)tryiv == value)
5203 sv_setiv(sv, tryiv);
5205 sv_setnv(sv, value);
5209 yylval.opval = newSVOP(OP_CONST, 0, sv);
5215 scan_formline(register char *s)
5220 SV *stuff = newSVpv("",0);
5221 bool needargs = FALSE;
5224 if (*s == '.' || *s == '}') {
5226 for (t = s+1; *t == ' ' || *t == '\t'; t++) ;
5230 if (in_eval && !rsfp) {
5231 eol = strchr(s,'\n');
5236 eol = bufend = SvPVX(linestr) + SvCUR(linestr);
5238 for (t = s; t < eol; t++) {
5239 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
5241 goto enough; /* ~~ must be first line in formline */
5243 if (*t == '@' || *t == '^')
5246 sv_catpvn(stuff, s, eol-s);
5250 s = filter_gets(linestr, rsfp, 0);
5251 oldoldbufptr = oldbufptr = bufptr = linestart = SvPVX(linestr);
5252 bufend = bufptr + SvCUR(linestr);
5255 yyerror("Format not terminated");
5265 lex_state = LEX_NORMAL;
5266 nextval[nexttoke].ival = 0;
5270 lex_state = LEX_FORMLINE;
5271 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff);
5273 nextval[nexttoke].ival = OP_FORMLINE;
5277 SvREFCNT_dec(stuff);
5289 cshlen = strlen(cshname);
5294 start_subparse(I32 is_format, U32 flags)
5297 I32 oldsavestack_ix = savestack_ix;
5298 CV* outsidecv = compcv;
5302 assert(SvTYPE(compcv) == SVt_PVCV);
5309 SAVESPTR(comppad_name);
5311 SAVEI32(comppad_name_fill);
5312 SAVEI32(min_intro_pending);
5313 SAVEI32(max_intro_pending);
5314 SAVEI32(pad_reset_pending);
5316 compcv = (CV*)NEWSV(1104,0);
5317 sv_upgrade((SV *)compcv, is_format ? SVt_PVFM : SVt_PVCV);
5318 CvFLAGS(compcv) |= flags;
5321 av_push(comppad, Nullsv);
5322 curpad = AvARRAY(comppad);
5323 comppad_name = newAV();
5324 comppad_name_fill = 0;
5325 min_intro_pending = 0;
5327 subline = curcop->cop_line;
5329 av_store(comppad_name, 0, newSVpv("@_", 2));
5330 curpad[0] = (SV*)newAV();
5331 SvPADMY_on(curpad[0]); /* XXX Needed? */
5332 CvOWNER(compcv) = 0;
5333 New(666, CvMUTEXP(compcv), 1, perl_mutex);
5334 MUTEX_INIT(CvMUTEXP(compcv));
5335 #endif /* USE_THREADS */
5337 comppadlist = newAV();
5338 AvREAL_off(comppadlist);
5339 av_store(comppadlist, 0, (SV*)comppad_name);
5340 av_store(comppadlist, 1, (SV*)comppad);
5342 CvPADLIST(compcv) = comppadlist;
5343 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc(outsidecv);
5345 CvOWNER(compcv) = 0;
5346 New(666, CvMUTEXP(compcv), 1, perl_mutex);
5347 MUTEX_INIT(CvMUTEXP(compcv));
5348 #endif /* USE_THREADS */
5350 return oldsavestack_ix;
5369 char *context = NULL;
5373 if (!yychar || (yychar == ';' && !rsfp))
5375 else if (bufptr > oldoldbufptr && bufptr - oldoldbufptr < 200 &&
5376 oldoldbufptr != oldbufptr && oldbufptr != bufptr) {
5377 while (isSPACE(*oldoldbufptr))
5379 context = oldoldbufptr;
5380 contlen = bufptr - oldoldbufptr;
5382 else if (bufptr > oldbufptr && bufptr - oldbufptr < 200 &&
5383 oldbufptr != bufptr) {
5384 while (isSPACE(*oldbufptr))
5386 context = oldbufptr;
5387 contlen = bufptr - oldbufptr;
5389 else if (yychar > 255)
5390 where = "next token ???";
5391 else if ((yychar & 127) == 127) {
5392 if (lex_state == LEX_NORMAL ||
5393 (lex_state == LEX_KNOWNEXT && lex_defer == LEX_NORMAL))
5394 where = "at end of line";
5396 where = "within pattern";
5398 where = "within string";
5401 SV *where_sv = sv_2mortal(newSVpv("next char ", 0));
5403 sv_catpvf(where_sv, "^%c", toCTRL(yychar));
5404 else if (isPRINT_LC(yychar))
5405 sv_catpvf(where_sv, "%c", yychar);
5407 sv_catpvf(where_sv, "\\%03o", yychar & 255);
5408 where = SvPVX(where_sv);
5410 msg = sv_2mortal(newSVpv(s, 0));
5411 sv_catpvf(msg, " at %_ line %ld, ",
5412 GvSV(curcop->cop_filegv), (long)curcop->cop_line);
5414 sv_catpvf(msg, "near \"%.*s\"\n", contlen, context);
5416 sv_catpvf(msg, "%s\n", where);
5417 if (multi_start < multi_end && (U32)(curcop->cop_line - multi_end) <= 1) {
5419 " (Might be a runaway multi-line %c%c string starting on line %ld)\n",
5420 (int)multi_open,(int)multi_close,(long)multi_start);
5426 sv_catsv(ERRSV, msg);
5428 PerlIO_write(PerlIO_stderr(), SvPVX(msg), SvCUR(msg));
5429 if (++error_count >= 10)
5430 croak("%_ has too many errors.\n", GvSV(curcop->cop_filegv));
5432 in_my_stash = Nullhv;