[comp.lang.fortran] lint like program for fortran

oneel@heawk1.rosserv.gsfc.nasa.gov ( Bruce Oneel ) (05/09/91)

This is probably a FAQ, but, is there a lint like program for fortran?
The best of all worlds is from the net for VAX/VMS fortran.

Thanks!!

bruce
--
Bruce O'Neel              oneel@heasfs.gsfc.nasa.gov
NASA/GSFC/STX/Code 664

gbastin@x102c.ess.harris.com (Gary Bastin 60293) (05/10/91)

My reply to this bounced, hence the post here...

In article <ONEEL.91May9115416@heawk1.rosserv.gsfc.nasa.gov> you write:
>This is probably a FAQ, but, is there a lint like program for fortran?

I posted a series of articles about FORCHEK recently.  It probably
comes closest to being a free 'lint for FORTRAN'.  The package, as
archived, had a bug in the Turbo-C makefile.  I have had no problems
porting FORCHEK to UNIX.  There is also a makefile for VAX; I have
no experience with that version of FORCHEK at all.  I also posted a
corrected Turbo-C makefile to allow successfully porting it to MSDOS.
Anyway, here is the key info that I posted along the path to
getting a running MSDOS version of FORCHEK.  Enjoy!
----------------------------------------------------------------------

forchek (short for  Fortran  checker)  is  designed  to
          detect  certain  errors in a Fortran program that a compiler
          usually does not.  Forchek  is  not  primarily  intended  to
          detect  syntax  errors. Its purpose is to assist the user in
          finding semantic errors. Semantic errors are  legal  in  the
          Fortran  language  but  are  wasteful or may cause incorrect
          operation. For example, variables which are never  used  may
          indicate   some   omission  in  the  program;  uninitialized
          variables contain garbage which may cause incorrect  results
          to  be  calculated; and variables which are not declared may
          not have the intended type. Bob Moniot, MONIOT@FORDMULC.BITNET

____________________________________________________________________

I would like to thank all the people who provided tips for compiling
FORCHEK Ver. 2.1 on a pc; you were all very helpful!  Now, I have
something like lint for FORTRAN on my PC!

Especially, thanks to Jim Davies (jrbd@craycos.com) who provided
the vital clues needed to straighten out my thinking regarding the
minimal compiler flags needed to compile FORCHEK using Turbo C on
a PC.

Basically, the problems were compiler directive related.  It was
necessary to delete the -d compiler flag.  For some reason, under
Turbo C Ver. 2.01, this particular flag caused the compiled executible
to do very strange things (spewing strange ASCII symbols, etc.)
when run.  There were other, more straight forward problems, with
the makefile.tc that was distributed.  To help others in speeding
up their compiling of FORCHEK on a PC, I have included a copy of
the Turbo C makefile I found to work at the end of this posting.

Many Thanks to all the people who contacted me, including:

cawlfld@nye.nscee.edu (David E. Cawlfield)
jrbd@craycos.com (James Davies)
kxb@math.ksu.edu (Karl Buck)
moshkovi@ecn.purdue.edu (Gennady Moshkovich)
ndeng@owl.ce.berkeley.edu (Nan Deng)
rao@amelia.nas.nasa.gov <Kuditipudi V. Rao>

For anyone who missed the earlier postings, FORCHEK is available from
the netlib server.  Just do the following:

mail netlib@research.att.com
send forchek from fortran

where the second line, "send forchek from fortran" is the subject,
and there is no actual body to the message.

A quick check of the archie server at McGill also shows that 
forchek is available from:

Host uokmax.ecn.uoknor.edu   (129.15.20.2)
Last updated 05:03 20 Apr 1991

    Location: /uploads
      FILE      rw-r--r--    107849  Jan 25 15:56   forchek.tar.Z


----

Gary Bastin, WB4YAF      /-/-/      Internet: gbastin@x102c.ess.harris.com
Mail Stop 102-4858         |        phone: (407) 729-3045
Harris Corporation GASD    |        
P.O.B. 94000, Melbourne FL 32902    Speaking from, but not for, Harris! 

new makefile.tc  (Copy this to makefile prior to running make.)
-------8<--CUT---HERE-----------------------------------------------

# Turbo C version of Makefile for Fortran program checker

# declare smaller data areas, and use the huge model.
CFLAGS= -DSMALL_MACHINE  -O -mh

OBJS=  exprtype.obj forchek.obj forlex.obj fortran.obj \
	prsymtab.obj symtab.obj


forchek: $(OBJS)
	tcc -eforchek $(CFLAGS) *.c


exprtype.obj: forchek.h symtab.h tokdefs.h

forchek.obj: forchek.h

forlex.obj: forchek.h tokdefs.h symtab.h

fortran.obj: forchek.h symtab.h fortran.c

prsymtab.obj: forchek.h symtab.h

