[comp.lang.fortran] VAX/VMS Fortran 77 extensions

chris2@garfield.MUN.EDU (Chris Paulse) (09/03/89)

I was recently sent some Fortran code which was written for
VAX/VMS that included some extensions that made our bsd f77 
compiler hiccup.  The particular extensions that did this were

  o  comments at the end of a line indicated as ...

     SOURCE GOES HERE  ! this is a comment

  o  the do/enddo construct

Does there exist a preprocessor for this flavor of F77 which
will easily convert it back to vanilla f77?

Chris Paulse
cpaulse@mun.bitnet          
cpaulse@kean.mun.ca            `I say to you that there is in     
                                operation at the present time     
                                a conspiracy to sell ... and I    
                                use the word sell advisedly ...   
                                this Country to the Dominion      
                                of Canada' -  Major Peter J.       
                                              Cashin at the        
                                              Newfoundland Convention

mccalpin@masig3.ocean.fsu.edu (John D. McCalpin) (09/03/89)

In message <5272@garfield.MUN.EDU> chris2@garfield.MUN.EDU (Chris
Paulse) writes:
>I was recently sent some Fortran code which was written for
>VAX/VMS that included some extensions that made our bsd f77 
>compiler hiccup.  The particular extensions that did this were
>  o  comments at the end of a line indicated as ...
>     SOURCE GOES HERE  ! this is a comment
>  o  the do/enddo construct
>Does there exist a preprocessor for this flavor of F77 which
>will easily convert it back to vanilla f77?

My mailer couldn't find garfield.mun.edu, so here is a lex program
that should do the trick.  It is possible to fool it by some obscure
constructs, (i.e. DO I = 1.0) but it does a pretty good job.
Since the request is for a bsd system, lex should certainly be
available....

/*									*/
/* format.lex								*/
/* by John D. McCalpin revised to 89.03.09				*/
/* mccalpin@scri1.scri.fsu.edu	mccalpin@delocn.udel.edu		*/
/*									*/
/* This lex program interprets DO...END_DO structures in Fortran	*/
/* programs, converting them to standard number DO loops.		*/
/*									*/
/* To compile:								*/
/*	lex format.lex							*/
/*	cc lex.yy.c -ll -o format					*/
/*									*/
	extern char *strchr();
	static int base = 10000;
	static int temp;
	static int index = 0;
	static int stack[200];
	int i;
	char *string;
%%
^[ \t0-9]+do[ \t]+[^0-9]	{		/* supports do/end_do	*/
		unput(yytext[yyleng-1]);	/* unget last character	*/
		yytext[yyleng-1]='\0';		/* delete last char	*/
		++base;				/* increment base	*/
		stack[index]=base; index++;	/* push base onto stack	*/
		printf("%s %d ",yytext,base);	/* write statement	*/
		}
^[ \t]+end[ _]*do	{			/* converts end_do	*/
		if ( index == 0 ) {		/* check stack		*/
			fprintf(stderr,"ERROR - too many end_do's\n");
			fprintf(stderr," last statement number %d\n",
						stack[index]);
			exit (1); }
		temp=stack[--index];		/* pop stack		*/
		printf("%d\t",temp);		/* write line number	*/
		for ( i = 1 ; i <= index ; i++)	/* add indentation	*/
			printf("    ");		/*   4 spaces per loop	*/
		printf("continue");		/* finish statement	*/
		}
!		{				/* deletes ! comments	*/
		yytext[yyleng-1]='c';		/* make it a comment	*/
		printf("\n%s",yytext);		/* print first part	*/
		}
_		;				/* delete underscores	*/




--
John D. McCalpin - mccalpin@masig1.ocean.fsu.edu
		   mccalpin@scri1.scri.fsu.edu
		   mccalpin@delocn.udel.edu