* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
* @(#)gram.head 5.1 (Berkeley) 6/7/85
* First part of the f77 grammar, f77 compiler pass 1.
* University of Utah CS Dept modification history:
* Revision 3.2 84/11/06 17:40:52 donn
* Fixed bug with redundant labels causing errors when they appear on (e.g.)
* Revision 3.1 84/10/13 00:22:16 donn
* Merged Jerry Berkman's version into mine.
* Revision 2.2 84/08/04 21:13:02 donn
* Moved some code out of gram.head into gram.exec in accordance with
* Jerry Berkman's fixes to make ASSIGNs work right.
* Revision 2.1 84/07/19 12:03:20 donn
* Changed comment headers for UofU.
* Revision 1.2 84/03/23 22:43:06 donn
* The subroutine argument temporary fixes from Bob Corbett didn't take into
* account the fact that the code generator collects all the assignments to
* temporaries at the start of a statement -- hence the temporaries need to
* be initialized once per statement instead of once per call.
static struct { expptr lb, ub; } dims[MAXDIM+1];
static struct Labelblock *labarray[MAXLABLIST];
static int lastwasbranch = NO;
static int thiswasbranch = NO;
expptr mklogcon(), mkaddcon(), mkrealcon(), mkstrcon(), mkbitcon();
struct Listblock *mklist();
struct Listblock *mklist();
struct Impldoblock *mkiodo();
struct Extsym *comblock();
/* Specify precedences and associativities. */
struct Labelblock *labval;
struct Nameblock *namval;
%nonassoc SLT SGT SLE SGE SEQ SNE
%type <labval> thislabel label assignlabel
%type <tagval> other inelt
%type <ival> lengspec type typespec typename dcl letter addop relop stop nameeq
%type <charpval> filename
%type <chval> namelistlist funarglist funargs dospec
%type <chval> callarglist arglist args exprlist inlist outlist out2 substring
%type <namval> name arg call var entryname progname
%type <expval> lhs expr uexpr opt_expr fexpr unpar_fexpr
%type <expval> ubound callarg complex_const simple_const
%type <extval> common comblock
%type <expval> datavalue real_const unsignedreal bit_const
%type <vexpval> unsignedint int_const
%type <vexpval> iconprimary iconfactor iconterm iconexpr opticonexpr
%type <drvals> datarval datarvals
%type <dvals> iconexprlist datasubs
%type <deltp> dataelt dataimplieddo datalval
%type <elistp> dlist datalvals
{ if($1 && ($1->labelno==dorange))
if(lastwasbranch && thislabel==NULL)
warn("statement cannot be reached");
lastwasbranch = thiswasbranch;
if($1->labtype == LABFORMAT)
err("label already that of a format");
argtemplist = hookup(argtemplist, activearglist);
| thislabel SINCLUDE filename
| thislabel SEND end_spec
{ lastwasbranch = NO; endproc(); }
{ execerr("unclassifiable statement", CNULL); flline(); };
{ flline(); needkwd = NO; inioctl = NO;
$$ = thislabel = mklabel(yystno);
if(thislabel->labdefined)
execerr("label %s already defined",
convic(thislabel->stateno) );
if(thislabel->blklevel!=0 && thislabel->blklevel<blklevel
&& thislabel->labtype!=LABFORMAT)
warn1("there is a branch to label %s from outside block",
convic( (ftnint) (thislabel->stateno) ) );
thislabel->blklevel = blklevel;
thislabel->labdefined = YES;
else $$ = thislabel = NULL;
entry: SPROGRAM new_proc progname
{startproc($3, CLMAIN); }
| SBLOCK new_proc progname
{ if($3) NO66("named BLOCKDATA");
startproc($3, CLBLOCK); }
| SSUBROUTINE new_proc entryname arglist
{ entrypt(CLPROC, TYSUBR, (ftnint) 0, $3, $4); }
| SFUNCTION new_proc entryname arglist
{ entrypt(CLPROC, TYUNKNOWN, (ftnint) 0, $3, $4); }
| type SFUNCTION new_proc entryname arglist
{ entrypt(CLPROC, $1, varleng, $4, $5); }
| SENTRY entryname arglist
{ if(parstate==OUTSIDE || procclass==CLMAIN
execerr("misplaced entry statement", CNULL);
entrypt(CLENTRY, 0, (ftnint) 0, $2, $3);
{ $$ = mkname(toklen, token); }
{ NO66(" () argument list");
{ $$ = ($1 ? mkchain($1,CHNULL) : CHNULL ); }
{ if($3) $1 = $$ = hookup($1, mkchain($3,CHNULL)); }
{ if(($1->vstg!=STGUNKNOWN && $1->vstg!=STGARG)
|| ($1->vclass == CLPARAM) ) {
dclerr("name declared as argument after use", $1);
{ NO66("altenate return argument");
$$ = 0; substars = YES; }
s = copyn(toklen+1, token);