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