This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Do not constant-fold ops that depend on locale if C<use locale>
[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);
1993 if (isALPHA(*s)) {
c07a80fd 1994 for (t = s; t < bufend && isALNUM(*t); t++) ;
a0d0e21e
LW
1995 }
1996 else if (*s == '\'' || *s == '"') {
1997 t = strchr(s+1,*s);
1998 if (!t++)
1999 t = s;
2000 }
2001 else
2002 t = s;
2003 while (t < bufend && isSPACE(*t))
2004 t++;
2005 if ((*t == ',' && !isLOWER(*s)) || (*t == '=' && t[1] == '>'))
2006 OPERATOR(HASHBRACK);
2007 if (expect == XREF)
2008 expect = XTERM;
2009 else {
2010 lex_brackstack[lex_brackets-1] = XSTATE;
2011 expect = XSTATE;
2012 }
8990e307 2013 }
a0d0e21e 2014 break;
463ee0b2 2015 }
79072805
LW
2016 yylval.ival = curcop->cop_line;
2017 if (isSPACE(*s) || *s == '#')
2018 copline = NOLINE; /* invalidate current command line number */
79072805 2019 TOKEN('{');
378cc40b 2020 case '}':
79072805
LW
2021 rightbracket:
2022 s++;
463ee0b2
LW
2023 if (lex_brackets <= 0)
2024 yyerror("Unmatched right bracket");
2025 else
2026 expect = (expectation)lex_brackstack[--lex_brackets];
85e6fe83
LW
2027 if (lex_brackets < lex_formbrack)
2028 lex_formbrack = 0;
79072805 2029 if (lex_state == LEX_INTERPNORMAL) {
463ee0b2 2030 if (lex_brackets == 0) {
79072805
LW
2031 if (lex_fakebrack) {
2032 lex_state = LEX_INTERPEND;
2033 bufptr = s;
2034 return yylex(); /* ignore fake brackets */
2035 }
fa83b5b6
PP
2036 if (*s == '-' && s[1] == '>')
2037 lex_state = LEX_INTERPENDMAYBE;
2038 else if (*s != '[' && *s != '{')
79072805
LW
2039 lex_state = LEX_INTERPEND;
2040 }
2041 }
748a9306
LW
2042 if (lex_brackets < lex_fakebrack) {
2043 bufptr = s;
2044 lex_fakebrack = 0;
2045 return yylex(); /* ignore fake brackets */
2046 }
79072805
LW
2047 force_next('}');
2048 TOKEN(';');
378cc40b
LW
2049 case '&':
2050 s++;
2051 tmp = *s++;
2052 if (tmp == '&')
a0d0e21e 2053 AOPERATOR(ANDAND);
378cc40b 2054 s--;
463ee0b2 2055 if (expect == XOPERATOR) {
fd049845 2056 if (dowarn && isALPHA(*s) && bufptr == linestart) {
463ee0b2
LW
2057 curcop->cop_line--;
2058 warn(warn_nosemi);
2059 curcop->cop_line++;
2060 }
79072805 2061 BAop(OP_BIT_AND);
463ee0b2 2062 }
79072805 2063
8903cb82 2064 s = scan_ident(s - 1, bufend, tokenbuf, sizeof tokenbuf, TRUE);
463ee0b2
LW
2065 if (*tokenbuf) {
2066 expect = XOPERATOR;
a0d0e21e 2067 force_ident(tokenbuf, '&');
463ee0b2 2068 }
79072805
LW
2069 else
2070 PREREF('&');
c07a80fd 2071 yylval.ival = (OPpENTERSUB_AMPER<<8);
79072805
LW
2072 TERM('&');
2073
378cc40b
LW
2074 case '|':
2075 s++;
2076 tmp = *s++;
2077 if (tmp == '|')
a0d0e21e 2078 AOPERATOR(OROR);
378cc40b 2079 s--;
79072805 2080 BOop(OP_BIT_OR);
378cc40b
LW
2081 case '=':
2082 s++;
2083 tmp = *s++;
2084 if (tmp == '=')
79072805
LW
2085 Eop(OP_EQ);
2086 if (tmp == '>')
2087 OPERATOR(',');
378cc40b 2088 if (tmp == '~')
79072805 2089 PMop(OP_MATCH);
463ee0b2 2090 if (dowarn && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
ff0cee69 2091 warn("Reversed %c= operator",(int)tmp);
378cc40b 2092 s--;
748a9306 2093 if (expect == XSTATE && isALPHA(tmp) &&
fd049845 2094 (s == linestart+1 || s[-2] == '\n') )
748a9306 2095 {
a5f75d66
AD
2096 if (in_eval && !rsfp) {
2097 d = bufend;
2098 while (s < d) {
2099 if (*s++ == '\n') {
2100 incline(s);
2101 if (strnEQ(s,"=cut",4)) {
2102 s = strchr(s,'\n');
2103 if (s)
2104 s++;
2105 else
2106 s = d;
2107 incline(s);
2108 goto retry;
2109 }
2110 }
2111 }
2112 goto retry;
2113 }
a0d0e21e
LW
2114 s = bufend;
2115 doextract = TRUE;
2116 goto retry;
2117 }
2118 if (lex_brackets < lex_formbrack) {
2119 char *t;
2120 for (t = s; *t == ' ' || *t == '\t'; t++) ;
2121 if (*t == '\n' || *t == '#') {
2122 s--;
2123 expect = XBLOCK;
2124 goto leftbracket;
2125 }
79072805 2126 }
a0d0e21e
LW
2127 yylval.ival = 0;
2128 OPERATOR(ASSIGNOP);
378cc40b
LW
2129 case '!':
2130 s++;
2131 tmp = *s++;
2132 if (tmp == '=')
79072805 2133 Eop(OP_NE);
378cc40b 2134 if (tmp == '~')
79072805 2135 PMop(OP_NOT);
378cc40b
LW
2136 s--;
2137 OPERATOR('!');
2138 case '<':
79072805 2139 if (expect != XOPERATOR) {
93a17b20 2140 if (s[1] != '<' && !strchr(s,'>'))
2f3197b3 2141 check_uni();
79072805
LW
2142 if (s[1] == '<')
2143 s = scan_heredoc(s);
2144 else
2145 s = scan_inputsymbol(s);
2146 TERM(sublex_start());
378cc40b
LW
2147 }
2148 s++;
2149 tmp = *s++;
2150 if (tmp == '<')
79072805 2151 SHop(OP_LEFT_SHIFT);
395c3793
LW
2152 if (tmp == '=') {
2153 tmp = *s++;
2154 if (tmp == '>')
79072805 2155 Eop(OP_NCMP);
395c3793 2156 s--;
79072805 2157 Rop(OP_LE);
395c3793 2158 }
378cc40b 2159 s--;
79072805 2160 Rop(OP_LT);
378cc40b
LW
2161 case '>':
2162 s++;
2163 tmp = *s++;
2164 if (tmp == '>')
79072805 2165 SHop(OP_RIGHT_SHIFT);
378cc40b 2166 if (tmp == '=')
79072805 2167 Rop(OP_GE);
378cc40b 2168 s--;
79072805 2169 Rop(OP_GT);
378cc40b
LW
2170
2171 case '$':
bbce6d69
PP
2172 CLINE;
2173
2174 if (expect == XOPERATOR) {
2175 if (lex_formbrack && lex_brackets == lex_formbrack) {
2176 expect = XTERM;
2177 depcom();
2178 return ','; /* grandfather non-comma-format format */
8990e307 2179 }
bbce6d69
PP
2180 }
2181
2182 if (s[1] == '#' && (isALPHA(s[2]) || strchr("_{$:", s[2]))) {
2183 if (expect == XOPERATOR)
2184 no_op("Array length", bufptr);
2185 tokenbuf[0] = '@';
8903cb82
PP
2186 s = scan_ident(s + 1, bufend, tokenbuf + 1, sizeof tokenbuf - 1,
2187 FALSE);
bbce6d69 2188 if (!tokenbuf[1])
a0d0e21e 2189 PREREF(DOLSHARP);
463ee0b2 2190 expect = XOPERATOR;
bbce6d69 2191 pending_ident = '#';
463ee0b2 2192 TOKEN(DOLSHARP);
79072805 2193 }
bbce6d69
PP
2194
2195 if (expect == XOPERATOR)
2196 no_op("Scalar", bufptr);
2197 tokenbuf[0] = '$';
8903cb82 2198 s = scan_ident(s, bufend, tokenbuf + 1, sizeof tokenbuf - 1, FALSE);
bbce6d69
PP
2199 if (!tokenbuf[1]) {
2200 if (s == bufend)
2201 yyerror("Final $ should be \\$ or $name");
2202 PREREF('$');
8990e307 2203 }
a0d0e21e 2204
bbce6d69
PP
2205 /* This kludge not intended to be bulletproof. */
2206 if (tokenbuf[1] == '[' && !tokenbuf[2]) {
2207 yylval.opval = newSVOP(OP_CONST, 0,
2208 newSViv((IV)compiling.cop_arybase));
2209 yylval.opval->op_private = OPpCONST_ARYBASE;
2210 TERM(THING);
2211 }
2212
ff68c719
PP
2213 d = s;
2214 if (lex_state == LEX_NORMAL)
2215 s = skipspace(s);
2216
bbce6d69
PP
2217 if ((expect != XREF || oldoldbufptr == last_lop) && intuit_more(s)) {
2218 char *t;
2219 if (*s == '[') {
2220 tokenbuf[0] = '@';
2221 if (dowarn) {
2222 for(t = s + 1;
2223 isSPACE(*t) || isALNUM(*t) || *t == '$';
2224 t++) ;
a0d0e21e
LW
2225 if (*t++ == ',') {
2226 bufptr = skipspace(bufptr);
bbce6d69
PP
2227 while (t < bufend && *t != ']')
2228 t++;
a0d0e21e 2229 warn("Multidimensional syntax %.*s not supported",
bbce6d69 2230 (t - bufptr) + 1, bufptr);
a0d0e21e
LW
2231 }
2232 }
bbce6d69
PP
2233 }
2234 else if (*s == '{') {
2235 tokenbuf[0] = '%';
2236 if (dowarn && strEQ(tokenbuf+1, "SIG") &&
2237 (t = strchr(s, '}')) && (t = strchr(t, '=')))
2238 {
8903cb82 2239 char tmpbuf[sizeof tokenbuf];
a0d0e21e
LW
2240 STRLEN len;
2241 for (t++; isSPACE(*t); t++) ;
748a9306 2242 if (isIDFIRST(*t)) {
8903cb82 2243 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
748a9306
LW
2244 if (*t != '(' && perl_get_cv(tmpbuf, FALSE))
2245 warn("You need to quote \"%s\"", tmpbuf);
2246 }
93a17b20
LW
2247 }
2248 }
2f3197b3 2249 }
bbce6d69
PP
2250
2251 expect = XOPERATOR;
ff68c719 2252 if (lex_state == LEX_NORMAL && isSPACE(*d)) {
bbce6d69 2253 bool islop = (last_lop == oldoldbufptr);
bbce6d69
PP
2254 if (!islop || last_lop_op == OP_GREPSTART)
2255 expect = XOPERATOR;
2256 else if (strchr("$@\"'`q", *s))
2257 expect = XTERM; /* e.g. print $fh "foo" */
2258 else if (strchr("&*<%", *s) && isIDFIRST(s[1]))
2259 expect = XTERM; /* e.g. print $fh &sub */
68dc0745 2260 else if (isIDFIRST(*s)) {
8903cb82
PP
2261 char tmpbuf[sizeof tokenbuf];
2262 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
68dc0745
PP
2263 if (keyword(tmpbuf, len))
2264 expect = XTERM; /* e.g. print $fh length() */
2265 else {
2266 GV *gv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
2267 if (gv && GvCVu(gv))
2268 expect = XTERM; /* e.g. print $fh subr() */
2269 }
2270 }
bbce6d69
PP
2271 else if (isDIGIT(*s))
2272 expect = XTERM; /* e.g. print $fh 3 */
2273 else if (*s == '.' && isDIGIT(s[1]))
2274 expect = XTERM; /* e.g. print $fh .3 */
2275 else if (strchr("/?-+", *s) && !isSPACE(s[1]))
2276 expect = XTERM; /* e.g. print $fh -1 */
2277 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]))
2278 expect = XTERM; /* print $fh <<"EOF" */
2279 }
2280 pending_ident = '$';
79072805 2281 TOKEN('$');
378cc40b
LW
2282
2283 case '@':
8990e307 2284 if (expect == XOPERATOR)
bbce6d69
PP
2285 no_op("Array", s);
2286 tokenbuf[0] = '@';
8903cb82 2287 s = scan_ident(s, bufend, tokenbuf + 1, sizeof tokenbuf - 1, FALSE);
bbce6d69
PP
2288 if (!tokenbuf[1]) {
2289 if (s == bufend)
2290 yyerror("Final @ should be \\@ or @name");
2291 PREREF('@');
2292 }
ff68c719
PP
2293 if (lex_state == LEX_NORMAL)
2294 s = skipspace(s);
bbce6d69
PP
2295 if ((expect != XREF || oldoldbufptr == last_lop) && intuit_more(s)) {
2296 if (*s == '{')
2297 tokenbuf[0] = '%';
a0d0e21e
LW
2298
2299 /* Warn about @ where they meant $. */
2300 if (dowarn) {
2301 if (*s == '[' || *s == '{') {
2302 char *t = s + 1;
2303 while (*t && (isALNUM(*t) || strchr(" \t$#+-'\"", *t)))
2304 t++;
2305 if (*t == '}' || *t == ']') {
2306 t++;
2307 bufptr = skipspace(bufptr);
2308 warn("Scalar value %.*s better written as $%.*s",
2309 t-bufptr, bufptr, t-bufptr-1, bufptr+1);
2310 }
93a17b20
LW
2311 }
2312 }
463ee0b2 2313 }
bbce6d69 2314 pending_ident = '@';
79072805 2315 TERM('@');
378cc40b
LW
2316
2317 case '/': /* may either be division or pattern */
2318 case '?': /* may either be conditional or pattern */
79072805 2319 if (expect != XOPERATOR) {
2f3197b3 2320 check_uni();
79072805
LW
2321 s = scan_pat(s);
2322 TERM(sublex_start());
378cc40b
LW
2323 }
2324 tmp = *s++;
a687059c 2325 if (tmp == '/')
79072805 2326 Mop(OP_DIVIDE);
378cc40b
LW
2327 OPERATOR(tmp);
2328
2329 case '.':
748a9306 2330 if (lex_formbrack && lex_brackets == lex_formbrack && s[1] == '\n' &&
fd049845 2331 (s == linestart || s[-1] == '\n') ) {
85e6fe83 2332 lex_formbrack = 0;
8990e307 2333 expect = XSTATE;
79072805
LW
2334 goto rightbracket;
2335 }
2336 if (expect == XOPERATOR || !isDIGIT(s[1])) {
378cc40b 2337 tmp = *s++;
a687059c
LW
2338 if (*s == tmp) {
2339 s++;
2f3197b3
LW
2340 if (*s == tmp) {
2341 s++;
79072805 2342 yylval.ival = OPf_SPECIAL;
2f3197b3
LW
2343 }
2344 else
79072805 2345 yylval.ival = 0;
378cc40b 2346 OPERATOR(DOTDOT);
a687059c 2347 }
79072805 2348 if (expect != XOPERATOR)
2f3197b3 2349 check_uni();
79072805 2350 Aop(OP_CONCAT);
378cc40b
LW
2351 }
2352 /* FALL THROUGH */
2353 case '0': case '1': case '2': case '3': case '4':
2354 case '5': case '6': case '7': case '8': case '9':
79072805 2355 s = scan_num(s);
8990e307
LW
2356 if (expect == XOPERATOR)
2357 no_op("Number",s);
79072805
LW
2358 TERM(THING);
2359
2360 case '\'':
8990e307 2361 s = scan_str(s);
463ee0b2 2362 if (expect == XOPERATOR) {
a0d0e21e
LW
2363 if (lex_formbrack && lex_brackets == lex_formbrack) {
2364 expect = XTERM;
2365 depcom();
2366 return ','; /* grandfather non-comma-format format */
2367 }
463ee0b2 2368 else
8990e307 2369 no_op("String",s);
463ee0b2 2370 }
79072805 2371 if (!s)
85e6fe83 2372 missingterm((char*)0);
79072805
LW
2373 yylval.ival = OP_CONST;
2374 TERM(sublex_start());
2375
2376 case '"':
8990e307 2377 s = scan_str(s);
463ee0b2 2378 if (expect == XOPERATOR) {
a0d0e21e
LW
2379 if (lex_formbrack && lex_brackets == lex_formbrack) {
2380 expect = XTERM;
2381 depcom();
2382 return ','; /* grandfather non-comma-format format */
2383 }
463ee0b2 2384 else
8990e307 2385 no_op("String",s);
463ee0b2 2386 }
79072805 2387 if (!s)
85e6fe83 2388 missingterm((char*)0);
4633a7c4
LW
2389 yylval.ival = OP_CONST;
2390 for (d = SvPV(lex_stuff, len); len; len--, d++) {
2391 if (*d == '$' || *d == '@' || *d == '\\') {
2392 yylval.ival = OP_STRINGIFY;
2393 break;
2394 }
2395 }
79072805
LW
2396 TERM(sublex_start());
2397
2398 case '`':
2399 s = scan_str(s);
8990e307
LW
2400 if (expect == XOPERATOR)
2401 no_op("Backticks",s);
79072805 2402 if (!s)
85e6fe83 2403 missingterm((char*)0);
79072805
LW
2404 yylval.ival = OP_BACKTICK;
2405 set_csh();
2406 TERM(sublex_start());
2407
2408 case '\\':
2409 s++;
748a9306
LW
2410 if (dowarn && lex_inwhat && isDIGIT(*s))
2411 warn("Can't use \\%c to mean $%c in expression", *s, *s);
8990e307
LW
2412 if (expect == XOPERATOR)
2413 no_op("Backslash",s);
79072805
LW
2414 OPERATOR(REFGEN);
2415
2416 case 'x':
2417 if (isDIGIT(s[1]) && expect == XOPERATOR) {
2418 s++;
2419 Mop(OP_REPEAT);
2f3197b3 2420 }
79072805
LW
2421 goto keylookup;
2422
378cc40b 2423 case '_':
79072805
LW
2424 case 'a': case 'A':
2425 case 'b': case 'B':
2426 case 'c': case 'C':
2427 case 'd': case 'D':
2428 case 'e': case 'E':
2429 case 'f': case 'F':
2430 case 'g': case 'G':
2431 case 'h': case 'H':
2432 case 'i': case 'I':
2433 case 'j': case 'J':
2434 case 'k': case 'K':
2435 case 'l': case 'L':
2436 case 'm': case 'M':
2437 case 'n': case 'N':
2438 case 'o': case 'O':
2439 case 'p': case 'P':
2440 case 'q': case 'Q':
2441 case 'r': case 'R':
2442 case 's': case 'S':
2443 case 't': case 'T':
2444 case 'u': case 'U':
2445 case 'v': case 'V':
2446 case 'w': case 'W':
2447 case 'X':
2448 case 'y': case 'Y':
2449 case 'z': case 'Z':
2450
2451 keylookup:
748a9306 2452 bufptr = s;
8903cb82 2453 s = scan_word(s, tokenbuf, sizeof tokenbuf, FALSE, &len);
8ebc5c01
PP
2454
2455 /* Some keywords can be followed by any delimiter, including ':' */
2456 tmp = (len == 1 && strchr("msyq", tokenbuf[0]) ||
2457 len == 2 && ((tokenbuf[0] == 't' && tokenbuf[1] == 'r') ||
2458 (tokenbuf[0] == 'q' &&
2459 strchr("qwx", tokenbuf[1]))));
2460
2461 /* x::* is just a word, unless x is "CORE" */
2462 if (!tmp && *s == ':' && s[1] == ':' && strNE(tokenbuf, "CORE"))
4633a7c4
LW
2463 goto just_a_word;
2464
3643fb5f
CS
2465 d = s;
2466 while (d < bufend && isSPACE(*d))
2467 d++; /* no comments skipped here, or s### is misparsed */
2468
2469 /* Is this a label? */
8ebc5c01
PP
2470 if (!tmp && expect == XSTATE
2471 && d < bufend && *d == ':' && *(d + 1) != ':') {
2472 s = d + 1;
2473 yylval.pval = savepv(tokenbuf);
2474 CLINE;
2475 TOKEN(LABEL);
3643fb5f
CS
2476 }
2477
2478 /* Check for keywords */
a0d0e21e 2479 tmp = keyword(tokenbuf, len);
748a9306
LW
2480
2481 /* Is this a word before a => operator? */
748a9306
LW
2482 if (strnEQ(d,"=>",2)) {
2483 CLINE;
2484 if (dowarn && (tmp || perl_get_cv(tokenbuf, FALSE)))
2485 warn("Ambiguous use of %s => resolved to \"%s\" =>",
2486 tokenbuf, tokenbuf);
2487 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf,0));
2488 yylval.opval->op_private = OPpCONST_BARE;
2489 TERM(WORD);
2490 }
2491
a0d0e21e
LW
2492 if (tmp < 0) { /* second-class keyword? */
2493 GV* gv;
2494 if (expect != XOPERATOR &&
a5f75d66
AD
2495 (*s != ':' || s[1] != ':') &&
2496 (gv = gv_fetchpv(tokenbuf, FALSE, SVt_PVCV)) &&
2497 GvIMPORTED_CV(gv))
a0d0e21e
LW
2498 {
2499 tmp = 0;
2500 }
2501 else
2502 tmp = -tmp;
2503 }
2504
2505 reserved_word:
2506 switch (tmp) {
79072805
LW
2507
2508 default: /* not a keyword */
93a17b20
LW
2509 just_a_word: {
2510 GV *gv;
96e4d5b1 2511 SV *sv;
748a9306 2512 char lastchar = (bufptr == oldoldbufptr ? 0 : bufptr[-1]);
8990e307
LW
2513
2514 /* Get the rest if it looks like a package qualifier */
2515
a0d0e21e 2516 if (*s == '\'' || *s == ':' && s[1] == ':') {
8903cb82
PP
2517 s = scan_word(s, tokenbuf + len, sizeof tokenbuf - len,
2518 TRUE, &len);
a0d0e21e
LW
2519 if (!len)
2520 croak("Bad name after %s::", tokenbuf);
2521 }
8990e307 2522
3643fb5f 2523 if (expect == XOPERATOR) {
fd049845 2524 if (bufptr == linestart) {
463ee0b2
LW
2525 curcop->cop_line--;
2526 warn(warn_nosemi);
2527 curcop->cop_line++;
2528 }
2529 else
54310121 2530 no_op("Bareword",s);
463ee0b2 2531 }
8990e307
LW
2532
2533 /* Look for a subroutine with this name in current package. */
2534
85e6fe83 2535 gv = gv_fetchpv(tokenbuf,FALSE, SVt_PVCV);
8990e307 2536
a0d0e21e
LW
2537 /* Presume this is going to be a bareword of some sort. */
2538
2539 CLINE;
2540 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf,0));
2541 yylval.opval->op_private = OPpCONST_BARE;
2542
8990e307
LW
2543 /* See if it's the indirect object for a list operator. */
2544
a0d0e21e
LW
2545 if (oldoldbufptr &&
2546 oldoldbufptr < bufptr &&
2547 (oldoldbufptr == last_lop || oldoldbufptr == last_uni) &&
2548 /* NO SKIPSPACE BEFORE HERE! */
2549 (expect == XREF ||
2550 (opargs[last_lop_op] >> OASHIFT & 7) == OA_FILEREF) )
2551 {
748a9306
LW
2552 bool immediate_paren = *s == '(';
2553
a0d0e21e
LW
2554 /* (Now we can afford to cross potential line boundary.) */
2555 s = skipspace(s);
2556
2557 /* Two barewords in a row may indicate method call. */
2558
2559 if ((isALPHA(*s) || *s == '$') && (tmp=intuit_method(s,gv)))
2560 return tmp;
2561
2562 /* If not a declared subroutine, it's an indirect object. */
2563 /* (But it's an indir obj regardless for sort.) */
2564
8e07c86e 2565 if ((last_lop_op == OP_SORT ||
8ebc5c01 2566 (!immediate_paren && (!gv || !GvCVu(gv))) ) &&
8e07c86e 2567 (last_lop_op != OP_MAPSTART && last_lop_op != OP_GREPSTART)){
748a9306
LW
2568 expect = (last_lop == oldoldbufptr) ? XTERM : XOPERATOR;
2569 goto bareword;
93a17b20
LW
2570 }
2571 }
8990e307
LW
2572
2573 /* If followed by a paren, it's certainly a subroutine. */
2574
2575 expect = XOPERATOR;
2576 s = skipspace(s);
93a17b20 2577 if (*s == '(') {
79072805 2578 CLINE;
96e4d5b1
PP
2579 if (gv && GvCVu(gv)) {
2580 for (d = s + 1; *d == ' ' || *d == '\t'; d++) ;
2581 if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) {
2582 s = d + 1;
2583 goto its_constant;
2584 }
2585 }
a0d0e21e 2586 nextval[nexttoke].opval = yylval.opval;
463ee0b2 2587 expect = XOPERATOR;
93a17b20 2588 force_next(WORD);
c07a80fd 2589 yylval.ival = 0;
463ee0b2 2590 TOKEN('&');
79072805 2591 }
93a17b20 2592
a0d0e21e 2593 /* If followed by var or block, call it a method (unless sub) */
8990e307 2594
8ebc5c01 2595 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
463ee0b2 2596 last_lop = oldbufptr;
8990e307 2597 last_lop_op = OP_METHOD;
93a17b20 2598 PREBLOCK(METHOD);
463ee0b2
LW
2599 }
2600
8990e307
LW
2601 /* If followed by a bareword, see if it looks like indir obj. */
2602
a0d0e21e
LW
2603 if ((isALPHA(*s) || *s == '$') && (tmp = intuit_method(s,gv)))
2604 return tmp;
93a17b20 2605
8990e307
LW
2606 /* Not a method, so call it a subroutine (if defined) */
2607
8ebc5c01 2608 if (gv && GvCVu(gv)) {
46fc3d4c 2609 CV* cv;
748a9306 2610 if (lastchar == '-')
c2960299 2611 warn("Ambiguous use of -%s resolved as -&%s()",
748a9306 2612 tokenbuf, tokenbuf);
8990e307 2613 last_lop = oldbufptr;
a0d0e21e 2614 last_lop_op = OP_ENTERSUB;
89bfa8cd 2615 /* Check for a constant sub */
46fc3d4c 2616 cv = GvCV(gv);
96e4d5b1
PP
2617 if ((sv = cv_const_sv(cv))) {
2618 its_constant:
2619 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
2620 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
2621 yylval.opval->op_private = 0;
2622 TOKEN(WORD);
89bfa8cd
PP
2623 }
2624
a5f75d66
AD
2625 /* Resolve to GV now. */
2626 op_free(yylval.opval);
2627 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
4633a7c4
LW
2628 /* Is there a prototype? */
2629 if (SvPOK(cv)) {
2630 STRLEN len;
2631 char *proto = SvPV((SV*)cv, len);
2632 if (!len)
2633 TERM(FUNC0SUB);
2634 if (strEQ(proto, "$"))
2635 OPERATOR(UNIOPSUB);
2636 if (*proto == '&' && *s == '{') {
2637 sv_setpv(subname,"__ANON__");
2638 PREBLOCK(LSTOPSUB);
2639 }
2640 }
a5f75d66 2641 nextval[nexttoke].opval = yylval.opval;
8990e307
LW
2642 expect = XTERM;
2643 force_next(WORD);
2644 TOKEN(NOAMP);
2645 }
748a9306
LW
2646
2647 if (hints & HINT_STRICT_SUBS &&
2648 lastchar != '-' &&
a0d0e21e 2649 strnNE(s,"->",2) &&
9b01e405 2650 last_lop_op != OP_TRUNCATE && /* S/F prototype in opcode.pl */
a0d0e21e
LW
2651 last_lop_op != OP_ACCEPT &&
2652 last_lop_op != OP_PIPE_OP &&
2653 last_lop_op != OP_SOCKPAIR)
2654 {
2655 warn(
2656 "Bareword \"%s\" not allowed while \"strict subs\" in use",
85e6fe83
LW
2657 tokenbuf);
2658 ++error_count;
2659 }
8990e307
LW
2660
2661 /* Call it a bare word */
2662
748a9306
LW
2663 bareword:
2664 if (dowarn) {
2665 if (lastchar != '-') {
2666 for (d = tokenbuf; *d && isLOWER(*d); d++) ;
2667 if (!*d)
2668 warn(warn_reserved, tokenbuf);
2669 }
2670 }
2671 if (lastchar && strchr("*%&", lastchar)) {
2672 warn("Operator or semicolon missing before %c%s",
2673 lastchar, tokenbuf);
c2960299 2674 warn("Ambiguous use of %c resolved as operator %c",
748a9306
LW
2675 lastchar, lastchar);
2676 }
93a17b20 2677 TOKEN(WORD);
79072805 2678 }
79072805 2679
68dc0745 2680 case KEY___FILE__:
46fc3d4c
PP
2681 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
2682 newSVsv(GvSV(curcop->cop_filegv)));
2683 TERM(THING);
2684
79072805 2685 case KEY___LINE__:
46fc3d4c
PP
2686 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
2687 newSVpvf("%ld", (long)curcop->cop_line));
79072805 2688 TERM(THING);
68dc0745
PP
2689
2690 case KEY___PACKAGE__:
2691 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
2692 (curstash
2693 ? newSVsv(curstname)
2694 : &sv_undef));
2695 TERM(THING);
79072805 2696
e50aee73 2697 case KEY___DATA__:
79072805
LW
2698 case KEY___END__: {
2699 GV *gv;
79072805
LW
2700
2701 /*SUPPRESS 560*/
a5f75d66 2702 if (rsfp && (!in_eval || tokenbuf[2] == 'D')) {
e50aee73
AD
2703 char *pname = "main";
2704 if (tokenbuf[2] == 'D')
2705 pname = HvNAME(curstash ? curstash : defstash);
46fc3d4c 2706 gv = gv_fetchpv(form("%s::DATA", pname), TRUE, SVt_PVIO);
a5f75d66 2707 GvMULTI_on(gv);
79072805 2708 if (!GvIO(gv))
a0d0e21e
LW
2709 GvIOp(gv) = newIO();
2710 IoIFP(GvIOp(gv)) = rsfp;
2711#if defined(HAS_FCNTL) && defined(F_SETFD)
2712 {
760ac839 2713 int fd = PerlIO_fileno(rsfp);
a0d0e21e
LW
2714 fcntl(fd,F_SETFD,fd >= 3);
2715 }
79072805 2716#endif
fd049845
PP
2717 /* Mark this internal pseudo-handle as clean */
2718 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
79072805 2719 if (preprocess)
a0d0e21e 2720 IoTYPE(GvIOp(gv)) = '|';
760ac839 2721 else if ((PerlIO*)rsfp == PerlIO_stdin())
a0d0e21e 2722 IoTYPE(GvIOp(gv)) = '-';
79072805 2723 else
a0d0e21e 2724 IoTYPE(GvIOp(gv)) = '<';
79072805
LW
2725 rsfp = Nullfp;
2726 }
2727 goto fake_eof;
e929a76b 2728 }
de3bb511 2729
8990e307 2730 case KEY_AUTOLOAD:
ed6116ce 2731 case KEY_DESTROY:
79072805
LW
2732 case KEY_BEGIN:
2733 case KEY_END:
a0d0e21e 2734 if (expect == XSTATE) {
93a17b20
LW
2735 s = bufptr;
2736 goto really_sub;
79072805
LW
2737 }
2738 goto just_a_word;
2739
a0d0e21e
LW
2740 case KEY_CORE:
2741 if (*s == ':' && s[1] == ':') {
2742 s += 2;
748a9306 2743 d = s;
8903cb82 2744 s = scan_word(s, tokenbuf, sizeof tokenbuf, FALSE, &len);
a0d0e21e
LW
2745 tmp = keyword(tokenbuf, len);
2746 if (tmp < 0)
2747 tmp = -tmp;
2748 goto reserved_word;
2749 }
2750 goto just_a_word;
2751
463ee0b2
LW
2752 case KEY_abs:
2753 UNI(OP_ABS);
2754
79072805
LW
2755 case KEY_alarm:
2756 UNI(OP_ALARM);
2757
2758 case KEY_accept:
a0d0e21e 2759 LOP(OP_ACCEPT,XTERM);
79072805 2760
463ee0b2
LW
2761 case KEY_and:
2762 OPERATOR(ANDOP);
2763
79072805 2764 case KEY_atan2:
a0d0e21e 2765 LOP(OP_ATAN2,XTERM);
85e6fe83 2766
79072805 2767 case KEY_bind:
a0d0e21e 2768 LOP(OP_BIND,XTERM);
79072805
LW
2769
2770 case KEY_binmode:
2771 UNI(OP_BINMODE);
2772
2773 case KEY_bless:
a0d0e21e 2774 LOP(OP_BLESS,XTERM);
79072805
LW
2775
2776 case KEY_chop:
2777 UNI(OP_CHOP);
2778
2779 case KEY_continue:
2780 PREBLOCK(CONTINUE);
2781
2782 case KEY_chdir:
85e6fe83 2783 (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */
79072805
LW
2784 UNI(OP_CHDIR);
2785
2786 case KEY_close:
2787 UNI(OP_CLOSE);
2788
2789 case KEY_closedir:
2790 UNI(OP_CLOSEDIR);
2791
2792 case KEY_cmp:
2793 Eop(OP_SCMP);
2794
2795 case KEY_caller:
2796 UNI(OP_CALLER);
2797
2798 case KEY_crypt:
2799#ifdef FCRYPT
de3bb511
LW
2800 if (!cryptseen++)
2801 init_des();
a687059c 2802#endif
a0d0e21e 2803 LOP(OP_CRYPT,XTERM);
79072805
LW
2804
2805 case KEY_chmod:
748a9306
LW
2806 if (dowarn) {
2807 for (d = s; d < bufend && (isSPACE(*d) || *d == '('); d++) ;
2808 if (*d != '0' && isDIGIT(*d))
2809 yywarn("chmod: mode argument is missing initial 0");
2810 }
a0d0e21e 2811 LOP(OP_CHMOD,XTERM);
79072805
LW
2812
2813 case KEY_chown:
a0d0e21e 2814 LOP(OP_CHOWN,XTERM);
79072805
LW
2815
2816 case KEY_connect:
a0d0e21e 2817 LOP(OP_CONNECT,XTERM);
79072805 2818
463ee0b2
LW
2819 case KEY_chr:
2820 UNI(OP_CHR);
2821
79072805
LW
2822 case KEY_cos:
2823 UNI(OP_COS);
2824
2825 case KEY_chroot:
2826 UNI(OP_CHROOT);
2827
2828 case KEY_do:
2829 s = skipspace(s);
2830 if (*s == '{')
a0d0e21e 2831 PRETERMBLOCK(DO);
79072805 2832 if (*s != '\'')
a0d0e21e 2833 s = force_word(s,WORD,FALSE,TRUE,FALSE);
378cc40b 2834 OPERATOR(DO);
79072805
LW
2835
2836 case KEY_die:
a0d0e21e
LW
2837 hints |= HINT_BLOCK_SCOPE;
2838 LOP(OP_DIE,XTERM);
79072805
LW
2839
2840 case KEY_defined:
2841 UNI(OP_DEFINED);
2842
2843 case KEY_delete:
a0d0e21e 2844 UNI(OP_DELETE);
79072805
LW
2845
2846 case KEY_dbmopen:
a0d0e21e
LW
2847 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
2848 LOP(OP_DBMOPEN,XTERM);
79072805
LW
2849
2850 case KEY_dbmclose:
2851 UNI(OP_DBMCLOSE);
2852
2853 case KEY_dump:
a0d0e21e 2854 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
2855 LOOPX(OP_DUMP);
2856
2857 case KEY_else:
2858 PREBLOCK(ELSE);
2859
2860 case KEY_elsif:
2861 yylval.ival = curcop->cop_line;
2862 OPERATOR(ELSIF);
2863
2864 case KEY_eq:
2865 Eop(OP_SEQ);
2866
a0d0e21e
LW
2867 case KEY_exists:
2868 UNI(OP_EXISTS);
2869
79072805
LW
2870 case KEY_exit:
2871 UNI(OP_EXIT);
2872
2873 case KEY_eval:
79072805 2874 s = skipspace(s);
a0d0e21e 2875 expect = (*s == '{') ? XTERMBLOCK : XTERM;
463ee0b2 2876 UNIBRACK(OP_ENTEREVAL);
79072805
LW
2877
2878 case KEY_eof:
2879 UNI(OP_EOF);
2880
2881 case KEY_exp:
2882 UNI(OP_EXP);
2883
2884 case KEY_each:
2885 UNI(OP_EACH);
2886
2887 case KEY_exec:
2888 set_csh();
a0d0e21e 2889 LOP(OP_EXEC,XREF);
79072805
LW
2890
2891 case KEY_endhostent:
2892 FUN0(OP_EHOSTENT);
2893
2894 case KEY_endnetent:
2895 FUN0(OP_ENETENT);
2896
2897 case KEY_endservent:
2898 FUN0(OP_ESERVENT);
2899
2900 case KEY_endprotoent:
2901 FUN0(OP_EPROTOENT);
2902
2903 case KEY_endpwent:
2904 FUN0(OP_EPWENT);
2905
2906 case KEY_endgrent:
2907 FUN0(OP_EGRENT);
2908
2909 case KEY_for:
2910 case KEY_foreach:
2911 yylval.ival = curcop->cop_line;
55497cff
PP
2912 s = skipspace(s);
2913 if (isIDFIRST(*s)) {
2914 char *p = s;
2915 if ((bufend - p) >= 3 &&
2916 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
2917 p += 2;
2918 p = skipspace(p);
2919 if (isIDFIRST(*p))
2920 croak("Missing $ on loop variable");
2921 }
79072805
LW
2922 OPERATOR(FOR);
2923
2924 case KEY_formline:
a0d0e21e 2925 LOP(OP_FORMLINE,XTERM);
79072805
LW
2926
2927 case KEY_fork:
2928 FUN0(OP_FORK);
2929
2930 case KEY_fcntl:
a0d0e21e 2931 LOP(OP_FCNTL,XTERM);
79072805
LW
2932
2933 case KEY_fileno:
2934 UNI(OP_FILENO);
2935
2936 case KEY_flock:
a0d0e21e 2937 LOP(OP_FLOCK,XTERM);
79072805
LW
2938
2939 case KEY_gt:
2940 Rop(OP_SGT);
2941
2942 case KEY_ge:
2943 Rop(OP_SGE);
2944
2945 case KEY_grep:
a0d0e21e 2946 LOP(OP_GREPSTART, *s == '(' ? XTERM : XREF);
79072805
LW
2947
2948 case KEY_goto:
a0d0e21e 2949 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
2950 LOOPX(OP_GOTO);
2951
2952 case KEY_gmtime:
2953 UNI(OP_GMTIME);
2954
2955 case KEY_getc:
2956 UNI(OP_GETC);
2957
2958 case KEY_getppid:
2959 FUN0(OP_GETPPID);
2960
2961 case KEY_getpgrp:
2962 UNI(OP_GETPGRP);
2963
2964 case KEY_getpriority:
a0d0e21e 2965 LOP(OP_GETPRIORITY,XTERM);
79072805
LW
2966
2967 case KEY_getprotobyname:
2968 UNI(OP_GPBYNAME);
2969
2970 case KEY_getprotobynumber:
a0d0e21e 2971 LOP(OP_GPBYNUMBER,XTERM);
79072805
LW
2972
2973 case KEY_getprotoent:
2974 FUN0(OP_GPROTOENT);
2975
2976 case KEY_getpwent:
2977 FUN0(OP_GPWENT);
2978
2979 case KEY_getpwnam:
ff68c719 2980 UNI(OP_GPWNAM);
79072805
LW
2981
2982 case KEY_getpwuid:
ff68c719 2983 UNI(OP_GPWUID);
79072805
LW
2984
2985 case KEY_getpeername:
2986 UNI(OP_GETPEERNAME);
2987
2988 case KEY_gethostbyname:
2989 UNI(OP_GHBYNAME);
2990
2991 case KEY_gethostbyaddr:
a0d0e21e 2992 LOP(OP_GHBYADDR,XTERM);
79072805
LW
2993
2994 case KEY_gethostent:
2995 FUN0(OP_GHOSTENT);
2996
2997 case KEY_getnetbyname:
2998 UNI(OP_GNBYNAME);
2999
3000 case KEY_getnetbyaddr:
a0d0e21e 3001 LOP(OP_GNBYADDR,XTERM);
79072805
LW
3002
3003 case KEY_getnetent:
3004 FUN0(OP_GNETENT);
3005
3006 case KEY_getservbyname:
a0d0e21e 3007 LOP(OP_GSBYNAME,XTERM);
79072805
LW
3008
3009 case KEY_getservbyport:
a0d0e21e 3010 LOP(OP_GSBYPORT,XTERM);
79072805
LW
3011
3012 case KEY_getservent:
3013 FUN0(OP_GSERVENT);
3014
3015 case KEY_getsockname:
3016 UNI(OP_GETSOCKNAME);
3017
3018 case KEY_getsockopt:
a0d0e21e 3019 LOP(OP_GSOCKOPT,XTERM);
79072805
LW
3020
3021 case KEY_getgrent:
3022 FUN0(OP_GGRENT);
3023
3024 case KEY_getgrnam:
ff68c719 3025 UNI(OP_GGRNAM);
79072805
LW
3026
3027 case KEY_getgrgid:
ff68c719 3028 UNI(OP_GGRGID);
79072805
LW
3029
3030 case KEY_getlogin:
3031 FUN0(OP_GETLOGIN);
3032
93a17b20 3033 case KEY_glob:
a0d0e21e
LW
3034 set_csh();
3035 LOP(OP_GLOB,XTERM);
93a17b20 3036
79072805
LW
3037 case KEY_hex:
3038 UNI(OP_HEX);
3039
3040 case KEY_if:
3041 yylval.ival = curcop->cop_line;
71be2cbc 3042 OPERATOR(IF);
79072805
LW
3043
3044 case KEY_index:
a0d0e21e 3045 LOP(OP_INDEX,XTERM);
79072805
LW
3046
3047 case KEY_int:
3048 UNI(OP_INT);
3049
3050 case KEY_ioctl:
a0d0e21e 3051 LOP(OP_IOCTL,XTERM);
79072805
LW
3052
3053 case KEY_join:
a0d0e21e 3054 LOP(OP_JOIN,XTERM);
79072805
LW
3055
3056 case KEY_keys:
3057 UNI(OP_KEYS);
3058
3059 case KEY_kill:
a0d0e21e 3060 LOP(OP_KILL,XTERM);
79072805
LW
3061
3062 case KEY_last:
a0d0e21e 3063 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805 3064 LOOPX(OP_LAST);
a0d0e21e 3065
79072805
LW
3066 case KEY_lc:
3067 UNI(OP_LC);
3068
3069 case KEY_lcfirst:
3070 UNI(OP_LCFIRST);
3071
3072 case KEY_local:
3073 OPERATOR(LOCAL);
3074
3075 case KEY_length:
3076 UNI(OP_LENGTH);
3077
3078 case KEY_lt:
3079 Rop(OP_SLT);
3080
3081 case KEY_le:
3082 Rop(OP_SLE);
3083
3084 case KEY_localtime:
3085 UNI(OP_LOCALTIME);
3086
3087 case KEY_log:
3088 UNI(OP_LOG);
3089
3090 case KEY_link:
a0d0e21e 3091 LOP(OP_LINK,XTERM);
79072805
LW
3092
3093 case KEY_listen:
a0d0e21e 3094 LOP(OP_LISTEN,XTERM);
79072805
LW
3095
3096 case KEY_lstat:
3097 UNI(OP_LSTAT);
3098
3099 case KEY_m:
3100 s = scan_pat(s);
3101 TERM(sublex_start());
3102
a0d0e21e
LW
3103 case KEY_map:
3104 LOP(OP_MAPSTART,XREF);
3105
79072805 3106 case KEY_mkdir:
a0d0e21e 3107 LOP(OP_MKDIR,XTERM);
79072805
LW
3108
3109 case KEY_msgctl:
a0d0e21e 3110 LOP(OP_MSGCTL,XTERM);
79072805
LW
3111
3112 case KEY_msgget:
a0d0e21e 3113 LOP(OP_MSGGET,XTERM);
79072805
LW
3114
3115 case KEY_msgrcv:
a0d0e21e 3116 LOP(OP_MSGRCV,XTERM);
79072805
LW
3117
3118 case KEY_msgsnd:
a0d0e21e 3119 LOP(OP_MSGSND,XTERM);
79072805 3120
93a17b20
LW
3121 case KEY_my:
3122 in_my = TRUE;
55497cff 3123 OPERATOR(MY);
93a17b20 3124
79072805 3125 case KEY_next:
a0d0e21e 3126 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
3127 LOOPX(OP_NEXT);
3128
3129 case KEY_ne:
3130 Eop(OP_SNE);
3131
a0d0e21e
LW
3132 case KEY_no:
3133 if (expect != XSTATE)
3134 yyerror("\"no\" not allowed in expression");
3135 s = force_word(s,WORD,FALSE,TRUE,FALSE);
89bfa8cd 3136 s = force_version(s);
a0d0e21e
LW
3137 yylval.ival = 0;
3138 OPERATOR(USE);
3139
3140 case KEY_not:
3141 OPERATOR(NOTOP);
3142
79072805 3143 case KEY_open:
93a17b20
LW
3144 s = skipspace(s);
3145 if (isIDFIRST(*s)) {
3146 char *t;
3147 for (d = s; isALNUM(*d); d++) ;
3148 t = skipspace(d);
3149 if (strchr("|&*+-=!?:.", *t))
3150 warn("Precedence problem: open %.*s should be open(%.*s)",
3151 d-s,s, d-s,s);
3152 }
a0d0e21e 3153 LOP(OP_OPEN,XTERM);
79072805 3154
463ee0b2 3155 case KEY_or:
a0d0e21e 3156 yylval.ival = OP_OR;
463ee0b2
LW
3157 OPERATOR(OROP);
3158
79072805
LW
3159 case KEY_ord:
3160 UNI(OP_ORD);
3161
3162 case KEY_oct:
3163 UNI(OP_OCT);
3164
3165 case KEY_opendir:
a0d0e21e 3166 LOP(OP_OPEN_DIR,XTERM);
79072805
LW
3167
3168 case KEY_print:
3169 checkcomma(s,tokenbuf,"filehandle");
a0d0e21e 3170 LOP(OP_PRINT,XREF);
79072805
LW
3171
3172 case KEY_printf:
3173 checkcomma(s,tokenbuf,"filehandle");
a0d0e21e 3174 LOP(OP_PRTF,XREF);
79072805 3175
c07a80fd
PP
3176 case KEY_prototype:
3177 UNI(OP_PROTOTYPE);
3178
79072805 3179 case KEY_push:
a0d0e21e 3180 LOP(OP_PUSH,XTERM);
79072805
LW
3181
3182 case KEY_pop:
3183 UNI(OP_POP);
3184
a0d0e21e
LW
3185 case KEY_pos:
3186 UNI(OP_POS);
3187
79072805 3188 case KEY_pack:
a0d0e21e 3189 LOP(OP_PACK,XTERM);
79072805
LW
3190
3191 case KEY_package:
a0d0e21e 3192 s = force_word(s,WORD,FALSE,TRUE,FALSE);
79072805
LW
3193 OPERATOR(PACKAGE);
3194
3195 case KEY_pipe:
a0d0e21e 3196 LOP(OP_PIPE_OP,XTERM);
79072805
LW
3197
3198 case KEY_q:
3199 s = scan_str(s);
3200 if (!s)
85e6fe83 3201 missingterm((char*)0);
79072805
LW
3202 yylval.ival = OP_CONST;
3203 TERM(sublex_start());
3204
a0d0e21e
LW
3205 case KEY_quotemeta:
3206 UNI(OP_QUOTEMETA);
3207
8990e307
LW
3208 case KEY_qw:
3209 s = scan_str(s);
3210 if (!s)
85e6fe83 3211 missingterm((char*)0);
55497cff
PP
3212 if (dowarn && SvLEN(lex_stuff)) {
3213 d = SvPV_force(lex_stuff, len);
3214 for (; len; --len, ++d) {
3215 if (*d == ',') {
3216 warn("Possible attempt to separate words with commas");
3217 break;
3218 }
3219 if (*d == '#') {
3220 warn("Possible attempt to put comments in qw() list");
3221 break;
3222 }
3223 }
3224 }
8990e307
LW
3225 force_next(')');
3226 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, q(lex_stuff));
3227 lex_stuff = Nullsv;
3228 force_next(THING);
3229 force_next(',');
3230 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(" ",1));
3231 force_next(THING);
3232 force_next('(');
a0d0e21e
LW
3233 yylval.ival = OP_SPLIT;
3234 CLINE;
3235 expect = XTERM;
3236 bufptr = s;
3237 last_lop = oldbufptr;
3238 last_lop_op = OP_SPLIT;
3239 return FUNC;
8990e307 3240
79072805
LW
3241 case KEY_qq:
3242 s = scan_str(s);
3243 if (!s)
85e6fe83 3244 missingterm((char*)0);
a0d0e21e 3245 yylval.ival = OP_STRINGIFY;
ed6116ce
LW
3246 if (SvIVX(lex_stuff) == '\'')
3247 SvIVX(lex_stuff) = 0; /* qq'$foo' should intepolate */
79072805
LW
3248 TERM(sublex_start());
3249
3250 case KEY_qx:
3251 s = scan_str(s);
3252 if (!s)
85e6fe83 3253 missingterm((char*)0);
79072805
LW
3254 yylval.ival = OP_BACKTICK;
3255 set_csh();
3256 TERM(sublex_start());
3257
3258 case KEY_return:
3259 OLDLOP(OP_RETURN);
3260
3261 case KEY_require:
748a9306 3262 *tokenbuf = '\0';
a0d0e21e 3263 s = force_word(s,WORD,TRUE,TRUE,FALSE);
748a9306 3264 if (isIDFIRST(*tokenbuf))
89bfa8cd 3265 gv_stashpvn(tokenbuf, strlen(tokenbuf), TRUE);
748a9306 3266 else if (*s == '<')
a0d0e21e 3267 yyerror("<> should be quotes");
463ee0b2 3268 UNI(OP_REQUIRE);
79072805
LW
3269
3270 case KEY_reset:
3271 UNI(OP_RESET);
3272
3273 case KEY_redo:
a0d0e21e 3274 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
3275 LOOPX(OP_REDO);
3276
3277 case KEY_rename:
a0d0e21e 3278 LOP(OP_RENAME,XTERM);
79072805
LW
3279
3280 case KEY_rand:
3281 UNI(OP_RAND);
3282
3283 case KEY_rmdir:
3284 UNI(OP_RMDIR);
3285
3286 case KEY_rindex:
a0d0e21e 3287 LOP(OP_RINDEX,XTERM);
79072805
LW
3288
3289 case KEY_read:
a0d0e21e 3290 LOP(OP_READ,XTERM);
79072805
LW
3291
3292 case KEY_readdir:
3293 UNI(OP_READDIR);
3294
93a17b20
LW
3295 case KEY_readline:
3296 set_csh();
3297 UNI(OP_READLINE);
3298
3299 case KEY_readpipe:
3300 set_csh();
3301 UNI(OP_BACKTICK);
3302
79072805
LW
3303 case KEY_rewinddir:
3304 UNI(OP_REWINDDIR);
3305
3306 case KEY_recv:
a0d0e21e 3307 LOP(OP_RECV,XTERM);
79072805
LW
3308
3309 case KEY_reverse:
a0d0e21e 3310 LOP(OP_REVERSE,XTERM);
79072805
LW
3311
3312 case KEY_readlink:
3313 UNI(OP_READLINK);
3314
3315 case KEY_ref:
3316 UNI(OP_REF);
3317
3318 case KEY_s:
3319 s = scan_subst(s);
3320 if (yylval.opval)
3321 TERM(sublex_start());
3322 else
3323 TOKEN(1); /* force error */
3324
a0d0e21e
LW
3325 case KEY_chomp:
3326 UNI(OP_CHOMP);
3327
79072805
LW
3328 case KEY_scalar:
3329 UNI(OP_SCALAR);
3330
3331 case KEY_select:
a0d0e21e 3332 LOP(OP_SELECT,XTERM);
79072805
LW
3333
3334 case KEY_seek:
a0d0e21e 3335 LOP(OP_SEEK,XTERM);
79072805
LW
3336
3337 case KEY_semctl:
a0d0e21e 3338 LOP(OP_SEMCTL,XTERM);
79072805
LW
3339
3340 case KEY_semget:
a0d0e21e 3341 LOP(OP_SEMGET,XTERM);
79072805
LW
3342
3343 case KEY_semop:
a0d0e21e 3344 LOP(OP_SEMOP,XTERM);
79072805
LW
3345
3346 case KEY_send:
a0d0e21e 3347 LOP(OP_SEND,XTERM);
79072805
LW
3348
3349 case KEY_setpgrp:
a0d0e21e 3350 LOP(OP_SETPGRP,XTERM);
79072805
LW
3351
3352 case KEY_setpriority:
a0d0e21e 3353 LOP(OP_SETPRIORITY,XTERM);
79072805
LW
3354
3355 case KEY_sethostent:
ff68c719 3356 UNI(OP_SHOSTENT);
79072805
LW
3357
3358 case KEY_setnetent:
ff68c719 3359 UNI(OP_SNETENT);
79072805
LW
3360
3361 case KEY_setservent:
ff68c719 3362 UNI(OP_SSERVENT);
79072805
LW
3363
3364 case KEY_setprotoent:
ff68c719 3365 UNI(OP_SPROTOENT);
79072805
LW
3366
3367 case KEY_setpwent:
3368 FUN0(OP_SPWENT);
3369
3370 case KEY_setgrent:
3371 FUN0(OP_SGRENT);
3372
3373 case KEY_seekdir:
a0d0e21e 3374 LOP(OP_SEEKDIR,XTERM);
79072805
LW
3375
3376 case KEY_setsockopt:
a0d0e21e 3377 LOP(OP_SSOCKOPT,XTERM);
79072805
LW
3378
3379 case KEY_shift:
3380 UNI(OP_SHIFT);
3381
3382 case KEY_shmctl:
a0d0e21e 3383 LOP(OP_SHMCTL,XTERM);
79072805
LW
3384
3385 case KEY_shmget:
a0d0e21e 3386 LOP(OP_SHMGET,XTERM);
79072805
LW
3387
3388 case KEY_shmread:
a0d0e21e 3389 LOP(OP_SHMREAD,XTERM);
79072805
LW
3390
3391 case KEY_shmwrite:
a0d0e21e 3392 LOP(OP_SHMWRITE,XTERM);
79072805
LW
3393
3394 case KEY_shutdown:
a0d0e21e 3395 LOP(OP_SHUTDOWN,XTERM);
79072805
LW
3396
3397 case KEY_sin:
3398 UNI(OP_SIN);
3399
3400 case KEY_sleep:
3401 UNI(OP_SLEEP);
3402
3403 case KEY_socket:
a0d0e21e 3404 LOP(OP_SOCKET,XTERM);
79072805
LW
3405
3406 case KEY_socketpair:
a0d0e21e 3407 LOP(OP_SOCKPAIR,XTERM);
79072805
LW
3408
3409 case KEY_sort:
3410 checkcomma(s,tokenbuf,"subroutine name");
3411 s = skipspace(s);
3412 if (*s == ';' || *s == ')') /* probably a close */
463ee0b2
LW
3413 croak("sort is now a reserved word");
3414 expect = XTERM;
a0d0e21e
LW
3415 s = force_word(s,WORD,TRUE,TRUE,TRUE);
3416 LOP(OP_SORT,XREF);
79072805
LW
3417
3418 case KEY_split:
a0d0e21e 3419 LOP(OP_SPLIT,XTERM);
79072805
LW
3420
3421 case KEY_sprintf:
a0d0e21e 3422 LOP(OP_SPRINTF,XTERM);
79072805
LW
3423
3424 case KEY_splice:
a0d0e21e 3425 LOP(OP_SPLICE,XTERM);
79072805
LW
3426
3427 case KEY_sqrt:
3428 UNI(OP_SQRT);
3429
3430 case KEY_srand:
3431 UNI(OP_SRAND);
3432
3433 case KEY_stat:
3434 UNI(OP_STAT);
3435
3436 case KEY_study:
3437 sawstudy++;
3438 UNI(OP_STUDY);
3439
3440 case KEY_substr:
a0d0e21e 3441 LOP(OP_SUBSTR,XTERM);
79072805
LW
3442
3443 case KEY_format:
3444 case KEY_sub:
93a17b20 3445 really_sub:
79072805 3446 s = skipspace(s);
4633a7c4 3447
463ee0b2 3448 if (isIDFIRST(*s) || *s == '\'' || *s == ':') {
8903cb82 3449 char tmpbuf[sizeof tokenbuf];
4633a7c4 3450 expect = XBLOCK;
8903cb82 3451 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
463ee0b2
LW
3452 if (strchr(tmpbuf, ':'))
3453 sv_setpv(subname, tmpbuf);
3454 else {
3455 sv_setsv(subname,curstname);
8990e307 3456 sv_catpvn(subname,"::",2);
463ee0b2
LW
3457 sv_catpvn(subname,tmpbuf,len);
3458 }
a0d0e21e 3459 s = force_word(s,WORD,FALSE,TRUE,TRUE);
4633a7c4 3460 s = skipspace(s);
79072805 3461 }
4633a7c4
LW
3462 else {
3463 expect = XTERMBLOCK;
79072805 3464 sv_setpv(subname,"?");
4633a7c4
LW
3465 }
3466
3467 if (tmp == KEY_format) {
3468 s = skipspace(s);
3469 if (*s == '=')
3470 lex_formbrack = lex_brackets + 1;
3471 OPERATOR(FORMAT);
3472 }
79072805 3473
4633a7c4
LW
3474 /* Look for a prototype */
3475 if (*s == '(') {
68dc0745
PP
3476 char *p;
3477
4633a7c4
LW
3478 s = scan_str(s);
3479 if (!s) {
3480 if (lex_stuff)
3481 SvREFCNT_dec(lex_stuff);
3482 lex_stuff = Nullsv;
3483 croak("Prototype not terminated");
3484 }
68dc0745
PP
3485 /* strip spaces */
3486 d = SvPVX(lex_stuff);
3487 tmp = 0;
3488 for (p = d; *p; ++p) {
3489 if (!isSPACE(*p))
3490 d[tmp++] = *p;
3491 }
3492 d[tmp] = '\0';
3493 SvCUR(lex_stuff) = tmp;
3494
4633a7c4
LW
3495 nexttoke++;
3496 nextval[1] = nextval[0];
3497 nexttype[1] = nexttype[0];
3498 nextval[0].opval = (OP*)newSVOP(OP_CONST, 0, lex_stuff);
3499 nexttype[0] = THING;
3500 if (nexttoke == 1) {
3501 lex_defer = lex_state;
3502 lex_expect = expect;
3503 lex_state = LEX_KNOWNEXT;
3504 }
3505 lex_stuff = Nullsv;
3506 }
79072805 3507
4633a7c4
LW
3508 if (*SvPV(subname,na) == '?') {
3509 sv_setpv(subname,"__ANON__");
3510 TOKEN(ANONSUB);
3511 }
3512 PREBLOCK(SUB);
79072805
LW
3513
3514 case KEY_system:
3515 set_csh();
a0d0e21e 3516 LOP(OP_SYSTEM,XREF);
79072805
LW
3517
3518 case KEY_symlink:
a0d0e21e 3519 LOP(OP_SYMLINK,XTERM);
79072805
LW
3520
3521 case KEY_syscall:
a0d0e21e 3522 LOP(OP_SYSCALL,XTERM);
79072805 3523
c07a80fd
PP
3524 case KEY_sysopen:
3525 LOP(OP_SYSOPEN,XTERM);
3526
137443ea
PP
3527 case KEY_sysseek:
3528 LOP(OP_SYSSEEK,XTERM);
3529
96e4d5b1
PP
3530 case KEY_sysread:
3531 LOP(OP_SYSREAD,XTERM);
3532
79072805 3533 case KEY_syswrite:
a0d0e21e 3534 LOP(OP_SYSWRITE,XTERM);
79072805
LW
3535
3536 case KEY_tr:
3537 s = scan_trans(s);
3538 TERM(sublex_start());
3539
3540 case KEY_tell:
3541 UNI(OP_TELL);
3542
3543 case KEY_telldir:
3544 UNI(OP_TELLDIR);
3545
463ee0b2 3546 case KEY_tie:
a0d0e21e 3547 LOP(OP_TIE,XTERM);
463ee0b2 3548
c07a80fd
PP
3549 case KEY_tied:
3550 UNI(OP_TIED);
3551
79072805
LW
3552 case KEY_time:
3553 FUN0(OP_TIME);
3554
3555 case KEY_times:
3556 FUN0(OP_TMS);
3557
3558 case KEY_truncate:
a0d0e21e 3559 LOP(OP_TRUNCATE,XTERM);
79072805
LW
3560
3561 case KEY_uc:
3562 UNI(OP_UC);
3563
3564 case KEY_ucfirst:
3565 UNI(OP_UCFIRST);
3566
463ee0b2
LW
3567 case KEY_untie:
3568 UNI(OP_UNTIE);
3569
79072805
LW
3570 case KEY_until:
3571 yylval.ival = curcop->cop_line;
71be2cbc 3572 OPERATOR(UNTIL);
79072805
LW
3573
3574 case KEY_unless:
3575 yylval.ival = curcop->cop_line;
71be2cbc 3576 OPERATOR(UNLESS);
79072805
LW
3577
3578 case KEY_unlink:
a0d0e21e 3579 LOP(OP_UNLINK,XTERM);
79072805
LW
3580
3581 case KEY_undef:
3582 UNI(OP_UNDEF);
3583
3584 case KEY_unpack:
a0d0e21e 3585 LOP(OP_UNPACK,XTERM);
79072805
LW
3586
3587 case KEY_utime:
a0d0e21e 3588 LOP(OP_UTIME,XTERM);
79072805
LW
3589
3590 case KEY_umask:
748a9306
LW
3591 if (dowarn) {
3592 for (d = s; d < bufend && (isSPACE(*d) || *d == '('); d++) ;
3593 if (*d != '0' && isDIGIT(*d))
3594 yywarn("umask: argument is missing initial 0");
3595 }
79072805
LW
3596 UNI(OP_UMASK);
3597
3598 case KEY_unshift:
a0d0e21e
LW
3599 LOP(OP_UNSHIFT,XTERM);
3600
3601 case KEY_use:
3602 if (expect != XSTATE)
3603 yyerror("\"use\" not allowed in expression");
89bfa8cd
PP
3604 s = skipspace(s);
3605 if(isDIGIT(*s)) {
3606 s = force_version(s);
3607 if(*s == ';' || (s = skipspace(s), *s == ';')) {
3608 nextval[nexttoke].opval = Nullop;
3609 force_next(WORD);
3610 }
3611 }
3612 else {
3613 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3614 s = force_version(s);
3615 }
a0d0e21e
LW
3616 yylval.ival = 1;
3617 OPERATOR(USE);
79072805
LW
3618
3619 case KEY_values:
3620 UNI(OP_VALUES);
3621
3622 case KEY_vec:
3623 sawvec = TRUE;
a0d0e21e 3624 LOP(OP_VEC,XTERM);
79072805
LW
3625
3626 case KEY_while:
3627 yylval.ival = curcop->cop_line;
71be2cbc 3628 OPERATOR(WHILE);
79072805
LW
3629
3630 case KEY_warn:
a0d0e21e
LW
3631 hints |= HINT_BLOCK_SCOPE;
3632 LOP(OP_WARN,XTERM);
79072805
LW
3633
3634 case KEY_wait:
3635 FUN0(OP_WAIT);
3636
3637 case KEY_waitpid:
a0d0e21e 3638 LOP(OP_WAITPID,XTERM);
79072805
LW
3639
3640 case KEY_wantarray:
3641 FUN0(OP_WANTARRAY);
3642
3643 case KEY_write:
85e6fe83 3644 gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */
79072805
LW
3645 UNI(OP_ENTERWRITE);
3646
3647 case KEY_x:
3648 if (expect == XOPERATOR)
3649 Mop(OP_REPEAT);
3650 check_uni();
3651 goto just_a_word;
3652
a0d0e21e
LW
3653 case KEY_xor:
3654 yylval.ival = OP_XOR;
3655 OPERATOR(OROP);
3656
79072805
LW
3657 case KEY_y:
3658 s = scan_trans(s);
3659 TERM(sublex_start());
3660 }
3661 }
3662}
3663
3664I32
3665keyword(d, len)
3666register char *d;
3667I32 len;
3668{
3669 switch (*d) {
3670 case '_':
3671 if (d[1] == '_') {
a0d0e21e 3672 if (strEQ(d,"__FILE__")) return -KEY___FILE__;
68dc0745
PP
3673 if (strEQ(d,"__LINE__")) return -KEY___LINE__;
3674 if (strEQ(d,"__PACKAGE__")) return -KEY___PACKAGE__;
e50aee73 3675 if (strEQ(d,"__DATA__")) return KEY___DATA__;
79072805
LW
3676 if (strEQ(d,"__END__")) return KEY___END__;
3677 }
3678 break;
8990e307
LW
3679 case 'A':
3680 if (strEQ(d,"AUTOLOAD")) return KEY_AUTOLOAD;
3681 break;
79072805 3682 case 'a':
463ee0b2
LW
3683 switch (len) {
3684 case 3:
a0d0e21e
LW
3685 if (strEQ(d,"and")) return -KEY_and;
3686 if (strEQ(d,"abs")) return -KEY_abs;
85e6fe83 3687 break;
463ee0b2 3688 case 5:
a0d0e21e
LW
3689 if (strEQ(d,"alarm")) return -KEY_alarm;
3690 if (strEQ(d,"atan2")) return -KEY_atan2;
463ee0b2
LW
3691 break;
3692 case 6:
a0d0e21e 3693 if (strEQ(d,"accept")) return -KEY_accept;
463ee0b2
LW
3694 break;
3695 }
79072805
LW
3696 break;
3697 case 'B':
3698 if (strEQ(d,"BEGIN")) return KEY_BEGIN;
93a17b20 3699 break;
79072805 3700 case 'b':
a0d0e21e
LW
3701 if (strEQ(d,"bless")) return -KEY_bless;
3702 if (strEQ(d,"bind")) return -KEY_bind;
3703 if (strEQ(d,"binmode")) return -KEY_binmode;
3704 break;
3705 case 'C':
3706 if (strEQ(d,"CORE")) return -KEY_CORE;
79072805
LW
3707 break;
3708 case 'c':
3709 switch (len) {
3710 case 3:
a0d0e21e
LW
3711 if (strEQ(d,"cmp")) return -KEY_cmp;
3712 if (strEQ(d,"chr")) return -KEY_chr;
3713 if (strEQ(d,"cos")) return -KEY_cos;
79072805
LW
3714 break;
3715 case 4:
3716 if (strEQ(d,"chop")) return KEY_chop;
3717 break;
3718 case 5:
a0d0e21e
LW
3719 if (strEQ(d,"close")) return -KEY_close;
3720 if (strEQ(d,"chdir")) return -KEY_chdir;
3721 if (strEQ(d,"chomp")) return KEY_chomp;
3722 if (strEQ(d,"chmod")) return -KEY_chmod;
3723 if (strEQ(d,"chown")) return -KEY_chown;
3724 if (strEQ(d,"crypt")) return -KEY_crypt;
79072805
LW
3725 break;
3726 case 6:
a0d0e21e
LW
3727 if (strEQ(d,"chroot")) return -KEY_chroot;
3728 if (strEQ(d,"caller")) return -KEY_caller;
79072805
LW
3729 break;
3730 case 7:
a0d0e21e 3731 if (strEQ(d,"connect")) return -KEY_connect;
79072805
LW
3732 break;
3733 case 8:
a0d0e21e
LW
3734 if (strEQ(d,"closedir")) return -KEY_closedir;
3735 if (strEQ(d,"continue")) return -KEY_continue;
79072805
LW
3736 break;
3737 }
3738 break;
ed6116ce
LW
3739 case 'D':
3740 if (strEQ(d,"DESTROY")) return KEY_DESTROY;
3741 break;
79072805
LW
3742 case 'd':
3743 switch (len) {
3744 case 2:
3745 if (strEQ(d,"do")) return KEY_do;
3746 break;
3747 case 3:
a0d0e21e 3748 if (strEQ(d,"die")) return -KEY_die;
79072805
LW
3749 break;
3750 case 4:
a0d0e21e 3751 if (strEQ(d,"dump")) return -KEY_dump;
79072805
LW
3752 break;
3753 case 6:
3754 if (strEQ(d,"delete")) return KEY_delete;
3755 break;
3756 case 7:
3757 if (strEQ(d,"defined")) return KEY_defined;
a0d0e21e 3758 if (strEQ(d,"dbmopen")) return -KEY_dbmopen;
79072805
LW
3759 break;
3760 case 8:
a0d0e21e 3761 if (strEQ(d,"dbmclose")) return -KEY_dbmclose;
79072805
LW
3762 break;
3763 }
3764 break;
3765 case 'E':
a0d0e21e 3766 if (strEQ(d,"EQ")) { deprecate(d); return -KEY_eq;}
79072805
LW
3767 if (strEQ(d,"END")) return KEY_END;
3768 break;
3769 case 'e':
3770 switch (len) {
3771 case 2:
a0d0e21e 3772 if (strEQ(d,"eq")) return -KEY_eq;
79072805
LW
3773 break;
3774 case 3:
a0d0e21e
LW
3775 if (strEQ(d,"eof")) return -KEY_eof;
3776 if (strEQ(d,"exp")) return -KEY_exp;
79072805
LW
3777 break;
3778 case 4:
3779 if (strEQ(d,"else")) return KEY_else;
a0d0e21e 3780 if (strEQ(d,"exit")) return -KEY_exit;
79072805 3781 if (strEQ(d,"eval")) return KEY_eval;
a0d0e21e 3782 if (strEQ(d,"exec")) return -KEY_exec;
79072805
LW
3783 if (strEQ(d,"each")) return KEY_each;
3784 break;
3785 case 5:
3786 if (strEQ(d,"elsif")) return KEY_elsif;
3787 break;
a0d0e21e
LW
3788 case 6:
3789 if (strEQ(d,"exists")) return KEY_exists;
4633a7c4 3790 if (strEQ(d,"elseif")) warn("elseif should be elsif");
a0d0e21e 3791 break;
79072805 3792 case 8:
a0d0e21e
LW
3793 if (strEQ(d,"endgrent")) return -KEY_endgrent;
3794 if (strEQ(d,"endpwent")) return -KEY_endpwent;
79072805
LW
3795 break;
3796 case 9:
a0d0e21e 3797 if (strEQ(d,"endnetent")) return -KEY_endnetent;
79072805
LW
3798 break;
3799 case 10:
a0d0e21e
LW
3800 if (strEQ(d,"endhostent")) return -KEY_endhostent;
3801 if (strEQ(d,"endservent")) return -KEY_endservent;
79072805
LW
3802 break;
3803 case 11:
a0d0e21e 3804 if (strEQ(d,"endprotoent")) return -KEY_endprotoent;
79072805 3805 break;
a687059c 3806 }
a687059c 3807 break;
79072805
LW
3808 case 'f':
3809 switch (len) {
3810 case 3:
3811 if (strEQ(d,"for")) return KEY_for;
3812 break;
3813 case 4:
a0d0e21e 3814 if (strEQ(d,"fork")) return -KEY_fork;
79072805
LW
3815 break;
3816 case 5:
a0d0e21e
LW
3817 if (strEQ(d,"fcntl")) return -KEY_fcntl;
3818 if (strEQ(d,"flock")) return -KEY_flock;
79072805
LW
3819 break;
3820 case 6:
3821 if (strEQ(d,"format")) return KEY_format;
a0d0e21e 3822 if (strEQ(d,"fileno")) return -KEY_fileno;
79072805
LW
3823 break;
3824 case 7:
3825 if (strEQ(d,"foreach")) return KEY_foreach;
3826 break;
3827 case 8:
a0d0e21e 3828 if (strEQ(d,"formline")) return -KEY_formline;
79072805 3829 break;
378cc40b 3830 }
a687059c 3831 break;
79072805
LW
3832 case 'G':
3833 if (len == 2) {
a0d0e21e
LW
3834 if (strEQ(d,"GT")) { deprecate(d); return -KEY_gt;}
3835 if (strEQ(d,"GE")) { deprecate(d); return -KEY_ge;}
9f68db38 3836 }
a687059c 3837 break;
79072805 3838 case 'g':
a687059c
LW
3839 if (strnEQ(d,"get",3)) {
3840 d += 3;
3841 if (*d == 'p') {
79072805
LW
3842 switch (len) {
3843 case 7:
a0d0e21e
LW
3844 if (strEQ(d,"ppid")) return -KEY_getppid;
3845 if (strEQ(d,"pgrp")) return -KEY_getpgrp;
79072805
LW
3846 break;
3847 case 8:
a0d0e21e
LW
3848 if (strEQ(d,"pwent")) return -KEY_getpwent;
3849 if (strEQ(d,"pwnam")) return -KEY_getpwnam;
3850 if (strEQ(d,"pwuid")) return -KEY_getpwuid;
79072805
LW
3851 break;
3852 case 11:
a0d0e21e
LW
3853 if (strEQ(d,"peername")) return -KEY_getpeername;
3854 if (strEQ(d,"protoent")) return -KEY_getprotoent;
3855 if (strEQ(d,"priority")) return -KEY_getpriority;
79072805
LW
3856 break;
3857 case 14:
a0d0e21e 3858 if (strEQ(d,"protobyname")) return -KEY_getprotobyname;
79072805
LW
3859 break;
3860 case 16:
a0d0e21e 3861 if (strEQ(d,"protobynumber"))return -KEY_getprotobynumber;
79072805
LW
3862 break;
3863 }
a687059c
LW
3864 }
3865 else if (*d == 'h') {