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