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