xref: /illumos-gate/usr/src/cmd/oawk/awk.g.y (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate %{
2*7c478bd9Sstevel@tonic-gate /*
3*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
4*7c478bd9Sstevel@tonic-gate  *
5*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
6*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
7*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
8*7c478bd9Sstevel@tonic-gate  * with the License.
9*7c478bd9Sstevel@tonic-gate  *
10*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
12*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
13*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
14*7c478bd9Sstevel@tonic-gate  *
15*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
16*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
18*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
19*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
20*7c478bd9Sstevel@tonic-gate  *
21*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
22*7c478bd9Sstevel@tonic-gate  */
23*7c478bd9Sstevel@tonic-gate %}
24*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
25*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate %{
30*7c478bd9Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate %}
32*7c478bd9Sstevel@tonic-gate %token	FIRSTTOKEN	/* must be first */
33*7c478bd9Sstevel@tonic-gate %token	FINAL FATAL
34*7c478bd9Sstevel@tonic-gate %token	LT LE GT GE EQ NE
35*7c478bd9Sstevel@tonic-gate %token	MATCH NOTMATCH
36*7c478bd9Sstevel@tonic-gate %token	APPEND
37*7c478bd9Sstevel@tonic-gate %token	ADD MINUS MULT DIVIDE MOD UMINUS
38*7c478bd9Sstevel@tonic-gate %token	ASSIGN ADDEQ SUBEQ MULTEQ DIVEQ MODEQ
39*7c478bd9Sstevel@tonic-gate %token	JUMP
40*7c478bd9Sstevel@tonic-gate %token	XBEGIN XEND
41*7c478bd9Sstevel@tonic-gate %token	NL
42*7c478bd9Sstevel@tonic-gate %token	PRINT PRINTF SPRINTF SPLIT
43*7c478bd9Sstevel@tonic-gate %token	IF ELSE WHILE FOR IN NEXT EXIT BREAK CONTINUE
44*7c478bd9Sstevel@tonic-gate %token	PROGRAM PASTAT PASTAT2
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate %right	ASGNOP
48*7c478bd9Sstevel@tonic-gate %left	BOR
49*7c478bd9Sstevel@tonic-gate %left	AND
50*7c478bd9Sstevel@tonic-gate %left	NOT
51*7c478bd9Sstevel@tonic-gate %left	NUMBER VAR ARRAY FNCN SUBSTR LSUBSTR INDEX
52*7c478bd9Sstevel@tonic-gate %left	GETLINE
53*7c478bd9Sstevel@tonic-gate %nonassoc RELOP MATCHOP
54*7c478bd9Sstevel@tonic-gate %left	OR
55*7c478bd9Sstevel@tonic-gate %left	STRING  DOT CCL NCCL CHAR
56*7c478bd9Sstevel@tonic-gate %left	'(' '^' '$'
57*7c478bd9Sstevel@tonic-gate %left	CAT
58*7c478bd9Sstevel@tonic-gate %left	'+' '-'
59*7c478bd9Sstevel@tonic-gate %left	'*' '/' '%'
60*7c478bd9Sstevel@tonic-gate %left	STAR PLUS QUEST
61*7c478bd9Sstevel@tonic-gate %left	POSTINCR PREINCR POSTDECR PREDECR INCR DECR
62*7c478bd9Sstevel@tonic-gate %left	FIELD INDIRECT
63*7c478bd9Sstevel@tonic-gate %token	JUMPTRUE JUMPFALSE PUSH GETREC
64*7c478bd9Sstevel@tonic-gate %token	NEWSTAT
65*7c478bd9Sstevel@tonic-gate %token	IN_INIT IN_EXIT
66*7c478bd9Sstevel@tonic-gate %token	LASTTOKEN	/* has to be last */
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate %{
70*7c478bd9Sstevel@tonic-gate #include "awk.def"
71*7c478bd9Sstevel@tonic-gate #ifndef	DEBUG
72*7c478bd9Sstevel@tonic-gate #	define	PUTS(x)
73*7c478bd9Sstevel@tonic-gate #endif
74*7c478bd9Sstevel@tonic-gate static wchar_t L_record[] = L"$record";
75*7c478bd9Sstevel@tonic-gate static wchar_t L_zeronull[] = L"$zero&null";
76*7c478bd9Sstevel@tonic-gate %}
77*7c478bd9Sstevel@tonic-gate %%
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate program:
81*7c478bd9Sstevel@tonic-gate 		begin pa_stats end	{
82*7c478bd9Sstevel@tonic-gate 			if (errorflag==0)
83*7c478bd9Sstevel@tonic-gate 				winner = (NODE *)stat3(PROGRAM, $1, $2, $3); }
84*7c478bd9Sstevel@tonic-gate 	| error			{ yyclearin; yyerror("bailing out"); }
85*7c478bd9Sstevel@tonic-gate 	;
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate begin:
89*7c478bd9Sstevel@tonic-gate 		XBEGIN '{' stat_list '}'	{ $$ = $3; }
90*7c478bd9Sstevel@tonic-gate 	| begin NL
91*7c478bd9Sstevel@tonic-gate 	| 	{ $$ = (int) 0; }
92*7c478bd9Sstevel@tonic-gate 	;
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate end:
96*7c478bd9Sstevel@tonic-gate 		XEND '{' stat_list '}'	{ $$ = $3; }
97*7c478bd9Sstevel@tonic-gate 	| end NL
98*7c478bd9Sstevel@tonic-gate 	|	{ $$ = (int) 0; }
99*7c478bd9Sstevel@tonic-gate 	;
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate compound_conditional:
103*7c478bd9Sstevel@tonic-gate 		conditional BOR conditional	{ $$ = op2(BOR, $1, $3); }
104*7c478bd9Sstevel@tonic-gate 	| conditional AND conditional	{ $$ = op2(AND, $1, $3); }
105*7c478bd9Sstevel@tonic-gate 	| NOT conditional		{ $$ = op1(NOT, $2); }
106*7c478bd9Sstevel@tonic-gate 	| '(' compound_conditional ')'	{ $$ = $2; }
107*7c478bd9Sstevel@tonic-gate 	;
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate compound_pattern:
111*7c478bd9Sstevel@tonic-gate 		pattern BOR pattern	{ $$ = op2(BOR, $1, $3); }
112*7c478bd9Sstevel@tonic-gate 	| pattern AND pattern	{ $$ = op2(AND, $1, $3); }
113*7c478bd9Sstevel@tonic-gate 	| NOT pattern		{ $$ = op1(NOT, $2); }
114*7c478bd9Sstevel@tonic-gate 	| '(' compound_pattern ')'	{ $$ = $2; }
115*7c478bd9Sstevel@tonic-gate 	;
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate conditional:
119*7c478bd9Sstevel@tonic-gate 		expr  {
120*7c478bd9Sstevel@tonic-gate 		$$ = op2(NE, $1,
121*7c478bd9Sstevel@tonic-gate 			valtonode(lookup(L_zeronull, symtab, 0), CCON));
122*7c478bd9Sstevel@tonic-gate 		}
123*7c478bd9Sstevel@tonic-gate 	| rel_expr
124*7c478bd9Sstevel@tonic-gate 	| lex_expr
125*7c478bd9Sstevel@tonic-gate 	| compound_conditional
126*7c478bd9Sstevel@tonic-gate 	;
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate else:
130*7c478bd9Sstevel@tonic-gate 		ELSE optNL
131*7c478bd9Sstevel@tonic-gate 	;
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate field:
135*7c478bd9Sstevel@tonic-gate 		FIELD		{ $$ = valtonode($1, CFLD); }
136*7c478bd9Sstevel@tonic-gate 	| INDIRECT term { $$ = op1(INDIRECT, $2); }
137*7c478bd9Sstevel@tonic-gate 	;
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate if:
141*7c478bd9Sstevel@tonic-gate 		IF '(' conditional ')' optNL	{ $$ = $3; }
142*7c478bd9Sstevel@tonic-gate 	;
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate lex_expr:
146*7c478bd9Sstevel@tonic-gate 		expr MATCHOP regular_expr	{
147*7c478bd9Sstevel@tonic-gate 			$$ = op2($2, $1, makedfa($3)); }
148*7c478bd9Sstevel@tonic-gate 	| '(' lex_expr ')'		{ $$ = $2; }
149*7c478bd9Sstevel@tonic-gate 	;
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate var:
153*7c478bd9Sstevel@tonic-gate 		NUMBER	{ $$ = valtonode($1, CCON); }
154*7c478bd9Sstevel@tonic-gate 	| STRING 	{ $$ = valtonode($1, CCON); }
155*7c478bd9Sstevel@tonic-gate 	| VAR		{ $$ = valtonode($1, CVAR); }
156*7c478bd9Sstevel@tonic-gate 	| VAR '[' expr ']'	{ $$ = op2(ARRAY, $1, $3); }
157*7c478bd9Sstevel@tonic-gate 	| field
158*7c478bd9Sstevel@tonic-gate 	;
159*7c478bd9Sstevel@tonic-gate term:
160*7c478bd9Sstevel@tonic-gate 		var
161*7c478bd9Sstevel@tonic-gate 	| GETLINE	{ $$ = op1(GETLINE, 0); }
162*7c478bd9Sstevel@tonic-gate 	| FNCN		{
163*7c478bd9Sstevel@tonic-gate 		$$ = op2(FNCN, $1,
164*7c478bd9Sstevel@tonic-gate 			valtonode(lookup(L_record, symtab, 0), CFLD));
165*7c478bd9Sstevel@tonic-gate 			}
166*7c478bd9Sstevel@tonic-gate 	| FNCN '(' ')'	{
167*7c478bd9Sstevel@tonic-gate 				$$ = op2(FNCN, $1,
168*7c478bd9Sstevel@tonic-gate 				valtonode(lookup(L_record, symtab, 0), CFLD));
169*7c478bd9Sstevel@tonic-gate 			}
170*7c478bd9Sstevel@tonic-gate 	| FNCN '(' expr ')'	{ $$ = op2(FNCN, $1, $3); }
171*7c478bd9Sstevel@tonic-gate 	| SPRINTF print_list	{ $$ = op1($1, $2); }
172*7c478bd9Sstevel@tonic-gate 	| SUBSTR '(' expr ',' expr ',' expr ')'
173*7c478bd9Sstevel@tonic-gate 			{ $$ = op3(SUBSTR, $3, $5, $7); }
174*7c478bd9Sstevel@tonic-gate 	| SUBSTR '(' expr ',' expr ')'
175*7c478bd9Sstevel@tonic-gate 			{ $$ = op3(SUBSTR, $3, $5, 0); }
176*7c478bd9Sstevel@tonic-gate 	| SPLIT '(' expr ',' VAR ',' expr ')'
177*7c478bd9Sstevel@tonic-gate 			{ $$ = op3(SPLIT, $3, $5, $7); }
178*7c478bd9Sstevel@tonic-gate 	| SPLIT '(' expr ',' VAR ')'
179*7c478bd9Sstevel@tonic-gate 			{ $$ = op3(SPLIT, $3, $5, 0); }
180*7c478bd9Sstevel@tonic-gate 	| INDEX '(' expr ',' expr ')'
181*7c478bd9Sstevel@tonic-gate 			{ $$ = op2(INDEX, $3, $5); }
182*7c478bd9Sstevel@tonic-gate 	| '(' expr ')'			{$$ = $2; }
183*7c478bd9Sstevel@tonic-gate 	| term '+' term			{ $$ = op2(ADD, $1, $3); }
184*7c478bd9Sstevel@tonic-gate 	| term '-' term			{ $$ = op2(MINUS, $1, $3); }
185*7c478bd9Sstevel@tonic-gate 	| term '*' term			{ $$ = op2(MULT, $1, $3); }
186*7c478bd9Sstevel@tonic-gate 	| term '/' term			{ $$ = op2(DIVIDE, $1, $3); }
187*7c478bd9Sstevel@tonic-gate 	| term '%' term			{ $$ = op2(MOD, $1, $3); }
188*7c478bd9Sstevel@tonic-gate 	| '-' term %prec QUEST		{ $$ = op1(UMINUS, $2); }
189*7c478bd9Sstevel@tonic-gate 	| '+' term %prec QUEST		{ $$ = $2; }
190*7c478bd9Sstevel@tonic-gate 	| INCR var	{ $$ = op1(PREINCR, $2); }
191*7c478bd9Sstevel@tonic-gate 	| DECR var	{ $$ = op1(PREDECR, $2); }
192*7c478bd9Sstevel@tonic-gate 	| var INCR	{ $$= op1(POSTINCR, $1); }
193*7c478bd9Sstevel@tonic-gate 	| var DECR	{ $$= op1(POSTDECR, $1); }
194*7c478bd9Sstevel@tonic-gate 	;
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate expr:
198*7c478bd9Sstevel@tonic-gate 		term
199*7c478bd9Sstevel@tonic-gate 	| expr term	{ $$ = op2(CAT, $1, $2); }
200*7c478bd9Sstevel@tonic-gate 	| var ASGNOP expr	{ $$ = op2($2, $1, $3); }
201*7c478bd9Sstevel@tonic-gate 	;
202*7c478bd9Sstevel@tonic-gate 
203*7c478bd9Sstevel@tonic-gate 
204*7c478bd9Sstevel@tonic-gate optNL:
205*7c478bd9Sstevel@tonic-gate 		NL
206*7c478bd9Sstevel@tonic-gate 	|
207*7c478bd9Sstevel@tonic-gate 	;
208*7c478bd9Sstevel@tonic-gate 
209*7c478bd9Sstevel@tonic-gate 
210*7c478bd9Sstevel@tonic-gate pa_stat:
211*7c478bd9Sstevel@tonic-gate 		pattern	{ $$ = stat2(PASTAT, $1, genprint()); }
212*7c478bd9Sstevel@tonic-gate 	| pattern '{' stat_list '}'	{ $$ = stat2(PASTAT, $1, $3); }
213*7c478bd9Sstevel@tonic-gate 	| pattern ',' pattern		{ $$ = pa2stat($1, $3, genprint()); }
214*7c478bd9Sstevel@tonic-gate 	| pattern ',' pattern '{' stat_list '}'
215*7c478bd9Sstevel@tonic-gate 					{ $$ = pa2stat($1, $3, $5); }
216*7c478bd9Sstevel@tonic-gate 	| '{' stat_list '}'	{ $$ = stat2(PASTAT, 0, $2); }
217*7c478bd9Sstevel@tonic-gate 	;
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate 
220*7c478bd9Sstevel@tonic-gate pa_stats:
221*7c478bd9Sstevel@tonic-gate 		pa_stats pa_stat st	{ $$ = linkum($1, $2); }
222*7c478bd9Sstevel@tonic-gate 	|	{ $$ = (int)0; }
223*7c478bd9Sstevel@tonic-gate 	| pa_stats pa_stat	{ $$ = linkum($1, $2); }
224*7c478bd9Sstevel@tonic-gate 	;
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate 
227*7c478bd9Sstevel@tonic-gate pattern:
228*7c478bd9Sstevel@tonic-gate 		regular_expr	{
229*7c478bd9Sstevel@tonic-gate 		$$ = op2(MATCH,
230*7c478bd9Sstevel@tonic-gate 		valtonode(lookup(L_record, symtab, 0), CFLD), makedfa($1));
231*7c478bd9Sstevel@tonic-gate 		}
232*7c478bd9Sstevel@tonic-gate 	| rel_expr
233*7c478bd9Sstevel@tonic-gate 	| lex_expr
234*7c478bd9Sstevel@tonic-gate 	| compound_pattern
235*7c478bd9Sstevel@tonic-gate 	;
236*7c478bd9Sstevel@tonic-gate 
237*7c478bd9Sstevel@tonic-gate 
238*7c478bd9Sstevel@tonic-gate print_list:
239*7c478bd9Sstevel@tonic-gate 	expr
240*7c478bd9Sstevel@tonic-gate 	| pe_list
241*7c478bd9Sstevel@tonic-gate 	|	{
242*7c478bd9Sstevel@tonic-gate 			$$ = valtonode(lookup(L_record, symtab, 0), CFLD);
243*7c478bd9Sstevel@tonic-gate 			}
244*7c478bd9Sstevel@tonic-gate 	;
245*7c478bd9Sstevel@tonic-gate 
246*7c478bd9Sstevel@tonic-gate 
247*7c478bd9Sstevel@tonic-gate pe_list:
248*7c478bd9Sstevel@tonic-gate 		expr ',' expr	{$$ = linkum($1, $3); }
249*7c478bd9Sstevel@tonic-gate 	| pe_list ',' expr	{$$ = linkum($1, $3); }
250*7c478bd9Sstevel@tonic-gate 	| '(' pe_list ')'		{$$ = $2; }
251*7c478bd9Sstevel@tonic-gate 	;
252*7c478bd9Sstevel@tonic-gate 
253*7c478bd9Sstevel@tonic-gate 
254*7c478bd9Sstevel@tonic-gate redir:
255*7c478bd9Sstevel@tonic-gate 		RELOP
256*7c478bd9Sstevel@tonic-gate 	| '|'
257*7c478bd9Sstevel@tonic-gate 	;
258*7c478bd9Sstevel@tonic-gate 
259*7c478bd9Sstevel@tonic-gate 
260*7c478bd9Sstevel@tonic-gate regular_expr:
261*7c478bd9Sstevel@tonic-gate 		'/'	{ startreg(); }
262*7c478bd9Sstevel@tonic-gate 		r '/'
263*7c478bd9Sstevel@tonic-gate 		{ $$ = $3; }
264*7c478bd9Sstevel@tonic-gate 	;
265*7c478bd9Sstevel@tonic-gate 
266*7c478bd9Sstevel@tonic-gate 
267*7c478bd9Sstevel@tonic-gate r:
268*7c478bd9Sstevel@tonic-gate 		CHAR		{ $$ = op2(CHAR, (NODE *) 0, $1); }
269*7c478bd9Sstevel@tonic-gate 	| DOT		{ $$ = op2(DOT, (NODE *) 0, (NODE *) 0); }
270*7c478bd9Sstevel@tonic-gate 	| CCL		{ $$ = op2(CCL, (NODE *) 0, cclenter($1)); }
271*7c478bd9Sstevel@tonic-gate 	| NCCL		{ $$ = op2(NCCL, (NODE *) 0, cclenter($1)); }
272*7c478bd9Sstevel@tonic-gate 	| '^'		{ $$ = op2(CHAR, (NODE *) 0, HAT); }
273*7c478bd9Sstevel@tonic-gate 	| '$'		{ $$ = op2(CHAR, (NODE *) 0, (NODE *) 0); }
274*7c478bd9Sstevel@tonic-gate 	| r OR r	{ $$ = op2(OR, $1, $3); }
275*7c478bd9Sstevel@tonic-gate 	| r r   %prec CAT
276*7c478bd9Sstevel@tonic-gate 			{ $$ = op2(CAT, $1, $2); }
277*7c478bd9Sstevel@tonic-gate 	| r STAR	{ $$ = op2(STAR, $1, (NODE *) 0); }
278*7c478bd9Sstevel@tonic-gate 	| r PLUS	{ $$ = op2(PLUS, $1, (NODE *) 0); }
279*7c478bd9Sstevel@tonic-gate 	| r QUEST	{ $$ = op2(QUEST, $1, (NODE *) 0); }
280*7c478bd9Sstevel@tonic-gate 	| '(' r ')'	{ $$ = $2; }
281*7c478bd9Sstevel@tonic-gate 	;
282*7c478bd9Sstevel@tonic-gate 
283*7c478bd9Sstevel@tonic-gate 
284*7c478bd9Sstevel@tonic-gate rel_expr:
285*7c478bd9Sstevel@tonic-gate 		expr RELOP expr
286*7c478bd9Sstevel@tonic-gate 		{ $$ = op2($2, $1, $3); }
287*7c478bd9Sstevel@tonic-gate 	| '(' rel_expr ')'
288*7c478bd9Sstevel@tonic-gate 		{ $$ = $2; }
289*7c478bd9Sstevel@tonic-gate 	;
290*7c478bd9Sstevel@tonic-gate 
291*7c478bd9Sstevel@tonic-gate 
292*7c478bd9Sstevel@tonic-gate st:
293*7c478bd9Sstevel@tonic-gate 		NL
294*7c478bd9Sstevel@tonic-gate 	| ';'
295*7c478bd9Sstevel@tonic-gate 	;
296*7c478bd9Sstevel@tonic-gate 
297*7c478bd9Sstevel@tonic-gate 
298*7c478bd9Sstevel@tonic-gate simple_stat:
299*7c478bd9Sstevel@tonic-gate 		PRINT print_list redir expr
300*7c478bd9Sstevel@tonic-gate 		{ $$ = stat3($1, $2, $3, $4); }
301*7c478bd9Sstevel@tonic-gate 	| PRINT print_list
302*7c478bd9Sstevel@tonic-gate 		{ $$ = stat3($1, $2, 0, 0); }
303*7c478bd9Sstevel@tonic-gate 	| PRINTF print_list redir expr
304*7c478bd9Sstevel@tonic-gate 		{ $$ = stat3($1, $2, $3, $4); }
305*7c478bd9Sstevel@tonic-gate 	| PRINTF print_list
306*7c478bd9Sstevel@tonic-gate 		{ $$ = stat3($1, $2, 0, 0); }
307*7c478bd9Sstevel@tonic-gate 	| expr	{ $$ = exptostat($1); }
308*7c478bd9Sstevel@tonic-gate 	|		{ $$ = (int)0; }
309*7c478bd9Sstevel@tonic-gate 	| error		{ yyclearin; yyerror("illegal statement"); $$ = (int)0; }
310*7c478bd9Sstevel@tonic-gate 	;
311*7c478bd9Sstevel@tonic-gate 
312*7c478bd9Sstevel@tonic-gate 
313*7c478bd9Sstevel@tonic-gate statement:
314*7c478bd9Sstevel@tonic-gate 		simple_stat st
315*7c478bd9Sstevel@tonic-gate 	| if statement		{ $$ = stat3(IF, $1, $2, 0); }
316*7c478bd9Sstevel@tonic-gate 	| if statement else statement
317*7c478bd9Sstevel@tonic-gate 		{ $$ = stat3(IF, $1, $2, $4); }
318*7c478bd9Sstevel@tonic-gate 	| while statement	{ $$ = stat2(WHILE, $1, $2); }
319*7c478bd9Sstevel@tonic-gate 	| for
320*7c478bd9Sstevel@tonic-gate 	| NEXT st		{ $$ = stat1(NEXT, 0); }
321*7c478bd9Sstevel@tonic-gate 	| EXIT st		{ $$ = stat1(EXIT, 0); }
322*7c478bd9Sstevel@tonic-gate 	| EXIT expr st		{ $$ = stat1(EXIT, $2); }
323*7c478bd9Sstevel@tonic-gate 	| BREAK st		{ $$ = stat1(BREAK, 0); }
324*7c478bd9Sstevel@tonic-gate 	| CONTINUE st		{ $$ = stat1(CONTINUE, 0); }
325*7c478bd9Sstevel@tonic-gate 	| '{' stat_list '}'	{ $$ = $2; }
326*7c478bd9Sstevel@tonic-gate 	;
327*7c478bd9Sstevel@tonic-gate 
328*7c478bd9Sstevel@tonic-gate 
329*7c478bd9Sstevel@tonic-gate stat_list:
330*7c478bd9Sstevel@tonic-gate 		stat_list statement	{ $$ = linkum($1, $2); }
331*7c478bd9Sstevel@tonic-gate 	|			{ $$ = (int)0; }
332*7c478bd9Sstevel@tonic-gate 	;
333*7c478bd9Sstevel@tonic-gate 
334*7c478bd9Sstevel@tonic-gate 
335*7c478bd9Sstevel@tonic-gate while:
336*7c478bd9Sstevel@tonic-gate 		WHILE '(' conditional ')' optNL	{ $$ = $3; }
337*7c478bd9Sstevel@tonic-gate 	;
338*7c478bd9Sstevel@tonic-gate 
339*7c478bd9Sstevel@tonic-gate 
340*7c478bd9Sstevel@tonic-gate for:
341*7c478bd9Sstevel@tonic-gate 	FOR '(' simple_stat ';' conditional ';' simple_stat ')' optNL statement
342*7c478bd9Sstevel@tonic-gate 		{ $$ = stat4(FOR, $3, $5, $7, $10); }
343*7c478bd9Sstevel@tonic-gate 	| FOR '(' simple_stat ';'  ';' simple_stat ')' optNL statement
344*7c478bd9Sstevel@tonic-gate 		{ $$ = stat4(FOR, $3, 0, $6, $9); }
345*7c478bd9Sstevel@tonic-gate 	| FOR '(' VAR IN VAR ')' optNL statement
346*7c478bd9Sstevel@tonic-gate 		{ $$ = stat3(IN, $3, $5, $8); }
347*7c478bd9Sstevel@tonic-gate 	;
348*7c478bd9Sstevel@tonic-gate 
349*7c478bd9Sstevel@tonic-gate 
350*7c478bd9Sstevel@tonic-gate %%
351