⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exec.c

📁 把fortran语言编的程序转为c语言编的程序, 运行环境linux
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************Copyright 1990, 1993, 1994 by AT&T Bell Laboratories and Bellcore.Permission to use, copy, modify, and distribute this softwareand its documentation for any purpose and without fee is herebygranted, provided that the above copyright notice appear in allcopies and that both that the copyright notice and thispermission notice and warranty disclaimer appear in supportingdocumentation, and that the names of AT&T Bell Laboratories orBellcore or any of their entities not be used in advertising orpublicity pertaining to distribution of the software withoutspecific, written prior permission.AT&T and Bellcore disclaim all warranties with regard to thissoftware, including all implied warranties of merchantabilityand fitness.  In no event shall AT&T or Bellcore be liable forany special, indirect or consequential damages or any damageswhatsoever resulting from loss of use, data or profits, whetherin an action of contract, negligence or other tortious action,arising out of or in connection with the use or performance ofthis software.****************************************************************/#include "defs.h"#include "p1defs.h"#include "names.h"static void exar2 Argdcl((int, tagptr, struct Labelblock*, struct Labelblock*));static void popctl Argdcl((void));static void pushctl Argdcl((int));/*   Logical IF codes*/ void#ifdef KR_headersexif(p)	expptr p;#elseexif(expptr p)#endif{    pushctl(CTLIF);    putif(p, 0);	/* 0 => if, not elseif */} void#ifdef KR_headersexelif(p)	expptr p;#elseexelif(expptr p)#endif{    if (ctlstack->ctltype == CTLIF || ctlstack->ctltype == CTLIFX)	putif(p, 1);	/* 1 ==> elseif */    else	execerr("elseif out of place", CNULL);} voidexelse(Void){	register struct Ctlframe *c;	for(c = ctlstack; c->ctltype == CTLIFX; --c);	if(c->ctltype == CTLIF) {		p1_else ();		c->ctltype = CTLELSE;		}	else		execerr("else out of place", CNULL);	} void#ifdef KR_headersexendif()#elseexendif()#endif{	while(ctlstack->ctltype == CTLIFX) {		popctl();		p1else_end();		}	if(ctlstack->ctltype == CTLIF) {		popctl();		p1_endif ();		}	else if(ctlstack->ctltype == CTLELSE) {		popctl();		p1else_end ();		}	else		execerr("endif out of place", CNULL);	} void#ifdef KR_headersnew_endif()#elsenew_endif()#endif{	if (ctlstack->ctltype == CTLIF || ctlstack->ctltype == CTLIFX)		pushctl(CTLIFX);	else		err("new_endif bug");	}/* pushctl -- Start a new control construct, initialize the labels (to   zero) */ LOCAL void#ifdef KR_headerspushctl(code)	int code;#elsepushctl(int code)#endif{	register int i;	if(++ctlstack >= lastctl)		many("loops or if-then-elses", 'c', maxctl);	ctlstack->ctltype = code;	for(i = 0 ; i < 4 ; ++i)		ctlstack->ctlabels[i] = 0;	ctlstack->dowhile = 0;	++blklevel;} LOCAL voidpopctl(Void){	if( ctlstack-- < ctls )		Fatal("control stack empty");	--blklevel;}/* poplab -- update the flags in   labeltab   */ LOCAL voidpoplab(Void){	register struct Labelblock  *lp;	for(lp = labeltab ; lp < highlabtab ; ++lp)		if(lp->labdefined)		{			/* mark all labels in inner blocks unreachable */			if(lp->blklevel > blklevel)				lp->labinacc = YES;		}		else if(lp->blklevel > blklevel)		{			/* move all labels referred to in inner blocks out a level */			lp->blklevel = blklevel;		}}/*  BRANCHING CODE*/ void#ifdef KR_headersexgoto(lab)	struct Labelblock *lab;#elseexgoto(struct Labelblock *lab)#endif{	lab->labused = 1;	p1_goto (lab -> stateno);} void#ifdef KR_headersexequals(lp, rp)	register struct Primblock *lp;	register expptr rp;#elseexequals(register struct Primblock *lp, register expptr rp)#endif{	if(lp->tag != TPRIM)	{		err("assignment to a non-variable");		frexpr((expptr)lp);		frexpr(rp);	}	else if(lp->namep->vclass!=CLVAR && lp->argsp)	{		if(parstate >= INEXEC)			errstr("statement function %.62s amid executables.",				lp->namep->fvarname);		mkstfunct(lp, rp);	}	else if (lp->vtype == TYSUBR)		err("illegal use of subroutine name");	else	{		expptr new_lp, new_rp;		if(parstate < INDATA)			enddcl();		new_lp = mklhs (lp, keepsubs);		new_rp = fixtype (rp);		puteq(new_lp, new_rp);	}}/* Make Statement Function */long laststfcn = -1, thisstno;int doing_stmtfcn; void#ifdef KR_headersmkstfunct(lp, rp)	struct Primblock *lp;	expptr rp;#elsemkstfunct(struct Primblock *lp, expptr rp)#endif{	register struct Primblock *p;	register Namep np;	chainp args;	laststfcn = thisstno;	np = lp->namep;	if(np->vclass == CLUNKNOWN)		np->vclass = CLPROC;	else	{		dclerr("redeclaration of statement function", np);		return;	}	np->vprocclass = PSTFUNCT;	np->vstg = STGSTFUNCT;/* Set the type of the function */	impldcl(np);	if (np->vtype == TYCHAR && !np->vleng)		err("character statement function with length (*)");	args = (lp->argsp ? lp->argsp->listp : CHNULL);	np->varxptr.vstfdesc = mkchain((char *)args, (chainp)rp);	for(doing_stmtfcn = 1 ; args ; args = args->nextp)/* It is an error for the formal parameters to have arguments or   subscripts */		if( ((tagptr)(args->datap))->tag!=TPRIM ||		    (p = (struct Primblock *)(args->datap) )->argsp ||		    p->fcharp || p->lcharp ) {			err("non-variable argument in statement function definition");			args->datap = 0;			}		else		{/* Replace the name on the left-hand side */			args->datap = (char *)p->namep;			vardcl(p -> namep);			free((char *)p);		}	doing_stmtfcn = 0;} static void#ifdef KR_headersmixed_type(np)	Namep np;#elsemixed_type(Namep np)#endif{	char buf[128];	sprintf(buf, "%s function %.90s invoked as subroutine",		ftn_types[np->vtype], np->fvarname);	warn(buf);	} void#ifdef KR_headersexcall(name, args, nstars, labels)	Namep name;	struct Listblock *args;	int nstars;	struct Labelblock **labels;#elseexcall(Namep name, struct Listblock *args, int nstars, struct Labelblock **labels)#endif{	register expptr p;	if (name->vtype != TYSUBR) {		if (name->vinfproc && !name->vcalled) {			name->vtype = TYSUBR;			frexpr(name->vleng);			name->vleng = 0;			}		else if (!name->vimpltype && name->vtype != TYUNKNOWN)			mixed_type(name);		else			settype(name, TYSUBR, (ftnint)0);		}	p = mkfunct( mkprim(name, args, CHNULL) );	if (p->tag == TERROR)		return;/* Subroutines and their identifiers acquire the type INT */	p->exprblock.vtype = p->exprblock.leftp->headblock.vtype = TYINT;/* Handle the alternate return mechanism */	if(nstars > 0)		putcmgo(putx(fixtype(p)), nstars, labels);	else		putexpr(p);} void#ifdef KR_headersexstop(stop, p)	int stop;	register expptr p;#elseexstop(int stop, register expptr p)#endif{	char *str;	int n;	if(p)	{		if( ! ISCONST(p) )		{			execerr("pause/stop argument must be constant", CNULL);			frexpr(p);			p = mkstrcon(0, CNULL);		}		else if( ISINT(p->constblock.vtype) )		{			str = convic(p->constblock.Const.ci);			n = strlen(str);			if(n > 0)			{				p->constblock.Const.ccp = copyn(n, str);				p->constblock.Const.ccp1.blanks = 0;				p->constblock.vtype = TYCHAR;				p->constblock.vleng = (expptr) ICON(n);			}			else				p = (expptr) mkstrcon(0, CNULL);		}		else if(p->constblock.vtype != TYCHAR)		{			execerr("pause/stop argument must be integer or string", CNULL);			p = (expptr) mkstrcon(0, CNULL);		}	}	else	p = (expptr) mkstrcon(0, CNULL);    {	expptr subr_call;	subr_call = call1(TYSUBR, (stop ? "s_stop" : "s_paus"), p);	putexpr( subr_call );    }}/* DO LOOP CODE */#define DOINIT	par[0]#define DOLIMIT	par[1]#define DOINCR	par[2]/* Macros for   ctlstack -> dostepsign   */#define VARSTEP	0#define POSSTEP	1#define NEGSTEP	2/* exdo -- generate DO loop code.  In the case of a variable increment,   positive increment tests are placed above the body, negative increment   tests are placed below (see   enddo()   ) */ void#ifdef KR_headersexdo(range, loopname, spec)	int range;	Namep loopname;	chainp spec;#elseexdo(int range, Namep loopname, chainp spec)#endif			/* range = end label */			/* input spec must have at least 2 exprs */{	register expptr p;	register Namep np;	chainp cp;		/* loops over the fields in   spec */	register int i;	int dotype;		/* type of the index variable */	int incsign;		/* sign of the increment, if it's constant				   */	Addrp dovarp;		/* loop index variable */	expptr doinit;		/* constant or register for init param */	expptr par[3];		/* local specification parameters */	expptr init, test, inc;	/* Expressions in the resulting FOR loop */	test = ENULL;	pushctl(CTLDO);	dorange = ctlstack->dolabel = range;	ctlstack->loopname = loopname;/* Declare the loop index */	np = (Namep)spec->datap;	ctlstack->donamep = NULL;	if (!np) { /* do while */		ctlstack->dowhile = 1;#if 0		if (loopname) {			if (loopname->vtype == TYUNKNOWN) {				loopname->vdcldone = 1;				loopname->vclass = CLLABEL;				loopname->vprocclass = PLABEL;				loopname->vtype = TYLABEL;				}			if (loopname->vtype == TYLABEL)				if (loopname->vdovar)					dclerr("already in use as a loop name",						loopname);				else					loopname->vdovar = 1;			else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -