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