Re: Parsing Fortran, was specifying semantics

glen herrmannsfeldt <gah@ugcs.caltech.edu>
Fri, 4 Jul 2014 17:53:31 +0000 (UTC)

          From comp.compilers

Related articles
[3 earlier articles]
Re: specifying semantics, was Formatting of Language LRMs ivan@ootbcomp.com (Ivan Godard) (2014-06-28)
Re: specifying semantics, was Formatting of Language LRMs gneuner2@comcast.net (George Neuner) (2014-06-29)
Re: specifying semantics, was Formatting of Language LRMs ivan@ootbcomp.com (Ivan Godard) (2014-06-29)
Re: specifying semantics, was Formatting of Language LRMs anton@mips.complang.tuwien.ac.at (2014-07-02)
Re: specifying semantics, was Formatting of Language LRMs monnier@iro.umontreal.ca (Stefan Monnier) (2014-07-03)
Re: specifying semantics, was Formatting of Language LRMs DrDiettrich1@aol.com (Hans-Peter Diettrich) (2014-07-04)
Re: Parsing Fortran, was specifying semantics gah@ugcs.caltech.edu (glen herrmannsfeldt) (2014-07-04)
Re: Parsing Fortran, was specifying semantics wclodius@earthlink.net (2014-07-04)
| List of all articles for this month |

From: glen herrmannsfeldt <gah@ugcs.caltech.edu>
Newsgroups: comp.compilers
Date: Fri, 4 Jul 2014 17:53:31 +0000 (UTC)
Organization: Aioe.org NNTP Server
References: 14-06-010 14-06-023 14-06-025 14-06-027 14-06-030 14-06-031 14-07-003 14-07-006 14-07-011
Keywords: Fortran, comment
Posted-Date: 04 Jul 2014 14:05:51 EDT
X-Notice: Filtered by postfilter v. 0.8.2

Hans-Peter Diettrich <DrDiettrich1@aol.com> wrote:


(snip)


> whitespace popped up, where whitespace sometimes is required to separate
> keywords from identifiers, sometimes is optional:


> Fortran: D O I = ...
> Pascal: if x ...
> C: int i ...


(snip)


> [You can scan Fortran with longest match, but the things you're
> matching for are very context dependent. I've done it. I agree that
> it's unlikely we'll find a general model for different languages. -John]




The two favorite ones that I always remember for Fortran are:


            DO1I=1,2


and


            DO 1 I=1.2


(and with no IMPLICIT NONE in effect, or with DO1I already declared).


To avoid these kinds of problems, WATFIV disallows "FORMAT(" as the
first seven characters of a statement that isn't a FORMAT statement.


Doesn't seem like it is overly restrictive, but when using variable
format, I always called my array (it had to be an array back then)
FORMAT.


-- glen
[To parse a Fortran statement you first have to decide whether it's an
assignment or something else, after which you can use a simple
contnext sensitive longest match to find the tokens. To see if it's
an assignment, you look for an = sign that is not followed by a comma
that is not inside parens, being sure to skip over 'literal' and
9hHollerith strings and noting that in typical dialects the statement
REAL*4HFOO does not contain a Hollerith string.. It wasn't as hard as
it sounds. -John]


Post a followup to this message

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