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