3 * Copyright (c) 1991-1994, 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_word _((char *start, int token, int check_keyword, int allow_pack, int allow_tick));
20 static SV *q _((SV *sv));
21 static char *scan_const _((char *start));
22 static char *scan_formline _((char *s));
23 static char *scan_heredoc _((char *s));
24 static char *scan_ident _((char *s, char *send, char *dest, I32 ck_uni));
25 static char *scan_inputsymbol _((char *start));
26 static char *scan_pat _((char *start));
27 static char *scan_str _((char *start));
28 static char *scan_subst _((char *start));
29 static char *scan_trans _((char *start));
30 static char *scan_word _((char *s, char *dest, int allow_package, STRLEN *slp));
31 static char *skipspace _((char *s));
32 static void checkcomma _((char *s, char *name, char *what));
33 static void force_ident _((char *s, int kind));
34 static void incline _((char *s));
35 static int intuit_method _((char *s, GV *gv));
36 static int intuit_more _((char *s));
37 static I32 lop _((I32 f, expectation x, char *s));
38 static void missingterm _((char *s));
39 static void no_op _((char *what, char *s));
40 static void set_csh _((void));
41 static I32 sublex_done _((void));
42 static I32 sublex_start _((void));
44 static int uni _((I32 f, char *s));
46 static char * filter_gets _((SV *sv, FILE *fp));
48 /* The following are arranged oddly so that the guard on the switch statement
49 * can get by with a single comparison (if the compiler is smart enough).
53 #define LEX_INTERPNORMAL 8
54 #define LEX_INTERPCASEMOD 7
55 #define LEX_INTERPSTART 6
56 #define LEX_INTERPEND 5
57 #define LEX_INTERPENDMAYBE 4
58 #define LEX_INTERPCONCAT 3
59 #define LEX_INTERPCONST 2
60 #define LEX_FORMLINE 1
61 #define LEX_KNOWNEXT 0
79 #define CLINE (copline = (curcop->cop_line < copline ? curcop->cop_line : copline))
81 #define TOKEN(retval) return (bufptr = s,(int)retval)
82 #define OPERATOR(retval) return (expect = XTERM,bufptr = s,(int)retval)
83 #define AOPERATOR(retval) return ao((expect = XTERM,bufptr = s,(int)retval))
84 #define PREBLOCK(retval) return (expect = XBLOCK,bufptr = s,(int)retval)
85 #define PRETERMBLOCK(retval) return (expect = XTERMBLOCK,bufptr = s,(int)retval)
86 #define PREREF(retval) return (expect = XREF,bufptr = s,(int)retval)
87 #define TERM(retval) return (CLINE, expect = XOPERATOR,bufptr = s,(int)retval)
88 #define LOOPX(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)LOOPEX)
89 #define FTST(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)UNIOP)
90 #define FUN0(f) return(yylval.ival = f,expect = XOPERATOR,bufptr = s,(int)FUNC0)
91 #define FUN1(f) return(yylval.ival = f,expect = XOPERATOR,bufptr = s,(int)FUNC1)
92 #define BOop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)BITOROP))
93 #define BAop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)BITANDOP))
94 #define SHop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)SHIFTOP))
95 #define PWop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)POWOP))
96 #define PMop(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)MATCHOP)
97 #define Aop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)ADDOP))
98 #define Mop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)MULOP))
99 #define Eop(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)EQOP)
100 #define Rop(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)RELOP)
102 /* This bit of chicanery makes a unary function followed by
103 * a parenthesis into a function with one argument, highest precedence.
105 #define UNI(f) return(yylval.ival = f, \
108 last_uni = oldbufptr, \
110 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
112 #define UNIBRACK(f) return(yylval.ival = f, \
114 last_uni = oldbufptr, \
115 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
117 /* grandfather return to old style */
118 #define OLDLOP(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)LSTOP)
124 if (*bufptr == '=') {
126 if (toketype == ANDAND)
127 yylval.ival = OP_ANDASSIGN;
128 else if (toketype == OROR)
129 yylval.ival = OP_ORASSIGN;
141 char *oldbp = bufptr;
142 bool is_first = (oldbufptr == SvPVX(linestr));
144 sprintf(tmpbuf, "%s found where operator expected", what);
147 warn("\t(Missing semicolon on previous line?)\n");
148 else if (oldoldbufptr && isIDFIRST(*oldoldbufptr)) {
150 for (t = oldoldbufptr; *t && (isALNUM(*t) || *t == ':'); t++) ;
151 if (t < bufptr && isSPACE(*t))
152 warn("\t(Do you need to predeclare %.*s?)\n",
153 t - oldoldbufptr, oldoldbufptr);
157 warn("\t(Missing operator before %.*s?)\n", s - oldbp, oldbp);
168 char *nl = strrchr(s,'\n');
172 else if (multi_close < 32 || multi_close == 127) {
174 tmpbuf[1] = multi_close ^ 64;
180 *tmpbuf = multi_close;
184 q = strchr(s,'"') ? '\'' : '"';
185 croak("Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
193 warn("Use of %s is deprecated", s);
199 deprecate("comma-less variable list");
210 SAVEINT(lex_brackets);
211 SAVEINT(lex_fakebrack);
212 SAVEINT(lex_casemods);
217 SAVEINT(curcop->cop_line);
221 SAVEPPTR(oldoldbufptr);
223 SAVEPPTR(lex_brackstack);
224 SAVEPPTR(lex_casestack);
227 lex_state = LEX_NORMAL;
232 New(899, lex_brackstack, 120, char);
233 New(899, lex_casestack, 12, char);
234 SAVEFREEPV(lex_brackstack);
235 SAVEFREEPV(lex_casestack);
237 *lex_casestack = '\0';
241 SvREFCNT_dec(lex_stuff);
244 SvREFCNT_dec(lex_repl);
249 if (SvREADONLY(linestr))
250 linestr = sv_2mortal(newSVsv(linestr));
251 s = SvPV(linestr, len);
252 if (len && s[len-1] != ';') {
253 if (!(SvFLAGS(linestr) & SVs_TEMP))
254 linestr = sv_2mortal(newSVsv(linestr));
255 sv_catpvn(linestr, "\n;", 2);
258 oldoldbufptr = oldbufptr = bufptr = SvPVX(linestr);
259 bufend = bufptr + SvCUR(linestr);
284 while (*s == ' ' || *s == '\t') s++;
285 if (strnEQ(s, "line ", 5)) {
294 while (*s == ' ' || *s == '\t')
296 if (*s == '"' && (t = strchr(s+1, '"')))
300 return; /* false alarm */
301 for (t = s; !isSPACE(*t); t++) ;
306 curcop->cop_filegv = gv_fetchfile(s);
308 curcop->cop_filegv = gv_fetchfile(origfilename);
310 curcop->cop_line = atoi(n)-1;
317 if (lex_formbrack && lex_brackets <= lex_formbrack) {
318 while (s < bufend && (*s == ' ' || *s == '\t'))
323 while (s < bufend && isSPACE(*s))
325 if (s < bufend && *s == '#') {
326 while (s < bufend && *s != '\n')
331 if (s < bufend || !rsfp || lex_state != LEX_NORMAL)
333 if ((s = filter_gets(linestr, rsfp)) == Nullch) {
334 if (minus_n || minus_p) {
335 sv_setpv(linestr,minus_p ? ";}continue{print" : "");
336 sv_catpv(linestr,";}");
337 minus_n = minus_p = 0;
340 sv_setpv(linestr,";");
341 oldoldbufptr = oldbufptr = bufptr = s = SvPVX(linestr);
342 bufend = SvPVX(linestr) + SvCUR(linestr);
343 if (preprocess && !in_eval)
344 (void)my_pclose(rsfp);
345 else if ((FILE*)rsfp == stdin)
352 oldoldbufptr = oldbufptr = bufptr = s;
353 bufend = bufptr + SvCUR(linestr);
355 if (perldb && curstash != debstash) {
356 SV *sv = NEWSV(85,0);
358 sv_upgrade(sv, SVt_PVMG);
359 sv_setsv(sv,linestr);
360 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
371 if (oldoldbufptr != last_uni)
373 while (isSPACE(*last_uni))
375 for (s = last_uni; isALNUM(*s) || *s == '-'; s++) ;
376 if ((t = strchr(s, '(')) && t < bufptr)
380 warn("Warning: Use of \"%s\" without parens is ambiguous", last_uni);
387 #define UNI(f) return uni(f,s)
397 last_uni = oldbufptr;
408 #endif /* CRIPPLED_CC */
410 #define LOP(f,x) return lop(f,x,s)
422 last_lop = oldbufptr;
439 nexttype[nexttoke] = type;
441 if (lex_state != LEX_KNOWNEXT) {
442 lex_defer = lex_state;
444 lex_state = LEX_KNOWNEXT;
449 force_word(start,token,check_keyword,allow_pack,allow_tick)
450 register char *start;
459 start = skipspace(start);
462 (allow_pack && *s == ':') ||
463 (allow_tick && *s == '\'') )
465 s = scan_word(s, tokenbuf, allow_pack, &len);
466 if (check_keyword && keyword(tokenbuf, len))
468 if (token == METHOD) {
478 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST,0, newSVpv(tokenbuf,0));
479 nextval[nexttoke].opval->op_private |= OPpCONST_BARE;
491 OP* op = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
492 nextval[nexttoke].opval = op;
495 op->op_private = OPpCONST_ENTERED;
497 kind == '$' ? SVt_PV :
498 kind == '@' ? SVt_PVAV :
499 kind == '%' ? SVt_PVHV :
518 s = SvPV_force(sv, len);
522 while (s < send && *s != '\\')
529 if (s + 1 < send && (s[1] == '\\'))
530 s++; /* all that, just for this */
535 SvCUR_set(sv, d - SvPVX(sv));
543 register I32 op_type = yylval.ival;
545 if (op_type == OP_NULL) {
546 yylval.opval = lex_op;
550 if (op_type == OP_CONST || op_type == OP_READLINE) {
551 yylval.opval = (OP*)newSVOP(op_type, 0, q(lex_stuff));
558 SAVEINT(lex_brackets);
559 SAVEINT(lex_fakebrack);
560 SAVEINT(lex_casemods);
565 SAVEINT(curcop->cop_line);
568 SAVEPPTR(oldoldbufptr);
570 SAVEPPTR(lex_brackstack);
571 SAVEPPTR(lex_casestack);
576 bufend = bufptr = oldbufptr = oldoldbufptr = SvPVX(linestr);
577 bufend += SvCUR(linestr);
583 New(899, lex_brackstack, 120, char);
584 New(899, lex_casestack, 12, char);
585 SAVEFREEPV(lex_brackstack);
586 SAVEFREEPV(lex_casestack);
588 *lex_casestack = '\0';
590 lex_state = LEX_INTERPCONCAT;
591 curcop->cop_line = multi_start;
593 lex_inwhat = op_type;
594 if (op_type == OP_MATCH || op_type == OP_SUBST)
602 yylval.opval = lex_op;
615 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv("",0));
619 if (lex_casemods) { /* oops, we've got some unbalanced parens */
620 lex_state = LEX_INTERPCASEMOD;
624 /* Is there a right-hand side to take care of? */
625 if (lex_repl && (lex_inwhat == OP_SUBST || lex_inwhat == OP_TRANS)) {
628 bufend = bufptr = oldbufptr = oldoldbufptr = SvPVX(linestr);
629 bufend += SvCUR(linestr);
635 *lex_casestack = '\0';
637 if (SvCOMPILED(lex_repl)) {
638 lex_state = LEX_INTERPNORMAL;
642 lex_state = LEX_INTERPCONCAT;
648 bufend = SvPVX(linestr);
649 bufend += SvCUR(linestr);
659 register char *send = bufend;
660 SV *sv = NEWSV(93, send - start);
661 register char *s = start;
662 register char *d = SvPVX(sv);
663 bool dorange = FALSE;
667 ? "\\.^$@AGZdDwWsSbB+*?|()-nrtfeaxc0123456789[{]} \t\n\r\f\v#"
668 : (lex_inwhat & OP_TRANS)
672 while (s < send || dorange) {
673 if (lex_inwhat == OP_TRANS) {
678 SvGROW(sv, SvLEN(sv) + 256);
682 for (i = (U8)*d; i <= max; i++)
687 else if (*s == '-' && s+1 < send && s != start) {
692 else if (*s == '(' && lex_inpat && s[1] == '?' && s[2] == '#') {
693 while (s < send && *s != ')')
696 else if (*s == '#' && lex_inpat &&
697 ((PMOP*)lex_inpat)->op_pmflags & PMf_EXTENDED) {
698 while (s+1 < send && *s != '\n')
701 else if (*s == '@' && s[1] && (isALNUM(s[1]) || strchr(":'{$", s[1])))
703 else if (*s == '$') {
704 if (!lex_inpat) /* not a regexp, so $ must be var */
706 if (s + 1 < send && !strchr(")| \n\t", s[1]))
707 break; /* in regexp, $ might be tail anchor */
709 if (*s == '\\' && s+1 < send) {
711 if (*s && strchr(leave, *s)) {
716 if (lex_inwhat == OP_SUBST && !lex_inpat &&
717 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
720 warn("\\%c better written as $%c", *s, *s);
724 if (lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
730 if (lex_inwhat == OP_TRANS) {
738 case '0': case '1': case '2': case '3':
739 case '4': case '5': case '6': case '7':
740 *d++ = scan_oct(s, 3, &len);
744 *d++ = scan_hex(++s, 2, &len);
782 SvCUR_set(sv, d - SvPVX(sv));
785 if (SvCUR(sv) + 5 < SvLEN(sv)) {
786 SvLEN_set(sv, SvCUR(sv) + 1);
787 Renew(SvPVX(sv), SvLEN(sv), char);
790 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
796 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
803 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
805 if (*s != '{' && *s != '[')
810 /* In a pattern, so maybe we have {n,m}. */
827 /* On the other hand, maybe we have a character class */
830 if (*s == ']' || *s == '^')
833 int weight = 2; /* let's weigh the evidence */
835 unsigned char un_char = 0, last_un_char;
836 char *send = strchr(s,']');
839 if (!send) /* has to be an expression */
845 else if (isDIGIT(*s)) {
847 if (isDIGIT(s[1]) && s[2] == ']')
853 for (; s < send; s++) {
854 last_un_char = un_char;
855 un_char = (unsigned char)*s;
860 weight -= seen[un_char] * 10;
862 scan_ident(s,send,tmpbuf,FALSE);
863 if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV))
868 else if (*s == '$' && s[1] &&
869 strchr("[#!%*<>()-=",s[1])) {
870 if (/*{*/ strchr("])} =",s[2]))
879 if (strchr("wds]",s[1]))
881 else if (seen['\''] || seen['"'])
883 else if (strchr("rnftbxcav",s[1]))
885 else if (isDIGIT(s[1])) {
887 while (s[1] && isDIGIT(s[1]))
897 if (strchr("aA01! ",last_un_char))
899 if (strchr("zZ79~",s[1]))
903 if (!isALNUM(last_un_char) && !strchr("$@&",last_un_char) &&
904 isALPHA(*s) && s[1] && isALPHA(s[1])) {
909 if (keyword(tmpbuf, d - tmpbuf))
912 if (un_char == last_un_char + 1)
914 weight -= seen[un_char];
919 if (weight >= 0) /* probably a character class */
927 intuit_method(start,gv)
931 char *s = start + (*start == '$');
942 s = scan_word(s, tmpbuf, TRUE, &len);
944 if (gv || last_lop_op == OP_PRINT || isUPPER(*tokenbuf))
949 return *s == '(' ? FUNCMETH : METHOD;
951 if (!keyword(tmpbuf, len)) {
952 indirgv = gv_fetchpv(tmpbuf,FALSE, SVt_PVCV);
953 if (indirgv && GvCV(indirgv))
955 /* filehandle or package name makes it a method */
956 if (!gv || GvIO(indirgv) || gv_stashpv(tmpbuf, FALSE)) {
958 nextval[nexttoke].opval =
959 (OP*)newSVOP(OP_CONST, 0,
961 nextval[nexttoke].opval->op_private =
966 return *s == '(' ? FUNCMETH : METHOD;
976 char *pdb = getenv("PERL5DB");
980 return "BEGIN { require 'perl5db.pl' }";
986 /* Encoded script support. filter_add() effectively inserts a
987 * 'pre-processing' function into the current source input stream.
988 * Note that the filter function only applies to the current source file
989 * (e.g., it will not affect files 'require'd or 'use'd by this one).
991 * The datasv parameter (which may be NULL) can be used to pass
992 * private data to this instance of the filter. The filter function
993 * can recover the SV using the FILTER_DATA macro and use it to
994 * store private buffers and state information.
996 * The supplied datasv parameter is upgraded to a PVIO type
997 * and the IoDIRP field is used to store the function pointer.
998 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
999 * private use must be set using malloc'd pointers.
1001 static int filter_debug = 0;
1004 filter_add(funcp, datasv)
1008 if (!funcp){ /* temporary handy debugging hack to be deleted */
1009 filter_debug = atoi((char*)datasv);
1013 rsfp_filters = newAV();
1016 if (!SvUPGRADE(datasv, SVt_PVIO))
1017 die("Can't upgrade filter_add data to SVt_PVIO");
1018 IoDIRP(datasv) = (DIR*)funcp; /* stash funcp into spare field */
1020 warn("filter_add func %lx (%s)", funcp, SvPV(datasv,na));
1021 av_unshift(rsfp_filters, 1);
1022 av_store(rsfp_filters, 0, datasv) ;
1027 /* Delete most recently added instance of this filter function. */
1033 warn("filter_del func %lx", funcp);
1034 if (!rsfp_filters || AvFILL(rsfp_filters)<0)
1036 /* if filter is on top of stack (usual case) just pop it off */
1037 if (IoDIRP(FILTER_DATA(0)) == (void*)funcp){
1038 /* sv_free(av_pop(rsfp_filters)); */
1039 sv_free(av_shift(rsfp_filters));
1043 /* we need to search for the correct entry and clear it */
1044 die("filter_del can only delete in reverse order (currently)");
1048 /* Invoke the n'th filter function for the current rsfp. */
1050 filter_read(idx, buf_sv, maxlen)
1053 int maxlen; /* 0 = read one text line */
1060 if (idx > AvFILL(rsfp_filters)){ /* Any more filters? */
1061 /* Provide a default input filter to make life easy. */
1062 /* Note that we append to the line. This is handy. */
1064 warn("filter_read %d: from rsfp\n", idx);
1068 int old_len = SvCUR(buf_sv) ;
1070 /* ensure buf_sv is large enough */
1071 SvGROW(buf_sv, old_len + maxlen) ;
1072 if ((len = fread(SvPVX(buf_sv) + old_len, 1, maxlen, rsfp)) <= 0){
1074 return -1; /* error */
1076 return 0 ; /* end of file */
1078 SvCUR_set(buf_sv, old_len + len) ;
1081 if (sv_gets(buf_sv, rsfp, SvCUR(buf_sv)) == NULL) {
1083 return -1; /* error */
1085 return 0 ; /* end of file */
1088 return SvCUR(buf_sv);
1090 /* Skip this filter slot if filter has been deleted */
1091 if ( (datasv = FILTER_DATA(idx)) == &sv_undef){
1093 warn("filter_read %d: skipped (filter deleted)\n", idx);
1094 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
1096 /* Get function pointer hidden within datasv */
1097 funcp = (filter_t)IoDIRP(datasv);
1099 warn("filter_read %d: via function %lx (%s)\n",
1100 idx, funcp, SvPV(datasv,na));
1101 /* Call function. The function is expected to */
1102 /* call "FILTER_READ(idx+1, buf_sv)" first. */
1103 /* Return: <0:error, =0:eof, >0:not eof */
1104 return (*funcp)(idx, buf_sv, maxlen);
1114 SvCUR_set(sv, 0); /* start with empty line */
1115 if (FILTER_READ(0, sv, 0) > 0)
1116 return ( SvPVX(sv) ) ;
1121 return (sv_gets(sv, fp, 0)) ;
1127 static char* exp_name[] =
1128 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "TERMBLOCK" };
1131 extern int yychar; /* last token */
1141 switch (lex_state) {
1143 case LEX_NORMAL: /* Some compilers will produce faster */
1144 case LEX_INTERPNORMAL: /* code if we comment these out. */
1150 yylval = nextval[nexttoke];
1152 lex_state = lex_defer;
1153 expect = lex_expect;
1154 lex_defer = LEX_NORMAL;
1156 return(nexttype[nexttoke]);
1158 case LEX_INTERPCASEMOD:
1160 if (bufptr != bufend && *bufptr != '\\')
1161 croak("panic: INTERPCASEMOD");
1163 if (bufptr == bufend || bufptr[1] == 'E') {
1166 oldmod = lex_casestack[--lex_casemods];
1167 lex_casestack[lex_casemods] = '\0';
1168 if (bufptr != bufend && strchr("LUQ", oldmod)) {
1170 lex_state = LEX_INTERPCONCAT;
1174 if (bufptr != bufend)
1176 lex_state = LEX_INTERPCONCAT;
1181 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
1182 tmp = *s, *s = s[2], s[2] = tmp; /* misordered... */
1183 if (strchr("LU", *s) &&
1184 (strchr(lex_casestack, 'L') || strchr(lex_casestack, 'U')))
1186 lex_casestack[--lex_casemods] = '\0';
1189 if (lex_casemods > 10) {
1190 char* newlb = (char*)realloc(lex_casestack, lex_casemods + 2);
1191 if (newlb != lex_casestack) {
1193 lex_casestack = newlb;
1196 lex_casestack[lex_casemods++] = *s;
1197 lex_casestack[lex_casemods] = '\0';
1198 lex_state = LEX_INTERPCONCAT;
1199 nextval[nexttoke].ival = 0;
1202 nextval[nexttoke].ival = OP_LCFIRST;
1204 nextval[nexttoke].ival = OP_UCFIRST;
1206 nextval[nexttoke].ival = OP_LC;
1208 nextval[nexttoke].ival = OP_UC;
1210 nextval[nexttoke].ival = OP_QUOTEMETA;
1212 croak("panic: yylex");
1224 case LEX_INTERPSTART:
1225 if (bufptr == bufend)
1226 return sublex_done();
1228 lex_dojoin = (*bufptr == '@');
1229 lex_state = LEX_INTERPNORMAL;
1231 nextval[nexttoke].ival = 0;
1233 force_ident("\"", '$');
1234 nextval[nexttoke].ival = 0;
1236 nextval[nexttoke].ival = 0;
1238 nextval[nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
1249 case LEX_INTERPENDMAYBE:
1250 if (intuit_more(bufptr)) {
1251 lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
1259 lex_state = LEX_INTERPCONCAT;
1263 case LEX_INTERPCONCAT:
1266 croak("panic: INTERPCONCAT");
1268 if (bufptr == bufend)
1269 return sublex_done();
1271 if (SvIVX(linestr) == '\'') {
1272 SV *sv = newSVsv(linestr);
1275 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1279 s = scan_const(bufptr);
1281 lex_state = LEX_INTERPCASEMOD;
1283 lex_state = LEX_INTERPSTART;
1287 nextval[nexttoke] = yylval;
1300 lex_state = LEX_NORMAL;
1301 s = scan_formline(bufptr);
1308 oldoldbufptr = oldbufptr;
1311 fprintf(stderr,"### Tokener expecting %s at %s\n", exp_name[expect], s);
1317 warn("Unrecognized character \\%03o ignored", *s++ & 255);
1321 goto fake_eof; /* emulate EOF on ^D or ^Z */
1325 yyerror("Missing right bracket");
1329 goto retry; /* ignore stray nulls */
1332 if (!in_eval && !preambled) {
1334 sv_setpv(linestr,incl_perldb());
1336 sv_catpv(linestr,";");
1338 while(AvFILL(preambleav) >= 0) {
1339 SV *tmpsv = av_shift(preambleav);
1340 sv_catsv(linestr, tmpsv);
1341 sv_catpv(linestr, ";");
1344 sv_free((SV*)preambleav);
1347 if (minus_n || minus_p) {
1348 sv_catpv(linestr, "LINE: while (<>) {");
1350 sv_catpv(linestr,"chomp;");
1354 if ( splitstr[0] == '/' ||
1355 splitstr[0] == '\'' ||
1356 splitstr[0] == '"' )
1357 sprintf( tmpbuf1, "@F=split(%s);", splitstr );
1359 sprintf( tmpbuf1, "@F=split('%s');", splitstr );
1360 sv_catpv(linestr,tmpbuf1);
1363 sv_catpv(linestr,"@F=split(' ');");
1366 sv_catpv(linestr, "\n");
1367 oldoldbufptr = oldbufptr = s = SvPVX(linestr);
1368 bufend = SvPVX(linestr) + SvCUR(linestr);
1369 if (perldb && curstash != debstash) {
1370 SV *sv = NEWSV(85,0);
1372 sv_upgrade(sv, SVt_PVMG);
1373 sv_setsv(sv,linestr);
1374 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
1379 if ((s = filter_gets(linestr, rsfp)) == Nullch) {
1382 if (preprocess && !in_eval)
1383 (void)my_pclose(rsfp);
1384 else if ((FILE*)rsfp == stdin)
1390 if (!in_eval && (minus_n || minus_p)) {
1391 sv_setpv(linestr,minus_p ? ";}continue{print" : "");
1392 sv_catpv(linestr,";}");
1393 oldoldbufptr = oldbufptr = s = SvPVX(linestr);
1394 bufend = SvPVX(linestr) + SvCUR(linestr);
1395 minus_n = minus_p = 0;
1398 oldoldbufptr = oldbufptr = s = SvPVX(linestr);
1399 sv_setpv(linestr,"");
1400 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
1403 if (*s == '#' && s[1] == '!' && instr(s,"perl"))
1406 /* Incest with pod. */
1407 if (*s == '=' && strnEQ(s, "=cut", 4)) {
1408 sv_setpv(linestr, "");
1409 oldoldbufptr = oldbufptr = s = SvPVX(linestr);
1410 bufend = SvPVX(linestr) + SvCUR(linestr);
1415 } while (doextract);
1416 oldoldbufptr = oldbufptr = bufptr = s;
1417 if (perldb && curstash != debstash) {
1418 SV *sv = NEWSV(85,0);
1420 sv_upgrade(sv, SVt_PVMG);
1421 sv_setsv(sv,linestr);
1422 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
1424 bufend = SvPVX(linestr) + SvCUR(linestr);
1425 if (curcop->cop_line == 1) {
1426 while (s < bufend && isSPACE(*s))
1428 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
1430 if (!in_eval && *s == '#' && s[1] == '!') {
1431 d = instr(s,"perl -");
1433 d = instr(s,"perl");
1436 !instr(s,"indir") &&
1437 instr(origargv[0],"perl"))
1446 while (s < bufend && !isSPACE(*s))
1449 while (s < bufend && isSPACE(*s))
1452 Newz(899,newargv,origargc+3,char*);
1454 while (s < bufend && !isSPACE(*s))
1457 Copy(origargv+1, newargv+2, origargc+1, char*);
1463 croak("Can't exec %s", cmd);
1466 int oldpdb = perldb;
1470 while (*d && !isSPACE(*d)) d++;
1471 while (*d == ' ') d++;
1474 while (d = moreswitches(d)) ;
1475 if (perldb && !oldpdb ||
1479 sv_setpv(linestr, "");
1480 oldoldbufptr = oldbufptr = s = SvPVX(linestr);
1481 bufend = SvPVX(linestr) + SvCUR(linestr);
1484 (void)gv_fetchfile(origfilename);
1491 if (lex_formbrack && lex_brackets <= lex_formbrack) {
1493 lex_state = LEX_FORMLINE;
1497 case ' ': case '\t': case '\f': case '\r': case 013:
1502 if (lex_state != LEX_NORMAL || (in_eval && !rsfp)) {
1504 while (s < d && *s != '\n')
1509 if (lex_formbrack && lex_brackets <= lex_formbrack) {
1511 lex_state = LEX_FORMLINE;
1521 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
1526 while (s < bufend && (*s == ' ' || *s == '\t'))
1529 if (strnEQ(s,"=>",2)) {
1531 warn("Ambiguous use of -%c => resolved to \"-%c\" =>",
1533 s = force_word(bufptr,WORD,FALSE,FALSE,FALSE);
1534 OPERATOR('-'); /* unary minus */
1536 last_uni = oldbufptr;
1537 last_lop_op = OP_FTEREAD; /* good enough */
1539 case 'r': FTST(OP_FTEREAD);
1540 case 'w': FTST(OP_FTEWRITE);
1541 case 'x': FTST(OP_FTEEXEC);
1542 case 'o': FTST(OP_FTEOWNED);
1543 case 'R': FTST(OP_FTRREAD);
1544 case 'W': FTST(OP_FTRWRITE);
1545 case 'X': FTST(OP_FTREXEC);
1546 case 'O': FTST(OP_FTROWNED);
1547 case 'e': FTST(OP_FTIS);
1548 case 'z': FTST(OP_FTZERO);
1549 case 's': FTST(OP_FTSIZE);
1550 case 'f': FTST(OP_FTFILE);
1551 case 'd': FTST(OP_FTDIR);
1552 case 'l': FTST(OP_FTLINK);
1553 case 'p': FTST(OP_FTPIPE);
1554 case 'S': FTST(OP_FTSOCK);
1555 case 'u': FTST(OP_FTSUID);
1556 case 'g': FTST(OP_FTSGID);
1557 case 'k': FTST(OP_FTSVTX);
1558 case 'b': FTST(OP_FTBLK);
1559 case 'c': FTST(OP_FTCHR);
1560 case 't': FTST(OP_FTTTY);
1561 case 'T': FTST(OP_FTTEXT);
1562 case 'B': FTST(OP_FTBINARY);
1563 case 'M': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTMTIME);
1564 case 'A': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTATIME);
1565 case 'C': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTCTIME);
1567 croak("Unrecognized file test: -%c", tmp);
1574 if (expect == XOPERATOR)
1579 else if (*s == '>') {
1582 if (isIDFIRST(*s)) {
1583 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
1591 if (expect == XOPERATOR)
1594 if (isSPACE(*s) || !isSPACE(*bufptr))
1596 OPERATOR('-'); /* unary minus */
1603 if (expect == XOPERATOR)
1608 if (expect == XOPERATOR)
1611 if (isSPACE(*s) || !isSPACE(*bufptr))
1617 if (expect != XOPERATOR) {
1618 s = scan_ident(s, bufend, tokenbuf, TRUE);
1620 force_ident(tokenbuf, '*');
1633 if (expect != XOPERATOR) {
1634 s = scan_ident(s, bufend, tokenbuf + 1, TRUE);
1639 if (strchr(tokenbuf,':'))
1640 croak(no_myglob,tokenbuf);
1641 nextval[nexttoke].opval = newOP(OP_PADANY, 0);
1642 nextval[nexttoke].opval->op_targ = pad_allocmy(tokenbuf);
1643 force_next(PRIVATEREF);
1646 if (!strchr(tokenbuf,':')) {
1647 if (tmp = pad_findmy(tokenbuf)) {
1648 nextval[nexttoke].opval = newOP(OP_PADANY, 0);
1649 nextval[nexttoke].opval->op_targ = tmp;
1650 force_next(PRIVATEREF);
1654 force_ident(tokenbuf + 1, *tokenbuf);
1682 if (last_lop == oldoldbufptr || last_uni == oldoldbufptr)
1683 oldbufptr = oldoldbufptr; /* allow print(STDOUT 123) */
1688 if (curcop->cop_line < copline)
1689 copline = curcop->cop_line;
1700 if (lex_brackets <= 0)
1701 yyerror("Unmatched right bracket");
1704 if (lex_state == LEX_INTERPNORMAL) {
1705 if (lex_brackets == 0) {
1706 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
1707 lex_state = LEX_INTERPEND;
1714 if (lex_brackets > 100) {
1715 char* newlb = (char*)realloc(lex_brackstack, lex_brackets + 1);
1716 if (newlb != lex_brackstack) {
1718 lex_brackstack = newlb;
1723 if (lex_formbrack) {
1727 if (oldoldbufptr == last_lop)
1728 lex_brackstack[lex_brackets++] = XTERM;
1730 lex_brackstack[lex_brackets++] = XOPERATOR;
1731 OPERATOR(HASHBRACK);
1734 while (s < bufend && (*s == ' ' || *s == '\t'))
1736 if (s < bufend && isALPHA(*s)) {
1737 d = scan_word(s, tokenbuf, FALSE, &len);
1738 while (d < bufend && (*d == ' ' || *d == '\t'))
1742 (keyword(tokenbuf, len) ||
1743 perl_get_cv(tokenbuf, FALSE) ))
1744 warn("Ambiguous use of {%s} resolved to {\"%s\"}",
1745 tokenbuf, tokenbuf);
1746 s = force_word(s,WORD,FALSE,TRUE,FALSE);
1751 lex_brackstack[lex_brackets++] = XSTATE;
1755 lex_brackstack[lex_brackets++] = XOPERATOR;
1760 if (oldoldbufptr == last_lop)
1761 lex_brackstack[lex_brackets++] = XTERM;
1763 lex_brackstack[lex_brackets++] = XOPERATOR;
1766 OPERATOR(HASHBRACK);
1768 for (t = s; t < bufend && isALPHA(*t); t++) ;
1770 else if (*s == '\'' || *s == '"') {
1777 while (t < bufend && isSPACE(*t))
1779 if ((*t == ',' && !isLOWER(*s)) || (*t == '=' && t[1] == '>'))
1780 OPERATOR(HASHBRACK);
1784 lex_brackstack[lex_brackets-1] = XSTATE;
1790 yylval.ival = curcop->cop_line;
1791 if (isSPACE(*s) || *s == '#')
1792 copline = NOLINE; /* invalidate current command line number */
1797 if (lex_brackets <= 0)
1798 yyerror("Unmatched right bracket");
1800 expect = (expectation)lex_brackstack[--lex_brackets];
1801 if (lex_brackets < lex_formbrack)
1803 if (lex_state == LEX_INTERPNORMAL) {
1804 if (lex_brackets == 0) {
1805 if (lex_fakebrack) {
1806 lex_state = LEX_INTERPEND;
1808 return yylex(); /* ignore fake brackets */
1810 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
1811 lex_state = LEX_INTERPEND;
1814 if (lex_brackets < lex_fakebrack) {
1817 return yylex(); /* ignore fake brackets */
1827 if (expect == XOPERATOR) {
1828 if (dowarn && isALPHA(*s) && bufptr == SvPVX(linestr)) {
1836 s = scan_ident(s-1, bufend, tokenbuf, TRUE);
1839 force_ident(tokenbuf, '&');
1861 if (dowarn && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
1862 warn("Reversed %c= operator",tmp);
1864 if (expect == XSTATE && isALPHA(tmp) &&
1865 (s == SvPVX(linestr)+1 || s[-2] == '\n') )
1871 if (lex_brackets < lex_formbrack) {
1873 for (t = s; *t == ' ' || *t == '\t'; t++) ;
1874 if (*t == '\n' || *t == '#') {
1892 if (expect != XOPERATOR) {
1893 if (s[1] != '<' && !strchr(s,'>'))
1896 s = scan_heredoc(s);
1898 s = scan_inputsymbol(s);
1899 TERM(sublex_start());
1904 SHop(OP_LEFT_SHIFT);
1918 SHop(OP_RIGHT_SHIFT);
1925 if (s[1] == '#' && (isALPHA(s[2]) || strchr("_{$:", s[2]))) {
1926 s = scan_ident(s+1, bufend, tokenbuf+1, FALSE);
1927 if (expect == XOPERATOR) {
1928 if (lex_formbrack && lex_brackets == lex_formbrack) {
1931 return ','; /* grandfather non-comma-format format */
1934 no_op("Array length",s);
1936 else if (!tokenbuf[1])
1938 if (!strchr(tokenbuf+1,':')) {
1940 if (tmp = pad_findmy(tokenbuf)) {
1941 nextval[nexttoke].opval = newOP(OP_PADANY, 0);
1942 nextval[nexttoke].opval->op_targ = tmp;
1944 force_next(PRIVATEREF);
1949 force_ident(tokenbuf+1, *tokenbuf);
1952 s = scan_ident(s, bufend, tokenbuf+1, FALSE);
1953 if (expect == XOPERATOR) {
1954 if (lex_formbrack && lex_brackets == lex_formbrack) {
1957 return ','; /* grandfather non-comma-format format */
1963 expectation oldexpect = expect;
1965 /* This kludge not intended to be bulletproof. */
1966 if (tokenbuf[1] == '[' && !tokenbuf[2]) {
1967 yylval.opval = newSVOP(OP_CONST, 0,
1968 newSViv((IV)compiling.cop_arybase));
1969 yylval.opval->op_private = OPpCONST_ARYBASE;
1975 if (*s == '[' && oldexpect != XREF) {
1976 for (t = s+1; isSPACE(*t) || isALNUM(*t) || *t == '$'; t++) ;
1978 bufptr = skipspace(bufptr);
1979 while (t < bufend && *t != ']') t++;
1980 warn("Multidimensional syntax %.*s not supported",
1981 t-bufptr+1, bufptr);
1984 if (*s == '{' && strEQ(tokenbuf, "$SIG") &&
1985 (t = strchr(s,'}')) && (t = strchr(t,'='))) {
1988 for (t++; isSPACE(*t); t++) ;
1989 if (isIDFIRST(*t)) {
1990 t = scan_word(t, tmpbuf, TRUE, &len);
1991 if (*t != '(' && perl_get_cv(tmpbuf, FALSE))
1992 warn("You need to quote \"%s\"", tmpbuf);
1997 if (lex_state == LEX_NORMAL && isSPACE(*s)) {
1998 bool islop = (last_lop == oldoldbufptr);
2000 if (!islop || last_lop_op == OP_GREPSTART)
2002 else if (strchr("$@\"'`q", *s))
2003 expect = XTERM; /* e.g. print $fh "foo" */
2004 else if (strchr("&*<%", *s) && isIDFIRST(s[1]))
2005 expect = XTERM; /* e.g. print $fh &sub */
2006 else if (isDIGIT(*s))
2007 expect = XTERM; /* e.g. print $fh 3 */
2008 else if (*s == '.' && isDIGIT(s[1]))
2009 expect = XTERM; /* e.g. print $fh .3 */
2010 else if (strchr("/?-+", *s) && !isSPACE(s[1]))
2011 expect = XTERM; /* e.g. print $fh -1 */
2012 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]))
2013 expect = XTERM; /* print $fh <<"EOF" */
2016 if (strchr(tokenbuf,':'))
2017 croak(no_myglob,tokenbuf);
2018 nextval[nexttoke].opval = newOP(OP_PADANY, 0);
2019 nextval[nexttoke].opval->op_targ = pad_allocmy(tokenbuf);
2020 force_next(PRIVATEREF);
2022 else if (!strchr(tokenbuf,':')) {
2023 if (oldexpect != XREF || oldoldbufptr == last_lop) {
2024 if (intuit_more(s)) {
2031 if (tmp = pad_findmy(tokenbuf)) {
2032 nextval[nexttoke].opval = newOP(OP_PADANY, 0);
2033 nextval[nexttoke].opval->op_targ = tmp;
2034 force_next(PRIVATEREF);
2037 force_ident(tokenbuf+1, *tokenbuf);
2040 force_ident(tokenbuf+1, *tokenbuf);
2044 yyerror("Final $ should be \\$ or $name");
2050 s = scan_ident(s, bufend, tokenbuf+1, FALSE);
2051 if (expect == XOPERATOR)
2059 if (strchr(tokenbuf,':'))
2060 croak(no_myglob,tokenbuf);
2061 nextval[nexttoke].opval = newOP(OP_PADANY, 0);
2062 nextval[nexttoke].opval->op_targ = pad_allocmy(tokenbuf);
2063 force_next(PRIVATEREF);
2066 else if (!strchr(tokenbuf,':')) {
2067 if (intuit_more(s)) {
2071 if (tmp = pad_findmy(tokenbuf)) {
2072 nextval[nexttoke].opval = newOP(OP_PADANY, 0);
2073 nextval[nexttoke].opval->op_targ = tmp;
2074 force_next(PRIVATEREF);
2079 /* Force them to make up their mind on "@foo". */
2080 if (lex_state != LEX_NORMAL && !lex_brackets &&
2081 ( !(gv = gv_fetchpv(tokenbuf+1, FALSE, SVt_PVAV)) ||
2087 sprintf(tmpbuf, "Literal @%s now requires backslash",tokenbuf+1);
2091 /* Warn about @ where they meant $. */
2093 if (*s == '[' || *s == '{') {
2095 while (*t && (isALNUM(*t) || strchr(" \t$#+-'\"", *t)))
2097 if (*t == '}' || *t == ']') {
2099 bufptr = skipspace(bufptr);
2100 warn("Scalar value %.*s better written as $%.*s",
2101 t-bufptr, bufptr, t-bufptr-1, bufptr+1);
2105 force_ident(tokenbuf+1, *tokenbuf);
2109 yyerror("Final @ should be \\@ or @name");
2114 case '/': /* may either be division or pattern */
2115 case '?': /* may either be conditional or pattern */
2116 if (expect != XOPERATOR) {
2119 TERM(sublex_start());
2127 if (lex_formbrack && lex_brackets == lex_formbrack && s[1] == '\n' &&
2128 (s == SvPVX(linestr) || s[-1] == '\n') ) {
2133 if (expect == XOPERATOR || !isDIGIT(s[1])) {
2139 yylval.ival = OPf_SPECIAL;
2145 if (expect != XOPERATOR)
2150 case '0': case '1': case '2': case '3': case '4':
2151 case '5': case '6': case '7': case '8': case '9':
2153 if (expect == XOPERATOR)
2159 if (expect == XOPERATOR) {
2160 if (lex_formbrack && lex_brackets == lex_formbrack) {
2163 return ','; /* grandfather non-comma-format format */
2169 missingterm((char*)0);
2170 yylval.ival = OP_CONST;
2171 TERM(sublex_start());
2175 if (expect == XOPERATOR) {
2176 if (lex_formbrack && lex_brackets == lex_formbrack) {
2179 return ','; /* grandfather non-comma-format format */
2185 missingterm((char*)0);
2186 yylval.ival = OP_CONST;
2187 for (d = SvPV(lex_stuff, len); len; len--, d++) {
2188 if (*d == '$' || *d == '@' || *d == '\\') {
2189 yylval.ival = OP_STRINGIFY;
2193 TERM(sublex_start());
2197 if (expect == XOPERATOR)
2198 no_op("Backticks",s);
2200 missingterm((char*)0);
2201 yylval.ival = OP_BACKTICK;
2203 TERM(sublex_start());
2207 if (dowarn && lex_inwhat && isDIGIT(*s))
2208 warn("Can't use \\%c to mean $%c in expression", *s, *s);
2209 if (expect == XOPERATOR)
2210 no_op("Backslash",s);
2214 if (isDIGIT(s[1]) && expect == XOPERATOR) {
2250 s = scan_word(s, tokenbuf, FALSE, &len);
2252 if (*s == ':' && s[1] == ':' && strNE(tokenbuf, "CORE"))
2255 tmp = keyword(tokenbuf, len);
2257 /* Is this a word before a => operator? */
2259 while (d < bufend && (*d == ' ' || *d == '\t'))
2260 d++; /* no comments skipped here, or s### is misparsed */
2261 if (strnEQ(d,"=>",2)) {
2263 if (dowarn && (tmp || perl_get_cv(tokenbuf, FALSE)))
2264 warn("Ambiguous use of %s => resolved to \"%s\" =>",
2265 tokenbuf, tokenbuf);
2266 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf,0));
2267 yylval.opval->op_private = OPpCONST_BARE;
2271 if (tmp < 0) { /* second-class keyword? */
2273 if (expect != XOPERATOR &&
2274 (*s != ':' || s[1] != ':') &&
2275 (gv = gv_fetchpv(tokenbuf,FALSE, SVt_PVCV)) &&
2276 (GvFLAGS(gv) & GVf_IMPORTED) &&
2288 default: /* not a keyword */
2291 char lastchar = (bufptr == oldoldbufptr ? 0 : bufptr[-1]);
2293 /* Get the rest if it looks like a package qualifier */
2295 if (*s == '\'' || *s == ':' && s[1] == ':') {
2296 s = scan_word(s, tokenbuf + len, TRUE, &len);
2298 croak("Bad name after %s::", tokenbuf);
2301 /* Do special processing at start of statement. */
2303 if (expect == XSTATE) {
2304 while (isSPACE(*s)) s++;
2305 if (*s == ':') { /* It's a label. */
2306 yylval.pval = savepv(tokenbuf);
2312 else if (expect == XOPERATOR) {
2313 if (bufptr == SvPVX(linestr)) {
2319 no_op("Bare word",s);
2322 /* Look for a subroutine with this name in current package. */
2324 gv = gv_fetchpv(tokenbuf,FALSE, SVt_PVCV);
2326 /* Presume this is going to be a bareword of some sort. */
2329 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf,0));
2330 yylval.opval->op_private = OPpCONST_BARE;
2332 /* See if it's the indirect object for a list operator. */
2335 oldoldbufptr < bufptr &&
2336 (oldoldbufptr == last_lop || oldoldbufptr == last_uni) &&
2337 /* NO SKIPSPACE BEFORE HERE! */
2339 (opargs[last_lop_op] >> OASHIFT & 7) == OA_FILEREF) )
2341 bool immediate_paren = *s == '(';
2343 /* (Now we can afford to cross potential line boundary.) */
2346 /* Two barewords in a row may indicate method call. */
2348 if ((isALPHA(*s) || *s == '$') && (tmp=intuit_method(s,gv)))
2351 /* If not a declared subroutine, it's an indirect object. */
2352 /* (But it's an indir obj regardless for sort.) */
2354 if ((last_lop_op == OP_SORT ||
2355 (!immediate_paren && (!gv || !GvCV(gv))) ) &&
2356 (last_lop_op != OP_MAPSTART && last_lop_op != OP_GREPSTART)){
2357 expect = (last_lop == oldoldbufptr) ? XTERM : XOPERATOR;
2362 /* If followed by a paren, it's certainly a subroutine. */
2368 nextval[nexttoke].opval = yylval.opval;
2374 /* If followed by var or block, call it a method (unless sub) */
2376 if ((*s == '$' || *s == '{') && (!gv || !GvCV(gv))) {
2377 last_lop = oldbufptr;
2378 last_lop_op = OP_METHOD;
2382 /* If followed by a bareword, see if it looks like indir obj. */
2384 if ((isALPHA(*s) || *s == '$') && (tmp = intuit_method(s,gv)))
2387 /* Not a method, so call it a subroutine (if defined) */
2389 if (gv && GvCV(gv)) {
2391 nextval[nexttoke].opval = yylval.opval;
2397 if (lastchar == '-')
2398 warn("Ambiguous use of -%s resolved as -&%s()",
2399 tokenbuf, tokenbuf);
2400 last_lop = oldbufptr;
2401 last_lop_op = OP_ENTERSUB;
2402 /* Is there a prototype? */
2405 char *proto = SvPV((SV*)cv, len);
2408 if (strEQ(proto, "$"))
2410 if (*proto == '&' && *s == '{') {
2411 sv_setpv(subname,"__ANON__");
2420 if (hints & HINT_STRICT_SUBS &&
2423 last_lop_op != OP_ACCEPT &&
2424 last_lop_op != OP_PIPE_OP &&
2425 last_lop_op != OP_SOCKPAIR)
2428 "Bareword \"%s\" not allowed while \"strict subs\" in use",
2433 /* Call it a bare word */
2437 if (lastchar != '-') {
2438 for (d = tokenbuf; *d && isLOWER(*d); d++) ;
2440 warn(warn_reserved, tokenbuf);
2443 if (lastchar && strchr("*%&", lastchar)) {
2444 warn("Operator or semicolon missing before %c%s",
2445 lastchar, tokenbuf);
2446 warn("Ambiguous use of %c resolved as operator %c",
2447 lastchar, lastchar);
2453 case KEY___FILE__: {
2454 if (tokenbuf[2] == 'L')
2455 (void)sprintf(tokenbuf,"%ld",(long)curcop->cop_line);
2457 strcpy(tokenbuf, SvPVX(GvSV(curcop->cop_filegv)));
2458 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf,0));
2467 if (!in_eval || tokenbuf[2] == 'D') {
2469 char *pname = "main";
2470 if (tokenbuf[2] == 'D')
2471 pname = HvNAME(curstash ? curstash : defstash);
2472 sprintf(dname,"%s::DATA", pname);
2473 gv = gv_fetchpv(dname,TRUE, SVt_PVIO);
2476 GvIOp(gv) = newIO();
2477 IoIFP(GvIOp(gv)) = rsfp;
2478 #if defined(HAS_FCNTL) && defined(F_SETFD)
2480 int fd = fileno(rsfp);
2481 fcntl(fd,F_SETFD,fd >= 3);
2485 IoTYPE(GvIOp(gv)) = '|';
2486 else if ((FILE*)rsfp == stdin)
2487 IoTYPE(GvIOp(gv)) = '-';
2489 IoTYPE(GvIOp(gv)) = '<';
2499 if (expect == XSTATE) {
2506 if (*s == ':' && s[1] == ':') {
2509 s = scan_word(s, tokenbuf, FALSE, &len);
2510 tmp = keyword(tokenbuf, len);
2524 LOP(OP_ACCEPT,XTERM);
2530 LOP(OP_ATAN2,XTERM);
2539 LOP(OP_BLESS,XTERM);
2548 (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */
2568 LOP(OP_CRYPT,XTERM);
2572 for (d = s; d < bufend && (isSPACE(*d) || *d == '('); d++) ;
2573 if (*d != '0' && isDIGIT(*d))
2574 yywarn("chmod: mode argument is missing initial 0");
2576 LOP(OP_CHMOD,XTERM);
2579 LOP(OP_CHOWN,XTERM);
2582 LOP(OP_CONNECT,XTERM);
2598 s = force_word(s,WORD,FALSE,TRUE,FALSE);
2602 hints |= HINT_BLOCK_SCOPE;
2612 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
2613 LOP(OP_DBMOPEN,XTERM);
2619 s = force_word(s,WORD,TRUE,FALSE,FALSE);
2626 yylval.ival = curcop->cop_line;
2640 expect = (*s == '{') ? XTERMBLOCK : XTERM;
2641 UNIBRACK(OP_ENTEREVAL);
2656 case KEY_endhostent:
2662 case KEY_endservent:
2665 case KEY_endprotoent:
2676 yylval.ival = curcop->cop_line;
2677 while (s < bufend && isSPACE(*s))
2680 croak("Missing $ on loop variable");
2684 LOP(OP_FORMLINE,XTERM);
2690 LOP(OP_FCNTL,XTERM);
2696 LOP(OP_FLOCK,XTERM);
2705 LOP(OP_GREPSTART, *s == '(' ? XTERM : XREF);
2708 s = force_word(s,WORD,TRUE,FALSE,FALSE);
2723 case KEY_getpriority:
2724 LOP(OP_GETPRIORITY,XTERM);
2726 case KEY_getprotobyname:
2729 case KEY_getprotobynumber:
2730 LOP(OP_GPBYNUMBER,XTERM);
2732 case KEY_getprotoent:
2744 case KEY_getpeername:
2745 UNI(OP_GETPEERNAME);
2747 case KEY_gethostbyname:
2750 case KEY_gethostbyaddr:
2751 LOP(OP_GHBYADDR,XTERM);
2753 case KEY_gethostent:
2756 case KEY_getnetbyname:
2759 case KEY_getnetbyaddr:
2760 LOP(OP_GNBYADDR,XTERM);
2765 case KEY_getservbyname:
2766 LOP(OP_GSBYNAME,XTERM);
2768 case KEY_getservbyport:
2769 LOP(OP_GSBYPORT,XTERM);
2771 case KEY_getservent:
2774 case KEY_getsockname:
2775 UNI(OP_GETSOCKNAME);
2777 case KEY_getsockopt:
2778 LOP(OP_GSOCKOPT,XTERM);
2800 yylval.ival = curcop->cop_line;
2804 LOP(OP_INDEX,XTERM);
2810 LOP(OP_IOCTL,XTERM);
2822 s = force_word(s,WORD,TRUE,FALSE,FALSE);
2854 LOP(OP_LISTEN,XTERM);
2861 TERM(sublex_start());
2864 LOP(OP_MAPSTART,XREF);
2867 LOP(OP_MKDIR,XTERM);
2870 LOP(OP_MSGCTL,XTERM);
2873 LOP(OP_MSGGET,XTERM);
2876 LOP(OP_MSGRCV,XTERM);
2879 LOP(OP_MSGSND,XTERM);
2887 s = force_word(s,WORD,TRUE,FALSE,FALSE);
2894 if (expect != XSTATE)
2895 yyerror("\"no\" not allowed in expression");
2896 s = force_word(s,WORD,FALSE,TRUE,FALSE);
2905 if (isIDFIRST(*s)) {
2907 for (d = s; isALNUM(*d); d++) ;
2909 if (strchr("|&*+-=!?:.", *t))
2910 warn("Precedence problem: open %.*s should be open(%.*s)",
2916 yylval.ival = OP_OR;
2926 LOP(OP_OPEN_DIR,XTERM);
2929 checkcomma(s,tokenbuf,"filehandle");
2933 checkcomma(s,tokenbuf,"filehandle");
2949 s = force_word(s,WORD,FALSE,TRUE,FALSE);
2953 LOP(OP_PIPE_OP,XTERM);
2958 missingterm((char*)0);
2959 yylval.ival = OP_CONST;
2960 TERM(sublex_start());
2968 missingterm((char*)0);
2970 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, q(lex_stuff));
2974 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(" ",1));
2977 yylval.ival = OP_SPLIT;
2981 last_lop = oldbufptr;
2982 last_lop_op = OP_SPLIT;
2988 missingterm((char*)0);
2989 yylval.ival = OP_STRINGIFY;
2990 if (SvIVX(lex_stuff) == '\'')
2991 SvIVX(lex_stuff) = 0; /* qq'$foo' should intepolate */
2992 TERM(sublex_start());
2997 missingterm((char*)0);
2998 yylval.ival = OP_BACKTICK;
3000 TERM(sublex_start());
3007 s = force_word(s,WORD,TRUE,TRUE,FALSE);
3008 if (isIDFIRST(*tokenbuf))
3009 gv_stashpv(tokenbuf, TRUE);
3011 yyerror("<> should be quotes");
3018 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3022 LOP(OP_RENAME,XTERM);
3031 LOP(OP_RINDEX,XTERM);
3054 LOP(OP_REVERSE,XTERM);
3065 TERM(sublex_start());
3067 TOKEN(1); /* force error */
3076 LOP(OP_SELECT,XTERM);
3082 LOP(OP_SEMCTL,XTERM);
3085 LOP(OP_SEMGET,XTERM);
3088 LOP(OP_SEMOP,XTERM);
3094 LOP(OP_SETPGRP,XTERM);
3096 case KEY_setpriority:
3097 LOP(OP_SETPRIORITY,XTERM);
3099 case KEY_sethostent:
3105 case KEY_setservent:
3108 case KEY_setprotoent:
3118 LOP(OP_SEEKDIR,XTERM);
3120 case KEY_setsockopt:
3121 LOP(OP_SSOCKOPT,XTERM);
3127 LOP(OP_SHMCTL,XTERM);
3130 LOP(OP_SHMGET,XTERM);
3133 LOP(OP_SHMREAD,XTERM);
3136 LOP(OP_SHMWRITE,XTERM);
3139 LOP(OP_SHUTDOWN,XTERM);
3148 LOP(OP_SOCKET,XTERM);
3150 case KEY_socketpair:
3151 LOP(OP_SOCKPAIR,XTERM);
3154 checkcomma(s,tokenbuf,"subroutine name");
3156 if (*s == ';' || *s == ')') /* probably a close */
3157 croak("sort is now a reserved word");
3159 s = force_word(s,WORD,TRUE,TRUE,TRUE);
3163 LOP(OP_SPLIT,XTERM);
3166 LOP(OP_SPRINTF,XTERM);
3169 LOP(OP_SPLICE,XTERM);
3185 LOP(OP_SUBSTR,XTERM);
3192 if (isIDFIRST(*s) || *s == '\'' || *s == ':') {
3195 d = scan_word(s, tmpbuf, TRUE, &len);
3196 if (strchr(tmpbuf, ':'))
3197 sv_setpv(subname, tmpbuf);
3199 sv_setsv(subname,curstname);
3200 sv_catpvn(subname,"::",2);
3201 sv_catpvn(subname,tmpbuf,len);
3203 s = force_word(s,WORD,FALSE,TRUE,TRUE);
3207 expect = XTERMBLOCK;
3208 sv_setpv(subname,"?");
3211 if (tmp == KEY_format) {
3214 lex_formbrack = lex_brackets + 1;
3218 /* Look for a prototype */
3223 SvREFCNT_dec(lex_stuff);
3225 croak("Prototype not terminated");
3228 nextval[1] = nextval[0];
3229 nexttype[1] = nexttype[0];
3230 nextval[0].opval = (OP*)newSVOP(OP_CONST, 0, lex_stuff);
3231 nexttype[0] = THING;
3232 if (nexttoke == 1) {
3233 lex_defer = lex_state;
3234 lex_expect = expect;
3235 lex_state = LEX_KNOWNEXT;
3240 if (*SvPV(subname,na) == '?') {
3241 sv_setpv(subname,"__ANON__");
3248 LOP(OP_SYSTEM,XREF);
3251 LOP(OP_SYMLINK,XTERM);
3254 LOP(OP_SYSCALL,XTERM);
3257 LOP(OP_SYSREAD,XTERM);
3260 LOP(OP_SYSWRITE,XTERM);
3264 TERM(sublex_start());
3282 LOP(OP_TRUNCATE,XTERM);
3294 yylval.ival = curcop->cop_line;
3298 yylval.ival = curcop->cop_line;
3302 LOP(OP_UNLINK,XTERM);
3308 LOP(OP_UNPACK,XTERM);
3311 LOP(OP_UTIME,XTERM);
3315 for (d = s; d < bufend && (isSPACE(*d) || *d == '('); d++) ;
3316 if (*d != '0' && isDIGIT(*d))
3317 yywarn("umask: argument is missing initial 0");
3322 LOP(OP_UNSHIFT,XTERM);
3325 if (expect != XSTATE)
3326 yyerror("\"use\" not allowed in expression");
3327 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3339 yylval.ival = curcop->cop_line;
3343 hints |= HINT_BLOCK_SCOPE;
3350 LOP(OP_WAITPID,XTERM);
3356 gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */
3360 if (expect == XOPERATOR)
3366 yylval.ival = OP_XOR;
3371 TERM(sublex_start());
3384 if (strEQ(d,"__LINE__")) return -KEY___LINE__;
3385 if (strEQ(d,"__FILE__")) return -KEY___FILE__;
3386 if (strEQ(d,"__DATA__")) return KEY___DATA__;
3387 if (strEQ(d,"__END__")) return KEY___END__;
3391 if (strEQ(d,"AUTOLOAD")) return KEY_AUTOLOAD;
3396 if (strEQ(d,"and")) return -KEY_and;
3397 if (strEQ(d,"abs")) return -KEY_abs;
3400 if (strEQ(d,"alarm")) return -KEY_alarm;
3401 if (strEQ(d,"atan2")) return -KEY_atan2;
3404 if (strEQ(d,"accept")) return -KEY_accept;
3409 if (strEQ(d,"BEGIN")) return KEY_BEGIN;
3412 if (strEQ(d,"bless")) return -KEY_bless;
3413 if (strEQ(d,"bind")) return -KEY_bind;
3414 if (strEQ(d,"binmode")) return -KEY_binmode;
3417 if (strEQ(d,"CORE")) return -KEY_CORE;
3422 if (strEQ(d,"cmp")) return -KEY_cmp;
3423 if (strEQ(d,"chr")) return -KEY_chr;
3424 if (strEQ(d,"cos")) return -KEY_cos;
3427 if (strEQ(d,"chop")) return KEY_chop;
3430 if (strEQ(d,"close")) return -KEY_close;
3431 if (strEQ(d,"chdir")) return -KEY_chdir;
3432 if (strEQ(d,"chomp")) return KEY_chomp;
3433 if (strEQ(d,"chmod")) return -KEY_chmod;
3434 if (strEQ(d,"chown")) return -KEY_chown;
3435 if (strEQ(d,"crypt")) return -KEY_crypt;
3438 if (strEQ(d,"chroot")) return -KEY_chroot;
3439 if (strEQ(d,"caller")) return -KEY_caller;
3442 if (strEQ(d,"connect")) return -KEY_connect;
3445 if (strEQ(d,"closedir")) return -KEY_closedir;
3446 if (strEQ(d,"continue")) return -KEY_continue;
3451 if (strEQ(d,"DESTROY")) return KEY_DESTROY;
3456 if (strEQ(d,"do")) return KEY_do;
3459 if (strEQ(d,"die")) return -KEY_die;
3462 if (strEQ(d,"dump")) return -KEY_dump;
3465 if (strEQ(d,"delete")) return KEY_delete;
3468 if (strEQ(d,"defined")) return KEY_defined;
3469 if (strEQ(d,"dbmopen")) return -KEY_dbmopen;
3472 if (strEQ(d,"dbmclose")) return -KEY_dbmclose;
3477 if (strEQ(d,"EQ")) { deprecate(d); return -KEY_eq;}
3478 if (strEQ(d,"END")) return KEY_END;
3483 if (strEQ(d,"eq")) return -KEY_eq;
3486 if (strEQ(d,"eof")) return -KEY_eof;
3487 if (strEQ(d,"exp")) return -KEY_exp;
3490 if (strEQ(d,"else")) return KEY_else;
3491 if (strEQ(d,"exit")) return -KEY_exit;
3492 if (strEQ(d,"eval")) return KEY_eval;
3493 if (strEQ(d,"exec")) return -KEY_exec;
3494 if (strEQ(d,"each")) return KEY_each;
3497 if (strEQ(d,"elsif")) return KEY_elsif;
3500 if (strEQ(d,"exists")) return KEY_exists;
3501 if (strEQ(d,"elseif")) warn("elseif should be elsif");
3504 if (strEQ(d,"endgrent")) return -KEY_endgrent;
3505 if (strEQ(d,"endpwent")) return -KEY_endpwent;
3508 if (strEQ(d,"endnetent")) return -KEY_endnetent;
3511 if (strEQ(d,"endhostent")) return -KEY_endhostent;
3512 if (strEQ(d,"endservent")) return -KEY_endservent;
3515 if (strEQ(d,"endprotoent")) return -KEY_endprotoent;
3522 if (strEQ(d,"for")) return KEY_for;
3525 if (strEQ(d,"fork")) return -KEY_fork;
3528 if (strEQ(d,"fcntl")) return -KEY_fcntl;
3529 if (strEQ(d,"flock")) return -KEY_flock;
3532 if (strEQ(d,"format")) return KEY_format;
3533 if (strEQ(d,"fileno")) return -KEY_fileno;
3536 if (strEQ(d,"foreach")) return KEY_foreach;
3539 if (strEQ(d,"formline")) return -KEY_formline;
3545 if (strEQ(d,"GT")) { deprecate(d); return -KEY_gt;}
3546 if (strEQ(d,"GE")) { deprecate(d); return -KEY_ge;}
3550 if (strnEQ(d,"get",3)) {
3555 if (strEQ(d,"ppid")) return -KEY_getppid;
3556 if (strEQ(d,"pgrp")) return -KEY_getpgrp;
3559 if (strEQ(d,"pwent")) return -KEY_getpwent;
3560 if (strEQ(d,"pwnam")) return -KEY_getpwnam;
3561 if (strEQ(d,"pwuid")) return -KEY_getpwuid;
3564 if (strEQ(d,"peername")) return -KEY_getpeername;
3565 if (strEQ(d,"protoent")) return -KEY_getprotoent;
3566 if (strEQ(d,"priority")) return -KEY_getpriority;
3569 if (strEQ(d,"protobyname")) return -KEY_getprotobyname;
3572 if (strEQ(d,"protobynumber"))return -KEY_getprotobynumber;
3576 else if (*d == 'h') {
3577 if (strEQ(d,"hostbyname")) return -KEY_gethostbyname;
3578 if (strEQ(d,"hostbyaddr")) return -KEY_gethostbyaddr;
3579 if (strEQ(d,"hostent")) return -KEY_gethostent;
3581 else if (*d == 'n') {
3582 if (strEQ(d,"netbyname")) return -KEY_getnetbyname;
3583 if (strEQ(d,"netbyaddr")) return -KEY_getnetbyaddr;
3584 if (strEQ(d,"netent")) return -KEY_getnetent;
3586 else if (*d == 's') {
3587 if (strEQ(d,"servbyname")) return -KEY_getservbyname;
3588 if (strEQ(d,"servbyport")) return -KEY_getservbyport;
3589 if (strEQ(d,"servent")) return -KEY_getservent;
3590 if (strEQ(d,"sockname")) return -KEY_getsockname;
3591 if (strEQ(d,"sockopt")) return -KEY_getsockopt;
3593 else if (*d == 'g') {
3594 if (strEQ(d,"grent")) return -KEY_getgrent;
3595 if (strEQ(d,"grnam")) return -KEY_getgrnam;
3596 if (strEQ(d,"grgid")) return -KEY_getgrgid;
3598 else if (*d == 'l') {
3599 if (strEQ(d,"login")) return -KEY_getlogin;
3601 else if (strEQ(d,"c")) return -KEY_getc;
3606 if (strEQ(d,"gt")) return -KEY_gt;
3607 if (strEQ(d,"ge")) return -KEY_ge;
3610 if (strEQ(d,"grep")) return KEY_grep;
3611 if (strEQ(d,"goto")) return KEY_goto;
3612 if (strEQ(d,"glob")) return -KEY_glob;
3615 if (strEQ(d,"gmtime")) return -KEY_gmtime;
3620 if (strEQ(d,"hex")) return -KEY_hex;
3625 if (strEQ(d,"if")) return KEY_if;
3628 if (strEQ(d,"int")) return -KEY_int;
3631 if (strEQ(d,"index")) return -KEY_index;
3632 if (strEQ(d,"ioctl")) return -KEY_ioctl;
3637 if (strEQ(d,"join")) return -KEY_join;
3641 if (strEQ(d,"keys")) return KEY_keys;
3642 if (strEQ(d,"kill")) return -KEY_kill;
3647 if (strEQ(d,"LT")) { deprecate(d); return -KEY_lt;}
3648 if (strEQ(d,"LE")) { deprecate(d); return -KEY_le;}
3654 if (strEQ(d,"lt")) return -KEY_lt;
3655 if (strEQ(d,"le")) return -KEY_le;
3656 if (strEQ(d,"lc")) return -KEY_lc;
3659 if (strEQ(d,"log")) return -KEY_log;
3662 if (strEQ(d,"last")) return KEY_last;
3663 if (strEQ(d,"link")) return -KEY_link;
3666 if (strEQ(d,"local")) return KEY_local;
3667 if (strEQ(d,"lstat")) return -KEY_lstat;
3670 if (strEQ(d,"length")) return -KEY_length;
3671 if (strEQ(d,"listen")) return -KEY_listen;
3674 if (strEQ(d,"lcfirst")) return -KEY_lcfirst;
3677 if (strEQ(d,"localtime")) return -KEY_localtime;
3683 case 1: return KEY_m;
3685 if (strEQ(d,"my")) return KEY_my;
3688 if (strEQ(d,"map")) return KEY_map;
3691 if (strEQ(d,"mkdir")) return -KEY_mkdir;
3694 if (strEQ(d,"msgctl")) return -KEY_msgctl;
3695 if (strEQ(d,"msgget")) return -KEY_msgget;
3696 if (strEQ(d,"msgrcv")) return -KEY_msgrcv;
3697 if (strEQ(d,"msgsnd")) return -KEY_msgsnd;
3702 if (strEQ(d,"NE")) { deprecate(d); return -KEY_ne;}
3705 if (strEQ(d,"next")) return KEY_next;
3706 if (strEQ(d,"ne")) return -KEY_ne;
3707 if (strEQ(d,"not")) return -KEY_not;
3708 if (strEQ(d,"no")) return KEY_no;
3713 if (strEQ(d,"or")) return -KEY_or;
3716 if (strEQ(d,"ord")) return -KEY_ord;
3717 if (strEQ(d,"oct")) return -KEY_oct;
3720 if (strEQ(d,"open")) return -KEY_open;
3723 if (strEQ(d,"opendir")) return -KEY_opendir;
3730 if (strEQ(d,"pop")) return KEY_pop;
3731 if (strEQ(d,"pos")) return KEY_pos;
3734 if (strEQ(d,"push")) return KEY_push;
3735 if (strEQ(d,"pack")) return -KEY_pack;
3736 if (strEQ(d,"pipe")) return -KEY_pipe;
3739 if (strEQ(d,"print")) return KEY_print;
3742 if (strEQ(d,"printf")) return KEY_printf;
3745 if (strEQ(d,"package")) return KEY_package;
3751 if (strEQ(d,"q")) return KEY_q;
3752 if (strEQ(d,"qq")) return KEY_qq;
3753 if (strEQ(d,"qw")) return KEY_qw;
3754 if (strEQ(d,"qx")) return KEY_qx;
3756 else if (strEQ(d,"quotemeta")) return -KEY_quotemeta;
3761 if (strEQ(d,"ref")) return -KEY_ref;
3764 if (strEQ(d,"read")) return -KEY_read;
3765 if (strEQ(d,"rand")) return -KEY_rand;
3766 if (strEQ(d,"recv")) return -KEY_recv;
3767 if (strEQ(d,"redo")) return KEY_redo;
3770 if (strEQ(d,"rmdir")) return -KEY_rmdir;
3771 if (strEQ(d,"reset")) return -KEY_reset;
3774 if (strEQ(d,"return")) return KEY_return;
3775 if (strEQ(d,"rename")) return -KEY_rename;
3776 if (strEQ(d,"rindex")) return -KEY_rindex;
3779 if (strEQ(d,"require")) return -KEY_require;
3780 if (strEQ(d,"reverse")) return -KEY_reverse;
3781 if (strEQ(d,"readdir")) return -KEY_readdir;
3784 if (strEQ(d,"readlink")) return -KEY_readlink;
3785 if (strEQ(d,"readline")) return -KEY_readline;
3786 if (strEQ(d,"readpipe")) return -KEY_readpipe;
3789 if (strEQ(d,"rewinddir")) return -KEY_rewinddir;
3795 case 0: return KEY_s;
3797 if (strEQ(d,"scalar")) return KEY_scalar;
3802 if (strEQ(d,"seek")) return -KEY_seek;
3803 if (strEQ(d,"send")) return -KEY_send;
3806 if (strEQ(d,"semop")) return -KEY_semop;
3809 if (strEQ(d,"select")) return -KEY_select;
3810 if (strEQ(d,"semctl")) return -KEY_semctl;
3811 if (strEQ(d,"semget")) return -KEY_semget;
3814 if (strEQ(d,"setpgrp")) return -KEY_setpgrp;
3815 if (strEQ(d,"seekdir")) return -KEY_seekdir;
3818 if (strEQ(d,"setpwent")) return -KEY_setpwent;
3819 if (strEQ(d,"setgrent")) return -KEY_setgrent;
3822 if (strEQ(d,"setnetent")) return -KEY_setnetent;
3825 if (strEQ(d,"setsockopt")) return -KEY_setsockopt;
3826 if (strEQ(d,"sethostent")) return -KEY_sethostent;
3827 if (strEQ(d,"setservent")) return -KEY_setservent;
3830 if (strEQ(d,"setpriority")) return -KEY_setpriority;
3831 if (strEQ(d,"setprotoent")) return -KEY_setprotoent;
3838 if (strEQ(d,"shift")) return KEY_shift;
3841 if (strEQ(d,"shmctl")) return -KEY_shmctl;
3842 if (strEQ(d,"shmget")) return -KEY_shmget;
3845 if (strEQ(d,"shmread")) return -KEY_shmread;
3848 if (strEQ(d,"shmwrite")) return -KEY_shmwrite;
3849 if (strEQ(d,"shutdown")) return -KEY_shutdown;
3854 if (strEQ(d,"sin")) return -KEY_sin;
3857 if (strEQ(d,"sleep")) return -KEY_sleep;
3860 if (strEQ(d,"sort")) return KEY_sort;
3861 if (strEQ(d,"socket")) return -KEY_socket;
3862 if (strEQ(d,"socketpair")) return -KEY_socketpair;
3865 if (strEQ(d,"split")) return KEY_split;
3866 if (strEQ(d,"sprintf")) return -KEY_sprintf;
3867 if (strEQ(d,"splice")) return KEY_splice;
3870 if (strEQ(d,"sqrt")) return -KEY_sqrt;
3873 if (strEQ(d,"srand")) return -KEY_srand;
3876 if (strEQ(d,"stat")) return -KEY_stat;
3877 if (strEQ(d,"study")) return KEY_study;
3880 if (strEQ(d,"substr")) return -KEY_substr;
3881 if (strEQ(d,"sub")) return KEY_sub;
3886 if (strEQ(d,"system")) return -KEY_system;
3889 if (strEQ(d,"sysread")) return -KEY_sysread;
3890 if (strEQ(d,"symlink")) return -KEY_symlink;
3891 if (strEQ(d,"syscall")) return -KEY_syscall;
3894 if (strEQ(d,"syswrite")) return -KEY_syswrite;
3903 if (strEQ(d,"tr")) return KEY_tr;
3906 if (strEQ(d,"tie")) return KEY_tie;
3909 if (strEQ(d,"tell")) return -KEY_tell;
3910 if (strEQ(d,"time")) return -KEY_time;
3913 if (strEQ(d,"times")) return -KEY_times;
3916 if (strEQ(d,"telldir")) return -KEY_telldir;
3919 if (strEQ(d,"truncate")) return -KEY_truncate;
3926 if (strEQ(d,"uc")) return -KEY_uc;
3929 if (strEQ(d,"use")) return KEY_use;
3932 if (strEQ(d,"undef")) return KEY_undef;
3933 if (strEQ(d,"until")) return KEY_until;
3934 if (strEQ(d,"untie")) return KEY_untie;
3935 if (strEQ(d,"utime")) return -KEY_utime;
3936 if (strEQ(d,"umask")) return -KEY_umask;
3939 if (strEQ(d,"unless")) return KEY_unless;
3940 if (strEQ(d,"unpack")) return -KEY_unpack;
3941 if (strEQ(d,"unlink")) return -KEY_unlink;
3944 if (strEQ(d,"unshift")) return KEY_unshift;
3945 if (strEQ(d,"ucfirst")) return -KEY_ucfirst;
3950 if (strEQ(d,"values")) return -KEY_values;
3951 if (strEQ(d,"vec")) return -KEY_vec;
3956 if (strEQ(d,"warn")) return -KEY_warn;
3957 if (strEQ(d,"wait")) return -KEY_wait;
3960 if (strEQ(d,"while")) return KEY_while;
3961 if (strEQ(d,"write")) return -KEY_write;
3964 if (strEQ(d,"waitpid")) return -KEY_waitpid;
3967 if (strEQ(d,"wantarray")) return -KEY_wantarray;
3972 if (len == 1) return -KEY_x;
3973 if (strEQ(d,"xor")) return -KEY_xor;
3976 if (len == 1) return KEY_y;
3985 checkcomma(s,name,what)
3992 if (dowarn && *s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
3994 for (w = s+2; *w && level; w++) {
4001 for (; *w && isSPACE(*w); w++) ;
4002 if (!*w || !strchr(";|})]oa!=", *w)) /* an advisory hack only... */
4003 warn("%s (...) interpreted as function",name);
4005 while (s < bufend && isSPACE(*s))
4009 while (s < bufend && isSPACE(*s))
4011 if (isIDFIRST(*s)) {
4015 while (s < bufend && isSPACE(*s))
4020 kw = keyword(w, s - w) || perl_get_cv(w, FALSE) != 0;
4024 croak("No comma allowed after %s", what);
4030 scan_word(s, dest, allow_package, slp)
4036 register char *d = dest;
4040 else if (*s == '\'' && allow_package && isIDFIRST(s[1])) {
4045 else if (*s == ':' && s[1] == ':' && allow_package && isIDFIRST(s[2])) {
4058 scan_ident(s,send,dest,ck_uni)
4060 register char *send;
4068 if (lex_brackets == 0)
4081 else if (*s == '\'' && isIDFIRST(s[1])) {
4086 else if (*s == ':' && s[1] == ':') {
4097 if (lex_state != LEX_NORMAL)
4098 lex_state = LEX_INTERPENDMAYBE;
4101 if (*s == '$' && s[1] &&
4102 (isALPHA(s[1]) || strchr("$_{", s[1]) || strnEQ(s+1,"::",2)) )
4113 if (*d == '^' && *s && (isUPPER(*s) || strchr("[\\]^_?", *s))) {
4117 if (isSPACE(s[-1])) {
4118 while (s < send && (*s == ' ' || *s == '\t')) s++;
4121 if (isALPHA(*d) || *d == '_') {
4123 while (isALNUM(*s) || *s == ':')
4126 while (s < send && (*s == ' ' || *s == '\t')) s++;
4127 if ((*s == '[' || *s == '{')) {
4128 if (dowarn && keyword(dest, d - dest)) {
4129 char *brack = *s == '[' ? "[...]" : "{...}";
4130 warn("Ambiguous use of %c{%s%s} resolved to %c%s%s",
4131 funny, dest, brack, funny, dest, brack);
4133 lex_fakebrack = lex_brackets+1;
4135 lex_brackstack[lex_brackets++] = XOPERATOR;
4141 if (lex_state == LEX_INTERPNORMAL && !lex_brackets)
4142 lex_state = LEX_INTERPEND;
4146 (keyword(dest, d - dest) || perl_get_cv(dest, FALSE)))
4147 warn("Ambiguous use of %c{%s} resolved to %c%s",
4148 funny, dest, funny, dest);
4151 s = bracket; /* let the parser handle it */
4155 else if (lex_state == LEX_INTERPNORMAL && !lex_brackets && !intuit_more(s))
4156 lex_state = LEX_INTERPEND;
4160 void pmflag(pmfl,ch)
4169 *pmfl |= PMf_GLOBAL;
4173 *pmfl |= PMf_MULTILINE;
4175 *pmfl |= PMf_SINGLELINE;
4177 *pmfl |= PMf_EXTENDED;
4187 s = scan_str(start);
4190 SvREFCNT_dec(lex_stuff);
4192 croak("Search pattern not terminated");
4194 pm = (PMOP*)newPMOP(OP_MATCH, 0);
4195 if (multi_open == '?')
4196 pm->op_pmflags |= PMf_ONCE;
4198 while (*s && strchr("iogmsx", *s))
4199 pmflag(&pm->op_pmflags,*s++);
4201 pm->op_pmpermflags = pm->op_pmflags;
4203 yylval.ival = OP_MATCH;
4215 yylval.ival = OP_NULL;
4217 s = scan_str(start);
4221 SvREFCNT_dec(lex_stuff);
4223 croak("Substitution pattern not terminated");
4226 if (s[-1] == multi_open)
4232 SvREFCNT_dec(lex_stuff);
4235 SvREFCNT_dec(lex_repl);
4237 croak("Substitution replacement not terminated");
4240 pm = (PMOP*)newPMOP(OP_SUBST, 0);
4241 while (*s && strchr("iogmsex", *s)) {
4247 pmflag(&pm->op_pmflags,*s++);
4252 pm->op_pmflags |= PMf_EVAL;
4253 repl = newSVpv("",0);
4255 sv_catpv(repl, es ? "eval " : "do ");
4256 sv_catpvn(repl, "{ ", 2);
4257 sv_catsv(repl, lex_repl);
4258 sv_catpvn(repl, " };", 2);
4259 SvCOMPILED_on(repl);
4260 SvREFCNT_dec(lex_repl);
4264 pm->op_pmpermflags = pm->op_pmflags;
4266 yylval.ival = OP_SUBST;
4274 if (!pm->op_pmshort && pm->op_pmregexp->regstart &&
4275 (!pm->op_pmregexp->regmust || pm->op_pmregexp->reganch & ROPT_ANCH)
4277 if (!(pm->op_pmregexp->reganch & ROPT_ANCH))
4278 pm->op_pmflags |= PMf_SCANFIRST;
4279 else if (pm->op_pmflags & PMf_FOLD)
4281 pm->op_pmshort = SvREFCNT_inc(pm->op_pmregexp->regstart);
4282 pm->op_pmslen = SvCUR(pm->op_pmshort);
4284 else if (pm->op_pmregexp->regmust) {/* is there a better short-circuit? */
4285 if (pm->op_pmshort &&
4286 sv_eq(pm->op_pmshort,pm->op_pmregexp->regmust))
4288 if (pm->op_pmflags & PMf_SCANFIRST) {
4289 SvREFCNT_dec(pm->op_pmshort);
4290 pm->op_pmshort = Nullsv;
4293 SvREFCNT_dec(pm->op_pmregexp->regmust);
4294 pm->op_pmregexp->regmust = Nullsv;
4298 if (!pm->op_pmshort || /* promote the better string */
4299 ((pm->op_pmflags & PMf_SCANFIRST) &&
4300 (SvCUR(pm->op_pmshort) < SvCUR(pm->op_pmregexp->regmust)) )){
4301 SvREFCNT_dec(pm->op_pmshort); /* ok if null */
4302 pm->op_pmshort = pm->op_pmregexp->regmust;
4303 pm->op_pmslen = SvCUR(pm->op_pmshort);
4304 pm->op_pmregexp->regmust = Nullsv;
4305 pm->op_pmflags |= PMf_SCANFIRST;
4321 yylval.ival = OP_NULL;
4323 s = scan_str(start);
4326 SvREFCNT_dec(lex_stuff);
4328 croak("Translation pattern not terminated");
4330 if (s[-1] == multi_open)
4336 SvREFCNT_dec(lex_stuff);
4339 SvREFCNT_dec(lex_repl);
4341 croak("Translation replacement not terminated");
4344 New(803,tbl,256,short);
4345 op = newPVOP(OP_TRANS, 0, (char*)tbl);
4347 complement = delete = squash = 0;
4348 while (*s == 'c' || *s == 'd' || *s == 's') {
4350 complement = OPpTRANS_COMPLEMENT;
4352 delete = OPpTRANS_DELETE;
4354 squash = OPpTRANS_SQUASH;
4357 op->op_private = delete|squash|complement;
4360 yylval.ival = OP_TRANS;
4369 I32 op_type = OP_SCALAR;
4380 for (peek = s; *peek == ' ' || *peek == '\t'; peek++) ;
4381 if (*peek && strchr("`'\"",*peek)) {
4384 s = cpytill(d,s,bufend,term,&len);
4395 deprecate("bare << to mean <<\"\"");
4398 } /* assuming tokenbuf won't clobber */
4403 if (rsfp || !(d=ninstr(s,bufend,d,d+1)))
4404 herewas = newSVpv(s,bufend-s);
4406 s--, herewas = newSVpv(s,d-s);
4407 s += SvCUR(herewas);
4409 tmpstr = NEWSV(87,80);
4410 sv_upgrade(tmpstr, SVt_PVIV);
4415 else if (term == '`') {
4416 op_type = OP_BACKTICK;
4417 SvIVX(tmpstr) = '\\';
4421 multi_start = curcop->cop_line;
4422 multi_open = multi_close = '<';
4426 while (s < bufend &&
4427 (*s != term || bcmp(s,tokenbuf,len) != 0) ) {
4432 curcop->cop_line = multi_start;
4433 missingterm(tokenbuf);
4435 sv_setpvn(tmpstr,d+1,s-d);
4437 sv_catpvn(herewas,s,bufend-s);
4438 sv_setsv(linestr,herewas);
4439 oldoldbufptr = oldbufptr = bufptr = s = SvPVX(linestr);
4440 bufend = SvPVX(linestr) + SvCUR(linestr);
4443 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
4444 while (s >= bufend) { /* multiple line string? */
4446 !(oldoldbufptr = oldbufptr = s = filter_gets(linestr, rsfp))) {
4447 curcop->cop_line = multi_start;
4448 missingterm(tokenbuf);
4451 if (perldb && curstash != debstash) {
4452 SV *sv = NEWSV(88,0);
4454 sv_upgrade(sv, SVt_PVMG);
4455 sv_setsv(sv,linestr);
4456 av_store(GvAV(curcop->cop_filegv),
4457 (I32)curcop->cop_line,sv);
4459 bufend = SvPVX(linestr) + SvCUR(linestr);
4460 if (*s == term && bcmp(s,tokenbuf,len) == 0) {
4463 sv_catsv(linestr,herewas);
4464 bufend = SvPVX(linestr) + SvCUR(linestr);
4468 sv_catsv(tmpstr,linestr);
4471 multi_end = curcop->cop_line;
4473 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
4474 SvLEN_set(tmpstr, SvCUR(tmpstr) + 1);
4475 Renew(SvPVX(tmpstr), SvLEN(tmpstr), char);
4477 SvREFCNT_dec(herewas);
4479 yylval.ival = op_type;
4484 scan_inputsymbol(start)
4487 register char *s = start;
4492 s = cpytill(d, s+1, bufend, '>', &len);
4496 croak("Unterminated <> operator");
4498 if (*d == '$' && d[1]) d++;
4499 while (*d && (isALNUM(*d) || *d == '\'' || *d == ':'))
4501 if (d - tokenbuf != len) {
4502 yylval.ival = OP_GLOB;
4504 s = scan_str(start);
4506 croak("Glob not terminated");
4512 (void)strcpy(d,"ARGV");
4515 if (tmp = pad_findmy(d)) {
4516 OP *op = newOP(OP_PADSV, 0);
4518 lex_op = (OP*)newUNOP(OP_READLINE, 0, newUNOP(OP_RV2GV, 0, op));
4521 GV *gv = gv_fetchpv(d+1,TRUE, SVt_PV);
4522 lex_op = (OP*)newUNOP(OP_READLINE, 0,
4523 newUNOP(OP_RV2GV, 0,
4524 newUNOP(OP_RV2SV, 0,
4525 newGVOP(OP_GV, 0, gv))));
4527 yylval.ival = OP_NULL;
4530 GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO);
4531 lex_op = (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
4532 yylval.ival = OP_NULL;
4544 register char *s = start;
4553 multi_start = curcop->cop_line;
4555 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4560 sv_upgrade(sv, SVt_PVIV);
4562 (void)SvPOK_only(sv); /* validate pointer */
4565 SvGROW(sv, SvCUR(sv) + (bufend - s) + 1);
4566 to = SvPVX(sv)+SvCUR(sv);
4567 if (multi_open == multi_close) {
4568 for (; s < bufend; s++,to++) {
4569 if (*s == '\n' && !rsfp)
4571 if (*s == '\\' && s+1 < bufend && term != '\\') {
4577 else if (*s == term)
4583 for (; s < bufend; s++,to++) {
4584 if (*s == '\n' && !rsfp)
4586 if (*s == '\\' && s+1 < bufend && term != '\\') {
4592 else if (*s == term && --brackets <= 0)
4594 else if (*s == multi_open)
4600 SvCUR_set(sv, to - SvPVX(sv));
4602 if (s < bufend) break; /* string ends on this line? */
4605 !(oldoldbufptr = oldbufptr = s = filter_gets(linestr, rsfp))) {
4606 curcop->cop_line = multi_start;
4610 if (perldb && curstash != debstash) {
4611 SV *sv = NEWSV(88,0);
4613 sv_upgrade(sv, SVt_PVMG);
4614 sv_setsv(sv,linestr);
4615 av_store(GvAV(curcop->cop_filegv),
4616 (I32)curcop->cop_line, sv);
4618 bufend = SvPVX(linestr) + SvCUR(linestr);
4620 multi_end = curcop->cop_line;
4622 if (SvCUR(sv) + 5 < SvLEN(sv)) {
4623 SvLEN_set(sv, SvCUR(sv) + 1);
4624 Renew(SvPVX(sv), SvLEN(sv), char);
4637 register char *s = start;
4647 croak("panic: scan_num");
4657 else if (s[1] == '.')
4671 yyerror("Illegal octal digit");
4673 case '0': case '1': case '2': case '3': case '4':
4674 case '5': case '6': case '7':
4678 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
4679 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
4683 i += (*s++ & 7) + 9;
4690 if (tryi32 == i && tryi32 >= 0)
4691 sv_setiv(sv,tryi32);
4693 sv_setnv(sv,(double)i);
4696 case '1': case '2': case '3': case '4': case '5':
4697 case '6': case '7': case '8': case '9': case '.':
4701 while (isDIGIT(*s) || *s == '_') {
4703 if (dowarn && lastub && s - lastub != 3)
4704 warn("Misplaced _ in number");
4710 if (dowarn && lastub && s - lastub != 3)
4711 warn("Misplaced _ in number");
4712 if (*s == '.' && s[1] != '.') {
4715 while (isDIGIT(*s) || *s == '_') {
4722 if (*s && strchr("eE",*s) && strchr("+-0123456789",s[1])) {
4725 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
4726 if (*s == '+' || *s == '-')
4733 value = atof(tokenbuf);
4734 tryi32 = I_32(value);
4735 if (!floatit && (double)tryi32 == value)
4736 sv_setiv(sv,tryi32);
4742 yylval.opval = newSVOP(OP_CONST, 0, sv);
4753 SV *stuff = newSVpv("",0);
4754 bool needargs = FALSE;
4757 if (*s == '.' || *s == '}') {
4759 for (t = s+1; *t == ' ' || *t == '\t'; t++) ;
4763 if (in_eval && !rsfp) {
4764 eol = strchr(s,'\n');
4769 eol = bufend = SvPVX(linestr) + SvCUR(linestr);
4771 for (t = s; t < eol; t++) {
4772 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
4774 goto enough; /* ~~ must be first line in formline */
4776 if (*t == '@' || *t == '^')
4779 sv_catpvn(stuff, s, eol-s);
4783 s = filter_gets(linestr, rsfp);
4784 oldoldbufptr = oldbufptr = bufptr = SvPVX(linestr);
4785 bufend = bufptr + SvCUR(linestr);
4788 yyerror("Format not terminated");
4798 lex_state = LEX_NORMAL;
4799 nextval[nexttoke].ival = 0;
4803 lex_state = LEX_FORMLINE;
4804 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff);
4806 nextval[nexttoke].ival = OP_FORMLINE;
4810 SvREFCNT_dec(stuff);
4822 cshlen = strlen(cshname);
4829 int oldsavestack_ix = savestack_ix;
4830 CV* outsidecv = compcv;
4834 assert(SvTYPE(compcv) == SVt_PVCV);
4841 SAVESPTR(comppad_name);
4843 SAVEINT(comppad_name_fill);
4844 SAVEINT(min_intro_pending);
4845 SAVEINT(max_intro_pending);
4846 SAVEINT(pad_reset_pending);
4848 compcv = (CV*)NEWSV(1104,0);
4849 sv_upgrade((SV *)compcv, SVt_PVCV);
4852 comppad_name = newAV();
4853 comppad_name_fill = 0;
4854 min_intro_pending = 0;
4855 av_push(comppad, Nullsv);
4856 curpad = AvARRAY(comppad);
4858 subline = curcop->cop_line;
4860 comppadlist = newAV();
4861 AvREAL_off(comppadlist);
4862 av_store(comppadlist, 0, (SV*)comppad_name);
4863 av_store(comppadlist, 1, (SV*)comppad);
4865 CvPADLIST(compcv) = comppadlist;
4866 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc((SV*)outsidecv);
4868 return oldsavestack_ix;
4887 char *tname = tmpbuf;
4889 if (bufptr > oldoldbufptr && bufptr - oldoldbufptr < 200 &&
4890 oldoldbufptr != oldbufptr && oldbufptr != bufptr) {
4891 while (isSPACE(*oldoldbufptr))
4893 sprintf(tname,"near \"%.*s\"",bufptr - oldoldbufptr, oldoldbufptr);
4895 else if (bufptr > oldbufptr && bufptr - oldbufptr < 200 &&
4896 oldbufptr != bufptr) {
4897 while (isSPACE(*oldbufptr))
4899 sprintf(tname,"near \"%.*s\"",bufptr - oldbufptr, oldbufptr);
4901 else if (yychar > 255)
4902 tname = "next token ???";
4903 else if (!yychar || (yychar == ';' && !rsfp))
4904 (void)strcpy(tname,"at EOF");
4905 else if ((yychar & 127) == 127) {
4906 if (lex_state == LEX_NORMAL ||
4907 (lex_state == LEX_KNOWNEXT && lex_defer == LEX_NORMAL))
4908 (void)strcpy(tname,"at end of line");
4910 (void)strcpy(tname,"within pattern");
4912 (void)strcpy(tname,"within string");
4914 else if (yychar < 32)
4915 (void)sprintf(tname,"next char ^%c",yychar+64);
4917 (void)sprintf(tname,"next char %c",yychar);
4918 (void)sprintf(buf, "%s at %s line %d, %s\n",
4919 s,SvPVX(GvSV(curcop->cop_filegv)),curcop->cop_line,tname);
4920 if (curcop->cop_line == multi_end && multi_start < multi_end) {
4921 sprintf(buf+strlen(buf),
4922 " (Might be a runaway multi-line %c%c string starting on line %ld)\n",
4923 multi_open,multi_close,(long)multi_start);
4929 sv_catpv(GvSV(errgv),buf);
4932 if (++error_count >= 10)
4933 croak("%s has too many errors.\n",
4934 SvPVX(GvSV(curcop->cop_filegv)));