Fortran Parser Question

Tim Roberts timr at probo.com
Sat Apr 14 01:58:01 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.

Mark is correct; this is a huge problem.  You basically need a full-fledged
compiler.  For example, to do a complete job, you're going to have to parse
statement functions and expand them when encountered.  IMPLICIT statements
are another interesting twist.  Most of the simple parsers you can download
are for Pascal-type languages.  Fortran's "rules" are quite different.

Now that we've discouraged you, can you give me a concrete example of the
kind of situation you want to detect?

> 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!

Fortran is likely to defy analysis with regular expressions.  You're going
to need a state-driven lexical analyzer.

Have you done a web search for Fortran parsers?
--
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list