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