Fortran Parser Question

Paul Hughett hughett at mercur.uphs.upenn.edu
Mon Apr 16 10:39:48 EDT 2001


Hassan Aurag <aurag at geocities.com> wrote:

:  I am trying to write a Fortran parser in python.

:  What I need is really simple. Given a fortran file, get all variables
: with their type and decompose arthmetic operations. Stuff like a = b+c
: .... and check their types to see if those ops can be dangerous when
: ported on various platforms.

:  So, I won't need a full fledged compiler, but really something simple. I
: am new to regular exps and friends, so if anyone can help with something
: simple I can start with, please drop me a note!

I think you may be approaching this problem from the wrong direction.
Rather than building your own half-baked compiler, consider using an
existing Fortran compiler that is really, really picky and is often
used for writing portable software.  The Gnu folks write a lot of
portable software and I know from experience that their gcc compiler
is--with the right options--pretty good at catching non-portable
constructs.  I don't have much experience with their Fortran compiler
(g77) but I'd certainly check whether it's also good at catching
non-portable constructs.  If it works, it's certainly going to be much
easier than writing your own.

Another option: go to www.netlib.org, which is a site for numerical
analysis software, written mostly in Fortran, and browse around for
Fortran programming tools.  It wouldn't surprise me if something like
what you want already exists.  Look also at f2c, which is a
Fortran-to-C converter; even if it doesn't provide good diagnostics,
it contains a Fortran parser already written which you can try
adapting.

Paul Hughett




More information about the Python-list mailing list