Re: Parsing Fortran, was Programming language and IDE design

glen herrmannsfeldt <gah@ugcs.caltech.edu>
Tue, 19 Nov 2013 20:18:55 +0000 (UTC)

          From comp.compilers

Related articles
Re: Programming language and IDE design martin@gkc.org.uk (Martin Ward) (2013-11-16)
Re: Programming language and IDE design gneuner2@comcast.net (George Neuner) (2013-11-18)
Re: Programming language and IDE design gneuner2@comcast.net (George Neuner) (2013-11-19)
Re: Parsing Fortran, was Programming language and IDE design gah@ugcs.caltech.edu (glen herrmannsfeldt) (2013-11-19)
Re: Parsing Fortran, was Programming language and IDE design gah@ugcs.caltech.edu (glen herrmannsfeldt) (2013-11-21)
| List of all articles for this month |
From: glen herrmannsfeldt <gah@ugcs.caltech.edu>
Newsgroups: comp.compilers
Date: Tue, 19 Nov 2013 20:18:55 +0000 (UTC)
Organization: Aioe.org NNTP Server
References: 13-11-016 13-11-018 13-11-021
Keywords: Fortran, comment
Posted-Date: 21 Nov 2013 11:18:56 EST

George Neuner <gneuner2@comcast.net> wrote:
> Our esteemed moderator wrote:


>>[Fortran through F77 potentially had to look arbitrarily far ahead to
>>tell FORMAT statements from an assignment to an array called FORMAT.
>>BTDT. But I would be surprised if any modern languages were that hard
>>to lex. -John]


> You're right - I forgot that the FORMAT *statement* also could be
> confused with an assignment [I only ever used format strings with READ
> and WRITE]. That potentially could require a large lookahead.


It is the H format descriptor that complicates the parsing, and I
believe that has been removed by now from the standard. Even so, many
compilers still support it for back compatibility.


Because of this complication, WATFIV, at least the version I used,
disallowed 'FORMAT(' as the first seven characters of a statement that
wasn't a FORMAT statement. That is, no assignment to elements of an
array named FORMAT. (I believe WATFIV allows multiple assignment, so
there would have been a way to get around it.)


One feature of Fortran 66 was that you could store the format data
into an array (had to be an array, not a scalar) and use that in place
of a FORMAT statement. It always seemed obvious to me that the array
be named FORMAT.


I believe a favorite example might have been similar to:


1 FORMAT(I2,5H)=X(1,I2)


(and gfortran seems to allow this one.)


> But it's still LL(k). 8-)


> [Oh, sure, once you know whether a statement is an assignment or
> something else, parsing is trivial. -John]


As previously noted, fixed form is still allowed in the current and
proposed next standard. That is, all additions to the language since
Fortran 77 can also be written in fixed form. Someone presumably checks
to be sure that there aren't any new ambiguities added with the new
features.


-- glen
[I found that H descriptors were easy to handle, just pull them out in a
prepass. The problem was assignments that look like format statements:


            FORMAT(A5,I3,I5) = 42


WATFIV was a student compiler and probably concluded that any student
who wrote code like that deserved to fail. -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.