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