This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix a2p translation of '{print "a" "b" "c"}'
[perl5.git] / toke.c
CommitLineData
a0d0e21e 1/* toke.c
a687059c 2 *
a0d0e21e 3 * Copyright (c) 1991-1994, Larry Wall
a687059c 4 *
d48672a2
LW
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.
378cc40b 7 *
a0d0e21e
LW
8 */
9
10/*
11 * "It all comes from here, the stench and the peril." --Frodo
378cc40b
LW
12 */
13
14#include "EXTERN.h"
15#include "perl.h"
378cc40b 16
a0d0e21e
LW
17static void check_uni _((void));
18static void force_next _((I32 type));
89bfa8cd 19static char *force_version _((char *start));
a0d0e21e
LW
20static char *force_word _((char *start, int token, int check_keyword, int allow_pack, int allow_tick));
21static SV *q _((SV *sv));
22static char *scan_const _((char *start));
23static char *scan_formline _((char *s));
24static char *scan_heredoc _((char *s));
25static char *scan_ident _((char *s, char *send, char *dest, I32 ck_uni));
26static char *scan_inputsymbol _((char *start));
27static char *scan_pat _((char *start));
28static char *scan_str _((char *start));
29static char *scan_subst _((char *start));
30static char *scan_trans _((char *start));
31static char *scan_word _((char *s, char *dest, int allow_package, STRLEN *slp));
32static char *skipspace _((char *s));
33static void checkcomma _((char *s, char *name, char *what));
34static void force_ident _((char *s, int kind));
35static void incline _((char *s));
36static int intuit_method _((char *s, GV *gv));
37static int intuit_more _((char *s));
38static I32 lop _((I32 f, expectation x, char *s));
39static void missingterm _((char *s));
40static void no_op _((char *what, char *s));
41static void set_csh _((void));
42static I32 sublex_done _((void));
43static I32 sublex_start _((void));
44#ifdef CRIPPLED_CC
45static int uni _((I32 f, char *s));
46#endif
fd049845 47static char * filter_gets _((SV *sv, PerlIO *fp, STRLEN append));
6d5fb7e3 48static void restore_rsfp _((void *f));
2f3197b3 49
fd049845
PP
50static char *linestart; /* beg. of most recently read line */
51
79072805
LW
52/* The following are arranged oddly so that the guard on the switch statement
53 * can get by with a single comparison (if the compiler is smart enough).
54 */
55
a0d0e21e
LW
56#define LEX_NORMAL 9
57#define LEX_INTERPNORMAL 8
58#define LEX_INTERPCASEMOD 7
59#define LEX_INTERPSTART 6
60#define LEX_INTERPEND 5
61#define LEX_INTERPENDMAYBE 4
62#define LEX_INTERPCONCAT 3
63#define LEX_INTERPCONST 2
64#define LEX_FORMLINE 1
79072805
LW
65#define LEX_KNOWNEXT 0
66
395c3793
LW
67#ifdef I_FCNTL
68#include <fcntl.h>
69#endif
fe14fcc3
LW
70#ifdef I_SYS_FILE
71#include <sys/file.h>
72#endif
395c3793 73
a790bc05
PP
74/* XXX If this causes problems, set i_unistd=undef in the hint file. */
75#ifdef I_UNISTD
76# include <unistd.h> /* Needed for execv() */
77#endif
78
79
79072805
LW
80#ifdef ff_next
81#undef ff_next
d48672a2
LW
82#endif
83
79072805 84#include "keywords.h"
fe14fcc3 85
ae986130
LW
86#ifdef CLINE
87#undef CLINE
88#endif
79072805 89#define CLINE (copline = (curcop->cop_line < copline ? curcop->cop_line : copline))
378cc40b 90
79072805
LW
91#define TOKEN(retval) return (bufptr = s,(int)retval)
92#define OPERATOR(retval) return (expect = XTERM,bufptr = s,(int)retval)
a0d0e21e 93#define AOPERATOR(retval) return ao((expect = XTERM,bufptr = s,(int)retval))
79072805 94#define PREBLOCK(retval) return (expect = XBLOCK,bufptr = s,(int)retval)
a0d0e21e 95#define PRETERMBLOCK(retval) return (expect = XTERMBLOCK,bufptr = s,(int)retval)
79072805
LW
96#define PREREF(retval) return (expect = XREF,bufptr = s,(int)retval)
97#define TERM(retval) return (CLINE, expect = XOPERATOR,bufptr = s,(int)retval)
463ee0b2 98#define LOOPX(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)LOOPEX)
79072805
LW
99#define FTST(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)UNIOP)
100#define FUN0(f) return(yylval.ival = f,expect = XOPERATOR,bufptr = s,(int)FUNC0)
101#define FUN1(f) return(yylval.ival = f,expect = XOPERATOR,bufptr = s,(int)FUNC1)
a0d0e21e
LW
102#define BOop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)BITOROP))
103#define BAop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)BITANDOP))
104#define SHop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)SHIFTOP))
105#define PWop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)POWOP))
79072805 106#define PMop(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)MATCHOP)
a0d0e21e
LW
107#define Aop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)ADDOP))
108#define Mop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)MULOP))
79072805
LW
109#define Eop(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)EQOP)
110#define Rop(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)RELOP)
2f3197b3 111
a687059c
LW
112/* This bit of chicanery makes a unary function followed by
113 * a parenthesis into a function with one argument, highest precedence.
114 */
2f3197b3 115#define UNI(f) return(yylval.ival = f, \
79072805 116 expect = XTERM, \
2f3197b3
LW
117 bufptr = s, \
118 last_uni = oldbufptr, \
a0d0e21e 119 last_lop_op = f, \
a687059c
LW
120 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
121
79072805
LW
122#define UNIBRACK(f) return(yylval.ival = f, \
123 bufptr = s, \
124 last_uni = oldbufptr, \
125 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
126
9f68db38 127/* grandfather return to old style */
79072805
LW
128#define OLDLOP(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)LSTOP)
129
a0d0e21e
LW
130static int
131ao(toketype)
132int toketype;
133{
134 if (*bufptr == '=') {
135 bufptr++;
136 if (toketype == ANDAND)
137 yylval.ival = OP_ANDASSIGN;
138 else if (toketype == OROR)
139 yylval.ival = OP_ORASSIGN;
140 toketype = ASSIGNOP;
141 }
142 return toketype;
143}
144
8990e307
LW
145static void
146no_op(what, s)
463ee0b2 147char *what;
8990e307 148char *s;
463ee0b2 149{
8990e307 150 char tmpbuf[128];
748a9306 151 char *oldbp = bufptr;
fd049845 152 bool is_first = (oldbufptr == linestart);
8990e307
LW
153 bufptr = s;
154 sprintf(tmpbuf, "%s found where operator expected", what);
155 yywarn(tmpbuf);
748a9306 156 if (is_first)
a0d0e21e 157 warn("\t(Missing semicolon on previous line?)\n");
748a9306
LW
158 else if (oldoldbufptr && isIDFIRST(*oldoldbufptr)) {
159 char *t;
160 for (t = oldoldbufptr; *t && (isALNUM(*t) || *t == ':'); t++) ;
161 if (t < bufptr && isSPACE(*t))
162 warn("\t(Do you need to predeclare %.*s?)\n",
163 t - oldoldbufptr, oldoldbufptr);
164
165 }
166 else
167 warn("\t(Missing operator before %.*s?)\n", s - oldbp, oldbp);
168 bufptr = oldbp;
8990e307
LW
169}
170
171static void
172missingterm(s)
173char *s;
174{
175 char tmpbuf[3];
176 char q;
177 if (s) {
178 char *nl = strrchr(s,'\n');
179 if (nl)
180 *nl = '\0';
181 }
182 else if (multi_close < 32 || multi_close == 127) {
183 *tmpbuf = '^';
184 tmpbuf[1] = multi_close ^ 64;
185 s = "\\n";
186 tmpbuf[2] = '\0';
187 s = tmpbuf;
188 }
189 else {
190 *tmpbuf = multi_close;
191 tmpbuf[1] = '\0';
192 s = tmpbuf;
193 }
194 q = strchr(s,'"') ? '\'' : '"';
195 croak("Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
463ee0b2 196}
79072805
LW
197
198void
a0d0e21e
LW
199deprecate(s)
200char *s;
201{
202 if (dowarn)
203 warn("Use of %s is deprecated", s);
204}
205
206static void
207depcom()
208{
209 deprecate("comma-less variable list");
210}
211
212void
8990e307
LW
213lex_start(line)
214SV *line;
79072805 215{
8990e307
LW
216 char *s;
217 STRLEN len;
218
463ee0b2
LW
219 SAVEINT(lex_dojoin);
220 SAVEINT(lex_brackets);
221 SAVEINT(lex_fakebrack);
222 SAVEINT(lex_casemods);
223 SAVEINT(lex_starts);
224 SAVEINT(lex_state);
a0d0e21e 225 SAVESPTR(lex_inpat);
463ee0b2
LW
226 SAVEINT(lex_inwhat);
227 SAVEINT(curcop->cop_line);
85e6fe83
LW
228 SAVEPPTR(bufptr);
229 SAVEPPTR(bufend);
230 SAVEPPTR(oldbufptr);
231 SAVEPPTR(oldoldbufptr);
fd049845 232 SAVEPPTR(linestart);
463ee0b2 233 SAVESPTR(linestr);
85e6fe83 234 SAVEPPTR(lex_brackstack);
a0d0e21e 235 SAVEPPTR(lex_casestack);
6d5fb7e3 236 SAVEDESTRUCTOR(restore_rsfp, rsfp);
463ee0b2 237
79072805
LW
238 lex_state = LEX_NORMAL;
239 lex_defer = 0;
8990e307 240 expect = XSTATE;
79072805
LW
241 lex_brackets = 0;
242 lex_fakebrack = 0;
8990e307 243 New(899, lex_brackstack, 120, char);
a0d0e21e 244 New(899, lex_casestack, 12, char);
8990e307 245 SAVEFREEPV(lex_brackstack);
a0d0e21e 246 SAVEFREEPV(lex_casestack);
79072805 247 lex_casemods = 0;
a0d0e21e 248 *lex_casestack = '\0';
79072805
LW
249 lex_dojoin = 0;
250 lex_starts = 0;
251 if (lex_stuff)
8990e307 252 SvREFCNT_dec(lex_stuff);
79072805
LW
253 lex_stuff = Nullsv;
254 if (lex_repl)
8990e307 255 SvREFCNT_dec(lex_repl);
79072805
LW
256 lex_repl = Nullsv;
257 lex_inpat = 0;
258 lex_inwhat = 0;
8990e307
LW
259 linestr = line;
260 if (SvREADONLY(linestr))
261 linestr = sv_2mortal(newSVsv(linestr));
262 s = SvPV(linestr, len);
263 if (len && s[len-1] != ';') {
a0d0e21e 264 if (!(SvFLAGS(linestr) & SVs_TEMP))
8990e307
LW
265 linestr = sv_2mortal(newSVsv(linestr));
266 sv_catpvn(linestr, "\n;", 2);
267 }
268 SvTEMP_off(linestr);
fd049845 269 oldoldbufptr = oldbufptr = bufptr = linestart = SvPVX(linestr);
79072805 270 bufend = bufptr + SvCUR(linestr);
c07a80fd
PP
271 SvREFCNT_dec(rs);
272 rs = newSVpv("\n", 1);
8990e307 273 rsfp = 0;
79072805 274}
a687059c 275
463ee0b2
LW
276void
277lex_end()
278{
463ee0b2
LW
279}
280
281static void
6d5fb7e3
CS
282restore_rsfp(f)
283void *f;
284{
760ac839 285 PerlIO *fp = (PerlIO*)f;
6d5fb7e3 286
760ac839
LW
287 if (rsfp == PerlIO_stdin())
288 PerlIO_clearerr(rsfp);
a5f75d66 289 else if (rsfp && (rsfp != fp))
760ac839 290 PerlIO_close(rsfp);
6d5fb7e3
CS
291 rsfp = fp;
292}
293
294static void
463ee0b2
LW
295incline(s)
296char *s;
297{
298 char *t;
299 char *n;
300 char ch;
301 int sawline = 0;
302
303 curcop->cop_line++;
304 if (*s++ != '#')
305 return;
306 while (*s == ' ' || *s == '\t') s++;
307 if (strnEQ(s, "line ", 5)) {
308 s += 5;
309 sawline = 1;
310 }
311 if (!isDIGIT(*s))
312 return;
313 n = s;
314 while (isDIGIT(*s))
315 s++;
316 while (*s == ' ' || *s == '\t')
317 s++;
318 if (*s == '"' && (t = strchr(s+1, '"')))
319 s++;
320 else {
321 if (!sawline)
322 return; /* false alarm */
323 for (t = s; !isSPACE(*t); t++) ;
324 }
325 ch = *t;
326 *t = '\0';
327 if (t - s > 0)
328 curcop->cop_filegv = gv_fetchfile(s);
329 else
330 curcop->cop_filegv = gv_fetchfile(origfilename);
331 *t = ch;
332 curcop->cop_line = atoi(n)-1;
333}
334
8990e307 335static char *
a687059c
LW
336skipspace(s)
337register char *s;
338{
85e6fe83 339 if (lex_formbrack && lex_brackets <= lex_formbrack) {
463ee0b2
LW
340 while (s < bufend && (*s == ' ' || *s == '\t'))
341 s++;
342 return s;
343 }
344 for (;;) {
fd049845 345 STRLEN prevlen;
463ee0b2
LW
346 while (s < bufend && isSPACE(*s))
347 s++;
348 if (s < bufend && *s == '#') {
349 while (s < bufend && *s != '\n')
350 s++;
351 if (s < bufend)
352 s++;
353 }
a0d0e21e 354 if (s < bufend || !rsfp || lex_state != LEX_NORMAL)
463ee0b2 355 return s;
fd049845 356 if ((s = filter_gets(linestr, rsfp, (prevlen = SvCUR(linestr)))) == Nullch) {
a0d0e21e
LW
357 if (minus_n || minus_p) {
358 sv_setpv(linestr,minus_p ? ";}continue{print" : "");
359 sv_catpv(linestr,";}");
360 minus_n = minus_p = 0;
361 }
362 else
363 sv_setpv(linestr,";");
fd049845 364 oldoldbufptr = oldbufptr = bufptr = s = linestart = SvPVX(linestr);
a0d0e21e
LW
365 bufend = SvPVX(linestr) + SvCUR(linestr);
366 if (preprocess && !in_eval)
8990e307 367 (void)my_pclose(rsfp);
760ac839
LW
368 else if ((PerlIO*)rsfp == PerlIO_stdin())
369 PerlIO_clearerr(rsfp);
8990e307 370 else
760ac839 371 (void)PerlIO_close(rsfp);
8990e307 372 rsfp = Nullfp;
463ee0b2
LW
373 return s;
374 }
fd049845
PP
375 linestart = bufptr = s + prevlen;
376 bufend = s + SvCUR(linestr);
377 s = bufptr;
a0d0e21e 378 incline(s);
8990e307
LW
379 if (perldb && curstash != debstash) {
380 SV *sv = NEWSV(85,0);
381
382 sv_upgrade(sv, SVt_PVMG);
fd049845 383 sv_setpvn(sv,bufptr,bufend-bufptr);
8990e307
LW
384 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
385 }
463ee0b2 386 }
a687059c 387}
378cc40b 388
8990e307 389static void
2f3197b3
LW
390check_uni() {
391 char *s;
392 char ch;
a0d0e21e 393 char *t;
2f3197b3
LW
394
395 if (oldoldbufptr != last_uni)
396 return;
397 while (isSPACE(*last_uni))
398 last_uni++;
e334a159 399 for (s = last_uni; isALNUM(*s) || *s == '-'; s++) ;
a0d0e21e
LW
400 if ((t = strchr(s, '(')) && t < bufptr)
401 return;
2f3197b3
LW
402 ch = *s;
403 *s = '\0';
404 warn("Warning: Use of \"%s\" without parens is ambiguous", last_uni);
405 *s = ch;
406}
407
ffed7fef
LW
408#ifdef CRIPPLED_CC
409
410#undef UNI
ffed7fef 411#define UNI(f) return uni(f,s)
ffed7fef 412
8990e307 413static int
ffed7fef 414uni(f,s)
79072805 415I32 f;
ffed7fef
LW
416char *s;
417{
418 yylval.ival = f;
79072805 419 expect = XTERM;
ffed7fef 420 bufptr = s;
2f3197b3 421 last_uni = oldbufptr;
a0d0e21e 422 last_lop_op = f;
ffed7fef
LW
423 if (*s == '(')
424 return FUNC1;
425 s = skipspace(s);
426 if (*s == '(')
427 return FUNC1;
428 else
429 return UNIOP;
430}
431
a0d0e21e
LW
432#endif /* CRIPPLED_CC */
433
434#define LOP(f,x) return lop(f,x,s)
435
8990e307 436static I32
a0d0e21e 437lop(f,x,s)
79072805 438I32 f;
a0d0e21e 439expectation x;
ffed7fef
LW
440char *s;
441{
79072805 442 yylval.ival = f;
35c8bce7 443 CLINE;
a0d0e21e 444 expect = x;
79072805 445 bufptr = s;
8990e307
LW
446 last_lop = oldbufptr;
447 last_lop_op = f;
a0d0e21e
LW
448 if (nexttoke)
449 return LSTOP;
79072805
LW
450 if (*s == '(')
451 return FUNC;
452 s = skipspace(s);
453 if (*s == '(')
454 return FUNC;
455 else
456 return LSTOP;
457}
458
8990e307 459static void
79072805
LW
460force_next(type)
461I32 type;
462{
463 nexttype[nexttoke] = type;
464 nexttoke++;
465 if (lex_state != LEX_KNOWNEXT) {
466 lex_defer = lex_state;
463ee0b2 467 lex_expect = expect;
79072805
LW
468 lex_state = LEX_KNOWNEXT;
469 }
470}
471
8990e307 472static char *
a0d0e21e 473force_word(start,token,check_keyword,allow_pack,allow_tick)
463ee0b2 474register char *start;
79072805 475int token;
463ee0b2 476int check_keyword;
a0d0e21e 477int allow_pack;
463ee0b2 478int allow_tick;
79072805 479{
463ee0b2
LW
480 register char *s;
481 STRLEN len;
482
483 start = skipspace(start);
484 s = start;
a0d0e21e
LW
485 if (isIDFIRST(*s) ||
486 (allow_pack && *s == ':') ||
487 (allow_tick && *s == '\'') )
488 {
489 s = scan_word(s, tokenbuf, allow_pack, &len);
463ee0b2
LW
490 if (check_keyword && keyword(tokenbuf, len))
491 return start;
492 if (token == METHOD) {
493 s = skipspace(s);
494 if (*s == '(')
495 expect = XTERM;
496 else {
497 expect = XOPERATOR;
498 force_next(')');
499 force_next('(');
500 }
79072805 501 }
463ee0b2 502 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST,0, newSVpv(tokenbuf,0));
8990e307 503 nextval[nexttoke].opval->op_private |= OPpCONST_BARE;
79072805
LW
504 force_next(token);
505 }
506 return s;
507}
508
8990e307 509static void
a0d0e21e 510force_ident(s, kind)
79072805 511register char *s;
a0d0e21e 512int kind;
79072805
LW
513{
514 if (s && *s) {
748a9306
LW
515 OP* op = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
516 nextval[nexttoke].opval = op;
79072805 517 force_next(WORD);
748a9306
LW
518 if (kind) {
519 op->op_private = OPpCONST_ENTERED;
a0d0e21e
LW
520 gv_fetchpv(s, TRUE,
521 kind == '$' ? SVt_PV :
522 kind == '@' ? SVt_PVAV :
523 kind == '%' ? SVt_PVHV :
524 SVt_PVGV
525 );
748a9306 526 }
79072805
LW
527 }
528}
529
89bfa8cd
PP
530static char *
531force_version(s)
532char *s;
533{
534 OP *version = Nullop;
535
536 s = skipspace(s);
537
538 /* default VERSION number -- GBARR */
539
540 if(isDIGIT(*s)) {
541 char *d;
542 int c;
543 for( d=s, c = 1; isDIGIT(*d) || (*d == '.' && c--); d++);
544 if((*d == ';' || isSPACE(*d)) && *(skipspace(d)) != ',') {
545 s = scan_num(s);
546 /* real VERSION number -- GBARR */
547 version = yylval.opval;
548 }
549 }
550
551 /* NOTE: The parser sees the package name and the VERSION swapped */
552 nextval[nexttoke].opval = version;
553 force_next(WORD);
554
555 return (s);
556}
557
8990e307 558static SV *
79072805
LW
559q(sv)
560SV *sv;
561{
562 register char *s;
563 register char *send;
564 register char *d;
463ee0b2 565 STRLEN len;
79072805
LW
566
567 if (!SvLEN(sv))
568 return sv;
569
a0d0e21e 570 s = SvPV_force(sv, len);
748a9306
LW
571 if (SvIVX(sv) == -1)
572 return sv;
463ee0b2 573 send = s + len;
79072805
LW
574 while (s < send && *s != '\\')
575 s++;
576 if (s == send)
577 return sv;
578 d = s;
79072805
LW
579 while (s < send) {
580 if (*s == '\\') {
a0d0e21e 581 if (s + 1 < send && (s[1] == '\\'))
79072805
LW
582 s++; /* all that, just for this */
583 }
584 *d++ = *s++;
585 }
586 *d = '\0';
463ee0b2 587 SvCUR_set(sv, d - SvPVX(sv));
79072805
LW
588
589 return sv;
590}
591
8990e307 592static I32
79072805
LW
593sublex_start()
594{
595 register I32 op_type = yylval.ival;
79072805
LW
596
597 if (op_type == OP_NULL) {
598 yylval.opval = lex_op;
599 lex_op = Nullop;
600 return THING;
601 }
602 if (op_type == OP_CONST || op_type == OP_READLINE) {
603 yylval.opval = (OP*)newSVOP(op_type, 0, q(lex_stuff));
604 lex_stuff = Nullsv;
605 return THING;
606 }
607
608 push_scope();
609 SAVEINT(lex_dojoin);
610 SAVEINT(lex_brackets);
611 SAVEINT(lex_fakebrack);
612 SAVEINT(lex_casemods);
613 SAVEINT(lex_starts);
614 SAVEINT(lex_state);
a0d0e21e 615 SAVESPTR(lex_inpat);
79072805
LW
616 SAVEINT(lex_inwhat);
617 SAVEINT(curcop->cop_line);
85e6fe83
LW
618 SAVEPPTR(bufptr);
619 SAVEPPTR(oldbufptr);
620 SAVEPPTR(oldoldbufptr);
fd049845 621 SAVEPPTR(linestart);
79072805 622 SAVESPTR(linestr);
85e6fe83 623 SAVEPPTR(lex_brackstack);
a0d0e21e 624 SAVEPPTR(lex_casestack);
79072805
LW
625
626 linestr = lex_stuff;
627 lex_stuff = Nullsv;
628
fd049845 629 bufend = bufptr = oldbufptr = oldoldbufptr = linestart = SvPVX(linestr);
79072805 630 bufend += SvCUR(linestr);
8990e307 631 SAVEFREESV(linestr);
79072805
LW
632
633 lex_dojoin = FALSE;
634 lex_brackets = 0;
635 lex_fakebrack = 0;
8990e307 636 New(899, lex_brackstack, 120, char);
a0d0e21e 637 New(899, lex_casestack, 12, char);
8990e307 638 SAVEFREEPV(lex_brackstack);
a0d0e21e 639 SAVEFREEPV(lex_casestack);
79072805 640 lex_casemods = 0;
a0d0e21e 641 *lex_casestack = '\0';
79072805
LW
642 lex_starts = 0;
643 lex_state = LEX_INTERPCONCAT;
644 curcop->cop_line = multi_start;
645
646 lex_inwhat = op_type;
647 if (op_type == OP_MATCH || op_type == OP_SUBST)
a0d0e21e 648 lex_inpat = lex_op;
79072805
LW
649 else
650 lex_inpat = 0;
651
463ee0b2 652 expect = XTERM;
79072805
LW
653 force_next('(');
654 if (lex_op) {
655 yylval.opval = lex_op;
656 lex_op = Nullop;
657 return PMFUNC;
658 }
659 else
660 return FUNC;
661}
662
8990e307 663static I32
79072805
LW
664sublex_done()
665{
666 if (!lex_starts++) {
667 expect = XOPERATOR;
93a17b20 668 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv("",0));
79072805
LW
669 return THING;
670 }
671
672 if (lex_casemods) { /* oops, we've got some unbalanced parens */
673 lex_state = LEX_INTERPCASEMOD;
674 return yylex();
675 }
676
79072805
LW
677 /* Is there a right-hand side to take care of? */
678 if (lex_repl && (lex_inwhat == OP_SUBST || lex_inwhat == OP_TRANS)) {
679 linestr = lex_repl;
680 lex_inpat = 0;
fd049845 681 bufend = bufptr = oldbufptr = oldoldbufptr = linestart = SvPVX(linestr);
79072805 682 bufend += SvCUR(linestr);
8990e307 683 SAVEFREESV(linestr);
79072805
LW
684 lex_dojoin = FALSE;
685 lex_brackets = 0;
686 lex_fakebrack = 0;
687 lex_casemods = 0;
a0d0e21e 688 *lex_casestack = '\0';
79072805
LW
689 lex_starts = 0;
690 if (SvCOMPILED(lex_repl)) {
691 lex_state = LEX_INTERPNORMAL;
692 lex_starts++;
693 }
694 else
695 lex_state = LEX_INTERPCONCAT;
696 lex_repl = Nullsv;
697 return ',';
ffed7fef
LW
698 }
699 else {
79072805 700 pop_scope();
463ee0b2 701 bufend = SvPVX(linestr);
79072805
LW
702 bufend += SvCUR(linestr);
703 expect = XOPERATOR;
704 return ')';
ffed7fef
LW
705 }
706}
707
8990e307 708static char *
79072805
LW
709scan_const(start)
710char *start;
711{
712 register char *send = bufend;
713 SV *sv = NEWSV(93, send - start);
714 register char *s = start;
463ee0b2 715 register char *d = SvPVX(sv);
79072805
LW
716 bool dorange = FALSE;
717 I32 len;
718 char *leave =
719 lex_inpat
748a9306 720 ? "\\.^$@AGZdDwWsSbB+*?|()-nrtfeaxc0123456789[{]} \t\n\r\f\v#"
79072805
LW
721 : (lex_inwhat & OP_TRANS)
722 ? ""
723 : "";
724
725 while (s < send || dorange) {
726 if (lex_inwhat == OP_TRANS) {
727 if (dorange) {
728 I32 i;
729 I32 max;
463ee0b2 730 i = d - SvPVX(sv);
79072805 731 SvGROW(sv, SvLEN(sv) + 256);
463ee0b2 732 d = SvPVX(sv) + i;
79072805 733 d -= 2;
91b7def8
PP
734 max = (U8)d[1];
735 for (i = (U8)*d; i <= max; i++)
79072805
LW
736 *d++ = i;
737 dorange = FALSE;
738 continue;
739 }
740 else if (*s == '-' && s+1 < send && s != start) {
741 dorange = TRUE;
742 s++;
743 }
744 }
748a9306
LW
745 else if (*s == '(' && lex_inpat && s[1] == '?' && s[2] == '#') {
746 while (s < send && *s != ')')
747 *d++ = *s++;
748 }
749 else if (*s == '#' && lex_inpat &&
750 ((PMOP*)lex_inpat)->op_pmflags & PMf_EXTENDED) {
751 while (s+1 < send && *s != '\n')
752 *d++ = *s++;
753 }
a0d0e21e 754 else if (*s == '@' && s[1] && (isALNUM(s[1]) || strchr(":'{$", s[1])))
79072805
LW
755 break;
756 else if (*s == '$') {
757 if (!lex_inpat) /* not a regexp, so $ must be var */
758 break;
a0d0e21e 759 if (s + 1 < send && !strchr(")| \n\t", s[1]))
79072805
LW
760 break; /* in regexp, $ might be tail anchor */
761 }
762 if (*s == '\\' && s+1 < send) {
763 s++;
93a17b20 764 if (*s && strchr(leave, *s)) {
79072805
LW
765 *d++ = '\\';
766 *d++ = *s++;
767 continue;
768 }
769 if (lex_inwhat == OP_SUBST && !lex_inpat &&
a0d0e21e 770 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
79072805 771 {
a0d0e21e
LW
772 if (dowarn)
773 warn("\\%c better written as $%c", *s, *s);
79072805
LW
774 *--s = '$';
775 break;
776 }
a0d0e21e 777 if (lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
79072805
LW
778 --s;
779 break;
780 }
781 switch (*s) {
782 case '-':
783 if (lex_inwhat == OP_TRANS) {
784 *d++ = *s++;
785 continue;
786 }
787 /* FALL THROUGH */
788 default:
789 *d++ = *s++;
790 continue;
791 case '0': case '1': case '2': case '3':
792 case '4': case '5': case '6': case '7':
793 *d++ = scan_oct(s, 3, &len);
794 s += len;
795 continue;
796 case 'x':
797 *d++ = scan_hex(++s, 2, &len);
798 s += len;
799 continue;
800 case 'c':
801 s++;
802 *d = *s++;
803 if (isLOWER(*d))
a0d0e21e 804 *d = toUPPER(*d);
79072805
LW
805 *d++ ^= 64;
806 continue;
807 case 'b':
808 *d++ = '\b';
809 break;
810 case 'n':
811 *d++ = '\n';
812 break;
813 case 'r':
814 *d++ = '\r';
815 break;
816 case 'f':
817 *d++ = '\f';
818 break;
819 case 't':
820 *d++ = '\t';
821 break;
822 case 'e':
823 *d++ = '\033';
824 break;
825 case 'a':
826 *d++ = '\007';
827 break;
828 }
829 s++;
830 continue;
831 }
832 *d++ = *s++;
833 }
834 *d = '\0';
463ee0b2 835 SvCUR_set(sv, d - SvPVX(sv));
79072805
LW
836 SvPOK_on(sv);
837
838 if (SvCUR(sv) + 5 < SvLEN(sv)) {
839 SvLEN_set(sv, SvCUR(sv) + 1);
463ee0b2 840 Renew(SvPVX(sv), SvLEN(sv), char);
79072805
LW
841 }
842 if (s > bufptr)
843 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
844 else
8990e307 845 SvREFCNT_dec(sv);
79072805
LW
846 return s;
847}
848
849/* This is the one truly awful dwimmer necessary to conflate C and sed. */
8990e307 850static int
79072805
LW
851intuit_more(s)
852register char *s;
853{
854 if (lex_brackets)
855 return TRUE;
856 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
857 return TRUE;
858 if (*s != '{' && *s != '[')
859 return FALSE;
860 if (!lex_inpat)
861 return TRUE;
862
863 /* In a pattern, so maybe we have {n,m}. */
864 if (*s == '{') {
865 s++;
866 if (!isDIGIT(*s))
867 return TRUE;
868 while (isDIGIT(*s))
869 s++;
870 if (*s == ',')
871 s++;
872 while (isDIGIT(*s))
873 s++;
874 if (*s == '}')
875 return FALSE;
876 return TRUE;
877
878 }
879
880 /* On the other hand, maybe we have a character class */
881
882 s++;
883 if (*s == ']' || *s == '^')
884 return FALSE;
885 else {
886 int weight = 2; /* let's weigh the evidence */
887 char seen[256];
888 unsigned char un_char = 0, last_un_char;
93a17b20 889 char *send = strchr(s,']');
79072805
LW
890 char tmpbuf[512];
891
892 if (!send) /* has to be an expression */
893 return TRUE;
894
895 Zero(seen,256,char);
896 if (*s == '$')
897 weight -= 3;
898 else if (isDIGIT(*s)) {
899 if (s[1] != ']') {
900 if (isDIGIT(s[1]) && s[2] == ']')
901 weight -= 10;
902 }
903 else
904 weight -= 100;
905 }
906 for (; s < send; s++) {
907 last_un_char = un_char;
908 un_char = (unsigned char)*s;
909 switch (*s) {
910 case '@':
911 case '&':
912 case '$':
913 weight -= seen[un_char] * 10;
914 if (isALNUM(s[1])) {
915 scan_ident(s,send,tmpbuf,FALSE);
a0d0e21e 916 if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV))
79072805
LW
917 weight -= 100;
918 else
919 weight -= 10;
920 }
921 else if (*s == '$' && s[1] &&
93a17b20
LW
922 strchr("[#!%*<>()-=",s[1])) {
923 if (/*{*/ strchr("])} =",s[2]))
79072805
LW
924 weight -= 10;
925 else
926 weight -= 1;
927 }
928 break;
929 case '\\':
930 un_char = 254;
931 if (s[1]) {
93a17b20 932 if (strchr("wds]",s[1]))
79072805
LW
933 weight += 100;
934 else if (seen['\''] || seen['"'])
935 weight += 1;
93a17b20 936 else if (strchr("rnftbxcav",s[1]))
79072805
LW
937 weight += 40;
938 else if (isDIGIT(s[1])) {
939 weight += 40;
940 while (s[1] && isDIGIT(s[1]))
941 s++;
942 }
943 }
944 else
945 weight += 100;
946 break;
947 case '-':
948 if (s[1] == '\\')
949 weight += 50;
93a17b20 950 if (strchr("aA01! ",last_un_char))
79072805 951 weight += 30;
93a17b20 952 if (strchr("zZ79~",s[1]))
79072805
LW
953 weight += 30;
954 break;
955 default:
93a17b20 956 if (!isALNUM(last_un_char) && !strchr("$@&",last_un_char) &&
79072805
LW
957 isALPHA(*s) && s[1] && isALPHA(s[1])) {
958 char *d = tmpbuf;
959 while (isALPHA(*s))
960 *d++ = *s++;
961 *d = '\0';
962 if (keyword(tmpbuf, d - tmpbuf))
963 weight -= 150;
964 }
965 if (un_char == last_un_char + 1)
966 weight += 5;
967 weight -= seen[un_char];
968 break;
969 }
970 seen[un_char]++;
971 }
972 if (weight >= 0) /* probably a character class */
973 return FALSE;
974 }
975
976 return TRUE;
977}
ffed7fef 978
a0d0e21e
LW
979static int
980intuit_method(start,gv)
981char *start;
982GV *gv;
983{
984 char *s = start + (*start == '$');
985 char tmpbuf[1024];
986 STRLEN len;
987 GV* indirgv;
988
989 if (gv) {
990 if (GvIO(gv))
991 return 0;
992 if (!GvCV(gv))
993 gv = 0;
994 }
995 s = scan_word(s, tmpbuf, TRUE, &len);
996 if (*start == '$') {
997 if (gv || last_lop_op == OP_PRINT || isUPPER(*tokenbuf))
998 return 0;
999 s = skipspace(s);
1000 bufptr = start;
1001 expect = XREF;
1002 return *s == '(' ? FUNCMETH : METHOD;
1003 }
1004 if (!keyword(tmpbuf, len)) {
1005 indirgv = gv_fetchpv(tmpbuf,FALSE, SVt_PVCV);
1006 if (indirgv && GvCV(indirgv))
1007 return 0;
1008 /* filehandle or package name makes it a method */
89bfa8cd 1009 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
a0d0e21e
LW
1010 s = skipspace(s);
1011 nextval[nexttoke].opval =
1012 (OP*)newSVOP(OP_CONST, 0,
1013 newSVpv(tmpbuf,0));
1014 nextval[nexttoke].opval->op_private =
1015 OPpCONST_BARE;
1016 expect = XTERM;
1017 force_next(WORD);
1018 bufptr = s;
1019 return *s == '(' ? FUNCMETH : METHOD;
1020 }
1021 }
1022 return 0;
1023}
1024
1025static char*
1026incl_perldb()
1027{
1028 if (perldb) {
1029 char *pdb = getenv("PERL5DB");
1030
1031 if (pdb)
1032 return pdb;
1033 return "BEGIN { require 'perl5db.pl' }";
1034 }
1035 return "";
1036}
1037
1038
16d20bd9
AD
1039/* Encoded script support. filter_add() effectively inserts a
1040 * 'pre-processing' function into the current source input stream.
1041 * Note that the filter function only applies to the current source file
1042 * (e.g., it will not affect files 'require'd or 'use'd by this one).
1043 *
1044 * The datasv parameter (which may be NULL) can be used to pass
1045 * private data to this instance of the filter. The filter function
1046 * can recover the SV using the FILTER_DATA macro and use it to
1047 * store private buffers and state information.
1048 *
1049 * The supplied datasv parameter is upgraded to a PVIO type
1050 * and the IoDIRP field is used to store the function pointer.
1051 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
1052 * private use must be set using malloc'd pointers.
1053 */
1054static int filter_debug = 0;
1055
1056SV *
1057filter_add(funcp, datasv)
1058 filter_t funcp;
1059 SV *datasv;
1060{
1061 if (!funcp){ /* temporary handy debugging hack to be deleted */
1062 filter_debug = atoi((char*)datasv);
1063 return NULL;
1064 }
1065 if (!rsfp_filters)
1066 rsfp_filters = newAV();
1067 if (!datasv)
1068 datasv = newSV(0);
1069 if (!SvUPGRADE(datasv, SVt_PVIO))
1070 die("Can't upgrade filter_add data to SVt_PVIO");
1071 IoDIRP(datasv) = (DIR*)funcp; /* stash funcp into spare field */
1072 if (filter_debug)
1073 warn("filter_add func %lx (%s)", funcp, SvPV(datasv,na));
e50aee73
AD
1074 av_unshift(rsfp_filters, 1);
1075 av_store(rsfp_filters, 0, datasv) ;
16d20bd9
AD
1076 return(datasv);
1077}
1078
1079
1080/* Delete most recently added instance of this filter function. */
a0d0e21e 1081void
16d20bd9
AD
1082filter_del(funcp)
1083 filter_t funcp;
1084{
1085 if (filter_debug)
1086 warn("filter_del func %lx", funcp);
1087 if (!rsfp_filters || AvFILL(rsfp_filters)<0)
1088 return;
1089 /* if filter is on top of stack (usual case) just pop it off */
e50aee73
AD
1090 if (IoDIRP(FILTER_DATA(0)) == (void*)funcp){
1091 /* sv_free(av_pop(rsfp_filters)); */
1092 sv_free(av_shift(rsfp_filters));
1093
16d20bd9
AD
1094 return;
1095 }
1096 /* we need to search for the correct entry and clear it */
1097 die("filter_del can only delete in reverse order (currently)");
1098}
1099
1100
1101/* Invoke the n'th filter function for the current rsfp. */
1102I32
1103filter_read(idx, buf_sv, maxlen)
1104 int idx;
1105 SV *buf_sv;
1106 int maxlen; /* 0 = read one text line */
a0d0e21e 1107{
16d20bd9
AD
1108 filter_t funcp;
1109 SV *datasv = NULL;
e50aee73 1110
16d20bd9
AD
1111 if (!rsfp_filters)
1112 return -1;
1113 if (idx > AvFILL(rsfp_filters)){ /* Any more filters? */
1114 /* Provide a default input filter to make life easy. */
1115 /* Note that we append to the line. This is handy. */
16d20bd9
AD
1116 if (filter_debug)
1117 warn("filter_read %d: from rsfp\n", idx);
1118 if (maxlen) {
1119 /* Want a block */
1120 int len ;
1121 int old_len = SvCUR(buf_sv) ;
1122
1123 /* ensure buf_sv is large enough */
1124 SvGROW(buf_sv, old_len + maxlen) ;
760ac839
LW
1125 if ((len = PerlIO_read(rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
1126 if (PerlIO_error(rsfp))
37120919
AD
1127 return -1; /* error */
1128 else
1129 return 0 ; /* end of file */
1130 }
16d20bd9
AD
1131 SvCUR_set(buf_sv, old_len + len) ;
1132 } else {
1133 /* Want a line */
37120919 1134 if (sv_gets(buf_sv, rsfp, SvCUR(buf_sv)) == NULL) {
760ac839 1135 if (PerlIO_error(rsfp))
37120919
AD
1136 return -1; /* error */
1137 else
1138 return 0 ; /* end of file */
1139 }
16d20bd9
AD
1140 }
1141 return SvCUR(buf_sv);
1142 }
1143 /* Skip this filter slot if filter has been deleted */
1144 if ( (datasv = FILTER_DATA(idx)) == &sv_undef){
1145 if (filter_debug)
1146 warn("filter_read %d: skipped (filter deleted)\n", idx);
1147 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
1148 }
1149 /* Get function pointer hidden within datasv */
1150 funcp = (filter_t)IoDIRP(datasv);
1151 if (filter_debug)
1152 warn("filter_read %d: via function %lx (%s)\n",
1153 idx, funcp, SvPV(datasv,na));
1154 /* Call function. The function is expected to */
1155 /* call "FILTER_READ(idx+1, buf_sv)" first. */
37120919 1156 /* Return: <0:error, =0:eof, >0:not eof */
16d20bd9
AD
1157 return (*funcp)(idx, buf_sv, maxlen);
1158}
1159
1160static char *
fd049845 1161filter_gets(sv,fp, append)
16d20bd9 1162register SV *sv;
760ac839 1163register PerlIO *fp;
fd049845 1164STRLEN append;
16d20bd9
AD
1165{
1166 if (rsfp_filters) {
1167
1168 SvCUR_set(sv, 0); /* start with empty line */
1169 if (FILTER_READ(0, sv, 0) > 0)
1170 return ( SvPVX(sv) ) ;
1171 else
1172 return Nullch ;
1173 }
1174 else
fd049845 1175 return (sv_gets(sv, fp, append));
16d20bd9 1176
a0d0e21e
LW
1177}
1178
1179
748a9306
LW
1180#ifdef DEBUGGING
1181 static char* exp_name[] =
a0d0e21e 1182 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "TERMBLOCK" };
748a9306 1183#endif
463ee0b2
LW
1184
1185extern int yychar; /* last token */
1186
2f3197b3 1187int
378cc40b
LW
1188yylex()
1189{
79072805 1190 register char *s;
378cc40b 1191 register char *d;
79072805 1192 register I32 tmp;
463ee0b2 1193 STRLEN len;
a687059c 1194
79072805
LW
1195 switch (lex_state) {
1196#ifdef COMMENTARY
1197 case LEX_NORMAL: /* Some compilers will produce faster */
1198 case LEX_INTERPNORMAL: /* code if we comment these out. */
1199 break;
1200#endif
1201
1202 case LEX_KNOWNEXT:
1203 nexttoke--;
1204 yylval = nextval[nexttoke];
463ee0b2 1205 if (!nexttoke) {
79072805 1206 lex_state = lex_defer;
463ee0b2 1207 expect = lex_expect;
a0d0e21e 1208 lex_defer = LEX_NORMAL;
463ee0b2 1209 }
79072805
LW
1210 return(nexttype[nexttoke]);
1211
1212 case LEX_INTERPCASEMOD:
1213#ifdef DEBUGGING
1214 if (bufptr != bufend && *bufptr != '\\')
463ee0b2 1215 croak("panic: INTERPCASEMOD");
79072805
LW
1216#endif
1217 if (bufptr == bufend || bufptr[1] == 'E') {
a0d0e21e 1218 char oldmod;
79072805 1219 if (lex_casemods) {
a0d0e21e
LW
1220 oldmod = lex_casestack[--lex_casemods];
1221 lex_casestack[lex_casemods] = '\0';
1222 if (bufptr != bufend && strchr("LUQ", oldmod)) {
1223 bufptr += 2;
1224 lex_state = LEX_INTERPCONCAT;
1225 }
79072805
LW
1226 return ')';
1227 }
a0d0e21e
LW
1228 if (bufptr != bufend)
1229 bufptr += 2;
1230 lex_state = LEX_INTERPCONCAT;
79072805
LW
1231 return yylex();
1232 }
1233 else {
1234 s = bufptr + 1;
1235 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
1236 tmp = *s, *s = s[2], s[2] = tmp; /* misordered... */
a0d0e21e
LW
1237 if (strchr("LU", *s) &&
1238 (strchr(lex_casestack, 'L') || strchr(lex_casestack, 'U')))
1239 {
1240 lex_casestack[--lex_casemods] = '\0';
1241 return ')';
1242 }
1243 if (lex_casemods > 10) {
89bfa8cd 1244 char* newlb = Renew(lex_casestack, lex_casemods + 2, char);
a0d0e21e
LW
1245 if (newlb != lex_casestack) {
1246 SAVEFREEPV(newlb);
1247 lex_casestack = newlb;
1248 }
1249 }
1250 lex_casestack[lex_casemods++] = *s;
1251 lex_casestack[lex_casemods] = '\0';
79072805
LW
1252 lex_state = LEX_INTERPCONCAT;
1253 nextval[nexttoke].ival = 0;
1254 force_next('(');
1255 if (*s == 'l')
1256 nextval[nexttoke].ival = OP_LCFIRST;
1257 else if (*s == 'u')
1258 nextval[nexttoke].ival = OP_UCFIRST;
1259 else if (*s == 'L')
1260 nextval[nexttoke].ival = OP_LC;
1261 else if (*s == 'U')
1262 nextval[nexttoke].ival = OP_UC;
a0d0e21e
LW
1263 else if (*s == 'Q')
1264 nextval[nexttoke].ival = OP_QUOTEMETA;
79072805 1265 else
463ee0b2 1266 croak("panic: yylex");
79072805
LW
1267 bufptr = s + 1;
1268 force_next(FUNC);
1269 if (lex_starts) {
1270 s = bufptr;
463ee0b2 1271 lex_starts = 0;
79072805
LW
1272 Aop(OP_CONCAT);
1273 }
1274 else
1275 return yylex();
1276 }
1277
1278 case LEX_INTERPSTART:
1279 if (bufptr == bufend)
1280 return sublex_done();
1281 expect = XTERM;
1282 lex_dojoin = (*bufptr == '@');
1283 lex_state = LEX_INTERPNORMAL;
1284 if (lex_dojoin) {
1285 nextval[nexttoke].ival = 0;
1286 force_next(',');
a0d0e21e 1287 force_ident("\"", '$');
79072805
LW
1288 nextval[nexttoke].ival = 0;
1289 force_next('$');
1290 nextval[nexttoke].ival = 0;
1291 force_next('(');
1292 nextval[nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
1293 force_next(FUNC);
1294 }
1295 if (lex_starts++) {
1296 s = bufptr;
1297 Aop(OP_CONCAT);
1298 }
1299 else
1300 return yylex();
1301 break;
1302
1303 case LEX_INTERPENDMAYBE:
1304 if (intuit_more(bufptr)) {
1305 lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
1306 break;
1307 }
1308 /* FALL THROUGH */
1309
1310 case LEX_INTERPEND:
1311 if (lex_dojoin) {
1312 lex_dojoin = FALSE;
1313 lex_state = LEX_INTERPCONCAT;
1314 return ')';
1315 }
1316 /* FALLTHROUGH */
1317 case LEX_INTERPCONCAT:
1318#ifdef DEBUGGING
1319 if (lex_brackets)
463ee0b2 1320 croak("panic: INTERPCONCAT");
79072805
LW
1321#endif
1322 if (bufptr == bufend)
1323 return sublex_done();
1324
ed6116ce 1325 if (SvIVX(linestr) == '\'') {
79072805
LW
1326 SV *sv = newSVsv(linestr);
1327 if (!lex_inpat)
1328 sv = q(sv);
1329 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1330 s = bufend;
1331 }
1332 else {
1333 s = scan_const(bufptr);
1334 if (*s == '\\')
1335 lex_state = LEX_INTERPCASEMOD;
1336 else
1337 lex_state = LEX_INTERPSTART;
1338 }
1339
1340 if (s != bufptr) {
1341 nextval[nexttoke] = yylval;
463ee0b2 1342 expect = XTERM;
79072805
LW
1343 force_next(THING);
1344 if (lex_starts++)
1345 Aop(OP_CONCAT);
1346 else {
1347 bufptr = s;
1348 return yylex();
1349 }
1350 }
1351
1352 return yylex();
a0d0e21e
LW
1353 case LEX_FORMLINE:
1354 lex_state = LEX_NORMAL;
1355 s = scan_formline(bufptr);
1356 if (!lex_formbrack)
1357 goto rightbracket;
1358 OPERATOR(';');
79072805
LW
1359 }
1360
1361 s = bufptr;
a687059c
LW
1362 oldoldbufptr = oldbufptr;
1363 oldbufptr = s;
79072805 1364 DEBUG_p( {
760ac839 1365 PerlIO_printf(PerlIO_stderr(), "### Tokener expecting %s at %s\n", exp_name[expect], s);
79072805 1366 } )
463ee0b2
LW
1367
1368 retry:
378cc40b
LW
1369 switch (*s) {
1370 default:
a0d0e21e 1371 warn("Unrecognized character \\%03o ignored", *s++ & 255);
378cc40b 1372 goto retry;
e929a76b
LW
1373 case 4:
1374 case 26:
1375 goto fake_eof; /* emulate EOF on ^D or ^Z */
378cc40b 1376 case 0:
463ee0b2
LW
1377 if (!rsfp) {
1378 if (lex_brackets)
1379 yyerror("Missing right bracket");
79072805 1380 TOKEN(0);
463ee0b2 1381 }
a687059c
LW
1382 if (s++ < bufend)
1383 goto retry; /* ignore stray nulls */
2f3197b3 1384 last_uni = 0;
79072805 1385 last_lop = 0;
a0d0e21e 1386 if (!in_eval && !preambled) {
79072805 1387 preambled = TRUE;
a0d0e21e 1388 sv_setpv(linestr,incl_perldb());
91b7def8
PP
1389 if (SvCUR(linestr))
1390 sv_catpv(linestr,";");
1391 if (preambleav){
1392 while(AvFILL(preambleav) >= 0) {
1393 SV *tmpsv = av_shift(preambleav);
1394 sv_catsv(linestr, tmpsv);
1395 sv_catpv(linestr, ";");
1396 sv_free(tmpsv);
1397 }
1398 sv_free((SV*)preambleav);
1399 preambleav = NULL;
1400 }
79072805
LW
1401 if (minus_n || minus_p) {
1402 sv_catpv(linestr, "LINE: while (<>) {");
1403 if (minus_l)
a0d0e21e 1404 sv_catpv(linestr,"chomp;");
2304df62
AD
1405 if (minus_a){
1406 if (minus_F){
1407 char tmpbuf1[50];
1408 if ( splitstr[0] == '/' ||
1409 splitstr[0] == '\'' ||
1410 splitstr[0] == '"' )
1411 sprintf( tmpbuf1, "@F=split(%s);", splitstr );
1412 else
1413 sprintf( tmpbuf1, "@F=split('%s');", splitstr );
1414 sv_catpv(linestr,tmpbuf1);
1415 }
1416 else
1417 sv_catpv(linestr,"@F=split(' ');");
1418 }
79072805 1419 }
a0d0e21e 1420 sv_catpv(linestr, "\n");
fd049845 1421 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
463ee0b2 1422 bufend = SvPVX(linestr) + SvCUR(linestr);
a0d0e21e
LW
1423 if (perldb && curstash != debstash) {
1424 SV *sv = NEWSV(85,0);
1425
1426 sv_upgrade(sv, SVt_PVMG);
1427 sv_setsv(sv,linestr);
1428 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
1429 }
79072805 1430 goto retry;
a687059c 1431 }
e929a76b 1432 do {
fd049845 1433 if ((s = filter_gets(linestr, rsfp, 0)) == Nullch) {
e929a76b 1434 fake_eof:
395c3793 1435 if (rsfp) {
a0d0e21e 1436 if (preprocess && !in_eval)
79072805 1437 (void)my_pclose(rsfp);
760ac839
LW
1438 else if ((PerlIO *)rsfp == PerlIO_stdin())
1439 PerlIO_clearerr(rsfp);
395c3793 1440 else
760ac839 1441 (void)PerlIO_close(rsfp);
395c3793
LW
1442 rsfp = Nullfp;
1443 }
a0d0e21e 1444 if (!in_eval && (minus_n || minus_p)) {
79072805
LW
1445 sv_setpv(linestr,minus_p ? ";}continue{print" : "");
1446 sv_catpv(linestr,";}");
fd049845 1447 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
463ee0b2 1448 bufend = SvPVX(linestr) + SvCUR(linestr);
e929a76b
LW
1449 minus_n = minus_p = 0;
1450 goto retry;
1451 }
fd049845 1452 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
79072805
LW
1453 sv_setpv(linestr,"");
1454 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
378cc40b 1455 }
a0d0e21e
LW
1456 if (doextract) {
1457 if (*s == '#' && s[1] == '!' && instr(s,"perl"))
1458 doextract = FALSE;
1459
1460 /* Incest with pod. */
1461 if (*s == '=' && strnEQ(s, "=cut", 4)) {
1462 sv_setpv(linestr, "");
fd049845 1463 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
a0d0e21e
LW
1464 bufend = SvPVX(linestr) + SvCUR(linestr);
1465 doextract = FALSE;
1466 }
1467 }
463ee0b2 1468 incline(s);
e929a76b 1469 } while (doextract);
fd049845 1470 oldoldbufptr = oldbufptr = bufptr = linestart = s;
8990e307 1471 if (perldb && curstash != debstash) {
79072805 1472 SV *sv = NEWSV(85,0);
a687059c 1473
93a17b20 1474 sv_upgrade(sv, SVt_PVMG);
79072805
LW
1475 sv_setsv(sv,linestr);
1476 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
a687059c 1477 }
463ee0b2 1478 bufend = SvPVX(linestr) + SvCUR(linestr);
79072805
LW
1479 if (curcop->cop_line == 1) {
1480 while (s < bufend && isSPACE(*s))
1481 s++;
a0d0e21e 1482 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
79072805 1483 s++;
a0d0e21e 1484 if (!in_eval && *s == '#' && s[1] == '!') {
748a9306
LW
1485 d = instr(s,"perl -");
1486 if (!d)
1487 d = instr(s,"perl");
1488 if (!d &&
1489 !minus_c &&
1490 !instr(s,"indir") &&
1491 instr(origargv[0],"perl"))
1492 {
9f68db38
LW
1493 char **newargv;
1494 char *cmd;
1495
1496 s += 2;
1497 if (*s == ' ')
1498 s++;
1499 cmd = s;
de3bb511 1500 while (s < bufend && !isSPACE(*s))
9f68db38
LW
1501 s++;
1502 *s++ = '\0';
de3bb511 1503 while (s < bufend && isSPACE(*s))
9f68db38
LW
1504 s++;
1505 if (s < bufend) {
1506 Newz(899,newargv,origargc+3,char*);
1507 newargv[1] = s;
de3bb511 1508 while (s < bufend && !isSPACE(*s))
9f68db38
LW
1509 s++;
1510 *s = '\0';
1511 Copy(origargv+1, newargv+2, origargc+1, char*);
1512 }
1513 else
1514 newargv = origargv;
1515 newargv[0] = cmd;
1516 execv(cmd,newargv);
463ee0b2 1517 croak("Can't exec %s", cmd);
9f68db38 1518 }
748a9306 1519 if (d) {
a0d0e21e
LW
1520 int oldpdb = perldb;
1521 int oldn = minus_n;
1522 int oldp = minus_p;
748a9306
LW
1523
1524 while (*d && !isSPACE(*d)) d++;
89bfa8cd 1525 while (*d == ' ' || *d == '\t') d++;
748a9306
LW
1526
1527 if (*d++ == '-') {
1528 while (d = moreswitches(d)) ;
1529 if (perldb && !oldpdb ||
b084f20b
PP
1530 ( minus_n || minus_p ) && !(oldn || oldp) )
1531 /* if we have already added "LINE: while (<>) {",
1532 we must not do it again */
748a9306
LW
1533 {
1534 sv_setpv(linestr, "");
fd049845 1535 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
748a9306
LW
1536 bufend = SvPVX(linestr) + SvCUR(linestr);
1537 preambled = FALSE;
1538 if (perldb)
1539 (void)gv_fetchfile(origfilename);
1540 goto retry;
1541 }
a0d0e21e 1542 }
79072805 1543 }
9f68db38 1544 }
79072805 1545 }
85e6fe83 1546 if (lex_formbrack && lex_brackets <= lex_formbrack) {
a0d0e21e
LW
1547 bufptr = s;
1548 lex_state = LEX_FORMLINE;
1549 return yylex();
ae986130 1550 }
378cc40b 1551 goto retry;
fe14fcc3 1552 case ' ': case '\t': case '\f': case '\r': case 013:
378cc40b
LW
1553 s++;
1554 goto retry;
378cc40b 1555 case '#':
e929a76b 1556 case '\n':
79072805 1557 if (lex_state != LEX_NORMAL || (in_eval && !rsfp)) {
a687059c
LW
1558 d = bufend;
1559 while (s < d && *s != '\n')
378cc40b 1560 s++;
0f85fab0 1561 if (s < d)
378cc40b 1562 s++;
463ee0b2 1563 incline(s);
85e6fe83 1564 if (lex_formbrack && lex_brackets <= lex_formbrack) {
a0d0e21e
LW
1565 bufptr = s;
1566 lex_state = LEX_FORMLINE;
1567 return yylex();
a687059c 1568 }
378cc40b 1569 }
a687059c 1570 else {
378cc40b 1571 *s = '\0';
a687059c
LW
1572 bufend = s;
1573 }
378cc40b
LW
1574 goto retry;
1575 case '-':
79072805 1576 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
378cc40b 1577 s++;
748a9306
LW
1578 bufptr = s;
1579 tmp = *s++;
1580
1581 while (s < bufend && (*s == ' ' || *s == '\t'))
1582 s++;
1583
1584 if (strnEQ(s,"=>",2)) {
1585 if (dowarn)
1586 warn("Ambiguous use of -%c => resolved to \"-%c\" =>",
1587 tmp, tmp);
1588 s = force_word(bufptr,WORD,FALSE,FALSE,FALSE);
1589 OPERATOR('-'); /* unary minus */
1590 }
e334a159 1591 last_uni = oldbufptr;
a0d0e21e 1592 last_lop_op = OP_FTEREAD; /* good enough */
748a9306 1593 switch (tmp) {
79072805
LW
1594 case 'r': FTST(OP_FTEREAD);
1595 case 'w': FTST(OP_FTEWRITE);
1596 case 'x': FTST(OP_FTEEXEC);
1597 case 'o': FTST(OP_FTEOWNED);
1598 case 'R': FTST(OP_FTRREAD);
1599 case 'W': FTST(OP_FTRWRITE);
1600 case 'X': FTST(OP_FTREXEC);
1601 case 'O': FTST(OP_FTROWNED);
1602 case 'e': FTST(OP_FTIS);
1603 case 'z': FTST(OP_FTZERO);
1604 case 's': FTST(OP_FTSIZE);
1605 case 'f': FTST(OP_FTFILE);
1606 case 'd': FTST(OP_FTDIR);
1607 case 'l': FTST(OP_FTLINK);
1608 case 'p': FTST(OP_FTPIPE);
1609 case 'S': FTST(OP_FTSOCK);
1610 case 'u': FTST(OP_FTSUID);
1611 case 'g': FTST(OP_FTSGID);
1612 case 'k': FTST(OP_FTSVTX);
1613 case 'b': FTST(OP_FTBLK);
1614 case 'c': FTST(OP_FTCHR);
1615 case 't': FTST(OP_FTTTY);
1616 case 'T': FTST(OP_FTTEXT);
1617 case 'B': FTST(OP_FTBINARY);
85e6fe83
LW
1618 case 'M': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTMTIME);
1619 case 'A': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTATIME);
1620 case 'C': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTCTIME);
378cc40b 1621 default:
748a9306 1622 croak("Unrecognized file test: -%c", tmp);
378cc40b
LW
1623 break;
1624 }
1625 }
a687059c
LW
1626 tmp = *s++;
1627 if (*s == tmp) {
1628 s++;
79072805
LW
1629 if (expect == XOPERATOR)
1630 TERM(POSTDEC);
1631 else
1632 OPERATOR(PREDEC);
1633 }
1634 else if (*s == '>') {
1635 s++;
1636 s = skipspace(s);
1637 if (isIDFIRST(*s)) {
a0d0e21e 1638 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
463ee0b2 1639 TOKEN(ARROW);
79072805 1640 }
748a9306
LW
1641 else if (*s == '$')
1642 OPERATOR(ARROW);
463ee0b2 1643 else
748a9306 1644 TERM(ARROW);
a687059c 1645 }
79072805
LW
1646 if (expect == XOPERATOR)
1647 Aop(OP_SUBTRACT);
1648 else {
2f3197b3
LW
1649 if (isSPACE(*s) || !isSPACE(*bufptr))
1650 check_uni();
79072805 1651 OPERATOR('-'); /* unary minus */
2f3197b3 1652 }
79072805 1653
378cc40b 1654 case '+':
a687059c
LW
1655 tmp = *s++;
1656 if (*s == tmp) {
378cc40b 1657 s++;
79072805
LW
1658 if (expect == XOPERATOR)
1659 TERM(POSTINC);
1660 else
1661 OPERATOR(PREINC);
378cc40b 1662 }
79072805
LW
1663 if (expect == XOPERATOR)
1664 Aop(OP_ADD);
1665 else {
2f3197b3
LW
1666 if (isSPACE(*s) || !isSPACE(*bufptr))
1667 check_uni();
a687059c 1668 OPERATOR('+');
2f3197b3 1669 }
a687059c 1670
378cc40b 1671 case '*':
79072805
LW
1672 if (expect != XOPERATOR) {
1673 s = scan_ident(s, bufend, tokenbuf, TRUE);
463ee0b2 1674 expect = XOPERATOR;
a0d0e21e
LW
1675 force_ident(tokenbuf, '*');
1676 if (!*tokenbuf)
1677 PREREF('*');
79072805 1678 TERM('*');
a687059c 1679 }
79072805
LW
1680 s++;
1681 if (*s == '*') {
a687059c 1682 s++;
79072805 1683 PWop(OP_POW);
a687059c 1684 }
79072805
LW
1685 Mop(OP_MULTIPLY);
1686
378cc40b 1687 case '%':
79072805 1688 if (expect != XOPERATOR) {
93a17b20
LW
1689 s = scan_ident(s, bufend, tokenbuf + 1, TRUE);
1690 if (tokenbuf[1]) {
463ee0b2 1691 expect = XOPERATOR;
93a17b20
LW
1692 tokenbuf[0] = '%';
1693 if (in_my) {
463ee0b2 1694 if (strchr(tokenbuf,':'))
748a9306 1695 croak(no_myglob,tokenbuf);
ed6116ce 1696 nextval[nexttoke].opval = newOP(OP_PADANY, 0);
93a17b20
LW
1697 nextval[nexttoke].opval->op_targ = pad_allocmy(tokenbuf);
1698 force_next(PRIVATEREF);
1699 TERM('%');
1700 }
463ee0b2 1701 if (!strchr(tokenbuf,':')) {
93a17b20 1702 if (tmp = pad_findmy(tokenbuf)) {
ed6116ce 1703 nextval[nexttoke].opval = newOP(OP_PADANY, 0);
93a17b20
LW
1704 nextval[nexttoke].opval->op_targ = tmp;
1705 force_next(PRIVATEREF);
1706 TERM('%');
1707 }
1708 }
a0d0e21e 1709 force_ident(tokenbuf + 1, *tokenbuf);
93a17b20
LW
1710 }
1711 else
1712 PREREF('%');
79072805 1713 TERM('%');
a687059c 1714 }
79072805
LW
1715 ++s;
1716 Mop(OP_MODULO);
a687059c 1717
378cc40b 1718 case '^':
79072805 1719 s++;
a0d0e21e 1720 BOop(OP_BIT_XOR);
79072805
LW
1721 case '[':
1722 lex_brackets++;
1723 /* FALL THROUGH */
378cc40b 1724 case '~':
378cc40b 1725 case ',':
378cc40b
LW
1726 tmp = *s++;
1727 OPERATOR(tmp);
a0d0e21e
LW
1728 case ':':
1729 if (s[1] == ':') {
1730 len = 0;
1731 goto just_a_word;
1732 }
1733 s++;
1734 OPERATOR(':');
8990e307
LW
1735 case '(':
1736 s++;
a0d0e21e 1737 if (last_lop == oldoldbufptr || last_uni == oldoldbufptr)
8990e307 1738 oldbufptr = oldoldbufptr; /* allow print(STDOUT 123) */
a0d0e21e
LW
1739 else
1740 expect = XTERM;
1741 TOKEN('(');
378cc40b 1742 case ';':
79072805
LW
1743 if (curcop->cop_line < copline)
1744 copline = curcop->cop_line;
378cc40b
LW
1745 tmp = *s++;
1746 OPERATOR(tmp);
1747 case ')':
378cc40b 1748 tmp = *s++;
16d20bd9
AD
1749 s = skipspace(s);
1750 if (*s == '{')
1751 PREBLOCK(tmp);
378cc40b 1752 TERM(tmp);
79072805
LW
1753 case ']':
1754 s++;
463ee0b2
LW
1755 if (lex_brackets <= 0)
1756 yyerror("Unmatched right bracket");
1757 else
1758 --lex_brackets;
79072805 1759 if (lex_state == LEX_INTERPNORMAL) {
463ee0b2 1760 if (lex_brackets == 0) {
a0d0e21e 1761 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
79072805
LW
1762 lex_state = LEX_INTERPEND;
1763 }
1764 }
4633a7c4 1765 TERM(']');
79072805
LW
1766 case '{':
1767 leftbracket:
79072805 1768 s++;
8990e307 1769 if (lex_brackets > 100) {
89bfa8cd 1770 char* newlb = Renew(lex_brackstack, lex_brackets + 1, char);
8990e307
LW
1771 if (newlb != lex_brackstack) {
1772 SAVEFREEPV(newlb);
1773 lex_brackstack = newlb;
1774 }
1775 }
a0d0e21e
LW
1776 switch (expect) {
1777 case XTERM:
1778 if (lex_formbrack) {
1779 s--;
1780 PRETERMBLOCK(DO);
1781 }
1782 if (oldoldbufptr == last_lop)
1783 lex_brackstack[lex_brackets++] = XTERM;
1784 else
1785 lex_brackstack[lex_brackets++] = XOPERATOR;
79072805 1786 OPERATOR(HASHBRACK);
a0d0e21e 1787 break;
a0d0e21e 1788 case XOPERATOR:
748a9306
LW
1789 while (s < bufend && (*s == ' ' || *s == '\t'))
1790 s++;
89bfa8cd 1791 if (s < bufend && (isALPHA(*s) || *s == '_')) {
748a9306
LW
1792 d = scan_word(s, tokenbuf, FALSE, &len);
1793 while (d < bufend && (*d == ' ' || *d == '\t'))
1794 d++;
1795 if (*d == '}') {
1796 if (dowarn &&
1797 (keyword(tokenbuf, len) ||
1798 perl_get_cv(tokenbuf, FALSE) ))
1799 warn("Ambiguous use of {%s} resolved to {\"%s\"}",
1800 tokenbuf, tokenbuf);
1801 s = force_word(s,WORD,FALSE,TRUE,FALSE);
1802 }
1803 }
1804 /* FALL THROUGH */
1805 case XBLOCK:
a0d0e21e 1806 lex_brackstack[lex_brackets++] = XSTATE;
2304df62 1807 expect = XSTATE;
a0d0e21e
LW
1808 break;
1809 case XTERMBLOCK:
1810 lex_brackstack[lex_brackets++] = XOPERATOR;
1811 expect = XSTATE;
1812 break;
1813 default: {
1814 char *t;
1815 if (oldoldbufptr == last_lop)
1816 lex_brackstack[lex_brackets++] = XTERM;
1817 else
1818 lex_brackstack[lex_brackets++] = XOPERATOR;
1819 s = skipspace(s);
1820 if (*s == '}')
1821 OPERATOR(HASHBRACK);
1822 if (isALPHA(*s)) {
c07a80fd 1823 for (t = s; t < bufend && isALNUM(*t); t++) ;
a0d0e21e
LW
1824 }
1825 else if (*s == '\'' || *s == '"') {
1826 t = strchr(s+1,*s);
1827 if (!t++)
1828 t = s;
1829 }
1830 else
1831 t = s;
1832 while (t < bufend && isSPACE(*t))
1833 t++;
1834 if ((*t == ',' && !isLOWER(*s)) || (*t == '=' && t[1] == '>'))
1835 OPERATOR(HASHBRACK);
1836 if (expect == XREF)
1837 expect = XTERM;
1838 else {
1839 lex_brackstack[lex_brackets-1] = XSTATE;
1840 expect = XSTATE;
1841 }
8990e307 1842 }
a0d0e21e 1843 break;
463ee0b2 1844 }
79072805
LW
1845 yylval.ival = curcop->cop_line;
1846 if (isSPACE(*s) || *s == '#')
1847 copline = NOLINE; /* invalidate current command line number */
79072805 1848 TOKEN('{');
378cc40b 1849 case '}':
79072805
LW
1850 rightbracket:
1851 s++;
463ee0b2
LW
1852 if (lex_brackets <= 0)
1853 yyerror("Unmatched right bracket");
1854 else
1855 expect = (expectation)lex_brackstack[--lex_brackets];
85e6fe83
LW
1856 if (lex_brackets < lex_formbrack)
1857 lex_formbrack = 0;
79072805 1858 if (lex_state == LEX_INTERPNORMAL) {
463ee0b2 1859 if (lex_brackets == 0) {
79072805
LW
1860 if (lex_fakebrack) {
1861 lex_state = LEX_INTERPEND;
1862 bufptr = s;
1863 return yylex(); /* ignore fake brackets */
1864 }
a0d0e21e 1865 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
79072805
LW
1866 lex_state = LEX_INTERPEND;
1867 }
1868 }
748a9306
LW
1869 if (lex_brackets < lex_fakebrack) {
1870 bufptr = s;
1871 lex_fakebrack = 0;
1872 return yylex(); /* ignore fake brackets */
1873 }
79072805
LW
1874 force_next('}');
1875 TOKEN(';');
378cc40b
LW
1876 case '&':
1877 s++;
1878 tmp = *s++;
1879 if (tmp == '&')
a0d0e21e 1880 AOPERATOR(ANDAND);
378cc40b 1881 s--;
463ee0b2 1882 if (expect == XOPERATOR) {
fd049845 1883 if (dowarn && isALPHA(*s) && bufptr == linestart) {
463ee0b2
LW
1884 curcop->cop_line--;
1885 warn(warn_nosemi);
1886 curcop->cop_line++;
1887 }
79072805 1888 BAop(OP_BIT_AND);
463ee0b2 1889 }
79072805
LW
1890
1891 s = scan_ident(s-1, bufend, tokenbuf, TRUE);
463ee0b2
LW
1892 if (*tokenbuf) {
1893 expect = XOPERATOR;
a0d0e21e 1894 force_ident(tokenbuf, '&');
463ee0b2 1895 }
79072805
LW
1896 else
1897 PREREF('&');
c07a80fd 1898 yylval.ival = (OPpENTERSUB_AMPER<<8);
79072805
LW
1899 TERM('&');
1900
378cc40b
LW
1901 case '|':
1902 s++;
1903 tmp = *s++;
1904 if (tmp == '|')
a0d0e21e 1905 AOPERATOR(OROR);
378cc40b 1906 s--;
79072805 1907 BOop(OP_BIT_OR);
378cc40b
LW
1908 case '=':
1909 s++;
1910 tmp = *s++;
1911 if (tmp == '=')
79072805
LW
1912 Eop(OP_EQ);
1913 if (tmp == '>')
1914 OPERATOR(',');
378cc40b 1915 if (tmp == '~')
79072805 1916 PMop(OP_MATCH);
463ee0b2
LW
1917 if (dowarn && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
1918 warn("Reversed %c= operator",tmp);
378cc40b 1919 s--;
748a9306 1920 if (expect == XSTATE && isALPHA(tmp) &&
fd049845 1921 (s == linestart+1 || s[-2] == '\n') )
748a9306 1922 {
a5f75d66
AD
1923 if (in_eval && !rsfp) {
1924 d = bufend;
1925 while (s < d) {
1926 if (*s++ == '\n') {
1927 incline(s);
1928 if (strnEQ(s,"=cut",4)) {
1929 s = strchr(s,'\n');
1930 if (s)
1931 s++;
1932 else
1933 s = d;
1934 incline(s);
1935 goto retry;
1936 }
1937 }
1938 }
1939 goto retry;
1940 }
a0d0e21e
LW
1941 s = bufend;
1942 doextract = TRUE;
1943 goto retry;
1944 }
1945 if (lex_brackets < lex_formbrack) {
1946 char *t;
1947 for (t = s; *t == ' ' || *t == '\t'; t++) ;
1948 if (*t == '\n' || *t == '#') {
1949 s--;
1950 expect = XBLOCK;
1951 goto leftbracket;
1952 }
79072805 1953 }
a0d0e21e
LW
1954 yylval.ival = 0;
1955 OPERATOR(ASSIGNOP);
378cc40b
LW
1956 case '!':
1957 s++;
1958 tmp = *s++;
1959 if (tmp == '=')
79072805 1960 Eop(OP_NE);
378cc40b 1961 if (tmp == '~')
79072805 1962 PMop(OP_NOT);
378cc40b
LW
1963 s--;
1964 OPERATOR('!');
1965 case '<':
79072805 1966 if (expect != XOPERATOR) {
93a17b20 1967 if (s[1] != '<' && !strchr(s,'>'))
2f3197b3 1968 check_uni();
79072805
LW
1969 if (s[1] == '<')
1970 s = scan_heredoc(s);
1971 else
1972 s = scan_inputsymbol(s);
1973 TERM(sublex_start());
378cc40b
LW
1974 }
1975 s++;
1976 tmp = *s++;
1977 if (tmp == '<')
79072805 1978 SHop(OP_LEFT_SHIFT);
395c3793
LW
1979 if (tmp == '=') {
1980 tmp = *s++;
1981 if (tmp == '>')
79072805 1982 Eop(OP_NCMP);
395c3793 1983 s--;
79072805 1984 Rop(OP_LE);
395c3793 1985 }
378cc40b 1986 s--;
79072805 1987 Rop(OP_LT);
378cc40b
LW
1988 case '>':
1989 s++;
1990 tmp = *s++;
1991 if (tmp == '>')
79072805 1992 SHop(OP_RIGHT_SHIFT);
378cc40b 1993 if (tmp == '=')
79072805 1994 Rop(OP_GE);
378cc40b 1995 s--;
79072805 1996 Rop(OP_GT);
378cc40b
LW
1997
1998 case '$':
748a9306 1999 if (s[1] == '#' && (isALPHA(s[2]) || strchr("_{$:", s[2]))) {
a0d0e21e 2000 s = scan_ident(s+1, bufend, tokenbuf+1, FALSE);
8990e307 2001 if (expect == XOPERATOR) {
a0d0e21e
LW
2002 if (lex_formbrack && lex_brackets == lex_formbrack) {
2003 expect = XTERM;
2004 depcom();
2005 return ','; /* grandfather non-comma-format format */
2006 }
8990e307
LW
2007 else
2008 no_op("Array length",s);
2009 }
a0d0e21e
LW
2010 else if (!tokenbuf[1])
2011 PREREF(DOLSHARP);
2012 if (!strchr(tokenbuf+1,':')) {
2013 tokenbuf[0] = '@';
2014 if (tmp = pad_findmy(tokenbuf)) {
2015 nextval[nexttoke].opval = newOP(OP_PADANY, 0);
2016 nextval[nexttoke].opval->op_targ = tmp;
2017 expect = XOPERATOR;
2018 force_next(PRIVATEREF);
2019 TOKEN(DOLSHARP);
2020 }
2021 }
463ee0b2 2022 expect = XOPERATOR;
a0d0e21e 2023 force_ident(tokenbuf+1, *tokenbuf);
463ee0b2 2024 TOKEN(DOLSHARP);
79072805 2025 }
93a17b20 2026 s = scan_ident(s, bufend, tokenbuf+1, FALSE);
8990e307 2027 if (expect == XOPERATOR) {
a0d0e21e
LW
2028 if (lex_formbrack && lex_brackets == lex_formbrack) {
2029 expect = XTERM;
2030 depcom();
2031 return ','; /* grandfather non-comma-format format */
2032 }
8990e307
LW
2033 else
2034 no_op("Scalar",s);
2035 }
93a17b20 2036 if (tokenbuf[1]) {
a0d0e21e
LW
2037 expectation oldexpect = expect;
2038
2039 /* This kludge not intended to be bulletproof. */
2040 if (tokenbuf[1] == '[' && !tokenbuf[2]) {
748a9306 2041 yylval.opval = newSVOP(OP_CONST, 0,
a0d0e21e 2042 newSViv((IV)compiling.cop_arybase));
748a9306 2043 yylval.opval->op_private = OPpCONST_ARYBASE;
a0d0e21e
LW
2044 TERM(THING);
2045 }
93a17b20 2046 tokenbuf[0] = '$';
a0d0e21e 2047 if (dowarn) {
93a17b20 2048 char *t;
a0d0e21e
LW
2049 if (*s == '[' && oldexpect != XREF) {
2050 for (t = s+1; isSPACE(*t) || isALNUM(*t) || *t == '$'; t++) ;
2051 if (*t++ == ',') {
2052 bufptr = skipspace(bufptr);
2053 while (t < bufend && *t != ']') t++;
2054 warn("Multidimensional syntax %.*s not supported",
2055 t-bufptr+1, bufptr);
2056 }
2057 }
2058 if (*s == '{' && strEQ(tokenbuf, "$SIG") &&
2059 (t = strchr(s,'}')) && (t = strchr(t,'='))) {
2060 char tmpbuf[1024];
a0d0e21e
LW
2061 STRLEN len;
2062 for (t++; isSPACE(*t); t++) ;
748a9306
LW
2063 if (isIDFIRST(*t)) {
2064 t = scan_word(t, tmpbuf, TRUE, &len);
2065 if (*t != '(' && perl_get_cv(tmpbuf, FALSE))
2066 warn("You need to quote \"%s\"", tmpbuf);
2067 }
93a17b20
LW
2068 }
2069 }
463ee0b2
LW
2070 expect = XOPERATOR;
2071 if (lex_state == LEX_NORMAL && isSPACE(*s)) {
2072 bool islop = (last_lop == oldoldbufptr);
2073 s = skipspace(s);
a0d0e21e 2074 if (!islop || last_lop_op == OP_GREPSTART)
463ee0b2 2075 expect = XOPERATOR;
8990e307
LW
2076 else if (strchr("$@\"'`q", *s))
2077 expect = XTERM; /* e.g. print $fh "foo" */
463ee0b2
LW
2078 else if (strchr("&*<%", *s) && isIDFIRST(s[1]))
2079 expect = XTERM; /* e.g. print $fh &sub */
2080 else if (isDIGIT(*s))
2081 expect = XTERM; /* e.g. print $fh 3 */
2082 else if (*s == '.' && isDIGIT(s[1]))
2083 expect = XTERM; /* e.g. print $fh .3 */
2084 else if (strchr("/?-+", *s) && !isSPACE(s[1]))
2085 expect = XTERM; /* e.g. print $fh -1 */
2086 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]))
2087 expect = XTERM; /* print $fh <<"EOF" */
2088 }
93a17b20 2089 if (in_my) {
463ee0b2 2090 if (strchr(tokenbuf,':'))
748a9306 2091 croak(no_myglob,tokenbuf);
ed6116ce 2092 nextval[nexttoke].opval = newOP(OP_PADANY, 0);
93a17b20
LW
2093 nextval[nexttoke].opval->op_targ = pad_allocmy(tokenbuf);
2094 force_next(PRIVATEREF);
2095 }
463ee0b2 2096 else if (!strchr(tokenbuf,':')) {
748a9306 2097 if (oldexpect != XREF || oldoldbufptr == last_lop) {
4633a7c4
LW
2098 if (intuit_more(s)) {
2099 if (*s == '[')
2100 tokenbuf[0] = '@';
2101 else if (*s == '{')
2102 tokenbuf[0] = '%';
2103 }
a0d0e21e 2104 }
93a17b20 2105 if (tmp = pad_findmy(tokenbuf)) {
fd049845
PP
2106 if (last_lop_op == OP_SORT &&
2107 !tokenbuf[2] && *tokenbuf =='$' &&
c07a80fd
PP
2108 tokenbuf[1] <= 'b' && tokenbuf[1] >= 'a')
2109 {
fd049845 2110 for (d = in_eval ? oldoldbufptr : linestart;
c07a80fd
PP
2111 d < bufend && *d != '\n';
2112 d++)
2113 {
2114 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
2115 croak("Can't use \"my %s\" in sort comparison",
2116 tokenbuf);
2117 }
2118 }
2119 }
ed6116ce 2120 nextval[nexttoke].opval = newOP(OP_PADANY, 0);
93a17b20
LW
2121 nextval[nexttoke].opval->op_targ = tmp;
2122 force_next(PRIVATEREF);
2123 }
4633a7c4 2124 else
a0d0e21e 2125 force_ident(tokenbuf+1, *tokenbuf);
93a17b20
LW
2126 }
2127 else
a0d0e21e 2128 force_ident(tokenbuf+1, *tokenbuf);
93a17b20 2129 }
463ee0b2
LW
2130 else {
2131 if (s == bufend)
2132 yyerror("Final $ should be \\$ or $name");
79072805 2133 PREREF('$');
2f3197b3 2134 }
79072805 2135 TOKEN('$');
378cc40b
LW
2136
2137 case '@':
93a17b20 2138 s = scan_ident(s, bufend, tokenbuf+1, FALSE);
8990e307
LW
2139 if (expect == XOPERATOR)
2140 no_op("Array",s);
93a17b20 2141 if (tokenbuf[1]) {
a0d0e21e
LW
2142 GV* gv;
2143
93a17b20 2144 tokenbuf[0] = '@';
463ee0b2 2145 expect = XOPERATOR;
93a17b20 2146 if (in_my) {
463ee0b2 2147 if (strchr(tokenbuf,':'))
748a9306 2148 croak(no_myglob,tokenbuf);
ed6116ce 2149 nextval[nexttoke].opval = newOP(OP_PADANY, 0);
93a17b20
LW
2150 nextval[nexttoke].opval->op_targ = pad_allocmy(tokenbuf);
2151 force_next(PRIVATEREF);
2152 TERM('@');
2153 }
463ee0b2 2154 else if (!strchr(tokenbuf,':')) {
4633a7c4
LW
2155 if (intuit_more(s)) {
2156 if (*s == '{')
2157 tokenbuf[0] = '%';
2158 }
93a17b20 2159 if (tmp = pad_findmy(tokenbuf)) {
ed6116ce 2160 nextval[nexttoke].opval = newOP(OP_PADANY, 0);
93a17b20
LW
2161 nextval[nexttoke].opval->op_targ = tmp;
2162 force_next(PRIVATEREF);
2163 TERM('@');
2164 }
2165 }
a0d0e21e
LW
2166
2167 /* Force them to make up their mind on "@foo". */
4633a7c4 2168 if (lex_state != LEX_NORMAL && !lex_brackets &&
a0d0e21e
LW
2169 ( !(gv = gv_fetchpv(tokenbuf+1, FALSE, SVt_PVAV)) ||
2170 (*tokenbuf == '@'
2171 ? !GvAV(gv)
2172 : !GvHV(gv) )))
2173 {
2174 char tmpbuf[1024];
2175 sprintf(tmpbuf, "Literal @%s now requires backslash",tokenbuf+1);
2176 yyerror(tmpbuf);
2177 }
2178
2179 /* Warn about @ where they meant $. */
2180 if (dowarn) {
2181 if (*s == '[' || *s == '{') {
2182 char *t = s + 1;
2183 while (*t && (isALNUM(*t) || strchr(" \t$#+-'\"", *t)))
2184 t++;
2185 if (*t == '}' || *t == ']') {
2186 t++;
2187 bufptr = skipspace(bufptr);
2188 warn("Scalar value %.*s better written as $%.*s",
2189 t-bufptr, bufptr, t-bufptr-1, bufptr+1);
2190 }
93a17b20
LW
2191 }
2192 }
a0d0e21e 2193 force_ident(tokenbuf+1, *tokenbuf);
93a17b20 2194 }
463ee0b2
LW
2195 else {
2196 if (s == bufend)
2197 yyerror("Final @ should be \\@ or @name");
79072805 2198 PREREF('@');
463ee0b2 2199 }
79072805 2200 TERM('@');
378cc40b
LW
2201
2202 case '/': /* may either be division or pattern */
2203 case '?': /* may either be conditional or pattern */
79072805 2204 if (expect != XOPERATOR) {
2f3197b3 2205 check_uni();
79072805
LW
2206 s = scan_pat(s);
2207 TERM(sublex_start());
378cc40b
LW
2208 }
2209 tmp = *s++;
a687059c 2210 if (tmp == '/')
79072805 2211 Mop(OP_DIVIDE);
378cc40b
LW
2212 OPERATOR(tmp);
2213
2214 case '.':
748a9306 2215 if (lex_formbrack && lex_brackets == lex_formbrack && s[1] == '\n' &&
fd049845 2216 (s == linestart || s[-1] == '\n') ) {
85e6fe83 2217 lex_formbrack = 0;
8990e307 2218 expect = XSTATE;
79072805
LW
2219 goto rightbracket;
2220 }
2221 if (expect == XOPERATOR || !isDIGIT(s[1])) {
378cc40b 2222 tmp = *s++;
a687059c
LW
2223 if (*s == tmp) {
2224 s++;
2f3197b3
LW
2225 if (*s == tmp) {
2226 s++;
79072805 2227 yylval.ival = OPf_SPECIAL;
2f3197b3
LW
2228 }
2229 else
79072805 2230 yylval.ival = 0;
378cc40b 2231 OPERATOR(DOTDOT);
a687059c 2232 }
79072805 2233 if (expect != XOPERATOR)
2f3197b3 2234 check_uni();
79072805 2235 Aop(OP_CONCAT);
378cc40b
LW
2236 }
2237 /* FALL THROUGH */
2238 case '0': case '1': case '2': case '3': case '4':
2239 case '5': case '6': case '7': case '8': case '9':
79072805 2240 s = scan_num(s);
8990e307
LW
2241 if (expect == XOPERATOR)
2242 no_op("Number",s);
79072805
LW
2243 TERM(THING);
2244
2245 case '\'':
8990e307 2246 s = scan_str(s);
463ee0b2 2247 if (expect == XOPERATOR) {
a0d0e21e
LW
2248 if (lex_formbrack && lex_brackets == lex_formbrack) {
2249 expect = XTERM;
2250 depcom();
2251 return ','; /* grandfather non-comma-format format */
2252 }
463ee0b2 2253 else
8990e307 2254 no_op("String",s);
463ee0b2 2255 }
79072805 2256 if (!s)
85e6fe83 2257 missingterm((char*)0);
79072805
LW
2258 yylval.ival = OP_CONST;
2259 TERM(sublex_start());
2260
2261 case '"':
8990e307 2262 s = scan_str(s);
463ee0b2 2263 if (expect == XOPERATOR) {
a0d0e21e
LW
2264 if (lex_formbrack && lex_brackets == lex_formbrack) {
2265 expect = XTERM;
2266 depcom();
2267 return ','; /* grandfather non-comma-format format */
2268 }
463ee0b2 2269 else
8990e307 2270 no_op("String",s);
463ee0b2 2271 }
79072805 2272 if (!s)
85e6fe83 2273 missingterm((char*)0);
4633a7c4
LW
2274 yylval.ival = OP_CONST;
2275 for (d = SvPV(lex_stuff, len); len; len--, d++) {
2276 if (*d == '$' || *d == '@' || *d == '\\') {
2277 yylval.ival = OP_STRINGIFY;
2278 break;
2279 }
2280 }
79072805
LW
2281 TERM(sublex_start());
2282
2283 case '`':
2284 s = scan_str(s);
8990e307
LW
2285 if (expect == XOPERATOR)
2286 no_op("Backticks",s);
79072805 2287 if (!s)
85e6fe83 2288 missingterm((char*)0);
79072805
LW
2289 yylval.ival = OP_BACKTICK;
2290 set_csh();
2291 TERM(sublex_start());
2292
2293 case '\\':
2294 s++;
748a9306
LW
2295 if (dowarn && lex_inwhat && isDIGIT(*s))
2296 warn("Can't use \\%c to mean $%c in expression", *s, *s);
8990e307
LW
2297 if (expect == XOPERATOR)
2298 no_op("Backslash",s);
79072805
LW
2299 OPERATOR(REFGEN);
2300
2301 case 'x':
2302 if (isDIGIT(s[1]) && expect == XOPERATOR) {
2303 s++;
2304 Mop(OP_REPEAT);
2f3197b3 2305 }
79072805
LW
2306 goto keylookup;
2307
378cc40b 2308 case '_':
79072805
LW
2309 case 'a': case 'A':
2310 case 'b': case 'B':
2311 case 'c': case 'C':
2312 case 'd': case 'D':
2313 case 'e': case 'E':
2314 case 'f': case 'F':
2315 case 'g': case 'G':
2316 case 'h': case 'H':
2317 case 'i': case 'I':
2318 case 'j': case 'J':
2319 case 'k': case 'K':
2320 case 'l': case 'L':
2321 case 'm': case 'M':
2322 case 'n': case 'N':
2323 case 'o': case 'O':
2324 case 'p': case 'P':
2325 case 'q': case 'Q':
2326 case 'r': case 'R':
2327 case 's': case 'S':
2328 case 't': case 'T':
2329 case 'u': case 'U':
2330 case 'v': case 'V':
2331 case 'w': case 'W':
2332 case 'X':
2333 case 'y': case 'Y':
2334 case 'z': case 'Z':
2335
2336 keylookup:
748a9306 2337 bufptr = s;
463ee0b2
LW
2338 s = scan_word(s, tokenbuf, FALSE, &len);
2339
4633a7c4
LW
2340 if (*s == ':' && s[1] == ':' && strNE(tokenbuf, "CORE"))
2341 goto just_a_word;
2342
a0d0e21e 2343 tmp = keyword(tokenbuf, len);
748a9306
LW
2344
2345 /* Is this a word before a => operator? */
2346 d = s;
2347 while (d < bufend && (*d == ' ' || *d == '\t'))
2348 d++; /* no comments skipped here, or s### is misparsed */
2349 if (strnEQ(d,"=>",2)) {
2350 CLINE;
2351 if (dowarn && (tmp || perl_get_cv(tokenbuf, FALSE)))
2352 warn("Ambiguous use of %s => resolved to \"%s\" =>",
2353 tokenbuf, tokenbuf);
2354 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf,0));
2355 yylval.opval->op_private = OPpCONST_BARE;
2356 TERM(WORD);
2357 }
2358
a0d0e21e
LW
2359 if (tmp < 0) { /* second-class keyword? */
2360 GV* gv;
2361 if (expect != XOPERATOR &&
a5f75d66
AD
2362 (*s != ':' || s[1] != ':') &&
2363 (gv = gv_fetchpv(tokenbuf, FALSE, SVt_PVCV)) &&
2364 GvIMPORTED_CV(gv))
a0d0e21e
LW
2365 {
2366 tmp = 0;
2367 }
2368 else
2369 tmp = -tmp;
2370 }
2371
2372 reserved_word:
2373 switch (tmp) {
79072805
LW
2374
2375 default: /* not a keyword */
93a17b20
LW
2376 just_a_word: {
2377 GV *gv;
748a9306 2378 char lastchar = (bufptr == oldoldbufptr ? 0 : bufptr[-1]);
8990e307
LW
2379
2380 /* Get the rest if it looks like a package qualifier */
2381
a0d0e21e 2382 if (*s == '\'' || *s == ':' && s[1] == ':') {
463ee0b2 2383 s = scan_word(s, tokenbuf + len, TRUE, &len);
a0d0e21e
LW
2384 if (!len)
2385 croak("Bad name after %s::", tokenbuf);
2386 }
8990e307
LW
2387
2388 /* Do special processing at start of statement. */
2389
2390 if (expect == XSTATE) {
93a17b20 2391 while (isSPACE(*s)) s++;
8990e307 2392 if (*s == ':') { /* It's a label. */
a0d0e21e 2393 yylval.pval = savepv(tokenbuf);
93a17b20
LW
2394 s++;
2395 CLINE;
2396 TOKEN(LABEL);
2397 }
2398 }
a0d0e21e 2399 else if (expect == XOPERATOR) {
fd049845 2400 if (bufptr == linestart) {
463ee0b2
LW
2401 curcop->cop_line--;
2402 warn(warn_nosemi);
2403 curcop->cop_line++;
2404 }
2405 else
8990e307 2406 no_op("Bare word",s);
463ee0b2 2407 }
8990e307
LW
2408
2409 /* Look for a subroutine with this name in current package. */
2410
85e6fe83 2411 gv = gv_fetchpv(tokenbuf,FALSE, SVt_PVCV);
8990e307 2412
a0d0e21e
LW
2413 /* Presume this is going to be a bareword of some sort. */
2414
2415 CLINE;
2416 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf,0));
2417 yylval.opval->op_private = OPpCONST_BARE;
2418
8990e307
LW
2419 /* See if it's the indirect object for a list operator. */
2420
a0d0e21e
LW
2421 if (oldoldbufptr &&
2422 oldoldbufptr < bufptr &&
2423 (oldoldbufptr == last_lop || oldoldbufptr == last_uni) &&
2424 /* NO SKIPSPACE BEFORE HERE! */
2425 (expect == XREF ||
2426 (opargs[last_lop_op] >> OASHIFT & 7) == OA_FILEREF) )
2427 {
748a9306
LW
2428 bool immediate_paren = *s == '(';
2429
a0d0e21e
LW
2430 /* (Now we can afford to cross potential line boundary.) */
2431 s = skipspace(s);
2432
2433 /* Two barewords in a row may indicate method call. */
2434
2435 if ((isALPHA(*s) || *s == '$') && (tmp=intuit_method(s,gv)))
2436 return tmp;
2437
2438 /* If not a declared subroutine, it's an indirect object. */
2439 /* (But it's an indir obj regardless for sort.) */
2440
8e07c86e
AD
2441 if ((last_lop_op == OP_SORT ||
2442 (!immediate_paren && (!gv || !GvCV(gv))) ) &&
2443 (last_lop_op != OP_MAPSTART && last_lop_op != OP_GREPSTART)){
748a9306
LW
2444 expect = (last_lop == oldoldbufptr) ? XTERM : XOPERATOR;
2445 goto bareword;
93a17b20
LW
2446 }
2447 }
8990e307
LW
2448
2449 /* If followed by a paren, it's certainly a subroutine. */
2450
2451 expect = XOPERATOR;
2452 s = skipspace(s);
93a17b20 2453 if (*s == '(') {
79072805 2454 CLINE;
a0d0e21e 2455 nextval[nexttoke].opval = yylval.opval;
463ee0b2 2456 expect = XOPERATOR;
93a17b20 2457 force_next(WORD);
c07a80fd 2458 yylval.ival = 0;
463ee0b2 2459 TOKEN('&');
79072805 2460 }
93a17b20 2461
a0d0e21e 2462 /* If followed by var or block, call it a method (unless sub) */
8990e307
LW
2463
2464 if ((*s == '$' || *s == '{') && (!gv || !GvCV(gv))) {
463ee0b2 2465 last_lop = oldbufptr;
8990e307 2466 last_lop_op = OP_METHOD;
93a17b20 2467 PREBLOCK(METHOD);
463ee0b2
LW
2468 }
2469
8990e307
LW
2470 /* If followed by a bareword, see if it looks like indir obj. */
2471
a0d0e21e
LW
2472 if ((isALPHA(*s) || *s == '$') && (tmp = intuit_method(s,gv)))
2473 return tmp;
93a17b20 2474
8990e307
LW
2475 /* Not a method, so call it a subroutine (if defined) */
2476
2477 if (gv && GvCV(gv)) {
4633a7c4 2478 CV* cv = GvCV(gv);
8990e307 2479 if (*s == '(') {
a5f75d66 2480 nextval[nexttoke].opval = yylval.opval;
8990e307
LW
2481 expect = XTERM;
2482 force_next(WORD);
c07a80fd 2483 yylval.ival = 0;
8990e307
LW
2484 TOKEN('&');
2485 }
748a9306 2486 if (lastchar == '-')
c2960299 2487 warn("Ambiguous use of -%s resolved as -&%s()",
748a9306 2488 tokenbuf, tokenbuf);
8990e307 2489 last_lop = oldbufptr;
a0d0e21e 2490 last_lop_op = OP_ENTERSUB;
89bfa8cd 2491 /* Check for a constant sub */
760ac839
LW
2492 {
2493 SV *sv = cv_const_sv(cv);
89bfa8cd
PP
2494 if (sv) {
2495 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
2496 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
2497 yylval.opval->op_private = 0;
2498 TOKEN(WORD);
2499 }
2500 }
2501
a5f75d66
AD
2502 /* Resolve to GV now. */
2503 op_free(yylval.opval);
2504 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
4633a7c4
LW
2505 /* Is there a prototype? */
2506 if (SvPOK(cv)) {
2507 STRLEN len;
2508 char *proto = SvPV((SV*)cv, len);
2509 if (!len)
2510 TERM(FUNC0SUB);
2511 if (strEQ(proto, "$"))
2512 OPERATOR(UNIOPSUB);
2513 if (*proto == '&' && *s == '{') {
2514 sv_setpv(subname,"__ANON__");
2515 PREBLOCK(LSTOPSUB);
2516 }
2517 }
a5f75d66 2518 nextval[nexttoke].opval = yylval.opval;
8990e307
LW
2519 expect = XTERM;
2520 force_next(WORD);
2521 TOKEN(NOAMP);
2522 }
748a9306
LW
2523
2524 if (hints & HINT_STRICT_SUBS &&
2525 lastchar != '-' &&
a0d0e21e 2526 strnNE(s,"->",2) &&
9b01e405 2527 last_lop_op != OP_TRUNCATE && /* S/F prototype in opcode.pl */
a0d0e21e
LW
2528 last_lop_op != OP_ACCEPT &&
2529 last_lop_op != OP_PIPE_OP &&
2530 last_lop_op != OP_SOCKPAIR)
2531 {
2532 warn(
2533 "Bareword \"%s\" not allowed while \"strict subs\" in use",
85e6fe83
LW
2534 tokenbuf);
2535 ++error_count;
2536 }
8990e307
LW
2537
2538 /* Call it a bare word */
2539
748a9306
LW
2540 bareword:
2541 if (dowarn) {
2542 if (lastchar != '-') {
2543 for (d = tokenbuf; *d && isLOWER(*d); d++) ;
2544 if (!*d)
2545 warn(warn_reserved, tokenbuf);
2546 }
2547 }
2548 if (lastchar && strchr("*%&", lastchar)) {
2549 warn("Operator or semicolon missing before %c%s",
2550 lastchar, tokenbuf);
c2960299 2551 warn("Ambiguous use of %c resolved as operator %c",
748a9306
LW
2552 lastchar, lastchar);
2553 }
93a17b20 2554 TOKEN(WORD);
79072805 2555 }
79072805
LW
2556
2557 case KEY___LINE__:
2558 case KEY___FILE__: {
2559 if (tokenbuf[2] == 'L')
2560 (void)sprintf(tokenbuf,"%ld",(long)curcop->cop_line);
2561 else
463ee0b2 2562 strcpy(tokenbuf, SvPVX(GvSV(curcop->cop_filegv)));
79072805
LW
2563 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf,0));
2564 TERM(THING);
2565 }
2566
e50aee73 2567 case KEY___DATA__:
79072805
LW
2568 case KEY___END__: {
2569 GV *gv;
79072805
LW
2570
2571 /*SUPPRESS 560*/
a5f75d66 2572 if (rsfp && (!in_eval || tokenbuf[2] == 'D')) {
e50aee73
AD
2573 char dname[256];
2574 char *pname = "main";
2575 if (tokenbuf[2] == 'D')
2576 pname = HvNAME(curstash ? curstash : defstash);
2577 sprintf(dname,"%s::DATA", pname);
2578 gv = gv_fetchpv(dname,TRUE, SVt_PVIO);
a5f75d66 2579 GvMULTI_on(gv);
79072805 2580 if (!GvIO(gv))
a0d0e21e
LW
2581 GvIOp(gv) = newIO();
2582 IoIFP(GvIOp(gv)) = rsfp;
2583#if defined(HAS_FCNTL) && defined(F_SETFD)
2584 {
760ac839 2585 int fd = PerlIO_fileno(rsfp);
a0d0e21e
LW
2586 fcntl(fd,F_SETFD,fd >= 3);
2587 }
79072805 2588#endif
fd049845
PP
2589 /* Mark this internal pseudo-handle as clean */
2590 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
79072805 2591 if (preprocess)
a0d0e21e 2592 IoTYPE(GvIOp(gv)) = '|';
760ac839 2593 else if ((PerlIO*)rsfp == PerlIO_stdin())
a0d0e21e 2594 IoTYPE(GvIOp(gv)) = '-';
79072805 2595 else
a0d0e21e 2596 IoTYPE(GvIOp(gv)) = '<';
79072805
LW
2597 rsfp = Nullfp;
2598 }
2599 goto fake_eof;
e929a76b 2600 }
de3bb511 2601
8990e307 2602 case KEY_AUTOLOAD:
ed6116ce 2603 case KEY_DESTROY:
79072805
LW
2604 case KEY_BEGIN:
2605 case KEY_END:
a0d0e21e 2606 if (expect == XSTATE) {
93a17b20
LW
2607 s = bufptr;
2608 goto really_sub;
79072805
LW
2609 }
2610 goto just_a_word;
2611
a0d0e21e
LW
2612 case KEY_CORE:
2613 if (*s == ':' && s[1] == ':') {
2614 s += 2;
748a9306 2615 d = s;
a0d0e21e
LW
2616 s = scan_word(s, tokenbuf, FALSE, &len);
2617 tmp = keyword(tokenbuf, len);
2618 if (tmp < 0)
2619 tmp = -tmp;
2620 goto reserved_word;
2621 }
2622 goto just_a_word;
2623
463ee0b2
LW
2624 case KEY_abs:
2625 UNI(OP_ABS);
2626
79072805
LW
2627 case KEY_alarm:
2628 UNI(OP_ALARM);
2629
2630 case KEY_accept:
a0d0e21e 2631 LOP(OP_ACCEPT,XTERM);
79072805 2632
463ee0b2
LW
2633 case KEY_and:
2634 OPERATOR(ANDOP);
2635
79072805 2636 case KEY_atan2:
a0d0e21e 2637 LOP(OP_ATAN2,XTERM);
85e6fe83 2638
79072805 2639 case KEY_bind:
a0d0e21e 2640 LOP(OP_BIND,XTERM);
79072805
LW
2641
2642 case KEY_binmode:
2643 UNI(OP_BINMODE);
2644
2645 case KEY_bless:
a0d0e21e 2646 LOP(OP_BLESS,XTERM);
79072805
LW
2647
2648 case KEY_chop:
2649 UNI(OP_CHOP);
2650
2651 case KEY_continue:
2652 PREBLOCK(CONTINUE);
2653
2654 case KEY_chdir:
85e6fe83 2655 (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */
79072805
LW
2656 UNI(OP_CHDIR);
2657
2658 case KEY_close:
2659 UNI(OP_CLOSE);
2660
2661 case KEY_closedir:
2662 UNI(OP_CLOSEDIR);
2663
2664 case KEY_cmp:
2665 Eop(OP_SCMP);
2666
2667 case KEY_caller:
2668 UNI(OP_CALLER);
2669
2670 case KEY_crypt:
2671#ifdef FCRYPT
de3bb511
LW
2672 if (!cryptseen++)
2673 init_des();
a687059c 2674#endif
a0d0e21e 2675 LOP(OP_CRYPT,XTERM);
79072805
LW
2676
2677 case KEY_chmod:
748a9306
LW
2678 if (dowarn) {
2679 for (d = s; d < bufend && (isSPACE(*d) || *d == '('); d++) ;
2680 if (*d != '0' && isDIGIT(*d))
2681 yywarn("chmod: mode argument is missing initial 0");
2682 }
a0d0e21e 2683 LOP(OP_CHMOD,XTERM);
79072805
LW
2684
2685 case KEY_chown:
a0d0e21e 2686 LOP(OP_CHOWN,XTERM);
79072805
LW
2687
2688 case KEY_connect:
a0d0e21e 2689 LOP(OP_CONNECT,XTERM);
79072805 2690
463ee0b2
LW
2691 case KEY_chr:
2692 UNI(OP_CHR);
2693
79072805
LW
2694 case KEY_cos:
2695 UNI(OP_COS);
2696
2697 case KEY_chroot:
2698 UNI(OP_CHROOT);
2699
2700 case KEY_do:
2701 s = skipspace(s);
2702 if (*s == '{')
a0d0e21e 2703 PRETERMBLOCK(DO);
79072805 2704 if (*s != '\'')
a0d0e21e 2705 s = force_word(s,WORD,FALSE,TRUE,FALSE);
378cc40b 2706 OPERATOR(DO);
79072805
LW
2707
2708 case KEY_die:
a0d0e21e
LW
2709 hints |= HINT_BLOCK_SCOPE;
2710 LOP(OP_DIE,XTERM);
79072805
LW
2711
2712 case KEY_defined:
2713 UNI(OP_DEFINED);
2714
2715 case KEY_delete:
a0d0e21e 2716 UNI(OP_DELETE);
79072805
LW
2717
2718 case KEY_dbmopen:
a0d0e21e
LW
2719 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
2720 LOP(OP_DBMOPEN,XTERM);
79072805
LW
2721
2722 case KEY_dbmclose:
2723 UNI(OP_DBMCLOSE);
2724
2725 case KEY_dump:
a0d0e21e 2726 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
2727 LOOPX(OP_DUMP);
2728
2729 case KEY_else:
2730 PREBLOCK(ELSE);
2731
2732 case KEY_elsif:
2733 yylval.ival = curcop->cop_line;
2734 OPERATOR(ELSIF);
2735
2736 case KEY_eq:
2737 Eop(OP_SEQ);
2738
a0d0e21e
LW
2739 case KEY_exists:
2740 UNI(OP_EXISTS);
2741
79072805
LW
2742 case KEY_exit:
2743 UNI(OP_EXIT);
2744
2745 case KEY_eval:
79072805 2746 s = skipspace(s);
a0d0e21e 2747 expect = (*s == '{') ? XTERMBLOCK : XTERM;
463ee0b2 2748 UNIBRACK(OP_ENTEREVAL);
79072805
LW
2749
2750 case KEY_eof:
2751 UNI(OP_EOF);
2752
2753 case KEY_exp:
2754 UNI(OP_EXP);
2755
2756 case KEY_each:
2757 UNI(OP_EACH);
2758
2759 case KEY_exec:
2760 set_csh();
a0d0e21e 2761 LOP(OP_EXEC,XREF);
79072805
LW
2762
2763 case KEY_endhostent:
2764 FUN0(OP_EHOSTENT);
2765
2766 case KEY_endnetent:
2767 FUN0(OP_ENETENT);
2768
2769 case KEY_endservent:
2770 FUN0(OP_ESERVENT);
2771
2772 case KEY_endprotoent:
2773 FUN0(OP_EPROTOENT);
2774
2775 case KEY_endpwent:
2776 FUN0(OP_EPWENT);
2777
2778 case KEY_endgrent:
2779 FUN0(OP_EGRENT);
2780
2781 case KEY_for:
2782 case KEY_foreach:
2783 yylval.ival = curcop->cop_line;
2784 while (s < bufend && isSPACE(*s))
2785 s++;
2786 if (isIDFIRST(*s))
463ee0b2 2787 croak("Missing $ on loop variable");
79072805
LW
2788 OPERATOR(FOR);
2789
2790 case KEY_formline:
a0d0e21e 2791 LOP(OP_FORMLINE,XTERM);
79072805
LW
2792
2793 case KEY_fork:
2794 FUN0(OP_FORK);
2795
2796 case KEY_fcntl:
a0d0e21e 2797 LOP(OP_FCNTL,XTERM);
79072805
LW
2798
2799 case KEY_fileno:
2800 UNI(OP_FILENO);
2801
2802 case KEY_flock:
a0d0e21e 2803 LOP(OP_FLOCK,XTERM);
79072805
LW
2804
2805 case KEY_gt:
2806 Rop(OP_SGT);
2807
2808 case KEY_ge:
2809 Rop(OP_SGE);
2810
2811 case KEY_grep:
a0d0e21e 2812 LOP(OP_GREPSTART, *s == '(' ? XTERM : XREF);
79072805
LW
2813
2814 case KEY_goto:
a0d0e21e 2815 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
2816 LOOPX(OP_GOTO);
2817
2818 case KEY_gmtime:
2819 UNI(OP_GMTIME);
2820
2821 case KEY_getc:
2822 UNI(OP_GETC);
2823
2824 case KEY_getppid:
2825 FUN0(OP_GETPPID);
2826
2827 case KEY_getpgrp:
2828 UNI(OP_GETPGRP);
2829
2830 case KEY_getpriority:
a0d0e21e 2831 LOP(OP_GETPRIORITY,XTERM);
79072805
LW
2832
2833 case KEY_getprotobyname:
2834 UNI(OP_GPBYNAME);
2835
2836 case KEY_getprotobynumber:
a0d0e21e 2837 LOP(OP_GPBYNUMBER,XTERM);
79072805
LW
2838
2839 case KEY_getprotoent:
2840 FUN0(OP_GPROTOENT);
2841
2842 case KEY_getpwent:
2843 FUN0(OP_GPWENT);
2844
2845 case KEY_getpwnam:
2846 FUN1(OP_GPWNAM);
2847
2848 case KEY_getpwuid:
2849 FUN1(OP_GPWUID);
2850
2851 case KEY_getpeername:
2852 UNI(OP_GETPEERNAME);
2853
2854 case KEY_gethostbyname:
2855 UNI(OP_GHBYNAME);
2856
2857 case KEY_gethostbyaddr:
a0d0e21e 2858 LOP(OP_GHBYADDR,XTERM);
79072805
LW
2859
2860 case KEY_gethostent:
2861 FUN0(OP_GHOSTENT);
2862
2863 case KEY_getnetbyname:
2864 UNI(OP_GNBYNAME);
2865
2866 case KEY_getnetbyaddr:
a0d0e21e 2867 LOP(OP_GNBYADDR,XTERM);
79072805
LW
2868
2869 case KEY_getnetent:
2870 FUN0(OP_GNETENT);
2871
2872 case KEY_getservbyname:
a0d0e21e 2873 LOP(OP_GSBYNAME,XTERM);
79072805
LW
2874
2875 case KEY_getservbyport:
a0d0e21e 2876 LOP(OP_GSBYPORT,XTERM);
79072805
LW
2877
2878 case KEY_getservent:
2879 FUN0(OP_GSERVENT);
2880
2881 case KEY_getsockname:
2882 UNI(OP_GETSOCKNAME);
2883
2884 case KEY_getsockopt:
a0d0e21e 2885 LOP(OP_GSOCKOPT,XTERM);
79072805
LW
2886
2887 case KEY_getgrent:
2888 FUN0(OP_GGRENT);
2889
2890 case KEY_getgrnam:
2891 FUN1(OP_GGRNAM);
2892
2893 case KEY_getgrgid:
2894 FUN1(OP_GGRGID);
2895
2896 case KEY_getlogin:
2897 FUN0(OP_GETLOGIN);
2898
93a17b20 2899 case KEY_glob:
a0d0e21e
LW
2900 set_csh();
2901 LOP(OP_GLOB,XTERM);
93a17b20 2902
79072805
LW
2903 case KEY_hex:
2904 UNI(OP_HEX);
2905
2906 case KEY_if:
2907 yylval.ival = curcop->cop_line;
2908 OPERATOR(IF);
2909
2910 case KEY_index:
a0d0e21e 2911 LOP(OP_INDEX,XTERM);
79072805
LW
2912
2913 case KEY_int:
2914 UNI(OP_INT);
2915
2916 case KEY_ioctl:
a0d0e21e 2917 LOP(OP_IOCTL,XTERM);
79072805
LW
2918
2919 case KEY_join:
a0d0e21e 2920 LOP(OP_JOIN,XTERM);
79072805
LW
2921
2922 case KEY_keys:
2923 UNI(OP_KEYS);
2924
2925 case KEY_kill:
a0d0e21e 2926 LOP(OP_KILL,XTERM);
79072805
LW
2927
2928 case KEY_last:
a0d0e21e 2929 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805 2930 LOOPX(OP_LAST);
a0d0e21e 2931
79072805
LW
2932 case KEY_lc:
2933 UNI(OP_LC);
2934
2935 case KEY_lcfirst:
2936 UNI(OP_LCFIRST);
2937
2938 case KEY_local:
93a17b20 2939 yylval.ival = 0;
79072805
LW
2940 OPERATOR(LOCAL);
2941
2942 case KEY_length:
2943 UNI(OP_LENGTH);
2944
2945 case KEY_lt:
2946 Rop(OP_SLT);
2947
2948 case KEY_le:
2949 Rop(OP_SLE);
2950
2951 case KEY_localtime:
2952 UNI(OP_LOCALTIME);
2953
2954 case KEY_log:
2955 UNI(OP_LOG);
2956
2957 case KEY_link:
a0d0e21e 2958 LOP(OP_LINK,XTERM);
79072805
LW
2959
2960 case KEY_listen:
a0d0e21e 2961 LOP(OP_LISTEN,XTERM);
79072805
LW
2962
2963 case KEY_lstat:
2964 UNI(OP_LSTAT);
2965
2966 case KEY_m:
2967 s = scan_pat(s);
2968 TERM(sublex_start());
2969
a0d0e21e
LW
2970 case KEY_map:
2971 LOP(OP_MAPSTART,XREF);
2972
79072805 2973 case KEY_mkdir:
a0d0e21e 2974 LOP(OP_MKDIR,XTERM);
79072805
LW
2975
2976 case KEY_msgctl:
a0d0e21e 2977 LOP(OP_MSGCTL,XTERM);
79072805
LW
2978
2979 case KEY_msgget:
a0d0e21e 2980 LOP(OP_MSGGET,XTERM);
79072805
LW
2981
2982 case KEY_msgrcv:
a0d0e21e 2983 LOP(OP_MSGRCV,XTERM);
79072805
LW
2984
2985 case KEY_msgsnd:
a0d0e21e 2986 LOP(OP_MSGSND,XTERM);
79072805 2987
93a17b20
LW
2988 case KEY_my:
2989 in_my = TRUE;
2990 yylval.ival = 1;
2991 OPERATOR(LOCAL);
2992
79072805 2993 case KEY_next:
a0d0e21e 2994 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
2995 LOOPX(OP_NEXT);
2996
2997 case KEY_ne:
2998 Eop(OP_SNE);
2999
a0d0e21e
LW
3000 case KEY_no:
3001 if (expect != XSTATE)
3002 yyerror("\"no\" not allowed in expression");
3003 s = force_word(s,WORD,FALSE,TRUE,FALSE);
89bfa8cd 3004 s = force_version(s);
a0d0e21e
LW
3005 yylval.ival = 0;
3006 OPERATOR(USE);
3007
3008 case KEY_not:
3009 OPERATOR(NOTOP);
3010
79072805 3011 case KEY_open:
93a17b20
LW
3012 s = skipspace(s);
3013 if (isIDFIRST(*s)) {
3014 char *t;
3015 for (d = s; isALNUM(*d); d++) ;
3016 t = skipspace(d);
3017 if (strchr("|&*+-=!?:.", *t))
3018 warn("Precedence problem: open %.*s should be open(%.*s)",
3019 d-s,s, d-s,s);
3020 }
a0d0e21e 3021 LOP(OP_OPEN,XTERM);
79072805 3022
463ee0b2 3023 case KEY_or:
a0d0e21e 3024 yylval.ival = OP_OR;
463ee0b2
LW
3025 OPERATOR(OROP);
3026
79072805
LW
3027 case KEY_ord:
3028 UNI(OP_ORD);
3029
3030 case KEY_oct:
3031 UNI(OP_OCT);
3032
3033 case KEY_opendir:
a0d0e21e 3034 LOP(OP_OPEN_DIR,XTERM);
79072805
LW
3035
3036 case KEY_print:
3037 checkcomma(s,tokenbuf,"filehandle");
a0d0e21e 3038 LOP(OP_PRINT,XREF);
79072805
LW
3039
3040 case KEY_printf:
3041 checkcomma(s,tokenbuf,"filehandle");
a0d0e21e 3042 LOP(OP_PRTF,XREF);
79072805 3043
c07a80fd
PP
3044 case KEY_prototype:
3045 UNI(OP_PROTOTYPE);
3046
79072805 3047 case KEY_push:
a0d0e21e 3048 LOP(OP_PUSH,XTERM);
79072805
LW
3049
3050 case KEY_pop:
3051 UNI(OP_POP);
3052
a0d0e21e
LW
3053 case KEY_pos:
3054 UNI(OP_POS);
3055
79072805 3056 case KEY_pack:
a0d0e21e 3057 LOP(OP_PACK,XTERM);
79072805
LW
3058
3059 case KEY_package:
a0d0e21e 3060 s = force_word(s,WORD,FALSE,TRUE,FALSE);
79072805
LW
3061 OPERATOR(PACKAGE);
3062
3063 case KEY_pipe:
a0d0e21e 3064 LOP(OP_PIPE_OP,XTERM);
79072805
LW
3065
3066 case KEY_q:
3067 s = scan_str(s);
3068 if (!s)
85e6fe83 3069 missingterm((char*)0);
79072805
LW
3070 yylval.ival = OP_CONST;
3071 TERM(sublex_start());
3072
a0d0e21e
LW
3073 case KEY_quotemeta:
3074 UNI(OP_QUOTEMETA);
3075
8990e307
LW
3076 case KEY_qw:
3077 s = scan_str(s);
3078 if (!s)
85e6fe83 3079 missingterm((char*)0);
8990e307
LW
3080 force_next(')');
3081 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, q(lex_stuff));
3082 lex_stuff = Nullsv;
3083 force_next(THING);
3084 force_next(',');
3085 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(" ",1));
3086 force_next(THING);
3087 force_next('(');
a0d0e21e
LW
3088 yylval.ival = OP_SPLIT;
3089 CLINE;
3090 expect = XTERM;
3091 bufptr = s;
3092 last_lop = oldbufptr;
3093 last_lop_op = OP_SPLIT;
3094 return FUNC;
8990e307 3095
79072805
LW
3096 case KEY_qq:
3097 s = scan_str(s);
3098 if (!s)
85e6fe83 3099 missingterm((char*)0);
a0d0e21e 3100 yylval.ival = OP_STRINGIFY;
ed6116ce
LW
3101 if (SvIVX(lex_stuff) == '\'')
3102 SvIVX(lex_stuff) = 0; /* qq'$foo' should intepolate */
79072805
LW
3103 TERM(sublex_start());
3104
3105 case KEY_qx:
3106 s = scan_str(s);
3107 if (!s)
85e6fe83 3108 missingterm((char*)0);
79072805
LW
3109 yylval.ival = OP_BACKTICK;
3110 set_csh();
3111 TERM(sublex_start());
3112
3113 case KEY_return:
3114 OLDLOP(OP_RETURN);
3115
3116 case KEY_require:
748a9306 3117 *tokenbuf = '\0';
a0d0e21e 3118 s = force_word(s,WORD,TRUE,TRUE,FALSE);
748a9306 3119 if (isIDFIRST(*tokenbuf))
89bfa8cd 3120 gv_stashpvn(tokenbuf, strlen(tokenbuf), TRUE);
748a9306 3121 else if (*s == '<')
a0d0e21e 3122 yyerror("<> should be quotes");
463ee0b2 3123 UNI(OP_REQUIRE);
79072805
LW
3124
3125 case KEY_reset:
3126 UNI(OP_RESET);
3127
3128 case KEY_redo:
a0d0e21e 3129 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
3130 LOOPX(OP_REDO);
3131
3132 case KEY_rename:
a0d0e21e 3133 LOP(OP_RENAME,XTERM);
79072805
LW
3134
3135 case KEY_rand:
3136 UNI(OP_RAND);
3137
3138 case KEY_rmdir:
3139 UNI(OP_RMDIR);
3140
3141 case KEY_rindex:
a0d0e21e 3142 LOP(OP_RINDEX,XTERM);
79072805
LW
3143
3144 case KEY_read:
a0d0e21e 3145 LOP(OP_READ,XTERM);
79072805
LW
3146
3147 case KEY_readdir:
3148 UNI(OP_READDIR);
3149
93a17b20
LW
3150 case KEY_readline:
3151 set_csh();
3152 UNI(OP_READLINE);
3153
3154 case KEY_readpipe:
3155 set_csh();
3156 UNI(OP_BACKTICK);
3157
79072805
LW
3158 case KEY_rewinddir:
3159 UNI(OP_REWINDDIR);
3160
3161 case KEY_recv:
a0d0e21e 3162 LOP(OP_RECV,XTERM);
79072805
LW
3163
3164 case KEY_reverse:
a0d0e21e 3165 LOP(OP_REVERSE,XTERM);
79072805
LW
3166
3167 case KEY_readlink:
3168 UNI(OP_READLINK);
3169
3170 case KEY_ref:
3171 UNI(OP_REF);
3172
3173 case KEY_s:
3174 s = scan_subst(s);
3175 if (yylval.opval)
3176 TERM(sublex_start());
3177 else
3178 TOKEN(1); /* force error */
3179
a0d0e21e
LW
3180 case KEY_chomp:
3181 UNI(OP_CHOMP);
3182
79072805
LW
3183 case KEY_scalar:
3184 UNI(OP_SCALAR);
3185
3186 case KEY_select:
a0d0e21e 3187 LOP(OP_SELECT,XTERM);
79072805
LW
3188
3189 case KEY_seek:
a0d0e21e 3190 LOP(OP_SEEK,XTERM);
79072805
LW
3191
3192 case KEY_semctl:
a0d0e21e 3193 LOP(OP_SEMCTL,XTERM);
79072805
LW
3194
3195 case KEY_semget:
a0d0e21e 3196 LOP(OP_SEMGET,XTERM);
79072805
LW
3197
3198 case KEY_semop:
a0d0e21e 3199 LOP(OP_SEMOP,XTERM);
79072805
LW
3200
3201 case KEY_send:
a0d0e21e 3202 LOP(OP_SEND,XTERM);
79072805
LW
3203
3204 case KEY_setpgrp:
a0d0e21e 3205 LOP(OP_SETPGRP,XTERM);
79072805
LW
3206
3207 case KEY_setpriority:
a0d0e21e 3208 LOP(OP_SETPRIORITY,XTERM);
79072805
LW
3209
3210 case KEY_sethostent:
3211 FUN1(OP_SHOSTENT);
3212
3213 case KEY_setnetent:
3214 FUN1(OP_SNETENT);
3215
3216 case KEY_setservent:
3217 FUN1(OP_SSERVENT);
3218
3219 case KEY_setprotoent:
3220 FUN1(OP_SPROTOENT);
3221
3222 case KEY_setpwent:
3223 FUN0(OP_SPWENT);
3224
3225 case KEY_setgrent:
3226 FUN0(OP_SGRENT);
3227
3228 case KEY_seekdir:
a0d0e21e 3229 LOP(OP_SEEKDIR,XTERM);
79072805
LW
3230
3231 case KEY_setsockopt:
a0d0e21e 3232 LOP(OP_SSOCKOPT,XTERM);
79072805
LW
3233
3234 case KEY_shift:
3235 UNI(OP_SHIFT);
3236
3237 case KEY_shmctl:
a0d0e21e 3238 LOP(OP_SHMCTL,XTERM);
79072805
LW
3239
3240 case KEY_shmget:
a0d0e21e 3241 LOP(OP_SHMGET,XTERM);
79072805
LW
3242
3243 case KEY_shmread:
a0d0e21e 3244 LOP(OP_SHMREAD,XTERM);
79072805
LW
3245
3246 case KEY_shmwrite:
a0d0e21e 3247 LOP(OP_SHMWRITE,XTERM);
79072805
LW
3248
3249 case KEY_shutdown:
a0d0e21e 3250 LOP(OP_SHUTDOWN,XTERM);
79072805
LW
3251
3252 case KEY_sin:
3253 UNI(OP_SIN);
3254
3255 case KEY_sleep:
3256 UNI(OP_SLEEP);
3257
3258 case KEY_socket:
a0d0e21e 3259 LOP(OP_SOCKET,XTERM);
79072805
LW
3260
3261 case KEY_socketpair:
a0d0e21e 3262 LOP(OP_SOCKPAIR,XTERM);
79072805
LW
3263
3264 case KEY_sort:
3265 checkcomma(s,tokenbuf,"subroutine name");
3266 s = skipspace(s);
3267 if (*s == ';' || *s == ')') /* probably a close */
463ee0b2
LW
3268 croak("sort is now a reserved word");
3269 expect = XTERM;
a0d0e21e
LW
3270 s = force_word(s,WORD,TRUE,TRUE,TRUE);
3271 LOP(OP_SORT,XREF);
79072805
LW
3272
3273 case KEY_split:
a0d0e21e 3274 LOP(OP_SPLIT,XTERM);
79072805
LW
3275
3276 case KEY_sprintf:
a0d0e21e 3277 LOP(OP_SPRINTF,XTERM);
79072805
LW
3278
3279 case KEY_splice:
a0d0e21e 3280 LOP(OP_SPLICE,XTERM);
79072805
LW
3281
3282 case KEY_sqrt:
3283 UNI(OP_SQRT);
3284
3285 case KEY_srand:
3286 UNI(OP_SRAND);
3287
3288 case KEY_stat:
3289 UNI(OP_STAT);
3290
3291 case KEY_study:
3292 sawstudy++;
3293 UNI(OP_STUDY);
3294
3295 case KEY_substr:
a0d0e21e 3296 LOP(OP_SUBSTR,XTERM);
79072805
LW
3297
3298 case KEY_format:
3299 case KEY_sub:
93a17b20 3300 really_sub:
79072805 3301 s = skipspace(s);
4633a7c4 3302
463ee0b2
LW
3303 if (isIDFIRST(*s) || *s == '\'' || *s == ':') {
3304 char tmpbuf[128];
4633a7c4 3305 expect = XBLOCK;
463ee0b2
LW
3306 d = scan_word(s, tmpbuf, TRUE, &len);
3307 if (strchr(tmpbuf, ':'))
3308 sv_setpv(subname, tmpbuf);
3309 else {
3310 sv_setsv(subname,curstname);
8990e307 3311 sv_catpvn(subname,"::",2);
463ee0b2
LW
3312 sv_catpvn(subname,tmpbuf,len);
3313 }
a0d0e21e 3314 s = force_word(s,WORD,FALSE,TRUE,TRUE);
4633a7c4 3315 s = skipspace(s);
79072805 3316 }
4633a7c4
LW
3317 else {
3318 expect = XTERMBLOCK;
79072805 3319 sv_setpv(subname,"?");
4633a7c4
LW
3320 }
3321
3322 if (tmp == KEY_format) {
3323 s = skipspace(s);
3324 if (*s == '=')
3325 lex_formbrack = lex_brackets + 1;
3326 OPERATOR(FORMAT);
3327 }
79072805 3328
4633a7c4
LW
3329 /* Look for a prototype */
3330 if (*s == '(') {
3331 s = scan_str(s);
3332 if (!s) {
3333 if (lex_stuff)
3334 SvREFCNT_dec(lex_stuff);
3335 lex_stuff = Nullsv;
3336 croak("Prototype not terminated");
3337 }
3338 nexttoke++;
3339 nextval[1] = nextval[0];
3340 nexttype[1] = nexttype[0];
3341 nextval[0].opval = (OP*)newSVOP(OP_CONST, 0, lex_stuff);
3342 nexttype[0] = THING;
3343 if (nexttoke == 1) {
3344 lex_defer = lex_state;
3345 lex_expect = expect;
3346 lex_state = LEX_KNOWNEXT;
3347 }
3348 lex_stuff = Nullsv;
3349 }
79072805 3350
4633a7c4
LW
3351 if (*SvPV(subname,na) == '?') {
3352 sv_setpv(subname,"__ANON__");
3353 TOKEN(ANONSUB);
3354 }
3355 PREBLOCK(SUB);
79072805
LW
3356
3357 case KEY_system:
3358 set_csh();
a0d0e21e 3359 LOP(OP_SYSTEM,XREF);
79072805
LW
3360
3361 case KEY_symlink:
a0d0e21e 3362 LOP(OP_SYMLINK,XTERM);
79072805
LW
3363
3364 case KEY_syscall:
a0d0e21e 3365 LOP(OP_SYSCALL,XTERM);
79072805 3366
c07a80fd
PP
3367 case KEY_sysopen:
3368 LOP(OP_SYSOPEN,XTERM);
3369
79072805 3370 case KEY_sysread:
a0d0e21e 3371 LOP(OP_SYSREAD,XTERM);
79072805
LW
3372
3373 case KEY_syswrite:
a0d0e21e 3374 LOP(OP_SYSWRITE,XTERM);
79072805
LW
3375
3376 case KEY_tr:
3377 s = scan_trans(s);
3378 TERM(sublex_start());
3379
3380 case KEY_tell:
3381 UNI(OP_TELL);
3382
3383 case KEY_telldir:
3384 UNI(OP_TELLDIR);
3385
463ee0b2 3386 case KEY_tie:
a0d0e21e 3387 LOP(OP_TIE,XTERM);
463ee0b2 3388
c07a80fd
PP
3389 case KEY_tied:
3390 UNI(OP_TIED);
3391
79072805
LW
3392 case KEY_time:
3393 FUN0(OP_TIME);
3394
3395 case KEY_times:
3396 FUN0(OP_TMS);
3397
3398 case KEY_truncate:
a0d0e21e 3399 LOP(OP_TRUNCATE,XTERM);
79072805
LW
3400
3401 case KEY_uc:
3402 UNI(OP_UC);
3403
3404 case KEY_ucfirst:
3405 UNI(OP_UCFIRST);
3406
463ee0b2
LW
3407 case KEY_untie:
3408 UNI(OP_UNTIE);
3409
79072805
LW
3410 case KEY_until:
3411 yylval.ival = curcop->cop_line;
3412 OPERATOR(UNTIL);
3413
3414 case KEY_unless:
3415 yylval.ival = curcop->cop_line;
3416 OPERATOR(UNLESS);
3417
3418 case KEY_unlink:
a0d0e21e 3419 LOP(OP_UNLINK,XTERM);
79072805
LW
3420
3421 case KEY_undef:
3422 UNI(OP_UNDEF);
3423
3424 case KEY_unpack:
a0d0e21e 3425 LOP(OP_UNPACK,XTERM);
79072805
LW
3426
3427 case KEY_utime:
a0d0e21e 3428 LOP(OP_UTIME,XTERM);
79072805
LW
3429
3430 case KEY_umask:
748a9306
LW
3431 if (dowarn) {
3432 for (d = s; d < bufend && (isSPACE(*d) || *d == '('); d++) ;
3433 if (*d != '0' && isDIGIT(*d))
3434 yywarn("umask: argument is missing initial 0");
3435 }
79072805
LW
3436 UNI(OP_UMASK);
3437
3438 case KEY_unshift:
a0d0e21e
LW
3439 LOP(OP_UNSHIFT,XTERM);
3440
3441 case KEY_use:
3442 if (expect != XSTATE)
3443 yyerror("\"use\" not allowed in expression");
89bfa8cd
PP
3444 s = skipspace(s);
3445 if(isDIGIT(*s)) {
3446 s = force_version(s);
3447 if(*s == ';' || (s = skipspace(s), *s == ';')) {
3448 nextval[nexttoke].opval = Nullop;
3449 force_next(WORD);
3450 }
3451 }
3452 else {
3453 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3454 s = force_version(s);
3455 }
a0d0e21e
LW
3456 yylval.ival = 1;
3457 OPERATOR(USE);
79072805
LW
3458
3459 case KEY_values:
3460 UNI(OP_VALUES);
3461
3462 case KEY_vec:
3463 sawvec = TRUE;
a0d0e21e 3464 LOP(OP_VEC,XTERM);
79072805
LW
3465
3466 case KEY_while:
3467 yylval.ival = curcop->cop_line;
3468 OPERATOR(WHILE);
3469
3470 case KEY_warn:
a0d0e21e
LW
3471 hints |= HINT_BLOCK_SCOPE;
3472 LOP(OP_WARN,XTERM);
79072805
LW
3473
3474 case KEY_wait:
3475 FUN0(OP_WAIT);
3476
3477 case KEY_waitpid:
a0d0e21e 3478 LOP(OP_WAITPID,XTERM);
79072805
LW
3479
3480 case KEY_wantarray:
3481 FUN0(OP_WANTARRAY);
3482
3483 case KEY_write:
85e6fe83 3484 gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */
79072805
LW
3485 UNI(OP_ENTERWRITE);
3486
3487 case KEY_x:
3488 if (expect == XOPERATOR)
3489 Mop(OP_REPEAT);
3490 check_uni();
3491 goto just_a_word;
3492
a0d0e21e
LW
3493 case KEY_xor:
3494 yylval.ival = OP_XOR;
3495 OPERATOR(OROP);
3496
79072805
LW
3497 case KEY_y:
3498 s = scan_trans(s);
3499 TERM(sublex_start());
3500 }
3501 }
3502}
3503
3504I32
3505keyword(d, len)
3506register char *d;
3507I32 len;
3508{
3509 switch (*d) {
3510 case '_':
3511 if (d[1] == '_') {
a0d0e21e
LW
3512 if (strEQ(d,"__LINE__")) return -KEY___LINE__;
3513 if (strEQ(d,"__FILE__")) return -KEY___FILE__;
e50aee73 3514 if (strEQ(d,"__DATA__")) return KEY___DATA__;
79072805
LW
3515 if (strEQ(d,"__END__")) return KEY___END__;
3516 }
3517 break;
8990e307
LW
3518 case 'A':
3519 if (strEQ(d,"AUTOLOAD")) return KEY_AUTOLOAD;
3520 break;
79072805 3521 case 'a':
463ee0b2
LW
3522 switch (len) {
3523 case 3:
a0d0e21e
LW
3524 if (strEQ(d,"and")) return -KEY_and;
3525 if (strEQ(d,"abs")) return -KEY_abs;
85e6fe83 3526 break;
463ee0b2 3527 case 5:
a0d0e21e
LW
3528 if (strEQ(d,"alarm")) return -KEY_alarm;
3529 if (strEQ(d,"atan2")) return -KEY_atan2;
463ee0b2
LW
3530 break;
3531 case 6:
a0d0e21e 3532 if (strEQ(d,"accept")) return -KEY_accept;
463ee0b2
LW
3533 break;
3534 }
79072805
LW
3535 break;
3536 case 'B':
3537 if (strEQ(d,"BEGIN")) return KEY_BEGIN;
93a17b20 3538 break;
79072805 3539 case 'b':
a0d0e21e
LW
3540 if (strEQ(d,"bless")) return -KEY_bless;
3541 if (strEQ(d,"bind")) return -KEY_bind;
3542 if (strEQ(d,"binmode")) return -KEY_binmode;
3543 break;
3544 case 'C':
3545 if (strEQ(d,"CORE")) return -KEY_CORE;
79072805
LW
3546 break;
3547 case 'c':
3548 switch (len) {
3549 case 3:
a0d0e21e
LW
3550 if (strEQ(d,"cmp")) return -KEY_cmp;
3551 if (strEQ(d,"chr")) return -KEY_chr;
3552 if (strEQ(d,"cos")) return -KEY_cos;
79072805
LW
3553 break;
3554 case 4:
3555 if (strEQ(d,"chop")) return KEY_chop;
3556 break;
3557 case 5:
a0d0e21e
LW
3558 if (strEQ(d,"close")) return -KEY_close;
3559 if (strEQ(d,"chdir")) return -KEY_chdir;
3560 if (strEQ(d,"chomp")) return KEY_chomp;
3561 if (strEQ(d,"chmod")) return -KEY_chmod;
3562 if (strEQ(d,"chown")) return -KEY_chown;
3563 if (strEQ(d,"crypt")) return -KEY_crypt;
79072805
LW
3564 break;
3565 case 6:
a0d0e21e
LW
3566 if (strEQ(d,"chroot")) return -KEY_chroot;
3567 if (strEQ(d,"caller")) return -KEY_caller;
79072805
LW
3568 break;
3569 case 7:
a0d0e21e 3570 if (strEQ(d,"connect")) return -KEY_connect;
79072805
LW
3571 break;
3572 case 8:
a0d0e21e
LW
3573 if (strEQ(d,"closedir")) return -KEY_closedir;
3574 if (strEQ(d,"continue")) return -KEY_continue;
79072805
LW
3575 break;
3576 }
3577 break;
ed6116ce
LW
3578 case 'D':
3579 if (strEQ(d,"DESTROY")) return KEY_DESTROY;
3580 break;
79072805
LW
3581 case 'd':
3582 switch (len) {
3583 case 2:
3584 if (strEQ(d,"do")) return KEY_do;
3585 break;
3586 case 3:
a0d0e21e 3587 if (strEQ(d,"die")) return -KEY_die;
79072805
LW
3588 break;
3589 case 4:
a0d0e21e 3590 if (strEQ(d,"dump")) return -KEY_dump;
79072805
LW
3591 break;
3592 case 6:
3593 if (strEQ(d,"delete")) return KEY_delete;
3594 break;
3595 case 7:
3596 if (strEQ(d,"defined")) return KEY_defined;
a0d0e21e 3597 if (strEQ(d,"dbmopen")) return -KEY_dbmopen;
79072805
LW
3598 break;
3599 case 8:
a0d0e21e 3600 if (strEQ(d,"dbmclose")) return -KEY_dbmclose;
79072805
LW
3601 break;
3602 }
3603 break;
3604 case 'E':
a0d0e21e 3605 if (strEQ(d,"EQ")) { deprecate(d); return -KEY_eq;}
79072805
LW
3606 if (strEQ(d,"END")) return KEY_END;
3607 break;
3608 case 'e':
3609 switch (len) {
3610 case 2:
a0d0e21e 3611 if (strEQ(d,"eq")) return -KEY_eq;
79072805
LW
3612 break;
3613 case 3:
a0d0e21e
LW
3614 if (strEQ(d,"eof")) return -KEY_eof;
3615 if (strEQ(d,"exp")) return -KEY_exp;
79072805
LW
3616 break;
3617 case 4:
3618 if (strEQ(d,"else")) return KEY_else;
a0d0e21e 3619 if (strEQ(d,"exit")) return -KEY_exit;
79072805 3620 if (strEQ(d,"eval")) return KEY_eval;
a0d0e21e 3621 if (strEQ(d,"exec")) return -KEY_exec;
79072805
LW
3622 if (strEQ(d,"each")) return KEY_each;
3623 break;
3624 case 5:
3625 if (strEQ(d,"elsif")) return KEY_elsif;
3626 break;
a0d0e21e
LW
3627 case 6:
3628 if (strEQ(d,"exists")) return KEY_exists;
4633a7c4 3629 if (strEQ(d,"elseif")) warn("elseif should be elsif");
a0d0e21e 3630 break;
79072805 3631 case 8:
a0d0e21e
LW
3632 if (strEQ(d,"endgrent")) return -KEY_endgrent;
3633 if (strEQ(d,"endpwent")) return -KEY_endpwent;
79072805
LW
3634 break;
3635 case 9:
a0d0e21e 3636 if (strEQ(d,"endnetent")) return -KEY_endnetent;
79072805
LW
3637 break;
3638 case 10:
a0d0e21e
LW
3639 if (strEQ(d,"endhostent")) return -KEY_endhostent;
3640 if (strEQ(d,"endservent")) return -KEY_endservent;
79072805
LW
3641 break;
3642 case 11:
a0d0e21e 3643 if (strEQ(d,"endprotoent")) return -KEY_endprotoent;
79072805 3644 break;
a687059c 3645 }
a687059c 3646 break;
79072805
LW
3647 case 'f':
3648 switch (len) {
3649 case 3:
3650 if (strEQ(d,"for")) return KEY_for;
3651 break;
3652 case 4:
a0d0e21e 3653 if (strEQ(d,"fork")) return -KEY_fork;
79072805
LW
3654 break;
3655 case 5:
a0d0e21e
LW
3656 if (strEQ(d,"fcntl")) return -KEY_fcntl;
3657 if (strEQ(d,"flock")) return -KEY_flock;
79072805
LW
3658 break;
3659 case 6:
3660 if (strEQ(d,"format")) return KEY_format;
a0d0e21e 3661 if (strEQ(d,"fileno")) return -KEY_fileno;
79072805
LW
3662 break;
3663 case 7:
3664 if (strEQ(d,"foreach")) return KEY_foreach;
3665 break;
3666 case 8:
a0d0e21e 3667 if (strEQ(d,"formline")) return -KEY_formline;
79072805 3668 break;
378cc40b 3669 }
a687059c 3670 break;
79072805
LW
3671 case 'G':
3672 if (len == 2) {
a0d0e21e
LW
3673 if (strEQ(d,"GT")) { deprecate(d); return -KEY_gt;}
3674 if (strEQ(d,"GE")) { deprecate(d); return -KEY_ge;}
9f68db38 3675 }
a687059c 3676 break;
79072805 3677 case 'g':
a687059c
LW
3678 if (strnEQ(d,"get",3)) {
3679 d += 3;
3680 if (*d == 'p') {
79072805
LW
3681 switch (len) {
3682 case 7:
a0d0e21e
LW
3683 if (strEQ(d,"ppid")) return -KEY_getppid;
3684 if (strEQ(d,"pgrp")) return -KEY_getpgrp;
79072805
LW
3685 break;
3686 case 8:
a0d0e21e
LW
3687 if (strEQ(d,"pwent")) return -KEY_getpwent;
3688 if (strEQ(d,"pwnam")) return -KEY_getpwnam;
3689 if (strEQ(d,"pwuid")) return -KEY_getpwuid;
79072805
LW
3690 break;
3691 case 11:
a0d0e21e
LW
3692 if (strEQ(d,"peername")) return -KEY_getpeername;
3693 if (strEQ(d,"protoent")) return -KEY_getprotoent;
3694 if (strEQ(d,"priority")) return -KEY_getpriority;
79072805
LW
3695 break;
3696 case 14:
a0d0e21e 3697 if (strEQ(d,"protobyname")) return -KEY_getprotobyname;
79072805
LW
3698 break;
3699 case 16:
a0d0e21e 3700 if (strEQ(d,"protobynumber"))return -KEY_getprotobynumber;
79072805
LW
3701 break;
3702 }
a687059c
LW
3703 }
3704 else if (*d == 'h') {
a0d0e21e
LW
3705 if (strEQ(d,"hostbyname")) return -KEY_gethostbyname;
3706 if (strEQ(d,"hostbyaddr")) return -KEY_gethostbyaddr;
3707 if (strEQ(d,"hostent")) return -KEY_gethostent;
a687059c
LW
3708 }
3709 else if (*d == 'n') {
a0d0e21e
LW
3710 if (strEQ(d,"netbyname")) return -KEY_getnetbyname;
3711 if (strEQ(d,"netbyaddr")) return -KEY_getnetbyaddr;
3712 if (strEQ(d,"netent")) return -KEY_getnetent;
a687059c
LW
3713 }
3714 else if (*d == 's') {
a0d0e21e
LW
3715 if (strEQ(d,"servbyname")) return -KEY_getservbyname;
3716 if (strEQ(d,"servbyport")) return -KEY_getservbyport;
3717 if (strEQ(d,"servent")) return -KEY_getservent;
3718 if (strEQ(d,"sockname")) return -KEY_getsockname;
3719 if (strEQ(d,"sockopt")) return -KEY_getsockopt;
a687059c
LW
3720 }
3721 else if (*d == 'g') {
a0d0e21e
LW
3722 if (strEQ(d,"grent")) return -KEY_getgrent;
3723 if (strEQ(d,"grnam")) return -KEY_getgrnam;
3724 if (strEQ(d,"grgid")) return -KEY_getgrgid;
a687059c
LW
3725 }
3726 else if (*d == 'l') {
a0d0e21e 3727 if (strEQ(d,"login")) return -KEY_getlogin;
a687059c 3728 }
a0d0e21e 3729 else if (strEQ(d,"c")) return -KEY_getc;
79072805 3730 break;
a687059c 3731 }
79072805
LW
3732 switch (len) {
3733 case 2:
a0d0e21e
LW
3734 if (strEQ(d,"gt")) return -KEY_gt;
3735 if (strEQ(d,"ge")) return -KEY_ge;
79072805
LW
3736 break;
3737 case 4:
3738 if (strEQ(d,"grep")) return KEY_grep;
3739 if (strEQ(d,"goto")) return KEY_goto;
a0d0e21e 3740 if (strEQ(d,"glob")) return -KEY_glob;
79072805
LW
3741 break;
3742 case 6:
a0d0e21e 3743 if (strEQ(d,"gmtime")) return -KEY_gmtime;
79072805 3744 break;
378cc40b 3745 }
a687059c 3746 break;
79072805 3747 case 'h':
a0d0e21e 3748 if (strEQ(d,"hex")) return -KEY_hex;
a687059c 3749 break;
79072805
LW
3750 case 'i':
3751 switch (len) {
3752 case 2:
3753 if (strEQ(d,"if")) return KEY_if;
3754 break;
3755 case 3:
a0d0e21e 3756 if (strEQ(d,"int")) return -KEY_int;
79072805
LW
3757 break;
3758 case 5:
a0d0e21e
LW
3759 if (strEQ(d,"index")) return -KEY_index;
3760 if (strEQ(d,"ioctl")) return -KEY_ioctl;
79072805
LW
3761 break;
3762 }
a687059c 3763 break;
79072805 3764 case 'j':
a0d0e21e 3765 if (strEQ(d,"join")) return -KEY_join;
a687059c 3766 break;
79072805
LW
3767 case 'k':
3768 if (len == 4) {
3769 if (strEQ(d,"keys")) return KEY_keys;
a0d0e21e 3770 if (strEQ(d,"kill")) return -KEY_kill;
663a0e37 3771 }
79072805
LW
3772 break;
3773 case 'L':
3774 if (len == 2) {
a0d0e21e
LW
3775 if (strEQ(d,"LT")) { deprecate(d); return -KEY_lt;}
3776 if (strEQ(d,"LE")) { deprecate(d); return -KEY_le;}
378cc40b 3777 }
79072805
LW
3778 break;
3779 case 'l':
3780 switch (len) {
3781 case 2:
a0d0e21e
LW
3782 if (strEQ(d,"lt")) return -KEY_lt;
3783 if (strEQ(d,"le")) return -KEY_le;
3784 if (strEQ(d,"lc")) return -KEY_lc;
79072805
LW
3785 break;
3786 case 3:
a0d0e21e 3787 if (strEQ(d,"log")) return -KEY_log;
79072805
LW
3788 break;
3789 case 4:
3790 if (strEQ(d,"last")) return KEY_last;
a0d0e21e 3791 if (strEQ(d,"link")) return -KEY_link;
395c3793 3792 break;
79072805
LW
3793 case 5:
3794 if (strEQ(d,"local")) return KEY_local;
a0d0e21e 3795 if (strEQ(d,"lstat")) return -KEY_lstat;
79072805
LW
3796 break;
3797 case 6:
a0d0e21e
LW
3798 if (strEQ(d,"length")) return -KEY_length;
3799 if (strEQ(d,"listen")) return -KEY_listen;
79072805
LW
3800 break;
3801 case 7:
a0d0e21e 3802 if (strEQ(d,"lcfirst")) return -KEY_lcfirst;
79072805
LW
3803 break;
3804 case 9:
a0d0e21e 3805 if (strEQ(d,"localtime")) return -KEY_localtime;
395c3793
LW
3806 break;
3807 }
a687059c 3808 break;
79072805
LW
3809 case 'm':
3810 switch (len) {
3811 case 1: return KEY_m;
93a17b20
LW
3812 case 2:
3813 if (strEQ(d,"my")) return KEY_my;
3814 break;
a0d0e21e
LW
3815 case 3:
3816 if (strEQ(d,"map")) return KEY_map;
3817 break;
79072805 3818 case 5:
a0d0e21e 3819 if (strEQ(d,"mkdir")) return -KEY_mkdir;
79072805
LW
3820 break;
3821 case 6:
a0d0e21e
LW
3822 if (strEQ(d,"msgctl")) return -KEY_msgctl;
3823 if (strEQ(d,"msgget")) return -KEY_msgget;
3824 if (strEQ(d,"msgrcv")) return -KEY_msgrcv;
3825 if (strEQ(d,"msgsnd")) return -KEY_msgsnd;
79072805
LW
3826 break;
3827 }
a687059c 3828 break;
79072805 3829 case 'N':
a0d0e21e 3830 if (strEQ(d,"NE")) { deprecate(d); return -KEY_ne;}
a687059c 3831 break;
79072805
LW
3832 case 'n':
3833 if (strEQ(d,"next")) return KEY_next;
a0d0e21e
LW
3834 if (strEQ(d,"ne")) return -KEY_ne;
3835 if (strEQ(d,"not")) return -KEY_not;
3836 if (strEQ(d,"no")) return KEY_no;
a687059c 3837 break;
79072805
LW
3838 case 'o':
3839 switch (len) {
463ee0b2 3840 case 2:
a0d0e21e 3841 if (strEQ(d,"or")) return -KEY_or;
463ee0b2 3842 break;
79072805 3843 case 3:
a0d0e21e
LW
3844 if (strEQ(d,"ord")) return -KEY_ord;
3845 if (strEQ(d,"oct")) return -KEY_oct;
79072805
LW
3846 break;
3847 case 4:
a0d0e21e 3848 if (strEQ(d,"open")) return -KEY_open;
79072805
LW
3849 break;
3850 case 7:
a0d0e21e 3851 if (strEQ(d,"opendir")) return -KEY_opendir;
79072805 3852 break;
fe14fcc3 3853 }
a687059c 3854 break;
79072805
LW
3855 case 'p':
3856 switch (len) {
3857 case 3:
3858 if (strEQ(d,"pop")) return KEY_pop;
a0d0e21e 3859 if (strEQ(d,"pos")) return KEY_pos;
79072805
LW
3860 break;
3861 case 4:
3862 if (strEQ(d,"push")) return KEY_push;
a0d0e21e
LW
3863 if (strEQ(d,"pack")) return -KEY_pack;
3864 if (strEQ(d,"pipe")) return -KEY_pipe;
79072805
LW
3865 break;
3866 case 5:
3867 if (strEQ(d,"print")) return KEY_print;
3868 break;
3869 case 6:
3870 if (strEQ(d,"printf")) return KEY_printf;
3871 break;
3872 case 7:
3873 if (strEQ(d,"package")) return KEY_package;
3874 break;
c07a80fd
PP
3875 case 9:
3876 if (strEQ(d,"prototype")) return KEY_prototype;