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