147953Sbostic/*-
247953Sbostic * Copyright (c) 1980 The Regents of the University of California.
347953Sbostic * All rights reserved.
443210Sbostic *
547953Sbostic * %sccs.include.proprietary.c%
6*47958Sbostic *
7*47958Sbostic *	@(#)gram.exec	5.3 (Berkeley) 04/12/91
843210Sbostic */
943210Sbostic
1043210Sbostic/*
1143210Sbostic * gram.exec
1243210Sbostic *
1343210Sbostic * Grammar for executable statements, f77 compiler pass 1, 4.2 BSD.
1443210Sbostic *
1543210Sbostic * University of Utah CS Dept modification history:
1643210Sbostic *
1743210Sbostic * $Log:	gram.exec,v $
1843210Sbostic * Revision 3.1  84/10/13  00:36:41  donn
1943210Sbostic * Installed Jerry Berkman's version; preserved comment header.
2043210Sbostic *
2143210Sbostic * Revision 1.3  84/08/06  18:38:43  donn
2243210Sbostic * Fixed a bug in Jerry Berkman's label fixes which caused the same label to
2343210Sbostic * be generated twice for some types of logical IF statements.
2443210Sbostic *
2543210Sbostic * Revision 1.2  84/08/04  21:09:57  donn
2643210Sbostic * Added fixes from Jerry Berkman to allow proper ASSIGNS from format
2743210Sbostic * statement numbers.
2843210Sbostic *
2943210Sbostic */
3043210Sbostic
3143210Sbosticexec:	  iffable
3243210Sbostic	| SDO end_spec intonlyon label intonlyoff opt_comma dospec
3343210Sbostic		{
3443210Sbostic		if( !do_name_err ) {
3543210Sbostic		   if($4->labdefined)
3643210Sbostic			execerr("no backward DO loops", CNULL);
3743210Sbostic		   $4->blklevel = blklevel+1;
3843210Sbostic		   exdo($4->labelno, $7);
3943210Sbostic		   }
4043210Sbostic		}
4143210Sbostic	| logif iffable
4243210Sbostic		{ exendif();  thiswasbranch = NO; }
4343210Sbostic	| logif STHEN
4443210Sbostic	| SELSEIF end_spec SLPAR expr SRPAR STHEN
4543210Sbostic		{ exelif($4); lastwasbranch = NO; }
4643210Sbostic	| SELSE end_spec
4743210Sbostic		{ exelse(); lastwasbranch = NO; }
4843210Sbostic	| SENDIF end_spec
4943210Sbostic		{ exendif(); lastwasbranch = NO; }
5043210Sbostic	;
5143210Sbostic
5243210Sbosticlogif:	  SLOGIF end_spec SLPAR expr SRPAR
5343210Sbostic		{ exif($4); }
5443210Sbostic	;
5543210Sbostic
5643210Sbosticdospec:	  name SEQUALS exprlist
5743210Sbostic		{ if( $1->vclass != CLPARAM ) {
5843210Sbostic			$$ = mkchain($1, $3);
5943210Sbostic			do_name_err = 0;
6043210Sbostic		  } else {
6143210Sbostic			err("symbolic constant not allowed as DO variable");
6243210Sbostic		 	do_name_err = 1;
6343210Sbostic		  }
6443210Sbostic		}
6543210Sbostic	;
6643210Sbostic
6743210Sbosticiffable:  let lhs SEQUALS expr
6843210Sbostic		{ exequals($2, $4); }
6943210Sbostic	| SASSIGN end_spec assignlabel STO name
7043210Sbostic		{ if( $5->vclass != CLPARAM ) {
7143210Sbostic			exassign($5, $3);
7243210Sbostic		  } else {
7343210Sbostic			err("can only assign to a variable");
7443210Sbostic		  }
7543210Sbostic		}
7643210Sbostic	| SCONTINUE end_spec
7743210Sbostic	| goto
7843210Sbostic	| io
7943210Sbostic		{ inioctl = NO; }
8043210Sbostic	| SARITHIF end_spec SLPAR expr SRPAR label SCOMMA label SCOMMA label
8143210Sbostic		{ exarif($4, $6, $8, $10);  thiswasbranch = YES; }
8243210Sbostic	| call
8343210Sbostic		{ excall($1, PNULL, 0, labarray); }
8443210Sbostic	| call SLPAR SRPAR
8543210Sbostic		{ excall($1, PNULL, 0, labarray); }
8643210Sbostic	| call SLPAR callarglist SRPAR
8743210Sbostic		{ if(nstars < MAXLABLIST)
8843210Sbostic			excall($1, mklist($3), nstars, labarray);
8943210Sbostic		  else
9043210Sbostic			err("too many alternate returns");
9143210Sbostic		}
9243210Sbostic	| SRETURN end_spec opt_expr
9343210Sbostic		{ exreturn($3);  thiswasbranch = YES; }
9443210Sbostic	| stop end_spec opt_expr
9543210Sbostic		{ exstop($1, $3);  thiswasbranch = $1; }
9643210Sbostic	;
9743210Sbostic
9843210Sbosticassignlabel:   SICON
9943210Sbostic		{ $$ = mklabel( convci(toklen, token) ); }
10043210Sbostic	;
10143210Sbostic
10243210Sbosticlet:	  SLET
10343210Sbostic		{ if(parstate == OUTSIDE)
10443210Sbostic			{
10543210Sbostic			newproc();
10643210Sbostic			startproc(PNULL, CLMAIN);
10743210Sbostic			}
10843210Sbostic		  if( yystno != 0 && thislabel->labtype != LABFORMAT)
10943210Sbostic			if (optimflag)
11043210Sbostic				optbuff (SKLABEL, 0, thislabel->labelno, 1);
11143210Sbostic			else
11243210Sbostic				putlabel(thislabel->labelno);
11343210Sbostic		}
11443210Sbostic	;
11543210Sbostic
11643210Sbosticgoto:	  SGOTO end_spec label
11743210Sbostic		{ exgoto($3);  thiswasbranch = YES; }
11843210Sbostic	| SASGOTO end_spec name
11943210Sbostic		{ if( $3->vclass != CLPARAM ) {
12043210Sbostic			exasgoto($3);  thiswasbranch = YES;
12143210Sbostic		  } else {
12243210Sbostic			err("must go to label or assigned variable");
12343210Sbostic		  }
12443210Sbostic		}
12543210Sbostic	| SASGOTO end_spec name opt_comma SLPAR labellist SRPAR
12643210Sbostic		{ if( $3->vclass != CLPARAM ) {
12743210Sbostic			exasgoto($3);  thiswasbranch = YES;
12843210Sbostic		  } else {
12943210Sbostic			err("must go to label or assigned variable");
13043210Sbostic		  }
13143210Sbostic		}
13243210Sbostic	| SCOMPGOTO end_spec SLPAR labellist SRPAR opt_comma expr
13343210Sbostic		{ if(nstars < MAXLABLIST)
13443210Sbostic			if (optimflag)
13543210Sbostic			    optbuff (SKCMGOTO, fixtype($7), nstars, labarray);
13643210Sbostic			else
13743210Sbostic			    putcmgo (fixtype($7), nstars, labarray);
13843210Sbostic		  else
13943210Sbostic			err("computed GOTO list too long");
14043210Sbostic		}
14143210Sbostic	;
14243210Sbostic
14343210Sbosticopt_comma:
14443210Sbostic	| SCOMMA
14543210Sbostic	;
14643210Sbostic
14743210Sbosticcall:	  SCALL end_spec name
14843210Sbostic		{ nstars = 0; $$ = $3; }
14943210Sbostic	;
15043210Sbostic
15143210Sbosticcallarglist:  callarg
15243210Sbostic		{ $$ = ($1 ? mkchain($1,CHNULL) : CHNULL); }
15343210Sbostic	| callarglist SCOMMA callarg
15443210Sbostic		{ if($3)
15543210Sbostic			if($1) $$ = hookup($1, mkchain($3,CHNULL));
15643210Sbostic			else $$ = mkchain($3,CHNULL);
15743210Sbostic		  else
15843210Sbostic			$$ = $1;
15943210Sbostic		}
16043210Sbostic	;
16143210Sbostic
16243210Sbosticcallarg:  expr
16343210Sbostic	| SSTAR label
16443210Sbostic		{ if(nstars<MAXLABLIST) labarray[nstars++] = $2; $$ = 0; }
16543210Sbostic	;
16643210Sbostic
16743210Sbosticstop:	  SPAUSE
16843210Sbostic		{ $$ = 0; }
16943210Sbostic	| SSTOP
17043210Sbostic		{ $$ = 1; }
17143210Sbostic	;
17243210Sbostic
17343210Sbosticexprlist:  expr
17443210Sbostic		{ $$ = mkchain($1, CHNULL); }
17543210Sbostic	| exprlist SCOMMA expr
17643210Sbostic		{ $$ = hookup($1, mkchain($3,CHNULL) ); }
17743210Sbostic	;
17843210Sbostic
17943210Sbosticend_spec:
18043210Sbostic		{ if(parstate == OUTSIDE)
18143210Sbostic			{
18243210Sbostic			newproc();
18343210Sbostic			startproc(PNULL, CLMAIN);
18443210Sbostic			}
18543210Sbostic		  if(parstate < INDATA) enddcl();
18643210Sbostic		  if( yystno != 0 && thislabel->labtype != LABFORMAT)
18743210Sbostic			if (optimflag)
18843210Sbostic				optbuff (SKLABEL, 0, thislabel->labelno, 1);
18943210Sbostic			else
19043210Sbostic				putlabel(thislabel->labelno);
19143210Sbostic		  yystno = 0;
19243210Sbostic		}
19343210Sbostic	;
19443210Sbostic
19543210Sbosticintonlyon:
19643210Sbostic		{ intonly = YES; }
19743210Sbostic	;
19843210Sbostic
19943210Sbosticintonlyoff:
20043210Sbostic		{ intonly = NO; }
20143210Sbostic	;
202