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