[comp.lang.fortran] Lexing and Parsing Fortran

vsnyder@jato.jpl.nasa.gov (Van Snyder) (05/15/91)

In article <1991May13.145417.257@craycos.com> jrbd@craycos.com (James Davies) writes: [stuff deleted]
>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
These problems are usually handled by (almost) regular lookahead in the
lexer.  The only non-regular thing that need be done is counting parenthesis
balance.  The "," at level zero after an "=" sign gives away the "do" and
the absence of an "=" sign says the second is not an assignment statement.

Some dialects, however, have things that seem to require even more feedback:
In Univac Fortran V, an ASSIGNed variable could appear ANYWHERE a statement
label could appear, including in an arithmetic-IF.  Furthermore, one could
leave alternatives off an arithmetic-IF, meaning "go to the next statement."
So the statement IF (expr) GO TO 10 can't be parsed until one knows the
type of "expr":  If it's logical, this is a logical IF.  If it's numeric,
this is an arithmetic-IF, and GOTO10 is a variable to which a label has
presumably been assigned.

Oof!


-- 
vsnyder@jato.Jpl.Nasa.Gov
ames!elroy!jato!vsnyder
vsnyder@jato.uucp