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