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