symtab.obj: forchek.h symtab.h intrins.h

-------8<--CUT---HERE-----------------------------------------------

Gary Bastin, WB4YAF      /-/-/      Internet: gbastin@x102c.ess.harris.com
Mail Stop 102-4858         |        phone: (407) 729-3045
Harris Corporation GASD    |        
P.O.B. 94000, Melbourne FL 32902    Speaking from, but not for, Harris! 

jkorpela@vipunen.hut.fi (Jukka Korpela) (05/12/91)

A few comments on FORCHEK:
- It looks nice and useful in general.
- It is written in C but not entirely ANSI C conformantly.
- Its portability is decreased by the use of such global names in the
  program that there are serious difficulties if the recognition length
  for global names is, say, 6 or 8. (I tried to port it into VM/XA.)
- It ignores the fact that in FORTRAN blanks are insignificant. This is
  documented feature but not necessarily desirable.

wvenable@spam.ua.oz.au (Bill Venables) (05/12/91)

In article <JKORPELA.91May12124605@vipunen.hut.fi> jkorpela@vipunen.hut.fi
(Jukka Korpela) writes: 

:   A few comments on FORCHEK:
:   - It looks nice and useful in general.
:   - It is written in C but not entirely ANSI C conformantly.
:   - Its portability is decreased by the use of such global names in the
:     program that there are serious difficulties if the recognition length
:     for global names is, say, 6 or 8. (I tried to port it into VM/XA.)
:   - It ignores the fact that in FORTRAN blanks are insignificant. This is
:     documented feature but not necessarily desirable.
    
    - The parser is a yacc generated programme, but the yacc file is not
      part of the distribution.  This is, of course, the right of anyone
      offering free code, but somewhat unfortunate, since
	(a) porting is made more difficult as error messages from the
	    parser are given line numbers referring back to the original
	    (unavailable) forchek.y file,
	(b) the code is, as always with autogenerated parsers, unreadable,
	    and
	(c) the yacc file would have been interesting in its own right,
	    since using yacc to generate a parser for even a superficial
	    parsing of an old language like Fortran is no mean feat.

--
  Bill Venables, Dept. of Statistics,  | Email: venables@spam.adelaide.edu.au
  Univ. of Adelaide,  South Australia. | Phone:                +61 8 228 5412

jwe@che.utexas.edu (John W. Eaton) (05/13/91)

In article <WVENABLE.91May12231150@spam.ua.oz.au>
wvenable@spam.ua.oz.au (Bill Venables) writes about FORCHEK: 

>    - The parser is a yacc generated programme, but the yacc file is not
>      part of the distribution.  This is, of course, the right of anyone
>      offering free code, but somewhat unfortunate, since
>	(a) porting is made more difficult as error messages from the
>	    parser are given line numbers referring back to the original
>	    (unavailable) forchek.y file,

I agree that it would be useful to have the original yacc file in the
distribution.  Even without it though, it is not that difficult to
trace errors in the file fortran.c because the line numbers for the
error messages are determined from the preprocessor comments like this:

# line 345 "fortran.y"

--
John W. Eaton                       |  If the odds are a million to one
jwe@che.utexas.edu                  |  against something occurring, chances
Department of Chemical Engineering  |  are 50-50 it will.
The University of Texas at Austin   |                         -- fortune(1)

jrbd@craycos.com (James Davies) (05/13/91)

In article <WVENABLE.91May12231150@spam.ua.oz.au> wvenable@spam.ua.oz.au (Bill Venables) writes:
>In article <JKORPELA.91May12124605@vipunen.hut.fi> jkorpela@vipunen.hut.fi
>(Jukka Korpela) writes: 
>
>:   A few comments on FORCHEK:
 ...
>:   - It ignores the fact that in FORTRAN blanks are insignificant. This is
>:     documented feature but not necessarily desirable.

>	(c) the yacc file would have been interesting in its own right,
>	    since using yacc to generate a parser for even a superficial
>	    parsing of an old language like Fortran is no mean feat.

Actually, the hardest part of parsing Fortran (in my experience) is that
some feedback is needed from the parser to the lexical analyzer.  Partly
this is to handle holleriths and some other constants properly:
	do 10 h=1,10
	character*10 e10
and by requiring significant spaces FORCHEK dodges this problem.

Perhaps a more serious limitation is that FORCHEK doesn't handle equivalences.

winstead@faraday.ece.cmu.edu (Charles Holden Winstead) (05/13/91)

Other forchek questions:

- Is there any way to tell it to recognize double precision?

- Is there any way for it to recognize subroutines and functions with
  a "_" in the name?   i.e.  call find_minimum(a,b,c).

I realize this isn't standard FORTRAN, but then I don't much care about 
portability.  I write programs to get answers on my system.

Thanks!

-Chuck