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