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