1*22824Smckusick/*
2*22824Smckusick * Copyright (c) 1980 Regents of the University of California.
3*22824Smckusick * All rights reserved.  The Berkeley software License Agreement
4*22824Smckusick * specifies the terms and conditions for redistribution.
5*22824Smckusick *
6*22824Smckusick *	@(#)gram.exec	5.1 (Berkeley) 06/07/85
7*22824Smckusick */
8*22824Smckusick
9*22824Smckusick/*
10*22824Smckusick * gram.exec
11*22824Smckusick *
12*22824Smckusick * Grammar for executable statements, f77 compiler pass 1, 4.2 BSD.
13*22824Smckusick *
14*22824Smckusick * University of Utah CS Dept modification history:
15*22824Smckusick *
16*22824Smckusick * $Log:	gram.exec,v $
17*22824Smckusick * Revision 3.1  84/10/13  00:36:41  donn
18*22824Smckusick * Installed Jerry Berkman's version; preserved comment header.
19*22824Smckusick *
20*22824Smckusick * Revision 1.3  84/08/06  18:38:43  donn
21*22824Smckusick * Fixed a bug in Jerry Berkman's label fixes which caused the same label to
22*22824Smckusick * be generated twice for some types of logical IF statements.
23*22824Smckusick *
24*22824Smckusick * Revision 1.2  84/08/04  21:09:57  donn
25*22824Smckusick * Added fixes from Jerry Berkman to allow proper ASSIGNS from format
26*22824Smckusick * statement numbers.
27*22824Smckusick *
28*22824Smckusick */
29*22824Smckusick
30*22824Smckusickexec:	  iffable
31*22824Smckusick	| SDO end_spec intonlyon label intonlyoff opt_comma dospec
32*22824Smckusick		{
33*22824Smckusick		if( !do_name_err ) {
34*22824Smckusick		   if($4->labdefined)
35*22824Smckusick			execerr("no backward DO loops", CNULL);
36*22824Smckusick		   $4->blklevel = blklevel+1;
37*22824Smckusick		   exdo($4->labelno, $7);
38*22824Smckusick		   }
39*22824Smckusick		}
40*22824Smckusick	| logif iffable
41*22824Smckusick		{ exendif();  thiswasbranch = NO; }
42*22824Smckusick	| logif STHEN
43*22824Smckusick	| SELSEIF end_spec SLPAR expr SRPAR STHEN
44*22824Smckusick		{ exelif($4); lastwasbranch = NO; }
45*22824Smckusick	| SELSE end_spec
46*22824Smckusick		{ exelse(); lastwasbranch = NO; }
47*22824Smckusick	| SENDIF end_spec
48*22824Smckusick		{ exendif(); lastwasbranch = NO; }
49*22824Smckusick	;
50*22824Smckusick
51*22824Smckusicklogif:	  SLOGIF end_spec SLPAR expr SRPAR
52*22824Smckusick		{ exif($4); }
53*22824Smckusick	;
54*22824Smckusick
55*22824Smckusickdospec:	  name SEQUALS exprlist
56*22824Smckusick		{ if( $1->vclass != CLPARAM ) {
57*22824Smckusick			$$ = mkchain($1, $3);
58*22824Smckusick			do_name_err = 0;
59*22824Smckusick		  } else {
60*22824Smckusick			err("symbolic constant not allowed as DO variable");
61*22824Smckusick		 	do_name_err = 1;
62*22824Smckusick		  }
63*22824Smckusick		}
64*22824Smckusick	;
65*22824Smckusick
66*22824Smckusickiffable:  let lhs SEQUALS expr
67*22824Smckusick		{ exequals($2, $4); }
68*22824Smckusick	| SASSIGN end_spec assignlabel STO name
69*22824Smckusick		{ if( $5->vclass != CLPARAM ) {
70*22824Smckusick			exassign($5, $3);
71*22824Smckusick		  } else {
72*22824Smckusick			err("can only assign to a variable");
73*22824Smckusick		  }
74*22824Smckusick		}
75*22824Smckusick	| SCONTINUE end_spec
76*22824Smckusick	| goto
77*22824Smckusick	| io
78*22824Smckusick		{ inioctl = NO; }
79*22824Smckusick	| SARITHIF end_spec SLPAR expr SRPAR label SCOMMA label SCOMMA label
80*22824Smckusick		{ exarif($4, $6, $8, $10);  thiswasbranch = YES; }
81*22824Smckusick	| call
82*22824Smckusick		{ excall($1, PNULL, 0, labarray); }
83*22824Smckusick	| call SLPAR SRPAR
84*22824Smckusick		{ excall($1, PNULL, 0, labarray); }
85*22824Smckusick	| call SLPAR callarglist SRPAR
86*22824Smckusick		{ if(nstars < MAXLABLIST)
87*22824Smckusick			excall($1, mklist($3), nstars, labarray);
88*22824Smckusick		  else
89*22824Smckusick			err("too many alternate returns");
90*22824Smckusick		}
91*22824Smckusick	| SRETURN end_spec opt_expr
92*22824Smckusick		{ exreturn($3);  thiswasbranch = YES; }
93*22824Smckusick	| stop end_spec opt_expr
94*22824Smckusick		{ exstop($1, $3);  thiswasbranch = $1; }
95*22824Smckusick	;
96*22824Smckusick
97*22824Smckusickassignlabel:   SICON
98*22824Smckusick		{ $$ = mklabel( convci(toklen, token) ); }
99*22824Smckusick	;
100*22824Smckusick
101*22824Smckusicklet:	  SLET
102*22824Smckusick		{ if(parstate == OUTSIDE)
103*22824Smckusick			{
104*22824Smckusick			newproc();
105*22824Smckusick			startproc(PNULL, CLMAIN);
106*22824Smckusick			}
107*22824Smckusick		  if( yystno != 0 && thislabel->labtype != LABFORMAT)
108*22824Smckusick			if (optimflag)
109*22824Smckusick				optbuff (SKLABEL, 0, thislabel->labelno, 1);
110*22824Smckusick			else
111*22824Smckusick				putlabel(thislabel->labelno);
112*22824Smckusick		}
113*22824Smckusick	;
114*22824Smckusick
115*22824Smckusickgoto:	  SGOTO end_spec label
116*22824Smckusick		{ exgoto($3);  thiswasbranch = YES; }
117*22824Smckusick	| SASGOTO end_spec name
118*22824Smckusick		{ if( $3->vclass != CLPARAM ) {
119*22824Smckusick			exasgoto($3);  thiswasbranch = YES;
120*22824Smckusick		  } else {
121*22824Smckusick			err("must go to label or assigned variable");
122*22824Smckusick		  }
123*22824Smckusick		}
124*22824Smckusick	| SASGOTO end_spec name opt_comma SLPAR labellist SRPAR
125*22824Smckusick		{ if( $3->vclass != CLPARAM ) {
126*22824Smckusick			exasgoto($3);  thiswasbranch = YES;
127*22824Smckusick		  } else {
128*22824Smckusick			err("must go to label or assigned variable");
129*22824Smckusick		  }
130*22824Smckusick		}
131*22824Smckusick	| SCOMPGOTO end_spec SLPAR labellist SRPAR opt_comma expr
132*22824Smckusick		{ if(nstars < MAXLABLIST)
133*22824Smckusick			if (optimflag)
134*22824Smckusick			    optbuff (SKCMGOTO, fixtype($7), nstars, labarray);
135*22824Smckusick			else
136*22824Smckusick			    putcmgo (fixtype($7), nstars, labarray);
137*22824Smckusick		  else
138*22824Smckusick			err("computed GOTO list too long");
139*22824Smckusick		}
140*22824Smckusick	;
141*22824Smckusick
142*22824Smckusickopt_comma:
143*22824Smckusick	| SCOMMA
144*22824Smckusick	;
145*22824Smckusick
146*22824Smckusickcall:	  SCALL end_spec name
147*22824Smckusick		{ nstars = 0; $$ = $3; }
148*22824Smckusick	;
149*22824Smckusick
150*22824Smckusickcallarglist:  callarg
151*22824Smckusick		{ $$ = ($1 ? mkchain($1,CHNULL) : CHNULL); }
152*22824Smckusick	| callarglist SCOMMA callarg
153*22824Smckusick		{ if($3)
154*22824Smckusick			if($1) $$ = hookup($1, mkchain($3,CHNULL));
155*22824Smckusick			else $$ = mkchain($3,CHNULL);
156*22824Smckusick		  else
157*22824Smckusick			$$ = $1;
158*22824Smckusick		}
159*22824Smckusick	;
160*22824Smckusick
161*22824Smckusickcallarg:  expr
162*22824Smckusick	| SSTAR label
163*22824Smckusick		{ if(nstars<MAXLABLIST) labarray[nstars++] = $2; $$ = 0; }
164*22824Smckusick	;
165*22824Smckusick
166*22824Smckusickstop:	  SPAUSE
167*22824Smckusick		{ $$ = 0; }
168*22824Smckusick	| SSTOP
169*22824Smckusick		{ $$ = 1; }
170*22824Smckusick	;
171*22824Smckusick
172*22824Smckusickexprlist:  expr
173*22824Smckusick		{ $$ = mkchain($1, CHNULL); }
174*22824Smckusick	| exprlist SCOMMA expr
175*22824Smckusick		{ $$ = hookup($1, mkchain($3,CHNULL) ); }
176*22824Smckusick	;
177*22824Smckusick
178*22824Smckusickend_spec:
179*22824Smckusick		{ if(parstate == OUTSIDE)
180*22824Smckusick			{
181*22824Smckusick			newproc();
182*22824Smckusick			startproc(PNULL, CLMAIN);
183*22824Smckusick			}
184*22824Smckusick		  if(parstate < INDATA) enddcl();
185*22824Smckusick		  if( yystno != 0 && thislabel->labtype != LABFORMAT)
186*22824Smckusick			if (optimflag)
187*22824Smckusick				optbuff (SKLABEL, 0, thislabel->labelno, 1);
188*22824Smckusick			else
189*22824Smckusick				putlabel(thislabel->labelno);
190*22824Smckusick		  yystno = 0;
191*22824Smckusick		}
192*22824Smckusick	;
193*22824Smckusick
194*22824Smckusickintonlyon:
195*22824Smckusick		{ intonly = YES; }
196*22824Smckusick	;
197*22824Smckusick
198*22824Smckusickintonlyoff:
199*22824Smckusick		{ intonly = NO; }
200*22824Smckusick	;
201