This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove bad advice from perllocale.pod
[perl5.git] / toke.c
CommitLineData
a0d0e21e 1/* toke.c
a687059c 2 *
a0d0e21e 3 * Copyright (c) 1991-1994, Larry Wall
a687059c 4 *
d48672a2
LW
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
378cc40b 7 *
a0d0e21e
LW
8 */
9
10/*
11 * "It all comes from here, the stench and the peril." --Frodo
378cc40b
LW
12 */
13
14#include "EXTERN.h"
15#include "perl.h"
378cc40b 16
a0d0e21e
LW
17static void check_uni _((void));
18static void force_next _((I32 type));
89bfa8cd 19static char *force_version _((char *start));
a0d0e21e
LW
20static char *force_word _((char *start, int token, int check_keyword, int allow_pack, int allow_tick));
21static SV *q _((SV *sv));
22static char *scan_const _((char *start));
23static char *scan_formline _((char *s));
24static char *scan_heredoc _((char *s));
25static char *scan_ident _((char *s, char *send, char *dest, I32 ck_uni));
26static char *scan_inputsymbol _((char *start));
27static char *scan_pat _((char *start));
28static char *scan_str _((char *start));
29static char *scan_subst _((char *start));
30static char *scan_trans _((char *start));
31static char *scan_word _((char *s, char *dest, int allow_package, STRLEN *slp));
32static char *skipspace _((char *s));
33static void checkcomma _((char *s, char *name, char *what));
34static void force_ident _((char *s, int kind));
35static void incline _((char *s));
36static int intuit_method _((char *s, GV *gv));
37static int intuit_more _((char *s));
38static I32 lop _((I32 f, expectation x, char *s));
39static void missingterm _((char *s));
40static void no_op _((char *what, char *s));
41static void set_csh _((void));
42static I32 sublex_done _((void));
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
a0d0e21e 448lop(f,x,s)
79072805 449I32 f;
a0d0e21e 450expectation x;
ffed7fef
LW
451char *s;
452{
79072805 453 yylval.ival = f;
35c8bce7 454 CLINE;
a0d0e21e 455 expect = x;
79072805 456 bufptr = s;
8990e307
LW
457 last_lop = oldbufptr;
458 last_lop_op = f;
a0d0e21e
LW
459 if (nexttoke)
460 return LSTOP;
79072805
LW
461 if (*s == '(')
462 return FUNC;
463 s = skipspace(s);
464 if (*s == '(')
465 return FUNC;
466 else
467 return LSTOP;
468}
469
8990e307 470static void
79072805
LW
471force_next(type)
472I32 type;
473{
474 nexttype[nexttoke] = type;
475 nexttoke++;
476 if (lex_state != LEX_KNOWNEXT) {
477 lex_defer = lex_state;
463ee0b2 478 lex_expect = expect;
79072805
LW
479 lex_state = LEX_KNOWNEXT;
480 }
481}
482
8990e307 483static char *
a0d0e21e 484force_word(start,token,check_keyword,allow_pack,allow_tick)
463ee0b2 485register char *start;
79072805 486int token;
463ee0b2 487int check_keyword;
a0d0e21e 488int allow_pack;
463ee0b2 489int allow_tick;
79072805 490{
463ee0b2
LW
491 register char *s;
492 STRLEN len;
493
494 start = skipspace(start);
495 s = start;
a0d0e21e
LW
496 if (isIDFIRST(*s) ||
497 (allow_pack && *s == ':') ||
498 (allow_tick && *s == '\'') )
499 {
500 s = scan_word(s, tokenbuf, allow_pack, &len);
463ee0b2
LW
501 if (check_keyword && keyword(tokenbuf, len))
502 return start;
503 if (token == METHOD) {
504 s = skipspace(s);
505 if (*s == '(')
506 expect = XTERM;
507 else {
508 expect = XOPERATOR;
509 force_next(')');
510 force_next('(');
511 }
79072805 512 }
463ee0b2 513 nextval[nexttoke].opval = (OP*)newSVOP(OP_CONST,0, newSVpv(tokenbuf,0));
8990e307 514 nextval[nexttoke].opval->op_private |= OPpCONST_BARE;
79072805
LW
515 force_next(token);
516 }
517 return s;
518}
519
8990e307 520static void
a0d0e21e 521force_ident(s, kind)
79072805 522register char *s;
a0d0e21e 523int kind;
79072805
LW
524{
525 if (s && *s) {
748a9306
LW
526 OP* op = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
527 nextval[nexttoke].opval = op;
79072805 528 force_next(WORD);
748a9306
LW
529 if (kind) {
530 op->op_private = OPpCONST_ENTERED;
55497cff
PP
531 /* XXX see note in pp_entereval() for why we forgo typo
532 warnings if the symbol must be introduced in an eval.
533 GSAR 96-10-12 */
534 gv_fetchpv(s, in_eval ? GV_ADDMULTI : TRUE,
a0d0e21e
LW
535 kind == '$' ? SVt_PV :
536 kind == '@' ? SVt_PVAV :
537 kind == '%' ? SVt_PVHV :
538 SVt_PVGV
539 );
748a9306 540 }
79072805
LW
541 }
542}
543
89bfa8cd
PP
544static char *
545force_version(s)
546char *s;
547{
548 OP *version = Nullop;
549
550 s = skipspace(s);
551
552 /* default VERSION number -- GBARR */
553
554 if(isDIGIT(*s)) {
555 char *d;
556 int c;
55497cff 557 for( d=s, c = 1; isDIGIT(*d) || *d == '_' || (*d == '.' && c--); d++);
89bfa8cd
PP
558 if((*d == ';' || isSPACE(*d)) && *(skipspace(d)) != ',') {
559 s = scan_num(s);
560 /* real VERSION number -- GBARR */
561 version = yylval.opval;
562 }
563 }
564
565 /* NOTE: The parser sees the package name and the VERSION swapped */
566 nextval[nexttoke].opval = version;
567 force_next(WORD);
568
569 return (s);
570}
571
8990e307 572static SV *
79072805
LW
573q(sv)
574SV *sv;
575{
576 register char *s;
577 register char *send;
578 register char *d;
463ee0b2 579 STRLEN len;
79072805
LW
580
581 if (!SvLEN(sv))
582 return sv;
583
a0d0e21e 584 s = SvPV_force(sv, len);
748a9306
LW
585 if (SvIVX(sv) == -1)
586 return sv;
463ee0b2 587 send = s + len;
79072805
LW
588 while (s < send && *s != '\\')
589 s++;
590 if (s == send)
591 return sv;
592 d = s;
79072805
LW
593 while (s < send) {
594 if (*s == '\\') {
a0d0e21e 595 if (s + 1 < send && (s[1] == '\\'))
79072805
LW
596 s++; /* all that, just for this */
597 }
598 *d++ = *s++;
599 }
600 *d = '\0';
463ee0b2 601 SvCUR_set(sv, d - SvPVX(sv));
79072805
LW
602
603 return sv;
604}
605
8990e307 606static I32
79072805
LW
607sublex_start()
608{
609 register I32 op_type = yylval.ival;
79072805
LW
610
611 if (op_type == OP_NULL) {
612 yylval.opval = lex_op;
613 lex_op = Nullop;
614 return THING;
615 }
616 if (op_type == OP_CONST || op_type == OP_READLINE) {
617 yylval.opval = (OP*)newSVOP(op_type, 0, q(lex_stuff));
618 lex_stuff = Nullsv;
619 return THING;
620 }
621
55497cff
PP
622 sublex_info.super_state = lex_state;
623 sublex_info.sub_inwhat = op_type;
624 sublex_info.sub_op = lex_op;
625 lex_state = LEX_INTERPPUSH;
626
627 expect = XTERM;
628 if (lex_op) {
629 yylval.opval = lex_op;
630 lex_op = Nullop;
631 return PMFUNC;
632 }
633 else
634 return FUNC;
635}
636
637static I32
638sublex_push()
639{
79072805 640 push_scope();
55497cff
PP
641
642 lex_state = sublex_info.super_state;
643 SAVEI32(lex_dojoin);
644 SAVEI32(lex_brackets);
645 SAVEI32(lex_fakebrack);
646 SAVEI32(lex_casemods);
647 SAVEI32(lex_starts);
648 SAVEI32(lex_state);
a0d0e21e 649 SAVESPTR(lex_inpat);
55497cff
PP
650 SAVEI32(lex_inwhat);
651 SAVEI16(curcop->cop_line);
85e6fe83
LW
652 SAVEPPTR(bufptr);
653 SAVEPPTR(oldbufptr);
654 SAVEPPTR(oldoldbufptr);
fd049845 655 SAVEPPTR(linestart);
79072805 656 SAVESPTR(linestr);
85e6fe83 657 SAVEPPTR(lex_brackstack);
a0d0e21e 658 SAVEPPTR(lex_casestack);
79072805
LW
659
660 linestr = lex_stuff;
661 lex_stuff = Nullsv;
662
fd049845 663 bufend = bufptr = oldbufptr = oldoldbufptr = linestart = SvPVX(linestr);
79072805 664 bufend += SvCUR(linestr);
8990e307 665 SAVEFREESV(linestr);
79072805
LW
666
667 lex_dojoin = FALSE;
668 lex_brackets = 0;
669 lex_fakebrack = 0;
8990e307 670 New(899, lex_brackstack, 120, char);
a0d0e21e 671 New(899, lex_casestack, 12, char);
8990e307 672 SAVEFREEPV(lex_brackstack);
a0d0e21e 673 SAVEFREEPV(lex_casestack);
79072805 674 lex_casemods = 0;
a0d0e21e 675 *lex_casestack = '\0';
79072805
LW
676 lex_starts = 0;
677 lex_state = LEX_INTERPCONCAT;
678 curcop->cop_line = multi_start;
679
55497cff
PP
680 lex_inwhat = sublex_info.sub_inwhat;
681 if (lex_inwhat == OP_MATCH || lex_inwhat == OP_SUBST)
682 lex_inpat = sublex_info.sub_op;
79072805 683 else
55497cff 684 lex_inpat = Nullop;
79072805 685
55497cff 686 return '(';
79072805
LW
687}
688
8990e307 689static I32
79072805
LW
690sublex_done()
691{
692 if (!lex_starts++) {
693 expect = XOPERATOR;
93a17b20 694 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv("",0));
79072805
LW
695 return THING;
696 }
697
698 if (lex_casemods) { /* oops, we've got some unbalanced parens */
699 lex_state = LEX_INTERPCASEMOD;
700 return yylex();
701 }
702
79072805
LW
703 /* Is there a right-hand side to take care of? */
704 if (lex_repl && (lex_inwhat == OP_SUBST || lex_inwhat == OP_TRANS)) {
705 linestr = lex_repl;
706 lex_inpat = 0;
fd049845 707 bufend = bufptr = oldbufptr = oldoldbufptr = linestart = SvPVX(linestr);
79072805 708 bufend += SvCUR(linestr);
8990e307 709 SAVEFREESV(linestr);
79072805
LW
710 lex_dojoin = FALSE;
711 lex_brackets = 0;
712 lex_fakebrack = 0;
713 lex_casemods = 0;
a0d0e21e 714 *lex_casestack = '\0';
79072805
LW
715 lex_starts = 0;
716 if (SvCOMPILED(lex_repl)) {
717 lex_state = LEX_INTERPNORMAL;
718 lex_starts++;
719 }
720 else
721 lex_state = LEX_INTERPCONCAT;
722 lex_repl = Nullsv;
723 return ',';
ffed7fef
LW
724 }
725 else {
79072805 726 pop_scope();
463ee0b2 727 bufend = SvPVX(linestr);
79072805
LW
728 bufend += SvCUR(linestr);
729 expect = XOPERATOR;
730 return ')';
ffed7fef
LW
731 }
732}
733
8990e307 734static char *
79072805
LW
735scan_const(start)
736char *start;
737{
738 register char *send = bufend;
739 SV *sv = NEWSV(93, send - start);
740 register char *s = start;
463ee0b2 741 register char *d = SvPVX(sv);
79072805
LW
742 bool dorange = FALSE;
743 I32 len;
744 char *leave =
745 lex_inpat
748a9306 746 ? "\\.^$@AGZdDwWsSbB+*?|()-nrtfeaxc0123456789[{]} \t\n\r\f\v#"
79072805
LW
747 : (lex_inwhat & OP_TRANS)
748 ? ""
749 : "";
750
751 while (s < send || dorange) {
752 if (lex_inwhat == OP_TRANS) {
753 if (dorange) {
754 I32 i;
755 I32 max;
463ee0b2 756 i = d - SvPVX(sv);
79072805 757 SvGROW(sv, SvLEN(sv) + 256);
463ee0b2 758 d = SvPVX(sv) + i;
79072805 759 d -= 2;
91b7def8
PP
760 max = (U8)d[1];
761 for (i = (U8)*d; i <= max; i++)
79072805
LW
762 *d++ = i;
763 dorange = FALSE;
764 continue;
765 }
766 else if (*s == '-' && s+1 < send && s != start) {
767 dorange = TRUE;
768 s++;
769 }
770 }
748a9306
LW
771 else if (*s == '(' && lex_inpat && s[1] == '?' && s[2] == '#') {
772 while (s < send && *s != ')')
773 *d++ = *s++;
774 }
775 else if (*s == '#' && lex_inpat &&
776 ((PMOP*)lex_inpat)->op_pmflags & PMf_EXTENDED) {
777 while (s+1 < send && *s != '\n')
778 *d++ = *s++;
779 }
a0d0e21e 780 else if (*s == '@' && s[1] && (isALNUM(s[1]) || strchr(":'{$", s[1])))
79072805
LW
781 break;
782 else if (*s == '$') {
783 if (!lex_inpat) /* not a regexp, so $ must be var */
784 break;
a0d0e21e 785 if (s + 1 < send && !strchr(")| \n\t", s[1]))
79072805
LW
786 break; /* in regexp, $ might be tail anchor */
787 }
788 if (*s == '\\' && s+1 < send) {
789 s++;
93a17b20 790 if (*s && strchr(leave, *s)) {
79072805
LW
791 *d++ = '\\';
792 *d++ = *s++;
793 continue;
794 }
795 if (lex_inwhat == OP_SUBST && !lex_inpat &&
a0d0e21e 796 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
79072805 797 {
a0d0e21e
LW
798 if (dowarn)
799 warn("\\%c better written as $%c", *s, *s);
79072805
LW
800 *--s = '$';
801 break;
802 }
a0d0e21e 803 if (lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
79072805
LW
804 --s;
805 break;
806 }
807 switch (*s) {
808 case '-':
809 if (lex_inwhat == OP_TRANS) {
810 *d++ = *s++;
811 continue;
812 }
813 /* FALL THROUGH */
814 default:
815 *d++ = *s++;
816 continue;
817 case '0': case '1': case '2': case '3':
818 case '4': case '5': case '6': case '7':
819 *d++ = scan_oct(s, 3, &len);
820 s += len;
821 continue;
822 case 'x':
823 *d++ = scan_hex(++s, 2, &len);
824 s += len;
825 continue;
826 case 'c':
827 s++;
bbce6d69
PP
828 len = *s++;
829 *d++ = toCTRL(len);
79072805
LW
830 continue;
831 case 'b':
832 *d++ = '\b';
833 break;
834 case 'n':
835 *d++ = '\n';
836 break;
837 case 'r':
838 *d++ = '\r';
839 break;
840 case 'f':
841 *d++ = '\f';
842 break;
843 case 't':
844 *d++ = '\t';
845 break;
846 case 'e':
847 *d++ = '\033';
848 break;
849 case 'a':
850 *d++ = '\007';
851 break;
852 }
853 s++;
854 continue;
855 }
856 *d++ = *s++;
857 }
858 *d = '\0';
463ee0b2 859 SvCUR_set(sv, d - SvPVX(sv));
79072805
LW
860 SvPOK_on(sv);
861
862 if (SvCUR(sv) + 5 < SvLEN(sv)) {
863 SvLEN_set(sv, SvCUR(sv) + 1);
463ee0b2 864 Renew(SvPVX(sv), SvLEN(sv), char);
79072805
LW
865 }
866 if (s > bufptr)
867 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
868 else
8990e307 869 SvREFCNT_dec(sv);
79072805
LW
870 return s;
871}
872
873/* This is the one truly awful dwimmer necessary to conflate C and sed. */
8990e307 874static int
79072805
LW
875intuit_more(s)
876register char *s;
877{
878 if (lex_brackets)
879 return TRUE;
880 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
881 return TRUE;
882 if (*s != '{' && *s != '[')
883 return FALSE;
884 if (!lex_inpat)
885 return TRUE;
886
887 /* In a pattern, so maybe we have {n,m}. */
888 if (*s == '{') {
889 s++;
890 if (!isDIGIT(*s))
891 return TRUE;
892 while (isDIGIT(*s))
893 s++;
894 if (*s == ',')
895 s++;
896 while (isDIGIT(*s))
897 s++;
898 if (*s == '}')
899 return FALSE;
900 return TRUE;
901
902 }
903
904 /* On the other hand, maybe we have a character class */
905
906 s++;
907 if (*s == ']' || *s == '^')
908 return FALSE;
909 else {
910 int weight = 2; /* let's weigh the evidence */
911 char seen[256];
912 unsigned char un_char = 0, last_un_char;
93a17b20 913 char *send = strchr(s,']');
79072805
LW
914 char tmpbuf[512];
915
916 if (!send) /* has to be an expression */
917 return TRUE;
918
919 Zero(seen,256,char);
920 if (*s == '$')
921 weight -= 3;
922 else if (isDIGIT(*s)) {
923 if (s[1] != ']') {
924 if (isDIGIT(s[1]) && s[2] == ']')
925 weight -= 10;
926 }
927 else
928 weight -= 100;
929 }
930 for (; s < send; s++) {
931 last_un_char = un_char;
932 un_char = (unsigned char)*s;
933 switch (*s) {
934 case '@':
935 case '&':
936 case '$':
937 weight -= seen[un_char] * 10;
938 if (isALNUM(s[1])) {
939 scan_ident(s,send,tmpbuf,FALSE);
a0d0e21e 940 if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV))
79072805
LW
941 weight -= 100;
942 else
943 weight -= 10;
944 }
945 else if (*s == '$' && s[1] &&
93a17b20
LW
946 strchr("[#!%*<>()-=",s[1])) {
947 if (/*{*/ strchr("])} =",s[2]))
79072805
LW
948 weight -= 10;
949 else
950 weight -= 1;
951 }
952 break;
953 case '\\':
954 un_char = 254;
955 if (s[1]) {
93a17b20 956 if (strchr("wds]",s[1]))
79072805
LW
957 weight += 100;
958 else if (seen['\''] || seen['"'])
959 weight += 1;
93a17b20 960 else if (strchr("rnftbxcav",s[1]))
79072805
LW
961 weight += 40;
962 else if (isDIGIT(s[1])) {
963 weight += 40;
964 while (s[1] && isDIGIT(s[1]))
965 s++;
966 }
967 }
968 else
969 weight += 100;
970 break;
971 case '-':
972 if (s[1] == '\\')
973 weight += 50;
93a17b20 974 if (strchr("aA01! ",last_un_char))
79072805 975 weight += 30;
93a17b20 976 if (strchr("zZ79~",s[1]))
79072805
LW
977 weight += 30;
978 break;
979 default:
93a17b20 980 if (!isALNUM(last_un_char) && !strchr("$@&",last_un_char) &&
79072805
LW
981 isALPHA(*s) && s[1] && isALPHA(s[1])) {
982 char *d = tmpbuf;
983 while (isALPHA(*s))
984 *d++ = *s++;
985 *d = '\0';
986 if (keyword(tmpbuf, d - tmpbuf))
987 weight -= 150;
988 }
989 if (un_char == last_un_char + 1)
990 weight += 5;
991 weight -= seen[un_char];
992 break;
993 }
994 seen[un_char]++;
995 }
996 if (weight >= 0) /* probably a character class */
997 return FALSE;
998 }
999
1000 return TRUE;
1001}
ffed7fef 1002
a0d0e21e
LW
1003static int
1004intuit_method(start,gv)
1005char *start;
1006GV *gv;
1007{
1008 char *s = start + (*start == '$');
1009 char tmpbuf[1024];
1010 STRLEN len;
1011 GV* indirgv;
1012
1013 if (gv) {
1014 if (GvIO(gv))
1015 return 0;
8ebc5c01 1016 if (!GvCVu(gv))
a0d0e21e
LW
1017 gv = 0;
1018 }
1019 s = scan_word(s, tmpbuf, TRUE, &len);
1020 if (*start == '$') {
1021 if (gv || last_lop_op == OP_PRINT || isUPPER(*tokenbuf))
1022 return 0;
1023 s = skipspace(s);
1024 bufptr = start;
1025 expect = XREF;
1026 return *s == '(' ? FUNCMETH : METHOD;
1027 }
1028 if (!keyword(tmpbuf, len)) {
1029 indirgv = gv_fetchpv(tmpbuf,FALSE, SVt_PVCV);
8ebc5c01 1030 if (indirgv && GvCVu(indirgv))
a0d0e21e
LW
1031 return 0;
1032 /* filehandle or package name makes it a method */
89bfa8cd 1033 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
a0d0e21e 1034 s = skipspace(s);
55497cff
PP
1035 if ((bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
1036 return 0; /* no assumptions -- "=>" quotes bearword */
a0d0e21e
LW
1037 nextval[nexttoke].opval =
1038 (OP*)newSVOP(OP_CONST, 0,
1039 newSVpv(tmpbuf,0));
1040 nextval[nexttoke].opval->op_private =
1041 OPpCONST_BARE;
1042 expect = XTERM;
1043 force_next(WORD);
1044 bufptr = s;
1045 return *s == '(' ? FUNCMETH : METHOD;
1046 }
1047 }
1048 return 0;
1049}
1050
1051static char*
1052incl_perldb()
1053{
1054 if (perldb) {
1055 char *pdb = getenv("PERL5DB");
1056
1057 if (pdb)
1058 return pdb;
1059 return "BEGIN { require 'perl5db.pl' }";
1060 }
1061 return "";
1062}
1063
1064
16d20bd9
AD
1065/* Encoded script support. filter_add() effectively inserts a
1066 * 'pre-processing' function into the current source input stream.
1067 * Note that the filter function only applies to the current source file
1068 * (e.g., it will not affect files 'require'd or 'use'd by this one).
1069 *
1070 * The datasv parameter (which may be NULL) can be used to pass
1071 * private data to this instance of the filter. The filter function
1072 * can recover the SV using the FILTER_DATA macro and use it to
1073 * store private buffers and state information.
1074 *
1075 * The supplied datasv parameter is upgraded to a PVIO type
1076 * and the IoDIRP field is used to store the function pointer.
1077 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
1078 * private use must be set using malloc'd pointers.
1079 */
1080static int filter_debug = 0;
1081
1082SV *
1083filter_add(funcp, datasv)
1084 filter_t funcp;
1085 SV *datasv;
1086{
1087 if (!funcp){ /* temporary handy debugging hack to be deleted */
1088 filter_debug = atoi((char*)datasv);
1089 return NULL;
1090 }
1091 if (!rsfp_filters)
1092 rsfp_filters = newAV();
1093 if (!datasv)
1094 datasv = newSV(0);
1095 if (!SvUPGRADE(datasv, SVt_PVIO))
1096 die("Can't upgrade filter_add data to SVt_PVIO");
1097 IoDIRP(datasv) = (DIR*)funcp; /* stash funcp into spare field */
1098 if (filter_debug)
1099 warn("filter_add func %lx (%s)", funcp, SvPV(datasv,na));
e50aee73
AD
1100 av_unshift(rsfp_filters, 1);
1101 av_store(rsfp_filters, 0, datasv) ;
16d20bd9
AD
1102 return(datasv);
1103}
1104
1105
1106/* Delete most recently added instance of this filter function. */
a0d0e21e 1107void
16d20bd9
AD
1108filter_del(funcp)
1109 filter_t funcp;
1110{
1111 if (filter_debug)
1112 warn("filter_del func %lx", funcp);
1113 if (!rsfp_filters || AvFILL(rsfp_filters)<0)
1114 return;
1115 /* if filter is on top of stack (usual case) just pop it off */
e50aee73
AD
1116 if (IoDIRP(FILTER_DATA(0)) == (void*)funcp){
1117 /* sv_free(av_pop(rsfp_filters)); */
1118 sv_free(av_shift(rsfp_filters));
1119
16d20bd9
AD
1120 return;
1121 }
1122 /* we need to search for the correct entry and clear it */
1123 die("filter_del can only delete in reverse order (currently)");
1124}
1125
1126
1127/* Invoke the n'th filter function for the current rsfp. */
1128I32
1129filter_read(idx, buf_sv, maxlen)
1130 int idx;
1131 SV *buf_sv;
1132 int maxlen; /* 0 = read one text line */
a0d0e21e 1133{
16d20bd9
AD
1134 filter_t funcp;
1135 SV *datasv = NULL;
e50aee73 1136
16d20bd9
AD
1137 if (!rsfp_filters)
1138 return -1;
1139 if (idx > AvFILL(rsfp_filters)){ /* Any more filters? */
1140 /* Provide a default input filter to make life easy. */
1141 /* Note that we append to the line. This is handy. */
16d20bd9
AD
1142 if (filter_debug)
1143 warn("filter_read %d: from rsfp\n", idx);
1144 if (maxlen) {
1145 /* Want a block */
1146 int len ;
1147 int old_len = SvCUR(buf_sv) ;
1148
1149 /* ensure buf_sv is large enough */
1150 SvGROW(buf_sv, old_len + maxlen) ;
760ac839
LW
1151 if ((len = PerlIO_read(rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
1152 if (PerlIO_error(rsfp))
37120919
AD
1153 return -1; /* error */
1154 else
1155 return 0 ; /* end of file */
1156 }
16d20bd9
AD
1157 SvCUR_set(buf_sv, old_len + len) ;
1158 } else {
1159 /* Want a line */
37120919 1160 if (sv_gets(buf_sv, rsfp, SvCUR(buf_sv)) == NULL) {
760ac839 1161 if (PerlIO_error(rsfp))
37120919
AD
1162 return -1; /* error */
1163 else
1164 return 0 ; /* end of file */
1165 }
16d20bd9
AD
1166 }
1167 return SvCUR(buf_sv);
1168 }
1169 /* Skip this filter slot if filter has been deleted */
1170 if ( (datasv = FILTER_DATA(idx)) == &sv_undef){
1171 if (filter_debug)
1172 warn("filter_read %d: skipped (filter deleted)\n", idx);
1173 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
1174 }
1175 /* Get function pointer hidden within datasv */
1176 funcp = (filter_t)IoDIRP(datasv);
1177 if (filter_debug)
1178 warn("filter_read %d: via function %lx (%s)\n",
1179 idx, funcp, SvPV(datasv,na));
1180 /* Call function. The function is expected to */
1181 /* call "FILTER_READ(idx+1, buf_sv)" first. */
37120919 1182 /* Return: <0:error, =0:eof, >0:not eof */
16d20bd9
AD
1183 return (*funcp)(idx, buf_sv, maxlen);
1184}
1185
1186static char *
fd049845 1187filter_gets(sv,fp, append)
16d20bd9 1188register SV *sv;
760ac839 1189register PerlIO *fp;
fd049845 1190STRLEN append;
16d20bd9
AD
1191{
1192 if (rsfp_filters) {
1193
55497cff
PP
1194 if (!append)
1195 SvCUR_set(sv, 0); /* start with empty line */
16d20bd9
AD
1196 if (FILTER_READ(0, sv, 0) > 0)
1197 return ( SvPVX(sv) ) ;
1198 else
1199 return Nullch ;
1200 }
1201 else
fd049845 1202 return (sv_gets(sv, fp, append));
16d20bd9 1203
a0d0e21e
LW
1204}
1205
1206
748a9306
LW
1207#ifdef DEBUGGING
1208 static char* exp_name[] =
a0d0e21e 1209 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "TERMBLOCK" };
748a9306 1210#endif
463ee0b2 1211
71be2cbc 1212EXT int yychar; /* last token */
463ee0b2 1213
2f3197b3 1214int
378cc40b
LW
1215yylex()
1216{
79072805 1217 register char *s;
378cc40b 1218 register char *d;
79072805 1219 register I32 tmp;
463ee0b2 1220 STRLEN len;
a687059c 1221
bbce6d69
PP
1222 if (pending_ident) {
1223 char pit = pending_ident;
1224 pending_ident = 0;
1225
1226 if (in_my) {
1227 if (strchr(tokenbuf,':'))
1228 croak(no_myglob,tokenbuf);
1229 yylval.opval = newOP(OP_PADANY, 0);
1230 yylval.opval->op_targ = pad_allocmy(tokenbuf);
1231 return PRIVATEREF;
1232 }
1233
1234 if (!strchr(tokenbuf,':') && (tmp = pad_findmy(tokenbuf))) {
1235 if (last_lop_op == OP_SORT &&
1236 tokenbuf[0] == '$' &&
1237 (tokenbuf[1] == 'a' || tokenbuf[1] == 'b')
1238 && !tokenbuf[2])
1239 {
1240 for (d = in_eval ? oldoldbufptr : linestart;
1241 d < bufend && *d != '\n';
1242 d++)
1243 {
1244 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
1245 croak("Can't use \"my %s\" in sort comparison",
1246 tokenbuf);
1247 }
1248 }
1249 }
1250
1251 yylval.opval = newOP(OP_PADANY, 0);
1252 yylval.opval->op_targ = tmp;
1253 return PRIVATEREF;
1254 }
1255
1256 /* Force them to make up their mind on "@foo". */
1257 if (pit == '@' && lex_state != LEX_NORMAL && !lex_brackets) {
1258 GV *gv = gv_fetchpv(tokenbuf+1, FALSE, SVt_PVAV);
36477c24 1259 if (!gv || ((tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv))) {
bbce6d69
PP
1260 char tmpbuf[1024];
1261 sprintf(tmpbuf, "Literal %s now requires backslash", tokenbuf);
1262 yyerror(tmpbuf);
1263 }
1264 }
1265
1266 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(tokenbuf+1, 0));
1267 yylval.opval->op_private = OPpCONST_ENTERED;
1268 gv_fetchpv(tokenbuf+1, in_eval ? GV_ADDMULTI : TRUE,
1269 ((tokenbuf[0] == '$') ? SVt_PV
1270 : (tokenbuf[0] == '@') ? SVt_PVAV
1271 : SVt_PVHV));
1272 return WORD;
1273 }
1274
79072805
LW
1275 switch (lex_state) {
1276#ifdef COMMENTARY
1277 case LEX_NORMAL: /* Some compilers will produce faster */
1278 case LEX_INTERPNORMAL: /* code if we comment these out. */
1279 break;
1280#endif
1281
1282 case LEX_KNOWNEXT:
1283 nexttoke--;
1284 yylval = nextval[nexttoke];
463ee0b2 1285 if (!nexttoke) {
79072805 1286 lex_state = lex_defer;
463ee0b2 1287 expect = lex_expect;
a0d0e21e 1288 lex_defer = LEX_NORMAL;
463ee0b2 1289 }
79072805
LW
1290 return(nexttype[nexttoke]);
1291
1292 case LEX_INTERPCASEMOD:
1293#ifdef DEBUGGING
1294 if (bufptr != bufend && *bufptr != '\\')
463ee0b2 1295 croak("panic: INTERPCASEMOD");
79072805
LW
1296#endif
1297 if (bufptr == bufend || bufptr[1] == 'E') {
a0d0e21e 1298 char oldmod;
79072805 1299 if (lex_casemods) {
a0d0e21e
LW
1300 oldmod = lex_casestack[--lex_casemods];
1301 lex_casestack[lex_casemods] = '\0';
1302 if (bufptr != bufend && strchr("LUQ", oldmod)) {
1303 bufptr += 2;
1304 lex_state = LEX_INTERPCONCAT;
1305 }
79072805
LW
1306 return ')';
1307 }
a0d0e21e
LW
1308 if (bufptr != bufend)
1309 bufptr += 2;
1310 lex_state = LEX_INTERPCONCAT;
79072805
LW
1311 return yylex();
1312 }
1313 else {
1314 s = bufptr + 1;
1315 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
1316 tmp = *s, *s = s[2], s[2] = tmp; /* misordered... */
a0d0e21e
LW
1317 if (strchr("LU", *s) &&
1318 (strchr(lex_casestack, 'L') || strchr(lex_casestack, 'U')))
1319 {
1320 lex_casestack[--lex_casemods] = '\0';
1321 return ')';
1322 }
1323 if (lex_casemods > 10) {
89bfa8cd 1324 char* newlb = Renew(lex_casestack, lex_casemods + 2, char);
a0d0e21e
LW
1325 if (newlb != lex_casestack) {
1326 SAVEFREEPV(newlb);
1327 lex_casestack = newlb;
1328 }
1329 }
1330 lex_casestack[lex_casemods++] = *s;
1331 lex_casestack[lex_casemods] = '\0';
79072805
LW
1332 lex_state = LEX_INTERPCONCAT;
1333 nextval[nexttoke].ival = 0;
1334 force_next('(');
1335 if (*s == 'l')
1336 nextval[nexttoke].ival = OP_LCFIRST;
1337 else if (*s == 'u')
1338 nextval[nexttoke].ival = OP_UCFIRST;
1339 else if (*s == 'L')
1340 nextval[nexttoke].ival = OP_LC;
1341 else if (*s == 'U')
1342 nextval[nexttoke].ival = OP_UC;
a0d0e21e
LW
1343 else if (*s == 'Q')
1344 nextval[nexttoke].ival = OP_QUOTEMETA;
79072805 1345 else
463ee0b2 1346 croak("panic: yylex");
79072805
LW
1347 bufptr = s + 1;
1348 force_next(FUNC);
1349 if (lex_starts) {
1350 s = bufptr;
463ee0b2 1351 lex_starts = 0;
79072805
LW
1352 Aop(OP_CONCAT);
1353 }
1354 else
1355 return yylex();
1356 }
1357
55497cff
PP
1358 case LEX_INTERPPUSH:
1359 return sublex_push();
1360
79072805
LW
1361 case LEX_INTERPSTART:
1362 if (bufptr == bufend)
1363 return sublex_done();
1364 expect = XTERM;
1365 lex_dojoin = (*bufptr == '@');
1366 lex_state = LEX_INTERPNORMAL;
1367 if (lex_dojoin) {
1368 nextval[nexttoke].ival = 0;
1369 force_next(',');
a0d0e21e 1370 force_ident("\"", '$');
79072805
LW
1371 nextval[nexttoke].ival = 0;
1372 force_next('$');
1373 nextval[nexttoke].ival = 0;
1374 force_next('(');
1375 nextval[nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
1376 force_next(FUNC);
1377 }
1378 if (lex_starts++) {
1379 s = bufptr;
1380 Aop(OP_CONCAT);
1381 }
1382 else
1383 return yylex();
1384 break;
1385
1386 case LEX_INTERPENDMAYBE:
1387 if (intuit_more(bufptr)) {
1388 lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
1389 break;
1390 }
1391 /* FALL THROUGH */
1392
1393 case LEX_INTERPEND:
1394 if (lex_dojoin) {
1395 lex_dojoin = FALSE;
1396 lex_state = LEX_INTERPCONCAT;
1397 return ')';
1398 }
1399 /* FALLTHROUGH */
1400 case LEX_INTERPCONCAT:
1401#ifdef DEBUGGING
1402 if (lex_brackets)
463ee0b2 1403 croak("panic: INTERPCONCAT");
79072805
LW
1404#endif
1405 if (bufptr == bufend)
1406 return sublex_done();
1407
ed6116ce 1408 if (SvIVX(linestr) == '\'') {
79072805
LW
1409 SV *sv = newSVsv(linestr);
1410 if (!lex_inpat)
1411 sv = q(sv);
1412 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1413 s = bufend;
1414 }
1415 else {
1416 s = scan_const(bufptr);
1417 if (*s == '\\')
1418 lex_state = LEX_INTERPCASEMOD;
1419 else
1420 lex_state = LEX_INTERPSTART;
1421 }
1422
1423 if (s != bufptr) {
1424 nextval[nexttoke] = yylval;
463ee0b2 1425 expect = XTERM;
79072805
LW
1426 force_next(THING);
1427 if (lex_starts++)
1428 Aop(OP_CONCAT);
1429 else {
1430 bufptr = s;
1431 return yylex();
1432 }
1433 }
1434
1435 return yylex();
a0d0e21e
LW
1436 case LEX_FORMLINE:
1437 lex_state = LEX_NORMAL;
1438 s = scan_formline(bufptr);
1439 if (!lex_formbrack)
1440 goto rightbracket;
1441 OPERATOR(';');
79072805
LW
1442 }
1443
1444 s = bufptr;
a687059c
LW
1445 oldoldbufptr = oldbufptr;
1446 oldbufptr = s;
79072805 1447 DEBUG_p( {
760ac839 1448 PerlIO_printf(PerlIO_stderr(), "### Tokener expecting %s at %s\n", exp_name[expect], s);
79072805 1449 } )
463ee0b2
LW
1450
1451 retry:
378cc40b
LW
1452 switch (*s) {
1453 default:
a0d0e21e 1454 warn("Unrecognized character \\%03o ignored", *s++ & 255);
378cc40b 1455 goto retry;
e929a76b
LW
1456 case 4:
1457 case 26:
1458 goto fake_eof; /* emulate EOF on ^D or ^Z */
378cc40b 1459 case 0:
463ee0b2 1460 if (!rsfp) {
55497cff
PP
1461 last_uni = 0;
1462 last_lop = 0;
463ee0b2
LW
1463 if (lex_brackets)
1464 yyerror("Missing right bracket");
79072805 1465 TOKEN(0);
463ee0b2 1466 }
a687059c
LW
1467 if (s++ < bufend)
1468 goto retry; /* ignore stray nulls */
2f3197b3 1469 last_uni = 0;
79072805 1470 last_lop = 0;
a0d0e21e 1471 if (!in_eval && !preambled) {
79072805 1472 preambled = TRUE;
a0d0e21e 1473 sv_setpv(linestr,incl_perldb());
91b7def8
PP
1474 if (SvCUR(linestr))
1475 sv_catpv(linestr,";");
1476 if (preambleav){
1477 while(AvFILL(preambleav) >= 0) {
1478 SV *tmpsv = av_shift(preambleav);
1479 sv_catsv(linestr, tmpsv);
1480 sv_catpv(linestr, ";");
1481 sv_free(tmpsv);
1482 }
1483 sv_free((SV*)preambleav);
1484 preambleav = NULL;
1485 }
79072805
LW
1486 if (minus_n || minus_p) {
1487 sv_catpv(linestr, "LINE: while (<>) {");
1488 if (minus_l)
a0d0e21e 1489 sv_catpv(linestr,"chomp;");
2304df62
AD
1490 if (minus_a){
1491 if (minus_F){
1492 char tmpbuf1[50];
1493 if ( splitstr[0] == '/' ||
1494 splitstr[0] == '\'' ||
1495 splitstr[0] == '"' )
1496 sprintf( tmpbuf1, "@F=split(%s);", splitstr );
1497 else
1498 sprintf( tmpbuf1, "@F=split('%s');", splitstr );
1499 sv_catpv(linestr,tmpbuf1);
1500 }
1501 else
1502 sv_catpv(linestr,"@F=split(' ');");
1503 }
79072805 1504 }
a0d0e21e 1505 sv_catpv(linestr, "\n");
fd049845 1506 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
463ee0b2 1507 bufend = SvPVX(linestr) + SvCUR(linestr);
a0d0e21e
LW
1508 if (perldb && curstash != debstash) {
1509 SV *sv = NEWSV(85,0);
1510
1511 sv_upgrade(sv, SVt_PVMG);
1512 sv_setsv(sv,linestr);
1513 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
1514 }
79072805 1515 goto retry;
a687059c 1516 }
e929a76b 1517 do {
fd049845 1518 if ((s = filter_gets(linestr, rsfp, 0)) == Nullch) {
e929a76b 1519 fake_eof:
395c3793 1520 if (rsfp) {
a0d0e21e 1521 if (preprocess && !in_eval)
79072805 1522 (void)my_pclose(rsfp);
760ac839
LW
1523 else if ((PerlIO *)rsfp == PerlIO_stdin())
1524 PerlIO_clearerr(rsfp);
395c3793 1525 else
760ac839 1526 (void)PerlIO_close(rsfp);
395c3793
LW
1527 rsfp = Nullfp;
1528 }
a0d0e21e 1529 if (!in_eval && (minus_n || minus_p)) {
79072805
LW
1530 sv_setpv(linestr,minus_p ? ";}continue{print" : "");
1531 sv_catpv(linestr,";}");
fd049845 1532 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
463ee0b2 1533 bufend = SvPVX(linestr) + SvCUR(linestr);
e929a76b
LW
1534 minus_n = minus_p = 0;
1535 goto retry;
1536 }
fd049845 1537 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
79072805
LW
1538 sv_setpv(linestr,"");
1539 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
378cc40b 1540 }
a0d0e21e
LW
1541 if (doextract) {
1542 if (*s == '#' && s[1] == '!' && instr(s,"perl"))
1543 doextract = FALSE;
1544
1545 /* Incest with pod. */
1546 if (*s == '=' && strnEQ(s, "=cut", 4)) {
1547 sv_setpv(linestr, "");
fd049845 1548 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
a0d0e21e
LW
1549 bufend = SvPVX(linestr) + SvCUR(linestr);
1550 doextract = FALSE;
1551 }
1552 }
463ee0b2 1553 incline(s);
e929a76b 1554 } while (doextract);
fd049845 1555 oldoldbufptr = oldbufptr = bufptr = linestart = s;
8990e307 1556 if (perldb && curstash != debstash) {
79072805 1557 SV *sv = NEWSV(85,0);
a687059c 1558
93a17b20 1559 sv_upgrade(sv, SVt_PVMG);
79072805
LW
1560 sv_setsv(sv,linestr);
1561 av_store(GvAV(curcop->cop_filegv),(I32)curcop->cop_line,sv);
a687059c 1562 }
463ee0b2 1563 bufend = SvPVX(linestr) + SvCUR(linestr);
79072805
LW
1564 if (curcop->cop_line == 1) {
1565 while (s < bufend && isSPACE(*s))
1566 s++;
a0d0e21e 1567 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
79072805 1568 s++;
44a8e56a
PP
1569 d = Nullch;
1570 if (!in_eval) {
1571 if (*s == '#' && *(s+1) == '!')
1572 d = s + 2;
1573#ifdef ALTERNATE_SHEBANG
1574 else {
1575 static char as[] = ALTERNATE_SHEBANG;
1576 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
1577 d = s + (sizeof(as) - 1);
1578 }
1579#endif /* ALTERNATE_SHEBANG */
1580 }
1581 if (d) {
8ebc5c01 1582 /*
b8378b72
CS
1583 * HP-UX (at least) sets argv[0] to the script name,
1584 * which makes $^X incorrect. And Digital UNIX and Linux,
1585 * at least, set argv[0] to the basename of the Perl
1586 * interpreter. So, having found "#!", we'll set it right.
8ebc5c01 1587 */
b8378b72
CS
1588 SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV));
1589 char *ipath;
1590 char *ibase;
1591
b8378b72
CS
1592 while (*d == ' ' || *d == '\t')
1593 d++;
1594 ipath = d;
1595 ibase = Nullch;
1596 while (*d && !isSPACE(*d)) {
1597 if (*d++ == '/')
1598 ibase = d;
8ebc5c01 1599 }
b8378b72
CS
1600 assert(SvPOK(x) || SvGMAGICAL(x));
1601 if (sv_eq(x, GvSV(curcop->cop_filegv))
1602 || (ibase
1603 && SvCUR(x) == (d - ibase)
1604 && strnEQ(SvPVX(x), ibase, d - ibase)))
1605 sv_setpvn(x, ipath, d - ipath);
1606 /*
1607 * $^X is always tainted, but taintedness must be off
1608 * when parsing code, so forget we ever saw it.
1609 */
1610 TAINT_NOT;
1611
1612 /*
1613 * Look for options.
1614 */
748a9306
LW
1615 d = instr(s,"perl -");
1616 if (!d)
1617 d = instr(s,"perl");
44a8e56a
PP
1618#ifdef ALTERNATE_SHEBANG
1619 /*
1620 * If the ALTERNATE_SHEBANG on this system starts with a
1621 * character that can be part of a Perl expression, then if
1622 * we see it but not "perl", we're probably looking at the
1623 * start of Perl code, not a request to hand off to some
1624 * other interpreter. Similarly, if "perl" is there, but
1625 * not in the first 'word' of the line, we assume the line
1626 * contains the start of the Perl program.
1627 * This isn't foolproof, but it's generally a good guess.
1628 */
1629 if (d && *s != '#') {
1630 char *c = s;
1631 while (*c && !strchr("; \t\r\n\f\v#", *c))
1632 c++;
1633 if (c < d)
1634 d = Nullch; /* "perl" not in first word; ignore */
1635 else
1636 *s = '#'; /* Don't try to parse shebang line */
1637 }
1638#endif
748a9306 1639 if (!d &&
44a8e56a 1640 *s == '#' &&
748a9306
LW
1641 !minus_c &&
1642 !instr(s,"indir") &&
1643 instr(origargv[0],"perl"))
1644 {
9f68db38
LW
1645 char **newargv;
1646 char *cmd;
1647
1648 s += 2;
1649 if (*s == ' ')
1650 s++;
1651 cmd = s;
de3bb511 1652 while (s < bufend && !isSPACE(*s))
9f68db38
LW
1653 s++;
1654 *s++ = '\0';
de3bb511 1655 while (s < bufend && isSPACE(*s))
9f68db38
LW
1656 s++;
1657 if (s < bufend) {
1658 Newz(899,newargv,origargc+3,char*);
1659 newargv[1] = s;
de3bb511 1660 while (s < bufend && !isSPACE(*s))
9f68db38
LW
1661 s++;
1662 *s = '\0';
1663 Copy(origargv+1, newargv+2, origargc+1, char*);
1664 }
1665 else
1666 newargv = origargv;
1667 newargv[0] = cmd;
1668 execv(cmd,newargv);
463ee0b2 1669 croak("Can't exec %s", cmd);
9f68db38 1670 }
748a9306 1671 if (d) {
a0d0e21e
LW
1672 int oldpdb = perldb;
1673 int oldn = minus_n;
1674 int oldp = minus_p;
748a9306
LW
1675
1676 while (*d && !isSPACE(*d)) d++;
89bfa8cd 1677 while (*d == ' ' || *d == '\t') d++;
748a9306
LW
1678
1679 if (*d++ == '-') {
1680 while (d = moreswitches(d)) ;
1681 if (perldb && !oldpdb ||
b084f20b
PP
1682 ( minus_n || minus_p ) && !(oldn || oldp) )
1683 /* if we have already added "LINE: while (<>) {",
1684 we must not do it again */
748a9306
LW
1685 {
1686 sv_setpv(linestr, "");
fd049845 1687 oldoldbufptr = oldbufptr = s = linestart = SvPVX(linestr);
748a9306
LW
1688 bufend = SvPVX(linestr) + SvCUR(linestr);
1689 preambled = FALSE;
1690 if (perldb)
1691 (void)gv_fetchfile(origfilename);
1692 goto retry;
1693 }
a0d0e21e 1694 }
79072805 1695 }
9f68db38 1696 }
79072805 1697 }
85e6fe83 1698 if (lex_formbrack && lex_brackets <= lex_formbrack) {
a0d0e21e
LW
1699 bufptr = s;
1700 lex_state = LEX_FORMLINE;
1701 return yylex();
ae986130 1702 }
378cc40b 1703 goto retry;
fe14fcc3 1704 case ' ': case '\t': case '\f': case '\r': 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\" =>",
1739 tmp, tmp);
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:
748a9306 1774 croak("Unrecognized file test: -%c", 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
LW
2067 if (dowarn && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
2068 warn("Reversed %c= operator",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) {
a0d0e21e
LW
3879 if (strEQ(d,"LT")) { deprecate(d); return -KEY_lt;}
3880 if (strEQ(d,"LE")) { deprecate(d); return -KEY_le;}
378cc40b 3881 }
79072805
LW
3882 break;
3883 case 'l':
3884 switch (len) {
3885 case 2:
a0d0e21e
LW
3886 if (strEQ(d,"lt")) return -KEY_lt;
3887 if (strEQ(d,"le")) return -KEY_le;
3888 if (strEQ(d,"lc")) return -KEY_lc;
79072805
LW
3889 break;
3890 case 3:
a0d0e21e 3891 if (strEQ(d,"log")) return -KEY_log;
79072805
LW
3892<