This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[dummy merge]
[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));
25static char *scan_ident _((char *s, char *send, char *dest, I32 ck_uni));
26static char *scan_inputsymbol _((char *start));
27static char *scan_pat _((char *start));
28static char *scan_str _((char *start));
29static char *scan_subst _((char *start));
30static char *scan_trans _((char *start));
31static char *scan_word _((char *s, char *dest, int allow_package, STRLEN *slp));
32static char *skipspace _((char *s));
33static void checkcomma _((char *s, char *name, char *what));
34static void force_ident _((char *s, int kind));
35static void incline _((char *s));
36static int intuit_method _((char *s, GV *gv));
37static int intuit_more _((char *s));
38static I32 lop _((I32 f, expectation x, char *s));
39static void missingterm _((char *s));
40static void no_op _((char *what, char *s));
41static void set_csh _((void));
42static I32 sublex_done _((void));
55497cff 43static I32 sublex_push _((void));
a0d0e21e
LW
44static I32 sublex_start _((void));
45#ifdef CRIPPLED_CC
46static int uni _((I32 f, char *s));
47#endif
fd049845 48static char * filter_gets _((SV *sv, PerlIO *fp, STRLEN append));
6d5fb7e3 49static void restore_rsfp _((void *f));
2f3197b3 50
fd049845 51static char *linestart; /* beg. of most recently read line */
52
bbce6d69 53static char pending_ident; /* pending identifier lookup */
54
55497cff 55static struct {
56 I32 super_state; /* lexer state to save */
57 I32 sub_inwhat; /* "lex_inwhat" to use */
58 OP *sub_op; /* "lex_op" to use */
59} sublex_info;
60
79072805
LW
61/* The following are arranged oddly so that the guard on the switch statement
62 * can get by with a single comparison (if the compiler is smart enough).
63 */
64
55497cff 65#define LEX_NORMAL 10
66#define LEX_INTERPNORMAL 9
67#define LEX_INTERPCASEMOD 8
68#define LEX_INTERPPUSH 7
69#define LEX_INTERPSTART 6
70#define LEX_INTERPEND 5
71#define LEX_INTERPENDMAYBE 4
72#define LEX_INTERPCONCAT 3
73#define LEX_INTERPCONST 2
74#define LEX_FORMLINE 1
75#define LEX_KNOWNEXT 0
79072805 76
395c3793
LW
77#ifdef I_FCNTL
78#include <fcntl.h>
79#endif
fe14fcc3
LW
80#ifdef I_SYS_FILE
81#include <sys/file.h>
82#endif
395c3793 83
a790bc05 84/* XXX If this causes problems, set i_unistd=undef in the hint file. */
85#ifdef I_UNISTD
86# include <unistd.h> /* Needed for execv() */
87#endif
88
89
79072805
LW
90#ifdef ff_next
91#undef ff_next
d48672a2
LW
92#endif
93
79072805 94#include "keywords.h"
fe14fcc3 95
ae986130
LW
96#ifdef CLINE
97#undef CLINE
98#endif
79072805 99#define CLINE (copline = (curcop->cop_line < copline ? curcop->cop_line : copline))
378cc40b 100
79072805
LW
101#define TOKEN(retval) return (bufptr = s,(int)retval)
102#define OPERATOR(retval) return (expect = XTERM,bufptr = s,(int)retval)
a0d0e21e 103#define AOPERATOR(retval) return ao((expect = XTERM,bufptr = s,(int)retval))
79072805 104#define PREBLOCK(retval) return (expect = XBLOCK,bufptr = s,(int)retval)
a0d0e21e 105#define PRETERMBLOCK(retval) return (expect = XTERMBLOCK,bufptr = s,(int)retval)
79072805
LW
106#define PREREF(retval) return (expect = XREF,bufptr = s,(int)retval)
107#define TERM(retval) return (CLINE, expect = XOPERATOR,bufptr = s,(int)retval)
463ee0b2 108#define LOOPX(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)LOOPEX)
79072805
LW
109#define FTST(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)UNIOP)
110#define FUN0(f) return(yylval.ival = f,expect = XOPERATOR,bufptr = s,(int)FUNC0)
111#define FUN1(f) return(yylval.ival = f,expect = XOPERATOR,bufptr = s,(int)FUNC1)
a0d0e21e
LW
112#define BOop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)BITOROP))
113#define BAop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)BITANDOP))
114#define SHop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)SHIFTOP))
115#define PWop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)POWOP))
79072805 116#define PMop(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)MATCHOP)
a0d0e21e
LW
117#define Aop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)ADDOP))
118#define Mop(f) return ao((yylval.ival=f,expect = XTERM,bufptr = s,(int)MULOP))
79072805
LW
119#define Eop(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)EQOP)
120#define Rop(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)RELOP)
2f3197b3 121
a687059c
LW
122/* This bit of chicanery makes a unary function followed by
123 * a parenthesis into a function with one argument, highest precedence.
124 */
2f3197b3 125#define UNI(f) return(yylval.ival = f, \
79072805 126 expect = XTERM, \
2f3197b3
LW
127 bufptr = s, \
128 last_uni = oldbufptr, \
a0d0e21e 129 last_lop_op = f, \
a687059c
LW
130 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
131
79072805
LW
132#define UNIBRACK(f) return(yylval.ival = f, \
133 bufptr = s, \
134 last_uni = oldbufptr, \
135 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
136
9f68db38 137/* grandfather return to old style */
79072805
LW
138#define OLDLOP(f) return(yylval.ival=f,expect = XTERM,bufptr = s,(int)LSTOP)
139
a0d0e21e
LW
140static int
141ao(toketype)
142int toketype;
143{
144 if (*bufptr == '=') {
145 bufptr++;
146 if (toketype == ANDAND)
147 yylval.ival = OP_ANDASSIGN;
148 else if (toketype == OROR)
149 yylval.ival = OP_ORASSIGN;
150 toketype = ASSIGNOP;
151 }
152 return toketype;
153}
154
8990e307
LW
155static void
156no_op(what, s)
463ee0b2 157char *what;
8990e307 158char *s;
463ee0b2 159{
748a9306 160 char *oldbp = bufptr;
fd049845 161 bool is_first = (oldbufptr == linestart);
68dc0745 162 char *msg;
163
8990e307 164 bufptr = s;
68dc0745 165 New(890, msg, strlen(what) + 40, char);
166 sprintf(msg, "%s found where operator expected", what);
167 yywarn(msg);
168 Safefree(msg);
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 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 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 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 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 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 {
508 s = scan_word(s, 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 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 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 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 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 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 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 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 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 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,']');
79072805
LW
926 char tmpbuf[512];
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])) {
951 scan_ident(s,send,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 == '$');
1021 char tmpbuf[1024];
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 }
1031 s = scan_word(s, tmpbuf, TRUE, &len);
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 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 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 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);
36477c24 1271 if (!gv || ((tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv))) {
bbce6d69 1272 char tmpbuf[1024];
9607fc9c 1273 sprintf(tmpbuf, "In string, %s now must be written as \\%s",
1274 tokenbuf, tokenbuf);
bbce6d69 1275 yyerror(tmpbuf);
1276 }
1277 }
1278
1279 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf+1, 0));
1280 yylval.opval->op_private = OPpCONST_ENTERED;
1281 gv_fetchpv(tokenbuf+1, in_eval ? GV_ADDMULTI : TRUE,
1282 ((tokenbuf[0] == '$') ? SVt_PV
1283 : (tokenbuf[0] == '@') ? SVt_PVAV
1284 : SVt_PVHV));
1285 return WORD;
1286 }
1287
79072805
LW
1288 switch (lex_state) {
1289#ifdef COMMENTARY
1290 case LEX_NORMAL: /* Some compilers will produce faster */
1291 case LEX_INTERPNORMAL: /* code if we comment these out. */
1292 break;
1293#endif
1294
1295 case LEX_KNOWNEXT:
1296 nexttoke--;
1297 yylval = nextval[nexttoke];
463ee0b2 1298 if (!nexttoke) {
79072805 1299 lex_state = lex_defer;
463ee0b2 1300 expect = lex_expect;
a0d0e21e 1301 lex_defer = LEX_NORMAL;
463ee0b2 1302 }
79072805
LW
1303 return(nexttype[nexttoke]);
1304
1305 case LEX_INTERPCASEMOD:
1306#ifdef DEBUGGING
1307 if (bufptr != bufend && *bufptr != '\\')
463ee0b2 1308 croak("panic: INTERPCASEMOD");
79072805
LW
1309#endif
1310 if (bufptr == bufend || bufptr[1] == 'E') {
a0d0e21e 1311 char oldmod;
79072805 1312 if (lex_casemods) {
a0d0e21e
LW
1313 oldmod = lex_casestack[--lex_casemods];
1314 lex_casestack[lex_casemods] = '\0';
1315 if (bufptr != bufend && strchr("LUQ", oldmod)) {
1316 bufptr += 2;
1317 lex_state = LEX_INTERPCONCAT;
1318 }
79072805
LW
1319 return ')';
1320 }
a0d0e21e
LW
1321 if (bufptr != bufend)
1322 bufptr += 2;
1323 lex_state = LEX_INTERPCONCAT;
79072805
LW
1324 return yylex();
1325 }
1326 else {
1327 s = bufptr + 1;
1328 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
1329 tmp = *s, *s = s[2], s[2] = tmp; /* misordered... */
a0d0e21e
LW
1330 if (strchr("LU", *s) &&
1331 (strchr(lex_casestack, 'L') || strchr(lex_casestack, 'U')))
1332 {
1333 lex_casestack[--lex_casemods] = '\0';
1334 return ')';
1335 }
1336 if (lex_casemods > 10) {
89bfa8cd 1337 char* newlb = Renew(lex_casestack, lex_casemods + 2, char);
a0d0e21e
LW
1338 if (newlb != lex_casestack) {
1339 SAVEFREEPV(newlb);
1340 lex_casestack = newlb;
1341 }
1342 }
1343 lex_casestack[lex_casemods++] = *s;
1344 lex_casestack[lex_casemods] = '\0';
79072805
LW
1345 lex_state = LEX_INTERPCONCAT;
1346 nextval[nexttoke].ival = 0;
1347 force_next('(');
1348 if (*s == 'l')
1349 nextval[nexttoke].ival = OP_LCFIRST;
1350 else if (*s == 'u')
1351 nextval[nexttoke].ival = OP_UCFIRST;
1352 else if (*s == 'L')
1353 nextval[nexttoke].ival = OP_LC;
1354 else if (*s == 'U')
1355 nextval[nexttoke].ival = OP_UC;
a0d0e21e
LW
1356 else if (*s == 'Q')
1357 nextval[nexttoke].ival = OP_QUOTEMETA;
79072805 1358 else
463ee0b2 1359 croak("panic: yylex");
79072805
LW
1360 bufptr = s + 1;
1361 force_next(FUNC);
1362 if (lex_starts) {
1363 s = bufptr;
463ee0b2 1364 lex_starts = 0;
79072805
LW
1365 Aop(OP_CONCAT);
1366 }
1367 else
1368 return yylex();
1369 }
1370
55497cff 1371 case LEX_INTERPPUSH:
1372 return sublex_push();
1373
79072805
LW
1374 case LEX_INTERPSTART:
1375 if (bufptr == bufend)
1376 return sublex_done();
1377 expect = XTERM;
1378 lex_dojoin = (*bufptr == '@');
1379 lex_state = LEX_INTERPNORMAL;
1380 if (lex_dojoin) {
1381 nextval[nexttoke].ival = 0;
1382 force_next(',');
a0d0e21e 1383 force_ident("\"", '$');
79072805
LW
1384 nextval[nexttoke].ival = 0;
1385 force_next('$');
1386 nextval[nexttoke].ival = 0;
1387 force_next('(');
1388 nextval[nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
1389 force_next(FUNC);
1390 }
1391 if (lex_starts++) {
1392 s = bufptr;
1393 Aop(OP_CONCAT);
1394 }
68dc0745 1395 return yylex();
79072805
LW
1396
1397 case LEX_INTERPENDMAYBE:
1398 if (intuit_more(bufptr)) {
1399 lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
1400 break;
1401 }
1402 /* FALL THROUGH */
1403
1404 case LEX_INTERPEND:
1405 if (lex_dojoin) {
1406 lex_dojoin = FALSE;
1407 lex_state = LEX_INTERPCONCAT;
1408 return ')';
1409 }
1410 /* FALLTHROUGH */
1411 case LEX_INTERPCONCAT:
1412#ifdef DEBUGGING
1413 if (lex_brackets)
463ee0b2 1414 croak("panic: INTERPCONCAT");
79072805
LW
1415#endif
1416 if (bufptr == bufend)
1417 return sublex_done();
1418
ed6116ce 1419 if (SvIVX(linestr) == '\'') {
79072805
LW
1420 SV *sv = newSVsv(linestr);
1421 if (!lex_inpat)
1422 sv = q(sv);
1423 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1424 s = bufend;
1425 }
1426 else {
1427 s = scan_const(bufptr);
1428 if (*s == '\\')
1429 lex_state = LEX_INTERPCASEMOD;
1430 else
1431 lex_state = LEX_INTERPSTART;
1432 }
1433
1434 if (s != bufptr) {
1435 nextval[nexttoke] = yylval;
463ee0b2 1436 expect = XTERM;
79072805
LW
1437 force_next(THING);
1438 if (lex_starts++)
1439 Aop(OP_CONCAT);
1440 else {
1441 bufptr = s;
1442 return yylex();
1443 }
1444 }
1445
1446 return yylex();
a0d0e21e
LW
1447 case LEX_FORMLINE:
1448 lex_state = LEX_NORMAL;
1449 s = scan_formline(bufptr);
1450 if (!lex_formbrack)
1451 goto rightbracket;
1452 OPERATOR(';');
79072805
LW
1453 }
1454
1455 s = bufptr;
a687059c
LW
1456 oldoldbufptr = oldbufptr;
1457 oldbufptr = s;
79072805 1458 DEBUG_p( {
760ac839 1459 PerlIO_printf(PerlIO_stderr(), "### Tokener expecting %s at %s\n", exp_name[expect], s);
79072805 1460 } )
463ee0b2
LW
1461
1462 retry:
378cc40b
LW
1463 switch (*s) {
1464 default:
54310121 1465 croak("Unrecognized character \\%03o", *s & 255);
e929a76b
LW
1466 case 4:
1467 case 26:
1468 goto fake_eof; /* emulate EOF on ^D or ^Z */
378cc40b 1469 case 0:
463ee0b2 1470 if (!rsfp) {
55497cff 1471 last_uni = 0;
1472 last_lop = 0;
463ee0b2
LW
1473 if (lex_brackets)
1474 yyerror("Missing right bracket");
79072805 1475 TOKEN(0);
463ee0b2 1476 }
a687059c
LW
1477 if (s++ < bufend)
1478 goto retry; /* ignore stray nulls */
2f3197b3 1479 last_uni = 0;
79072805 1480 last_lop = 0;
a0d0e21e 1481 if (!in_eval && !preambled) {
79072805 1482 preambled = TRUE;
a0d0e21e 1483 sv_setpv(linestr,incl_perldb());
91b7def8 1484 if (SvCUR(linestr))
1485 sv_catpv(linestr,";");
1486 if (preambleav){
1487 while(AvFILL(preambleav) >= 0) {
1488 SV *tmpsv = av_shift(preambleav);
1489 sv_catsv(linestr, tmpsv);
1490 sv_catpv(linestr, ";");
1491 sv_free(tmpsv);
1492 }
1493 sv_free((SV*)preambleav);
1494 preambleav = NULL;
1495 }
79072805
LW
1496 if (minus_n || minus_p) {
1497 sv_catpv(linestr, "LINE: while (<>) {");
1498 if (minus_l)
a0d0e21e 1499 sv_catpv(linestr,"chomp;");
8fd239a7
CS
1500 if (minus_a) {
1501 GV* gv = gv_fetchpv("::F", TRUE, SVt_PVAV);
1502 if (gv)
1503 GvIMPORTED_AV_on(gv);
1504 if (minus_F) {
54310121 1505 char *tmpbuf1;
1506 New(201, tmpbuf1, strlen(splitstr) * 2 + 20, char);
1507 if (strchr("/'\"", *splitstr)
1508 && strchr(splitstr + 1, *splitstr))
1509 sprintf(tmpbuf1, "@F=split(%s);", splitstr);
1510 else {
1511 char delim;
1512 s = "'~#\200\1'"; /* surely one char is unused...*/
1513 while (s[1] && strchr(splitstr, *s)) s++;
1514 delim = *s;
1515 sprintf(tmpbuf1, "@F=split(%s%c",
1516 "q" + (delim == '\''), delim);
1517 d = tmpbuf1 + strlen(tmpbuf1);
1518 for (s = splitstr; *s; ) {
1519 if (*s == '\\')
1520 *d++ = '\\';
1521 *d++ = *s++;
1522 }
1523 sprintf(d, "%c);", delim);
1524 }
8fd239a7 1525 sv_catpv(linestr,tmpbuf1);
54310121 1526 Safefree(tmpbuf1);
2304df62
AD
1527 }
1528 else
1529 sv_catpv(linestr,"@F=split(' ');");
1530 }
79072805 1531 }
a0d0e21e 1532 sv_catpv(linestr, "\n");
fd049845 1533 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
463ee0b2 1534 bufend = SvPVX(linestr) + SvCUR(linestr);
a0d0e21e
LW
1535 if (perldb && curstash != debstash) {
1536 SV *sv = NEWSV(85,0);
1537
1538 sv_upgrade(sv, SVt_PVMG);
1539 sv_setsv(sv,linestr);
1540 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
1541 }
79072805 1542 goto retry;
a687059c 1543 }
e929a76b 1544 do {
fd049845 1545 if ((s = filter_gets(linestr, rsfp, 0)) == Nullch) {
e929a76b 1546 fake_eof:
395c3793 1547 if (rsfp) {
a0d0e21e 1548 if (preprocess && !in_eval)
79072805 1549 (void)my_pclose(rsfp);
760ac839
LW
1550 else if ((PerlIO *)rsfp == PerlIO_stdin())
1551 PerlIO_clearerr(rsfp);
395c3793 1552 else
760ac839 1553 (void)PerlIO_close(rsfp);
395c3793
LW
1554 rsfp = Nullfp;
1555 }
a0d0e21e 1556 if (!in_eval && (minus_n || minus_p)) {
79072805
LW
1557 sv_setpv(linestr,minus_p ? ";}continue{print" : "");
1558 sv_catpv(linestr,";}");
fd049845 1559 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
463ee0b2 1560 bufend = SvPVX(linestr) + SvCUR(linestr);
e929a76b
LW
1561 minus_n = minus_p = 0;
1562 goto retry;
1563 }
fd049845 1564 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
79072805
LW
1565 sv_setpv(linestr,"");
1566 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
378cc40b 1567 }
a0d0e21e
LW
1568 if (doextract) {
1569 if (*s == '#' && s[1] == '!' && instr(s,"perl"))
1570 doextract = FALSE;
1571
1572 /* Incest with pod. */
1573 if (*s == '=' && strnEQ(s, "=cut", 4)) {
1574 sv_setpv(linestr, "");
fd049845 1575 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
a0d0e21e
LW
1576 bufend = SvPVX(linestr) + SvCUR(linestr);
1577 doextract = FALSE;
1578 }
1579 }
463ee0b2 1580 incline(s);
e929a76b 1581 } while (doextract);
fd049845 1582 oldoldbufptr = oldbufptr = bufptr = linestart = s;
8990e307 1583 if (perldb && curstash != debstash) {
79072805 1584 SV *sv = NEWSV(85,0);
a687059c 1585
93a17b20 1586 sv_upgrade(sv, SVt_PVMG);
79072805
LW
1587 sv_setsv(sv,linestr);
1588 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
a687059c 1589 }
463ee0b2 1590 bufend = SvPVX(linestr) + SvCUR(linestr);
79072805
LW
1591 if (curcop->cop_line == 1) {
1592 while (s < bufend && isSPACE(*s))
1593 s++;
a0d0e21e 1594 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
79072805 1595 s++;
44a8e56a 1596 d = Nullch;
1597 if (!in_eval) {
1598 if (*s == '#' && *(s+1) == '!')
1599 d = s + 2;
1600#ifdef ALTERNATE_SHEBANG
1601 else {
1602 static char as[] = ALTERNATE_SHEBANG;
1603 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
1604 d = s + (sizeof(as) - 1);
1605 }
1606#endif /* ALTERNATE_SHEBANG */
1607 }
1608 if (d) {
b8378b72 1609 char *ipath;
774d564b 1610 char *ipathend;
b8378b72 1611
774d564b 1612 while (isSPACE(*d))
b8378b72
CS
1613 d++;
1614 ipath = d;
774d564b 1615 while (*d && !isSPACE(*d))
1616 d++;
1617 ipathend = d;
1618
1619#ifdef ARG_ZERO_IS_SCRIPT
1620 if (ipathend > ipath) {
1621 /*
1622 * HP-UX (at least) sets argv[0] to the script name,
1623 * which makes $^X incorrect. And Digital UNIX and Linux,
1624 * at least, set argv[0] to the basename of the Perl
1625 * interpreter. So, having found "#!", we'll set it right.
1626 */
1627 SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV));
1628 assert(SvPOK(x) || SvGMAGICAL(x));
9607fc9c 1629 if (sv_eq(x, GvSV(curcop->cop_filegv))) {
774d564b 1630 sv_setpvn(x, ipath, ipathend - ipath);
9607fc9c 1631 SvSETMAGIC(x);
1632 }
774d564b 1633 TAINT_NOT; /* $^X is always tainted, but that's OK */
8ebc5c01 1634 }
774d564b 1635#endif /* ARG_ZERO_IS_SCRIPT */
b8378b72
CS
1636
1637 /*
1638 * Look for options.
1639 */
748a9306
LW
1640 d = instr(s,"perl -");
1641 if (!d)
1642 d = instr(s,"perl");
44a8e56a 1643#ifdef ALTERNATE_SHEBANG
1644 /*
1645 * If the ALTERNATE_SHEBANG on this system starts with a
1646 * character that can be part of a Perl expression, then if
1647 * we see it but not "perl", we're probably looking at the
1648 * start of Perl code, not a request to hand off to some
1649 * other interpreter. Similarly, if "perl" is there, but
1650 * not in the first 'word' of the line, we assume the line
1651 * contains the start of the Perl program.
44a8e56a 1652 */
1653 if (d && *s != '#') {
774d564b 1654 char *c = ipath;
44a8e56a 1655 while (*c && !strchr("; \t\r\n\f\v#", *c))
1656 c++;
1657 if (c < d)
1658 d = Nullch; /* "perl" not in first word; ignore */
1659 else
1660 *s = '#'; /* Don't try to parse shebang line */
1661 }
774d564b 1662#endif /* ALTERNATE_SHEBANG */
748a9306 1663 if (!d &&
44a8e56a 1664 *s == '#' &&
774d564b 1665 ipathend > ipath &&
748a9306
LW
1666 !minus_c &&
1667 !instr(s,"indir") &&
1668 instr(origargv[0],"perl"))
1669 {
9f68db38 1670 char **newargv;
9f68db38 1671
774d564b 1672 *ipathend = '\0';
1673 s = ipathend + 1;
de3bb511 1674 while (s < bufend && isSPACE(*s))
9f68db38
LW
1675 s++;
1676 if (s < bufend) {
1677 Newz(899,newargv,origargc+3,char*);
1678 newargv[1] = s;
de3bb511 1679 while (s < bufend && !isSPACE(*s))
9f68db38
LW
1680 s++;
1681 *s = '\0';
1682 Copy(origargv+1, newargv+2, origargc+1, char*);
1683 }
1684 else
1685 newargv = origargv;
774d564b 1686 newargv[0] = ipath;
1687 execv(ipath, newargv);
1688 croak("Can't exec %s", ipath);
9f68db38 1689 }
748a9306 1690 if (d) {
a0d0e21e
LW
1691 int oldpdb = perldb;
1692 int oldn = minus_n;
1693 int oldp = minus_p;
748a9306
LW
1694
1695 while (*d && !isSPACE(*d)) d++;
89bfa8cd 1696 while (*d == ' ' || *d == '\t') d++;
748a9306
LW
1697
1698 if (*d++ == '-') {
1699 while (d = moreswitches(d)) ;
1700 if (perldb && !oldpdb ||
b084f20b 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 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
LW
1847 if (expect != XOPERATOR) {
1848 s = scan_ident(s, bufend, 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 1863 if (expect == XOPERATOR) {
1864 ++s;
1865 Mop(OP_MODULO);
a687059c 1866 }
bbce6d69 1867 tokenbuf[0] = '%';
1868 s = scan_ident(s, bufend, tokenbuf+1, TRUE);
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 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)) {
1958 d = scan_word(d, tokenbuf + 1, FALSE, &len);
748a9306
LW
1959 while (d < bufend && (*d == ' ' || *d == '\t'))
1960 d++;
1961 if (*d == '}') {
44a8e56a 1962 char minus = (tokenbuf[0] == '-');
748a9306 1963 if (dowarn &&
44a8e56a 1964 (keyword(tokenbuf + 1, len) ||
1965 (minus && len == 1 && isALPHA(tokenbuf[1])) ||
1966 perl_get_cv(tokenbuf + 1, FALSE) ))
748a9306 1967 warn("Ambiguous use of {%s} resolved to {\"%s\"}",
44a8e56a 1968 tokenbuf + !minus, tokenbuf + !minus);
1969 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
1970 if (minus)
1971 force_next('-');
748a9306
LW
1972 }
1973 }
1974 /* FALL THROUGH */
1975 case XBLOCK:
a0d0e21e 1976 lex_brackstack[lex_brackets++] = XSTATE;
2304df62 1977 expect = XSTATE;
a0d0e21e
LW
1978 break;
1979 case XTERMBLOCK:
1980 lex_brackstack[lex_brackets++] = XOPERATOR;
1981 expect = XSTATE;
1982 break;
1983 default: {
1984 char *t;
1985 if (oldoldbufptr == last_lop)
1986 lex_brackstack[lex_brackets++] = XTERM;
1987 else
1988 lex_brackstack[lex_brackets++] = XOPERATOR;
1989 s = skipspace(s);
1990 if (*s == '}')
1991 OPERATOR(HASHBRACK);
1992 if (isALPHA(*s)) {
c07a80fd 1993 for (t = s; t < bufend && isALNUM(*t); t++) ;
a0d0e21e
LW
1994 }
1995 else if (*s == '\'' || *s == '"') {
1996 t = strchr(s+1,*s);
1997 if (!t++)
1998 t = s;
1999 }
2000 else
2001 t = s;
2002 while (t < bufend && isSPACE(*t))
2003 t++;
2004 if ((*t == ',' && !isLOWER(*s)) || (*t == '=' && t[1] == '>'))
2005 OPERATOR(HASHBRACK);
2006 if (expect == XREF)
2007 expect = XTERM;
2008 else {
2009 lex_brackstack[lex_brackets-1] = XSTATE;
2010 expect = XSTATE;
2011 }
8990e307 2012 }
a0d0e21e 2013 break;
463ee0b2 2014 }
79072805
LW
2015 yylval.ival = curcop->cop_line;
2016 if (isSPACE(*s) || *s == '#')
2017 copline = NOLINE; /* invalidate current command line number */
79072805 2018 TOKEN('{');
378cc40b 2019 case '}':
79072805
LW
2020 rightbracket:
2021 s++;
463ee0b2
LW
2022 if (lex_brackets <= 0)
2023 yyerror("Unmatched right bracket");
2024 else
2025 expect = (expectation)lex_brackstack[--lex_brackets];
85e6fe83
LW
2026 if (lex_brackets < lex_formbrack)
2027 lex_formbrack = 0;
79072805 2028 if (lex_state == LEX_INTERPNORMAL) {
463ee0b2 2029 if (lex_brackets == 0) {
79072805
LW
2030 if (lex_fakebrack) {
2031 lex_state = LEX_INTERPEND;
2032 bufptr = s;
2033 return yylex(); /* ignore fake brackets */
2034 }
fa83b5b6 2035 if (*s == '-' && s[1] == '>')
2036 lex_state = LEX_INTERPENDMAYBE;
2037 else if (*s != '[' && *s != '{')
79072805
LW
2038 lex_state = LEX_INTERPEND;
2039 }
2040 }
748a9306
LW
2041 if (lex_brackets < lex_fakebrack) {
2042 bufptr = s;
2043 lex_fakebrack = 0;
2044 return yylex(); /* ignore fake brackets */
2045 }
79072805
LW
2046 force_next('}');
2047 TOKEN(';');
378cc40b
LW
2048 case '&':
2049 s++;
2050 tmp = *s++;
2051 if (tmp == '&')
a0d0e21e 2052 AOPERATOR(ANDAND);
378cc40b 2053 s--;
463ee0b2 2054 if (expect == XOPERATOR) {
fd049845 2055 if (dowarn && isALPHA(*s) && bufptr == linestart) {
463ee0b2
LW
2056 curcop->cop_line--;
2057 warn(warn_nosemi);
2058 curcop->cop_line++;
2059 }
79072805 2060 BAop(OP_BIT_AND);
463ee0b2 2061 }
79072805
LW
2062
2063 s = scan_ident(s-1, bufend, tokenbuf, TRUE);
463ee0b2
LW
2064 if (*tokenbuf) {
2065 expect = XOPERATOR;
a0d0e21e 2066 force_ident(tokenbuf, '&');
463ee0b2 2067 }
79072805
LW
2068 else
2069 PREREF('&');
c07a80fd 2070 yylval.ival = (OPpENTERSUB_AMPER<<8);
79072805
LW
2071 TERM('&');
2072
378cc40b
LW
2073 case '|':
2074 s++;
2075 tmp = *s++;
2076 if (tmp == '|')
a0d0e21e 2077 AOPERATOR(OROR);
378cc40b 2078 s--;
79072805 2079 BOop(OP_BIT_OR);
378cc40b
LW
2080 case '=':
2081 s++;
2082 tmp = *s++;
2083 if (tmp == '=')
79072805
LW
2084 Eop(OP_EQ);
2085 if (tmp == '>')
2086 OPERATOR(',');
378cc40b 2087 if (tmp == '~')
79072805 2088 PMop(OP_MATCH);
463ee0b2 2089 if (dowarn && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
ff0cee69 2090 warn("Reversed %c= operator",(int)tmp);
378cc40b 2091 s--;
748a9306 2092 if (expect == XSTATE && isALPHA(tmp) &&
fd049845 2093 (s == linestart+1 || s[-2] == '\n') )
748a9306 2094 {
a5f75d66
AD
2095 if (in_eval && !rsfp) {
2096 d = bufend;
2097 while (s < d) {
2098 if (*s++ == '\n') {
2099 incline(s);
2100 if (strnEQ(s,"=cut",4)) {
2101 s = strchr(s,'\n');
2102 if (s)
2103 s++;
2104 else
2105 s = d;
2106 incline(s);
2107 goto retry;
2108 }
2109 }
2110 }
2111 goto retry;
2112 }
a0d0e21e
LW
2113 s = bufend;
2114 doextract = TRUE;
2115 goto retry;
2116 }
2117 if (lex_brackets < lex_formbrack) {
2118 char *t;
2119 for (t = s; *t == ' ' || *t == '\t'; t++) ;
2120 if (*t == '\n' || *t == '#') {
2121 s--;
2122 expect = XBLOCK;
2123 goto leftbracket;
2124 }
79072805 2125 }
a0d0e21e
LW
2126 yylval.ival = 0;
2127 OPERATOR(ASSIGNOP);
378cc40b
LW
2128 case '!':
2129 s++;
2130 tmp = *s++;
2131 if (tmp == '=')
79072805 2132 Eop(OP_NE);
378cc40b 2133 if (tmp == '~')
79072805 2134 PMop(OP_NOT);
378cc40b
LW
2135 s--;
2136 OPERATOR('!');
2137 case '<':
79072805 2138 if (expect != XOPERATOR) {
93a17b20 2139 if (s[1] != '<' && !strchr(s,'>'))
2f3197b3 2140 check_uni();
79072805
LW
2141 if (s[1] == '<')
2142 s = scan_heredoc(s);
2143 else
2144 s = scan_inputsymbol(s);
2145 TERM(sublex_start());
378cc40b
LW
2146 }
2147 s++;
2148 tmp = *s++;
2149 if (tmp == '<')
79072805 2150 SHop(OP_LEFT_SHIFT);
395c3793
LW
2151 if (tmp == '=') {
2152 tmp = *s++;
2153 if (tmp == '>')
79072805 2154 Eop(OP_NCMP);
395c3793 2155 s--;
79072805 2156 Rop(OP_LE);
395c3793 2157 }
378cc40b 2158 s--;
79072805 2159 Rop(OP_LT);
378cc40b
LW
2160 case '>':
2161 s++;
2162 tmp = *s++;
2163 if (tmp == '>')
79072805 2164 SHop(OP_RIGHT_SHIFT);
378cc40b 2165 if (tmp == '=')
79072805 2166 Rop(OP_GE);
378cc40b 2167 s--;
79072805 2168 Rop(OP_GT);
378cc40b
LW
2169
2170 case '$':
bbce6d69 2171 CLINE;
2172
2173 if (expect == XOPERATOR) {
2174 if (lex_formbrack && lex_brackets == lex_formbrack) {
2175 expect = XTERM;
2176 depcom();
2177 return ','; /* grandfather non-comma-format format */
8990e307 2178 }
bbce6d69 2179 }
2180
2181 if (s[1] == '#' && (isALPHA(s[2]) || strchr("_{$:", s[2]))) {
2182 if (expect == XOPERATOR)
2183 no_op("Array length", bufptr);
2184 tokenbuf[0] = '@';
2185 s = scan_ident(s+1, bufend, tokenbuf+1, FALSE);
2186 if (!tokenbuf[1])
a0d0e21e 2187 PREREF(DOLSHARP);
463ee0b2 2188 expect = XOPERATOR;
bbce6d69 2189 pending_ident = '#';
463ee0b2 2190 TOKEN(DOLSHARP);
79072805 2191 }
bbce6d69 2192
2193 if (expect == XOPERATOR)
2194 no_op("Scalar", bufptr);
2195 tokenbuf[0] = '$';
93a17b20 2196 s = scan_ident(s, bufend, tokenbuf+1, FALSE);
bbce6d69 2197 if (!tokenbuf[1]) {
2198 if (s == bufend)
2199 yyerror("Final $ should be \\$ or $name");
2200 PREREF('$');
8990e307 2201 }
a0d0e21e 2202
bbce6d69 2203 /* This kludge not intended to be bulletproof. */
2204 if (tokenbuf[1] == '[' && !tokenbuf[2]) {
2205 yylval.opval = newSVOP(OP_CONST, 0,
2206 newSViv((IV)compiling.cop_arybase));
2207 yylval.opval->op_private = OPpCONST_ARYBASE;
2208 TERM(THING);
2209 }
2210
ff68c719 2211 d = s;
2212 if (lex_state == LEX_NORMAL)
2213 s = skipspace(s);
2214
bbce6d69 2215 if ((expect != XREF || oldoldbufptr == last_lop) && intuit_more(s)) {
2216 char *t;
2217 if (*s == '[') {
2218 tokenbuf[0] = '@';
2219 if (dowarn) {
2220 for(t = s + 1;
2221 isSPACE(*t) || isALNUM(*t) || *t == '$';
2222 t++) ;
a0d0e21e
LW
2223 if (*t++ == ',') {
2224 bufptr = skipspace(bufptr);
bbce6d69 2225 while (t < bufend && *t != ']')
2226 t++;
a0d0e21e 2227 warn("Multidimensional syntax %.*s not supported",
bbce6d69 2228 (t - bufptr) + 1, bufptr);
a0d0e21e
LW
2229 }
2230 }
bbce6d69 2231 }
2232 else if (*s == '{') {
2233 tokenbuf[0] = '%';
2234 if (dowarn && strEQ(tokenbuf+1, "SIG") &&
2235 (t = strchr(s, '}')) && (t = strchr(t, '=')))
2236 {
a0d0e21e 2237 char tmpbuf[1024];
a0d0e21e
LW
2238 STRLEN len;
2239 for (t++; isSPACE(*t); t++) ;
748a9306
LW
2240 if (isIDFIRST(*t)) {
2241 t = scan_word(t, tmpbuf, TRUE, &len);
2242 if (*t != '(' && perl_get_cv(tmpbuf, FALSE))
2243 warn("You need to quote \"%s\"", tmpbuf);
2244 }
93a17b20
LW
2245 }
2246 }
2f3197b3 2247 }
bbce6d69 2248
2249 expect = XOPERATOR;
ff68c719 2250 if (lex_state == LEX_NORMAL && isSPACE(*d)) {
bbce6d69 2251 bool islop = (last_lop == oldoldbufptr);
bbce6d69 2252 if (!islop || last_lop_op == OP_GREPSTART)
2253 expect = XOPERATOR;
2254 else if (strchr("$@\"'`q", *s))
2255 expect = XTERM; /* e.g. print $fh "foo" */
2256 else if (strchr("&*<%", *s) && isIDFIRST(s[1]))
2257 expect = XTERM; /* e.g. print $fh &sub */
68dc0745 2258 else if (isIDFIRST(*s)) {
2259 char tmpbuf[1024];
2260 scan_word(s, tmpbuf, TRUE, &len);
2261 if (keyword(tmpbuf, len))
2262 expect = XTERM; /* e.g. print $fh length() */
2263 else {
2264 GV *gv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
2265 if (gv && GvCVu(gv))
2266 expect = XTERM; /* e.g. print $fh subr() */
2267 }
2268 }
bbce6d69 2269 else if (isDIGIT(*s))
2270 expect = XTERM; /* e.g. print $fh 3 */
2271 else if (*s == '.' && isDIGIT(s[1]))
2272 expect = XTERM; /* e.g. print $fh .3 */
2273 else if (strchr("/?-+", *s) && !isSPACE(s[1]))
2274 expect = XTERM; /* e.g. print $fh -1 */
2275 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]))
2276 expect = XTERM; /* print $fh <<"EOF" */
2277 }
2278 pending_ident = '$';
79072805 2279 TOKEN('$');
378cc40b
LW
2280
2281 case '@':
8990e307 2282 if (expect == XOPERATOR)
bbce6d69 2283 no_op("Array", s);
2284 tokenbuf[0] = '@';
2285 s = scan_ident(s, bufend, tokenbuf+1, FALSE);
2286 if (!tokenbuf[1]) {
2287 if (s == bufend)
2288 yyerror("Final @ should be \\@ or @name");
2289 PREREF('@');
2290 }
ff68c719 2291 if (lex_state == LEX_NORMAL)
2292 s = skipspace(s);
bbce6d69 2293 if ((expect != XREF || oldoldbufptr == last_lop) && intuit_more(s)) {
2294 if (*s == '{')
2295 tokenbuf[0] = '%';
a0d0e21e
LW
2296
2297 /* Warn about @ where they meant $. */
2298 if (dowarn) {
2299 if (*s == '[' || *s == '{') {
2300 char *t = s + 1;
2301 while (*t && (isALNUM(*t) || strchr(" \t$#+-'\"", *t)))
2302 t++;
2303 if (*t == '}' || *t == ']') {
2304 t++;
2305 bufptr = skipspace(bufptr);
2306 warn("Scalar value %.*s better written as $%.*s",
2307 t-bufptr, bufptr, t-bufptr-1, bufptr+1);
2308 }
93a17b20
LW
2309 }
2310 }
463ee0b2 2311 }
bbce6d69 2312 pending_ident = '@';
79072805 2313 TERM('@');
378cc40b
LW
2314
2315 case '/': /* may either be division or pattern */
2316 case '?': /* may either be conditional or pattern */
79072805 2317 if (expect != XOPERATOR) {
2f3197b3 2318 check_uni();
79072805
LW
2319 s = scan_pat(s);
2320 TERM(sublex_start());
378cc40b
LW
2321 }
2322 tmp = *s++;
a687059c 2323 if (tmp == '/')
79072805 2324 Mop(OP_DIVIDE);
378cc40b
LW
2325 OPERATOR(tmp);
2326
2327 case '.':
748a9306 2328 if (lex_formbrack && lex_brackets == lex_formbrack && s[1] == '\n' &&
fd049845 2329 (s == linestart || s[-1] == '\n') ) {
85e6fe83 2330 lex_formbrack = 0;
8990e307 2331 expect = XSTATE;
79072805
LW
2332 goto rightbracket;
2333 }
2334 if (expect == XOPERATOR || !isDIGIT(s[1])) {
378cc40b 2335 tmp = *s++;
a687059c
LW
2336 if (*s == tmp) {
2337 s++;
2f3197b3
LW
2338 if (*s == tmp) {
2339 s++;
79072805 2340 yylval.ival = OPf_SPECIAL;
2f3197b3
LW
2341 }
2342 else
79072805 2343 yylval.ival = 0;
378cc40b 2344 OPERATOR(DOTDOT);
a687059c 2345 }
79072805 2346 if (expect != XOPERATOR)
2f3197b3 2347 check_uni();
79072805 2348 Aop(OP_CONCAT);
378cc40b
LW
2349 }
2350 /* FALL THROUGH */
2351 case '0': case '1': case '2': case '3': case '4':
2352 case '5': case '6': case '7': case '8': case '9':
79072805 2353 s = scan_num(s);
8990e307
LW
2354 if (expect == XOPERATOR)
2355 no_op("Number",s);
79072805
LW
2356 TERM(THING);
2357
2358 case '\'':
8990e307 2359 s = scan_str(s);
463ee0b2 2360 if (expect == XOPERATOR) {
a0d0e21e
LW
2361 if (lex_formbrack && lex_brackets == lex_formbrack) {
2362 expect = XTERM;
2363 depcom();
2364 return ','; /* grandfather non-comma-format format */
2365 }
463ee0b2 2366 else
8990e307 2367 no_op("String",s);
463ee0b2 2368 }
79072805 2369 if (!s)
85e6fe83 2370 missingterm((char*)0);
79072805
LW
2371 yylval.ival = OP_CONST;
2372 TERM(sublex_start());
2373
2374 case '"':
8990e307 2375 s = scan_str(s);
463ee0b2 2376 if (expect == XOPERATOR) {
a0d0e21e
LW
2377 if (lex_formbrack && lex_brackets == lex_formbrack) {
2378 expect = XTERM;
2379 depcom();
2380 return ','; /* grandfather non-comma-format format */
2381 }
463ee0b2 2382 else
8990e307 2383 no_op("String",s);
463ee0b2 2384 }
79072805 2385 if (!s)
85e6fe83 2386 missingterm((char*)0);
4633a7c4
LW
2387 yylval.ival = OP_CONST;
2388 for (d = SvPV(lex_stuff, len); len; len--, d++) {
2389 if (*d == '$' || *d == '@' || *d == '\\') {
2390 yylval.ival = OP_STRINGIFY;
2391 break;
2392 }
2393 }
79072805
LW
2394 TERM(sublex_start());
2395
2396 case '`':
2397 s = scan_str(s);
8990e307
LW
2398 if (expect == XOPERATOR)
2399 no_op("Backticks",s);
79072805 2400 if (!s)
85e6fe83 2401 missingterm((char*)0);
79072805
LW
2402 yylval.ival = OP_BACKTICK;
2403 set_csh();
2404 TERM(sublex_start());
2405
2406 case '\\':
2407 s++;
748a9306
LW
2408 if (dowarn && lex_inwhat && isDIGIT(*s))
2409 warn("Can't use \\%c to mean $%c in expression", *s, *s);
8990e307
LW
2410 if (expect == XOPERATOR)
2411 no_op("Backslash",s);
79072805
LW
2412 OPERATOR(REFGEN);
2413
2414 case 'x':
2415 if (isDIGIT(s[1]) && expect == XOPERATOR) {
2416 s++;
2417 Mop(OP_REPEAT);
2f3197b3 2418 }
79072805
LW
2419 goto keylookup;
2420
378cc40b 2421 case '_':
79072805
LW
2422 case 'a': case 'A':
2423 case 'b': case 'B':
2424 case 'c': case 'C':
2425 case 'd': case 'D':
2426 case 'e': case 'E':
2427 case 'f': case 'F':
2428 case 'g': case 'G':
2429 case 'h': case 'H':
2430 case 'i': case 'I':
2431 case 'j': case 'J':
2432 case 'k': case 'K':
2433 case 'l': case 'L':
2434 case 'm': case 'M':
2435 case 'n': case 'N':
2436 case 'o': case 'O':
2437 case 'p': case 'P':
2438 case 'q': case 'Q':
2439 case 'r': case 'R':
2440 case 's': case 'S':
2441 case 't': case 'T':
2442 case 'u': case 'U':
2443 case 'v': case 'V':
2444 case 'w': case 'W':
2445 case 'X':
2446 case 'y': case 'Y':
2447 case 'z': case 'Z':
2448
2449 keylookup:
748a9306 2450 bufptr = s;
463ee0b2 2451 s = scan_word(s, tokenbuf, FALSE, &len);
8ebc5c01 2452
2453 /* Some keywords can be followed by any delimiter, including ':' */
2454 tmp = (len == 1 && strchr("msyq", tokenbuf[0]) ||
2455 len == 2 && ((tokenbuf[0] == 't' && tokenbuf[1] == 'r') ||
2456 (tokenbuf[0] == 'q' &&
2457 strchr("qwx", tokenbuf[1]))));
2458
2459 /* x::* is just a word, unless x is "CORE" */
2460 if (!tmp && *s == ':' && s[1] == ':' && strNE(tokenbuf, "CORE"))
4633a7c4
LW
2461 goto just_a_word;
2462
3643fb5f
CS
2463 d = s;
2464 while (d < bufend && isSPACE(*d))
2465 d++; /* no comments skipped here, or s### is misparsed */
2466
2467 /* Is this a label? */
8ebc5c01 2468 if (!tmp && expect == XSTATE
2469 && d < bufend && *d == ':' && *(d + 1) != ':') {
2470 s = d + 1;
2471 yylval.pval = savepv(tokenbuf);
2472 CLINE;
2473 TOKEN(LABEL);
3643fb5f
CS
2474 }
2475
2476 /* Check for keywords */
a0d0e21e 2477 tmp = keyword(tokenbuf, len);
748a9306
LW
2478
2479 /* Is this a word before a => operator? */
748a9306
LW
2480 if (strnEQ(d,"=>",2)) {
2481 CLINE;
2482 if (dowarn && (tmp || perl_get_cv(tokenbuf, FALSE)))
2483 warn("Ambiguous use of %s => resolved to \"%s\" =>",
2484 tokenbuf, tokenbuf);
2485 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf,0));
2486 yylval.opval->op_private = OPpCONST_BARE;
2487 TERM(WORD);
2488 }
2489
a0d0e21e
LW
2490 if (tmp < 0) { /* second-class keyword? */
2491 GV* gv;
2492 if (expect != XOPERATOR &&
a5f75d66
AD
2493 (*s != ':' || s[1] != ':') &&
2494 (gv = gv_fetchpv(tokenbuf, FALSE, SVt_PVCV)) &&
2495 GvIMPORTED_CV(gv))
a0d0e21e
LW
2496 {
2497 tmp = 0;
2498 }
2499 else
2500 tmp = -tmp;
2501 }
2502
2503 reserved_word:
2504 switch (tmp) {
79072805
LW
2505
2506 default: /* not a keyword */
93a17b20
LW
2507 just_a_word: {
2508 GV *gv;
748a9306 2509 char lastchar = (bufptr == oldoldbufptr ? 0 : bufptr[-1]);
8990e307
LW
2510
2511 /* Get the rest if it looks like a package qualifier */
2512
a0d0e21e 2513 if (*s == '\'' || *s == ':' && s[1] == ':') {
463ee0b2 2514 s = scan_word(s, tokenbuf + len, TRUE, &len);
a0d0e21e
LW
2515 if (!len)
2516 croak("Bad name after %s::", tokenbuf);
2517 }
8990e307 2518
3643fb5f 2519 if (expect == XOPERATOR) {
fd049845 2520 if (bufptr == linestart) {
463ee0b2
LW
2521 curcop->cop_line--;
2522 warn(warn_nosemi);
2523 curcop->cop_line++;
2524 }
2525 else
54310121 2526 no_op("Bareword",s);
463ee0b2 2527 }
8990e307
LW
2528
2529 /* Look for a subroutine with this name in current package. */
2530
85e6fe83 2531 gv = gv_fetchpv(tokenbuf,FALSE, SVt_PVCV);
8990e307 2532
a0d0e21e
LW
2533 /* Presume this is going to be a bareword of some sort. */
2534
2535 CLINE;
2536 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf,0));
2537 yylval.opval->op_private = OPpCONST_BARE;
2538
8990e307
LW
2539 /* See if it's the indirect object for a list operator. */
2540
a0d0e21e
LW
2541 if (oldoldbufptr &&
2542 oldoldbufptr < bufptr &&
2543 (oldoldbufptr == last_lop || oldoldbufptr == last_uni) &&
2544 /* NO SKIPSPACE BEFORE HERE! */
2545 (expect == XREF ||
2546 (opargs[last_lop_op] >> OASHIFT & 7) == OA_FILEREF) )
2547 {
748a9306
LW
2548 bool immediate_paren = *s == '(';
2549
a0d0e21e
LW
2550 /* (Now we can afford to cross potential line boundary.) */
2551 s = skipspace(s);
2552
2553 /* Two barewords in a row may indicate method call. */
2554
2555 if ((isALPHA(*s) || *s == '$') && (tmp=intuit_method(s,gv)))
2556 return tmp;
2557
2558 /* If not a declared subroutine, it's an indirect object. */
2559 /* (But it's an indir obj regardless for sort.) */
2560
8e07c86e 2561 if ((last_lop_op == OP_SORT ||
8ebc5c01 2562 (!immediate_paren && (!gv || !GvCVu(gv))) ) &&
8e07c86e 2563 (last_lop_op != OP_MAPSTART && last_lop_op != OP_GREPSTART)){
748a9306
LW
2564 expect = (last_lop == oldoldbufptr) ? XTERM : XOPERATOR;
2565 goto bareword;
93a17b20
LW
2566 }
2567 }
8990e307
LW
2568
2569 /* If followed by a paren, it's certainly a subroutine. */
2570
2571 expect = XOPERATOR;
2572 s = skipspace(s);
93a17b20 2573 if (*s == '(') {
79072805 2574 CLINE;
a0d0e21e 2575 nextval[nexttoke].opval = yylval.opval;
463ee0b2 2576 expect = XOPERATOR;
93a17b20 2577 force_next(WORD);
c07a80fd 2578 yylval.ival = 0;
463ee0b2 2579 TOKEN('&');
79072805 2580 }
93a17b20 2581
a0d0e21e 2582 /* If followed by var or block, call it a method (unless sub) */
8990e307 2583
8ebc5c01 2584 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
463ee0b2 2585 last_lop = oldbufptr;
8990e307 2586 last_lop_op = OP_METHOD;
93a17b20 2587 PREBLOCK(METHOD);
463ee0b2
LW
2588 }
2589
8990e307
LW
2590 /* If followed by a bareword, see if it looks like indir obj. */
2591
a0d0e21e
LW
2592 if ((isALPHA(*s) || *s == '$') && (tmp = intuit_method(s,gv)))
2593 return tmp;
93a17b20 2594
8990e307
LW
2595 /* Not a method, so call it a subroutine (if defined) */
2596
8ebc5c01 2597 if (gv && GvCVu(gv)) {
4633a7c4 2598 CV* cv = GvCV(gv);
8990e307 2599 if (*s == '(') {
a5f75d66 2600 nextval[nexttoke].opval = yylval.opval;
8990e307
LW
2601 expect = XTERM;
2602 force_next(WORD);
c07a80fd 2603 yylval.ival = 0;
8990e307
LW
2604 TOKEN('&');
2605 }
748a9306 2606 if (lastchar == '-')
c2960299 2607 warn("Ambiguous use of -%s resolved as -&%s()",
748a9306 2608 tokenbuf, tokenbuf);
8990e307 2609 last_lop = oldbufptr;
a0d0e21e 2610 last_lop_op = OP_ENTERSUB;
89bfa8cd 2611 /* Check for a constant sub */
760ac839
LW
2612 {
2613 SV *sv = cv_const_sv(cv);
89bfa8cd 2614 if (sv) {
2615 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
2616 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
2617 yylval.opval->op_private = 0;
2618 TOKEN(WORD);
2619 }
2620 }
2621
a5f75d66
AD
2622 /* Resolve to GV now. */
2623 op_free(yylval.opval);
2624 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
4633a7c4
LW
2625 /* Is there a prototype? */
2626 if (SvPOK(cv)) {
2627 STRLEN len;
2628 char *proto = SvPV((SV*)cv, len);
2629 if (!len)
2630 TERM(FUNC0SUB);
2631 if (strEQ(proto, "$"))
2632 OPERATOR(UNIOPSUB);
2633 if (*proto == '&' && *s == '{') {
2634 sv_setpv(subname,"__ANON__");
2635 PREBLOCK(LSTOPSUB);
2636 }
2637 }
a5f75d66 2638 nextval[nexttoke].opval = yylval.opval;
8990e307
LW
2639 expect = XTERM;
2640 force_next(WORD);
2641 TOKEN(NOAMP);
2642 }
748a9306
LW
2643
2644 if (hints & HINT_STRICT_SUBS &&
2645 lastchar != '-' &&
a0d0e21e 2646 strnNE(s,"->",2) &&
9b01e405 2647 last_lop_op != OP_TRUNCATE && /* S/F prototype in opcode.pl */
a0d0e21e
LW
2648 last_lop_op != OP_ACCEPT &&
2649 last_lop_op != OP_PIPE_OP &&
2650 last_lop_op != OP_SOCKPAIR)
2651 {
2652 warn(
2653 "Bareword \"%s\" not allowed while \"strict subs\" in use",
85e6fe83
LW
2654 tokenbuf);
2655 ++error_count;
2656 }
8990e307
LW
2657
2658 /* Call it a bare word */
2659
748a9306
LW
2660 bareword:
2661 if (dowarn) {
2662 if (lastchar != '-') {
2663 for (d = tokenbuf; *d && isLOWER(*d); d++) ;
2664 if (!*d)
2665 warn(warn_reserved, tokenbuf);
2666 }
2667 }
2668 if (lastchar && strchr("*%&", lastchar)) {
2669 warn("Operator or semicolon missing before %c%s",
2670 lastchar, tokenbuf);
c2960299 2671 warn("Ambiguous use of %c resolved as operator %c",
748a9306
LW
2672 lastchar, lastchar);
2673 }
93a17b20 2674 TOKEN(WORD);
79072805 2675 }
79072805 2676
68dc0745 2677 case KEY___FILE__:
79072805 2678 case KEY___LINE__:
79072805
LW
2679 if (tokenbuf[2] == 'L')
2680 (void)sprintf(tokenbuf,"%ld",(long)curcop->cop_line);
2681 else
463ee0b2 2682 strcpy(tokenbuf, SvPVX(GvSV(curcop->cop_filegv)));
79072805
LW
2683 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf,0));
2684 TERM(THING);
68dc0745 2685
2686 case KEY___PACKAGE__:
2687 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
2688 (curstash
2689 ? newSVsv(curstname)
2690 : &sv_undef));
2691 TERM(THING);
79072805 2692
e50aee73 2693 case KEY___DATA__:
79072805
LW
2694 case KEY___END__: {
2695 GV *gv;
79072805
LW
2696
2697 /*SUPPRESS 560*/
a5f75d66 2698 if (rsfp && (!in_eval || tokenbuf[2] == 'D')) {
e50aee73
AD
2699 char dname[256];
2700 char *pname = "main";
2701 if (tokenbuf[2] == 'D')
2702 pname = HvNAME(curstash ? curstash : defstash);
2703 sprintf(dname,"%s::DATA", pname);
2704 gv = gv_fetchpv(dname,TRUE, SVt_PVIO);
a5f75d66 2705 GvMULTI_on(gv);
79072805 2706 if (!GvIO(gv))
a0d0e21e
LW
2707 GvIOp(gv) = newIO();
2708 IoIFP(GvIOp(gv)) = rsfp;
2709#if defined(HAS_FCNTL) && defined(F_SETFD)
2710 {
760ac839 2711 int fd = PerlIO_fileno(rsfp);
a0d0e21e
LW
2712 fcntl(fd,F_SETFD,fd >= 3);
2713 }
79072805 2714#endif
fd049845 2715 /* Mark this internal pseudo-handle as clean */
2716 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
79072805 2717 if (preprocess)
a0d0e21e 2718 IoTYPE(GvIOp(gv)) = '|';
760ac839 2719 else if ((PerlIO*)rsfp == PerlIO_stdin())
a0d0e21e 2720 IoTYPE(GvIOp(gv)) = '-';
79072805 2721 else
a0d0e21e 2722 IoTYPE(GvIOp(gv)) = '<';
79072805
LW
2723 rsfp = Nullfp;
2724 }
2725 goto fake_eof;
e929a76b 2726 }
de3bb511 2727
8990e307 2728 case KEY_AUTOLOAD:
ed6116ce 2729 case KEY_DESTROY:
79072805
LW
2730 case KEY_BEGIN:
2731 case KEY_END:
a0d0e21e 2732 if (expect == XSTATE) {
93a17b20
LW
2733 s = bufptr;
2734 goto really_sub;
79072805
LW
2735 }
2736 goto just_a_word;
2737
a0d0e21e
LW
2738 case KEY_CORE:
2739 if (*s == ':' && s[1] == ':') {
2740 s += 2;
748a9306 2741 d = s;
a0d0e21e
LW
2742 s = scan_word(s, tokenbuf, FALSE, &len);
2743 tmp = keyword(tokenbuf, len);
2744 if (tmp < 0)
2745 tmp = -tmp;
2746 goto reserved_word;
2747 }
2748 goto just_a_word;
2749
463ee0b2
LW
2750 case KEY_abs:
2751 UNI(OP_ABS);
2752
79072805
LW
2753 case KEY_alarm:
2754 UNI(OP_ALARM);
2755
2756 case KEY_accept:
a0d0e21e 2757 LOP(OP_ACCEPT,XTERM);
79072805 2758
463ee0b2
LW
2759 case KEY_and:
2760 OPERATOR(ANDOP);
2761
79072805 2762 case KEY_atan2:
a0d0e21e 2763 LOP(OP_ATAN2,XTERM);
85e6fe83 2764
79072805 2765 case KEY_bind:
a0d0e21e 2766 LOP(OP_BIND,XTERM);
79072805
LW
2767
2768 case KEY_binmode:
2769 UNI(OP_BINMODE);
2770
2771 case KEY_bless:
a0d0e21e 2772 LOP(OP_BLESS,XTERM);
79072805
LW
2773
2774 case KEY_chop:
2775 UNI(OP_CHOP);
2776
2777 case KEY_continue:
2778 PREBLOCK(CONTINUE);
2779
2780 case KEY_chdir:
85e6fe83 2781 (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */
79072805
LW
2782 UNI(OP_CHDIR);
2783
2784 case KEY_close:
2785 UNI(OP_CLOSE);
2786
2787 case KEY_closedir:
2788 UNI(OP_CLOSEDIR);
2789
2790 case KEY_cmp:
2791 Eop(OP_SCMP);
2792
2793 case KEY_caller:
2794 UNI(OP_CALLER);
2795
2796 case KEY_crypt:
2797#ifdef FCRYPT
de3bb511
LW
2798 if (!cryptseen++)
2799 init_des();
a687059c 2800#endif
a0d0e21e 2801 LOP(OP_CRYPT,XTERM);
79072805
LW
2802
2803 case KEY_chmod:
748a9306
LW
2804 if (dowarn) {
2805 for (d = s; d < bufend && (isSPACE(*d) || *d == '('); d++) ;
2806 if (*d != '0' && isDIGIT(*d))
2807 yywarn("chmod: mode argument is missing initial 0");
2808 }
a0d0e21e 2809 LOP(OP_CHMOD,XTERM);
79072805
LW
2810
2811 case KEY_chown:
a0d0e21e 2812 LOP(OP_CHOWN,XTERM);
79072805
LW
2813
2814 case KEY_connect:
a0d0e21e 2815 LOP(OP_CONNECT,XTERM);
79072805 2816
463ee0b2
LW
2817 case KEY_chr:
2818 UNI(OP_CHR);
2819
79072805
LW
2820 case KEY_cos:
2821 UNI(OP_COS);
2822
2823 case KEY_chroot:
2824 UNI(OP_CHROOT);
2825
2826 case KEY_do:
2827 s = skipspace(s);
2828 if (*s == '{')
a0d0e21e 2829 PRETERMBLOCK(DO);
79072805 2830 if (*s != '\'')
a0d0e21e 2831 s = force_word(s,WORD,FALSE,TRUE,FALSE);
378cc40b 2832 OPERATOR(DO);
79072805
LW
2833
2834 case KEY_die:
a0d0e21e
LW
2835 hints |= HINT_BLOCK_SCOPE;
2836 LOP(OP_DIE,XTERM);
79072805
LW
2837
2838 case KEY_defined:
2839 UNI(OP_DEFINED);
2840
2841 case KEY_delete:
a0d0e21e 2842 UNI(OP_DELETE);
79072805
LW
2843
2844 case KEY_dbmopen:
a0d0e21e
LW
2845 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
2846 LOP(OP_DBMOPEN,XTERM);
79072805
LW
2847
2848 case KEY_dbmclose:
2849 UNI(OP_DBMCLOSE);
2850
2851 case KEY_dump:
a0d0e21e 2852 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
2853 LOOPX(OP_DUMP);
2854
2855 case KEY_else:
2856 PREBLOCK(ELSE);
2857
2858 case KEY_elsif:
2859 yylval.ival = curcop->cop_line;
2860 OPERATOR(ELSIF);
2861
2862 case KEY_eq:
2863 Eop(OP_SEQ);
2864
a0d0e21e
LW
2865 case KEY_exists:
2866 UNI(OP_EXISTS);
2867
79072805
LW
2868 case KEY_exit:
2869 UNI(OP_EXIT);
2870
2871 case KEY_eval:
79072805 2872 s = skipspace(s);
a0d0e21e 2873 expect = (*s == '{') ? XTERMBLOCK : XTERM;
463ee0b2 2874 UNIBRACK(OP_ENTEREVAL);
79072805
LW
2875
2876 case KEY_eof:
2877 UNI(OP_EOF);
2878
2879 case KEY_exp:
2880 UNI(OP_EXP);
2881
2882 case KEY_each:
2883 UNI(OP_EACH);
2884
2885 case KEY_exec:
2886 set_csh();
a0d0e21e 2887 LOP(OP_EXEC,XREF);
79072805
LW
2888
2889 case KEY_endhostent:
2890 FUN0(OP_EHOSTENT);
2891
2892 case KEY_endnetent:
2893 FUN0(OP_ENETENT);
2894
2895 case KEY_endservent:
2896 FUN0(OP_ESERVENT);
2897
2898 case KEY_endprotoent:
2899 FUN0(OP_EPROTOENT);
2900
2901 case KEY_endpwent:
2902 FUN0(OP_EPWENT);
2903
2904 case KEY_endgrent:
2905 FUN0(OP_EGRENT);
2906
2907 case KEY_for:
2908 case KEY_foreach:
2909 yylval.ival = curcop->cop_line;
55497cff 2910 s = skipspace(s);
2911 if (isIDFIRST(*s)) {
2912 char *p = s;
2913 if ((bufend - p) >= 3 &&
2914 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
2915 p += 2;
2916 p = skipspace(p);
2917 if (isIDFIRST(*p))
2918 croak("Missing $ on loop variable");
2919 }
79072805
LW
2920 OPERATOR(FOR);
2921
2922 case KEY_formline:
a0d0e21e 2923 LOP(OP_FORMLINE,XTERM);
79072805
LW
2924
2925 case KEY_fork:
2926 FUN0(OP_FORK);
2927
2928 case KEY_fcntl:
a0d0e21e 2929 LOP(OP_FCNTL,XTERM);
79072805
LW
2930
2931 case KEY_fileno:
2932 UNI(OP_FILENO);
2933
2934 case KEY_flock:
a0d0e21e 2935 LOP(OP_FLOCK,XTERM);
79072805
LW
2936
2937 case KEY_gt:
2938 Rop(OP_SGT);
2939
2940 case KEY_ge:
2941 Rop(OP_SGE);
2942
2943 case KEY_grep:
a0d0e21e 2944 LOP(OP_GREPSTART, *s == '(' ? XTERM : XREF);
79072805
LW
2945
2946 case KEY_goto:
a0d0e21e 2947 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
2948 LOOPX(OP_GOTO);
2949
2950 case KEY_gmtime:
2951 UNI(OP_GMTIME);
2952
2953 case KEY_getc:
2954 UNI(OP_GETC);
2955
2956 case KEY_getppid:
2957 FUN0(OP_GETPPID);
2958
2959 case KEY_getpgrp:
2960 UNI(OP_GETPGRP);
2961
2962 case KEY_getpriority:
a0d0e21e 2963 LOP(OP_GETPRIORITY,XTERM);
79072805
LW
2964
2965 case KEY_getprotobyname:
2966 UNI(OP_GPBYNAME);
2967
2968 case KEY_getprotobynumber:
a0d0e21e 2969 LOP(OP_GPBYNUMBER,XTERM);
79072805
LW
2970
2971 case KEY_getprotoent:
2972 FUN0(OP_GPROTOENT);
2973
2974 case KEY_getpwent:
2975 FUN0(OP_GPWENT);
2976
2977 case KEY_getpwnam:
ff68c719 2978 UNI(OP_GPWNAM);
79072805
LW
2979
2980 case KEY_getpwuid:
ff68c719 2981 UNI(OP_GPWUID);
79072805
LW
2982
2983 case KEY_getpeername:
2984 UNI(OP_GETPEERNAME);
2985
2986 case KEY_gethostbyname:
2987 UNI(OP_GHBYNAME);
2988
2989 case KEY_gethostbyaddr:
a0d0e21e 2990 LOP(OP_GHBYADDR,XTERM);
79072805
LW
2991
2992 case KEY_gethostent:
2993 FUN0(OP_GHOSTENT);
2994
2995 case KEY_getnetbyname:
2996 UNI(OP_GNBYNAME);
2997
2998 case KEY_getnetbyaddr:
a0d0e21e 2999 LOP(OP_GNBYADDR,XTERM);
79072805
LW
3000
3001 case KEY_getnetent:
3002 FUN0(OP_GNETENT);
3003
3004 case KEY_getservbyname:
a0d0e21e 3005 LOP(OP_GSBYNAME,XTERM);
79072805
LW
3006
3007 case KEY_getservbyport:
a0d0e21e 3008 LOP(OP_GSBYPORT,XTERM);
79072805
LW
3009
3010 case KEY_getservent:
3011 FUN0(OP_GSERVENT);
3012
3013 case KEY_getsockname:
3014 UNI(OP_GETSOCKNAME);
3015
3016 case KEY_getsockopt:
a0d0e21e 3017 LOP(OP_GSOCKOPT,XTERM);
79072805
LW
3018
3019 case KEY_getgrent:
3020 FUN0(OP_GGRENT);
3021
3022 case KEY_getgrnam:
ff68c719 3023 UNI(OP_GGRNAM);
79072805
LW
3024
3025 case KEY_getgrgid:
ff68c719 3026 UNI(OP_GGRGID);
79072805
LW
3027
3028 case KEY_getlogin:
3029 FUN0(OP_GETLOGIN);
3030
93a17b20 3031 case KEY_glob:
a0d0e21e
LW
3032 set_csh();
3033 LOP(OP_GLOB,XTERM);
93a17b20 3034
79072805
LW
3035 case KEY_hex:
3036 UNI(OP_HEX);
3037
3038 case KEY_if:
3039 yylval.ival = curcop->cop_line;
71be2cbc 3040 OPERATOR(IF);
79072805
LW
3041
3042 case KEY_index:
a0d0e21e 3043 LOP(OP_INDEX,XTERM);
79072805
LW
3044
3045 case KEY_int:
3046 UNI(OP_INT);
3047
3048 case KEY_ioctl:
a0d0e21e 3049 LOP(OP_IOCTL,XTERM);
79072805
LW
3050
3051 case KEY_join:
a0d0e21e 3052 LOP(OP_JOIN,XTERM);
79072805
LW
3053
3054 case KEY_keys:
3055 UNI(OP_KEYS);
3056
3057 case KEY_kill:
a0d0e21e 3058 LOP(OP_KILL,XTERM);
79072805
LW
3059
3060 case KEY_last:
a0d0e21e 3061 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805 3062 LOOPX(OP_LAST);
a0d0e21e 3063
79072805
LW
3064 case KEY_lc:
3065 UNI(OP_LC);
3066
3067 case KEY_lcfirst:
3068 UNI(OP_LCFIRST);
3069
3070 case KEY_local:
3071 OPERATOR(LOCAL);
3072
3073 case KEY_length:
3074 UNI(OP_LENGTH);
3075
3076 case KEY_lt:
3077 Rop(OP_SLT);
3078
3079 case KEY_le:
3080 Rop(OP_SLE);
3081
3082 case KEY_localtime:
3083 UNI(OP_LOCALTIME);
3084
3085 case KEY_log:
3086 UNI(OP_LOG);
3087
3088 case KEY_link:
a0d0e21e 3089 LOP(OP_LINK,XTERM);
79072805
LW
3090
3091 case KEY_listen:
a0d0e21e 3092 LOP(OP_LISTEN,XTERM);
79072805
LW
3093
3094 case KEY_lstat:
3095 UNI(OP_LSTAT);
3096
3097 case KEY_m:
3098 s = scan_pat(s);
3099 TERM(sublex_start());
3100
a0d0e21e
LW
3101 case KEY_map:
3102 LOP(OP_MAPSTART,XREF);
3103
79072805 3104 case KEY_mkdir:
a0d0e21e 3105 LOP(OP_MKDIR,XTERM);
79072805
LW
3106
3107 case KEY_msgctl:
a0d0e21e 3108 LOP(OP_MSGCTL,XTERM);
79072805
LW
3109
3110 case KEY_msgget:
a0d0e21e 3111 LOP(OP_MSGGET,XTERM);
79072805
LW
3112
3113 case KEY_msgrcv:
a0d0e21e 3114 LOP(OP_MSGRCV,XTERM);
79072805
LW
3115
3116 case KEY_msgsnd:
a0d0e21e 3117 LOP(OP_MSGSND,XTERM);
79072805 3118
93a17b20
LW
3119 case KEY_my:
3120 in_my = TRUE;
55497cff 3121 OPERATOR(MY);
93a17b20 3122
79072805 3123 case KEY_next:
a0d0e21e 3124 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
3125 LOOPX(OP_NEXT);
3126
3127 case KEY_ne:
3128 Eop(OP_SNE);
3129
a0d0e21e
LW
3130 case KEY_no:
3131 if (expect != XSTATE)
3132 yyerror("\"no\" not allowed in expression");
3133 s = force_word(s,WORD,FALSE,TRUE,FALSE);
89bfa8cd 3134 s = force_version(s);
a0d0e21e
LW
3135 yylval.ival = 0;
3136 OPERATOR(USE);
3137
3138 case KEY_not:
3139 OPERATOR(NOTOP);
3140
79072805 3141 case KEY_open:
93a17b20
LW
3142 s = skipspace(s);
3143 if (isIDFIRST(*s)) {
3144 char *t;
3145 for (d = s; isALNUM(*d); d++) ;
3146 t = skipspace(d);
3147 if (strchr("|&*+-=!?:.", *t))
3148 warn("Precedence problem: open %.*s should be open(%.*s)",
3149 d-s,s, d-s,s);
3150 }
a0d0e21e 3151 LOP(OP_OPEN,XTERM);
79072805 3152
463ee0b2 3153 case KEY_or:
a0d0e21e 3154 yylval.ival = OP_OR;
463ee0b2
LW
3155 OPERATOR(OROP);
3156
79072805
LW
3157 case KEY_ord:
3158 UNI(OP_ORD);
3159
3160 case KEY_oct:
3161 UNI(OP_OCT);
3162
3163 case KEY_opendir:
a0d0e21e 3164 LOP(OP_OPEN_DIR,XTERM);
79072805
LW
3165
3166 case KEY_print:
3167 checkcomma(s,tokenbuf,"filehandle");
a0d0e21e 3168 LOP(OP_PRINT,XREF);
79072805
LW
3169
3170 case KEY_printf:
3171 checkcomma(s,tokenbuf,"filehandle");
a0d0e21e 3172 LOP(OP_PRTF,XREF);
79072805 3173
c07a80fd 3174 case KEY_prototype:
3175 UNI(OP_PROTOTYPE);
3176
79072805 3177 case KEY_push:
a0d0e21e 3178 LOP(OP_PUSH,XTERM);
79072805
LW
3179
3180 case KEY_pop:
3181 UNI(OP_POP);
3182
a0d0e21e
LW
3183 case KEY_pos:
3184 UNI(OP_POS);
3185
79072805 3186 case KEY_pack:
a0d0e21e 3187 LOP(OP_PACK,XTERM);
79072805
LW
3188
3189 case KEY_package:
a0d0e21e 3190 s = force_word(s,WORD,FALSE,TRUE,FALSE);
79072805
LW
3191 OPERATOR(PACKAGE);
3192
3193 case KEY_pipe:
a0d0e21e 3194 LOP(OP_PIPE_OP,XTERM);
79072805
LW
3195
3196 case KEY_q:
3197 s = scan_str(s);
3198 if (!s)
85e6fe83 3199 missingterm((char*)0);
79072805
LW
3200 yylval.ival = OP_CONST;
3201 TERM(sublex_start());
3202
a0d0e21e
LW
3203 case KEY_quotemeta:
3204 UNI(OP_QUOTEMETA);
3205
8990e307
LW
3206 case KEY_qw:
3207 s = scan_str(s);
3208 if (!s)
85e6fe83 3209 missingterm((char*)0);
55497cff 3210 if (dowarn && SvLEN(lex_stuff)) {
3211 d = SvPV_force(lex_stuff, len);
3212 for (; len; --len, ++d) {
3213 if (*d == ',') {
3214 warn("Possible attempt to separate words with commas");
3215 break;
3216 }
3217 if (*d == '#') {
3218 warn("Possible attempt to put comments in qw() list");
3219 break;
3220 }
3221 }
3222 }
8990e307
LW
3223 force_next(')');
3224 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, q(lex_stuff));
3225 lex_stuff = Nullsv;
3226 force_next(THING);
3227 force_next(',');
3228 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(" ",1));
3229 force_next(THING);
3230 force_next('(');
a0d0e21e
LW
3231 yylval.ival = OP_SPLIT;
3232 CLINE;
3233 expect = XTERM;
3234 bufptr = s;
3235 last_lop = oldbufptr;
3236 last_lop_op = OP_SPLIT;
3237 return FUNC;
8990e307 3238
79072805
LW
3239 case KEY_qq:
3240 s = scan_str(s);
3241 if (!s)
85e6fe83 3242 missingterm((char*)0);
a0d0e21e 3243 yylval.ival = OP_STRINGIFY;
ed6116ce
LW
3244 if (SvIVX(lex_stuff) == '\'')
3245 SvIVX(lex_stuff) = 0; /* qq'$foo' should intepolate */
79072805
LW
3246 TERM(sublex_start());
3247
3248 case KEY_qx:
3249 s = scan_str(s);
3250 if (!s)
85e6fe83 3251 missingterm((char*)0);
79072805
LW
3252 yylval.ival = OP_BACKTICK;
3253 set_csh();
3254 TERM(sublex_start());
3255
3256 case KEY_return:
3257 OLDLOP(OP_RETURN);
3258
3259 case KEY_require:
748a9306 3260 *tokenbuf = '\0';
a0d0e21e 3261 s = force_word(s,WORD,TRUE,TRUE,FALSE);
748a9306 3262 if (isIDFIRST(*tokenbuf))
89bfa8cd 3263 gv_stashpvn(tokenbuf, strlen(tokenbuf), TRUE);
748a9306 3264 else if (*s == '<')
a0d0e21e 3265 yyerror("<> should be quotes");
463ee0b2 3266 UNI(OP_REQUIRE);
79072805
LW
3267
3268 case KEY_reset:
3269 UNI(OP_RESET);
3270
3271 case KEY_redo:
a0d0e21e 3272 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
3273 LOOPX(OP_REDO);
3274
3275 case KEY_rename:
a0d0e21e 3276 LOP(OP_RENAME,XTERM);
79072805
LW
3277
3278 case KEY_rand:
3279 UNI(OP_RAND);
3280
3281 case KEY_rmdir:
3282 UNI(OP_RMDIR);
3283
3284 case KEY_rindex:
a0d0e21e 3285 LOP(OP_RINDEX,XTERM);
79072805
LW
3286
3287 case KEY_read:
a0d0e21e 3288 LOP(OP_READ,XTERM);
79072805
LW
3289
3290 case KEY_readdir:
3291 UNI(OP_READDIR);
3292
93a17b20
LW
3293 case KEY_readline:
3294 set_csh();
3295 UNI(OP_READLINE);
3296
3297 case KEY_readpipe:
3298 set_csh();
3299 UNI(OP_BACKTICK);
3300
79072805
LW
3301 case KEY_rewinddir:
3302 UNI(OP_REWINDDIR);
3303
3304 case KEY_recv:
a0d0e21e 3305 LOP(OP_RECV,XTERM);
79072805
LW
3306
3307 case KEY_reverse:
a0d0e21e 3308 LOP(OP_REVERSE,XTERM);
79072805
LW
3309
3310 case KEY_readlink:
3311 UNI(OP_READLINK);
3312
3313 case KEY_ref:
3314 UNI(OP_REF);
3315
3316 case KEY_s:
3317 s = scan_subst(s);
3318 if (yylval.opval)
3319 TERM(sublex_start());
3320 else
3321 TOKEN(1); /* force error */
3322
a0d0e21e
LW
3323 case KEY_chomp:
3324 UNI(OP_CHOMP);
3325
79072805
LW
3326 case KEY_scalar:
3327 UNI(OP_SCALAR);
3328
3329 case KEY_select:
a0d0e21e 3330 LOP(OP_SELECT,XTERM);
79072805
LW
3331
3332 case KEY_seek:
a0d0e21e 3333 LOP(OP_SEEK,XTERM);
79072805
LW
3334
3335 case KEY_semctl:
a0d0e21e 3336 LOP(OP_SEMCTL,XTERM);
79072805
LW
3337
3338 case KEY_semget:
a0d0e21e 3339 LOP(OP_SEMGET,XTERM);
79072805
LW
3340
3341 case KEY_semop:
a0d0e21e 3342 LOP(OP_SEMOP,XTERM);
79072805
LW
3343
3344 case KEY_send:
a0d0e21e 3345 LOP(OP_SEND,XTERM);
79072805
LW
3346
3347 case KEY_setpgrp:
a0d0e21e 3348 LOP(OP_SETPGRP,XTERM);
79072805
LW
3349
3350 case KEY_setpriority:
a0d0e21e 3351 LOP(OP_SETPRIORITY,XTERM);
79072805
LW
3352
3353 case KEY_sethostent:
ff68c719 3354 UNI(OP_SHOSTENT);
79072805
LW
3355
3356 case KEY_setnetent:
ff68c719 3357 UNI(OP_SNETENT);
79072805
LW
3358
3359 case KEY_setservent:
ff68c719 3360 UNI(OP_SSERVENT);
79072805
LW
3361
3362 case KEY_setprotoent:
ff68c719 3363 UNI(OP_SPROTOENT);
79072805
LW
3364
3365 case KEY_setpwent:
3366 FUN0(OP_SPWENT);
3367
3368 case KEY_setgrent:
3369 FUN0(OP_SGRENT);
3370
3371 case KEY_seekdir:
a0d0e21e 3372 LOP(OP_SEEKDIR,XTERM);
79072805
LW
3373
3374 case KEY_setsockopt:
a0d0e21e 3375 LOP(OP_SSOCKOPT,XTERM);
79072805
LW
3376
3377 case KEY_shift:
3378 UNI(OP_SHIFT);
3379
3380 case KEY_shmctl:
a0d0e21e 3381 LOP(OP_SHMCTL,XTERM);
79072805
LW
3382
3383 case KEY_shmget:
a0d0e21e 3384 LOP(OP_SHMGET,XTERM);
79072805
LW
3385
3386 case KEY_shmread:
a0d0e21e 3387 LOP(OP_SHMREAD,XTERM);
79072805
LW
3388
3389 case KEY_shmwrite:
a0d0e21e 3390 LOP(OP_SHMWRITE,XTERM);
79072805
LW
3391
3392 case KEY_shutdown:
a0d0e21e 3393 LOP(OP_SHUTDOWN,XTERM);
79072805
LW
3394
3395 case KEY_sin:
3396 UNI(OP_SIN);
3397
3398 case KEY_sleep:
3399 UNI(OP_SLEEP);
3400
3401 case KEY_socket:
a0d0e21e 3402 LOP(OP_SOCKET,XTERM);
79072805
LW
3403
3404 case KEY_socketpair:
a0d0e21e 3405 LOP(OP_SOCKPAIR,XTERM);
79072805
LW
3406
3407 case KEY_sort:
3408 checkcomma(s,tokenbuf,"subroutine name");
3409 s = skipspace(s);
3410 if (*s == ';' || *s == ')') /* probably a close */
463ee0b2
LW
3411 croak("sort is now a reserved word");
3412 expect = XTERM;
a0d0e21e
LW
3413 s = force_word(s,WORD,TRUE,TRUE,TRUE);
3414 LOP(OP_SORT,XREF);
79072805
LW
3415
3416 case KEY_split:
a0d0e21e 3417 LOP(OP_SPLIT,XTERM);
79072805
LW
3418
3419 case KEY_sprintf:
a0d0e21e 3420 LOP(OP_SPRINTF,XTERM);
79072805
LW
3421
3422 case KEY_splice:
a0d0e21e 3423 LOP(OP_SPLICE,XTERM);
79072805
LW
3424
3425 case KEY_sqrt:
3426 UNI(OP_SQRT);
3427
3428 case KEY_srand:
3429 UNI(OP_SRAND);
3430
3431 case KEY_stat:
3432 UNI(OP_STAT);
3433
3434 case KEY_study:
3435 sawstudy++;
3436 UNI(OP_STUDY);
3437
3438 case KEY_substr:
a0d0e21e 3439 LOP(OP_SUBSTR,XTERM);
79072805
LW
3440
3441 case KEY_format:
3442 case KEY_sub:
93a17b20 3443 really_sub:
79072805 3444 s = skipspace(s);
4633a7c4 3445
463ee0b2
LW
3446 if (isIDFIRST(*s) || *s == '\'' || *s == ':') {
3447 char tmpbuf[128];
4633a7c4 3448 expect = XBLOCK;
463ee0b2
LW
3449 d = scan_word(s, tmpbuf, TRUE, &len);
3450 if (strchr(tmpbuf, ':'))
3451 sv_setpv(subname, tmpbuf);
3452 else {
3453 sv_setsv(subname,curstname);
8990e307 3454 sv_catpvn(subname,"::",2);
463ee0b2
LW
3455 sv_catpvn(subname,tmpbuf,len);
3456 }
a0d0e21e 3457 s = force_word(s,WORD,FALSE,TRUE,TRUE);
4633a7c4 3458 s = skipspace(s);
79072805 3459 }
4633a7c4
LW
3460 else {
3461 expect = XTERMBLOCK;
79072805 3462 sv_setpv(subname,"?");
4633a7c4
LW
3463 }
3464
3465 if (tmp == KEY_format) {
3466 s = skipspace(s);
3467 if (*s == '=')
3468 lex_formbrack = lex_brackets + 1;
3469 OPERATOR(FORMAT);
3470 }
79072805 3471
4633a7c4
LW
3472 /* Look for a prototype */
3473 if (*s == '(') {
68dc0745 3474 char *p;
3475
4633a7c4
LW
3476 s = scan_str(s);
3477 if (!s) {
3478 if (lex_stuff)
3479 SvREFCNT_dec(lex_stuff);
3480 lex_stuff = Nullsv;
3481 croak("Prototype not terminated");
3482 }
68dc0745 3483 /* strip spaces */
3484 d = SvPVX(lex_stuff);
3485 tmp = 0;
3486 for (p = d; *p; ++p) {
3487 if (!isSPACE(*p))
3488 d[tmp++] = *p;
3489 }
3490 d[tmp] = '\0';
3491 SvCUR(lex_stuff) = tmp;
3492
4633a7c4
LW
3493 nexttoke++;
3494 nextval[1] = nextval[0];
3495 nexttype[1] = nexttype[0];
3496 nextval[0].opval = (OP*)newSVOP(OP_CONST, 0, lex_stuff);
3497 nexttype[0] = THING;
3498 if (nexttoke == 1) {
3499 lex_defer = lex_state;
3500 lex_expect = expect;
3501 lex_state = LEX_KNOWNEXT;
3502 }
3503 lex_stuff = Nullsv;
3504 }
79072805 3505
4633a7c4
LW
3506 if (*SvPV(subname,na) == '?') {
3507 sv_setpv(subname,"__ANON__");
3508 TOKEN(ANONSUB);
3509 }
3510 PREBLOCK(SUB);
79072805
LW
3511
3512 case KEY_system:
3513 set_csh();
a0d0e21e 3514 LOP(OP_SYSTEM,XREF);
79072805
LW
3515
3516 case KEY_symlink:
a0d0e21e 3517 LOP(OP_SYMLINK,XTERM);
79072805
LW
3518
3519 case KEY_syscall:
a0d0e21e 3520 LOP(OP_SYSCALL,XTERM);
79072805 3521
c07a80fd 3522 case KEY_sysopen:
3523 LOP(OP_SYSOPEN,XTERM);
3524
79072805 3525 case KEY_sysread:
a0d0e21e 3526 LOP(OP_SYSREAD,XTERM);
79072805
LW
3527
3528 case KEY_syswrite:
a0d0e21e 3529 LOP(OP_SYSWRITE,XTERM);
79072805
LW
3530
3531 case KEY_tr:
3532 s = scan_trans(s);
3533 TERM(sublex_start());
3534
3535 case KEY_tell:
3536 UNI(OP_TELL);
3537
3538 case KEY_telldir:
3539 UNI(OP_TELLDIR);
3540
463ee0b2 3541 case KEY_tie:
a0d0e21e 3542 LOP(OP_TIE,XTERM);
463ee0b2 3543
c07a80fd 3544 case KEY_tied:
3545 UNI(OP_TIED);
3546
79072805
LW
3547 case KEY_time:
3548 FUN0(OP_TIME);
3549
3550 case KEY_times:
3551 FUN0(OP_TMS);
3552
3553 case KEY_truncate:
a0d0e21e 3554 LOP(OP_TRUNCATE,XTERM);
79072805
LW
3555
3556 case KEY_uc:
3557 UNI(OP_UC);
3558
3559 case KEY_ucfirst:
3560 UNI(OP_UCFIRST);
3561
463ee0b2
LW
3562 case KEY_untie:
3563 UNI(OP_UNTIE);
3564
79072805
LW
3565 case KEY_until:
3566 yylval.ival = curcop->cop_line;
71be2cbc 3567 OPERATOR(UNTIL);
79072805
LW
3568
3569 case KEY_unless:
3570 yylval.ival = curcop->cop_line;
71be2cbc 3571 OPERATOR(UNLESS);
79072805
LW
3572
3573 case KEY_unlink:
a0d0e21e 3574 LOP(OP_UNLINK,XTERM);
79072805
LW
3575
3576 case KEY_undef:
3577 UNI(OP_UNDEF);
3578
3579 case KEY_unpack:
a0d0e21e 3580 LOP(OP_UNPACK,XTERM);
79072805
LW
3581
3582 case KEY_utime:
a0d0e21e 3583 LOP(OP_UTIME,XTERM);
79072805
LW
3584
3585 case KEY_umask:
748a9306
LW
3586 if (dowarn) {
3587 for (d = s; d < bufend && (isSPACE(*d) || *d == '('); d++) ;
3588 if (*d != '0' && isDIGIT(*d))
3589 yywarn("umask: argument is missing initial 0");
3590 }
79072805
LW
3591 UNI(OP_UMASK);
3592
3593 case KEY_unshift:
a0d0e21e
LW
3594 LOP(OP_UNSHIFT,XTERM);
3595
3596 case KEY_use:
3597 if (expect != XSTATE)
3598 yyerror("\"use\" not allowed in expression");
89bfa8cd 3599 s = skipspace(s);
3600 if(isDIGIT(*s)) {
3601 s = force_version(s);
3602 if(*s == ';' || (s = skipspace(s), *s == ';')) {
3603 nextval[nexttoke].opval = Nullop;
3604 force_next(WORD);
3605 }
3606 }
3607 else {
3608 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3609 s = force_version(s);
3610 }
a0d0e21e
LW
3611 yylval.ival = 1;
3612 OPERATOR(USE);
79072805
LW
3613
3614 case KEY_values:
3615 UNI(OP_VALUES);
3616
3617 case KEY_vec:
3618 sawvec = TRUE;
a0d0e21e 3619 LOP(OP_VEC,XTERM);
79072805
LW
3620
3621 case KEY_while:
3622 yylval.ival = curcop->cop_line;
71be2cbc 3623 OPERATOR(WHILE);
79072805
LW
3624
3625 case KEY_warn:
a0d0e21e
LW
3626 hints |= HINT_BLOCK_SCOPE;
3627 LOP(OP_WARN,XTERM);
79072805
LW
3628
3629 case KEY_wait:
3630 FUN0(OP_WAIT);
3631
3632 case KEY_waitpid:
a0d0e21e 3633 LOP(OP_WAITPID,XTERM);
79072805
LW
3634
3635 case KEY_wantarray:
3636 FUN0(OP_WANTARRAY);
3637
3638 case KEY_write:
85e6fe83 3639 gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */
79072805
LW
3640 UNI(OP_ENTERWRITE);
3641
3642 case KEY_x:
3643 if (expect == XOPERATOR)
3644 Mop(OP_REPEAT);
3645 check_uni();
3646 goto just_a_word;
3647
a0d0e21e
LW
3648 case KEY_xor:
3649 yylval.ival = OP_XOR;
3650 OPERATOR(OROP);
3651
79072805
LW
3652 case KEY_y:
3653 s = scan_trans(s);
3654 TERM(sublex_start());
3655 }
3656 }
3657}
3658
3659I32
3660keyword(d, len)
3661register char *d;
3662I32 len;
3663{
3664 switch (*d) {
3665 case '_':
3666 if (d[1] == '_') {
a0d0e21e 3667 if (strEQ(d,"__FILE__")) return -KEY___FILE__;
68dc0745 3668 if (strEQ(d,"__LINE__")) return -KEY___LINE__;
3669 if (strEQ(d,"__PACKAGE__")) return -KEY___PACKAGE__;
e50aee73 3670 if (strEQ(d,"__DATA__")) return KEY___DATA__;
79072805
LW
3671 if (strEQ(d,"__END__")) return KEY___END__;
3672 }
3673 break;
8990e307
LW
3674 case 'A':
3675 if (strEQ(d,"AUTOLOAD")) return KEY_AUTOLOAD;
3676 break;
79072805 3677 case 'a':
463ee0b2
LW
3678 switch (len) {
3679 case 3:
a0d0e21e
LW
3680 if (strEQ(d,"and")) return -KEY_and;
3681 if (strEQ(d,"abs")) return -KEY_abs;
85e6fe83 3682 break;
463ee0b2 3683 case 5:
a0d0e21e
LW
3684 if (strEQ(d,"alarm")) return -KEY_alarm;
3685 if (strEQ(d,"atan2")) return -KEY_atan2;
463ee0b2
LW
3686 break;
3687 case 6:
a0d0e21e 3688 if (strEQ(d,"accept")) return -KEY_accept;
463ee0b2
LW
3689 break;
3690 }
79072805
LW
3691 break;
3692 case 'B':
3693 if (strEQ(d,"BEGIN")) return KEY_BEGIN;
93a17b20 3694 break;
79072805 3695 case 'b':
a0d0e21e
LW
3696 if (strEQ(d,"bless")) return -KEY_bless;
3697 if (strEQ(d,"bind")) return -KEY_bind;
3698 if (strEQ(d,"binmode")) return -KEY_binmode;
3699 break;
3700 case 'C':
3701 if (strEQ(d,"CORE")) return -KEY_CORE;
79072805
LW
3702 break;
3703 case 'c':
3704 switch (len) {
3705 case 3:
a0d0e21e
LW
3706 if (strEQ(d,"cmp")) return -KEY_cmp;
3707 if (strEQ(d,"chr")) return -KEY_chr;
3708 if (strEQ(d,"cos")) return -KEY_cos;
79072805
LW
3709 break;
3710 case 4:
3711 if (strEQ(d,"chop")) return KEY_chop;
3712 break;
3713 case 5:
a0d0e21e
LW
3714 if (strEQ(d,"close")) return -KEY_close;
3715 if (strEQ(d,"chdir")) return -KEY_chdir;
3716 if (strEQ(d,"chomp")) return KEY_chomp;
3717 if (strEQ(d,"chmod")) return -KEY_chmod;
3718 if (strEQ(d,"chown")) return -KEY_chown;
3719 if (strEQ(d,"crypt")) return -KEY_crypt;
79072805
LW
3720 break;
3721 case 6:
a0d0e21e
LW
3722 if (strEQ(d,"chroot")) return -KEY_chroot;
3723 if (strEQ(d,"caller")) return -KEY_caller;
79072805
LW
3724 break;
3725 case 7:
a0d0e21e 3726 if (strEQ(d,"connect")) return -KEY_connect;
79072805
LW
3727 break;
3728 case 8:
a0d0e21e
LW
3729 if (strEQ(d,"closedir")) return -KEY_closedir;
3730 if (strEQ(d,"continue")) return -KEY_continue;
79072805
LW
3731 break;
3732 }
3733 break;
ed6116ce
LW
3734 case 'D':
3735 if (strEQ(d,"DESTROY")) return KEY_DESTROY;
3736 break;
79072805
LW
3737 case 'd':
3738 switch (len) {
3739 case 2:
3740 if (strEQ(d,"do")) return KEY_do;
3741 break;
3742 case 3:
a0d0e21e 3743 if (strEQ(d,"die")) return -KEY_die;
79072805
LW
3744 break;
3745 case 4:
a0d0e21e 3746 if (strEQ(d,"dump")) return -KEY_dump;
79072805
LW
3747 break;
3748 case 6:
3749 if (strEQ(d,"delete")) return KEY_delete;
3750 break;
3751 case 7:
3752 if (strEQ(d,"defined")) return KEY_defined;
a0d0e21e 3753 if (strEQ(d,"dbmopen")) return -KEY_dbmopen;
79072805
LW
3754 break;
3755 case 8:
a0d0e21e 3756 if (strEQ(d,"dbmclose")) return -KEY_dbmclose;
79072805
LW
3757 break;
3758 }
3759 break;
3760 case 'E':
a0d0e21e 3761 if (strEQ(d,"EQ")) { deprecate(d); return -KEY_eq;}
79072805
LW
3762 if (strEQ(d,"END")) return KEY_END;
3763 break;
3764 case 'e':
3765 switch (len) {
3766 case 2:
a0d0e21e 3767 if (strEQ(d,"eq")) return -KEY_eq;
79072805
LW
3768 break;
3769 case 3:
a0d0e21e
LW
3770 if (strEQ(d,"eof")) return -KEY_eof;
3771 if (strEQ(d,"exp")) return -KEY_exp;
79072805
LW
3772 break;
3773 case 4:
3774 if (strEQ(d,"else")) return KEY_else;
a0d0e21e 3775 if (strEQ(d,"exit")) return -KEY_exit;
79072805 3776 if (strEQ(d,"eval")) return KEY_eval;
a0d0e21e 3777 if (strEQ(d,"exec")) return -KEY_exec;
79072805
LW
3778 if (strEQ(d,"each")) return KEY_each;
3779 break;
3780 case 5:
3781 if (strEQ(d,"elsif")) return KEY_elsif;
3782 break;
a0d0e21e
LW
3783 case 6:
3784 if (strEQ(d,"exists")) return KEY_exists;
4633a7c4 3785 if (strEQ(d,"elseif")) warn("elseif should be elsif");
a0d0e21e 3786 break;
79072805 3787 case 8:
a0d0e21e
LW
3788 if (strEQ(d,"endgrent")) return -KEY_endgrent;
3789 if (strEQ(d,"endpwent")) return -KEY_endpwent;
79072805
LW
3790 break;
3791 case 9:
a0d0e21e 3792 if (strEQ(d,"endnetent")) return -KEY_endnetent;
79072805
LW
3793 break;
3794 case 10:
a0d0e21e
LW
3795 if (strEQ(d,"endhostent")) return -KEY_endhostent;
3796 if (strEQ(d,"endservent")) return -KEY_endservent;
79072805
LW
3797 break;
3798 case 11:
a0d0e21e 3799 if (strEQ(d,"endprotoent")) return -KEY_endprotoent;
79072805 3800 break;
a687059c 3801 }
a687059c 3802 break;
79072805
LW
3803 case 'f':
3804 switch (len) {
3805 case 3:
3806 if (strEQ(d,"for")) return KEY_for;
3807 break;
3808 case 4:
a0d0e21e 3809 if (strEQ(d,"fork")) return -KEY_fork;
79072805
LW
3810 break;
3811 case 5:
a0d0e21e
LW
3812 if (strEQ(d,"fcntl")) return -KEY_fcntl;
3813 if (strEQ(d,"flock")) return -KEY_flock;
79072805
LW
3814 break;
3815 case 6:
3816 if (strEQ(d,"format")) return KEY_format;
a0d0e21e 3817 if (strEQ(d,"fileno")) return -KEY_fileno;
79072805
LW
3818 break;
3819 case 7:
3820 if (strEQ(d,"foreach")) return KEY_foreach;
3821 break;
3822 case 8:
a0d0e21e 3823 if (strEQ(d,"formline")) return -KEY_formline;
79072805 3824 break;
378cc40b 3825 }
a687059c 3826 break;
79072805
LW
3827 case 'G':
3828 if (len == 2) {
a0d0e21e
LW
3829 if (strEQ(d,"GT")) { deprecate(d); return -KEY_gt;}
3830 if (strEQ(d,"GE")) { deprecate(d); return -KEY_ge;}
9f68db38 3831 }
a687059c 3832 break;
79072805 3833 case 'g':
a687059c
LW
3834 if (strnEQ(d,"get",3)) {
3835 d += 3;
3836 if (*d == 'p') {
79072805
LW
3837 switch (len) {
3838 case 7:
a0d0e21e
LW
3839 if (strEQ(d,"ppid")) return -KEY_getppid;
3840 if (strEQ(d,"pgrp")) return -KEY_getpgrp;
79072805
LW
3841 break;
3842 case 8:
a0d0e21e
LW
3843 if (strEQ(d,"pwent")) return -KEY_getpwent;
3844 if (strEQ(d,"pwnam")) return -KEY_getpwnam;
3845 if (strEQ(d,"pwuid")) return -KEY_getpwuid;
79072805
LW
3846 break;
3847 case 11:
a0d0e21e
LW
3848 if (strEQ(d,"peername")) return -KEY_getpeername;
3849 if (strEQ(d,"protoent")) return -KEY_getprotoent;
3850 if (strEQ(d,"priority")) return -KEY_getpriority;
79072805
LW
3851 break;
3852 case 14:
a0d0e21e 3853 if (strEQ(d,"protobyname")) return -KEY_getprotobyname;
79072805
LW
3854 break;
3855 case 16:
a0d0e21e 3856 if (strEQ(d,"protobynumber"))return -KEY_getprotobynumber;
79072805
LW
3857 break;
3858 }
a687059c
LW
3859 }
3860 else if (*d == 'h') {
a0d0e21e
LW
3861 if (strEQ(d,"hostbyname")) return -KEY_gethostbyname;
3862 if (strEQ(d,"hostbyaddr")) return -KEY_gethostbyaddr;
3863 if (strEQ(d,"hostent")) return -KEY_gethostent;
a687059c
LW
3864 }
3865 else if (*d == 'n') {
a0d0e21e
LW
3866 if (strEQ(d,"netbyname")) return -KEY_getnetbyname;
3867 if (strEQ(d,"netbyaddr")) return -KEY_getnetbyaddr;
3868 if (strEQ(d,"netent")) return -KEY_getnetent;
a687059c
LW
3869 }
3870 else if (*d == 's') {
a0d0e21e
LW
3871 if (strEQ(d,"servbyname")) return -KEY_getservbyname;
3872 if (strEQ(d,"servbyport")) return -KEY_getservbyport;
3873 if (strEQ(d,"servent")) return -KEY_getservent;
3874 if (strEQ(d,"sockname")) return -KEY_getsockname;
3875 if (strEQ(d,"sockopt")) return -KEY_getsockopt;
a687059c
LW
3876 }
3877 else if (*d == 'g') {
a0d0e21e
LW
3878 if (strEQ(d,"grent")) return -KEY_getgrent;
3879 if (strEQ(d,"grnam")) return -KEY_getgrnam;
3880 if (strEQ(d,"grgid")) return -KEY_getgrgid;
a687059c
LW
3881 }
3882 else if (*d == 'l') {
a0d0e21e 3883 if (strEQ(d,"login")) return -KEY_getlogin;
a687059c 3884 }
a0d0e21e 3885 else if (strEQ(d,"c")) return -KEY_getc;
79072805 3886 break;
a687059c 3887 }
79072805
LW
3888 switch (len) {
3889