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));
53 static char ident_too_long[] = "Identifier too long";
55 static char *linestart; /* beg. of most recently read line */
57 static char pending_ident; /* pending identifier lookup */
60 I32 super_state; /* lexer state to save */
61 I32 sub_inwhat; /* "lex_inwhat" to use */
62 OP *sub_op; /* "lex_op" to use */
65 /* The following are arranged oddly so that the guard on the switch statement
66 * can get by with a single comparison (if the compiler is smart enough).
69 /* #define LEX_NOTPARSING 11 is done in perl.h. */
72 #define LEX_INTERPNORMAL 9
73 #define LEX_INTERPCASEMOD 8
74 #define LEX_INTERPPUSH 7
75 #define LEX_INTERPSTART 6
76 #define LEX_INTERPEND 5
77 #define LEX_INTERPENDMAYBE 4
78 #define LEX_INTERPCONCAT 3
79 #define LEX_INTERPCONST 2
80 #define LEX_FORMLINE 1
81 #define LEX_KNOWNEXT 0
90 /* XXX If this causes problems, set i_unistd=undef in the hint file. */
92 # include <unistd.h> /* Needed for execv() */
100 #include "keywords.h"
105 #define CLINE (copline = (curcop->cop_line < copline ? curcop->cop_line : copline))
107 #define TOKEN(retval) return (bufptr = s,(int)retval)
108 #define OPERATOR(retval) return (expect = XTERM,bufptr = s,(int)retval)
109 #define AOPERATOR(retval) return ao((expect = XTERM,bufptr = s,(int)retval))
110 #define PREBLOCK(retval) return (expect = XBLOCK,bufptr = s,(int)retval)
111 #define PRETERMBLOCK(retval) return (expect = XTERMBLOCK,bufptr = s,(int)retval)
112 #define PREREF(retval) return (expect = XREF,bufptr = s,(int)retval)
113 #define TERM(retval) return (CLINE, expect = XOPERATOR,bufptr = s,(int)retval)
114 #define LOOPX(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)LOOPEX)
115 #define FTST(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)UNIOP)
116 #define FUN0(f) return(yylval.ival = f,expect = XOPERATOR,bufptr = s,(int)FUNC0)
117 #define FUN1(f) return(yylval.ival = f,expect = XOPERATOR,bufptr = s,(int)FUNC1)
118 #define BOop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)BITOROP))
119 #define BAop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)BITANDOP))
120 #define SHop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)SHIFTOP))
121 #define PWop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)POWOP))
122 #define PMop(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)MATCHOP)
123 #define Aop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)ADDOP))
124 #define Mop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)MULOP))
125 #define Eop(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)EQOP)
126 #define Rop(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)RELOP)
128 /* This bit of chicanery makes a unary function followed by
129 * a parenthesis into a function with one argument, highest precedence.
131 #define UNI(f) return(yylval.ival = f, \
134 last_uni = oldbufptr, \
136 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
138 #define UNIBRACK(f) return(yylval.ival = f, \
140 last_uni = oldbufptr, \
141 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
143 /* grandfather return to old style */
144 #define OLDLOP(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)LSTOP)
149 if (*bufptr == '=') {
151 if (toketype == ANDAND)
152 yylval.ival = OP_ANDASSIGN;
153 else if (toketype == OROR)
154 yylval.ival = OP_ORASSIGN;
161 no_op(char *what, char *s)
163 char *oldbp = bufptr;
164 bool is_first = (oldbufptr == linestart);
167 yywarn(form("%s found where operator expected", what));
169 warn("\t(Missing semicolon on previous line?)\n");
170 else if (oldoldbufptr && isIDFIRST(*oldoldbufptr)) {
172 for (t = oldoldbufptr; *t && (isALNUM(*t) || *t == ':'); t++) ;
173 if (t < bufptr && isSPACE(*t))
174 warn("\t(Do you need to predeclare %.*s?)\n",
175 t - oldoldbufptr, oldoldbufptr);
179 warn("\t(Missing operator before %.*s?)\n", s - oldbp, oldbp);
189 char *nl = strrchr(s,'\n');
193 else if (multi_close < 32 || multi_close == 127) {
195 tmpbuf[1] = toCTRL(multi_close);
201 *tmpbuf = multi_close;
205 q = strchr(s,'"') ? '\'' : '"';
206 croak("Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
213 warn("Use of %s is deprecated", s);
219 deprecate("comma-less variable list");
225 win32_textfilter(int idx, SV *sv, int maxlen)
227 I32 count = FILTER_READ(idx+1, sv, maxlen);
228 if (count > 0 && !maxlen)
229 win32_strip_return(sv);
243 SAVEI32(lex_brackets);
244 SAVEI32(lex_fakebrack);
245 SAVEI32(lex_casemods);
250 SAVEI16(curcop->cop_line);
254 SAVEPPTR(oldoldbufptr);
257 SAVEPPTR(lex_brackstack);
258 SAVEPPTR(lex_casestack);
259 SAVEDESTRUCTOR(restore_rsfp, rsfp);
261 lex_state = LEX_NORMAL;
266 New(899, lex_brackstack, 120, char);
267 New(899, lex_casestack, 12, char);
268 SAVEFREEPV(lex_brackstack);
269 SAVEFREEPV(lex_casestack);
271 *lex_casestack = '\0';
275 SvREFCNT_dec(lex_stuff);
278 SvREFCNT_dec(lex_repl);
283 if (SvREADONLY(linestr))
284 linestr = sv_2mortal(newSVsv(linestr));
285 s = SvPV(linestr, len);
286 if (len && s[len-1] != ';') {
287 if (!(SvFLAGS(linestr) & SVs_TEMP))
288 linestr = sv_2mortal(newSVsv(linestr));
289 sv_catpvn(linestr, "\n;", 2);
292 oldoldbufptr = oldbufptr = bufptr = linestart = SvPVX(linestr);
293 bufend = bufptr + SvCUR(linestr);
295 rs = newSVpv("\n", 1);
306 restore_rsfp(void *f)
308 PerlIO *fp = (PerlIO*)f;
310 if (rsfp == PerlIO_stdin())
311 PerlIO_clearerr(rsfp);
312 else if (rsfp && (rsfp != fp))
329 while (*s == ' ' || *s == '\t') s++;
330 if (strnEQ(s, "line ", 5)) {
339 while (*s == ' ' || *s == '\t')
341 if (*s == '"' && (t = strchr(s+1, '"')))
345 return; /* false alarm */
346 for (t = s; !isSPACE(*t); t++) ;
351 curcop->cop_filegv = gv_fetchfile(s);
353 curcop->cop_filegv = gv_fetchfile(origfilename);
355 curcop->cop_line = atoi(n)-1;
359 skipspace(register char *s)
362 if (lex_formbrack && lex_brackets <= lex_formbrack) {
363 while (s < bufend && (*s == ' ' || *s == '\t'))
369 while (s < bufend && isSPACE(*s))
371 if (s < bufend && *s == '#') {
372 while (s < bufend && *s != '\n')
377 if (s < bufend || !rsfp || lex_state != LEX_NORMAL)
379 if ((s = filter_gets(linestr, rsfp, (prevlen = SvCUR(linestr)))) == Nullch) {
380 if (minus_n || minus_p) {
381 sv_setpv(linestr,minus_p ?
382 ";}continue{print or die qq(-p destination: $!\\n)" :
384 sv_catpv(linestr,";}");
385 minus_n = minus_p = 0;
388 sv_setpv(linestr,";");
389 oldoldbufptr = oldbufptr = bufptr = s = linestart = SvPVX(linestr);
390 bufend = SvPVX(linestr) + SvCUR(linestr);
391 if (preprocess && !in_eval)
392 (void)my_pclose(rsfp);
393 else if ((PerlIO*)rsfp == PerlIO_stdin())
394 PerlIO_clearerr(rsfp);
396 (void)PerlIO_close(rsfp);
402 linestart = bufptr = s + prevlen;
403 bufend = s + SvCUR(linestr);
406 if (PERLDB_LINE && curstash != debstash) {
407 SV *sv = NEWSV(85,0);
409 sv_upgrade(sv, SVt_PVMG);
410 sv_setpvn(sv,bufptr,bufend-bufptr);
411 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
422 if (oldoldbufptr != last_uni)
424 while (isSPACE(*last_uni))
426 for (s = last_uni; isALNUM(*s) || *s == '-'; s++) ;
427 if ((t = strchr(s, '(')) && t < bufptr)
431 warn("Warning: Use of \"%s\" without parens is ambiguous", last_uni);
438 #define UNI(f) return uni(f,s)
446 last_uni = oldbufptr;
457 #endif /* CRIPPLED_CC */
459 #define LOP(f,x) return lop(f,x,s)
464 (I32 f, expectation x, char *s)
470 #endif /* CAN_PROTOTYPE */
477 last_lop = oldbufptr;
493 nexttype[nexttoke] = type;
495 if (lex_state != LEX_KNOWNEXT) {
496 lex_defer = lex_state;
498 lex_state = LEX_KNOWNEXT;
503 force_word(register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
508 start = skipspace(start);
511 (allow_pack && *s == ':') ||
512 (allow_initial_tick && *s == '\'') )
514 s = scan_word(s, tokenbuf, sizeof tokenbuf, allow_pack, &len);
515 if (check_keyword && keyword(tokenbuf, len))
517 if (token == METHOD) {
527 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST,0, newSVpv(tokenbuf,0));
528 nextval[nexttoke].opval->op_private |= OPpCONST_BARE;
535 force_ident(register char *s, int kind)
538 OP* o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
539 nextval[nexttoke].opval = o;
542 dTHR; /* just for in_eval */
543 o->op_private = OPpCONST_ENTERED;
544 /* XXX see note in pp_entereval() for why we forgo typo
545 warnings if the symbol must be introduced in an eval.
547 gv_fetchpv(s, in_eval ? GV_ADDMULTI : TRUE,
548 kind == '$' ? SVt_PV :
549 kind == '@' ? SVt_PVAV :
550 kind == '%' ? SVt_PVHV :
558 force_version(char *s)
560 OP *version = Nullop;
564 /* default VERSION number -- GBARR */
569 for( d=s, c = 1; isDIGIT(*d) || *d == '_' || (*d == '.' && c--); d++);
570 if((*d == ';' || isSPACE(*d)) && *(skipspace(d)) != ',') {
572 /* real VERSION number -- GBARR */
573 version = yylval.opval;
577 /* NOTE: The parser sees the package name and the VERSION swapped */
578 nextval[nexttoke].opval = version;
595 s = SvPV_force(sv, len);
599 while (s < send && *s != '\\')
606 if (s + 1 < send && (s[1] == '\\'))
607 s++; /* all that, just for this */
612 SvCUR_set(sv, d - SvPVX(sv));
620 register I32 op_type = yylval.ival;
622 if (op_type == OP_NULL) {
623 yylval.opval = lex_op;
627 if (op_type == OP_CONST || op_type == OP_READLINE) {
628 SV *sv = q(lex_stuff);
630 char *p = SvPV(sv, len);
631 yylval.opval = (OP*)newSVOP(op_type, 0, newSVpv(p, len));
637 sublex_info.super_state = lex_state;
638 sublex_info.sub_inwhat = op_type;
639 sublex_info.sub_op = lex_op;
640 lex_state = LEX_INTERPPUSH;
644 yylval.opval = lex_op;
658 lex_state = sublex_info.super_state;
660 SAVEI32(lex_brackets);
661 SAVEI32(lex_fakebrack);
662 SAVEI32(lex_casemods);
667 SAVEI16(curcop->cop_line);
670 SAVEPPTR(oldoldbufptr);
673 SAVEPPTR(lex_brackstack);
674 SAVEPPTR(lex_casestack);
679 bufend = bufptr = oldbufptr = oldoldbufptr = linestart = SvPVX(linestr);
680 bufend += SvCUR(linestr);
686 New(899, lex_brackstack, 120, char);
687 New(899, lex_casestack, 12, char);
688 SAVEFREEPV(lex_brackstack);
689 SAVEFREEPV(lex_casestack);
691 *lex_casestack = '\0';
693 lex_state = LEX_INTERPCONCAT;
694 curcop->cop_line = multi_start;
696 lex_inwhat = sublex_info.sub_inwhat;
697 if (lex_inwhat == OP_MATCH || lex_inwhat == OP_SUBST)
698 lex_inpat = sublex_info.sub_op;
710 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv("",0));
714 if (lex_casemods) { /* oops, we've got some unbalanced parens */
715 lex_state = LEX_INTERPCASEMOD;
719 /* Is there a right-hand side to take care of? */
720 if (lex_repl && (lex_inwhat == OP_SUBST || lex_inwhat == OP_TRANS)) {
723 bufend = bufptr = oldbufptr = oldoldbufptr = linestart = SvPVX(linestr);
724 bufend += SvCUR(linestr);
730 *lex_casestack = '\0';
732 if (SvCOMPILED(lex_repl)) {
733 lex_state = LEX_INTERPNORMAL;
737 lex_state = LEX_INTERPCONCAT;
743 bufend = SvPVX(linestr);
744 bufend += SvCUR(linestr);
751 scan_const(char *start)
753 register char *send = bufend;
754 SV *sv = NEWSV(93, send - start);
755 register char *s = start;
756 register char *d = SvPVX(sv);
757 bool dorange = FALSE;
761 ? "\\.^$@AGZdDwWsSbB+*?|()-nrtfeaxc0123456789[{]} \t\n\r\f\v#"
762 : (lex_inwhat & OP_TRANS)
766 while (s < send || dorange) {
767 if (lex_inwhat == OP_TRANS) {
772 SvGROW(sv, SvLEN(sv) + 256);
776 for (i = (U8)*d; i <= max; i++)
781 else if (*s == '-' && s+1 < send && s != start) {
786 else if (*s == '(' && lex_inpat && s[1] == '?' && s[2] == '#') {
787 while (s < send && *s != ')')
790 else if (*s == '#' && lex_inpat &&
791 ((PMOP*)lex_inpat)->op_pmflags & PMf_EXTENDED) {
792 while (s+1 < send && *s != '\n')
795 else if (*s == '@' && s[1] && (isALNUM(s[1]) || strchr(":'{$", s[1])))
797 else if (*s == '$') {
798 if (!lex_inpat) /* not a regexp, so $ must be var */
800 if (s + 1 < send && !strchr("()| \n\t", s[1]))
801 break; /* in regexp, $ might be tail anchor */
803 if (*s == '\\' && s+1 < send) {
805 if (*s && strchr(leaveit, *s)) {
810 if (lex_inwhat == OP_SUBST && !lex_inpat &&
811 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
814 warn("\\%c better written as $%c", *s, *s);
818 if (lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
824 if (lex_inwhat == OP_TRANS) {
832 case '0': case '1': case '2': case '3':
833 case '4': case '5': case '6': case '7':
834 *d++ = scan_oct(s, 3, &len);
838 *d++ = scan_hex(++s, 2, &len);
874 SvCUR_set(sv, d - SvPVX(sv));
877 if (SvCUR(sv) + 5 < SvLEN(sv)) {
878 SvLEN_set(sv, SvCUR(sv) + 1);
879 Renew(SvPVX(sv), SvLEN(sv), char);
882 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
888 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
890 intuit_more(register char *s)
894 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
896 if (*s != '{' && *s != '[')
901 /* In a pattern, so maybe we have {n,m}. */
918 /* On the other hand, maybe we have a character class */
921 if (*s == ']' || *s == '^')
924 int weight = 2; /* let's weigh the evidence */
926 unsigned char un_char = 0, last_un_char;
927 char *send = strchr(s,']');
928 char tmpbuf[sizeof tokenbuf * 4];
930 if (!send) /* has to be an expression */
936 else if (isDIGIT(*s)) {
938 if (isDIGIT(s[1]) && s[2] == ']')
944 for (; s < send; s++) {
945 last_un_char = un_char;
946 un_char = (unsigned char)*s;
951 weight -= seen[un_char] * 10;
953 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
954 if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV))
959 else if (*s == '$' && s[1] &&
960 strchr("[#!%*<>()-=",s[1])) {
961 if (/*{*/ strchr("])} =",s[2]))
970 if (strchr("wds]",s[1]))
972 else if (seen['\''] || seen['"'])
974 else if (strchr("rnftbxcav",s[1]))
976 else if (isDIGIT(s[1])) {
978 while (s[1] && isDIGIT(s[1]))
988 if (strchr("aA01! ",last_un_char))
990 if (strchr("zZ79~",s[1]))
994 if (!isALNUM(last_un_char) && !strchr("$@&",last_un_char) &&
995 isALPHA(*s) && s[1] && isALPHA(s[1])) {
1000 if (keyword(tmpbuf, d - tmpbuf))
1003 if (un_char == last_un_char + 1)
1005 weight -= seen[un_char];
1010 if (weight >= 0) /* probably a character class */
1018 intuit_method(char *start, GV *gv)
1020 char *s = start + (*start == '$');
1021 char tmpbuf[sizeof tokenbuf];
1031 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
1032 if (*start == '$') {
1033 if (gv || last_lop_op == OP_PRINT || isUPPER(*tokenbuf))
1038 return *s == '(' ? FUNCMETH : METHOD;
1040 if (!keyword(tmpbuf, len)) {
1041 indirgv = gv_fetchpv(tmpbuf,FALSE, SVt_PVCV);
1042 if (indirgv && GvCVu(indirgv))
1044 /* filehandle or package name makes it a method */
1045 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
1047 if ((bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
1048 return 0; /* no assumptions -- "=>" quotes bearword */
1049 nextval[nexttoke].opval =
1050 (OP*)newSVOP(OP_CONST, 0,
1052 nextval[nexttoke].opval->op_private =
1057 return *s == '(' ? FUNCMETH : METHOD;
1067 char *pdb = getenv("PERL5DB");
1071 SETERRNO(0,SS$_NORMAL);
1072 return "BEGIN { require 'perl5db.pl' }";
1078 /* Encoded script support. filter_add() effectively inserts a
1079 * 'pre-processing' function into the current source input stream.
1080 * Note that the filter function only applies to the current source file
1081 * (e.g., it will not affect files 'require'd or 'use'd by this one).
1083 * The datasv parameter (which may be NULL) can be used to pass
1084 * private data to this instance of the filter. The filter function
1085 * can recover the SV using the FILTER_DATA macro and use it to
1086 * store private buffers and state information.
1088 * The supplied datasv parameter is upgraded to a PVIO type
1089 * and the IoDIRP field is used to store the function pointer.
1090 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
1091 * private use must be set using malloc'd pointers.
1093 static int filter_debug = 0;
1096 filter_add(filter_t funcp, SV *datasv)
1098 if (!funcp){ /* temporary handy debugging hack to be deleted */
1099 filter_debug = atoi((char*)datasv);
1103 rsfp_filters = newAV();
1106 if (!SvUPGRADE(datasv, SVt_PVIO))
1107 die("Can't upgrade filter_add data to SVt_PVIO");
1108 IoDIRP(datasv) = (DIR*)funcp; /* stash funcp into spare field */
1110 warn("filter_add func %p (%s)", funcp, SvPV(datasv,na));
1111 av_unshift(rsfp_filters, 1);
1112 av_store(rsfp_filters, 0, datasv) ;
1117 /* Delete most recently added instance of this filter function. */
1119 filter_del(filter_t funcp)
1122 warn("filter_del func %p", funcp);
1123 if (!rsfp_filters || AvFILL(rsfp_filters)<0)
1125 /* if filter is on top of stack (usual case) just pop it off */
1126 if (IoDIRP(FILTER_DATA(AvFILL(rsfp_filters))) == (void*)funcp){
1127 sv_free(av_pop(rsfp_filters));
1131 /* we need to search for the correct entry and clear it */
1132 die("filter_del can only delete in reverse order (currently)");
1136 /* Invoke the n'th filter function for the current rsfp. */
1138 filter_read(int idx, SV *buf_sv, int maxlen)
1141 /* 0 = read one text line */
1148 if (idx > AvFILL(rsfp_filters)){ /* Any more filters? */
1149 /* Provide a default input filter to make life easy. */
1150 /* Note that we append to the line. This is handy. */
1152 warn("filter_read %d: from rsfp\n", idx);
1156 int old_len = SvCUR(buf_sv) ;
1158 /* ensure buf_sv is large enough */
1159 SvGROW(buf_sv, old_len + maxlen) ;
1160 if ((len = PerlIO_read(rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
1161 if (PerlIO_error(rsfp))
1162 return -1; /* error */
1164 return 0 ; /* end of file */
1166 SvCUR_set(buf_sv, old_len + len) ;
1169 if (sv_gets(buf_sv, rsfp, SvCUR(buf_sv)) == NULL) {
1170 if (PerlIO_error(rsfp))
1171 return -1; /* error */
1173 return 0 ; /* end of file */
1177 return SvCUR(buf_sv);
1179 /* Skip this filter slot if filter has been deleted */
1180 if ( (datasv = FILTER_DATA(idx)) == &sv_undef){
1182 warn("filter_read %d: skipped (filter deleted)\n", idx);
1183 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
1185 /* Get function pointer hidden within datasv */
1186 funcp = (filter_t)IoDIRP(datasv);
1188 warn("filter_read %d: via function %p (%s)\n",
1189 idx, funcp, SvPV(datasv,na));
1190 /* Call function. The function is expected to */
1191 /* call "FILTER_READ(idx+1, buf_sv)" first. */
1192 /* Return: <0:error, =0:eof, >0:not eof */
1193 return (*funcp)(idx, buf_sv, maxlen);
1198 filter_gets(register SV *sv, register FILE *fp, STRLEN append)
1201 if (!rsfp_filters) {
1202 filter_add(win32_textfilter,NULL);
1208 SvCUR_set(sv, 0); /* start with empty line */
1209 if (FILTER_READ(0, sv, 0) > 0)
1210 return ( SvPVX(sv) ) ;
1215 return (sv_gets(sv, fp, append));
1220 static char* exp_name[] =
1221 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "TERMBLOCK" };
1224 EXT int yychar; /* last token */
1237 if (pending_ident) {
1238 char pit = pending_ident;
1242 if (strchr(tokenbuf,':'))
1243 croak(no_myglob,tokenbuf);
1244 yylval.opval = newOP(OP_PADANY, 0);
1245 yylval.opval->op_targ = pad_allocmy(tokenbuf);
1249 if (!strchr(tokenbuf,':')) {
1251 /* Check for single character per-thread SVs */
1252 if (tokenbuf[0] == '$' && tokenbuf[2] == '\0'
1253 && !isALPHA(tokenbuf[1]) /* Rule out obvious non-threadsvs */
1254 && (tmp = find_threadsv(&tokenbuf[1])) != NOT_IN_PAD)
1256 yylval.opval = newOP(OP_THREADSV, 0);
1257 yylval.opval->op_targ = tmp;
1260 #endif /* USE_THREADS */
1261 if ((tmp = pad_findmy(tokenbuf)) != NOT_IN_PAD) {
1262 if (last_lop_op == OP_SORT &&
1263 tokenbuf[0] == '$' &&
1264 (tokenbuf[1] == 'a' || tokenbuf[1] == 'b')
1267 for (d = in_eval ? oldoldbufptr : linestart;
1268 d < bufend && *d != '\n';
1271 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
1272 croak("Can't use \"my %s\" in sort comparison",
1278 yylval.opval = newOP(OP_PADANY, 0);
1279 yylval.opval->op_targ = tmp;
1284 /* Force them to make up their mind on "@foo". */
1285 if (pit == '@' && lex_state != LEX_NORMAL && !lex_brackets) {
1286 GV *gv = gv_fetchpv(tokenbuf+1, FALSE, SVt_PVAV);
1287 if (!gv || ((tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
1288 yyerror(form("In string, %s now must be written as \\%s",
1289 tokenbuf, tokenbuf));
1292 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf+1, 0));
1293 yylval.opval->op_private = OPpCONST_ENTERED;
1294 gv_fetchpv(tokenbuf+1, in_eval ? GV_ADDMULTI : TRUE,
1295 ((tokenbuf[0] == '$') ? SVt_PV
1296 : (tokenbuf[0] == '@') ? SVt_PVAV
1301 switch (lex_state) {
1303 case LEX_NORMAL: /* Some compilers will produce faster */
1304 case LEX_INTERPNORMAL: /* code if we comment these out. */
1310 yylval = nextval[nexttoke];
1312 lex_state = lex_defer;
1313 expect = lex_expect;
1314 lex_defer = LEX_NORMAL;
1316 return(nexttype[nexttoke]);
1318 case LEX_INTERPCASEMOD:
1320 if (bufptr != bufend && *bufptr != '\\')
1321 croak("panic: INTERPCASEMOD");
1323 if (bufptr == bufend || bufptr[1] == 'E') {
1326 oldmod = lex_casestack[--lex_casemods];
1327 lex_casestack[lex_casemods] = '\0';
1328 if (bufptr != bufend && strchr("LUQ", oldmod)) {
1330 lex_state = LEX_INTERPCONCAT;
1334 if (bufptr != bufend)
1336 lex_state = LEX_INTERPCONCAT;
1341 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
1342 tmp = *s, *s = s[2], s[2] = tmp; /* misordered... */
1343 if (strchr("LU", *s) &&
1344 (strchr(lex_casestack, 'L') || strchr(lex_casestack, 'U')))
1346 lex_casestack[--lex_casemods] = '\0';
1349 if (lex_casemods > 10) {
1350 char* newlb = Renew(lex_casestack, lex_casemods + 2, char);
1351 if (newlb != lex_casestack) {
1353 lex_casestack = newlb;
1356 lex_casestack[lex_casemods++] = *s;
1357 lex_casestack[lex_casemods] = '\0';
1358 lex_state = LEX_INTERPCONCAT;
1359 nextval[nexttoke].ival = 0;
1362 nextval[nexttoke].ival = OP_LCFIRST;
1364 nextval[nexttoke].ival = OP_UCFIRST;
1366 nextval[nexttoke].ival = OP_LC;
1368 nextval[nexttoke].ival = OP_UC;
1370 nextval[nexttoke].ival = OP_QUOTEMETA;
1372 croak("panic: yylex");
1384 case LEX_INTERPPUSH:
1385 return sublex_push();
1387 case LEX_INTERPSTART:
1388 if (bufptr == bufend)
1389 return sublex_done();
1391 lex_dojoin = (*bufptr == '@');
1392 lex_state = LEX_INTERPNORMAL;
1394 nextval[nexttoke].ival = 0;
1397 nextval[nexttoke].opval = newOP(OP_THREADSV, 0);
1398 nextval[nexttoke].opval->op_targ = find_threadsv("\"");
1399 force_next(PRIVATEREF);
1401 force_ident("\"", '$');
1402 #endif /* USE_THREADS */
1403 nextval[nexttoke].ival = 0;
1405 nextval[nexttoke].ival = 0;
1407 nextval[nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
1416 case LEX_INTERPENDMAYBE:
1417 if (intuit_more(bufptr)) {
1418 lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
1426 lex_state = LEX_INTERPCONCAT;
1430 case LEX_INTERPCONCAT:
1433 croak("panic: INTERPCONCAT");
1435 if (bufptr == bufend)
1436 return sublex_done();
1438 if (SvIVX(linestr) == '\'') {
1439 SV *sv = newSVsv(linestr);
1442 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1446 s = scan_const(bufptr);
1448 lex_state = LEX_INTERPCASEMOD;
1450 lex_state = LEX_INTERPSTART;
1454 nextval[nexttoke] = yylval;
1467 lex_state = LEX_NORMAL;
1468 s = scan_formline(bufptr);
1475 oldoldbufptr = oldbufptr;
1478 PerlIO_printf(PerlIO_stderr(), "### Tokener expecting %s at %s\n", exp_name[expect], s);
1484 croak("Unrecognized character \\%03o", *s & 255);
1487 goto fake_eof; /* emulate EOF on ^D or ^Z */
1493 yyerror("Missing right bracket");
1497 goto retry; /* ignore stray nulls */
1500 if (!in_eval && !preambled) {
1502 sv_setpv(linestr,incl_perldb());
1504 sv_catpv(linestr,";");
1506 while(AvFILL(preambleav) >= 0) {
1507 SV *tmpsv = av_shift(preambleav);
1508 sv_catsv(linestr, tmpsv);
1509 sv_catpv(linestr, ";");
1512 sv_free((SV*)preambleav);
1515 if (minus_n || minus_p) {
1516 sv_catpv(linestr, "LINE: while (<>) {");
1518 sv_catpv(linestr,"chomp;");
1520 GV* gv = gv_fetchpv("::F", TRUE, SVt_PVAV);
1522 GvIMPORTED_AV_on(gv);
1524 if (strchr("/'\"", *splitstr)
1525 && strchr(splitstr + 1, *splitstr))
1526 sv_catpvf(linestr, "@F=split(%s);", splitstr);
1529 s = "'~#\200\1'"; /* surely one char is unused...*/
1530 while (s[1] && strchr(splitstr, *s)) s++;
1532 sv_catpvf(linestr, "@F=split(%s%c",
1533 "q" + (delim == '\''), delim);
1534 for (s = splitstr; *s; s++) {
1536 sv_catpvn(linestr, "\\", 1);
1537 sv_catpvn(linestr, s, 1);
1539 sv_catpvf(linestr, "%c);", delim);
1543 sv_catpv(linestr,"@F=split(' ');");
1546 sv_catpv(linestr, "\n");
1547 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
1548 bufend = SvPVX(linestr) + SvCUR(linestr);
1549 if (PERLDB_LINE && curstash != debstash) {
1550 SV *sv = NEWSV(85,0);
1552 sv_upgrade(sv, SVt_PVMG);
1553 sv_setsv(sv,linestr);
1554 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
1559 if ((s = filter_gets(linestr, rsfp, 0)) == Nullch) {
1562 if (preprocess && !in_eval)
1563 (void)my_pclose(rsfp);
1564 else if ((PerlIO *)rsfp == PerlIO_stdin())
1565 PerlIO_clearerr(rsfp);
1567 (void)PerlIO_close(rsfp);
1572 if (!in_eval && (minus_n || minus_p)) {
1573 sv_setpv(linestr,minus_p ? ";}continue{print" : "");
1574 sv_catpv(linestr,";}");
1575 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
1576 bufend = SvPVX(linestr) + SvCUR(linestr);
1577 minus_n = minus_p = 0;
1580 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
1581 sv_setpv(linestr,"");
1582 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
1585 if (*s == '#' && s[1] == '!' && instr(s,"perl"))
1588 /* Incest with pod. */
1589 if (*s == '=' && strnEQ(s, "=cut", 4)) {
1590 sv_setpv(linestr, "");
1591 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
1592 bufend = SvPVX(linestr) + SvCUR(linestr);
1597 } while (doextract);
1598 oldoldbufptr = oldbufptr = bufptr = linestart = s;
1599 if (PERLDB_LINE && curstash != debstash) {
1600 SV *sv = NEWSV(85,0);
1602 sv_upgrade(sv, SVt_PVMG);
1603 sv_setsv(sv,linestr);
1604 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
1606 bufend = SvPVX(linestr) + SvCUR(linestr);
1607 if (curcop->cop_line == 1) {
1608 while (s < bufend && isSPACE(*s))
1610 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
1614 if (*s == '#' && *(s+1) == '!')
1616 #ifdef ALTERNATE_SHEBANG
1618 static char as[] = ALTERNATE_SHEBANG;
1619 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
1620 d = s + (sizeof(as) - 1);
1622 #endif /* ALTERNATE_SHEBANG */
1631 while (*d && !isSPACE(*d))
1635 #ifdef ARG_ZERO_IS_SCRIPT
1636 if (ipathend > ipath) {
1638 * HP-UX (at least) sets argv[0] to the script name,
1639 * which makes $^X incorrect. And Digital UNIX and Linux,
1640 * at least, set argv[0] to the basename of the Perl
1641 * interpreter. So, having found "#!", we'll set it right.
1643 SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV));
1644 assert(SvPOK(x) || SvGMAGICAL(x));
1645 if (sv_eq(x, GvSV(curcop->cop_filegv))) {
1646 sv_setpvn(x, ipath, ipathend - ipath);
1649 TAINT_NOT; /* $^X is always tainted, but that's OK */
1651 #endif /* ARG_ZERO_IS_SCRIPT */
1656 d = instr(s,"perl -");
1658 d = instr(s,"perl");
1659 #ifdef ALTERNATE_SHEBANG
1661 * If the ALTERNATE_SHEBANG on this system starts with a
1662 * character that can be part of a Perl expression, then if
1663 * we see it but not "perl", we're probably looking at the
1664 * start of Perl code, not a request to hand off to some
1665 * other interpreter. Similarly, if "perl" is there, but
1666 * not in the first 'word' of the line, we assume the line
1667 * contains the start of the Perl program.
1669 if (d && *s != '#') {
1671 while (*c && !strchr("; \t\r\n\f\v#", *c))
1674 d = Nullch; /* "perl" not in first word; ignore */
1676 *s = '#'; /* Don't try to parse shebang line */
1678 #endif /* ALTERNATE_SHEBANG */
1683 !instr(s,"indir") &&
1684 instr(origargv[0],"perl"))
1690 while (s < bufend && isSPACE(*s))
1693 Newz(899,newargv,origargc+3,char*);
1695 while (s < bufend && !isSPACE(*s))
1698 Copy(origargv+1, newargv+2, origargc+1, char*);
1703 execv(ipath, newargv);
1704 croak("Can't exec %s", ipath);
1707 U32 oldpdb = perldb;
1708 bool oldn = minus_n;
1709 bool oldp = minus_p;
1711 while (*d && !isSPACE(*d)) d++;
1712 while (*d == ' ' || *d == '\t') d++;
1716 if (*d == 'M' || *d == 'm') {
1718 while (*d && !isSPACE(*d)) d++;
1719 croak("Too late for \"-%.*s\" option",
1722 d = moreswitches(d);
1724 if (PERLDB_LINE && !oldpdb ||
1725 ( minus_n || minus_p ) && !(oldn || oldp) )
1726 /* if we have already added "LINE: while (<>) {",
1727 we must not do it again */
1729 sv_setpv(linestr, "");
1730 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
1731 bufend = SvPVX(linestr) + SvCUR(linestr);
1734 (void)gv_fetchfile(origfilename);
1741 if (lex_formbrack && lex_brackets <= lex_formbrack) {
1743 lex_state = LEX_FORMLINE;
1749 warn("Illegal character \\%03o (carriage return)", '\r');
1751 "(Maybe you didn't strip carriage returns after a network transfer?)\n");
1753 case ' ': case '\t': case '\f': case 013:
1758 if (lex_state != LEX_NORMAL || (in_eval && !rsfp)) {
1760 while (s < d && *s != '\n')
1765 if (lex_formbrack && lex_brackets <= lex_formbrack) {
1767 lex_state = LEX_FORMLINE;
1777 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
1782 while (s < bufend && (*s == ' ' || *s == '\t'))
1785 if (strnEQ(s,"=>",2)) {
1787 warn("Ambiguous use of -%c => resolved to \"-%c\" =>",
1788 (int)tmp, (int)tmp);
1789 s = force_word(bufptr,WORD,FALSE,FALSE,FALSE);
1790 OPERATOR('-'); /* unary minus */
1792 last_uni = oldbufptr;
1793 last_lop_op = OP_FTEREAD; /* good enough */
1795 case 'r': FTST(OP_FTEREAD);
1796 case 'w': FTST(OP_FTEWRITE);
1797 case 'x': FTST(OP_FTEEXEC);
1798 case 'o': FTST(OP_FTEOWNED);
1799 case 'R': FTST(OP_FTRREAD);
1800 case 'W': FTST(OP_FTRWRITE);
1801 case 'X': FTST(OP_FTREXEC);
1802 case 'O': FTST(OP_FTROWNED);
1803 case 'e': FTST(OP_FTIS);
1804 case 'z': FTST(OP_FTZERO);
1805 case 's': FTST(OP_FTSIZE);
1806 case 'f': FTST(OP_FTFILE);
1807 case 'd': FTST(OP_FTDIR);
1808 case 'l': FTST(OP_FTLINK);
1809 case 'p': FTST(OP_FTPIPE);
1810 case 'S': FTST(OP_FTSOCK);
1811 case 'u': FTST(OP_FTSUID);
1812 case 'g': FTST(OP_FTSGID);
1813 case 'k': FTST(OP_FTSVTX);
1814 case 'b': FTST(OP_FTBLK);
1815 case 'c': FTST(OP_FTCHR);
1816 case 't': FTST(OP_FTTTY);
1817 case 'T': FTST(OP_FTTEXT);
1818 case 'B': FTST(OP_FTBINARY);
1819 case 'M': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTMTIME);
1820 case 'A': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTATIME);
1821 case 'C': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTCTIME);
1823 croak("Unrecognized file test: -%c", (int)tmp);
1830 if (expect == XOPERATOR)
1835 else if (*s == '>') {
1838 if (isIDFIRST(*s)) {
1839 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
1847 if (expect == XOPERATOR)
1850 if (isSPACE(*s) || !isSPACE(*bufptr))
1852 OPERATOR('-'); /* unary minus */
1859 if (expect == XOPERATOR)
1864 if (expect == XOPERATOR)
1867 if (isSPACE(*s) || !isSPACE(*bufptr))
1873 if (expect != XOPERATOR) {
1874 s = scan_ident(s, bufend, tokenbuf, sizeof tokenbuf, TRUE);
1876 force_ident(tokenbuf, '*');
1889 if (expect == XOPERATOR) {
1894 s = scan_ident(s, bufend, tokenbuf + 1, sizeof tokenbuf - 1, TRUE);
1897 yyerror("Final % should be \\% or %name");
1900 pending_ident = '%';
1922 if (last_lop == oldoldbufptr || last_uni == oldoldbufptr)
1923 oldbufptr = oldoldbufptr; /* allow print(STDOUT 123) */
1928 if (curcop->cop_line < copline)
1929 copline = curcop->cop_line;
1940 if (lex_brackets <= 0)
1941 yyerror("Unmatched right bracket");
1944 if (lex_state == LEX_INTERPNORMAL) {
1945 if (lex_brackets == 0) {
1946 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
1947 lex_state = LEX_INTERPEND;
1954 if (lex_brackets > 100) {
1955 char* newlb = Renew(lex_brackstack, lex_brackets + 1, char);
1956 if (newlb != lex_brackstack) {
1958 lex_brackstack = newlb;
1963 if (lex_formbrack) {
1967 if (oldoldbufptr == last_lop)
1968 lex_brackstack[lex_brackets++] = XTERM;
1970 lex_brackstack[lex_brackets++] = XOPERATOR;
1971 OPERATOR(HASHBRACK);
1973 while (s < bufend && (*s == ' ' || *s == '\t'))
1977 if (d < bufend && *d == '-') {
1980 while (d < bufend && (*d == ' ' || *d == '\t'))
1983 if (d < bufend && isIDFIRST(*d)) {
1984 d = scan_word(d, tokenbuf + 1, sizeof tokenbuf - 1,
1986 while (d < bufend && (*d == ' ' || *d == '\t'))
1989 char minus = (tokenbuf[0] == '-');
1991 (keyword(tokenbuf + 1, len) ||
1992 (minus && len == 1 && isALPHA(tokenbuf[1])) ||
1993 perl_get_cv(tokenbuf + 1, FALSE) ))
1994 warn("Ambiguous use of {%s} resolved to {\"%s\"}",
1995 tokenbuf + !minus, tokenbuf + !minus);
1996 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
2003 lex_brackstack[lex_brackets++] = XSTATE;
2007 lex_brackstack[lex_brackets++] = XOPERATOR;
2012 if (oldoldbufptr == last_lop)
2013 lex_brackstack[lex_brackets++] = XTERM;
2015 lex_brackstack[lex_brackets++] = XOPERATOR;
2018 OPERATOR(HASHBRACK);
2019 /* This hack serves to disambiguate a pair of curlies
2020 * as being a block or an anon hash. Normally, expectation
2021 * determines that, but in cases where we're not in a
2022 * position to expect anything in particular (like inside
2023 * eval"") we have to resolve the ambiguity. This code
2024 * covers the case where the first term in the curlies is a
2025 * quoted string. Most other cases need to be explicitly
2026 * disambiguated by prepending a `+' before the opening
2027 * curly in order to force resolution as an anon hash.
2029 * XXX should probably propagate the outer expectation
2030 * into eval"" to rely less on this hack, but that could
2031 * potentially break current behavior of eval"".
2035 if (*s == '\'' || *s == '"' || *s == '`') {
2036 /* common case: get past first string, handling escapes */
2037 for (t++; t < bufend && *t != *s;)
2038 if (*t++ == '\\' && (*t == '\\' || *t == *s))
2042 else if (*s == 'q') {
2045 || ((*t == 'q' || *t == 'x') && ++t < bufend
2046 && !isALNUM(*t)))) {
2048 char open, close, term;
2051 while (t < bufend && isSPACE(*t))
2055 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
2059 for (t++; t < bufend; t++) {
2060 if (*t == '\\' && t+1 < bufend && open != '\\')
2062 else if (*t == open)
2066 for (t++; t < bufend; t++) {
2067 if (*t == '\\' && t+1 < bufend)
2069 else if (*t == close && --brackets <= 0)
2071 else if (*t == open)
2077 else if (isALPHA(*s)) {
2078 for (t++; t < bufend && isALNUM(*t); t++) ;
2080 while (t < bufend && isSPACE(*t))
2082 /* if comma follows first term, call it an anon hash */
2083 /* XXX it could be a comma expression with loop modifiers */
2084 if (t < bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
2085 || (*t == '=' && t[1] == '>')))
2086 OPERATOR(HASHBRACK);
2090 lex_brackstack[lex_brackets-1] = XSTATE;
2096 yylval.ival = curcop->cop_line;
2097 if (isSPACE(*s) || *s == '#')
2098 copline = NOLINE; /* invalidate current command line number */
2103 if (lex_brackets <= 0)
2104 yyerror("Unmatched right bracket");
2106 expect = (expectation)lex_brackstack[--lex_brackets];
2107 if (lex_brackets < lex_formbrack)
2109 if (lex_state == LEX_INTERPNORMAL) {
2110 if (lex_brackets == 0) {
2111 if (lex_fakebrack) {
2112 lex_state = LEX_INTERPEND;
2114 return yylex(); /* ignore fake brackets */
2116 if (*s == '-' && s[1] == '>')
2117 lex_state = LEX_INTERPENDMAYBE;
2118 else if (*s != '[' && *s != '{')
2119 lex_state = LEX_INTERPEND;
2122 if (lex_brackets < lex_fakebrack) {
2125 return yylex(); /* ignore fake brackets */
2135 if (expect == XOPERATOR) {
2136 if (dowarn && isALPHA(*s) && bufptr == linestart) {
2144 s = scan_ident(s - 1, bufend, tokenbuf, sizeof tokenbuf, TRUE);
2147 force_ident(tokenbuf, '&');
2151 yylval.ival = (OPpENTERSUB_AMPER<<8);
2170 if (dowarn && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
2171 warn("Reversed %c= operator",(int)tmp);
2173 if (expect == XSTATE && isALPHA(tmp) &&
2174 (s == linestart+1 || s[-2] == '\n') )
2176 if (in_eval && !rsfp) {
2181 if (strnEQ(s,"=cut",4)) {
2198 if (lex_brackets < lex_formbrack) {
2200 for (t = s; *t == ' ' || *t == '\t'; t++) ;
2201 if (*t == '\n' || *t == '#') {
2219 if (expect != XOPERATOR) {
2220 if (s[1] != '<' && !strchr(s,'>'))
2223 s = scan_heredoc(s);
2225 s = scan_inputsymbol(s);
2226 TERM(sublex_start());
2231 SHop(OP_LEFT_SHIFT);
2245 SHop(OP_RIGHT_SHIFT);
2254 if (expect == XOPERATOR) {
2255 if (lex_formbrack && lex_brackets == lex_formbrack) {
2258 return ','; /* grandfather non-comma-format format */
2262 if (s[1] == '#' && (isALPHA(s[2]) || strchr("_{$:", s[2]))) {
2263 if (expect == XOPERATOR)
2264 no_op("Array length", bufptr);
2266 s = scan_ident(s + 1, bufend, tokenbuf + 1, sizeof tokenbuf - 1,
2271 pending_ident = '#';
2275 if (expect == XOPERATOR)
2276 no_op("Scalar", bufptr);
2278 s = scan_ident(s, bufend, tokenbuf + 1, sizeof tokenbuf - 1, FALSE);
2281 yyerror("Final $ should be \\$ or $name");
2285 /* This kludge not intended to be bulletproof. */
2286 if (tokenbuf[1] == '[' && !tokenbuf[2]) {
2287 yylval.opval = newSVOP(OP_CONST, 0,
2288 newSViv((IV)compiling.cop_arybase));
2289 yylval.opval->op_private = OPpCONST_ARYBASE;
2294 if (lex_state == LEX_NORMAL)
2297 if ((expect != XREF || oldoldbufptr == last_lop) && intuit_more(s)) {
2303 isSPACE(*t) || isALNUM(*t) || *t == '$';
2306 bufptr = skipspace(bufptr);
2307 while (t < bufend && *t != ']')
2309 warn("Multidimensional syntax %.*s not supported",
2310 (t - bufptr) + 1, bufptr);
2314 else if (*s == '{') {
2316 if (dowarn && strEQ(tokenbuf+1, "SIG") &&
2317 (t = strchr(s, '}')) && (t = strchr(t, '=')))
2319 char tmpbuf[sizeof tokenbuf];
2321 for (t++; isSPACE(*t); t++) ;
2322 if (isIDFIRST(*t)) {
2323 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
2324 if (*t != '(' && perl_get_cv(tmpbuf, FALSE))
2325 warn("You need to quote \"%s\"", tmpbuf);
2332 if (lex_state == LEX_NORMAL && isSPACE(*d)) {
2333 bool islop = (last_lop == oldoldbufptr);
2334 if (!islop || last_lop_op == OP_GREPSTART)
2336 else if (strchr("$@\"'`q", *s))
2337 expect = XTERM; /* e.g. print $fh "foo" */
2338 else if (strchr("&*<%", *s) && isIDFIRST(s[1]))
2339 expect = XTERM; /* e.g. print $fh &sub */
2340 else if (isIDFIRST(*s)) {
2341 char tmpbuf[sizeof tokenbuf];
2342 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2343 if (tmp = keyword(tmpbuf, len)) {
2344 /* binary operators exclude handle interpretations */
2356 expect = XTERM; /* e.g. print $fh length() */
2361 GV *gv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
2362 if (gv && GvCVu(gv))
2363 expect = XTERM; /* e.g. print $fh subr() */
2366 else if (isDIGIT(*s))
2367 expect = XTERM; /* e.g. print $fh 3 */
2368 else if (*s == '.' && isDIGIT(s[1]))
2369 expect = XTERM; /* e.g. print $fh .3 */
2370 else if (strchr("/?-+", *s) && !isSPACE(s[1]))
2371 expect = XTERM; /* e.g. print $fh -1 */
2372 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]))
2373 expect = XTERM; /* print $fh <<"EOF" */
2375 pending_ident = '$';
2379 if (expect == XOPERATOR)
2382 s = scan_ident(s, bufend, tokenbuf + 1, sizeof tokenbuf - 1, FALSE);
2385 yyerror("Final @ should be \\@ or @name");
2388 if (lex_state == LEX_NORMAL)
2390 if ((expect != XREF || oldoldbufptr == last_lop) && intuit_more(s)) {
2394 /* Warn about @ where they meant $. */
2396 if (*s == '[' || *s == '{') {
2398 while (*t && (isALNUM(*t) || strchr(" \t$#+-'\"", *t)))
2400 if (*t == '}' || *t == ']') {
2402 bufptr = skipspace(bufptr);
2403 warn("Scalar value %.*s better written as $%.*s",
2404 t-bufptr, bufptr, t-bufptr-1, bufptr+1);
2409 pending_ident = '@';
2412 case '/': /* may either be division or pattern */
2413 case '?': /* may either be conditional or pattern */
2414 if (expect != XOPERATOR) {
2415 /* Disable warning on "study /blah/" */
2416 if (oldoldbufptr == last_uni
2417 && (*last_uni != 's' || s - last_uni < 5
2418 || memNE(last_uni, "study", 5) || isALNUM(last_uni[5])))
2421 TERM(sublex_start());
2429 if (lex_formbrack && lex_brackets == lex_formbrack && s[1] == '\n' &&
2430 (s == linestart || s[-1] == '\n') ) {
2435 if (expect == XOPERATOR || !isDIGIT(s[1])) {
2441 yylval.ival = OPf_SPECIAL;
2447 if (expect != XOPERATOR)
2452 case '0': case '1': case '2': case '3': case '4':
2453 case '5': case '6': case '7': case '8': case '9':
2455 if (expect == XOPERATOR)
2461 if (expect == XOPERATOR) {
2462 if (lex_formbrack && lex_brackets == lex_formbrack) {
2465 return ','; /* grandfather non-comma-format format */
2471 missingterm((char*)0);
2472 yylval.ival = OP_CONST;
2473 TERM(sublex_start());
2477 if (expect == XOPERATOR) {
2478 if (lex_formbrack && lex_brackets == lex_formbrack) {
2481 return ','; /* grandfather non-comma-format format */
2487 missingterm((char*)0);
2488 yylval.ival = OP_CONST;
2489 for (d = SvPV(lex_stuff, len); len; len--, d++) {
2490 if (*d == '$' || *d == '@' || *d == '\\') {
2491 yylval.ival = OP_STRINGIFY;
2495 TERM(sublex_start());
2499 if (expect == XOPERATOR)
2500 no_op("Backticks",s);
2502 missingterm((char*)0);
2503 yylval.ival = OP_BACKTICK;
2505 TERM(sublex_start());
2509 if (dowarn && lex_inwhat && isDIGIT(*s))
2510 warn("Can't use \\%c to mean $%c in expression", *s, *s);
2511 if (expect == XOPERATOR)
2512 no_op("Backslash",s);
2516 if (isDIGIT(s[1]) && expect == XOPERATOR) {
2555 s = scan_word(s, tokenbuf, sizeof tokenbuf, FALSE, &len);
2557 /* Some keywords can be followed by any delimiter, including ':' */
2558 tmp = (len == 1 && strchr("msyq", tokenbuf[0]) ||
2559 len == 2 && ((tokenbuf[0] == 't' && tokenbuf[1] == 'r') ||
2560 (tokenbuf[0] == 'q' &&
2561 strchr("qwx", tokenbuf[1]))));
2563 /* x::* is just a word, unless x is "CORE" */
2564 if (!tmp && *s == ':' && s[1] == ':' && strNE(tokenbuf, "CORE"))
2568 while (d < bufend && isSPACE(*d))
2569 d++; /* no comments skipped here, or s### is misparsed */
2571 /* Is this a label? */
2572 if (!tmp && expect == XSTATE
2573 && d < bufend && *d == ':' && *(d + 1) != ':') {
2575 yylval.pval = savepv(tokenbuf);
2580 /* Check for keywords */
2581 tmp = keyword(tokenbuf, len);
2583 /* Is this a word before a => operator? */
2584 if (strnEQ(d,"=>",2)) {
2586 if (dowarn && (tmp || perl_get_cv(tokenbuf, FALSE)))
2587 warn("Ambiguous use of %s => resolved to \"%s\" =>",
2588 tokenbuf, tokenbuf);
2589 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf,0));
2590 yylval.opval->op_private = OPpCONST_BARE;
2594 if (tmp < 0) { /* second-class keyword? */
2595 if (expect != XOPERATOR && (*s != ':' || s[1] != ':') &&
2596 (((gv = gv_fetchpv(tokenbuf, FALSE, SVt_PVCV)) &&
2597 GvCVu(gv) && GvIMPORTED_CV(gv)) ||
2598 ((gvp = (GV**)hv_fetch(globalstash,tokenbuf,len,FALSE)) &&
2599 (gv = *gvp) != (GV*)&sv_undef &&
2600 GvCVu(gv) && GvIMPORTED_CV(gv))))
2602 tmp = 0; /* overridden by importation */
2605 && -tmp==KEY_lock /* XXX generalizable kludge */
2606 && !hv_fetch(GvHVn(incgv), "Thread.pm", 9, FALSE))
2608 tmp = 0; /* any sub overrides "weak" keyword */
2611 tmp = -tmp; gv = Nullgv; gvp = 0;
2618 default: /* not a keyword */
2621 char lastchar = (bufptr == oldoldbufptr ? 0 : bufptr[-1]);
2623 /* Get the rest if it looks like a package qualifier */
2625 if (*s == '\'' || *s == ':' && s[1] == ':') {
2626 s = scan_word(s, tokenbuf + len, sizeof tokenbuf - len,
2629 croak("Bad name after %s::", tokenbuf);
2632 if (expect == XOPERATOR) {
2633 if (bufptr == linestart) {
2639 no_op("Bareword",s);
2642 /* Look for a subroutine with this name in current package. */
2645 sv = newSVpv("CORE::GLOBAL::",14);
2646 sv_catpv(sv,tokenbuf);
2649 sv = newSVpv(tokenbuf,0);
2651 gv = gv_fetchpv(tokenbuf,FALSE, SVt_PVCV);
2653 /* Presume this is going to be a bareword of some sort. */
2656 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2657 yylval.opval->op_private = OPpCONST_BARE;
2659 /* See if it's the indirect object for a list operator. */
2662 oldoldbufptr < bufptr &&
2663 (oldoldbufptr == last_lop || oldoldbufptr == last_uni) &&
2664 /* NO SKIPSPACE BEFORE HERE! */
2666 ((opargs[last_lop_op] >> OASHIFT)& 7) == OA_FILEREF) )
2668 bool immediate_paren = *s == '(';
2670 /* (Now we can afford to cross potential line boundary.) */
2673 /* Two barewords in a row may indicate method call. */
2675 if ((isALPHA(*s) || *s == '$') && (tmp=intuit_method(s,gv)))
2678 /* If not a declared subroutine, it's an indirect object. */
2679 /* (But it's an indir obj regardless for sort.) */
2681 if ((last_lop_op == OP_SORT ||
2682 (!immediate_paren && (!gv || !GvCVu(gv))) ) &&
2683 (last_lop_op != OP_MAPSTART && last_lop_op != OP_GREPSTART)){
2684 expect = (last_lop == oldoldbufptr) ? XTERM : XOPERATOR;
2689 /* If followed by a paren, it's certainly a subroutine. */
2695 if (gv && GvCVu(gv)) {
2696 for (d = s + 1; *d == ' ' || *d == '\t'; d++) ;
2697 if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) {
2702 nextval[nexttoke].opval = yylval.opval;
2709 /* If followed by var or block, call it a method (unless sub) */
2711 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
2712 last_lop = oldbufptr;
2713 last_lop_op = OP_METHOD;
2717 /* If followed by a bareword, see if it looks like indir obj. */
2719 if ((isALPHA(*s) || *s == '$') && (tmp = intuit_method(s,gv)))
2722 /* Not a method, so call it a subroutine (if defined) */
2724 if (gv && GvCVu(gv)) {
2726 if (lastchar == '-')
2727 warn("Ambiguous use of -%s resolved as -&%s()",
2728 tokenbuf, tokenbuf);
2729 last_lop = oldbufptr;
2730 last_lop_op = OP_ENTERSUB;
2731 /* Check for a constant sub */
2733 if ((sv = cv_const_sv(cv))) {
2735 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
2736 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
2737 yylval.opval->op_private = 0;
2741 /* Resolve to GV now. */
2742 op_free(yylval.opval);
2743 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
2744 /* Is there a prototype? */
2747 char *proto = SvPV((SV*)cv, len);
2750 if (strEQ(proto, "$"))
2752 if (*proto == '&' && *s == '{') {
2753 sv_setpv(subname,"__ANON__");
2757 nextval[nexttoke].opval = yylval.opval;
2763 if (hints & HINT_STRICT_SUBS &&
2766 last_lop_op != OP_TRUNCATE && /* S/F prototype in opcode.pl */
2767 last_lop_op != OP_ACCEPT &&
2768 last_lop_op != OP_PIPE_OP &&
2769 last_lop_op != OP_SOCKPAIR)
2772 "Bareword \"%s\" not allowed while \"strict subs\" in use",
2777 /* Call it a bare word */
2781 if (lastchar != '-') {
2782 for (d = tokenbuf; *d && isLOWER(*d); d++) ;
2784 warn(warn_reserved, tokenbuf);
2787 if (lastchar && strchr("*%&", lastchar)) {
2788 warn("Operator or semicolon missing before %c%s",
2789 lastchar, tokenbuf);
2790 warn("Ambiguous use of %c resolved as operator %c",
2791 lastchar, lastchar);
2797 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
2798 newSVsv(GvSV(curcop->cop_filegv)));
2802 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
2803 newSVpvf("%ld", (long)curcop->cop_line));
2806 case KEY___PACKAGE__:
2807 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
2809 ? newSVsv(curstname)
2818 if (rsfp && (!in_eval || tokenbuf[2] == 'D')) {
2819 char *pname = "main";
2820 if (tokenbuf[2] == 'D')
2821 pname = HvNAME(curstash ? curstash : defstash);
2822 gv = gv_fetchpv(form("%s::DATA", pname), TRUE, SVt_PVIO);
2825 GvIOp(gv) = newIO();
2826 IoIFP(GvIOp(gv)) = rsfp;
2827 #if defined(HAS_FCNTL) && defined(F_SETFD)
2829 int fd = PerlIO_fileno(rsfp);
2830 fcntl(fd,F_SETFD,fd >= 3);
2833 /* Mark this internal pseudo-handle as clean */
2834 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
2836 IoTYPE(GvIOp(gv)) = '|';
2837 else if ((PerlIO*)rsfp == PerlIO_stdin())
2838 IoTYPE(GvIOp(gv)) = '-';
2840 IoTYPE(GvIOp(gv)) = '<';
2851 if (expect == XSTATE) {
2858 if (*s == ':' && s[1] == ':') {
2861 s = scan_word(s, tokenbuf, sizeof tokenbuf, FALSE, &len);
2862 tmp = keyword(tokenbuf, len);
2876 LOP(OP_ACCEPT,XTERM);
2882 LOP(OP_ATAN2,XTERM);
2891 LOP(OP_BLESS,XTERM);
2900 (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */
2920 LOP(OP_CRYPT,XTERM);
2924 for (d = s; d < bufend && (isSPACE(*d) || *d == '('); d++) ;
2925 if (*d != '0' && isDIGIT(*d))
2926 yywarn("chmod: mode argument is missing initial 0");
2928 LOP(OP_CHMOD,XTERM);
2931 LOP(OP_CHOWN,XTERM);
2934 LOP(OP_CONNECT,XTERM);
2950 s = force_word(s,WORD,FALSE,TRUE,FALSE);
2954 hints |= HINT_BLOCK_SCOPE;
2964 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
2965 LOP(OP_DBMOPEN,XTERM);
2971 s = force_word(s,WORD,TRUE,FALSE,FALSE);
2978 yylval.ival = curcop->cop_line;
2992 expect = (*s == '{') ? XTERMBLOCK : XTERM;
2993 UNIBRACK(OP_ENTEREVAL);
3008 case KEY_endhostent:
3014 case KEY_endservent:
3017 case KEY_endprotoent:
3028 yylval.ival = curcop->cop_line;
3030 if (isIDFIRST(*s)) {
3032 if ((bufend - p) >= 3 &&
3033 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
3037 croak("Missing $ on loop variable");
3042 LOP(OP_FORMLINE,XTERM);
3048 LOP(OP_FCNTL,XTERM);
3054 LOP(OP_FLOCK,XTERM);
3063 LOP(OP_GREPSTART, *s == '(' ? XTERM : XREF);
3066 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3081 case KEY_getpriority:
3082 LOP(OP_GETPRIORITY,XTERM);
3084 case KEY_getprotobyname:
3087 case KEY_getprotobynumber:
3088 LOP(OP_GPBYNUMBER,XTERM);
3090 case KEY_getprotoent:
3102 case KEY_getpeername:
3103 UNI(OP_GETPEERNAME);
3105 case KEY_gethostbyname:
3108 case KEY_gethostbyaddr:
3109 LOP(OP_GHBYADDR,XTERM);
3111 case KEY_gethostent:
3114 case KEY_getnetbyname:
3117 case KEY_getnetbyaddr:
3118 LOP(OP_GNBYADDR,XTERM);
3123 case KEY_getservbyname:
3124 LOP(OP_GSBYNAME,XTERM);
3126 case KEY_getservbyport:
3127 LOP(OP_GSBYPORT,XTERM);
3129 case KEY_getservent:
3132 case KEY_getsockname:
3133 UNI(OP_GETSOCKNAME);
3135 case KEY_getsockopt:
3136 LOP(OP_GSOCKOPT,XTERM);
3158 yylval.ival = curcop->cop_line;
3162 LOP(OP_INDEX,XTERM);
3168 LOP(OP_IOCTL,XTERM);
3180 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3211 LOP(OP_LISTEN,XTERM);
3221 TERM(sublex_start());
3224 LOP(OP_MAPSTART,XREF);
3227 LOP(OP_MKDIR,XTERM);
3230 LOP(OP_MSGCTL,XTERM);
3233 LOP(OP_MSGGET,XTERM);
3236 LOP(OP_MSGRCV,XTERM);
3239 LOP(OP_MSGSND,XTERM);
3244 if (isIDFIRST(*s)) {
3245 s = scan_word(s, tokenbuf, sizeof tokenbuf, TRUE, &len);
3246 in_my_stash = gv_stashpv(tokenbuf, FALSE);
3250 sprintf(tmpbuf, "No such class %.1000s", tokenbuf);
3257 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3264 if (expect != XSTATE)
3265 yyerror("\"no\" not allowed in expression");
3266 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3267 s = force_version(s);
3276 if (isIDFIRST(*s)) {
3278 for (d = s; isALNUM(*d); d++) ;
3280 if (strchr("|&*+-=!?:.", *t))
3281 warn("Precedence problem: open %.*s should be open(%.*s)",
3287 yylval.ival = OP_OR;
3297 LOP(OP_OPEN_DIR,XTERM);
3300 checkcomma(s,tokenbuf,"filehandle");
3304 checkcomma(s,tokenbuf,"filehandle");
3323 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3327 LOP(OP_PIPE_OP,XTERM);
3332 missingterm((char*)0);
3333 yylval.ival = OP_CONST;
3334 TERM(sublex_start());
3342 missingterm((char*)0);
3343 if (dowarn && SvLEN(lex_stuff)) {
3344 d = SvPV_force(lex_stuff, len);
3345 for (; len; --len, ++d) {
3347 warn("Possible attempt to separate words with commas");
3351 warn("Possible attempt to put comments in qw() list");
3357 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, q(lex_stuff));
3361 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(" ",1));
3364 yylval.ival = OP_SPLIT;
3368 last_lop = oldbufptr;
3369 last_lop_op = OP_SPLIT;
3375 missingterm((char*)0);
3376 yylval.ival = OP_STRINGIFY;
3377 if (SvIVX(lex_stuff) == '\'')
3378 SvIVX(lex_stuff) = 0; /* qq'$foo' should intepolate */
3379 TERM(sublex_start());
3384 missingterm((char*)0);
3385 yylval.ival = OP_BACKTICK;
3387 TERM(sublex_start());
3394 s = force_word(s,WORD,TRUE,TRUE,FALSE);
3395 if (isIDFIRST(*tokenbuf))
3396 gv_stashpvn(tokenbuf, strlen(tokenbuf), TRUE);
3398 yyerror("<> should be quotes");
3405 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3409 LOP(OP_RENAME,XTERM);
3418 LOP(OP_RINDEX,XTERM);
3441 LOP(OP_REVERSE,XTERM);
3452 TERM(sublex_start());
3454 TOKEN(1); /* force error */
3463 LOP(OP_SELECT,XTERM);
3469 LOP(OP_SEMCTL,XTERM);
3472 LOP(OP_SEMGET,XTERM);
3475 LOP(OP_SEMOP,XTERM);
3481 LOP(OP_SETPGRP,XTERM);
3483 case KEY_setpriority:
3484 LOP(OP_SETPRIORITY,XTERM);
3486 case KEY_sethostent:
3492 case KEY_setservent:
3495 case KEY_setprotoent:
3505 LOP(OP_SEEKDIR,XTERM);
3507 case KEY_setsockopt:
3508 LOP(OP_SSOCKOPT,XTERM);
3514 LOP(OP_SHMCTL,XTERM);
3517 LOP(OP_SHMGET,XTERM);
3520 LOP(OP_SHMREAD,XTERM);
3523 LOP(OP_SHMWRITE,XTERM);
3526 LOP(OP_SHUTDOWN,XTERM);
3535 LOP(OP_SOCKET,XTERM);
3537 case KEY_socketpair:
3538 LOP(OP_SOCKPAIR,XTERM);
3541 checkcomma(s,tokenbuf,"subroutine name");
3543 if (*s == ';' || *s == ')') /* probably a close */
3544 croak("sort is now a reserved word");
3546 s = force_word(s,WORD,TRUE,TRUE,FALSE);
3550 LOP(OP_SPLIT,XTERM);
3553 LOP(OP_SPRINTF,XTERM);
3556 LOP(OP_SPLICE,XTERM);
3572 LOP(OP_SUBSTR,XTERM);
3579 if (isIDFIRST(*s) || *s == '\'' || *s == ':') {
3580 char tmpbuf[sizeof tokenbuf];
3582 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3583 if (strchr(tmpbuf, ':'))
3584 sv_setpv(subname, tmpbuf);
3586 sv_setsv(subname,curstname);
3587 sv_catpvn(subname,"::",2);
3588 sv_catpvn(subname,tmpbuf,len);
3590 s = force_word(s,WORD,FALSE,TRUE,TRUE);
3594 expect = XTERMBLOCK;
3595 sv_setpv(subname,"?");
3598 if (tmp == KEY_format) {
3601 lex_formbrack = lex_brackets + 1;
3605 /* Look for a prototype */
3612 SvREFCNT_dec(lex_stuff);
3614 croak("Prototype not terminated");
3617 d = SvPVX(lex_stuff);
3619 for (p = d; *p; ++p) {
3624 SvCUR(lex_stuff) = tmp;
3627 nextval[1] = nextval[0];
3628 nexttype[1] = nexttype[0];
3629 nextval[0].opval = (OP*)newSVOP(OP_CONST, 0, lex_stuff);
3630 nexttype[0] = THING;
3631 if (nexttoke == 1) {
3632 lex_defer = lex_state;
3633 lex_expect = expect;
3634 lex_state = LEX_KNOWNEXT;
3639 if (*SvPV(subname,na) == '?') {
3640 sv_setpv(subname,"__ANON__");
3647 LOP(OP_SYSTEM,XREF);
3650 LOP(OP_SYMLINK,XTERM);
3653 LOP(OP_SYSCALL,XTERM);
3656 LOP(OP_SYSOPEN,XTERM);
3659 LOP(OP_SYSSEEK,XTERM);
3662 LOP(OP_SYSREAD,XTERM);
3665 LOP(OP_SYSWRITE,XTERM);
3669 TERM(sublex_start());
3690 LOP(OP_TRUNCATE,XTERM);
3702 yylval.ival = curcop->cop_line;
3706 yylval.ival = curcop->cop_line;
3710 LOP(OP_UNLINK,XTERM);
3716 LOP(OP_UNPACK,XTERM);
3719 LOP(OP_UTIME,XTERM);
3723 for (d = s; d < bufend && (isSPACE(*d) || *d == '('); d++) ;
3724 if (*d != '0' && isDIGIT(*d))
3725 yywarn("umask: argument is missing initial 0");
3730 LOP(OP_UNSHIFT,XTERM);
3733 if (expect != XSTATE)
3734 yyerror("\"use\" not allowed in expression");
3737 s = force_version(s);
3738 if(*s == ';' || (s = skipspace(s), *s == ';')) {
3739 nextval[nexttoke].opval = Nullop;
3744 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3745 s = force_version(s);
3758 yylval.ival = curcop->cop_line;
3762 hints |= HINT_BLOCK_SCOPE;
3769 LOP(OP_WAITPID,XTERM);
3775 gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */
3779 if (expect == XOPERATOR)
3785 yylval.ival = OP_XOR;
3790 TERM(sublex_start());
3796 keyword(register char *d, I32 len)
3801 if (strEQ(d,"__FILE__")) return -KEY___FILE__;
3802 if (strEQ(d,"__LINE__")) return -KEY___LINE__;
3803 if (strEQ(d,"__PACKAGE__")) return -KEY___PACKAGE__;
3804 if (strEQ(d,"__DATA__")) return KEY___DATA__;
3805 if (strEQ(d,"__END__")) return KEY___END__;
3809 if (strEQ(d,"AUTOLOAD")) return KEY_AUTOLOAD;
3814 if (strEQ(d,"and")) return -KEY_and;
3815 if (strEQ(d,"abs")) return -KEY_abs;
3818 if (strEQ(d,"alarm")) return -KEY_alarm;
3819 if (strEQ(d,"atan2")) return -KEY_atan2;
3822 if (strEQ(d,"accept")) return -KEY_accept;
3827 if (strEQ(d,"BEGIN")) return KEY_BEGIN;
3830 if (strEQ(d,"bless")) return -KEY_bless;
3831 if (strEQ(d,"bind")) return -KEY_bind;
3832 if (strEQ(d,"binmode")) return -KEY_binmode;
3835 if (strEQ(d,"CORE")) return -KEY_CORE;
3840 if (strEQ(d,"cmp")) return -KEY_cmp;
3841 if (strEQ(d,"chr")) return -KEY_chr;
3842 if (strEQ(d,"cos")) return -KEY_cos;
3845 if (strEQ(d,"chop")) return KEY_chop;
3848 if (strEQ(d,"close")) return -KEY_close;
3849 if (strEQ(d,"chdir")) return -KEY_chdir;
3850 if (strEQ(d,"chomp")) return KEY_chomp;
3851 if (strEQ(d,"chmod")) return -KEY_chmod;
3852 if (strEQ(d,"chown")) return -KEY_chown;
3853 if (strEQ(d,"crypt")) return -KEY_crypt;
3856 if (strEQ(d,"chroot")) return -KEY_chroot;
3857 if (strEQ(d,"caller")) return -KEY_caller;
3860 if (strEQ(d,"connect")) return -KEY_connect;
3863 if (strEQ(d,"closedir")) return -KEY_closedir;
3864 if (strEQ(d,"continue")) return -KEY_continue;
3869 if (strEQ(d,"DESTROY")) return KEY_DESTROY;
3874 if (strEQ(d,"do")) return KEY_do;
3877 if (strEQ(d,"die")) return -KEY_die;
3880 if (strEQ(d,"dump")) return -KEY_dump;
3883 if (strEQ(d,"delete")) return KEY_delete;
3886 if (strEQ(d,"defined")) return KEY_defined;
3887 if (strEQ(d,"dbmopen")) return -KEY_dbmopen;
3890 if (strEQ(d,"dbmclose")) return -KEY_dbmclose;
3895 if (strEQ(d,"EQ")) { deprecate(d); return -KEY_eq;}
3896 if (strEQ(d,"END")) return KEY_END;
3901 if (strEQ(d,"eq")) return -KEY_eq;
3904 if (strEQ(d,"eof")) return -KEY_eof;
3905 if (strEQ(d,"exp")) return -KEY_exp;
3908 if (strEQ(d,"else")) return KEY_else;
3909 if (strEQ(d,"exit")) return -KEY_exit;
3910 if (strEQ(d,"eval")) return KEY_eval;
3911 if (strEQ(d,"exec")) return -KEY_exec;
3912 if (strEQ(d,"each")) return KEY_each;
3915 if (strEQ(d,"elsif")) return KEY_elsif;
3918 if (strEQ(d,"exists")) return KEY_exists;
3919 if (strEQ(d,"elseif")) warn("elseif should be elsif");
3922 if (strEQ(d,"endgrent")) return -KEY_endgrent;
3923 if (strEQ(d,"endpwent")) return -KEY_endpwent;
3926 if (strEQ(d,"endnetent")) return -KEY_endnetent;
3929 if (strEQ(d,"endhostent")) return -KEY_endhostent;
3930 if (strEQ(d,"endservent")) return -KEY_endservent;
3933 if (strEQ(d,"endprotoent")) return -KEY_endprotoent;
3940 if (strEQ(d,"for")) return KEY_for;
3943 if (strEQ(d,"fork")) return -KEY_fork;
3946 if (strEQ(d,"fcntl")) return -KEY_fcntl;
3947 if (strEQ(d,"flock")) return -KEY_flock;
3950 if (strEQ(d,"format")) return KEY_format;
3951 if (strEQ(d,"fileno")) return -KEY_fileno;
3954 if (strEQ(d,"foreach")) return KEY_foreach;
3957 if (strEQ(d,"formline")) return -KEY_formline;
3963 if (strEQ(d,"GT")) { deprecate(d); return -KEY_gt;}
3964 if (strEQ(d,"GE")) { deprecate(d); return -KEY_ge;}
3968 if (strnEQ(d,"get",3)) {
3973 if (strEQ(d,"ppid")) return -KEY_getppid;
3974 if (strEQ(d,"pgrp")) return -KEY_getpgrp;
3977 if (strEQ(d,"pwent")) return -KEY_getpwent;
3978 if (strEQ(d,"pwnam")) return -KEY_getpwnam;
3979 if (strEQ(d,"pwuid")) return -KEY_getpwuid;
3982 if (strEQ(d,"peername")) return -KEY_getpeername;
3983 if (strEQ(d,"protoent")) return -KEY_getprotoent;
3984 if (strEQ(d,"priority")) return -KEY_getpriority;
3987 if (strEQ(d,"protobyname")) return -KEY_getprotobyname;
3990 if (strEQ(d,"protobynumber"))return -KEY_getprotobynumber;
3994 else if (*d == 'h') {
3995 if (strEQ(d,"hostbyname")) return -KEY_gethostbyname;
3996 if (strEQ(d,"hostbyaddr")) return -KEY_gethostbyaddr;
3997 if (strEQ(d,"hostent")) return -KEY_gethostent;
3999 else if (*d == 'n') {
4000 if (strEQ(d,"netbyname")) return -KEY_getnetbyname;
4001 if (strEQ(d,"netbyaddr")) return -KEY_getnetbyaddr;
4002 if (strEQ(d,"netent")) return -KEY_getnetent;
4004 else if (*d == 's') {
4005 if (strEQ(d,"servbyname")) return -KEY_getservbyname;
4006 if (strEQ(d,"servbyport")) return -KEY_getservbyport;
4007 if (strEQ(d,"servent")) return -KEY_getservent;
4008 if (strEQ(d,"sockname")) return -KEY_getsockname;
4009 if (strEQ(d,"sockopt")) return -KEY_getsockopt;
4011 else if (*d == 'g') {
4012 if (strEQ(d,"grent")) return -KEY_getgrent;
4013 if (strEQ(d,"grnam")) return -KEY_getgrnam;
4014 if (strEQ(d,"grgid")) return -KEY_getgrgid;
4016 else if (*d == 'l') {
4017 if (strEQ(d,"login")) return -KEY_getlogin;
4019 else if (strEQ(d,"c")) return -KEY_getc;
4024 if (strEQ(d,"gt")) return -KEY_gt;
4025 if (strEQ(d,"ge")) return -KEY_ge;
4028 if (strEQ(d,"grep")) return KEY_grep;
4029 if (strEQ(d,"goto")) return KEY_goto;
4030 if (strEQ(d,"glob")) return KEY_glob;
4033 if (strEQ(d,"gmtime")) return -KEY_gmtime;
4038 if (strEQ(d,"hex")) return -KEY_hex;
4041 if (strEQ(d,"INIT")) return KEY_INIT;
4046 if (strEQ(d,"if")) return KEY_if;
4049 if (strEQ(d,"int")) return -KEY_int;
4052 if (strEQ(d,"index")) return -KEY_index;
4053 if (strEQ(d,"ioctl")) return -KEY_ioctl;
4058 if (strEQ(d,"join")) return -KEY_join;
4062 if (strEQ(d,"keys")) return KEY_keys;
4063 if (strEQ(d,"kill")) return -KEY_kill;
4068 if (strEQ(d,"LT")) { deprecate(d); return -KEY_lt;}
4069 if (strEQ(d,"LE")) { deprecate(d); return -KEY_le;}
4075 if (strEQ(d,"lt")) return -KEY_lt;
4076 if (strEQ(d,"le")) return -KEY_le;
4077 if (strEQ(d,"lc")) return -KEY_lc;
4080 if (strEQ(d,"log")) return -KEY_log;
4083 if (strEQ(d,"last")) return KEY_last;
4084 if (strEQ(d,"link")) return -KEY_link;
4085 if (strEQ(d,"lock")) return -KEY_lock;
4088 if (strEQ(d,"local")) return KEY_local;
4089 if (strEQ(d,"lstat")) return -KEY_lstat;
4092 if (strEQ(d,"length")) return -KEY_length;
4093 if (strEQ(d,"listen")) return -KEY_listen;
4096 if (strEQ(d,"lcfirst")) return -KEY_lcfirst;
4099 if (strEQ(d,"localtime")) return -KEY_localtime;
4105 case 1: return KEY_m;
4107 if (strEQ(d,"my")) return KEY_my;
4110 if (strEQ(d,"map")) return KEY_map;
4113 if (strEQ(d,"mkdir")) return -KEY_mkdir;
4116 if (strEQ(d,"msgctl")) return -KEY_msgctl;
4117 if (strEQ(d,"msgget")) return -KEY_msgget;
4118 if (strEQ(d,"msgrcv")) return -KEY_msgrcv;
4119 if (strEQ(d,"msgsnd")) return -KEY_msgsnd;
4124 if (strEQ(d,"NE")) { deprecate(d); return -KEY_ne;}
4127 if (strEQ(d,"next")) return KEY_next;
4128 if (strEQ(d,"ne")) return -KEY_ne;
4129 if (strEQ(d,"not")) return -KEY_not;
4130 if (strEQ(d,"no")) return KEY_no;
4135 if (strEQ(d,"or")) return -KEY_or;
4138 if (strEQ(d,"ord")) return -KEY_ord;
4139 if (strEQ(d,"oct")) return -KEY_oct;
4142 if (strEQ(d,"open")) return -KEY_open;
4145 if (strEQ(d,"opendir")) return -KEY_opendir;
4152 if (strEQ(d,"pop")) return KEY_pop;
4153 if (strEQ(d,"pos")) return KEY_pos;
4156 if (strEQ(d,"push")) return KEY_push;
4157 if (strEQ(d,"pack")) return -KEY_pack;
4158 if (strEQ(d,"pipe")) return -KEY_pipe;
4161 if (strEQ(d,"print")) return KEY_print;
4164 if (strEQ(d,"printf")) return KEY_printf;
4167 if (strEQ(d,"package")) return KEY_package;
4170 if (strEQ(d,"prototype")) return KEY_prototype;
4175 if (strEQ(d,"q")) return KEY_q;
4176 if (strEQ(d,"qq")) return KEY_qq;
4177 if (strEQ(d,"qw")) return KEY_qw;
4178 if (strEQ(d,"qx")) return KEY_qx;
4180 else if (strEQ(d,"quotemeta")) return -KEY_quotemeta;
4185 if (strEQ(d,"ref")) return -KEY_ref;
4188 if (strEQ(d,"read")) return -KEY_read;
4189 if (strEQ(d,"rand")) return -KEY_rand;
4190 if (strEQ(d,"recv")) return -KEY_recv;
4191 if (strEQ(d,"redo")) return KEY_redo;
4194 if (strEQ(d,"rmdir")) return -KEY_rmdir;
4195 if (strEQ(d,"reset")) return -KEY_reset;
4198 if (strEQ(d,"return")) return KEY_return;
4199 if (strEQ(d,"rename")) return -KEY_rename;
4200 if (strEQ(d,"rindex")) return -KEY_rindex;
4203 if (strEQ(d,"require")) return -KEY_require;
4204 if (strEQ(d,"reverse")) return -KEY_reverse;
4205 if (strEQ(d,"readdir")) return -KEY_readdir;
4208 if (strEQ(d,"readlink")) return -KEY_readlink;
4209 if (strEQ(d,"readline")) return -KEY_readline;
4210 if (strEQ(d,"readpipe")) return -KEY_readpipe;
4213 if (strEQ(d,"rewinddir")) return -KEY_rewinddir;
4219 case 0: return KEY_s;
4221 if (strEQ(d,"scalar")) return KEY_scalar;
4226 if (strEQ(d,"seek")) return -KEY_seek;
4227 if (strEQ(d,"send")) return -KEY_send;
4230 if (strEQ(d,"semop")) return -KEY_semop;
4233 if (strEQ(d,"select")) return -KEY_select;
4234 if (strEQ(d,"semctl")) return -KEY_semctl;
4235 if (strEQ(d,"semget")) return -KEY_semget;
4238 if (strEQ(d,"setpgrp")) return -KEY_setpgrp;
4239 if (strEQ(d,"seekdir")) return -KEY_seekdir;
4242 if (strEQ(d,"setpwent")) return -KEY_setpwent;
4243 if (strEQ(d,"setgrent")) return -KEY_setgrent;
4246 if (strEQ(d,"setnetent")) return -KEY_setnetent;
4249 if (strEQ(d,"setsockopt")) return -KEY_setsockopt;
4250 if (strEQ(d,"sethostent")) return -KEY_sethostent;
4251 if (strEQ(d,"setservent")) return -KEY_setservent;
4254 if (strEQ(d,"setpriority")) return -KEY_setpriority;
4255 if (strEQ(d,"setprotoent")) return -KEY_setprotoent;
4262 if (strEQ(d,"shift")) return KEY_shift;
4265 if (strEQ(d,"shmctl")) return -KEY_shmctl;
4266 if (strEQ(d,"shmget")) return -KEY_shmget;
4269 if (strEQ(d,"shmread")) return -KEY_shmread;
4272 if (strEQ(d,"shmwrite")) return -KEY_shmwrite;
4273 if (strEQ(d,"shutdown")) return -KEY_shutdown;
4278 if (strEQ(d,"sin")) return -KEY_sin;
4281 if (strEQ(d,"sleep")) return -KEY_sleep;
4284 if (strEQ(d,"sort")) return KEY_sort;
4285 if (strEQ(d,"socket")) return -KEY_socket;
4286 if (strEQ(d,"socketpair")) return -KEY_socketpair;
4289 if (strEQ(d,"split")) return KEY_split;
4290 if (strEQ(d,"sprintf")) return -KEY_sprintf;
4291 if (strEQ(d,"splice")) return KEY_splice;
4294 if (strEQ(d,"sqrt")) return -KEY_sqrt;
4297 if (strEQ(d,"srand")) return -KEY_srand;
4300 if (strEQ(d,"stat")) return -KEY_stat;
4301 if (strEQ(d,"study")) return KEY_study;
4304 if (strEQ(d,"substr")) return -KEY_substr;
4305 if (strEQ(d,"sub")) return KEY_sub;
4310 if (strEQ(d,"system")) return -KEY_system;
4313 if (strEQ(d,"symlink")) return -KEY_symlink;
4314 if (strEQ(d,"syscall")) return -KEY_syscall;
4315 if (strEQ(d,"sysopen")) return -KEY_sysopen;
4316 if (strEQ(d,"sysread")) return -KEY_sysread;
4317 if (strEQ(d,"sysseek")) return -KEY_sysseek;
4320 if (strEQ(d,"syswrite")) return -KEY_syswrite;
4329 if (strEQ(d,"tr")) return KEY_tr;
4332 if (strEQ(d,"tie")) return KEY_tie;
4335 if (strEQ(d,"tell")) return -KEY_tell;
4336 if (strEQ(d,"tied")) return KEY_tied;
4337 if (strEQ(d,"time")) return -KEY_time;
4340 if (strEQ(d,"times")) return -KEY_times;
4343 if (strEQ(d,"telldir")) return -KEY_telldir;
4346 if (strEQ(d,"truncate")) return -KEY_truncate;
4353 if (strEQ(d,"uc")) return -KEY_uc;
4356 if (strEQ(d,"use")) return KEY_use;
4359 if (strEQ(d,"undef")) return KEY_undef;
4360 if (strEQ(d,"until")) return KEY_until;
4361 if (strEQ(d,"untie")) return KEY_untie;
4362 if (strEQ(d,"utime")) return -KEY_utime;
4363 if (strEQ(d,"umask")) return -KEY_umask;
4366 if (strEQ(d,"unless")) return KEY_unless;
4367 if (strEQ(d,"unpack")) return -KEY_unpack;
4368 if (strEQ(d,"unlink")) return -KEY_unlink;
4371 if (strEQ(d,"unshift")) return KEY_unshift;
4372 if (strEQ(d,"ucfirst")) return -KEY_ucfirst;
4377 if (strEQ(d,"values")) return -KEY_values;
4378 if (strEQ(d,"vec")) return -KEY_vec;
4383 if (strEQ(d,"warn")) return -KEY_warn;
4384 if (strEQ(d,"wait")) return -KEY_wait;
4387 if (strEQ(d,"while")) return KEY_while;
4388 if (strEQ(d,"write")) return -KEY_write;
4391 if (strEQ(d,"waitpid")) return -KEY_waitpid;
4394 if (strEQ(d,"wantarray")) return -KEY_wantarray;
4399 if (len == 1) return -KEY_x;
4400 if (strEQ(d,"xor")) return -KEY_xor;
4403 if (len == 1) return KEY_y;
4412 checkcomma(register char *s, char *name, char *what)
4416 if (dowarn && *s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
4418 for (w = s+2; *w && level; w++) {
4425 for (; *w && isSPACE(*w); w++) ;
4426 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
4427 warn("%s (...) interpreted as function",name);
4429 while (s < bufend && isSPACE(*s))
4433 while (s < bufend && isSPACE(*s))
4435 if (isIDFIRST(*s)) {
4439 while (s < bufend && isSPACE(*s))
4444 kw = keyword(w, s - w) || perl_get_cv(w, FALSE) != 0;
4448 croak("No comma allowed after %s", what);
4454 scan_word(register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
4456 register char *d = dest;
4457 register char *e = d + destlen - 3; /* two-character token, ending NUL */
4460 croak(ident_too_long);
4463 else if (*s == '\'' && allow_package && isIDFIRST(s[1])) {
4468 else if (*s == ':' && s[1] == ':' && allow_package && isIDFIRST(s[2])) {
4481 scan_ident(register char *s, register char *send, char *dest, STRLEN destlen, I32 ck_uni)
4488 if (lex_brackets == 0)
4493 e = d + destlen - 3; /* two-character token, ending NUL */
4495 while (isDIGIT(*s)) {
4497 croak(ident_too_long);
4504 croak(ident_too_long);
4507 else if (*s == '\'' && isIDFIRST(s[1])) {
4512 else if (*s == ':' && s[1] == ':') {
4523 if (lex_state != LEX_NORMAL)
4524 lex_state = LEX_INTERPENDMAYBE;
4527 if (*s == '$' && s[1] &&
4528 (isALNUM(s[1]) || strchr("${", s[1]) || strnEQ(s+1,"::",2)) )
4530 if (isDIGIT(s[1]) && lex_state == LEX_INTERPNORMAL)
4531 deprecate("\"$$<digit>\" to mean \"${$}<digit>\"");
4544 if (*d == '^' && *s && (isUPPER(*s) || strchr("[\\]^_?", *s))) {
4549 if (isSPACE(s[-1])) {
4552 if (ch != ' ' && ch != '\t') {
4558 if (isIDFIRST(*d)) {
4560 while (isALNUM(*s) || *s == ':')
4563 while (s < send && (*s == ' ' || *s == '\t')) s++;
4564 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
4565 if (dowarn && keyword(dest, d - dest)) {
4566 char *brack = *s == '[' ? "[...]" : "{...}";
4567 warn("Ambiguous use of %c{%s%s} resolved to %c%s%s",
4568 funny, dest, brack, funny, dest, brack);
4570 lex_fakebrack = lex_brackets+1;
4572 lex_brackstack[lex_brackets++] = XOPERATOR;
4578 if (lex_state == LEX_INTERPNORMAL && !lex_brackets)
4579 lex_state = LEX_INTERPEND;
4582 if (dowarn && lex_state == LEX_NORMAL &&
4583 (keyword(dest, d - dest) || perl_get_cv(dest, FALSE)))
4584 warn("Ambiguous use of %c{%s} resolved to %c%s",
4585 funny, dest, funny, dest);
4588 s = bracket; /* let the parser handle it */
4592 else if (lex_state == LEX_INTERPNORMAL && !lex_brackets && !intuit_more(s))
4593 lex_state = LEX_INTERPEND;
4597 void pmflag(U16 *pmfl, int ch)
4602 *pmfl |= PMf_GLOBAL;
4604 *pmfl |= PMf_CONTINUE;
4608 *pmfl |= PMf_MULTILINE;
4610 *pmfl |= PMf_SINGLELINE;
4612 *pmfl |= PMf_EXTENDED;
4616 scan_pat(char *start)
4621 s = scan_str(start);
4624 SvREFCNT_dec(lex_stuff);
4626 croak("Search pattern not terminated");
4629 pm = (PMOP*)newPMOP(OP_MATCH, 0);
4630 if (multi_open == '?')
4631 pm->op_pmflags |= PMf_ONCE;
4632 while (*s && strchr("iogcmsx", *s))
4633 pmflag(&pm->op_pmflags,*s++);
4634 pm->op_pmpermflags = pm->op_pmflags;
4637 yylval.ival = OP_MATCH;
4642 scan_subst(char *start)
4649 yylval.ival = OP_NULL;
4651 s = scan_str(start);
4655 SvREFCNT_dec(lex_stuff);
4657 croak("Substitution pattern not terminated");
4660 if (s[-1] == multi_open)
4663 first_start = multi_start;
4667 SvREFCNT_dec(lex_stuff);
4670 SvREFCNT_dec(lex_repl);
4672 croak("Substitution replacement not terminated");
4674 multi_start = first_start; /* so whole substitution is taken together */
4676 pm = (PMOP*)newPMOP(OP_SUBST, 0);
4677 while (*s && strchr("iogcmsex", *s)) {
4683 pmflag(&pm->op_pmflags,*s++);
4688 pm->op_pmflags |= PMf_EVAL;
4689 repl = newSVpv("",0);
4691 sv_catpv(repl, es ? "eval " : "do ");
4692 sv_catpvn(repl, "{ ", 2);
4693 sv_catsv(repl, lex_repl);
4694 sv_catpvn(repl, " };", 2);
4695 SvCOMPILED_on(repl);
4696 SvREFCNT_dec(lex_repl);
4700 pm->op_pmpermflags = pm->op_pmflags;
4702 yylval.ival = OP_SUBST;
4707 scan_trans(char *start)
4716 yylval.ival = OP_NULL;
4718 s = scan_str(start);
4721 SvREFCNT_dec(lex_stuff);
4723 croak("Translation pattern not terminated");
4725 if (s[-1] == multi_open)
4731 SvREFCNT_dec(lex_stuff);
4734 SvREFCNT_dec(lex_repl);
4736 croak("Translation replacement not terminated");
4739 New(803,tbl,256,short);
4740 o = newPVOP(OP_TRANS, 0, (char*)tbl);
4742 complement = Delete = squash = 0;
4743 while (*s == 'c' || *s == 'd' || *s == 's') {
4745 complement = OPpTRANS_COMPLEMENT;
4747 Delete = OPpTRANS_DELETE;
4749 squash = OPpTRANS_SQUASH;
4752 o->op_private = Delete|squash|complement;
4755 yylval.ival = OP_TRANS;
4760 scan_heredoc(register char *s)
4764 I32 op_type = OP_SCALAR;
4771 int outer = (rsfp && !lex_inwhat);
4775 e = tokenbuf + sizeof tokenbuf - 1;
4778 for (peek = s; *peek == ' ' || *peek == '\t'; peek++) ;
4779 if (*peek && strchr("`'\"",*peek)) {
4782 s = delimcpy(d, e, s, bufend, term, &len);
4793 deprecate("bare << to mean <<\"\"");
4794 for (; isALNUM(*s); s++) {
4799 if (d >= tokenbuf + sizeof tokenbuf - 1)
4800 croak("Delimiter for here document is too long");
4805 if (outer || !(d=ninstr(s,bufend,d,d+1)))
4806 herewas = newSVpv(s,bufend-s);
4808 s--, herewas = newSVpv(s,d-s);
4809 s += SvCUR(herewas);
4811 tmpstr = NEWSV(87,80);
4812 sv_upgrade(tmpstr, SVt_PVIV);
4817 else if (term == '`') {
4818 op_type = OP_BACKTICK;
4819 SvIVX(tmpstr) = '\\';
4823 multi_start = curcop->cop_line;
4824 multi_open = multi_close = '<';
4828 while (s < bufend &&
4829 (*s != term || memNE(s,tokenbuf,len)) ) {
4834 curcop->cop_line = multi_start;
4835 missingterm(tokenbuf);
4837 sv_setpvn(tmpstr,d+1,s-d);
4839 sv_catpvn(herewas,s,bufend-s);
4840 sv_setsv(linestr,herewas);
4841 oldoldbufptr = oldbufptr = bufptr = s = linestart = SvPVX(linestr);
4842 bufend = SvPVX(linestr) + SvCUR(linestr);
4845 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
4846 while (s >= bufend) { /* multiple line string? */
4848 !(oldoldbufptr = oldbufptr = s = linestart = filter_gets(linestr, rsfp, 0))) {
4849 curcop->cop_line = multi_start;
4850 missingterm(tokenbuf);
4853 if (PERLDB_LINE && curstash != debstash) {
4854 SV *sv = NEWSV(88,0);
4856 sv_upgrade(sv, SVt_PVMG);
4857 sv_setsv(sv,linestr);
4858 av_store(GvAV(curcop->cop_filegv),
4859 (I32)curcop->cop_line,sv);
4861 bufend = SvPVX(linestr) + SvCUR(linestr);
4862 if (*s == term && memEQ(s,tokenbuf,len)) {
4865 sv_catsv(linestr,herewas);
4866 bufend = SvPVX(linestr) + SvCUR(linestr);
4870 sv_catsv(tmpstr,linestr);
4873 multi_end = curcop->cop_line;
4875 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
4876 SvLEN_set(tmpstr, SvCUR(tmpstr) + 1);
4877 Renew(SvPVX(tmpstr), SvLEN(tmpstr), char);
4879 SvREFCNT_dec(herewas);
4881 yylval.ival = op_type;
4886 scan_inputsymbol(char *start)
4888 register char *s = start;
4894 e = tokenbuf + sizeof tokenbuf;
4895 s = delimcpy(d, e, s + 1, bufend, '>', &len);
4896 if (len >= sizeof tokenbuf)
4897 croak("Excessively long <> operator");
4899 croak("Unterminated <> operator");
4901 if (*d == '$' && d[1]) d++;
4902 while (*d && (isALNUM(*d) || *d == '\'' || *d == ':'))
4904 if (d - tokenbuf != len) {
4905 yylval.ival = OP_GLOB;
4907 s = scan_str(start);
4909 croak("Glob not terminated");
4915 (void)strcpy(d,"ARGV");
4918 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
4919 OP *o = newOP(OP_PADSV, 0);
4921 lex_op = (OP*)newUNOP(OP_READLINE, 0, newUNOP(OP_RV2GV, 0, o));
4924 GV *gv = gv_fetchpv(d+1,TRUE, SVt_PV);
4925 lex_op = (OP*)newUNOP(OP_READLINE, 0,
4926 newUNOP(OP_RV2GV, 0,
4927 newUNOP(OP_RV2SV, 0,
4928 newGVOP(OP_GV, 0, gv))));
4930 yylval.ival = OP_NULL;
4933 GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO);
4934 lex_op = (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
4935 yylval.ival = OP_NULL;
4942 scan_str(char *start)
4947 register char *s = start;
4956 multi_start = curcop->cop_line;
4958 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4963 sv_upgrade(sv, SVt_PVIV);
4965 (void)SvPOK_only(sv); /* validate pointer */
4968 SvGROW(sv, SvCUR(sv) + (bufend - s) + 1);
4969 to = SvPVX(sv)+SvCUR(sv);
4970 if (multi_open == multi_close) {
4971 for (; s < bufend; s++,to++) {
4972 if (*s == '\n' && !rsfp)
4974 if (*s == '\\' && s+1 < bufend && term != '\\') {
4980 else if (*s == term)
4986 for (; s < bufend; s++,to++) {
4987 if (*s == '\n' && !rsfp)
4989 if (*s == '\\' && s+1 < bufend) {
4990 if ((s[1] == multi_open) || (s[1] == multi_close))
4995 else if (*s == multi_close && --brackets <= 0)
4997 else if (*s == multi_open)
5003 SvCUR_set(sv, to - SvPVX(sv));
5005 if (s < bufend) break; /* string ends on this line? */
5008 !(oldoldbufptr = oldbufptr = s = linestart = filter_gets(linestr, rsfp, 0))) {
5010 curcop->cop_line = multi_start;
5014 if (PERLDB_LINE && curstash != debstash) {
5015 SV *sv = NEWSV(88,0);
5017 sv_upgrade(sv, SVt_PVMG);
5018 sv_setsv(sv,linestr);
5019 av_store(GvAV(curcop->cop_filegv),
5020 (I32)curcop->cop_line, sv);
5022 bufend = SvPVX(linestr) + SvCUR(linestr);
5024 multi_end = curcop->cop_line;
5026 if (SvCUR(sv) + 5 < SvLEN(sv)) {
5027 SvLEN_set(sv, SvCUR(sv) + 1);
5028 Renew(SvPVX(sv), SvLEN(sv), char);
5038 scan_num(char *start)
5040 register char *s = start;
5048 static char number_too_long[] = "Number too long";
5052 croak("panic: scan_num");
5057 bool overflowed = FALSE;
5063 else if (s[1] == '.')
5079 yyerror("Illegal octal digit");
5081 case '0': case '1': case '2': case '3': case '4':
5082 case '5': case '6': case '7':
5085 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
5086 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
5092 if (!overflowed && (n >> shift) != u) {
5093 warn("Integer overflow in %s number",
5094 (shift == 4) ? "hex" : "octal");
5106 case '1': case '2': case '3': case '4': case '5':
5107 case '6': case '7': case '8': case '9': case '.':
5110 e = tokenbuf + sizeof tokenbuf - 6; /* room for various punctuation */
5112 while (isDIGIT(*s) || *s == '_') {
5114 if (dowarn && lastub && s - lastub != 3)
5115 warn("Misplaced _ in number");
5120 croak(number_too_long);
5124 if (dowarn && lastub && s - lastub != 3)
5125 warn("Misplaced _ in number");
5126 if (*s == '.' && s[1] != '.') {
5129 for (; isDIGIT(*s) || *s == '_'; s++) {
5131 croak(number_too_long);
5136 if (*s && strchr("eE",*s) && strchr("+-0123456789",s[1])) {
5139 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
5140 if (*s == '+' || *s == '-')
5142 while (isDIGIT(*s)) {
5144 croak(number_too_long);
5150 SET_NUMERIC_STANDARD();
5151 value = atof(tokenbuf);
5153 if (!floatit && (double)tryiv == value)
5154 sv_setiv(sv, tryiv);
5156 sv_setnv(sv, value);
5160 yylval.opval = newSVOP(OP_CONST, 0, sv);
5166 scan_formline(register char *s)
5171 SV *stuff = newSVpv("",0);
5172 bool needargs = FALSE;
5175 if (*s == '.' || *s == '}') {
5177 for (t = s+1; *t == ' ' || *t == '\t'; t++) ;
5181 if (in_eval && !rsfp) {
5182 eol = strchr(s,'\n');
5187 eol = bufend = SvPVX(linestr) + SvCUR(linestr);
5189 for (t = s; t < eol; t++) {
5190 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
5192 goto enough; /* ~~ must be first line in formline */
5194 if (*t == '@' || *t == '^')
5197 sv_catpvn(stuff, s, eol-s);
5201 s = filter_gets(linestr, rsfp, 0);
5202 oldoldbufptr = oldbufptr = bufptr = linestart = SvPVX(linestr);
5203 bufend = bufptr + SvCUR(linestr);
5206 yyerror("Format not terminated");
5216 lex_state = LEX_NORMAL;
5217 nextval[nexttoke].ival = 0;
5221 lex_state = LEX_FORMLINE;
5222 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff);
5224 nextval[nexttoke].ival = OP_FORMLINE;
5228 SvREFCNT_dec(stuff);
5240 cshlen = strlen(cshname);
5245 start_subparse(I32 is_format, U32 flags)
5248 I32 oldsavestack_ix = savestack_ix;
5249 CV* outsidecv = compcv;
5253 assert(SvTYPE(compcv) == SVt_PVCV);
5260 SAVESPTR(comppad_name);
5262 SAVEI32(comppad_name_fill);
5263 SAVEI32(min_intro_pending);
5264 SAVEI32(max_intro_pending);
5265 SAVEI32(pad_reset_pending);
5267 compcv = (CV*)NEWSV(1104,0);
5268 sv_upgrade((SV *)compcv, is_format ? SVt_PVFM : SVt_PVCV);
5269 CvFLAGS(compcv) |= flags;
5272 av_push(comppad, Nullsv);
5273 curpad = AvARRAY(comppad);
5274 comppad_name = newAV();
5275 comppad_name_fill = 0;
5276 min_intro_pending = 0;
5278 subline = curcop->cop_line;
5280 av_store(comppad_name, 0, newSVpv("@_", 2));
5281 curpad[0] = (SV*)newAV();
5282 SvPADMY_on(curpad[0]); /* XXX Needed? */
5283 CvOWNER(compcv) = 0;
5284 New(666, CvMUTEXP(compcv), 1, perl_mutex);
5285 MUTEX_INIT(CvMUTEXP(compcv));
5286 #endif /* USE_THREADS */
5288 comppadlist = newAV();
5289 AvREAL_off(comppadlist);
5290 av_store(comppadlist, 0, (SV*)comppad_name);
5291 av_store(comppadlist, 1, (SV*)comppad);
5293 CvPADLIST(compcv) = comppadlist;
5294 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc(outsidecv);
5296 CvOWNER(compcv) = 0;
5297 New(666, CvMUTEXP(compcv), 1, perl_mutex);
5298 MUTEX_INIT(CvMUTEXP(compcv));
5299 #endif /* USE_THREADS */
5301 return oldsavestack_ix;
5320 char *context = NULL;
5324 if (!yychar || (yychar == ';' && !rsfp))
5326 else if (bufptr > oldoldbufptr && bufptr - oldoldbufptr < 200 &&
5327 oldoldbufptr != oldbufptr && oldbufptr != bufptr) {
5328 while (isSPACE(*oldoldbufptr))
5330 context = oldoldbufptr;
5331 contlen = bufptr - oldoldbufptr;
5333 else if (bufptr > oldbufptr && bufptr - oldbufptr < 200 &&
5334 oldbufptr != bufptr) {
5335 while (isSPACE(*oldbufptr))
5337 context = oldbufptr;
5338 contlen = bufptr - oldbufptr;
5340 else if (yychar > 255)
5341 where = "next token ???";
5342 else if ((yychar & 127) == 127) {
5343 if (lex_state == LEX_NORMAL ||
5344 (lex_state == LEX_KNOWNEXT && lex_defer == LEX_NORMAL))
5345 where = "at end of line";
5347 where = "within pattern";
5349 where = "within string";
5352 SV *where_sv = sv_2mortal(newSVpv("next char ", 0));
5354 sv_catpvf(where_sv, "^%c", toCTRL(yychar));
5355 else if (isPRINT_LC(yychar))
5356 sv_catpvf(where_sv, "%c", yychar);
5358 sv_catpvf(where_sv, "\\%03o", yychar & 255);
5359 where = SvPVX(where_sv);
5361 msg = sv_2mortal(newSVpv(s, 0));
5362 sv_catpvf(msg, " at %_ line %ld, ",
5363 GvSV(curcop->cop_filegv), (long)curcop->cop_line);
5365 sv_catpvf(msg, "near \"%.*s\"\n", contlen, context);
5367 sv_catpvf(msg, "%s\n", where);
5368 if (multi_start < multi_end && (U32)(curcop->cop_line - multi_end) <= 1) {
5370 " (Might be a runaway multi-line %c%c string starting on line %ld)\n",
5371 (int)multi_open,(int)multi_close,(long)multi_start);
5377 sv_catsv(ERRSV, msg);
5379 PerlIO_write(PerlIO_stderr(), SvPVX(msg), SvCUR(msg));
5380 if (++error_count >= 10)
5381 croak("%_ has too many errors.\n", GvSV(curcop->cop_filegv));
5383 in_my_stash = Nullhv;