Other people have mentioned Waite's F90 grammar. I have modified it to create
an F95 grammar, which you are welcome to. There is also a grammar for HPF,
which includes F90, available as part of an HPF compiler at the University of
Syracuse. It is available on the web but I don't remember the page at the
moment. I have not looked at it in detail.
Before you decide what grammar to use, you really have to ask what you intend
to do with it. From the way you posed the question you sounded
unsophisticated, but for unsophisticated users I expect that the less formal
language of his main text, or of something like Metcalf and Reid, is adequate.
I suspect that one of Brainerd's texts is best if you want to use the grammar
only to get some insight into the languages syntactical structure as part of
the process of learning to use the language. The grammar in Brainerd's texts
or the standard also might be best if you want to create very simple tools,
e.g., syntactic highlighting for an editor. However, be aware that the same
language can be described by a number of different grammars, and the best
grammar for discussing informal usage need not be the best grammar for some
forms of implementation, and additional semantic information, e.g., the
constraints in the standard or Brainerd's texts, is needed for more
sophisticated usages.
Some requests for this sort of information are for use with automated tools
such as YACC. These tools almost invariably require that the grammar be simple
to interpret, YACC in particular requires that the grammar be of the form
LALR(1) ((L)ook (A)head (L)eft to right constructing a (R)ightmost derivation
with 1 token of lookahead). Other tools may require LL(1) or LL(k) grammars.
The standard's grammar is not LALR(k) with k finite, there are some
constructs, such as statement functions or DO loops in their most general
form, that can only be recognized semantically. There are other constructs in
the official grammar that have to be rewritten as a series of simpler
constructs to be put in LALR(1) form. Format codes introduce a sublanguage
that is difficult to deal with consistently as part of the whole language (and
in come contexts cannot be dealt with.) The grammar, which only describes
correct programs, is also not the best one to use if you want to properly
report errors for erroneous constructs.
Eli's parser generators (it has options for two different parser generators)
are similar to YACC's in that they requires LALR(1) grammars. Waite has put in
a significant amount of effort in dealing with recognizing semantic
constructs, reporting problems with format codes at compile time, and
recognizing a superset of the language so that more detailed error messages
can be generated. He also provides a semantics analysis for Fortran 77.
However, this semantics analyzer is not currently compatible with his F90
parser. I have recently started modifying the semantics analyzer so that it
can be used to analyze F77 as a subset (retaining deleted constructs) of F95.
It appears that this will suggest minor changes in my F95 parser.
You could use Waite's grammar directly with Eli if you have a UNIX based
system (warning Eli is a complex tool), or transform it to a YACC compatible
form. Note you will also want a lexical analyzer and fixed format Fortran is
not well suited for automated tools. Waite does a good job with his lexical
analyzer, but rolling your own may be preferable.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|