This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 3.0 patch #44 patch #42, continued
[perl5.git] / perl.y
CommitLineData
27e2fb84 1/* $Header: perl.y,v 3.0.1.11 91/01/11 21:57:40 lwall Locked $
a687059c
LW
2 *
3 * Copyright (c) 1989, Larry Wall
4 *
5 * You may distribute under the terms of the GNU General Public License
6 * as specified in the README file that comes with the perl 3.0 kit.
8d063cd8
LW
7 *
8 * $Log: perl.y,v $
27e2fb84
LW
9 * Revision 3.0.1.11 91/01/11 21:57:40 lwall
10 * patch42: addendum
11 *
c623bd54
LW
12 * Revision 3.0.1.10 91/01/11 18:14:28 lwall
13 * patch42: package didn't create symbol tables that could be reset
14 * patch42: split with no arguments could wipe out next operator
15 *
d9d8d8de
LW
16 * Revision 3.0.1.9 90/10/15 18:01:45 lwall
17 * patch29: added SysV IPC
18 * patch29: package behavior is now more consistent
19 * patch29: index and substr now have optional 3rd args
20 *
6eb13c3b
LW
21 * Revision 3.0.1.8 90/08/13 22:19:55 lwall
22 * patch28: lowercase unquoted strings caused infinite loop
23 *
450a55e4
LW
24 * Revision 3.0.1.7 90/08/09 04:17:44 lwall
25 * patch19: did preliminary work toward debugging packages and evals
26 * patch19: added require operator
27 * patch19: bare identifiers are now strings if no other interpretation possible
28 * patch19: null-label lines threw off line number of next statement
29 * patch19: split; didn't pass correct bufend to scanpat
30 *
0f85fab0
LW
31 * Revision 3.0.1.6 90/03/27 16:13:45 lwall
32 * patch16: formats didn't work inside eval
33 *
79a0689e
LW
34 * Revision 3.0.1.5 90/03/12 16:55:56 lwall
35 * patch13: added list slice operator (LIST)[LIST]
36 * patch13: (LIST,) now legal
37 *
ac58e20f
LW
38 * Revision 3.0.1.4 90/02/28 18:03:23 lwall
39 * patch9: line numbers were bogus during certain portions of foreach evaluation
40 *
663a0e37
LW
41 * Revision 3.0.1.3 89/12/21 20:13:41 lwall
42 * patch7: send() didn't allow a TO argument
43 *
ae986130
LW
44 * Revision 3.0.1.2 89/11/11 04:49:04 lwall
45 * patch2: moved yydebug to where its type doesn't matter
46 * patch2: !$foo++ was unreasonably illegal
47 * patch2: local(@foo) didn't work
48 * patch2: default args to unary operators didn't work
49 *
03a14243
LW
50 * Revision 3.0.1.1 89/10/26 23:20:41 lwall
51 * patch1: grandfathered "format stdout"
52 * patch1: operator(); is now normally equivalent to operator;
53 *
a687059c
LW
54 * Revision 3.0 89/10/18 15:22:04 lwall
55 * 3.0 baseline
8d063cd8
LW
56 *
57 */
58
59%{
8d063cd8
LW
60#include "INTERN.h"
61#include "perl.h"
378cc40b 62
378cc40b 63STAB *scrstab;
a687059c
LW
64ARG *arg4; /* rarely used arguments to make_op() */
65ARG *arg5;
378cc40b 66
8d063cd8
LW
67%}
68
69%start prog
70
71%union {
72 int ival;
73 char *cval;
74 ARG *arg;
75 CMD *cmdval;
76 struct compcmd compval;
77 STAB *stabval;
78 FCMD *formval;
79}
80
81%token <cval> WORD
450a55e4 82%token <ival> APPEND OPEN SSELECT LOOPEX
378cc40b 83%token <ival> USING FORMAT DO SHIFT PUSH POP LVALFUN
a687059c
LW
84%token <ival> WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE SPLIT FLIST
85%token <ival> FOR FILOP FILOP2 FILOP3 FILOP4 FILOP22 FILOP25
d9d8d8de 86%token <ival> FUNC0 FUNC1 FUNC2 FUNC2x FUNC3 FUNC4 FUNC5 HSHFUN HSHFUN3
a687059c 87%token <ival> FLIST2 SUB FILETEST LOCAL DELETE
d9d8d8de 88%token <ival> RELOP EQOP MULOP ADDOP PACKAGE AMPER
8d063cd8 89%token <formval> FORMLIST
a687059c 90%token <stabval> REG ARYLEN ARY HSH STAR
8d063cd8
LW
91%token <arg> SUBST PATTERN
92%token <arg> RSTRING TRANS
93
a687059c 94%type <ival> prog decl format remember
8d063cd8 95%type <cmdval> block lineseq line loop cond sideff nexpr else
a687059c 96%type <arg> expr sexpr cexpr csexpr term handle aryword hshword
450a55e4 97%type <arg> texpr listop bareword
8d063cd8
LW
98%type <cval> label
99%type <compval> compblock
100
378cc40b 101%nonassoc <ival> LISTOP
8d063cd8 102%left ','
8d063cd8
LW
103%right '='
104%right '?' ':'
105%nonassoc DOTDOT
106%left OROR
107%left ANDAND
108%left '|' '^'
109%left '&'
a687059c
LW
110%nonassoc EQOP
111%nonassoc RELOP
378cc40b
LW
112%nonassoc <ival> UNIOP
113%nonassoc FILETEST
8d063cd8 114%left LS RS
a687059c
LW
115%left ADDOP
116%left MULOP
8d063cd8
LW
117%left MATCH NMATCH
118%right '!' '~' UMINUS
a687059c 119%right POW
8d063cd8
LW
120%nonassoc INC DEC
121%left '('
122
123%% /* RULES */
124
ae986130
LW
125prog : /* NULL */
126 {
127#if defined(YYDEBUG) && defined(DEBUGGING)
128 yydebug = (debug & 1);
129#endif
130 }
131 /*CONTINUED*/ lineseq
a559c259 132 { if (in_eval)
ae986130 133 eval_root = block_head($2);
a559c259 134 else
ae986130 135 main_root = block_head($2); }
8d063cd8
LW
136 ;
137
138compblock: block CONTINUE block
139 { $$.comp_true = $1; $$.comp_alt = $3; }
140 | block else
141 { $$.comp_true = $1; $$.comp_alt = $2; }
142 ;
143
144else : /* NULL */
145 { $$ = Nullcmd; }
146 | ELSE block
147 { $$ = $2; }
148 | ELSIF '(' expr ')' compblock
378cc40b 149 { cmdline = $1;
a687059c 150 $$ = make_ccmd(C_ELSIF,$3,$5); }
8d063cd8
LW
151 ;
152
a687059c
LW
153block : '{' remember lineseq '}'
154 { $$ = block_head($3);
155 if (savestack->ary_fill > $2)
156 restorelist($2); }
157 ;
158
159remember: /* NULL */ /* in case they push a package name */
160 { $$ = savestack->ary_fill; }
8d063cd8
LW
161 ;
162
163lineseq : /* NULL */
164 { $$ = Nullcmd; }
165 | lineseq line
166 { $$ = append_line($1,$2); }
167 ;
168
169line : decl
170 { $$ = Nullcmd; }
171 | label cond
172 { $$ = add_label($1,$2); }
173 | loop /* loops add their own labels */
174 | label ';'
175 { if ($1 != Nullch) {
378cc40b 176 $$ = add_label($1, make_acmd(C_EXPR, Nullstab,
8d063cd8 177 Nullarg, Nullarg) );
450a55e4
LW
178 }
179 else {
180 $$ = Nullcmd;
181 cmdline = NOLINE;
182 } }
8d063cd8
LW
183 | label sideff ';'
184 { $$ = add_label($1,$2); }
185 ;
186
a687059c
LW
187sideff : error
188 { $$ = Nullcmd; }
189 | expr
8d063cd8 190 { $$ = make_acmd(C_EXPR, Nullstab, $1, Nullarg); }
a687059c 191 | expr IF expr
8d063cd8 192 { $$ = addcond(
a687059c
LW
193 make_acmd(C_EXPR, Nullstab, Nullarg, $1), $3); }
194 | expr UNLESS expr
195 { $$ = addcond(invert(
196 make_acmd(C_EXPR, Nullstab, Nullarg, $1)), $3); }
197 | expr WHILE expr
8d063cd8 198 { $$ = addloop(
a687059c
LW
199 make_acmd(C_EXPR, Nullstab, Nullarg, $1), $3); }
200 | expr UNTIL expr
201 { $$ = addloop(invert(
202 make_acmd(C_EXPR, Nullstab, Nullarg, $1)), $3); }
8d063cd8
LW
203 ;
204
205cond : IF '(' expr ')' compblock
378cc40b 206 { cmdline = $1;
a687059c 207 $$ = make_icmd(C_IF,$3,$5); }
8d063cd8 208 | UNLESS '(' expr ')' compblock
378cc40b 209 { cmdline = $1;
a687059c 210 $$ = invert(make_icmd(C_IF,$3,$5)); }
8d063cd8 211 | IF block compblock
378cc40b
LW
212 { cmdline = $1;
213 $$ = make_ccmd(C_IF,cmd_to_arg($2),$3); }
8d063cd8 214 | UNLESS block compblock
378cc40b
LW
215 { cmdline = $1;
216 $$ = invert(make_ccmd(C_IF,cmd_to_arg($2),$3)); }
8d063cd8
LW
217 ;
218
219loop : label WHILE '(' texpr ')' compblock
378cc40b
LW
220 { cmdline = $2;
221 $$ = wopt(add_label($1,
8d063cd8
LW
222 make_ccmd(C_WHILE,$4,$6) )); }
223 | label UNTIL '(' expr ')' compblock
378cc40b
LW
224 { cmdline = $2;
225 $$ = wopt(add_label($1,
8d063cd8
LW
226 invert(make_ccmd(C_WHILE,$4,$6)) )); }
227 | label WHILE block compblock
378cc40b
LW
228 { cmdline = $2;
229 $$ = wopt(add_label($1,
8d063cd8
LW
230 make_ccmd(C_WHILE, cmd_to_arg($3),$4) )); }
231 | label UNTIL block compblock
378cc40b
LW
232 { cmdline = $2;
233 $$ = wopt(add_label($1,
8d063cd8 234 invert(make_ccmd(C_WHILE, cmd_to_arg($3),$4)) )); }
378cc40b
LW
235 | label FOR REG '(' expr ')' compblock
236 { cmdline = $2;
237 /*
238 * The following gobbledygook catches EXPRs that
239 * aren't explicit array refs and translates
240 * foreach VAR (EXPR) {
241 * into
242 * @ary = EXPR;
243 * foreach VAR (@ary) {
244 * where @ary is a hidden array made by genstab().
a687059c
LW
245 * (Note that @ary may become a local array if
246 * it is determined that it might be called
247 * recursively. See cmd_tosave().)
378cc40b
LW
248 */
249 if ($5->arg_type != O_ARRAY) {
250 scrstab = aadd(genstab());
251 $$ = append_line(
252 make_acmd(C_EXPR, Nullstab,
253 l(make_op(O_ASSIGN,2,
254 listish(make_op(O_ARRAY, 1,
255 stab2arg(A_STAB,scrstab),
450a55e4 256 Nullarg,Nullarg )),
a687059c
LW
257 listish(make_list($5)),
258 Nullarg)),
378cc40b
LW
259 Nullarg),
260 wopt(over($3,add_label($1,
261 make_ccmd(C_WHILE,
262 make_op(O_ARRAY, 1,
263 stab2arg(A_STAB,scrstab),
a687059c 264 Nullarg,Nullarg ),
378cc40b 265 $7)))));
ac58e20f
LW
266 $$->c_line = $2;
267 $$->c_head->c_line = $2;
378cc40b
LW
268 }
269 else {
270 $$ = wopt(over($3,add_label($1,
271 make_ccmd(C_WHILE,$5,$7) )));
272 }
273 }
274 | label FOR '(' expr ')' compblock
275 { cmdline = $2;
276 if ($4->arg_type != O_ARRAY) {
277 scrstab = aadd(genstab());
278 $$ = append_line(
279 make_acmd(C_EXPR, Nullstab,
280 l(make_op(O_ASSIGN,2,
281 listish(make_op(O_ARRAY, 1,
282 stab2arg(A_STAB,scrstab),
450a55e4 283 Nullarg,Nullarg )),
a687059c
LW
284 listish(make_list($4)),
285 Nullarg)),
378cc40b
LW
286 Nullarg),
287 wopt(over(defstab,add_label($1,
288 make_ccmd(C_WHILE,
289 make_op(O_ARRAY, 1,
290 stab2arg(A_STAB,scrstab),
a687059c 291 Nullarg,Nullarg ),
378cc40b 292 $6)))));
ac58e20f
LW
293 $$->c_line = $2;
294 $$->c_head->c_line = $2;
378cc40b
LW
295 }
296 else { /* lisp, anyone? */
297 $$ = wopt(over(defstab,add_label($1,
298 make_ccmd(C_WHILE,$4,$6) )));
299 }
300 }
8d063cd8
LW
301 | label FOR '(' nexpr ';' texpr ';' nexpr ')' block
302 /* basically fake up an initialize-while lineseq */
303 { yyval.compval.comp_true = $10;
304 yyval.compval.comp_alt = $8;
378cc40b 305 cmdline = $2;
8d063cd8
LW
306 $$ = append_line($4,wopt(add_label($1,
307 make_ccmd(C_WHILE,$6,yyval.compval) ))); }
308 | label compblock /* a block is a loop that happens once */
309 { $$ = add_label($1,make_ccmd(C_BLOCK,Nullarg,$2)); }
310 ;
311
312nexpr : /* NULL */
313 { $$ = Nullcmd; }
314 | sideff
315 ;
316
317texpr : /* NULL means true */
a687059c 318 { (void)scanstr("1"); $$ = yylval.arg; }
8d063cd8
LW
319 | expr
320 ;
321
322label : /* empty */
323 { $$ = Nullch; }
324 | WORD ':'
325 ;
326
8d063cd8
LW
327decl : format
328 { $$ = 0; }
329 | subrout
330 { $$ = 0; }
a687059c
LW
331 | package
332 { $$ = 0; }
8d063cd8
LW
333 ;
334
a687059c 335format : FORMAT WORD '=' FORMLIST
03a14243 336 { if (strEQ($2,"stdout"))
0f85fab0 337 make_form(stabent("STDOUT",TRUE),$4);
03a14243 338 else if (strEQ($2,"stderr"))
0f85fab0 339 make_form(stabent("STDERR",TRUE),$4);
03a14243 340 else
0f85fab0 341 make_form(stabent($2,TRUE),$4);
03a14243 342 Safefree($2);}
a687059c 343 | FORMAT '=' FORMLIST
0f85fab0 344 { make_form(stabent("STDOUT",TRUE),$3); }
8d063cd8
LW
345 ;
346
347subrout : SUB WORD block
378cc40b 348 { make_sub($2,$3); }
8d063cd8
LW
349 ;
350
a687059c
LW
351package : PACKAGE WORD ';'
352 { char tmpbuf[256];
450a55e4 353 STAB *tmpstab;
a687059c
LW
354
355 savehptr(&curstash);
356 saveitem(curstname);
357 str_set(curstname,$2);
358 sprintf(tmpbuf,"'_%s",$2);
c623bd54
LW
359 tmpstab = stabent(tmpbuf,TRUE);
360 if (!stab_xhash(tmpstab))
361 stab_xhash(tmpstab) = hnew(0);
450a55e4 362 curstash = stab_xhash(tmpstab);
d9d8d8de
LW
363 if (!curstash->tbl_name)
364 curstash->tbl_name = savestr($2);
a687059c
LW
365 curstash->tbl_coeffsize = 0;
366 Safefree($2);
d9d8d8de 367 cmdline = NOLINE;
a687059c
LW
368 }
369 ;
370
371cexpr : ',' expr
372 { $$ = $2; }
373 ;
374
375expr : expr ',' sexpr
376 { $$ = make_op(O_COMMA, 2, $1, $3, Nullarg); }
8d063cd8
LW
377 | sexpr
378 ;
379
a687059c
LW
380csexpr : ',' sexpr
381 { $$ = $2; }
382 ;
383
8d063cd8
LW
384sexpr : sexpr '=' sexpr
385 { $1 = listish($1);
a687059c
LW
386 if ($1->arg_type == O_ASSIGN && $1->arg_len == 1)
387 $1->arg_type = O_ITEM; /* a local() */
8d063cd8
LW
388 if ($1->arg_type == O_LIST)
389 $3 = listish($3);
a687059c
LW
390 $$ = l(make_op(O_ASSIGN, 2, $1, $3, Nullarg)); }
391 | sexpr POW '=' sexpr
392 { $$ = l(make_op(O_POW, 2, $1, $4, Nullarg)); }
393 | sexpr MULOP '=' sexpr
394 { $$ = l(make_op($2, 2, $1, $4, Nullarg)); }
395 | sexpr ADDOP '=' sexpr
396 { $$ = rcatmaybe(l(make_op($2, 2, $1, $4, Nullarg)));}
8d063cd8 397 | sexpr LS '=' sexpr
a687059c 398 { $$ = l(make_op(O_LEFT_SHIFT, 2, $1, $4, Nullarg)); }
8d063cd8 399 | sexpr RS '=' sexpr
a687059c 400 { $$ = l(make_op(O_RIGHT_SHIFT, 2, $1, $4, Nullarg)); }
8d063cd8 401 | sexpr '&' '=' sexpr
a687059c 402 { $$ = l(make_op(O_BIT_AND, 2, $1, $4, Nullarg)); }
8d063cd8 403 | sexpr '^' '=' sexpr
a687059c 404 { $$ = l(make_op(O_XOR, 2, $1, $4, Nullarg)); }
8d063cd8 405 | sexpr '|' '=' sexpr
a687059c
LW
406 { $$ = l(make_op(O_BIT_OR, 2, $1, $4, Nullarg)); }
407
408
409 | sexpr POW sexpr
410 { $$ = make_op(O_POW, 2, $1, $3, Nullarg); }
411 | sexpr MULOP sexpr
412 { $$ = make_op($2, 2, $1, $3, Nullarg); }
413 | sexpr ADDOP sexpr
414 { $$ = make_op($2, 2, $1, $3, Nullarg); }
8d063cd8 415 | sexpr LS sexpr
a687059c 416 { $$ = make_op(O_LEFT_SHIFT, 2, $1, $3, Nullarg); }
8d063cd8 417 | sexpr RS sexpr
a687059c
LW
418 { $$ = make_op(O_RIGHT_SHIFT, 2, $1, $3, Nullarg); }
419 | sexpr RELOP sexpr
420 { $$ = make_op($2, 2, $1, $3, Nullarg); }
421 | sexpr EQOP sexpr
422 { $$ = make_op($2, 2, $1, $3, Nullarg); }
8d063cd8 423 | sexpr '&' sexpr
a687059c 424 { $$ = make_op(O_BIT_AND, 2, $1, $3, Nullarg); }
8d063cd8 425 | sexpr '^' sexpr
a687059c 426 { $$ = make_op(O_XOR, 2, $1, $3, Nullarg); }
8d063cd8 427 | sexpr '|' sexpr
a687059c 428 { $$ = make_op(O_BIT_OR, 2, $1, $3, Nullarg); }
8d063cd8 429 | sexpr DOTDOT sexpr
a687059c
LW
430 { arg4 = Nullarg;
431 $$ = make_op(O_F_OR_R, 4, $1, $3, Nullarg); }
8d063cd8 432 | sexpr ANDAND sexpr
a687059c 433 { $$ = make_op(O_AND, 2, $1, $3, Nullarg); }
8d063cd8 434 | sexpr OROR sexpr
a687059c 435 { $$ = make_op(O_OR, 2, $1, $3, Nullarg); }
8d063cd8 436 | sexpr '?' sexpr ':' sexpr
a687059c 437 { $$ = make_op(O_COND_EXPR, 3, $1, $3, $5); }
8d063cd8
LW
438 | sexpr MATCH sexpr
439 { $$ = mod_match(O_MATCH, $1, $3); }
440 | sexpr NMATCH sexpr
441 { $$ = mod_match(O_NMATCH, $1, $3); }
8d063cd8
LW
442 | term
443 { $$ = $1; }
444 ;
445
446term : '-' term %prec UMINUS
a687059c
LW
447 { $$ = make_op(O_NEGATE, 1, $2, Nullarg, Nullarg); }
448 | '+' term %prec UMINUS
449 { $$ = $2; }
8d063cd8 450 | '!' term
a687059c 451 { $$ = make_op(O_NOT, 1, $2, Nullarg, Nullarg); }
8d063cd8 452 | '~' term
a687059c 453 { $$ = make_op(O_COMPLEMENT, 1, $2, Nullarg, Nullarg);}
ae986130
LW
454 | term INC
455 { $$ = addflags(1, AF_POST|AF_UP,
456 l(make_op(O_ITEM,1,$1,Nullarg,Nullarg))); }
457 | term DEC
458 { $$ = addflags(1, AF_POST,
459 l(make_op(O_ITEM,1,$1,Nullarg,Nullarg))); }
460 | INC term
461 { $$ = addflags(1, AF_PRE|AF_UP,
462 l(make_op(O_ITEM,1,$2,Nullarg,Nullarg))); }
463 | DEC term
464 { $$ = addflags(1, AF_PRE,
465 l(make_op(O_ITEM,1,$2,Nullarg,Nullarg))); }
378cc40b
LW
466 | FILETEST WORD
467 { opargs[$1] = 0; /* force it special */
468 $$ = make_op($1, 1,
469 stab2arg(A_STAB,stabent($2,TRUE)),
a687059c 470 Nullarg, Nullarg);
378cc40b
LW
471 }
472 | FILETEST sexpr
473 { opargs[$1] = 1;
a687059c 474 $$ = make_op($1, 1, $2, Nullarg, Nullarg); }
378cc40b
LW
475 | FILETEST
476 { opargs[$1] = ($1 != O_FTTTY);
477 $$ = make_op($1, 1,
478 stab2arg(A_STAB,
a687059c
LW
479 $1 == O_FTTTY?stabent("STDIN",TRUE):defstab),
480 Nullarg, Nullarg); }
378cc40b 481 | LOCAL '(' expr ')'
ae986130 482 { $$ = l(localize(make_op(O_ASSIGN, 1,
a687059c 483 localize(listish(make_list($3))),
ae986130 484 Nullarg,Nullarg))); }
79a0689e
LW
485 | '(' expr ',' ')'
486 { $$ = make_list(hide_ary($2)); }
8d063cd8
LW
487 | '(' expr ')'
488 { $$ = make_list(hide_ary($2)); }
489 | '(' ')'
490 { $$ = make_list(Nullarg); }
378cc40b 491 | DO sexpr %prec FILETEST
d9d8d8de 492 { $$ = make_op(O_DOFILE,2,$2,Nullarg,Nullarg);
a687059c 493 allstabs = TRUE;}
8d063cd8
LW
494 | DO block %prec '('
495 { $$ = cmd_to_arg($2); }
496 | REG %prec '('
378cc40b 497 { $$ = stab2arg(A_STAB,$1); }
a687059c
LW
498 | STAR %prec '('
499 { $$ = stab2arg(A_STAR,$1); }
8d063cd8 500 | REG '[' expr ']' %prec '('
a687059c
LW
501 { $$ = make_op(O_AELEM, 2,
502 stab2arg(A_STAB,aadd($1)), $3, Nullarg); }
503 | HSH %prec '('
504 { $$ = make_op(O_HASH, 1,
505 stab2arg(A_STAB,$1),
506 Nullarg, Nullarg); }
8d063cd8
LW
507 | ARY %prec '('
508 { $$ = make_op(O_ARRAY, 1,
378cc40b 509 stab2arg(A_STAB,$1),
a687059c 510 Nullarg, Nullarg); }
8d063cd8 511 | REG '{' expr '}' %prec '('
a687059c
LW
512 { $$ = make_op(O_HELEM, 2,
513 stab2arg(A_STAB,hadd($1)),
514 jmaybe($3),
515 Nullarg); }
79a0689e
LW
516 | '(' expr ')' '[' expr ']' %prec '('
517 { $$ = make_op(O_LSLICE, 3,
518 Nullarg,
519 listish(make_list($5)),
520 listish(make_list($2))); }
a687059c
LW
521 | ARY '[' expr ']' %prec '('
522 { $$ = make_op(O_ASLICE, 2,
523 stab2arg(A_STAB,aadd($1)),
524 listish(make_list($3)),
525 Nullarg); }
526 | ARY '{' expr '}' %prec '('
527 { $$ = make_op(O_HSLICE, 2,
528 stab2arg(A_STAB,hadd($1)),
529 listish(make_list($3)),
530 Nullarg); }
378cc40b
LW
531 | DELETE REG '{' expr '}' %prec '('
532 { $$ = make_op(O_DELETE, 2,
a687059c
LW
533 stab2arg(A_STAB,hadd($2)),
534 jmaybe($4),
535 Nullarg); }
8d063cd8 536 | ARYLEN %prec '('
378cc40b 537 { $$ = stab2arg(A_ARYLEN,$1); }
8d063cd8
LW
538 | RSTRING %prec '('
539 { $$ = $1; }
540 | PATTERN %prec '('
541 { $$ = $1; }
542 | SUBST %prec '('
543 { $$ = $1; }
544 | TRANS %prec '('
545 { $$ = $1; }
546 | DO WORD '(' expr ')'
a687059c
LW
547 { $$ = make_op((perldb ? O_DBSUBR : O_SUBR), 2,
548 stab2arg(A_WORD,stabent($2,TRUE)),
8d063cd8 549 make_list($4),
a687059c
LW
550 Nullarg); Safefree($2); }
551 | AMPER WORD '(' expr ')'
552 { $$ = make_op((perldb ? O_DBSUBR : O_SUBR), 2,
378cc40b 553 stab2arg(A_WORD,stabent($2,TRUE)),
a687059c
LW
554 make_list($4),
555 Nullarg); Safefree($2); }
8d063cd8 556 | DO WORD '(' ')'
a687059c
LW
557 { $$ = make_op((perldb ? O_DBSUBR : O_SUBR), 2,
558 stab2arg(A_WORD,stabent($2,TRUE)),
8d063cd8 559 make_list(Nullarg),
a687059c
LW
560 Nullarg); }
561 | AMPER WORD '(' ')'
562 { $$ = make_op((perldb ? O_DBSUBR : O_SUBR), 2,
378cc40b 563 stab2arg(A_WORD,stabent($2,TRUE)),
a687059c
LW
564 make_list(Nullarg),
565 Nullarg); }
566 | AMPER WORD
567 { $$ = make_op((perldb ? O_DBSUBR : O_SUBR), 2,
568 stab2arg(A_WORD,stabent($2,TRUE)),
569 Nullarg,
570 Nullarg); }
378cc40b 571 | DO REG '(' expr ')'
a687059c
LW
572 { $$ = make_op((perldb ? O_DBSUBR : O_SUBR), 2,
573 stab2arg(A_STAB,$2),
378cc40b 574 make_list($4),
a687059c
LW
575 Nullarg); }
576 | AMPER REG '(' expr ')'
577 { $$ = make_op((perldb ? O_DBSUBR : O_SUBR), 2,
378cc40b 578 stab2arg(A_STAB,$2),
a687059c
LW
579 make_list($4),
580 Nullarg); }
378cc40b 581 | DO REG '(' ')'
a687059c
LW
582 { $$ = make_op((perldb ? O_DBSUBR : O_SUBR), 2,
583 stab2arg(A_STAB,$2),
378cc40b 584 make_list(Nullarg),
a687059c
LW
585 Nullarg); }
586 | AMPER REG '(' ')'
587 { $$ = make_op((perldb ? O_DBSUBR : O_SUBR), 2,
378cc40b 588 stab2arg(A_STAB,$2),
a687059c
LW
589 make_list(Nullarg),
590 Nullarg); }
591 | AMPER REG
592 { $$ = make_op((perldb ? O_DBSUBR : O_SUBR), 2,
593 stab2arg(A_STAB,$2),
594 Nullarg,
595 Nullarg); }
8d063cd8 596 | LOOPEX
a687059c 597 { $$ = make_op($1,0,Nullarg,Nullarg,Nullarg); }
8d063cd8
LW
598 | LOOPEX WORD
599 { $$ = make_op($1,1,cval_to_arg($2),
a687059c 600 Nullarg,Nullarg); }
8d063cd8 601 | UNIOP
d9d8d8de 602 { $$ = make_op($1,0,Nullarg,Nullarg,Nullarg); }
8d063cd8 603 | UNIOP sexpr
d9d8d8de 604 { $$ = make_op($1,1,$2,Nullarg,Nullarg); }
450a55e4 605 | SSELECT
a687059c 606 { $$ = make_op(O_SELECT, 0, Nullarg, Nullarg, Nullarg);}
450a55e4 607 | SSELECT '(' handle ')'
a687059c 608 { $$ = make_op(O_SELECT, 1, $3, Nullarg, Nullarg); }
450a55e4 609 | SSELECT '(' sexpr csexpr csexpr csexpr ')'
a687059c
LW
610 { arg4 = $6;
611 $$ = make_op(O_SSELECT, 4, $3, $4, $5); }
8d063cd8
LW
612 | OPEN WORD %prec '('
613 { $$ = make_op(O_OPEN, 2,
378cc40b
LW
614 stab2arg(A_WORD,stabent($2,TRUE)),
615 stab2arg(A_STAB,stabent($2,TRUE)),
a687059c 616 Nullarg); }
8d063cd8
LW
617 | OPEN '(' WORD ')'
618 { $$ = make_op(O_OPEN, 2,
378cc40b
LW
619 stab2arg(A_WORD,stabent($3,TRUE)),
620 stab2arg(A_STAB,stabent($3,TRUE)),
a687059c
LW
621 Nullarg); }
622 | OPEN '(' handle cexpr ')'
378cc40b
LW
623 { $$ = make_op(O_OPEN, 2,
624 $3,
a687059c
LW
625 $4, Nullarg); }
626 | FILOP '(' handle ')'
627 { $$ = make_op($1, 1,
378cc40b 628 $3,
a687059c
LW
629 Nullarg, Nullarg); }
630 | FILOP WORD
631 { $$ = make_op($1, 1,
378cc40b 632 stab2arg(A_WORD,stabent($2,TRUE)),
a687059c
LW
633 Nullarg, Nullarg);
634 Safefree($2); }
635 | FILOP REG
636 { $$ = make_op($1, 1,
637 stab2arg(A_STAB,$2),
638 Nullarg, Nullarg); }
639 | FILOP '(' ')'
640 { $$ = make_op($1, 1,
378cc40b 641 stab2arg(A_WORD,Nullstab),
a687059c
LW
642 Nullarg, Nullarg); }
643 | FILOP %prec '('
644 { $$ = make_op($1, 0,
645 Nullarg, Nullarg, Nullarg); }
646 | FILOP2 '(' handle cexpr ')'
647 { $$ = make_op($1, 2, $3, $4, Nullarg); }
648 | FILOP3 '(' handle csexpr cexpr ')'
663a0e37 649 { $$ = make_op($1, 3, $3, $4, make_list($5)); }
a687059c
LW
650 | FILOP22 '(' handle ',' handle ')'
651 { $$ = make_op($1, 2, $3, $5, Nullarg); }
652 | FILOP4 '(' handle csexpr csexpr cexpr ')'
653 { arg4 = $6; $$ = make_op($1, 4, $3, $4, $5); }
654 | FILOP25 '(' handle ',' handle csexpr csexpr cexpr ')'
655 { arg4 = $7; arg5 = $8;
656 $$ = make_op($1, 5, $3, $5, $6); }
657 | PUSH '(' aryword cexpr ')'
8d063cd8 658 { $$ = make_op($1, 2,
a687059c
LW
659 $3,
660 make_list($4),
661 Nullarg); }
662 | POP aryword %prec '('
663 { $$ = make_op(O_POP, 1, $2, Nullarg, Nullarg); }
664 | POP '(' aryword ')'
665 { $$ = make_op(O_POP, 1, $3, Nullarg, Nullarg); }
666 | SHIFT aryword %prec '('
667 { $$ = make_op(O_SHIFT, 1, $2, Nullarg, Nullarg); }
668 | SHIFT '(' aryword ')'
669 { $$ = make_op(O_SHIFT, 1, $3, Nullarg, Nullarg); }
8d063cd8
LW
670 | SHIFT %prec '('
671 { $$ = make_op(O_SHIFT, 1,
a687059c
LW
672 stab2arg(A_STAB,
673 aadd(stabent(subline ? "_" : "ARGV", TRUE))),
674 Nullarg, Nullarg); }
8d063cd8 675 | SPLIT %prec '('
c623bd54
LW
676 { static char p[]="/\\s+/";
677 char *oldend = bufend;
27e2fb84 678 ARG *oldarg = yylval.arg;
c623bd54
LW
679
680 bufend=p+5;
681 (void)scanpat(p);
682 bufend=oldend;
683 $$ = make_split(defstab,yylval.arg,Nullarg);
684 yylval.arg = oldarg; }
a687059c
LW
685 | SPLIT '(' sexpr csexpr csexpr ')'
686 { $$ = mod_match(O_MATCH, $4,
687 make_split(defstab,$3,$5));}
688 | SPLIT '(' sexpr csexpr ')'
689 { $$ = mod_match(O_MATCH, $4,
690 make_split(defstab,$3,Nullarg) ); }
8d063cd8
LW
691 | SPLIT '(' sexpr ')'
692 { $$ = mod_match(O_MATCH,
378cc40b 693 stab2arg(A_STAB,defstab),
a687059c
LW
694 make_split(defstab,$3,Nullarg) ); }
695 | FLIST2 '(' sexpr cexpr ')'
696 { $$ = make_op($1, 2,
8d063cd8 697 $3,
a687059c
LW
698 listish(make_list($4)),
699 Nullarg); }
700 | FLIST '(' expr ')'
701 { $$ = make_op($1, 1,
8d063cd8
LW
702 make_list($3),
703 Nullarg,
a687059c
LW
704 Nullarg); }
705 | LVALFUN sexpr %prec '('
706 { $$ = l(make_op($1, 1, fixl($1,$2),
707 Nullarg, Nullarg)); }
378cc40b
LW
708 | LVALFUN
709 { $$ = l(make_op($1, 1,
710 stab2arg(A_STAB,defstab),
a687059c 711 Nullarg, Nullarg)); }
8d063cd8 712 | FUNC0
a687059c 713 { $$ = make_op($1, 0, Nullarg, Nullarg, Nullarg); }
ae986130
LW
714 | FUNC0 '(' ')'
715 { $$ = make_op($1, 0, Nullarg, Nullarg, Nullarg); }
03a14243 716 | FUNC1 '(' ')'
d9d8d8de 717 { $$ = make_op($1, 0, Nullarg, Nullarg, Nullarg); }
8d063cd8 718 | FUNC1 '(' expr ')'
d9d8d8de 719 { $$ = make_op($1, 1, $3, Nullarg, Nullarg); }
a687059c
LW
720 | FUNC2 '(' sexpr cexpr ')'
721 { $$ = make_op($1, 2, $3, $4, Nullarg);
378cc40b 722 if ($1 == O_INDEX && $$[2].arg_type == A_SINGLE)
a687059c 723 fbmcompile($$[2].arg_ptr.arg_str,0); }
d9d8d8de
LW
724 | FUNC2x '(' sexpr csexpr ')'
725 { $$ = make_op($1, 2, $3, $4, Nullarg);
726 if ($1 == O_INDEX && $$[2].arg_type == A_SINGLE)
727 fbmcompile($$[2].arg_ptr.arg_str,0); }
728 | FUNC2x '(' sexpr csexpr cexpr ')'
729 { $$ = make_op($1, 3, $3, $4, $5);
730 if ($1 == O_INDEX && $$[2].arg_type == A_SINGLE)
731 fbmcompile($$[2].arg_ptr.arg_str,0); }
a687059c
LW
732 | FUNC3 '(' sexpr csexpr cexpr ')'
733 { $$ = make_op($1, 3, $3, $4, $5); }
d9d8d8de
LW
734 | FUNC4 '(' sexpr csexpr csexpr cexpr ')'
735 { arg4 = $6;
736 $$ = make_op($1, 4, $3, $4, $5); }
737 | FUNC5 '(' sexpr csexpr csexpr csexpr cexpr ')'
738 { arg4 = $6; arg5 = $7;
739 $$ = make_op($1, 5, $3, $4, $5); }
a687059c
LW
740 | HSHFUN '(' hshword ')'
741 { $$ = make_op($1, 1,
742 $3,
743 Nullarg,
744 Nullarg); }
745 | HSHFUN hshword
8d063cd8 746 { $$ = make_op($1, 1,
a687059c 747 $2,
8d063cd8 748 Nullarg,
a687059c
LW
749 Nullarg); }
750 | HSHFUN3 '(' hshword csexpr cexpr ')'
751 { $$ = make_op($1, 3, $3, $4, $5); }
450a55e4 752 | bareword
378cc40b 753 | listop
8d063cd8
LW
754 ;
755
378cc40b 756listop : LISTOP
8d063cd8 757 { $$ = make_op($1,2,
378cc40b 758 stab2arg(A_WORD,Nullstab),
a687059c
LW
759 stab2arg(A_STAB,defstab),
760 Nullarg); }
378cc40b 761 | LISTOP expr
a687059c 762 { $$ = make_op($1,2,
378cc40b 763 stab2arg(A_WORD,Nullstab),
a687059c
LW
764 maybelistish($1,make_list($2)),
765 Nullarg); }
378cc40b 766 | LISTOP WORD
8d063cd8 767 { $$ = make_op($1,2,
378cc40b 768 stab2arg(A_WORD,stabent($2,TRUE)),
a687059c
LW
769 stab2arg(A_STAB,defstab),
770 Nullarg); }
378cc40b 771 | LISTOP WORD expr
a687059c 772 { $$ = make_op($1,2,
378cc40b 773 stab2arg(A_WORD,stabent($2,TRUE)),
a687059c
LW
774 maybelistish($1,make_list($3)),
775 Nullarg); Safefree($2); }
378cc40b 776 | LISTOP REG expr
a687059c 777 { $$ = make_op($1,2,
378cc40b 778 stab2arg(A_STAB,$2),
a687059c
LW
779 maybelistish($1,make_list($3)),
780 Nullarg); }
781 ;
782
783handle : WORD
784 { $$ = stab2arg(A_WORD,stabent($1,TRUE)); Safefree($1);}
785 | sexpr
786 ;
787
788aryword : WORD
789 { $$ = stab2arg(A_WORD,aadd(stabent($1,TRUE)));
790 Safefree($1); }
791 | ARY
792 { $$ = stab2arg(A_STAB,$1); }
793 ;
794
795hshword : WORD
796 { $$ = stab2arg(A_WORD,hadd(stabent($1,TRUE)));
797 Safefree($1); }
798 | HSH
799 { $$ = stab2arg(A_STAB,$1); }
8d063cd8
LW
800 ;
801
450a55e4
LW
802/*
803 * NOTE: The following entry must stay at the end of the file so that
804 * reduce/reduce conflicts resolve to it only if it's the only option.
805 */
806
807bareword: WORD
6eb13c3b 808 { char *s;
450a55e4
LW
809 $$ = op_new(1);
810 $$->arg_type = O_ITEM;
811 $$[1].arg_type = A_SINGLE;
812 $$[1].arg_ptr.arg_str = str_make($1,0);
6eb13c3b 813 for (s = $1; *s && islower(*s); s++) ;
450a55e4 814 if (dowarn && !*s)
6eb13c3b
LW
815 warn(
816 "\"%s\" may clash with future reserved word",
817 $1 );
450a55e4
LW
818 }
819
8d063cd8 820%% /* PROGRAM */