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