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