xref: /minix3/usr.bin/indent/parse.c (revision 97c7d358ea5970ca59196ed90e975115245f9e76)
1*97c7d358SVivek Prakash /*	$NetBSD: parse.c,v 1.7 2003/08/07 11:14:09 agc Exp $	*/
2*97c7d358SVivek Prakash 
3*97c7d358SVivek Prakash /*
4*97c7d358SVivek Prakash  * Copyright (c) 1980, 1993
5*97c7d358SVivek Prakash  *	The Regents of the University of California.  All rights reserved.
6*97c7d358SVivek Prakash  *
7*97c7d358SVivek Prakash  * Redistribution and use in source and binary forms, with or without
8*97c7d358SVivek Prakash  * modification, are permitted provided that the following conditions
9*97c7d358SVivek Prakash  * are met:
10*97c7d358SVivek Prakash  * 1. Redistributions of source code must retain the above copyright
11*97c7d358SVivek Prakash  *    notice, this list of conditions and the following disclaimer.
12*97c7d358SVivek Prakash  * 2. Redistributions in binary form must reproduce the above copyright
13*97c7d358SVivek Prakash  *    notice, this list of conditions and the following disclaimer in the
14*97c7d358SVivek Prakash  *    documentation and/or other materials provided with the distribution.
15*97c7d358SVivek Prakash  * 3. Neither the name of the University nor the names of its contributors
16*97c7d358SVivek Prakash  *    may be used to endorse or promote products derived from this software
17*97c7d358SVivek Prakash  *    without specific prior written permission.
18*97c7d358SVivek Prakash  *
19*97c7d358SVivek Prakash  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*97c7d358SVivek Prakash  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*97c7d358SVivek Prakash  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*97c7d358SVivek Prakash  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*97c7d358SVivek Prakash  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*97c7d358SVivek Prakash  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*97c7d358SVivek Prakash  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*97c7d358SVivek Prakash  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*97c7d358SVivek Prakash  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*97c7d358SVivek Prakash  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*97c7d358SVivek Prakash  * SUCH DAMAGE.
30*97c7d358SVivek Prakash  */
31*97c7d358SVivek Prakash 
32*97c7d358SVivek Prakash /*
33*97c7d358SVivek Prakash  * Copyright (c) 1976 Board of Trustees of the University of Illinois.
34*97c7d358SVivek Prakash  * Copyright (c) 1985 Sun Microsystems, Inc.
35*97c7d358SVivek Prakash  * All rights reserved.
36*97c7d358SVivek Prakash  *
37*97c7d358SVivek Prakash  * Redistribution and use in source and binary forms, with or without
38*97c7d358SVivek Prakash  * modification, are permitted provided that the following conditions
39*97c7d358SVivek Prakash  * are met:
40*97c7d358SVivek Prakash  * 1. Redistributions of source code must retain the above copyright
41*97c7d358SVivek Prakash  *    notice, this list of conditions and the following disclaimer.
42*97c7d358SVivek Prakash  * 2. Redistributions in binary form must reproduce the above copyright
43*97c7d358SVivek Prakash  *    notice, this list of conditions and the following disclaimer in the
44*97c7d358SVivek Prakash  *    documentation and/or other materials provided with the distribution.
45*97c7d358SVivek Prakash  * 3. All advertising materials mentioning features or use of this software
46*97c7d358SVivek Prakash  *    must display the following acknowledgement:
47*97c7d358SVivek Prakash  *	This product includes software developed by the University of
48*97c7d358SVivek Prakash  *	California, Berkeley and its contributors.
49*97c7d358SVivek Prakash  * 4. Neither the name of the University nor the names of its contributors
50*97c7d358SVivek Prakash  *    may be used to endorse or promote products derived from this software
51*97c7d358SVivek Prakash  *    without specific prior written permission.
52*97c7d358SVivek Prakash  *
53*97c7d358SVivek Prakash  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54*97c7d358SVivek Prakash  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55*97c7d358SVivek Prakash  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56*97c7d358SVivek Prakash  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57*97c7d358SVivek Prakash  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58*97c7d358SVivek Prakash  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59*97c7d358SVivek Prakash  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60*97c7d358SVivek Prakash  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61*97c7d358SVivek Prakash  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62*97c7d358SVivek Prakash  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63*97c7d358SVivek Prakash  * SUCH DAMAGE.
64*97c7d358SVivek Prakash  */
65*97c7d358SVivek Prakash 
66*97c7d358SVivek Prakash #include <sys/cdefs.h>
67*97c7d358SVivek Prakash #ifndef lint
68*97c7d358SVivek Prakash #if 0
69*97c7d358SVivek Prakash static char sccsid[] = "@(#)parse.c	8.1 (Berkeley) 6/6/93";
70*97c7d358SVivek Prakash #else
71*97c7d358SVivek Prakash __RCSID("$NetBSD: parse.c,v 1.7 2003/08/07 11:14:09 agc Exp $");
72*97c7d358SVivek Prakash #endif
73*97c7d358SVivek Prakash #endif				/* not lint */
74*97c7d358SVivek Prakash 
75*97c7d358SVivek Prakash #include <stdio.h>
76*97c7d358SVivek Prakash #include "indent_globs.h"
77*97c7d358SVivek Prakash #include "indent_codes.h"
78*97c7d358SVivek Prakash 
79*97c7d358SVivek Prakash /* tk: the code for the construct scanned */
80*97c7d358SVivek Prakash void
parse(int tk)81*97c7d358SVivek Prakash parse(int tk)
82*97c7d358SVivek Prakash {
83*97c7d358SVivek Prakash 	int     i;
84*97c7d358SVivek Prakash 
85*97c7d358SVivek Prakash #ifdef debug
86*97c7d358SVivek Prakash 	printf("%2d - %s\n", tk, token);
87*97c7d358SVivek Prakash #endif
88*97c7d358SVivek Prakash 
89*97c7d358SVivek Prakash 	while (ps.p_stack[ps.tos] == ifhead && tk != elselit) {
90*97c7d358SVivek Prakash 		/* true if we have an if without an else */
91*97c7d358SVivek Prakash 		ps.p_stack[ps.tos] = stmt;	/* apply the if(..) stmt ::=
92*97c7d358SVivek Prakash 						 * stmt reduction */
93*97c7d358SVivek Prakash 		reduce();	/* see if this allows any reduction */
94*97c7d358SVivek Prakash 	}
95*97c7d358SVivek Prakash 
96*97c7d358SVivek Prakash 
97*97c7d358SVivek Prakash 	switch (tk) {		/* go on and figure out what to do with the
98*97c7d358SVivek Prakash 				 * input */
99*97c7d358SVivek Prakash 
100*97c7d358SVivek Prakash 	case decl:		/* scanned a declaration word */
101*97c7d358SVivek Prakash 		ps.search_brace = btype_2;
102*97c7d358SVivek Prakash 		/* indicate that following brace should be on same line */
103*97c7d358SVivek Prakash 		if (ps.p_stack[ps.tos] != decl) {	/* only put one
104*97c7d358SVivek Prakash 							 * declaration onto
105*97c7d358SVivek Prakash 							 * stack */
106*97c7d358SVivek Prakash 			break_comma = true;	/* while in declaration,
107*97c7d358SVivek Prakash 						 * newline should be forced
108*97c7d358SVivek Prakash 						 * after comma */
109*97c7d358SVivek Prakash 			ps.p_stack[++ps.tos] = decl;
110*97c7d358SVivek Prakash 			ps.il[ps.tos] = ps.i_l_follow;
111*97c7d358SVivek Prakash 
112*97c7d358SVivek Prakash 			if (ps.ljust_decl) {	/* only do if we want left
113*97c7d358SVivek Prakash 						 * justified declarations */
114*97c7d358SVivek Prakash 				ps.ind_level = 0;
115*97c7d358SVivek Prakash 				for (i = ps.tos - 1; i > 0; --i)
116*97c7d358SVivek Prakash 					if (ps.p_stack[i] == decl)
117*97c7d358SVivek Prakash 						++ps.ind_level;	/* indentation is number
118*97c7d358SVivek Prakash 								 * of declaration levels
119*97c7d358SVivek Prakash 								 * deep we are */
120*97c7d358SVivek Prakash 				ps.i_l_follow = ps.ind_level;
121*97c7d358SVivek Prakash 			}
122*97c7d358SVivek Prakash 		}
123*97c7d358SVivek Prakash 		break;
124*97c7d358SVivek Prakash 
125*97c7d358SVivek Prakash 	case ifstmt:		/* scanned if (...) */
126*97c7d358SVivek Prakash 		if (ps.p_stack[ps.tos] == elsehead && ps.else_if)	/* "else if ..." */
127*97c7d358SVivek Prakash 			ps.i_l_follow = ps.il[ps.tos];
128*97c7d358SVivek Prakash 	case dolit:		/* 'do' */
129*97c7d358SVivek Prakash 	case forstmt:		/* for (...) */
130*97c7d358SVivek Prakash 		ps.p_stack[++ps.tos] = tk;
131*97c7d358SVivek Prakash 		ps.il[ps.tos] = ps.ind_level = ps.i_l_follow;
132*97c7d358SVivek Prakash 		++ps.i_l_follow;/* subsequent statements should be indented 1 */
133*97c7d358SVivek Prakash 		ps.search_brace = btype_2;
134*97c7d358SVivek Prakash 		break;
135*97c7d358SVivek Prakash 
136*97c7d358SVivek Prakash 	case lbrace:		/* scanned { */
137*97c7d358SVivek Prakash 		break_comma = false;	/* don't break comma in an initial
138*97c7d358SVivek Prakash 					 * list */
139*97c7d358SVivek Prakash 		if (ps.p_stack[ps.tos] == stmt || ps.p_stack[ps.tos] == decl
140*97c7d358SVivek Prakash 		    || ps.p_stack[ps.tos] == stmtl)
141*97c7d358SVivek Prakash 			++ps.i_l_follow;	/* it is a random, isolated
142*97c7d358SVivek Prakash 						 * stmt group or a declaration */
143*97c7d358SVivek Prakash 		else {
144*97c7d358SVivek Prakash 			if (s_code == e_code) {
145*97c7d358SVivek Prakash 				/*
146*97c7d358SVivek Prakash 				 * only do this if there is nothing on the line
147*97c7d358SVivek Prakash 				 */
148*97c7d358SVivek Prakash 				--ps.ind_level;
149*97c7d358SVivek Prakash 				/*
150*97c7d358SVivek Prakash 				 * it is a group as part of a while, for, etc.
151*97c7d358SVivek Prakash 				 */
152*97c7d358SVivek Prakash 				if (ps.p_stack[ps.tos] == swstmt && ps.case_indent >= 1)
153*97c7d358SVivek Prakash 					--ps.ind_level;
154*97c7d358SVivek Prakash 				/*
155*97c7d358SVivek Prakash 				 * for a switch, brace should be two levels out from the code
156*97c7d358SVivek Prakash 				 */
157*97c7d358SVivek Prakash 			}
158*97c7d358SVivek Prakash 		}
159*97c7d358SVivek Prakash 
160*97c7d358SVivek Prakash 		ps.p_stack[++ps.tos] = lbrace;
161*97c7d358SVivek Prakash 		ps.il[ps.tos] = ps.ind_level;
162*97c7d358SVivek Prakash 		ps.p_stack[++ps.tos] = stmt;
163*97c7d358SVivek Prakash 		/* allow null stmt between braces */
164*97c7d358SVivek Prakash 		ps.il[ps.tos] = ps.i_l_follow;
165*97c7d358SVivek Prakash 		break;
166*97c7d358SVivek Prakash 
167*97c7d358SVivek Prakash 	case whilestmt:	/* scanned while (...) */
168*97c7d358SVivek Prakash 		if (ps.p_stack[ps.tos] == dohead) {
169*97c7d358SVivek Prakash 			/* it is matched with do stmt */
170*97c7d358SVivek Prakash 			ps.ind_level = ps.i_l_follow = ps.il[ps.tos];
171*97c7d358SVivek Prakash 			ps.p_stack[++ps.tos] = whilestmt;
172*97c7d358SVivek Prakash 			ps.il[ps.tos] = ps.ind_level = ps.i_l_follow;
173*97c7d358SVivek Prakash 		} else {	/* it is a while loop */
174*97c7d358SVivek Prakash 			ps.p_stack[++ps.tos] = whilestmt;
175*97c7d358SVivek Prakash 			ps.il[ps.tos] = ps.i_l_follow;
176*97c7d358SVivek Prakash 			++ps.i_l_follow;
177*97c7d358SVivek Prakash 			ps.search_brace = btype_2;
178*97c7d358SVivek Prakash 		}
179*97c7d358SVivek Prakash 
180*97c7d358SVivek Prakash 		break;
181*97c7d358SVivek Prakash 
182*97c7d358SVivek Prakash 	case elselit:		/* scanned an else */
183*97c7d358SVivek Prakash 
184*97c7d358SVivek Prakash 		if (ps.p_stack[ps.tos] != ifhead)
185*97c7d358SVivek Prakash 			diag(1, "Unmatched 'else'");
186*97c7d358SVivek Prakash 		else {
187*97c7d358SVivek Prakash 			ps.ind_level = ps.il[ps.tos];	/* indentation for else
188*97c7d358SVivek Prakash 							 * should be same as for
189*97c7d358SVivek Prakash 							 * if */
190*97c7d358SVivek Prakash 			ps.i_l_follow = ps.ind_level + 1;	/* everything following
191*97c7d358SVivek Prakash 								 * should be in 1 level */
192*97c7d358SVivek Prakash 			ps.p_stack[ps.tos] = elsehead;
193*97c7d358SVivek Prakash 			/* remember if with else */
194*97c7d358SVivek Prakash 			ps.search_brace = btype_2 | ps.else_if;
195*97c7d358SVivek Prakash 		}
196*97c7d358SVivek Prakash 		break;
197*97c7d358SVivek Prakash 
198*97c7d358SVivek Prakash 	case rbrace:		/* scanned a } */
199*97c7d358SVivek Prakash 		/* stack should have <lbrace> <stmt> or <lbrace> <stmtl> */
200*97c7d358SVivek Prakash 		if (ps.p_stack[ps.tos - 1] == lbrace) {
201*97c7d358SVivek Prakash 			ps.ind_level = ps.i_l_follow = ps.il[--ps.tos];
202*97c7d358SVivek Prakash 			ps.p_stack[ps.tos] = stmt;
203*97c7d358SVivek Prakash 		} else
204*97c7d358SVivek Prakash 			diag(1, "Stmt nesting error.");
205*97c7d358SVivek Prakash 		break;
206*97c7d358SVivek Prakash 
207*97c7d358SVivek Prakash 	case swstmt:		/* had switch (...) */
208*97c7d358SVivek Prakash 		ps.p_stack[++ps.tos] = swstmt;
209*97c7d358SVivek Prakash 		ps.cstk[ps.tos] = case_ind;
210*97c7d358SVivek Prakash 		/* save current case indent level */
211*97c7d358SVivek Prakash 		ps.il[ps.tos] = ps.i_l_follow;
212*97c7d358SVivek Prakash 		case_ind = ps.i_l_follow + ps.case_indent;	/* cases should be one
213*97c7d358SVivek Prakash 								 * level down from
214*97c7d358SVivek Prakash 								 * switch */
215*97c7d358SVivek Prakash 		ps.i_l_follow += ps.case_indent + 1;	/* statements should be
216*97c7d358SVivek Prakash 							 * two levels in */
217*97c7d358SVivek Prakash 		ps.search_brace = btype_2;
218*97c7d358SVivek Prakash 		break;
219*97c7d358SVivek Prakash 
220*97c7d358SVivek Prakash 	case semicolon:	/* this indicates a simple stmt */
221*97c7d358SVivek Prakash 		break_comma = false;	/* turn off flag to break after commas
222*97c7d358SVivek Prakash 					 * in a declaration */
223*97c7d358SVivek Prakash 		ps.p_stack[++ps.tos] = stmt;
224*97c7d358SVivek Prakash 		ps.il[ps.tos] = ps.ind_level;
225*97c7d358SVivek Prakash 		break;
226*97c7d358SVivek Prakash 
227*97c7d358SVivek Prakash 	default:		/* this is an error */
228*97c7d358SVivek Prakash 		diag(1, "Unknown code to parser");
229*97c7d358SVivek Prakash 		return;
230*97c7d358SVivek Prakash 
231*97c7d358SVivek Prakash 
232*97c7d358SVivek Prakash 	}			/* end of switch */
233*97c7d358SVivek Prakash 
234*97c7d358SVivek Prakash 	reduce();		/* see if any reduction can be done */
235*97c7d358SVivek Prakash 
236*97c7d358SVivek Prakash #ifdef debug
237*97c7d358SVivek Prakash 	for (i = 1; i <= ps.tos; ++i)
238*97c7d358SVivek Prakash 		printf("(%d %d)", ps.p_stack[i], ps.il[i]);
239*97c7d358SVivek Prakash 	printf("\n");
240*97c7d358SVivek Prakash #endif
241*97c7d358SVivek Prakash }
242*97c7d358SVivek Prakash /*
243*97c7d358SVivek Prakash  * NAME: reduce
244*97c7d358SVivek Prakash  *
245*97c7d358SVivek Prakash  * FUNCTION: Implements the reduce part of the parsing algorithm
246*97c7d358SVivek Prakash  *
247*97c7d358SVivek Prakash  * ALGORITHM: The following reductions are done.  Reductions are repeated
248*97c7d358SVivek Prakash  *	until no more are possible.
249*97c7d358SVivek Prakash  *
250*97c7d358SVivek Prakash  * Old TOS		New TOS
251*97c7d358SVivek Prakash  * <stmt> <stmt>	<stmtl>
252*97c7d358SVivek Prakash  * <stmtl> <stmt>	<stmtl>
253*97c7d358SVivek Prakash  * do <stmt>		"dostmt"
254*97c7d358SVivek Prakash  * if <stmt>		"ifstmt"
255*97c7d358SVivek Prakash  * switch <stmt>	<stmt>
256*97c7d358SVivek Prakash  * decl <stmt>		<stmt>
257*97c7d358SVivek Prakash  * "ifelse" <stmt>	<stmt>
258*97c7d358SVivek Prakash  * for <stmt>		<stmt>
259*97c7d358SVivek Prakash  * while <stmt>		<stmt>
260*97c7d358SVivek Prakash  * "dostmt" while	<stmt>
261*97c7d358SVivek Prakash  *
262*97c7d358SVivek Prakash  * On each reduction, ps.i_l_follow (the indentation for the following line)
263*97c7d358SVivek Prakash  * is set to the indentation level associated with the old TOS.
264*97c7d358SVivek Prakash  *
265*97c7d358SVivek Prakash  * PARAMETERS: None
266*97c7d358SVivek Prakash  *
267*97c7d358SVivek Prakash  * RETURNS: Nothing
268*97c7d358SVivek Prakash  *
269*97c7d358SVivek Prakash  * GLOBALS: ps.cstk ps.i_l_follow = ps.il ps.p_stack = ps.tos =
270*97c7d358SVivek Prakash  *
271*97c7d358SVivek Prakash  * CALLS: None
272*97c7d358SVivek Prakash  *
273*97c7d358SVivek Prakash  * CALLED BY: parse
274*97c7d358SVivek Prakash  *
275*97c7d358SVivek Prakash  * HISTORY: initial coding 	November 1976	D A Willcox of CAC
276*97c7d358SVivek Prakash  *
277*97c7d358SVivek Prakash  */
278*97c7d358SVivek Prakash /*----------------------------------------------*\
279*97c7d358SVivek Prakash |   REDUCTION PHASE				    |
280*97c7d358SVivek Prakash \*----------------------------------------------*/
281*97c7d358SVivek Prakash void
reduce(void)282*97c7d358SVivek Prakash reduce(void)
283*97c7d358SVivek Prakash {
284*97c7d358SVivek Prakash 
285*97c7d358SVivek Prakash 	int     i;
286*97c7d358SVivek Prakash 
287*97c7d358SVivek Prakash 	for (;;) {		/* keep looping until there is nothing left to
288*97c7d358SVivek Prakash 				 * reduce */
289*97c7d358SVivek Prakash 
290*97c7d358SVivek Prakash 		switch (ps.p_stack[ps.tos]) {
291*97c7d358SVivek Prakash 
292*97c7d358SVivek Prakash 		case stmt:
293*97c7d358SVivek Prakash 			switch (ps.p_stack[ps.tos - 1]) {
294*97c7d358SVivek Prakash 
295*97c7d358SVivek Prakash 			case stmt:
296*97c7d358SVivek Prakash 			case stmtl:
297*97c7d358SVivek Prakash 				/* stmtl stmt or stmt stmt */
298*97c7d358SVivek Prakash 				ps.p_stack[--ps.tos] = stmtl;
299*97c7d358SVivek Prakash 				break;
300*97c7d358SVivek Prakash 
301*97c7d358SVivek Prakash 			case dolit:	/* <do> <stmt> */
302*97c7d358SVivek Prakash 				ps.p_stack[--ps.tos] = dohead;
303*97c7d358SVivek Prakash 				ps.i_l_follow = ps.il[ps.tos];
304*97c7d358SVivek Prakash 				break;
305*97c7d358SVivek Prakash 
306*97c7d358SVivek Prakash 			case ifstmt:
307*97c7d358SVivek Prakash 				/* <if> <stmt> */
308*97c7d358SVivek Prakash 				ps.p_stack[--ps.tos] = ifhead;
309*97c7d358SVivek Prakash 				for (i = ps.tos - 1;
310*97c7d358SVivek Prakash 				    (
311*97c7d358SVivek Prakash 					ps.p_stack[i] != stmt
312*97c7d358SVivek Prakash 					&&
313*97c7d358SVivek Prakash 					ps.p_stack[i] != stmtl
314*97c7d358SVivek Prakash 					&&
315*97c7d358SVivek Prakash 					ps.p_stack[i] != lbrace
316*97c7d358SVivek Prakash 				    );
317*97c7d358SVivek Prakash 				    --i);
318*97c7d358SVivek Prakash 				ps.i_l_follow = ps.il[i];
319*97c7d358SVivek Prakash 				/*
320*97c7d358SVivek Prakash 				 * for the time being, we will assume that there is no else on
321*97c7d358SVivek Prakash 				 * this if, and set the indentation level accordingly. If an
322*97c7d358SVivek Prakash 				 * else is scanned, it will be fixed up later
323*97c7d358SVivek Prakash 				 */
324*97c7d358SVivek Prakash 				break;
325*97c7d358SVivek Prakash 
326*97c7d358SVivek Prakash 			case swstmt:
327*97c7d358SVivek Prakash 				/* <switch> <stmt> */
328*97c7d358SVivek Prakash 				case_ind = ps.cstk[ps.tos - 1];
329*97c7d358SVivek Prakash 
330*97c7d358SVivek Prakash 			case decl:	/* finish of a declaration */
331*97c7d358SVivek Prakash 			case elsehead:
332*97c7d358SVivek Prakash 				/* <<if> <stmt> else> <stmt> */
333*97c7d358SVivek Prakash 			case forstmt:
334*97c7d358SVivek Prakash 				/* <for> <stmt> */
335*97c7d358SVivek Prakash 			case whilestmt:
336*97c7d358SVivek Prakash 				/* <while> <stmt> */
337*97c7d358SVivek Prakash 				ps.p_stack[--ps.tos] = stmt;
338*97c7d358SVivek Prakash 				ps.i_l_follow = ps.il[ps.tos];
339*97c7d358SVivek Prakash 				break;
340*97c7d358SVivek Prakash 
341*97c7d358SVivek Prakash 			default:	/* <anything else> <stmt> */
342*97c7d358SVivek Prakash 				return;
343*97c7d358SVivek Prakash 
344*97c7d358SVivek Prakash 			}	/* end of section for <stmt> on top of stack */
345*97c7d358SVivek Prakash 			break;
346*97c7d358SVivek Prakash 
347*97c7d358SVivek Prakash 		case whilestmt:/* while (...) on top */
348*97c7d358SVivek Prakash 			if (ps.p_stack[ps.tos - 1] == dohead) {
349*97c7d358SVivek Prakash 				/* it is termination of a do while */
350*97c7d358SVivek Prakash 				ps.p_stack[--ps.tos] = stmt;
351*97c7d358SVivek Prakash 				break;
352*97c7d358SVivek Prakash 			} else
353*97c7d358SVivek Prakash 				return;
354*97c7d358SVivek Prakash 
355*97c7d358SVivek Prakash 		default:	/* anything else on top */
356*97c7d358SVivek Prakash 			return;
357*97c7d358SVivek Prakash 
358*97c7d358SVivek Prakash 		}
359*97c7d358SVivek Prakash 	}
360*97c7d358SVivek Prakash }
361