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