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
18 static void check_uni _((void));
19 static void force_next _((I32 type));
20 static char *force_version _((char *start));
21 static char *force_word _((char *start, int token, int check_keyword, int allow_pack, int allow_tick));
22 static SV *tokeq _((SV *sv));
23 static char *scan_const _((char *start));
24 static char *scan_formline _((char *s));
25 static char *scan_heredoc _((char *s));
26 static char *scan_ident _((char *s, char *send, char *dest, STRLEN destlen,
28 static char *scan_inputsymbol _((char *start));
29 static char *scan_pat _((char *start));
30 static char *scan_str _((char *start));
31 static char *scan_subst _((char *start));
32 static char *scan_trans _((char *start));
33 static char *scan_word _((char *s, char *dest, STRLEN destlen,
34 int allow_package, STRLEN *slp));
35 static char *skipspace _((char *s));
36 static void checkcomma _((char *s, char *name, char *what));
37 static void force_ident _((char *s, int kind));
38 static void incline _((char *s));
39 static int intuit_method _((char *s, GV *gv));
40 static int intuit_more _((char *s));
41 static I32 lop _((I32 f, expectation x, char *s));
42 static void missingterm _((char *s));
43 static void no_op _((char *what, char *s));
44 static void set_csh _((void));
45 static I32 sublex_done _((void));
46 static I32 sublex_push _((void));
47 static I32 sublex_start _((void));
49 static int uni _((I32 f, char *s));
51 static char * filter_gets _((SV *sv, PerlIO *fp, STRLEN append));
52 static void restore_rsfp _((void *f));
53 #endif /* PERL_OBJECT */
55 static char ident_too_long[] = "Identifier too long";
57 static char *linestart; /* beg. of most recently read line */
59 static char pending_ident; /* pending identifier lookup */
62 I32 super_state; /* lexer state to save */
63 I32 sub_inwhat; /* "lex_inwhat" to use */
64 OP *sub_op; /* "lex_op" to use */
67 /* The following are arranged oddly so that the guard on the switch statement
68 * can get by with a single comparison (if the compiler is smart enough).
71 /* #define LEX_NOTPARSING 11 is done in perl.h. */
74 #define LEX_INTERPNORMAL 9
75 #define LEX_INTERPCASEMOD 8
76 #define LEX_INTERPPUSH 7
77 #define LEX_INTERPSTART 6
78 #define LEX_INTERPEND 5
79 #define LEX_INTERPENDMAYBE 4
80 #define LEX_INTERPCONCAT 3
81 #define LEX_INTERPCONST 2
82 #define LEX_FORMLINE 1
83 #define LEX_KNOWNEXT 0
92 /* XXX If this causes problems, set i_unistd=undef in the hint file. */
94 # include <unistd.h> /* Needed for execv() */
102 #include "keywords.h"
107 #define CLINE (copline = (curcop->cop_line < copline ? curcop->cop_line : copline))
109 #define TOKEN(retval) return (bufptr = s,(int)retval)
110 #define OPERATOR(retval) return (expect = XTERM,bufptr = s,(int)retval)
111 #define AOPERATOR(retval) return ao((expect = XTERM,bufptr = s,(int)retval))
112 #define PREBLOCK(retval) return (expect = XBLOCK,bufptr = s,(int)retval)
113 #define PRETERMBLOCK(retval) return (expect = XTERMBLOCK,bufptr = s,(int)retval)
114 #define PREREF(retval) return (expect = XREF,bufptr = s,(int)retval)
115 #define TERM(retval) return (CLINE, expect = XOPERATOR,bufptr = s,(int)retval)
116 #define LOOPX(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)LOOPEX)
117 #define FTST(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)UNIOP)
118 #define FUN0(f) return(yylval.ival = f,expect = XOPERATOR,bufptr = s,(int)FUNC0)
119 #define FUN1(f) return(yylval.ival = f,expect = XOPERATOR,bufptr = s,(int)FUNC1)
120 #define BOop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)BITOROP))
121 #define BAop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)BITANDOP))
122 #define SHop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)SHIFTOP))
123 #define PWop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)POWOP))
124 #define PMop(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)MATCHOP)
125 #define Aop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)ADDOP))
126 #define Mop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)MULOP))
127 #define Eop(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)EQOP)
128 #define Rop(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)RELOP)
130 /* This bit of chicanery makes a unary function followed by
131 * a parenthesis into a function with one argument, highest precedence.
133 #define UNI(f) return(yylval.ival = f, \
136 last_uni = oldbufptr, \
138 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
140 #define UNIBRACK(f) return(yylval.ival = f, \
142 last_uni = oldbufptr, \
143 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
145 /* grandfather return to old style */
146 #define OLDLOP(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)LSTOP)
149 static void RestoreRsfp(void *pPerl, void *ptr)
151 ((CPerlObj*)pPerl)->restore_rsfp(ptr);
153 #define RESTORERSFP RestoreRsfp
155 #define RESTORERSFP restore_rsfp
161 if (*bufptr == '=') {
163 if (toketype == ANDAND)
164 yylval.ival = OP_ANDASSIGN;
165 else if (toketype == OROR)
166 yylval.ival = OP_ORASSIGN;
173 no_op(char *what, char *s)
175 char *oldbp = bufptr;
176 bool is_first = (oldbufptr == linestart);
179 yywarn(form("%s found where operator expected", what));
181 warn("\t(Missing semicolon on previous line?)\n");
182 else if (oldoldbufptr && isIDFIRST(*oldoldbufptr)) {
184 for (t = oldoldbufptr; *t && (isALNUM(*t) || *t == ':'); t++) ;
185 if (t < bufptr && isSPACE(*t))
186 warn("\t(Do you need to predeclare %.*s?)\n",
187 t - oldoldbufptr, oldoldbufptr);
191 warn("\t(Missing operator before %.*s?)\n", s - oldbp, oldbp);
201 char *nl = strrchr(s,'\n');
205 else if (multi_close < 32 || multi_close == 127) {
207 tmpbuf[1] = toCTRL(multi_close);
213 *tmpbuf = multi_close;
217 q = strchr(s,'"') ? '\'' : '"';
218 croak("Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
225 warn("Use of %s is deprecated", s);
231 deprecate("comma-less variable list");
237 win32_textfilter(int idx, SV *sv, int maxlen)
239 I32 count = FILTER_READ(idx+1, sv, maxlen);
240 if (count > 0 && !maxlen)
241 win32_strip_return(sv);
255 SAVEI32(lex_brackets);
256 SAVEI32(lex_fakebrack);
257 SAVEI32(lex_casemods);
262 SAVEI16(curcop->cop_line);
266 SAVEPPTR(oldoldbufptr);
269 SAVEPPTR(lex_brackstack);
270 SAVEPPTR(lex_casestack);
271 SAVEDESTRUCTOR(RESTORERSFP, rsfp);
273 lex_state = LEX_NORMAL;
278 New(899, lex_brackstack, 120, char);
279 New(899, lex_casestack, 12, char);
280 SAVEFREEPV(lex_brackstack);
281 SAVEFREEPV(lex_casestack);
283 *lex_casestack = '\0';
287 SvREFCNT_dec(lex_stuff);
290 SvREFCNT_dec(lex_repl);
295 if (SvREADONLY(linestr))
296 linestr = sv_2mortal(newSVsv(linestr));
297 s = SvPV(linestr, len);
298 if (len && s[len-1] != ';') {
299 if (!(SvFLAGS(linestr) & SVs_TEMP))
300 linestr = sv_2mortal(newSVsv(linestr));
301 sv_catpvn(linestr, "\n;", 2);
304 oldoldbufptr = oldbufptr = bufptr = linestart = SvPVX(linestr);
305 bufend = bufptr + SvCUR(linestr);
307 rs = newSVpv("\n", 1);
318 restore_rsfp(void *f)
320 PerlIO *fp = (PerlIO*)f;
322 if (rsfp == PerlIO_stdin())
323 PerlIO_clearerr(rsfp);
324 else if (rsfp && (rsfp != fp))
341 while (*s == ' ' || *s == '\t') s++;
342 if (strnEQ(s, "line ", 5)) {
351 while (*s == ' ' || *s == '\t')
353 if (*s == '"' && (t = strchr(s+1, '"')))
357 return; /* false alarm */
358 for (t = s; !isSPACE(*t); t++) ;
363 curcop->cop_filegv = gv_fetchfile(s);
365 curcop->cop_filegv = gv_fetchfile(origfilename);
367 curcop->cop_line = atoi(n)-1;
371 skipspace(register char *s)
374 if (lex_formbrack && lex_brackets <= lex_formbrack) {
375 while (s < bufend && (*s == ' ' || *s == '\t'))
381 while (s < bufend && isSPACE(*s))
383 if (s < bufend && *s == '#') {
384 while (s < bufend && *s != '\n')
389 if (s < bufend || !rsfp || lex_state != LEX_NORMAL)
391 if ((s = filter_gets(linestr, rsfp, (prevlen = SvCUR(linestr)))) == Nullch) {
392 if (minus_n || minus_p) {
393 sv_setpv(linestr,minus_p ?
394 ";}continue{print or die qq(-p destination: $!\\n)" :
396 sv_catpv(linestr,";}");
397 minus_n = minus_p = 0;
400 sv_setpv(linestr,";");
401 oldoldbufptr = oldbufptr = bufptr = s = linestart = SvPVX(linestr);
402 bufend = SvPVX(linestr) + SvCUR(linestr);
403 if (preprocess && !in_eval)
404 (void)PerlProc_pclose(rsfp);
405 else if ((PerlIO*)rsfp == PerlIO_stdin())
406 PerlIO_clearerr(rsfp);
408 (void)PerlIO_close(rsfp);
414 linestart = bufptr = s + prevlen;
415 bufend = s + SvCUR(linestr);
418 if (PERLDB_LINE && curstash != debstash) {
419 SV *sv = NEWSV(85,0);
421 sv_upgrade(sv, SVt_PVMG);
422 sv_setpvn(sv,bufptr,bufend-bufptr);
423 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
434 if (oldoldbufptr != last_uni)
436 while (isSPACE(*last_uni))
438 for (s = last_uni; isALNUM(*s) || *s == '-'; s++) ;
439 if ((t = strchr(s, '(')) && t < bufptr)
443 warn("Warning: Use of \"%s\" without parens is ambiguous", last_uni);
450 #define UNI(f) return uni(f,s)
458 last_uni = oldbufptr;
469 #endif /* CRIPPLED_CC */
471 #define LOP(f,x) return lop(f,x,s)
476 (I32 f, expectation x, char *s)
482 #endif /* CAN_PROTOTYPE */
489 last_lop = oldbufptr;
505 nexttype[nexttoke] = type;
507 if (lex_state != LEX_KNOWNEXT) {
508 lex_defer = lex_state;
510 lex_state = LEX_KNOWNEXT;
515 force_word(register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
520 start = skipspace(start);
523 (allow_pack && *s == ':') ||
524 (allow_initial_tick && *s == '\'') )
526 s = scan_word(s, tokenbuf, sizeof tokenbuf, allow_pack, &len);
527 if (check_keyword && keyword(tokenbuf, len))
529 if (token == METHOD) {
539 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST,0, newSVpv(tokenbuf,0));
540 nextval[nexttoke].opval->op_private |= OPpCONST_BARE;
547 force_ident(register char *s, int kind)
550 OP* o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
551 nextval[nexttoke].opval = o;
554 dTHR; /* just for in_eval */
555 o->op_private = OPpCONST_ENTERED;
556 /* XXX see note in pp_entereval() for why we forgo typo
557 warnings if the symbol must be introduced in an eval.
559 gv_fetchpv(s, in_eval ? GV_ADDMULTI : TRUE,
560 kind == '$' ? SVt_PV :
561 kind == '@' ? SVt_PVAV :
562 kind == '%' ? SVt_PVHV :
570 force_version(char *s)
572 OP *version = Nullop;
576 /* default VERSION number -- GBARR */
581 for( d=s, c = 1; isDIGIT(*d) || *d == '_' || (*d == '.' && c--); d++);
582 if((*d == ';' || isSPACE(*d)) && *(skipspace(d)) != ',') {
584 /* real VERSION number -- GBARR */
585 version = yylval.opval;
589 /* NOTE: The parser sees the package name and the VERSION swapped */
590 nextval[nexttoke].opval = version;
607 s = SvPV_force(sv, len);
611 while (s < send && *s != '\\')
618 if (s + 1 < send && (s[1] == '\\'))
619 s++; /* all that, just for this */
624 SvCUR_set(sv, d - SvPVX(sv));
632 register I32 op_type = yylval.ival;
634 if (op_type == OP_NULL) {
635 yylval.opval = lex_op;
639 if (op_type == OP_CONST || op_type == OP_READLINE) {
640 SV *sv = tokeq(lex_stuff);
642 char *p = SvPV(sv, len);
643 yylval.opval = (OP*)newSVOP(op_type, 0, newSVpv(p, len));
649 sublex_info.super_state = lex_state;
650 sublex_info.sub_inwhat = op_type;
651 sublex_info.sub_op = lex_op;
652 lex_state = LEX_INTERPPUSH;
656 yylval.opval = lex_op;
670 lex_state = sublex_info.super_state;
672 SAVEI32(lex_brackets);
673 SAVEI32(lex_fakebrack);
674 SAVEI32(lex_casemods);
679 SAVEI16(curcop->cop_line);
682 SAVEPPTR(oldoldbufptr);
685 SAVEPPTR(lex_brackstack);
686 SAVEPPTR(lex_casestack);
691 bufend = bufptr = oldbufptr = oldoldbufptr = linestart = SvPVX(linestr);
692 bufend += SvCUR(linestr);
698 New(899, lex_brackstack, 120, char);
699 New(899, lex_casestack, 12, char);
700 SAVEFREEPV(lex_brackstack);
701 SAVEFREEPV(lex_casestack);
703 *lex_casestack = '\0';
705 lex_state = LEX_INTERPCONCAT;
706 curcop->cop_line = multi_start;
708 lex_inwhat = sublex_info.sub_inwhat;
709 if (lex_inwhat == OP_MATCH || lex_inwhat == OP_SUBST)
710 lex_inpat = sublex_info.sub_op;
722 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv("",0));
726 if (lex_casemods) { /* oops, we've got some unbalanced parens */
727 lex_state = LEX_INTERPCASEMOD;
731 /* Is there a right-hand side to take care of? */
732 if (lex_repl && (lex_inwhat == OP_SUBST || lex_inwhat == OP_TRANS)) {
735 bufend = bufptr = oldbufptr = oldoldbufptr = linestart = SvPVX(linestr);
736 bufend += SvCUR(linestr);
742 *lex_casestack = '\0';
744 if (SvCOMPILED(lex_repl)) {
745 lex_state = LEX_INTERPNORMAL;
749 lex_state = LEX_INTERPCONCAT;
755 bufend = SvPVX(linestr);
756 bufend += SvCUR(linestr);
763 scan_const(char *start)
765 register char *send = bufend;
766 SV *sv = NEWSV(93, send - start);
767 register char *s = start;
768 register char *d = SvPVX(sv);
769 bool dorange = FALSE;
773 ? "\\.^$@AGZdDwWsSbB+*?|()-nrtfeaxc0123456789[{]} \t\n\r\f\v#"
774 : (lex_inwhat & OP_TRANS)
778 while (s < send || dorange) {
779 if (lex_inwhat == OP_TRANS) {
784 SvGROW(sv, SvLEN(sv) + 256);
788 for (i = (U8)*d; i <= max; i++)
793 else if (*s == '-' && s+1 < send && s != start) {
798 else if (*s == '(' && lex_inpat && s[1] == '?' && s[2] == '#') {
799 while (s < send && *s != ')')
802 else if (*s == '#' && lex_inpat &&
803 ((PMOP*)lex_inpat)->op_pmflags & PMf_EXTENDED) {
804 while (s+1 < send && *s != '\n')
807 else if (*s == '@' && s[1] && (isALNUM(s[1]) || strchr(":'{$", s[1])))
809 else if (*s == '$') {
810 if (!lex_inpat) /* not a regexp, so $ must be var */
812 if (s + 1 < send && !strchr("()| \n\t", s[1]))
813 break; /* in regexp, $ might be tail anchor */
815 if (*s == '\\' && s+1 < send) {
817 if (*s && strchr(leaveit, *s)) {
822 if (lex_inwhat == OP_SUBST && !lex_inpat &&
823 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
826 warn("\\%c better written as $%c", *s, *s);
830 if (lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
836 if (lex_inwhat == OP_TRANS) {
844 case '0': case '1': case '2': case '3':
845 case '4': case '5': case '6': case '7':
846 *d++ = scan_oct(s, 3, &len);
850 *d++ = scan_hex(++s, 2, &len);
886 SvCUR_set(sv, d - SvPVX(sv));
889 if (SvCUR(sv) + 5 < SvLEN(sv)) {
890 SvLEN_set(sv, SvCUR(sv) + 1);
891 Renew(SvPVX(sv), SvLEN(sv), char);
894 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
900 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
902 intuit_more(register char *s)
906 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
908 if (*s != '{' && *s != '[')
913 /* In a pattern, so maybe we have {n,m}. */
930 /* On the other hand, maybe we have a character class */
933 if (*s == ']' || *s == '^')
936 int weight = 2; /* let's weigh the evidence */
938 unsigned char un_char = 0, last_un_char;
939 char *send = strchr(s,']');
940 char tmpbuf[sizeof tokenbuf * 4];
942 if (!send) /* has to be an expression */
948 else if (isDIGIT(*s)) {
950 if (isDIGIT(s[1]) && s[2] == ']')
956 for (; s < send; s++) {
957 last_un_char = un_char;
958 un_char = (unsigned char)*s;
963 weight -= seen[un_char] * 10;
965 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
966 if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV))
971 else if (*s == '$' && s[1] &&
972 strchr("[#!%*<>()-=",s[1])) {
973 if (/*{*/ strchr("])} =",s[2]))
982 if (strchr("wds]",s[1]))
984 else if (seen['\''] || seen['"'])
986 else if (strchr("rnftbxcav",s[1]))
988 else if (isDIGIT(s[1])) {
990 while (s[1] && isDIGIT(s[1]))
1000 if (strchr("aA01! ",last_un_char))
1002 if (strchr("zZ79~",s[1]))
1006 if (!isALNUM(last_un_char) && !strchr("$@&",last_un_char) &&
1007 isALPHA(*s) && s[1] && isALPHA(s[1])) {
1012 if (keyword(tmpbuf, d - tmpbuf))
1015 if (un_char == last_un_char + 1)
1017 weight -= seen[un_char];
1022 if (weight >= 0) /* probably a character class */
1030 intuit_method(char *start, GV *gv)
1032 char *s = start + (*start == '$');
1033 char tmpbuf[sizeof tokenbuf];
1043 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
1044 if (*start == '$') {
1045 if (gv || last_lop_op == OP_PRINT || isUPPER(*tokenbuf))
1050 return *s == '(' ? FUNCMETH : METHOD;
1052 if (!keyword(tmpbuf, len)) {
1053 indirgv = gv_fetchpv(tmpbuf,FALSE, SVt_PVCV);
1054 if (indirgv && GvCVu(indirgv))
1056 /* filehandle or package name makes it a method */
1057 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
1059 if ((bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
1060 return 0; /* no assumptions -- "=>" quotes bearword */
1061 nextval[nexttoke].opval =
1062 (OP*)newSVOP(OP_CONST, 0,
1064 nextval[nexttoke].opval->op_private =
1069 return *s == '(' ? FUNCMETH : METHOD;
1079 char *pdb = PerlEnv_getenv("PERL5DB");
1083 SETERRNO(0,SS$_NORMAL);
1084 return "BEGIN { require 'perl5db.pl' }";
1090 /* Encoded script support. filter_add() effectively inserts a
1091 * 'pre-processing' function into the current source input stream.
1092 * Note that the filter function only applies to the current source file
1093 * (e.g., it will not affect files 'require'd or 'use'd by this one).
1095 * The datasv parameter (which may be NULL) can be used to pass
1096 * private data to this instance of the filter. The filter function
1097 * can recover the SV using the FILTER_DATA macro and use it to
1098 * store private buffers and state information.
1100 * The supplied datasv parameter is upgraded to a PVIO type
1101 * and the IoDIRP field is used to store the function pointer.
1102 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
1103 * private use must be set using malloc'd pointers.
1105 static int filter_debug = 0;
1108 filter_add(filter_t funcp, SV *datasv)
1110 if (!funcp){ /* temporary handy debugging hack to be deleted */
1111 filter_debug = atoi((char*)datasv);
1115 rsfp_filters = newAV();
1118 if (!SvUPGRADE(datasv, SVt_PVIO))
1119 die("Can't upgrade filter_add data to SVt_PVIO");
1120 IoDIRP(datasv) = (DIR*)funcp; /* stash funcp into spare field */
1122 warn("filter_add func %p (%s)", funcp, SvPV(datasv,na));
1123 av_unshift(rsfp_filters, 1);
1124 av_store(rsfp_filters, 0, datasv) ;
1129 /* Delete most recently added instance of this filter function. */
1131 filter_del(filter_t funcp)
1134 warn("filter_del func %p", funcp);
1135 if (!rsfp_filters || AvFILL(rsfp_filters)<0)
1137 /* if filter is on top of stack (usual case) just pop it off */
1138 if (IoDIRP(FILTER_DATA(AvFILL(rsfp_filters))) == (void*)funcp){
1139 sv_free(av_pop(rsfp_filters));
1143 /* we need to search for the correct entry and clear it */
1144 die("filter_del can only delete in reverse order (currently)");
1148 /* Invoke the n'th filter function for the current rsfp. */
1150 filter_read(int idx, SV *buf_sv, int maxlen)
1153 /* 0 = read one text line */
1160 if (idx > AvFILL(rsfp_filters)){ /* Any more filters? */
1161 /* Provide a default input filter to make life easy. */
1162 /* Note that we append to the line. This is handy. */
1164 warn("filter_read %d: from rsfp\n", idx);
1168 int old_len = SvCUR(buf_sv) ;
1170 /* ensure buf_sv is large enough */
1171 SvGROW(buf_sv, old_len + maxlen) ;
1172 if ((len = PerlIO_read(rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
1173 if (PerlIO_error(rsfp))
1174 return -1; /* error */
1176 return 0 ; /* end of file */
1178 SvCUR_set(buf_sv, old_len + len) ;
1181 if (sv_gets(buf_sv, rsfp, SvCUR(buf_sv)) == NULL) {
1182 if (PerlIO_error(rsfp))
1183 return -1; /* error */
1185 return 0 ; /* end of file */
1189 return SvCUR(buf_sv);
1191 /* Skip this filter slot if filter has been deleted */
1192 if ( (datasv = FILTER_DATA(idx)) == &sv_undef){
1194 warn("filter_read %d: skipped (filter deleted)\n", idx);
1195 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
1197 /* Get function pointer hidden within datasv */
1198 funcp = (filter_t)IoDIRP(datasv);
1200 warn("filter_read %d: via function %p (%s)\n",
1201 idx, funcp, SvPV(datasv,na));
1202 /* Call function. The function is expected to */
1203 /* call "FILTER_READ(idx+1, buf_sv)" first. */
1204 /* Return: <0:error, =0:eof, >0:not eof */
1205 return (*funcp)(idx, buf_sv, maxlen);
1210 filter_gets(register SV *sv, register PerlIO *fp, STRLEN append)
1213 if (!rsfp_filters) {
1214 filter_add(win32_textfilter,NULL);
1220 SvCUR_set(sv, 0); /* start with empty line */
1221 if (FILTER_READ(0, sv, 0) > 0)
1222 return ( SvPVX(sv) ) ;
1227 return (sv_gets(sv, fp, append));
1232 static char* exp_name[] =
1233 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "TERMBLOCK" };
1236 EXT int yychar; /* last token */
1249 if (pending_ident) {
1250 char pit = pending_ident;
1254 if (strchr(tokenbuf,':'))
1255 croak(no_myglob,tokenbuf);
1256 yylval.opval = newOP(OP_PADANY, 0);
1257 yylval.opval->op_targ = pad_allocmy(tokenbuf);
1261 if (!strchr(tokenbuf,':')) {
1263 /* Check for single character per-thread SVs */
1264 if (tokenbuf[0] == '$' && tokenbuf[2] == '\0'
1265 && !isALPHA(tokenbuf[1]) /* Rule out obvious non-threadsvs */
1266 && (tmp = find_threadsv(&tokenbuf[1])) != NOT_IN_PAD)
1268 yylval.opval = newOP(OP_THREADSV, 0);
1269 yylval.opval->op_targ = tmp;
1272 #endif /* USE_THREADS */
1273 if ((tmp = pad_findmy(tokenbuf)) != NOT_IN_PAD) {
1274 if (last_lop_op == OP_SORT &&
1275 tokenbuf[0] == '$' &&
1276 (tokenbuf[1] == 'a' || tokenbuf[1] == 'b')
1279 for (d = in_eval ? oldoldbufptr : linestart;
1280 d < bufend && *d != '\n';
1283 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
1284 croak("Can't use \"my %s\" in sort comparison",
1290 yylval.opval = newOP(OP_PADANY, 0);
1291 yylval.opval->op_targ = tmp;
1296 /* Force them to make up their mind on "@foo". */
1297 if (pit == '@' && lex_state != LEX_NORMAL && !lex_brackets) {
1298 GV *gv = gv_fetchpv(tokenbuf+1, FALSE, SVt_PVAV);
1299 if (!gv || ((tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
1300 yyerror(form("In string, %s now must be written as \\%s",
1301 tokenbuf, tokenbuf));
1304 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf+1, 0));
1305 yylval.opval->op_private = OPpCONST_ENTERED;
1306 gv_fetchpv(tokenbuf+1, in_eval ? GV_ADDMULTI : TRUE,
1307 ((tokenbuf[0] == '$') ? SVt_PV
1308 : (tokenbuf[0] == '@') ? SVt_PVAV
1313 switch (lex_state) {
1315 case LEX_NORMAL: /* Some compilers will produce faster */
1316 case LEX_INTERPNORMAL: /* code if we comment these out. */
1322 yylval = nextval[nexttoke];
1324 lex_state = lex_defer;
1325 expect = lex_expect;
1326 lex_defer = LEX_NORMAL;
1328 return(nexttype[nexttoke]);
1330 case LEX_INTERPCASEMOD:
1332 if (bufptr != bufend && *bufptr != '\\')
1333 croak("panic: INTERPCASEMOD");
1335 if (bufptr == bufend || bufptr[1] == 'E') {
1338 oldmod = lex_casestack[--lex_casemods];
1339 lex_casestack[lex_casemods] = '\0';
1340 if (bufptr != bufend && strchr("LUQ", oldmod)) {
1342 lex_state = LEX_INTERPCONCAT;
1346 if (bufptr != bufend)
1348 lex_state = LEX_INTERPCONCAT;
1353 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
1354 tmp = *s, *s = s[2], s[2] = tmp; /* misordered... */
1355 if (strchr("LU", *s) &&
1356 (strchr(lex_casestack, 'L') || strchr(lex_casestack, 'U')))
1358 lex_casestack[--lex_casemods] = '\0';
1361 if (lex_casemods > 10) {
1362 char* newlb = Renew(lex_casestack, lex_casemods + 2, char);
1363 if (newlb != lex_casestack) {
1365 lex_casestack = newlb;
1368 lex_casestack[lex_casemods++] = *s;
1369 lex_casestack[lex_casemods] = '\0';
1370 lex_state = LEX_INTERPCONCAT;
1371 nextval[nexttoke].ival = 0;
1374 nextval[nexttoke].ival = OP_LCFIRST;
1376 nextval[nexttoke].ival = OP_UCFIRST;
1378 nextval[nexttoke].ival = OP_LC;
1380 nextval[nexttoke].ival = OP_UC;
1382 nextval[nexttoke].ival = OP_QUOTEMETA;
1384 croak("panic: yylex");
1396 case LEX_INTERPPUSH:
1397 return sublex_push();
1399 case LEX_INTERPSTART:
1400 if (bufptr == bufend)
1401 return sublex_done();
1403 lex_dojoin = (*bufptr == '@');
1404 lex_state = LEX_INTERPNORMAL;
1406 nextval[nexttoke].ival = 0;
1409 nextval[nexttoke].opval = newOP(OP_THREADSV, 0);
1410 nextval[nexttoke].opval->op_targ = find_threadsv("\"");
1411 force_next(PRIVATEREF);
1413 force_ident("\"", '$');
1414 #endif /* USE_THREADS */
1415 nextval[nexttoke].ival = 0;
1417 nextval[nexttoke].ival = 0;
1419 nextval[nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
1428 case LEX_INTERPENDMAYBE:
1429 if (intuit_more(bufptr)) {
1430 lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
1438 lex_state = LEX_INTERPCONCAT;
1442 case LEX_INTERPCONCAT:
1445 croak("panic: INTERPCONCAT");
1447 if (bufptr == bufend)
1448 return sublex_done();
1450 if (SvIVX(linestr) == '\'') {
1451 SV *sv = newSVsv(linestr);
1454 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1458 s = scan_const(bufptr);
1460 lex_state = LEX_INTERPCASEMOD;
1462 lex_state = LEX_INTERPSTART;
1466 nextval[nexttoke] = yylval;
1479 lex_state = LEX_NORMAL;
1480 s = scan_formline(bufptr);
1487 oldoldbufptr = oldbufptr;
1490 PerlIO_printf(PerlIO_stderr(), "### Tokener expecting %s at %s\n", exp_name[expect], s);
1496 croak("Unrecognized character \\%03o", *s & 255);
1499 goto fake_eof; /* emulate EOF on ^D or ^Z */
1505 yyerror("Missing right bracket");
1509 goto retry; /* ignore stray nulls */
1512 if (!in_eval && !preambled) {
1514 sv_setpv(linestr,incl_perldb());
1516 sv_catpv(linestr,";");
1518 while(AvFILL(preambleav) >= 0) {
1519 SV *tmpsv = av_shift(preambleav);
1520 sv_catsv(linestr, tmpsv);
1521 sv_catpv(linestr, ";");
1524 sv_free((SV*)preambleav);
1527 if (minus_n || minus_p) {
1528 sv_catpv(linestr, "LINE: while (<>) {");
1530 sv_catpv(linestr,"chomp;");
1532 GV* gv = gv_fetchpv("::F", TRUE, SVt_PVAV);
1534 GvIMPORTED_AV_on(gv);
1536 if (strchr("/'\"", *splitstr)
1537 && strchr(splitstr + 1, *splitstr))
1538 sv_catpvf(linestr, "@F=split(%s);", splitstr);
1541 s = "'~#\200\1'"; /* surely one char is unused...*/
1542 while (s[1] && strchr(splitstr, *s)) s++;
1544 sv_catpvf(linestr, "@F=split(%s%c",
1545 "q" + (delim == '\''), delim);
1546 for (s = splitstr; *s; s++) {
1548 sv_catpvn(linestr, "\\", 1);
1549 sv_catpvn(linestr, s, 1);
1551 sv_catpvf(linestr, "%c);", delim);
1555 sv_catpv(linestr,"@F=split(' ');");
1558 sv_catpv(linestr, "\n");
1559 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
1560 bufend = SvPVX(linestr) + SvCUR(linestr);
1561 if (PERLDB_LINE && curstash != debstash) {
1562 SV *sv = NEWSV(85,0);
1564 sv_upgrade(sv, SVt_PVMG);
1565 sv_setsv(sv,linestr);
1566 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
1571 if ((s = filter_gets(linestr, rsfp, 0)) == Nullch) {
1574 if (preprocess && !in_eval)
1575 (void)PerlProc_pclose(rsfp);
1576 else if ((PerlIO *)rsfp == PerlIO_stdin())
1577 PerlIO_clearerr(rsfp);
1579 (void)PerlIO_close(rsfp);
1584 if (!in_eval && (minus_n || minus_p)) {
1585 sv_setpv(linestr,minus_p ? ";}continue{print" : "");
1586 sv_catpv(linestr,";}");
1587 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
1588 bufend = SvPVX(linestr) + SvCUR(linestr);
1589 minus_n = minus_p = 0;
1592 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
1593 sv_setpv(linestr,"");
1594 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
1597 if (*s == '#' && s[1] == '!' && instr(s,"perl"))
1600 /* Incest with pod. */
1601 if (*s == '=' && strnEQ(s, "=cut", 4)) {
1602 sv_setpv(linestr, "");
1603 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
1604 bufend = SvPVX(linestr) + SvCUR(linestr);
1609 } while (doextract);
1610 oldoldbufptr = oldbufptr = bufptr = linestart = s;
1611 if (PERLDB_LINE && curstash != debstash) {
1612 SV *sv = NEWSV(85,0);
1614 sv_upgrade(sv, SVt_PVMG);
1615 sv_setsv(sv,linestr);
1616 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
1618 bufend = SvPVX(linestr) + SvCUR(linestr);
1619 if (curcop->cop_line == 1) {
1620 while (s < bufend && isSPACE(*s))
1622 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
1626 if (*s == '#' && *(s+1) == '!')
1628 #ifdef ALTERNATE_SHEBANG
1630 static char as[] = ALTERNATE_SHEBANG;
1631 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
1632 d = s + (sizeof(as) - 1);
1634 #endif /* ALTERNATE_SHEBANG */
1643 while (*d && !isSPACE(*d))
1647 #ifdef ARG_ZERO_IS_SCRIPT
1648 if (ipathend > ipath) {
1650 * HP-UX (at least) sets argv[0] to the script name,
1651 * which makes $^X incorrect. And Digital UNIX and Linux,
1652 * at least, set argv[0] to the basename of the Perl
1653 * interpreter. So, having found "#!", we'll set it right.
1655 SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV));
1656 assert(SvPOK(x) || SvGMAGICAL(x));
1657 if (sv_eq(x, GvSV(curcop->cop_filegv))) {
1658 sv_setpvn(x, ipath, ipathend - ipath);
1661 TAINT_NOT; /* $^X is always tainted, but that's OK */
1663 #endif /* ARG_ZERO_IS_SCRIPT */
1668 d = instr(s,"perl -");
1670 d = instr(s,"perl");
1671 #ifdef ALTERNATE_SHEBANG
1673 * If the ALTERNATE_SHEBANG on this system starts with a
1674 * character that can be part of a Perl expression, then if
1675 * we see it but not "perl", we're probably looking at the
1676 * start of Perl code, not a request to hand off to some
1677 * other interpreter. Similarly, if "perl" is there, but
1678 * not in the first 'word' of the line, we assume the line
1679 * contains the start of the Perl program.
1681 if (d && *s != '#') {
1683 while (*c && !strchr("; \t\r\n\f\v#", *c))
1686 d = Nullch; /* "perl" not in first word; ignore */
1688 *s = '#'; /* Don't try to parse shebang line */
1690 #endif /* ALTERNATE_SHEBANG */
1695 !instr(s,"indir") &&
1696 instr(origargv[0],"perl"))
1702 while (s < bufend && isSPACE(*s))
1705 Newz(899,newargv,origargc+3,char*);
1707 while (s < bufend && !isSPACE(*s))
1710 Copy(origargv+1, newargv+2, origargc+1, char*);
1715 execv(ipath, newargv);
1716 croak("Can't exec %s", ipath);
1719 U32 oldpdb = perldb;
1720 bool oldn = minus_n;
1721 bool oldp = minus_p;
1723 while (*d && !isSPACE(*d)) d++;
1724 while (*d == ' ' || *d == '\t') d++;
1728 if (*d == 'M' || *d == 'm') {
1730 while (*d && !isSPACE(*d)) d++;
1731 croak("Too late for \"-%.*s\" option",
1734 d = moreswitches(d);
1736 if (PERLDB_LINE && !oldpdb ||
1737 ( minus_n || minus_p ) && !(oldn || oldp) )
1738 /* if we have already added "LINE: while (<>) {",
1739 we must not do it again */
1741 sv_setpv(linestr, "");
1742 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
1743 bufend = SvPVX(linestr) + SvCUR(linestr);
1746 (void)gv_fetchfile(origfilename);
1753 if (lex_formbrack && lex_brackets <= lex_formbrack) {
1755 lex_state = LEX_FORMLINE;
1761 warn("Illegal character \\%03o (carriage return)", '\r');
1763 "(Maybe you didn't strip carriage returns after a network transfer?)\n");
1765 case ' ': case '\t': case '\f': case 013:
1770 if (lex_state != LEX_NORMAL || (in_eval && !rsfp)) {
1772 while (s < d && *s != '\n')
1777 if (lex_formbrack && lex_brackets <= lex_formbrack) {
1779 lex_state = LEX_FORMLINE;
1789 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
1794 while (s < bufend && (*s == ' ' || *s == '\t'))
1797 if (strnEQ(s,"=>",2)) {
1799 warn("Ambiguous use of -%c => resolved to \"-%c\" =>",
1800 (int)tmp, (int)tmp);
1801 s = force_word(bufptr,WORD,FALSE,FALSE,FALSE);
1802 OPERATOR('-'); /* unary minus */
1804 last_uni = oldbufptr;
1805 last_lop_op = OP_FTEREAD; /* good enough */
1807 case 'r': FTST(OP_FTEREAD);
1808 case 'w': FTST(OP_FTEWRITE);
1809 case 'x': FTST(OP_FTEEXEC);
1810 case 'o': FTST(OP_FTEOWNED);
1811 case 'R': FTST(OP_FTRREAD);
1812 case 'W': FTST(OP_FTRWRITE);
1813 case 'X': FTST(OP_FTREXEC);
1814 case 'O': FTST(OP_FTROWNED);
1815 case 'e': FTST(OP_FTIS);
1816 case 'z': FTST(OP_FTZERO);
1817 case 's': FTST(OP_FTSIZE);
1818 case 'f': FTST(OP_FTFILE);
1819 case 'd': FTST(OP_FTDIR);
1820 case 'l': FTST(OP_FTLINK);
1821 case 'p': FTST(OP_FTPIPE);
1822 case 'S': FTST(OP_FTSOCK);
1823 case 'u': FTST(OP_FTSUID);
1824 case 'g': FTST(OP_FTSGID);
1825 case 'k': FTST(OP_FTSVTX);
1826 case 'b': FTST(OP_FTBLK);
1827 case 'c': FTST(OP_FTCHR);
1828 case 't': FTST(OP_FTTTY);
1829 case 'T': FTST(OP_FTTEXT);
1830 case 'B': FTST(OP_FTBINARY);
1831 case 'M': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTMTIME);
1832 case 'A': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTATIME);
1833 case 'C': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTCTIME);
1835 croak("Unrecognized file test: -%c", (int)tmp);
1842 if (expect == XOPERATOR)
1847 else if (*s == '>') {
1850 if (isIDFIRST(*s)) {
1851 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
1859 if (expect == XOPERATOR)
1862 if (isSPACE(*s) || !isSPACE(*bufptr))
1864 OPERATOR('-'); /* unary minus */
1871 if (expect == XOPERATOR)
1876 if (expect == XOPERATOR)
1879 if (isSPACE(*s) || !isSPACE(*bufptr))
1885 if (expect != XOPERATOR) {
1886 s = scan_ident(s, bufend, tokenbuf, sizeof tokenbuf, TRUE);
1888 force_ident(tokenbuf, '*');
1901 if (expect == XOPERATOR) {
1906 s = scan_ident(s, bufend, tokenbuf + 1, sizeof tokenbuf - 1, TRUE);
1909 yyerror("Final % should be \\% or %name");
1912 pending_ident = '%';
1934 if (last_lop == oldoldbufptr || last_uni == oldoldbufptr)
1935 oldbufptr = oldoldbufptr; /* allow print(STDOUT 123) */
1940 if (curcop->cop_line < copline)
1941 copline = curcop->cop_line;
1952 if (lex_brackets <= 0)
1953 yyerror("Unmatched right bracket");
1956 if (lex_state == LEX_INTERPNORMAL) {
1957 if (lex_brackets == 0) {
1958 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
1959 lex_state = LEX_INTERPEND;
1966 if (lex_brackets > 100) {
1967 char* newlb = Renew(lex_brackstack, lex_brackets + 1, char);
1968 if (newlb != lex_brackstack) {
1970 lex_brackstack = newlb;
1975 if (lex_formbrack) {
1979 if (oldoldbufptr == last_lop)
1980 lex_brackstack[lex_brackets++] = XTERM;
1982 lex_brackstack[lex_brackets++] = XOPERATOR;
1983 OPERATOR(HASHBRACK);
1985 while (s < bufend && (*s == ' ' || *s == '\t'))
1989 if (d < bufend && *d == '-') {
1992 while (d < bufend && (*d == ' ' || *d == '\t'))
1995 if (d < bufend && isIDFIRST(*d)) {
1996 d = scan_word(d, tokenbuf + 1, sizeof tokenbuf - 1,
1998 while (d < bufend && (*d == ' ' || *d == '\t'))
2001 char minus = (tokenbuf[0] == '-');
2003 (keyword(tokenbuf + 1, len) ||
2004 (minus && len == 1 && isALPHA(tokenbuf[1])) ||
2005 perl_get_cv(tokenbuf + 1, FALSE) ))
2006 warn("Ambiguous use of {%s} resolved to {\"%s\"}",
2007 tokenbuf + !minus, tokenbuf + !minus);
2008 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
2015 lex_brackstack[lex_brackets++] = XSTATE;
2019 lex_brackstack[lex_brackets++] = XOPERATOR;
2024 if (oldoldbufptr == last_lop)
2025 lex_brackstack[lex_brackets++] = XTERM;
2027 lex_brackstack[lex_brackets++] = XOPERATOR;
2030 OPERATOR(HASHBRACK);
2031 /* This hack serves to disambiguate a pair of curlies
2032 * as being a block or an anon hash. Normally, expectation
2033 * determines that, but in cases where we're not in a
2034 * position to expect anything in particular (like inside
2035 * eval"") we have to resolve the ambiguity. This code
2036 * covers the case where the first term in the curlies is a
2037 * quoted string. Most other cases need to be explicitly
2038 * disambiguated by prepending a `+' before the opening
2039 * curly in order to force resolution as an anon hash.
2041 * XXX should probably propagate the outer expectation
2042 * into eval"" to rely less on this hack, but that could
2043 * potentially break current behavior of eval"".
2047 if (*s == '\'' || *s == '"' || *s == '`') {
2048 /* common case: get past first string, handling escapes */
2049 for (t++; t < bufend && *t != *s;)
2050 if (*t++ == '\\' && (*t == '\\' || *t == *s))
2054 else if (*s == 'q') {
2057 || ((*t == 'q' || *t == 'x') && ++t < bufend
2058 && !isALNUM(*t)))) {
2060 char open, close, term;
2063 while (t < bufend && isSPACE(*t))
2067 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
2071 for (t++; t < bufend; t++) {
2072 if (*t == '\\' && t+1 < bufend && open != '\\')
2074 else if (*t == open)
2078 for (t++; t < bufend; t++) {
2079 if (*t == '\\' && t+1 < bufend)
2081 else if (*t == close && --brackets <= 0)
2083 else if (*t == open)
2089 else if (isALPHA(*s)) {
2090 for (t++; t < bufend && isALNUM(*t); t++) ;
2092 while (t < bufend && isSPACE(*t))
2094 /* if comma follows first term, call it an anon hash */
2095 /* XXX it could be a comma expression with loop modifiers */
2096 if (t < bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
2097 || (*t == '=' && t[1] == '>')))
2098 OPERATOR(HASHBRACK);
2102 lex_brackstack[lex_brackets-1] = XSTATE;
2108 yylval.ival = curcop->cop_line;
2109 if (isSPACE(*s) || *s == '#')
2110 copline = NOLINE; /* invalidate current command line number */
2115 if (lex_brackets <= 0)
2116 yyerror("Unmatched right bracket");
2118 expect = (expectation)lex_brackstack[--lex_brackets];
2119 if (lex_brackets < lex_formbrack)
2121 if (lex_state == LEX_INTERPNORMAL) {
2122 if (lex_brackets == 0) {
2123 if (lex_fakebrack) {
2124 lex_state = LEX_INTERPEND;
2126 return yylex(); /* ignore fake brackets */
2128 if (*s == '-' && s[1] == '>')
2129 lex_state = LEX_INTERPENDMAYBE;
2130 else if (*s != '[' && *s != '{')
2131 lex_state = LEX_INTERPEND;
2134 if (lex_brackets < lex_fakebrack) {
2137 return yylex(); /* ignore fake brackets */
2147 if (expect == XOPERATOR) {
2148 if (dowarn && isALPHA(*s) && bufptr == linestart) {
2156 s = scan_ident(s - 1, bufend, tokenbuf, sizeof tokenbuf, TRUE);
2159 force_ident(tokenbuf, '&');
2163 yylval.ival = (OPpENTERSUB_AMPER<<8);
2182 if (dowarn && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
2183 warn("Reversed %c= operator",(int)tmp);
2185 if (expect == XSTATE && isALPHA(tmp) &&
2186 (s == linestart+1 || s[-2] == '\n') )
2188 if (in_eval && !rsfp) {
2193 if (strnEQ(s,"=cut",4)) {
2210 if (lex_brackets < lex_formbrack) {
2212 for (t = s; *t == ' ' || *t == '\t'; t++) ;
2213 if (*t == '\n' || *t == '#') {
2231 if (expect != XOPERATOR) {
2232 if (s[1] != '<' && !strchr(s,'>'))
2235 s = scan_heredoc(s);
2237 s = scan_inputsymbol(s);
2238 TERM(sublex_start());
2243 SHop(OP_LEFT_SHIFT);
2257 SHop(OP_RIGHT_SHIFT);
2266 if (expect == XOPERATOR) {
2267 if (lex_formbrack && lex_brackets == lex_formbrack) {
2270 return ','; /* grandfather non-comma-format format */
2274 if (s[1] == '#' && (isALPHA(s[2]) || strchr("_{$:", s[2]))) {
2275 if (expect == XOPERATOR)
2276 no_op("Array length", bufptr);
2278 s = scan_ident(s + 1, bufend, tokenbuf + 1, sizeof tokenbuf - 1,
2283 pending_ident = '#';
2287 if (expect == XOPERATOR)
2288 no_op("Scalar", bufptr);
2290 s = scan_ident(s, bufend, tokenbuf + 1, sizeof tokenbuf - 1, FALSE);
2293 yyerror("Final $ should be \\$ or $name");
2297 /* This kludge not intended to be bulletproof. */
2298 if (tokenbuf[1] == '[' && !tokenbuf[2]) {
2299 yylval.opval = newSVOP(OP_CONST, 0,
2300 newSViv((IV)compiling.cop_arybase));
2301 yylval.opval->op_private = OPpCONST_ARYBASE;
2306 if (lex_state == LEX_NORMAL)
2309 if ((expect != XREF || oldoldbufptr == last_lop) && intuit_more(s)) {
2315 isSPACE(*t) || isALNUM(*t) || *t == '$';
2318 bufptr = skipspace(bufptr);
2319 while (t < bufend && *t != ']')
2321 warn("Multidimensional syntax %.*s not supported",
2322 (t - bufptr) + 1, bufptr);
2326 else if (*s == '{') {
2328 if (dowarn && strEQ(tokenbuf+1, "SIG") &&
2329 (t = strchr(s, '}')) && (t = strchr(t, '=')))
2331 char tmpbuf[sizeof tokenbuf];
2333 for (t++; isSPACE(*t); t++) ;
2334 if (isIDFIRST(*t)) {
2335 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
2336 if (*t != '(' && perl_get_cv(tmpbuf, FALSE))
2337 warn("You need to quote \"%s\"", tmpbuf);
2344 if (lex_state == LEX_NORMAL && isSPACE(*d)) {
2345 bool islop = (last_lop == oldoldbufptr);
2346 if (!islop || last_lop_op == OP_GREPSTART)
2348 else if (strchr("$@\"'`q", *s))
2349 expect = XTERM; /* e.g. print $fh "foo" */
2350 else if (strchr("&*<%", *s) && isIDFIRST(s[1]))
2351 expect = XTERM; /* e.g. print $fh &sub */
2352 else if (isIDFIRST(*s)) {
2353 char tmpbuf[sizeof tokenbuf];
2354 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2355 if (tmp = keyword(tmpbuf, len)) {
2356 /* binary operators exclude handle interpretations */
2368 expect = XTERM; /* e.g. print $fh length() */
2373 GV *gv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
2374 if (gv && GvCVu(gv))
2375 expect = XTERM; /* e.g. print $fh subr() */
2378 else if (isDIGIT(*s))
2379 expect = XTERM; /* e.g. print $fh 3 */
2380 else if (*s == '.' && isDIGIT(s[1]))
2381 expect = XTERM; /* e.g. print $fh .3 */
2382 else if (strchr("/?-+", *s) && !isSPACE(s[1]))
2383 expect = XTERM; /* e.g. print $fh -1 */
2384 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]))
2385 expect = XTERM; /* print $fh <<"EOF" */
2387 pending_ident = '$';
2391 if (expect == XOPERATOR)
2394 s = scan_ident(s, bufend, tokenbuf + 1, sizeof tokenbuf - 1, FALSE);
2397 yyerror("Final @ should be \\@ or @name");
2400 if (lex_state == LEX_NORMAL)
2402 if ((expect != XREF || oldoldbufptr == last_lop) && intuit_more(s)) {
2406 /* Warn about @ where they meant $. */
2408 if (*s == '[' || *s == '{') {
2410 while (*t && (isALNUM(*t) || strchr(" \t$#+-'\"", *t)))
2412 if (*t == '}' || *t == ']') {
2414 bufptr = skipspace(bufptr);
2415 warn("Scalar value %.*s better written as $%.*s",
2416 t-bufptr, bufptr, t-bufptr-1, bufptr+1);
2421 pending_ident = '@';
2424 case '/': /* may either be division or pattern */
2425 case '?': /* may either be conditional or pattern */
2426 if (expect != XOPERATOR) {
2427 /* Disable warning on "study /blah/" */
2428 if (oldoldbufptr == last_uni
2429 && (*last_uni != 's' || s - last_uni < 5
2430 || memNE(last_uni, "study", 5) || isALNUM(last_uni[5])))
2433 TERM(sublex_start());
2441 if (lex_formbrack && lex_brackets == lex_formbrack && s[1] == '\n' &&
2442 (s == linestart || s[-1] == '\n') ) {
2447 if (expect == XOPERATOR || !isDIGIT(s[1])) {
2453 yylval.ival = OPf_SPECIAL;
2459 if (expect != XOPERATOR)
2464 case '0': case '1': case '2': case '3': case '4':
2465 case '5': case '6': case '7': case '8': case '9':
2467 if (expect == XOPERATOR)
2473 if (expect == XOPERATOR) {
2474 if (lex_formbrack && lex_brackets == lex_formbrack) {
2477 return ','; /* grandfather non-comma-format format */
2483 missingterm((char*)0);
2484 yylval.ival = OP_CONST;
2485 TERM(sublex_start());
2489 if (expect == XOPERATOR) {
2490 if (lex_formbrack && lex_brackets == lex_formbrack) {
2493 return ','; /* grandfather non-comma-format format */
2499 missingterm((char*)0);
2500 yylval.ival = OP_CONST;
2501 for (d = SvPV(lex_stuff, len); len; len--, d++) {
2502 if (*d == '$' || *d == '@' || *d == '\\') {
2503 yylval.ival = OP_STRINGIFY;
2507 TERM(sublex_start());
2511 if (expect == XOPERATOR)
2512 no_op("Backticks",s);
2514 missingterm((char*)0);
2515 yylval.ival = OP_BACKTICK;
2517 TERM(sublex_start());
2521 if (dowarn && lex_inwhat && isDIGIT(*s))
2522 warn("Can't use \\%c to mean $%c in expression", *s, *s);
2523 if (expect == XOPERATOR)
2524 no_op("Backslash",s);
2528 if (isDIGIT(s[1]) && expect == XOPERATOR) {
2567 s = scan_word(s, tokenbuf, sizeof tokenbuf, FALSE, &len);
2569 /* Some keywords can be followed by any delimiter, including ':' */
2570 tmp = (len == 1 && strchr("msyq", tokenbuf[0]) ||
2571 len == 2 && ((tokenbuf[0] == 't' && tokenbuf[1] == 'r') ||
2572 (tokenbuf[0] == 'q' &&
2573 strchr("qwx", tokenbuf[1]))));
2575 /* x::* is just a word, unless x is "CORE" */
2576 if (!tmp && *s == ':' && s[1] == ':' && strNE(tokenbuf, "CORE"))
2580 while (d < bufend && isSPACE(*d))
2581 d++; /* no comments skipped here, or s### is misparsed */
2583 /* Is this a label? */
2584 if (!tmp && expect == XSTATE
2585 && d < bufend && *d == ':' && *(d + 1) != ':') {
2587 yylval.pval = savepv(tokenbuf);
2592 /* Check for keywords */
2593 tmp = keyword(tokenbuf, len);
2595 /* Is this a word before a => operator? */
2596 if (strnEQ(d,"=>",2)) {
2598 if (dowarn && (tmp || perl_get_cv(tokenbuf, FALSE)))
2599 warn("Ambiguous use of %s => resolved to \"%s\" =>",
2600 tokenbuf, tokenbuf);
2601 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf,0));
2602 yylval.opval->op_private = OPpCONST_BARE;
2606 if (tmp < 0) { /* second-class keyword? */
2607 if (expect != XOPERATOR && (*s != ':' || s[1] != ':') &&
2608 (((gv = gv_fetchpv(tokenbuf, FALSE, SVt_PVCV)) &&
2609 GvCVu(gv) && GvIMPORTED_CV(gv)) ||
2610 ((gvp = (GV**)hv_fetch(globalstash,tokenbuf,len,FALSE)) &&
2611 (gv = *gvp) != (GV*)&sv_undef &&
2612 GvCVu(gv) && GvIMPORTED_CV(gv))))
2614 tmp = 0; /* overridden by importation */
2617 && -tmp==KEY_lock /* XXX generalizable kludge */
2618 && !hv_fetch(GvHVn(incgv), "Thread.pm", 9, FALSE))
2620 tmp = 0; /* any sub overrides "weak" keyword */
2623 tmp = -tmp; gv = Nullgv; gvp = 0;
2630 default: /* not a keyword */
2633 char lastchar = (bufptr == oldoldbufptr ? 0 : bufptr[-1]);
2635 /* Get the rest if it looks like a package qualifier */
2637 if (*s == '\'' || *s == ':' && s[1] == ':') {
2638 s = scan_word(s, tokenbuf + len, sizeof tokenbuf - len,
2641 croak("Bad name after %s::", tokenbuf);
2644 if (expect == XOPERATOR) {
2645 if (bufptr == linestart) {
2651 no_op("Bareword",s);
2654 /* Look for a subroutine with this name in current package. */
2657 sv = newSVpv("CORE::GLOBAL::",14);
2658 sv_catpv(sv,tokenbuf);
2661 sv = newSVpv(tokenbuf,0);
2663 gv = gv_fetchpv(tokenbuf,FALSE, SVt_PVCV);
2665 /* Presume this is going to be a bareword of some sort. */
2668 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2669 yylval.opval->op_private = OPpCONST_BARE;
2671 /* See if it's the indirect object for a list operator. */
2674 oldoldbufptr < bufptr &&
2675 (oldoldbufptr == last_lop || oldoldbufptr == last_uni) &&
2676 /* NO SKIPSPACE BEFORE HERE! */
2678 ((opargs[last_lop_op] >> OASHIFT)& 7) == OA_FILEREF) )
2680 bool immediate_paren = *s == '(';
2682 /* (Now we can afford to cross potential line boundary.) */
2685 /* Two barewords in a row may indicate method call. */
2687 if ((isALPHA(*s) || *s == '$') && (tmp=intuit_method(s,gv)))
2690 /* If not a declared subroutine, it's an indirect object. */
2691 /* (But it's an indir obj regardless for sort.) */
2693 if ((last_lop_op == OP_SORT ||
2694 (!immediate_paren && (!gv || !GvCVu(gv))) ) &&
2695 (last_lop_op != OP_MAPSTART && last_lop_op != OP_GREPSTART)){
2696 expect = (last_lop == oldoldbufptr) ? XTERM : XOPERATOR;
2701 /* If followed by a paren, it's certainly a subroutine. */
2707 if (gv && GvCVu(gv)) {
2708 for (d = s + 1; *d == ' ' || *d == '\t'; d++) ;
2709 if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) {
2714 nextval[nexttoke].opval = yylval.opval;
2721 /* If followed by var or block, call it a method (unless sub) */
2723 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
2724 last_lop = oldbufptr;
2725 last_lop_op = OP_METHOD;
2729 /* If followed by a bareword, see if it looks like indir obj. */
2731 if ((isALPHA(*s) || *s == '$') && (tmp = intuit_method(s,gv)))
2734 /* Not a method, so call it a subroutine (if defined) */
2736 if (gv && GvCVu(gv)) {
2738 if (lastchar == '-')
2739 warn("Ambiguous use of -%s resolved as -&%s()",
2740 tokenbuf, tokenbuf);
2741 last_lop = oldbufptr;
2742 last_lop_op = OP_ENTERSUB;
2743 /* Check for a constant sub */
2745 if ((sv = cv_const_sv(cv))) {
2747 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
2748 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
2749 yylval.opval->op_private = 0;
2753 /* Resolve to GV now. */
2754 op_free(yylval.opval);
2755 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
2756 /* Is there a prototype? */
2759 char *proto = SvPV((SV*)cv, len);
2762 if (strEQ(proto, "$"))
2764 if (*proto == '&' && *s == '{') {
2765 sv_setpv(subname,"__ANON__");
2769 nextval[nexttoke].opval = yylval.opval;
2775 if (hints & HINT_STRICT_SUBS &&
2778 last_lop_op != OP_TRUNCATE && /* S/F prototype in opcode.pl */
2779 last_lop_op != OP_ACCEPT &&
2780 last_lop_op != OP_PIPE_OP &&
2781 last_lop_op != OP_SOCKPAIR)
2784 "Bareword \"%s\" not allowed while \"strict subs\" in use",
2789 /* Call it a bare word */
2793 if (lastchar != '-') {
2794 for (d = tokenbuf; *d && isLOWER(*d); d++) ;
2796 warn(warn_reserved, tokenbuf);
2799 if (lastchar && strchr("*%&", lastchar)) {
2800 warn("Operator or semicolon missing before %c%s",
2801 lastchar, tokenbuf);
2802 warn("Ambiguous use of %c resolved as operator %c",
2803 lastchar, lastchar);
2809 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
2810 newSVsv(GvSV(curcop->cop_filegv)));
2814 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
2815 newSVpvf("%ld", (long)curcop->cop_line));
2818 case KEY___PACKAGE__:
2819 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
2821 ? newSVsv(curstname)
2830 if (rsfp && (!in_eval || tokenbuf[2] == 'D')) {
2831 char *pname = "main";
2832 if (tokenbuf[2] == 'D')
2833 pname = HvNAME(curstash ? curstash : defstash);
2834 gv = gv_fetchpv(form("%s::DATA", pname), TRUE, SVt_PVIO);
2837 GvIOp(gv) = newIO();
2838 IoIFP(GvIOp(gv)) = rsfp;
2839 #if defined(HAS_FCNTL) && defined(F_SETFD)
2841 int fd = PerlIO_fileno(rsfp);
2842 fcntl(fd,F_SETFD,fd >= 3);
2845 /* Mark this internal pseudo-handle as clean */
2846 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
2848 IoTYPE(GvIOp(gv)) = '|';
2849 else if ((PerlIO*)rsfp == PerlIO_stdin())
2850 IoTYPE(GvIOp(gv)) = '-';
2852 IoTYPE(GvIOp(gv)) = '<';
2863 if (expect == XSTATE) {
2870 if (*s == ':' && s[1] == ':') {
2873 s = scan_word(s, tokenbuf, sizeof tokenbuf, FALSE, &len);
2874 tmp = keyword(tokenbuf, len);
2888 LOP(OP_ACCEPT,XTERM);
2894 LOP(OP_ATAN2,XTERM);
2903 LOP(OP_BLESS,XTERM);
2912 (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */
2932 LOP(OP_CRYPT,XTERM);
2936 for (d = s; d < bufend && (isSPACE(*d) || *d == '('); d++) ;
2937 if (*d != '0' && isDIGIT(*d))
2938 yywarn("chmod: mode argument is missing initial 0");
2940 LOP(OP_CHMOD,XTERM);
2943 LOP(OP_CHOWN,XTERM);
2946 LOP(OP_CONNECT,XTERM);
2962 s = force_word(s,WORD,FALSE,TRUE,FALSE);
2966 hints |= HINT_BLOCK_SCOPE;
2976 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
2977 LOP(OP_DBMOPEN,XTERM);
2983 s = force_word(s,WORD,TRUE,FALSE,FALSE);
2990 yylval.ival = curcop->cop_line;
3004 expect = (*s == '{') ? XTERMBLOCK : XTERM;
3005 UNIBRACK(OP_ENTEREVAL);
3020 case KEY_endhostent:
3026 case KEY_endservent:
3029 case KEY_endprotoent:
3040 yylval.ival = curcop->cop_line;
3042 if (isIDFIRST(*s)) {
3044 if ((bufend - p) >= 3 &&
3045 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
3049 croak("Missing $ on loop variable");
3054 LOP(OP_FORMLINE,XTERM);
3060 LOP(OP_FCNTL,XTERM);
3066 LOP(OP_FLOCK,XTERM);
3075 LOP(OP_GREPSTART, *s == '(' ? XTERM : XREF);
3078 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3093 case KEY_getpriority:
3094 LOP(OP_GETPRIORITY,XTERM);
3096 case KEY_getprotobyname:
3099 case KEY_getprotobynumber:
3100 LOP(OP_GPBYNUMBER,XTERM);
3102 case KEY_getprotoent:
3114 case KEY_getpeername:
3115 UNI(OP_GETPEERNAME);
3117 case KEY_gethostbyname:
3120 case KEY_gethostbyaddr:
3121 LOP(OP_GHBYADDR,XTERM);
3123 case KEY_gethostent:
3126 case KEY_getnetbyname:
3129 case KEY_getnetbyaddr:
3130 LOP(OP_GNBYADDR,XTERM);
3135 case KEY_getservbyname:
3136 LOP(OP_GSBYNAME,XTERM);
3138 case KEY_getservbyport:
3139 LOP(OP_GSBYPORT,XTERM);
3141 case KEY_getservent:
3144 case KEY_getsockname:
3145 UNI(OP_GETSOCKNAME);
3147 case KEY_getsockopt:
3148 LOP(OP_GSOCKOPT,XTERM);
3170 yylval.ival = curcop->cop_line;
3174 LOP(OP_INDEX,XTERM);
3180 LOP(OP_IOCTL,XTERM);
3192 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3223 LOP(OP_LISTEN,XTERM);
3233 TERM(sublex_start());
3236 LOP(OP_MAPSTART,XREF);
3239 LOP(OP_MKDIR,XTERM);
3242 LOP(OP_MSGCTL,XTERM);
3245 LOP(OP_MSGGET,XTERM);
3248 LOP(OP_MSGRCV,XTERM);
3251 LOP(OP_MSGSND,XTERM);
3256 if (isIDFIRST(*s)) {
3257 s = scan_word(s, tokenbuf, sizeof tokenbuf, TRUE, &len);
3258 in_my_stash = gv_stashpv(tokenbuf, FALSE);
3262 sprintf(tmpbuf, "No such class %.1000s", tokenbuf);
3269 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3276 if (expect != XSTATE)
3277 yyerror("\"no\" not allowed in expression");
3278 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3279 s = force_version(s);
3288 if (isIDFIRST(*s)) {
3290 for (d = s; isALNUM(*d); d++) ;
3292 if (strchr("|&*+-=!?:.", *t))
3293 warn("Precedence problem: open %.*s should be open(%.*s)",
3299 yylval.ival = OP_OR;
3309 LOP(OP_OPEN_DIR,XTERM);
3312 checkcomma(s,tokenbuf,"filehandle");
3316 checkcomma(s,tokenbuf,"filehandle");
3335 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3339 LOP(OP_PIPE_OP,XTERM);
3344 missingterm((char*)0);
3345 yylval.ival = OP_CONST;
3346 TERM(sublex_start());
3354 missingterm((char*)0);
3355 if (dowarn && SvLEN(lex_stuff)) {
3356 d = SvPV_force(lex_stuff, len);
3357 for (; len; --len, ++d) {
3359 warn("Possible attempt to separate words with commas");
3363 warn("Possible attempt to put comments in qw() list");
3369 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, tokeq(lex_stuff));
3373 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(" ",1));
3376 yylval.ival = OP_SPLIT;
3380 last_lop = oldbufptr;
3381 last_lop_op = OP_SPLIT;
3387 missingterm((char*)0);
3388 yylval.ival = OP_STRINGIFY;
3389 if (SvIVX(lex_stuff) == '\'')
3390 SvIVX(lex_stuff) = 0; /* qq'$foo' should intepolate */
3391 TERM(sublex_start());
3396 missingterm((char*)0);
3397 yylval.ival = OP_BACKTICK;
3399 TERM(sublex_start());
3406 s = force_word(s,WORD,TRUE,TRUE,FALSE);
3407 if (isIDFIRST(*tokenbuf))
3408 gv_stashpvn(tokenbuf, strlen(tokenbuf), TRUE);
3410 yyerror("<> should be quotes");
3417 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3421 LOP(OP_RENAME,XTERM);
3430 LOP(OP_RINDEX,XTERM);
3453 LOP(OP_REVERSE,XTERM);
3464 TERM(sublex_start());
3466 TOKEN(1); /* force error */
3475 LOP(OP_SELECT,XTERM);
3481 LOP(OP_SEMCTL,XTERM);
3484 LOP(OP_SEMGET,XTERM);
3487 LOP(OP_SEMOP,XTERM);
3493 LOP(OP_SETPGRP,XTERM);
3495 case KEY_setpriority:
3496 LOP(OP_SETPRIORITY,XTERM);
3498 case KEY_sethostent:
3504 case KEY_setservent:
3507 case KEY_setprotoent:
3517 LOP(OP_SEEKDIR,XTERM);
3519 case KEY_setsockopt:
3520 LOP(OP_SSOCKOPT,XTERM);
3526 LOP(OP_SHMCTL,XTERM);
3529 LOP(OP_SHMGET,XTERM);
3532 LOP(OP_SHMREAD,XTERM);
3535 LOP(OP_SHMWRITE,XTERM);
3538 LOP(OP_SHUTDOWN,XTERM);
3547 LOP(OP_SOCKET,XTERM);
3549 case KEY_socketpair:
3550 LOP(OP_SOCKPAIR,XTERM);
3553 checkcomma(s,tokenbuf,"subroutine name");
3555 if (*s == ';' || *s == ')') /* probably a close */
3556 croak("sort is now a reserved word");
3558 s = force_word(s,WORD,TRUE,TRUE,FALSE);
3562 LOP(OP_SPLIT,XTERM);
3565 LOP(OP_SPRINTF,XTERM);
3568 LOP(OP_SPLICE,XTERM);
3584 LOP(OP_SUBSTR,XTERM);
3591 if (isIDFIRST(*s) || *s == '\'' || *s == ':') {
3592 char tmpbuf[sizeof tokenbuf];
3594 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3595 if (strchr(tmpbuf, ':'))
3596 sv_setpv(subname, tmpbuf);
3598 sv_setsv(subname,curstname);
3599 sv_catpvn(subname,"::",2);
3600 sv_catpvn(subname,tmpbuf,len);
3602 s = force_word(s,WORD,FALSE,TRUE,TRUE);
3606 expect = XTERMBLOCK;
3607 sv_setpv(subname,"?");
3610 if (tmp == KEY_format) {
3613 lex_formbrack = lex_brackets + 1;
3617 /* Look for a prototype */
3624 SvREFCNT_dec(lex_stuff);
3626 croak("Prototype not terminated");
3629 d = SvPVX(lex_stuff);
3631 for (p = d; *p; ++p) {
3636 SvCUR(lex_stuff) = tmp;
3639 nextval[1] = nextval[0];
3640 nexttype[1] = nexttype[0];
3641 nextval[0].opval = (OP*)newSVOP(OP_CONST, 0, lex_stuff);
3642 nexttype[0] = THING;
3643 if (nexttoke == 1) {
3644 lex_defer = lex_state;
3645 lex_expect = expect;
3646 lex_state = LEX_KNOWNEXT;
3651 if (*SvPV(subname,na) == '?') {
3652 sv_setpv(subname,"__ANON__");
3659 LOP(OP_SYSTEM,XREF);
3662 LOP(OP_SYMLINK,XTERM);
3665 LOP(OP_SYSCALL,XTERM);
3668 LOP(OP_SYSOPEN,XTERM);
3671 LOP(OP_SYSSEEK,XTERM);
3674 LOP(OP_SYSREAD,XTERM);
3677 LOP(OP_SYSWRITE,XTERM);
3681 TERM(sublex_start());
3702 LOP(OP_TRUNCATE,XTERM);
3714 yylval.ival = curcop->cop_line;
3718 yylval.ival = curcop->cop_line;
3722 LOP(OP_UNLINK,XTERM);
3728 LOP(OP_UNPACK,XTERM);
3731 LOP(OP_UTIME,XTERM);
3735 for (d = s; d < bufend && (isSPACE(*d) || *d == '('); d++) ;
3736 if (*d != '0' && isDIGIT(*d))
3737 yywarn("umask: argument is missing initial 0");
3742 LOP(OP_UNSHIFT,XTERM);
3745 if (expect != XSTATE)
3746 yyerror("\"use\" not allowed in expression");
3749 s = force_version(s);
3750 if(*s == ';' || (s = skipspace(s), *s == ';')) {
3751 nextval[nexttoke].opval = Nullop;
3756 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3757 s = force_version(s);
3770 yylval.ival = curcop->cop_line;
3774 hints |= HINT_BLOCK_SCOPE;
3781 LOP(OP_WAITPID,XTERM);
3787 gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */
3791 if (expect == XOPERATOR)
3797 yylval.ival = OP_XOR;
3802 TERM(sublex_start());
3808 keyword(register char *d, I32 len)
3813 if (strEQ(d,"__FILE__")) return -KEY___FILE__;
3814 if (strEQ(d,"__LINE__")) return -KEY___LINE__;
3815 if (strEQ(d,"__PACKAGE__")) return -KEY___PACKAGE__;
3816 if (strEQ(d,"__DATA__")) return KEY___DATA__;
3817 if (strEQ(d,"__END__")) return KEY___END__;
3821 if (strEQ(d,"AUTOLOAD")) return KEY_AUTOLOAD;
3826 if (strEQ(d,"and")) return -KEY_and;
3827 if (strEQ(d,"abs")) return -KEY_abs;
3830 if (strEQ(d,"alarm")) return -KEY_alarm;
3831 if (strEQ(d,"atan2")) return -KEY_atan2;
3834 if (strEQ(d,"accept")) return -KEY_accept;
3839 if (strEQ(d,"BEGIN")) return KEY_BEGIN;
3842 if (strEQ(d,"bless")) return -KEY_bless;
3843 if (strEQ(d,"bind")) return -KEY_bind;
3844 if (strEQ(d,"binmode")) return -KEY_binmode;
3847 if (strEQ(d,"CORE")) return -KEY_CORE;
3852 if (strEQ(d,"cmp")) return -KEY_cmp;
3853 if (strEQ(d,"chr")) return -KEY_chr;
3854 if (strEQ(d,"cos")) return -KEY_cos;
3857 if (strEQ(d,"chop")) return KEY_chop;
3860 if (strEQ(d,"close")) return -KEY_close;
3861 if (strEQ(d,"chdir")) return -KEY_chdir;
3862 if (strEQ(d,"chomp")) return KEY_chomp;
3863 if (strEQ(d,"chmod")) return -KEY_chmod;
3864 if (strEQ(d,"chown")) return -KEY_chown;
3865 if (strEQ(d,"crypt")) return -KEY_crypt;
3868 if (strEQ(d,"chroot")) return -KEY_chroot;
3869 if (strEQ(d,"caller")) return -KEY_caller;
3872 if (strEQ(d,"connect")) return -KEY_connect;
3875 if (strEQ(d,"closedir")) return -KEY_closedir;
3876 if (strEQ(d,"continue")) return -KEY_continue;
3881 if (strEQ(d,"DESTROY")) return KEY_DESTROY;
3886 if (strEQ(d,"do")) return KEY_do;
3889 if (strEQ(d,"die")) return -KEY_die;
3892 if (strEQ(d,"dump")) return -KEY_dump;
3895 if (strEQ(d,"delete")) return KEY_delete;
3898 if (strEQ(d,"defined")) return KEY_defined;
3899 if (strEQ(d,"dbmopen")) return -KEY_dbmopen;
3902 if (strEQ(d,"dbmclose")) return -KEY_dbmclose;
3907 if (strEQ(d,"EQ")) { deprecate(d); return -KEY_eq;}
3908 if (strEQ(d,"END")) return KEY_END;
3913 if (strEQ(d,"eq")) return -KEY_eq;
3916 if (strEQ(d,"eof")) return -KEY_eof;
3917 if (strEQ(d,"exp")) return -KEY_exp;
3920 if (strEQ(d,"else")) return KEY_else;
3921 if (strEQ(d,"exit")) return -KEY_exit;
3922 if (strEQ(d,"eval")) return KEY_eval;
3923 if (strEQ(d,"exec")) return -KEY_exec;
3924 if (strEQ(d,"each")) return KEY_each;
3927 if (strEQ(d,"elsif")) return KEY_elsif;
3930 if (strEQ(d,"exists")) return KEY_exists;
3931 if (strEQ(d,"elseif")) warn("elseif should be elsif");
3934 if (strEQ(d,"endgrent")) return -KEY_endgrent;
3935 if (strEQ(d,"endpwent")) return -KEY_endpwent;
3938 if (strEQ(d,"endnetent")) return -KEY_endnetent;
3941 if (strEQ(d,"endhostent")) return -KEY_endhostent;
3942 if (strEQ(d,"endservent")) return -KEY_endservent;
3945 if (strEQ(d,"endprotoent")) return -KEY_endprotoent;
3952 if (strEQ(d,"for")) return KEY_for;
3955 if (strEQ(d,"fork")) return -KEY_fork;
3958 if (strEQ(d,"fcntl")) return -KEY_fcntl;
3959 if (strEQ(d,"flock")) return -KEY_flock;
3962 if (strEQ(d,"format")) return KEY_format;
3963 if (strEQ(d,"fileno")) return -KEY_fileno;
3966 if (strEQ(d,"foreach")) return KEY_foreach;
3969 if (strEQ(d,"formline")) return -KEY_formline;
3975 if (strEQ(d,"GT")) { deprecate(d); return -KEY_gt;}
3976 if (strEQ(d,"GE")) { deprecate(d); return -KEY_ge;}
3980 if (strnEQ(d,"get",3)) {
3985 if (strEQ(d,"ppid")) return -KEY_getppid;
3986 if (strEQ(d,"pgrp")) return -KEY_getpgrp;
3989 if (strEQ(d,"pwent")) return -KEY_getpwent;
3990 if (strEQ(d,"pwnam")) return -KEY_getpwnam;
3991 if (strEQ(d,"pwuid")) return -KEY_getpwuid;
3994 if (strEQ(d,"peername")) return -KEY_getpeername;
3995 if (strEQ(d,"protoent")) return -KEY_getprotoent;
3996 if (strEQ(d,"priority")) return -KEY_getpriority;
3999 if (strEQ(d,"protobyname")) return -KEY_getprotobyname;
4002 if (strEQ(d,"protobynumber"))return -KEY_getprotobynumber;
4006 else if (*d == 'h') {
4007 if (strEQ(d,"hostbyname")) return -KEY_gethostbyname;
4008 if (strEQ(d,"hostbyaddr")) return -KEY_gethostbyaddr;
4009 if (strEQ(d,"hostent")) return -KEY_gethostent;
4011 else if (*d == 'n') {
4012 if (strEQ(d,"netbyname")) return -KEY_getnetbyname;
4013 if (strEQ(d,"netbyaddr")) return -KEY_getnetbyaddr;
4014 if (strEQ(d,"netent")) return -KEY_getnetent;
4016 else if (*d == 's') {
4017 if (strEQ(d,"servbyname")) return -KEY_getservbyname;
4018 if (strEQ(d,"servbyport")) return -KEY_getservbyport;
4019 if (strEQ(d,"servent")) return -KEY_getservent;
4020 if (strEQ(d,"sockname")) return -KEY_getsockname;
4021 if (strEQ(d,"sockopt")) return -KEY_getsockopt;
4023 else if (*d == 'g') {
4024 if (strEQ(d,"grent")) return -KEY_getgrent;
4025 if (strEQ(d,"grnam")) return -KEY_getgrnam;
4026 if (strEQ(d,"grgid")) return -KEY_getgrgid;
4028 else if (*d == 'l') {
4029 if (strEQ(d,"login")) return -KEY_getlogin;
4031 else if (strEQ(d,"c")) return -KEY_getc;
4036 if (strEQ(d,"gt")) return -KEY_gt;
4037 if (strEQ(d,"ge")) return -KEY_ge;
4040 if (strEQ(d,"grep")) return KEY_grep;
4041 if (strEQ(d,"goto")) return KEY_goto;
4042 if (strEQ(d,"glob")) return KEY_glob;
4045 if (strEQ(d,"gmtime")) return -KEY_gmtime;
4050 if (strEQ(d,"hex")) return -KEY_hex;
4053 if (strEQ(d,"INIT")) return KEY_INIT;
4058 if (strEQ(d,"if")) return KEY_if;
4061 if (strEQ(d,"int")) return -KEY_int;
4064 if (strEQ(d,"index")) return -KEY_index;
4065 if (strEQ(d,"ioctl")) return -KEY_ioctl;
4070 if (strEQ(d,"join")) return -KEY_join;
4074 if (strEQ(d,"keys")) return KEY_keys;
4075 if (strEQ(d,"kill")) return -KEY_kill;
4080 if (strEQ(d,"LT")) { deprecate(d); return -KEY_lt;}
4081 if (strEQ(d,"LE")) { deprecate(d); return -KEY_le;}
4087 if (strEQ(d,"lt")) return -KEY_lt;
4088 if (strEQ(d,"le")) return -KEY_le;
4089 if (strEQ(d,"lc")) return -KEY_lc;
4092 if (strEQ(d,"log")) return -KEY_log;
4095 if (strEQ(d,"last")) return KEY_last;
4096 if (strEQ(d,"link")) return -KEY_link;
4097 if (strEQ(d,"lock")) return -KEY_lock;
4100 if (strEQ(d,"local")) return KEY_local;
4101 if (strEQ(d,"lstat")) return -KEY_lstat;
4104 if (strEQ(d,"length")) return -KEY_length;
4105 if (strEQ(d,"listen")) return -KEY_listen;
4108 if (strEQ(d,"lcfirst")) return -KEY_lcfirst;
4111 if (strEQ(d,"localtime")) return -KEY_localtime;
4117 case 1: return KEY_m;
4119 if (strEQ(d,"my")) return KEY_my;
4122 if (strEQ(d,"map")) return KEY_map;
4125 if (strEQ(d,"mkdir")) return -KEY_mkdir;
4128 if (strEQ(d,"msgctl")) return -KEY_msgctl;
4129 if (strEQ(d,"msgget")) return -KEY_msgget;
4130 if (strEQ(d,"msgrcv")) return -KEY_msgrcv;
4131 if (strEQ(d,"msgsnd")) return -KEY_msgsnd;
4136 if (strEQ(d,"NE")) { deprecate(d); return -KEY_ne;}
4139 if (strEQ(d,"next")) return KEY_next;
4140 if (strEQ(d,"ne")) return -KEY_ne;
4141 if (strEQ(d,"not")) return -KEY_not;
4142 if (strEQ(d,"no")) return KEY_no;
4147 if (strEQ(d,"or")) return -KEY_or;
4150 if (strEQ(d,"ord")) return -KEY_ord;
4151 if (strEQ(d,"oct")) return -KEY_oct;
4154 if (strEQ(d,"open")) return -KEY_open;
4157 if (strEQ(d,"opendir")) return -KEY_opendir;
4164 if (strEQ(d,"pop")) return KEY_pop;
4165 if (strEQ(d,"pos")) return KEY_pos;
4168 if (strEQ(d,"push")) return KEY_push;
4169 if (strEQ(d,"pack")) return -KEY_pack;
4170 if (strEQ(d,"pipe")) return -KEY_pipe;
4173 if (strEQ(d,"print")) return KEY_print;
4176 if (strEQ(d,"printf")) return KEY_printf;
4179 if (strEQ(d,"package")) return KEY_package;
4182 if (strEQ(d,"prototype")) return KEY_prototype;
4187 if (strEQ(d,"q")) return KEY_q;
4188 if (strEQ(d,"qq")) return KEY_qq;
4189 if (strEQ(d,"qw")) return KEY_qw;
4190 if (strEQ(d,"qx")) return KEY_qx;
4192 else if (strEQ(d,"quotemeta")) return -KEY_quotemeta;
4197 if (strEQ(d,"ref")) return -KEY_ref;
4200 if (strEQ(d,"read")) return -KEY_read;
4201 if (strEQ(d,"rand")) return -KEY_rand;
4202 if (strEQ(d,"recv")) return -KEY_recv;
4203 if (strEQ(d,"redo")) return KEY_redo;
4206 if (strEQ(d,"rmdir")) return -KEY_rmdir;
4207 if (strEQ(d,"reset")) return -KEY_reset;
4210 if (strEQ(d,"return")) return KEY_return;
4211 if (strEQ(d,"rename")) return -KEY_rename;
4212 if (strEQ(d,"rindex")) return -KEY_rindex;
4215 if (strEQ(d,"require")) return -KEY_require;
4216 if (strEQ(d,"reverse")) return -KEY_reverse;
4217 if (strEQ(d,"readdir")) return -KEY_readdir;
4220 if (strEQ(d,"readlink")) return -KEY_readlink;
4221 if (strEQ(d,"readline")) return -KEY_readline;
4222 if (strEQ(d,"readpipe")) return -KEY_readpipe;
4225 if (strEQ(d,"rewinddir")) return -KEY_rewinddir;
4231 case 0: return KEY_s;
4233 if (strEQ(d,"scalar")) return KEY_scalar;
4238 if (strEQ(d,"seek")) return -KEY_seek;
4239 if (strEQ(d,"send")) return -KEY_send;
4242 if (strEQ(d,"semop")) return -KEY_semop;
4245 if (strEQ(d,"select")) return -KEY_select;
4246 if (strEQ(d,"semctl")) return -KEY_semctl;
4247 if (strEQ(d,"semget")) return -KEY_semget;
4250 if (strEQ(d,"setpgrp")) return -KEY_setpgrp;
4251 if (strEQ(d,"seekdir")) return -KEY_seekdir;
4254 if (strEQ(d,"setpwent")) return -KEY_setpwent;
4255 if (strEQ(d,"setgrent")) return -KEY_setgrent;
4258 if (strEQ(d,"setnetent")) return -KEY_setnetent;
4261 if (strEQ(d,"setsockopt")) return -KEY_setsockopt;
4262 if (strEQ(d,"sethostent")) return -KEY_sethostent;
4263 if (strEQ(d,"setservent")) return -KEY_setservent;
4266 if (strEQ(d,"setpriority")) return -KEY_setpriority;
4267 if (strEQ(d,"setprotoent")) return -KEY_setprotoent;
4274 if (strEQ(d,"shift")) return KEY_shift;
4277 if (strEQ(d,"shmctl")) return -KEY_shmctl;
4278 if (strEQ(d,"shmget")) return -KEY_shmget;
4281 if (strEQ(d,"shmread")) return -KEY_shmread;
4284 if (strEQ(d,"shmwrite")) return -KEY_shmwrite;
4285 if (strEQ(d,"shutdown")) return -KEY_shutdown;
4290 if (strEQ(d,"sin")) return -KEY_sin;
4293 if (strEQ(d,"sleep")) return -KEY_sleep;
4296 if (strEQ(d,"sort")) return KEY_sort;
4297 if (strEQ(d,"socket")) return -KEY_socket;
4298 if (strEQ(d,"socketpair")) return -KEY_socketpair;
4301 if (strEQ(d,"split")) return KEY_split;
4302 if (strEQ(d,"sprintf")) return -KEY_sprintf;
4303 if (strEQ(d,"splice")) return KEY_splice;
4306 if (strEQ(d,"sqrt")) return -KEY_sqrt;
4309 if (strEQ(d,"srand")) return -KEY_srand;
4312 if (strEQ(d,"stat")) return -KEY_stat;
4313 if (strEQ(d,"study")) return KEY_study;
4316 if (strEQ(d,"substr")) return -KEY_substr;
4317 if (strEQ(d,"sub")) return KEY_sub;
4322 if (strEQ(d,"system")) return -KEY_system;
4325 if (strEQ(d,"symlink")) return -KEY_symlink;
4326 if (strEQ(d,"syscall")) return -KEY_syscall;
4327 if (strEQ(d,"sysopen")) return -KEY_sysopen;
4328 if (strEQ(d,"sysread")) return -KEY_sysread;
4329 if (strEQ(d,"sysseek")) return -KEY_sysseek;
4332 if (strEQ(d,"syswrite")) return -KEY_syswrite;
4341 if (strEQ(d,"tr")) return KEY_tr;
4344 if (strEQ(d,"tie")) return KEY_tie;
4347 if (strEQ(d,"tell")) return -KEY_tell;
4348 if (strEQ(d,"tied")) return KEY_tied;
4349 if (strEQ(d,"time")) return -KEY_time;
4352 if (strEQ(d,"times")) return -KEY_times;
4355 if (strEQ(d,"telldir")) return -KEY_telldir;
4358 if (strEQ(d,"truncate")) return -KEY_truncate;
4365 if (strEQ(d,"uc")) return -KEY_uc;
4368 if (strEQ(d,"use")) return KEY_use;
4371 if (strEQ(d,"undef")) return KEY_undef;
4372 if (strEQ(d,"until")) return KEY_until;
4373 if (strEQ(d,"untie")) return KEY_untie;
4374 if (strEQ(d,"utime")) return -KEY_utime;
4375 if (strEQ(d,"umask")) return -KEY_umask;
4378 if (strEQ(d,"unless")) return KEY_unless;
4379 if (strEQ(d,"unpack")) return -KEY_unpack;
4380 if (strEQ(d,"unlink")) return -KEY_unlink;
4383 if (strEQ(d,"unshift")) return KEY_unshift;
4384 if (strEQ(d,"ucfirst")) return -KEY_ucfirst;
4389 if (strEQ(d,"values")) return -KEY_values;
4390 if (strEQ(d,"vec")) return -KEY_vec;
4395 if (strEQ(d,"warn")) return -KEY_warn;
4396 if (strEQ(d,"wait")) return -KEY_wait;
4399 if (strEQ(d,"while")) return KEY_while;
4400 if (strEQ(d,"write")) return -KEY_write;
4403 if (strEQ(d,"waitpid")) return -KEY_waitpid;
4406 if (strEQ(d,"wantarray")) return -KEY_wantarray;
4411 if (len == 1) return -KEY_x;
4412 if (strEQ(d,"xor")) return -KEY_xor;
4415 if (len == 1) return KEY_y;
4424 checkcomma(register char *s, char *name, char *what)
4428 if (dowarn && *s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
4430 for (w = s+2; *w && level; w++) {
4437 for (; *w && isSPACE(*w); w++) ;
4438 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
4439 warn("%s (...) interpreted as function",name);
4441 while (s < bufend && isSPACE(*s))
4445 while (s < bufend && isSPACE(*s))
4447 if (isIDFIRST(*s)) {
4451 while (s < bufend && isSPACE(*s))
4456 kw = keyword(w, s - w) || perl_get_cv(w, FALSE) != 0;
4460 croak("No comma allowed after %s", what);
4466 scan_word(register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
4468 register char *d = dest;
4469 register char *e = d + destlen - 3; /* two-character token, ending NUL */
4472 croak(ident_too_long);
4475 else if (*s == '\'' && allow_package && isIDFIRST(s[1])) {
4480 else if (*s == ':' && s[1] == ':' && allow_package && isIDFIRST(s[2])) {
4493 scan_ident(register char *s, register char *send, char *dest, STRLEN destlen, I32 ck_uni)
4500 if (lex_brackets == 0)
4505 e = d + destlen - 3; /* two-character token, ending NUL */
4507 while (isDIGIT(*s)) {
4509 croak(ident_too_long);
4516 croak(ident_too_long);
4519 else if (*s == '\'' && isIDFIRST(s[1])) {
4524 else if (*s == ':' && s[1] == ':') {
4535 if (lex_state != LEX_NORMAL)
4536 lex_state = LEX_INTERPENDMAYBE;
4539 if (*s == '$' && s[1] &&
4540 (isALNUM(s[1]) || strchr("${", s[1]) || strnEQ(s+1,"::",2)) )
4542 if (isDIGIT(s[1]) && lex_state == LEX_INTERPNORMAL)
4543 deprecate("\"$$<digit>\" to mean \"${$}<digit>\"");
4556 if (*d == '^' && *s && (isUPPER(*s) || strchr("[\\]^_?", *s))) {
4561 if (isSPACE(s[-1])) {
4564 if (ch != ' ' && ch != '\t') {
4570 if (isIDFIRST(*d)) {
4572 while (isALNUM(*s) || *s == ':')
4575 while (s < send && (*s == ' ' || *s == '\t')) s++;
4576 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
4577 if (dowarn && keyword(dest, d - dest)) {
4578 char *brack = *s == '[' ? "[...]" : "{...}";
4579 warn("Ambiguous use of %c{%s%s} resolved to %c%s%s",
4580 funny, dest, brack, funny, dest, brack);
4582 lex_fakebrack = lex_brackets+1;
4584 lex_brackstack[lex_brackets++] = XOPERATOR;
4590 if (lex_state == LEX_INTERPNORMAL && !lex_brackets)
4591 lex_state = LEX_INTERPEND;
4594 if (dowarn && lex_state == LEX_NORMAL &&
4595 (keyword(dest, d - dest) || perl_get_cv(dest, FALSE)))
4596 warn("Ambiguous use of %c{%s} resolved to %c%s",
4597 funny, dest, funny, dest);
4600 s = bracket; /* let the parser handle it */
4604 else if (lex_state == LEX_INTERPNORMAL && !lex_brackets && !intuit_more(s))
4605 lex_state = LEX_INTERPEND;
4609 void pmflag(U16 *pmfl, int ch)
4614 *pmfl |= PMf_GLOBAL;
4616 *pmfl |= PMf_CONTINUE;
4620 *pmfl |= PMf_MULTILINE;
4622 *pmfl |= PMf_SINGLELINE;
4624 *pmfl |= PMf_EXTENDED;
4628 scan_pat(char *start)
4633 s = scan_str(start);
4636 SvREFCNT_dec(lex_stuff);
4638 croak("Search pattern not terminated");
4641 pm = (PMOP*)newPMOP(OP_MATCH, 0);
4642 if (multi_open == '?')
4643 pm->op_pmflags |= PMf_ONCE;
4644 while (*s && strchr("iogcmsx", *s))
4645 pmflag(&pm->op_pmflags,*s++);
4646 pm->op_pmpermflags = pm->op_pmflags;
4649 yylval.ival = OP_MATCH;
4654 scan_subst(char *start)
4661 yylval.ival = OP_NULL;
4663 s = scan_str(start);
4667 SvREFCNT_dec(lex_stuff);
4669 croak("Substitution pattern not terminated");
4672 if (s[-1] == multi_open)
4675 first_start = multi_start;
4679 SvREFCNT_dec(lex_stuff);
4682 SvREFCNT_dec(lex_repl);
4684 croak("Substitution replacement not terminated");
4686 multi_start = first_start; /* so whole substitution is taken together */
4688 pm = (PMOP*)newPMOP(OP_SUBST, 0);
4689 while (*s && strchr("iogcmsex", *s)) {
4695 pmflag(&pm->op_pmflags,*s++);
4700 pm->op_pmflags |= PMf_EVAL;
4701 repl = newSVpv("",0);
4703 sv_catpv(repl, es ? "eval " : "do ");
4704 sv_catpvn(repl, "{ ", 2);
4705 sv_catsv(repl, lex_repl);
4706 sv_catpvn(repl, " };", 2);
4707 SvCOMPILED_on(repl);
4708 SvREFCNT_dec(lex_repl);
4712 pm->op_pmpermflags = pm->op_pmflags;
4714 yylval.ival = OP_SUBST;
4719 scan_trans(char *start)
4728 yylval.ival = OP_NULL;
4730 s = scan_str(start);
4733 SvREFCNT_dec(lex_stuff);
4735 croak("Translation pattern not terminated");
4737 if (s[-1] == multi_open)
4743 SvREFCNT_dec(lex_stuff);
4746 SvREFCNT_dec(lex_repl);
4748 croak("Translation replacement not terminated");
4751 New(803,tbl,256,short);
4752 o = newPVOP(OP_TRANS, 0, (char*)tbl);
4754 complement = Delete = squash = 0;
4755 while (*s == 'c' || *s == 'd' || *s == 's') {
4757 complement = OPpTRANS_COMPLEMENT;
4759 Delete = OPpTRANS_DELETE;
4761 squash = OPpTRANS_SQUASH;
4764 o->op_private = Delete|squash|complement;
4767 yylval.ival = OP_TRANS;
4772 scan_heredoc(register char *s)
4776 I32 op_type = OP_SCALAR;
4783 int outer = (rsfp && !lex_inwhat);
4787 e = tokenbuf + sizeof tokenbuf - 1;
4790 for (peek = s; *peek == ' ' || *peek == '\t'; peek++) ;
4791 if (*peek && strchr("`'\"",*peek)) {
4794 s = delimcpy(d, e, s, bufend, term, &len);
4805 deprecate("bare << to mean <<\"\"");
4806 for (; isALNUM(*s); s++) {
4811 if (d >= tokenbuf + sizeof tokenbuf - 1)
4812 croak("Delimiter for here document is too long");
4817 if (outer || !(d=ninstr(s,bufend,d,d+1)))
4818 herewas = newSVpv(s,bufend-s);
4820 s--, herewas = newSVpv(s,d-s);
4821 s += SvCUR(herewas);
4823 tmpstr = NEWSV(87,80);
4824 sv_upgrade(tmpstr, SVt_PVIV);
4829 else if (term == '`') {
4830 op_type = OP_BACKTICK;
4831 SvIVX(tmpstr) = '\\';
4835 multi_start = curcop->cop_line;
4836 multi_open = multi_close = '<';
4840 while (s < bufend &&
4841 (*s != term || memNE(s,tokenbuf,len)) ) {
4846 curcop->cop_line = multi_start;
4847 missingterm(tokenbuf);
4849 sv_setpvn(tmpstr,d+1,s-d);
4851 sv_catpvn(herewas,s,bufend-s);
4852 sv_setsv(linestr,herewas);
4853 oldoldbufptr = oldbufptr = bufptr = s = linestart = SvPVX(linestr);
4854 bufend = SvPVX(linestr) + SvCUR(linestr);
4857 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
4858 while (s >= bufend) { /* multiple line string? */
4860 !(oldoldbufptr = oldbufptr = s = linestart = filter_gets(linestr, rsfp, 0))) {
4861 curcop->cop_line = multi_start;
4862 missingterm(tokenbuf);
4865 if (PERLDB_LINE && curstash != debstash) {
4866 SV *sv = NEWSV(88,0);
4868 sv_upgrade(sv, SVt_PVMG);
4869 sv_setsv(sv,linestr);
4870 av_store(GvAV(curcop->cop_filegv),
4871 (I32)curcop->cop_line,sv);
4873 bufend = SvPVX(linestr) + SvCUR(linestr);
4874 if (*s == term && memEQ(s,tokenbuf,len)) {
4877 sv_catsv(linestr,herewas);
4878 bufend = SvPVX(linestr) + SvCUR(linestr);
4882 sv_catsv(tmpstr,linestr);
4885 multi_end = curcop->cop_line;
4887 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
4888 SvLEN_set(tmpstr, SvCUR(tmpstr) + 1);
4889 Renew(SvPVX(tmpstr), SvLEN(tmpstr), char);
4891 SvREFCNT_dec(herewas);
4893 yylval.ival = op_type;
4898 scan_inputsymbol(char *start)
4900 register char *s = start;
4906 e = tokenbuf + sizeof tokenbuf;
4907 s = delimcpy(d, e, s + 1, bufend, '>', &len);
4908 if (len >= sizeof tokenbuf)
4909 croak("Excessively long <> operator");
4911 croak("Unterminated <> operator");
4913 if (*d == '$' && d[1]) d++;
4914 while (*d && (isALNUM(*d) || *d == '\'' || *d == ':'))
4916 if (d - tokenbuf != len) {
4917 yylval.ival = OP_GLOB;
4919 s = scan_str(start);
4921 croak("Glob not terminated");
4927 (void)strcpy(d,"ARGV");
4930 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
4931 OP *o = newOP(OP_PADSV, 0);
4933 lex_op = (OP*)newUNOP(OP_READLINE, 0, newUNOP(OP_RV2GV, 0, o));
4936 GV *gv = gv_fetchpv(d+1,TRUE, SVt_PV);
4937 lex_op = (OP*)newUNOP(OP_READLINE, 0,
4938 newUNOP(OP_RV2GV, 0,
4939 newUNOP(OP_RV2SV, 0,
4940 newGVOP(OP_GV, 0, gv))));
4942 yylval.ival = OP_NULL;
4945 GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO);
4946 lex_op = (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
4947 yylval.ival = OP_NULL;
4954 scan_str(char *start)
4959 register char *s = start;
4968 multi_start = curcop->cop_line;
4970 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4975 sv_upgrade(sv, SVt_PVIV);
4977 (void)SvPOK_only(sv); /* validate pointer */
4980 SvGROW(sv, SvCUR(sv) + (bufend - s) + 1);
4981 to = SvPVX(sv)+SvCUR(sv);
4982 if (multi_open == multi_close) {
4983 for (; s < bufend; s++,to++) {
4984 if (*s == '\n' && !rsfp)
4986 if (*s == '\\' && s+1 < bufend && term != '\\') {
4992 else if (*s == term)
4998 for (; s < bufend; s++,to++) {
4999 if (*s == '\n' && !rsfp)
5001 if (*s == '\\' && s+1 < bufend) {
5002 if ((s[1] == multi_open) || (s[1] == multi_close))
5007 else if (*s == multi_close && --brackets <= 0)
5009 else if (*s == multi_open)
5015 SvCUR_set(sv, to - SvPVX(sv));
5017 if (s < bufend) break; /* string ends on this line? */
5020 !(oldoldbufptr = oldbufptr = s = linestart = filter_gets(linestr, rsfp, 0))) {
5022 curcop->cop_line = multi_start;
5026 if (PERLDB_LINE && curstash != debstash) {
5027 SV *sv = NEWSV(88,0);
5029 sv_upgrade(sv, SVt_PVMG);
5030 sv_setsv(sv,linestr);
5031 av_store(GvAV(curcop->cop_filegv),
5032 (I32)curcop->cop_line, sv);
5034 bufend = SvPVX(linestr) + SvCUR(linestr);
5036 multi_end = curcop->cop_line;
5038 if (SvCUR(sv) + 5 < SvLEN(sv)) {
5039 SvLEN_set(sv, SvCUR(sv) + 1);
5040 Renew(SvPVX(sv), SvLEN(sv), char);
5050 scan_num(char *start)
5052 register char *s = start;
5060 static char number_too_long[] = "Number too long";
5064 croak("panic: scan_num");
5069 bool overflowed = FALSE;
5075 else if (s[1] == '.')
5091 yyerror("Illegal octal digit");
5093 case '0': case '1': case '2': case '3': case '4':
5094 case '5': case '6': case '7':
5097 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
5098 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
5104 if (!overflowed && (n >> shift) != u) {
5105 warn("Integer overflow in %s number",
5106 (shift == 4) ? "hex" : "octal");
5118 case '1': case '2': case '3': case '4': case '5':
5119 case '6': case '7': case '8': case '9': case '.':
5122 e = tokenbuf + sizeof tokenbuf - 6; /* room for various punctuation */
5124 while (isDIGIT(*s) || *s == '_') {
5126 if (dowarn && lastub && s - lastub != 3)
5127 warn("Misplaced _ in number");
5132 croak(number_too_long);
5136 if (dowarn && lastub && s - lastub != 3)
5137 warn("Misplaced _ in number");
5138 if (*s == '.' && s[1] != '.') {
5141 for (; isDIGIT(*s) || *s == '_'; s++) {
5143 croak(number_too_long);
5148 if (*s && strchr("eE",*s) && strchr("+-0123456789",s[1])) {
5151 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
5152 if (*s == '+' || *s == '-')
5154 while (isDIGIT(*s)) {
5156 croak(number_too_long);
5162 SET_NUMERIC_STANDARD();
5163 value = atof(tokenbuf);
5165 if (!floatit && (double)tryiv == value)
5166 sv_setiv(sv, tryiv);
5168 sv_setnv(sv, value);
5172 yylval.opval = newSVOP(OP_CONST, 0, sv);
5178 scan_formline(register char *s)
5183 SV *stuff = newSVpv("",0);
5184 bool needargs = FALSE;
5187 if (*s == '.' || *s == '}') {
5189 for (t = s+1; *t == ' ' || *t == '\t'; t++) ;
5193 if (in_eval && !rsfp) {
5194 eol = strchr(s,'\n');
5199 eol = bufend = SvPVX(linestr) + SvCUR(linestr);
5201 for (t = s; t < eol; t++) {
5202 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
5204 goto enough; /* ~~ must be first line in formline */
5206 if (*t == '@' || *t == '^')
5209 sv_catpvn(stuff, s, eol-s);
5213 s = filter_gets(linestr, rsfp, 0);
5214 oldoldbufptr = oldbufptr = bufptr = linestart = SvPVX(linestr);
5215 bufend = bufptr + SvCUR(linestr);
5218 yyerror("Format not terminated");
5228 lex_state = LEX_NORMAL;
5229 nextval[nexttoke].ival = 0;
5233 lex_state = LEX_FORMLINE;
5234 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff);
5236 nextval[nexttoke].ival = OP_FORMLINE;
5240 SvREFCNT_dec(stuff);
5252 cshlen = strlen(cshname);
5257 start_subparse(I32 is_format, U32 flags)
5260 I32 oldsavestack_ix = savestack_ix;
5261 CV* outsidecv = compcv;
5265 assert(SvTYPE(compcv) == SVt_PVCV);
5272 SAVESPTR(comppad_name);
5274 SAVEI32(comppad_name_fill);
5275 SAVEI32(min_intro_pending);
5276 SAVEI32(max_intro_pending);
5277 SAVEI32(pad_reset_pending);
5279 compcv = (CV*)NEWSV(1104,0);
5280 sv_upgrade((SV *)compcv, is_format ? SVt_PVFM : SVt_PVCV);
5281 CvFLAGS(compcv) |= flags;
5284 av_push(comppad, Nullsv);
5285 curpad = AvARRAY(comppad);
5286 comppad_name = newAV();
5287 comppad_name_fill = 0;
5288 min_intro_pending = 0;
5290 subline = curcop->cop_line;
5292 av_store(comppad_name, 0, newSVpv("@_", 2));
5293 curpad[0] = (SV*)newAV();
5294 SvPADMY_on(curpad[0]); /* XXX Needed? */
5295 CvOWNER(compcv) = 0;
5296 New(666, CvMUTEXP(compcv), 1, perl_mutex);
5297 MUTEX_INIT(CvMUTEXP(compcv));
5298 #endif /* USE_THREADS */
5300 comppadlist = newAV();
5301 AvREAL_off(comppadlist);
5302 av_store(comppadlist, 0, (SV*)comppad_name);
5303 av_store(comppadlist, 1, (SV*)comppad);
5305 CvPADLIST(compcv) = comppadlist;
5306 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc(outsidecv);
5308 CvOWNER(compcv) = 0;
5309 New(666, CvMUTEXP(compcv), 1, perl_mutex);
5310 MUTEX_INIT(CvMUTEXP(compcv));
5311 #endif /* USE_THREADS */
5313 return oldsavestack_ix;
5332 char *context = NULL;
5336 if (!yychar || (yychar == ';' && !rsfp))
5338 else if (bufptr > oldoldbufptr && bufptr - oldoldbufptr < 200 &&
5339 oldoldbufptr != oldbufptr && oldbufptr != bufptr) {
5340 while (isSPACE(*oldoldbufptr))
5342 context = oldoldbufptr;
5343 contlen = bufptr - oldoldbufptr;
5345 else if (bufptr > oldbufptr && bufptr - oldbufptr < 200 &&
5346 oldbufptr != bufptr) {
5347 while (isSPACE(*oldbufptr))
5349 context = oldbufptr;
5350 contlen = bufptr - oldbufptr;
5352 else if (yychar > 255)
5353 where = "next token ???";
5354 else if ((yychar & 127) == 127) {
5355 if (lex_state == LEX_NORMAL ||
5356 (lex_state == LEX_KNOWNEXT && lex_defer == LEX_NORMAL))
5357 where = "at end of line";
5359 where = "within pattern";
5361 where = "within string";
5364 SV *where_sv = sv_2mortal(newSVpv("next char ", 0));
5366 sv_catpvf(where_sv, "^%c", toCTRL(yychar));
5367 else if (isPRINT_LC(yychar))
5368 sv_catpvf(where_sv, "%c", yychar);
5370 sv_catpvf(where_sv, "\\%03o", yychar & 255);
5371 where = SvPVX(where_sv);
5373 msg = sv_2mortal(newSVpv(s, 0));
5374 sv_catpvf(msg, " at %_ line %ld, ",
5375 GvSV(curcop->cop_filegv), (long)curcop->cop_line);
5377 sv_catpvf(msg, "near \"%.*s\"\n", contlen, context);
5379 sv_catpvf(msg, "%s\n", where);
5380 if (multi_start < multi_end && (U32)(curcop->cop_line - multi_end) <= 1) {
5382 " (Might be a runaway multi-line %c%c string starting on line %ld)\n",
5383 (int)multi_open,(int)multi_close,(long)multi_start);
5389 sv_catsv(ERRSV, msg);
5391 PerlIO_write(PerlIO_stderr(), SvPVX(msg), SvCUR(msg));
5392 if (++error_count >= 10)
5393 croak("%_ has too many errors.\n", GvSV(curcop->cop_filegv));
5395 in_my_stash = Nullhv;