This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 2.0 patch 1: removed redundant debugging code in regexp.c
[perl5.git] / perl.y
CommitLineData
378cc40b 1/* $Header: perl.y,v 2.0 88/06/05 00:09:36 root Exp $
8d063cd8
LW
2 *
3 * $Log: perl.y,v $
378cc40b
LW
4 * Revision 2.0 88/06/05 00:09:36 root
5 * Baseline version 2.0.
8d063cd8
LW
6 *
7 */
8
9%{
8d063cd8
LW
10#include "INTERN.h"
11#include "perl.h"
378cc40b 12
8d063cd8
LW
13char *tokename[] = {
14"256",
15"word",
16"append","open","write","select","close","loopctl",
378cc40b 17"using","format","do","shift","push","pop","chop/study",
8d063cd8
LW
18"while","until","if","unless","else","elsif","continue","split","sprintf",
19"for", "eof", "tell", "seek", "stat",
20"function(no args)","function(1 arg)","function(2 args)","function(3 args)","array function",
378cc40b 21"join", "sub", "file test", "local", "delete",
8d063cd8
LW
22"format lines",
23"register","array_length", "array",
24"s","pattern",
378cc40b
LW
25"string","tr",
26"list operator",
8d063cd8
LW
27"..",
28"||",
29"&&",
30"==","!=", "EQ", "NE",
31"<=",">=", "LT", "GT", "LE", "GE",
378cc40b
LW
32"unary operation",
33"file test",
8d063cd8
LW
34"<<",">>",
35"=~","!~",
36"unary -",
37"++", "--",
38"???"
39};
40
378cc40b
LW
41STAB *scrstab;
42
8d063cd8
LW
43%}
44
45%start prog
46
47%union {
48 int ival;
49 char *cval;
50 ARG *arg;
51 CMD *cmdval;
52 struct compcmd compval;
53 STAB *stabval;
54 FCMD *formval;
55}
56
57%token <cval> WORD
58%token <ival> APPEND OPEN WRITE SELECT CLOSE LOOPEX
378cc40b 59%token <ival> USING FORMAT DO SHIFT PUSH POP LVALFUN
8d063cd8
LW
60%token <ival> WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE SPLIT SPRINTF
61%token <ival> FOR FEOF TELL SEEK STAT
62%token <ival> FUNC0 FUNC1 FUNC2 FUNC3 STABFUN
378cc40b 63%token <ival> JOIN SUB FILETEST LOCAL DELETE
8d063cd8
LW
64%token <formval> FORMLIST
65%token <stabval> REG ARYLEN ARY
66%token <arg> SUBST PATTERN
67%token <arg> RSTRING TRANS
68
69%type <ival> prog decl format
70%type <stabval>
71%type <cmdval> block lineseq line loop cond sideff nexpr else
72%type <arg> expr sexpr term
378cc40b
LW
73%type <arg> condmod loopmod
74%type <arg> texpr listop
8d063cd8
LW
75%type <cval> label
76%type <compval> compblock
77
378cc40b 78%nonassoc <ival> LISTOP
8d063cd8 79%left ','
8d063cd8
LW
80%right '='
81%right '?' ':'
82%nonassoc DOTDOT
83%left OROR
84%left ANDAND
85%left '|' '^'
86%left '&'
87%nonassoc EQ NE SEQ SNE
88%nonassoc '<' '>' LE GE SLT SGT SLE SGE
378cc40b
LW
89%nonassoc <ival> UNIOP
90%nonassoc FILETEST
8d063cd8
LW
91%left LS RS
92%left '+' '-' '.'
93%left '*' '/' '%' 'x'
94%left MATCH NMATCH
95%right '!' '~' UMINUS
96%nonassoc INC DEC
97%left '('
98
99%% /* RULES */
100
101prog : lineseq
a559c259
LW
102 { if (in_eval)
103 eval_root = block_head($1);
104 else
105 main_root = block_head($1); }
8d063cd8
LW
106 ;
107
108compblock: block CONTINUE block
109 { $$.comp_true = $1; $$.comp_alt = $3; }
110 | block else
111 { $$.comp_true = $1; $$.comp_alt = $2; }
112 ;
113
114else : /* NULL */
115 { $$ = Nullcmd; }
116 | ELSE block
117 { $$ = $2; }
118 | ELSIF '(' expr ')' compblock
378cc40b
LW
119 { cmdline = $1;
120 $$ = make_ccmd(C_IF,$3,$5); }
8d063cd8
LW
121 ;
122
123block : '{' lineseq '}'
124 { $$ = block_head($2); }
125 ;
126
127lineseq : /* NULL */
128 { $$ = Nullcmd; }
129 | lineseq line
130 { $$ = append_line($1,$2); }
131 ;
132
133line : decl
134 { $$ = Nullcmd; }
135 | label cond
136 { $$ = add_label($1,$2); }
137 | loop /* loops add their own labels */
138 | label ';'
139 { if ($1 != Nullch) {
378cc40b 140 $$ = add_label($1, make_acmd(C_EXPR, Nullstab,
8d063cd8
LW
141 Nullarg, Nullarg) );
142 } else
143 $$ = Nullcmd; }
144 | label sideff ';'
145 { $$ = add_label($1,$2); }
146 ;
147
148sideff : expr
149 { $$ = make_acmd(C_EXPR, Nullstab, $1, Nullarg); }
150 | expr condmod
151 { $$ = addcond(
152 make_acmd(C_EXPR, Nullstab, Nullarg, $1), $2); }
153 | expr loopmod
154 { $$ = addloop(
155 make_acmd(C_EXPR, Nullstab, Nullarg, $1), $2); }
156 ;
157
158cond : IF '(' expr ')' compblock
378cc40b
LW
159 { cmdline = $1;
160 $$ = make_ccmd(C_IF,$3,$5); }
8d063cd8 161 | UNLESS '(' expr ')' compblock
378cc40b
LW
162 { cmdline = $1;
163 $$ = invert(make_ccmd(C_IF,$3,$5)); }
8d063cd8 164 | IF block compblock
378cc40b
LW
165 { cmdline = $1;
166 $$ = make_ccmd(C_IF,cmd_to_arg($2),$3); }
8d063cd8 167 | UNLESS block compblock
378cc40b
LW
168 { cmdline = $1;
169 $$ = invert(make_ccmd(C_IF,cmd_to_arg($2),$3)); }
8d063cd8
LW
170 ;
171
172loop : label WHILE '(' texpr ')' compblock
378cc40b
LW
173 { cmdline = $2;
174 $$ = wopt(add_label($1,
8d063cd8
LW
175 make_ccmd(C_WHILE,$4,$6) )); }
176 | label UNTIL '(' expr ')' compblock
378cc40b
LW
177 { cmdline = $2;
178 $$ = wopt(add_label($1,
8d063cd8
LW
179 invert(make_ccmd(C_WHILE,$4,$6)) )); }
180 | label WHILE block compblock
378cc40b
LW
181 { cmdline = $2;
182 $$ = wopt(add_label($1,
8d063cd8
LW
183 make_ccmd(C_WHILE, cmd_to_arg($3),$4) )); }
184 | label UNTIL block compblock
378cc40b
LW
185 { cmdline = $2;
186 $$ = wopt(add_label($1,
8d063cd8 187 invert(make_ccmd(C_WHILE, cmd_to_arg($3),$4)) )); }
378cc40b
LW
188 | label FOR REG '(' expr ')' compblock
189 { cmdline = $2;
190 /*
191 * The following gobbledygook catches EXPRs that
192 * aren't explicit array refs and translates
193 * foreach VAR (EXPR) {
194 * into
195 * @ary = EXPR;
196 * foreach VAR (@ary) {
197 * where @ary is a hidden array made by genstab().
198 */
199 if ($5->arg_type != O_ARRAY) {
200 scrstab = aadd(genstab());
201 $$ = append_line(
202 make_acmd(C_EXPR, Nullstab,
203 l(make_op(O_ASSIGN,2,
204 listish(make_op(O_ARRAY, 1,
205 stab2arg(A_STAB,scrstab),
206 Nullarg,Nullarg, 1)),
207 listish($5),
208 Nullarg,1)),
209 Nullarg),
210 wopt(over($3,add_label($1,
211 make_ccmd(C_WHILE,
212 make_op(O_ARRAY, 1,
213 stab2arg(A_STAB,scrstab),
214 Nullarg,Nullarg, 1 ),
215 $7)))));
216 }
217 else {
218 $$ = wopt(over($3,add_label($1,
219 make_ccmd(C_WHILE,$5,$7) )));
220 }
221 }
222 | label FOR '(' expr ')' compblock
223 { cmdline = $2;
224 if ($4->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 )),
232 listish($4),
233 Nullarg,1)),
234 Nullarg),
235 wopt(over(defstab,add_label($1,
236 make_ccmd(C_WHILE,
237 make_op(O_ARRAY, 1,
238 stab2arg(A_STAB,scrstab),
239 Nullarg,Nullarg, 1 ),
240 $6)))));
241 }
242 else { /* lisp, anyone? */
243 $$ = wopt(over(defstab,add_label($1,
244 make_ccmd(C_WHILE,$4,$6) )));
245 }
246 }
8d063cd8
LW
247 | label FOR '(' nexpr ';' texpr ';' nexpr ')' block
248 /* basically fake up an initialize-while lineseq */
249 { yyval.compval.comp_true = $10;
250 yyval.compval.comp_alt = $8;
378cc40b 251 cmdline = $2;
8d063cd8
LW
252 $$ = append_line($4,wopt(add_label($1,
253 make_ccmd(C_WHILE,$6,yyval.compval) ))); }
254 | label compblock /* a block is a loop that happens once */
255 { $$ = add_label($1,make_ccmd(C_BLOCK,Nullarg,$2)); }
256 ;
257
258nexpr : /* NULL */
259 { $$ = Nullcmd; }
260 | sideff
261 ;
262
263texpr : /* NULL means true */
264 { scanstr("1"); $$ = yylval.arg; }
265 | expr
266 ;
267
268label : /* empty */
269 { $$ = Nullch; }
270 | WORD ':'
271 ;
272
273loopmod : WHILE expr
274 { $$ = $2; }
275 | UNTIL expr
276 { $$ = make_op(O_NOT,1,$2,Nullarg,Nullarg,0); }
277 ;
278
279condmod : IF expr
280 { $$ = $2; }
281 | UNLESS expr
282 { $$ = make_op(O_NOT,1,$2,Nullarg,Nullarg,0); }
283 ;
284
285decl : format
286 { $$ = 0; }
287 | subrout
288 { $$ = 0; }
289 ;
290
291format : FORMAT WORD '=' FORMLIST '.'
292 { stabent($2,TRUE)->stab_form = $4; safefree($2); }
293 | FORMAT '=' FORMLIST '.'
294 { stabent("stdout",TRUE)->stab_form = $3; }
295 ;
296
297subrout : SUB WORD block
378cc40b 298 { make_sub($2,$3); }
8d063cd8
LW
299 ;
300
378cc40b 301expr : sexpr ',' expr
8d063cd8
LW
302 { $$ = make_op(O_COMMA, 2, $1, $3, Nullarg,0); }
303 | sexpr
304 ;
305
306sexpr : sexpr '=' sexpr
307 { $1 = listish($1);
308 if ($1->arg_type == O_LIST)
309 $3 = listish($3);
310 $$ = l(make_op(O_ASSIGN, 2, $1, $3, Nullarg,1)); }
311 | sexpr '*' '=' sexpr
312 { $$ = l(make_op(O_MULTIPLY, 2, $1, $4, Nullarg,0)); }
313 | sexpr '/' '=' sexpr
314 { $$ = l(make_op(O_DIVIDE, 2, $1, $4, Nullarg,0)); }
315 | sexpr '%' '=' sexpr
316 { $$ = l(make_op(O_MODULO, 2, $1, $4, Nullarg,0)); }
317 | sexpr 'x' '=' sexpr
318 { $$ = l(make_op(O_REPEAT, 2, $1, $4, Nullarg,0)); }
319 | sexpr '+' '=' sexpr
320 { $$ = l(make_op(O_ADD, 2, $1, $4, Nullarg,0)); }
321 | sexpr '-' '=' sexpr
322 { $$ = l(make_op(O_SUBTRACT, 2, $1, $4, Nullarg,0)); }
323 | sexpr LS '=' sexpr
324 { $$ = l(make_op(O_LEFT_SHIFT, 2, $1, $4, Nullarg,0)); }
325 | sexpr RS '=' sexpr
326 { $$ = l(make_op(O_RIGHT_SHIFT, 2, $1, $4, Nullarg,0)); }
327 | sexpr '&' '=' sexpr
328 { $$ = l(make_op(O_BIT_AND, 2, $1, $4, Nullarg,0)); }
329 | sexpr '^' '=' sexpr
330 { $$ = l(make_op(O_XOR, 2, $1, $4, Nullarg,0)); }
331 | sexpr '|' '=' sexpr
332 { $$ = l(make_op(O_BIT_OR, 2, $1, $4, Nullarg,0)); }
333 | sexpr '.' '=' sexpr
334 { $$ = l(make_op(O_CONCAT, 2, $1, $4, Nullarg,0)); }
335
336
337 | sexpr '*' sexpr
338 { $$ = make_op(O_MULTIPLY, 2, $1, $3, Nullarg,0); }
339 | sexpr '/' sexpr
340 { $$ = make_op(O_DIVIDE, 2, $1, $3, Nullarg,0); }
341 | sexpr '%' sexpr
342 { $$ = make_op(O_MODULO, 2, $1, $3, Nullarg,0); }
343 | sexpr 'x' sexpr
344 { $$ = make_op(O_REPEAT, 2, $1, $3, Nullarg,0); }
345 | sexpr '+' sexpr
346 { $$ = make_op(O_ADD, 2, $1, $3, Nullarg,0); }
347 | sexpr '-' sexpr
348 { $$ = make_op(O_SUBTRACT, 2, $1, $3, Nullarg,0); }
349 | sexpr LS sexpr
350 { $$ = make_op(O_LEFT_SHIFT, 2, $1, $3, Nullarg,0); }
351 | sexpr RS sexpr
352 { $$ = make_op(O_RIGHT_SHIFT, 2, $1, $3, Nullarg,0); }
353 | sexpr '<' sexpr
354 { $$ = make_op(O_LT, 2, $1, $3, Nullarg,0); }
355 | sexpr '>' sexpr
356 { $$ = make_op(O_GT, 2, $1, $3, Nullarg,0); }
357 | sexpr LE sexpr
358 { $$ = make_op(O_LE, 2, $1, $3, Nullarg,0); }
359 | sexpr GE sexpr
360 { $$ = make_op(O_GE, 2, $1, $3, Nullarg,0); }
361 | sexpr EQ sexpr
362 { $$ = make_op(O_EQ, 2, $1, $3, Nullarg,0); }
363 | sexpr NE sexpr
364 { $$ = make_op(O_NE, 2, $1, $3, Nullarg,0); }
365 | sexpr SLT sexpr
366 { $$ = make_op(O_SLT, 2, $1, $3, Nullarg,0); }
367 | sexpr SGT sexpr
368 { $$ = make_op(O_SGT, 2, $1, $3, Nullarg,0); }
369 | sexpr SLE sexpr
370 { $$ = make_op(O_SLE, 2, $1, $3, Nullarg,0); }
371 | sexpr SGE sexpr
372 { $$ = make_op(O_SGE, 2, $1, $3, Nullarg,0); }
373 | sexpr SEQ sexpr
374 { $$ = make_op(O_SEQ, 2, $1, $3, Nullarg,0); }
375 | sexpr SNE sexpr
376 { $$ = make_op(O_SNE, 2, $1, $3, Nullarg,0); }
377 | sexpr '&' sexpr
378 { $$ = make_op(O_BIT_AND, 2, $1, $3, Nullarg,0); }
379 | sexpr '^' sexpr
380 { $$ = make_op(O_XOR, 2, $1, $3, Nullarg,0); }
381 | sexpr '|' sexpr
382 { $$ = make_op(O_BIT_OR, 2, $1, $3, Nullarg,0); }
383 | sexpr DOTDOT sexpr
384 { $$ = make_op(O_FLIP, 4,
385 flipflip($1),
386 flipflip($3),
387 Nullarg,0);}
388 | sexpr ANDAND sexpr
389 { $$ = make_op(O_AND, 2, $1, $3, Nullarg,0); }
390 | sexpr OROR sexpr
391 { $$ = make_op(O_OR, 2, $1, $3, Nullarg,0); }
392 | sexpr '?' sexpr ':' sexpr
393 { $$ = make_op(O_COND_EXPR, 3, $1, $3, $5,0); }
394 | sexpr '.' sexpr
395 { $$ = make_op(O_CONCAT, 2, $1, $3, Nullarg,0); }
396 | sexpr MATCH sexpr
397 { $$ = mod_match(O_MATCH, $1, $3); }
398 | sexpr NMATCH sexpr
399 { $$ = mod_match(O_NMATCH, $1, $3); }
400 | term INC
401 { $$ = addflags(1, AF_POST|AF_UP,
402 l(make_op(O_ITEM,1,$1,Nullarg,Nullarg,0))); }
403 | term DEC
404 { $$ = addflags(1, AF_POST,
405 l(make_op(O_ITEM,1,$1,Nullarg,Nullarg,0))); }
406 | INC term
407 { $$ = addflags(1, AF_PRE|AF_UP,
408 l(make_op(O_ITEM,1,$2,Nullarg,Nullarg,0))); }
409 | DEC term
410 { $$ = addflags(1, AF_PRE,
411 l(make_op(O_ITEM,1,$2,Nullarg,Nullarg,0))); }
412 | term
413 { $$ = $1; }
414 ;
415
416term : '-' term %prec UMINUS
417 { $$ = make_op(O_NEGATE, 1, $2, Nullarg, Nullarg,0); }
418 | '!' term
419 { $$ = make_op(O_NOT, 1, $2, Nullarg, Nullarg,0); }
420 | '~' term
421 { $$ = make_op(O_COMPLEMENT, 1, $2, Nullarg, Nullarg,0);}
378cc40b
LW
422 | FILETEST WORD
423 { opargs[$1] = 0; /* force it special */
424 $$ = make_op($1, 1,
425 stab2arg(A_STAB,stabent($2,TRUE)),
426 Nullarg, Nullarg,0);
427 }
428 | FILETEST sexpr
429 { opargs[$1] = 1;
430 $$ = make_op($1, 1, $2, Nullarg, Nullarg,0); }
431 | FILETEST
432 { opargs[$1] = ($1 != O_FTTTY);
433 $$ = make_op($1, 1,
434 stab2arg(A_STAB,
435 $1 == O_FTTTY?stabent("stdin",TRUE):defstab),
436 Nullarg, Nullarg,0); }
437 | LOCAL '(' expr ')'
438 { $$ = localize(listish(make_list(hide_ary($3)))); }
8d063cd8
LW
439 | '(' expr ')'
440 { $$ = make_list(hide_ary($2)); }
441 | '(' ')'
442 { $$ = make_list(Nullarg); }
378cc40b
LW
443 | DO sexpr %prec FILETEST
444 { $$ = make_op(O_DOFILE,1,$2,Nullarg,Nullarg,0);
445 allstabs = TRUE;}
8d063cd8
LW
446 | DO block %prec '('
447 { $$ = cmd_to_arg($2); }
448 | REG %prec '('
378cc40b 449 { $$ = stab2arg(A_STAB,$1); }
8d063cd8
LW
450 | REG '[' expr ']' %prec '('
451 { $$ = make_op(O_ARRAY, 2,
378cc40b 452 $3, stab2arg(A_STAB,aadd($1)), Nullarg,0); }
8d063cd8
LW
453 | ARY %prec '('
454 { $$ = make_op(O_ARRAY, 1,
378cc40b 455 stab2arg(A_STAB,$1),
8d063cd8
LW
456 Nullarg, Nullarg, 1); }
457 | REG '{' expr '}' %prec '('
458 { $$ = make_op(O_HASH, 2,
378cc40b
LW
459 $3, stab2arg(A_STAB,hadd($1)), Nullarg,0); }
460 | DELETE REG '{' expr '}' %prec '('
461 { $$ = make_op(O_DELETE, 2,
462 $4, stab2arg(A_STAB,hadd($2)), Nullarg,0); }
8d063cd8 463 | ARYLEN %prec '('
378cc40b 464 { $$ = stab2arg(A_ARYLEN,$1); }
8d063cd8
LW
465 | RSTRING %prec '('
466 { $$ = $1; }
467 | PATTERN %prec '('
468 { $$ = $1; }
469 | SUBST %prec '('
470 { $$ = $1; }
471 | TRANS %prec '('
472 { $$ = $1; }
473 | DO WORD '(' expr ')'
474 { $$ = make_op(O_SUBR, 2,
475 make_list($4),
378cc40b 476 stab2arg(A_WORD,stabent($2,TRUE)),
8d063cd8
LW
477 Nullarg,1); }
478 | DO WORD '(' ')'
479 { $$ = make_op(O_SUBR, 2,
480 make_list(Nullarg),
378cc40b
LW
481 stab2arg(A_WORD,stabent($2,TRUE)),
482 Nullarg,1); }
483 | DO REG '(' expr ')'
484 { $$ = make_op(O_SUBR, 2,
485 make_list($4),
486 stab2arg(A_STAB,$2),
487 Nullarg,1); }
488 | DO REG '(' ')'
489 { $$ = make_op(O_SUBR, 2,
490 make_list(Nullarg),
491 stab2arg(A_STAB,$2),
8d063cd8
LW
492 Nullarg,1); }
493 | LOOPEX
494 { $$ = make_op($1,0,Nullarg,Nullarg,Nullarg,0); }
495 | LOOPEX WORD
496 { $$ = make_op($1,1,cval_to_arg($2),
497 Nullarg,Nullarg,0); }
498 | UNIOP
499 { $$ = make_op($1,1,Nullarg,Nullarg,Nullarg,0); }
500 | UNIOP sexpr
501 { $$ = make_op($1,1,$2,Nullarg,Nullarg,0); }
502 | WRITE
503 { $$ = make_op(O_WRITE, 0,
504 Nullarg, Nullarg, Nullarg,0); }
505 | WRITE '(' ')'
506 { $$ = make_op(O_WRITE, 0,
507 Nullarg, Nullarg, Nullarg,0); }
508 | WRITE '(' WORD ')'
509 { $$ = l(make_op(O_WRITE, 1,
378cc40b 510 stab2arg(A_STAB,stabent($3,TRUE)),
8d063cd8
LW
511 Nullarg, Nullarg,0)); safefree($3); }
512 | WRITE '(' expr ')'
513 { $$ = make_op(O_WRITE, 1, $3, Nullarg, Nullarg,0); }
514 | SELECT '(' WORD ')'
515 { $$ = l(make_op(O_SELECT, 1,
378cc40b 516 stab2arg(A_STAB,stabent($3,TRUE)),
8d063cd8
LW
517 Nullarg, Nullarg,0)); safefree($3); }
518 | SELECT '(' expr ')'
519 { $$ = make_op(O_SELECT, 1, $3, Nullarg, Nullarg,0); }
520 | OPEN WORD %prec '('
521 { $$ = make_op(O_OPEN, 2,
378cc40b
LW
522 stab2arg(A_WORD,stabent($2,TRUE)),
523 stab2arg(A_STAB,stabent($2,TRUE)),
8d063cd8
LW
524 Nullarg,0); }
525 | OPEN '(' WORD ')'
526 { $$ = make_op(O_OPEN, 2,
378cc40b
LW
527 stab2arg(A_WORD,stabent($3,TRUE)),
528 stab2arg(A_STAB,stabent($3,TRUE)),
8d063cd8
LW
529 Nullarg,0); }
530 | OPEN '(' WORD ',' expr ')'
531 { $$ = make_op(O_OPEN, 2,
378cc40b
LW
532 stab2arg(A_WORD,stabent($3,TRUE)),
533 $5, Nullarg,0); }
534 | OPEN '(' sexpr ',' expr ')'
535 { $$ = make_op(O_OPEN, 2,
536 $3,
8d063cd8
LW
537 $5, Nullarg,0); }
538 | CLOSE '(' WORD ')'
539 { $$ = make_op(O_CLOSE, 1,
378cc40b
LW
540 stab2arg(A_WORD,stabent($3,TRUE)),
541 Nullarg, Nullarg,0); }
542 | CLOSE '(' expr ')'
543 { $$ = make_op(O_CLOSE, 1,
544 $3,
8d063cd8
LW
545 Nullarg, Nullarg,0); }
546 | CLOSE WORD %prec '('
547 { $$ = make_op(O_CLOSE, 1,
378cc40b 548 stab2arg(A_WORD,stabent($2,TRUE)),
8d063cd8
LW
549 Nullarg, Nullarg,0); }
550 | FEOF '(' WORD ')'
551 { $$ = make_op(O_EOF, 1,
378cc40b
LW
552 stab2arg(A_WORD,stabent($3,TRUE)),
553 Nullarg, Nullarg,0); }
554 | FEOF '(' expr ')'
555 { $$ = make_op(O_EOF, 1,
556 $3,
8d063cd8
LW
557 Nullarg, Nullarg,0); }
558 | FEOF '(' ')'
378cc40b
LW
559 { $$ = make_op(O_EOF, 1,
560 stab2arg(A_WORD,Nullstab),
8d063cd8
LW
561 Nullarg, Nullarg,0); }
562 | FEOF
563 { $$ = make_op(O_EOF, 0,
564 Nullarg, Nullarg, Nullarg,0); }
565 | TELL '(' WORD ')'
566 { $$ = make_op(O_TELL, 1,
378cc40b
LW
567 stab2arg(A_WORD,stabent($3,TRUE)),
568 Nullarg, Nullarg,0); }
569 | TELL '(' expr ')'
570 { $$ = make_op(O_TELL, 1,
571 $3,
8d063cd8
LW
572 Nullarg, Nullarg,0); }
573 | TELL
574 { $$ = make_op(O_TELL, 0,
575 Nullarg, Nullarg, Nullarg,0); }
576 | SEEK '(' WORD ',' sexpr ',' expr ')'
577 { $$ = make_op(O_SEEK, 3,
378cc40b
LW
578 stab2arg(A_WORD,stabent($3,TRUE)),
579 $5, $7,1); }
580 | SEEK '(' sexpr ',' sexpr ',' expr ')'
581 { $$ = make_op(O_SEEK, 3,
582 $3,
8d063cd8
LW
583 $5, $7,1); }
584 | PUSH '(' WORD ',' expr ')'
585 { $$ = make_op($1, 2,
586 make_list($5),
378cc40b 587 stab2arg(A_STAB,aadd(stabent($3,TRUE))),
8d063cd8
LW
588 Nullarg,1); }
589 | PUSH '(' ARY ',' expr ')'
590 { $$ = make_op($1, 2,
591 make_list($5),
378cc40b 592 stab2arg(A_STAB,$3),
8d063cd8
LW
593 Nullarg,1); }
594 | POP WORD %prec '('
595 { $$ = make_op(O_POP, 1,
378cc40b 596 stab2arg(A_STAB,aadd(stabent($2,TRUE))),
8d063cd8
LW
597 Nullarg, Nullarg,0); }
598 | POP '(' WORD ')'
599 { $$ = make_op(O_POP, 1,
378cc40b 600 stab2arg(A_STAB,aadd(stabent($3,TRUE))),
8d063cd8
LW
601 Nullarg, Nullarg,0); }
602 | POP ARY %prec '('
603 { $$ = make_op(O_POP, 1,
378cc40b 604 stab2arg(A_STAB,$2),
8d063cd8
LW
605 Nullarg,
606 Nullarg,
607 0); }
608 | POP '(' ARY ')'
609 { $$ = make_op(O_POP, 1,
378cc40b 610 stab2arg(A_STAB,$3),
8d063cd8
LW
611 Nullarg,
612 Nullarg,
613 0); }
614 | SHIFT WORD %prec '('
615 { $$ = make_op(O_SHIFT, 1,
378cc40b 616 stab2arg(A_STAB,aadd(stabent($2,TRUE))),
8d063cd8
LW
617 Nullarg, Nullarg,0); }
618 | SHIFT '(' WORD ')'
619 { $$ = make_op(O_SHIFT, 1,
378cc40b 620 stab2arg(A_STAB,aadd(stabent($3,TRUE))),
8d063cd8
LW
621 Nullarg, Nullarg,0); }
622 | SHIFT ARY %prec '('
623 { $$ = make_op(O_SHIFT, 1,
378cc40b 624 stab2arg(A_STAB,$2), Nullarg, Nullarg,0); }
8d063cd8
LW
625 | SHIFT '(' ARY ')'
626 { $$ = make_op(O_SHIFT, 1,
378cc40b 627 stab2arg(A_STAB,$3), Nullarg, Nullarg,0); }
8d063cd8
LW
628 | SHIFT %prec '('
629 { $$ = make_op(O_SHIFT, 1,
378cc40b 630 stab2arg(A_STAB,aadd(stabent("ARGV",TRUE))),
8d063cd8
LW
631 Nullarg, Nullarg,0); }
632 | SPLIT %prec '('
378cc40b 633 { scanpat("/\\s+/");
8d063cd8
LW
634 $$ = make_split(defstab,yylval.arg); }
635 | SPLIT '(' WORD ')'
378cc40b 636 { scanpat("/\\s+/");
8d063cd8
LW
637 $$ = make_split(stabent($3,TRUE),yylval.arg); }
638 | SPLIT '(' WORD ',' PATTERN ')'
639 { $$ = make_split(stabent($3,TRUE),$5); }
640 | SPLIT '(' WORD ',' PATTERN ',' sexpr ')'
641 { $$ = mod_match(O_MATCH,
642 $7,
643 make_split(stabent($3,TRUE),$5) ); }
644 | SPLIT '(' sexpr ',' sexpr ')'
645 { $$ = mod_match(O_MATCH, $5, make_split(defstab,$3) ); }
646 | SPLIT '(' sexpr ')'
647 { $$ = mod_match(O_MATCH,
378cc40b 648 stab2arg(A_STAB,defstab),
8d063cd8
LW
649 make_split(defstab,$3) ); }
650 | JOIN '(' WORD ',' expr ')'
651 { $$ = make_op(O_JOIN, 2,
652 $5,
378cc40b 653 stab2arg(A_STAB,aadd(stabent($3,TRUE))),
8d063cd8
LW
654 Nullarg,0); }
655 | JOIN '(' sexpr ',' expr ')'
656 { $$ = make_op(O_JOIN, 2,
657 $3,
658 make_list($5),
659 Nullarg,2); }
660 | SPRINTF '(' expr ')'
661 { $$ = make_op(O_SPRINTF, 1,
662 make_list($3),
663 Nullarg,
664 Nullarg,1); }
665 | STAT '(' WORD ')'
666 { $$ = l(make_op(O_STAT, 1,
378cc40b 667 stab2arg(A_STAB,stabent($3,TRUE)),
8d063cd8
LW
668 Nullarg, Nullarg,0)); }
669 | STAT '(' expr ')'
670 { $$ = make_op(O_STAT, 1, $3, Nullarg, Nullarg,0); }
378cc40b
LW
671 | LVALFUN
672 { $$ = l(make_op($1, 1,
673 stab2arg(A_STAB,defstab),
8d063cd8 674 Nullarg, Nullarg,0)); }
378cc40b
LW
675 | LVALFUN '(' expr ')'
676 { $$ = l(make_op($1, 1, $3, Nullarg, Nullarg,0)); }
8d063cd8
LW
677 | FUNC0
678 { $$ = make_op($1, 0, Nullarg, Nullarg, Nullarg,0); }
679 | FUNC1 '(' expr ')'
680 { $$ = make_op($1, 1, $3, Nullarg, Nullarg,0); }
681 | FUNC2 '(' sexpr ',' expr ')'
378cc40b
LW
682 { $$ = make_op($1, 2, $3, $5, Nullarg, 0);
683 if ($1 == O_INDEX && $$[2].arg_type == A_SINGLE)
684 fbmcompile($$[2].arg_ptr.arg_str); }
8d063cd8
LW
685 | FUNC3 '(' sexpr ',' sexpr ',' expr ')'
686 { $$ = make_op($1, 3, $3, $5, $7, 0); }
687 | STABFUN '(' WORD ')'
688 { $$ = make_op($1, 1,
378cc40b 689 stab2arg(A_STAB,hadd(stabent($3,TRUE))),
8d063cd8
LW
690 Nullarg,
691 Nullarg, 0); }
378cc40b 692 | listop
8d063cd8
LW
693 ;
694
378cc40b 695listop : LISTOP
8d063cd8 696 { $$ = make_op($1,2,
378cc40b
LW
697 stab2arg(A_STAB,defstab),
698 stab2arg(A_WORD,Nullstab),
8d063cd8 699 Nullarg,0); }
378cc40b 700 | LISTOP expr
8d063cd8 701 { $$ = make_op($1,2,make_list($2),
378cc40b 702 stab2arg(A_WORD,Nullstab),
8d063cd8 703 Nullarg,1); }
378cc40b 704 | LISTOP WORD
8d063cd8 705 { $$ = make_op($1,2,
378cc40b
LW
706 stab2arg(A_STAB,defstab),
707 stab2arg(A_WORD,stabent($2,TRUE)),
708 Nullarg,1); }
709 | LISTOP WORD expr
710 { $$ = make_op($1,2,make_list($3),
711 stab2arg(A_WORD,stabent($2,TRUE)),
8d063cd8 712 Nullarg,1); }
378cc40b 713 | LISTOP REG expr
8d063cd8 714 { $$ = make_op($1,2,make_list($3),
378cc40b 715 stab2arg(A_STAB,$2),
8d063cd8
LW
716 Nullarg,1); }
717 ;
718
719%% /* PROGRAM */