Re: Keywords and Reserved Words in Fortran

Thomas Koenig <tkoenig@netcologne.de>
Thu, 10 Mar 2022 07:07:25 -0000 (UTC)

          From comp.compilers

Related articles
How do you create a grammar for a multi-language language? costello@mitre.org (Roger L Costello) (2022-03-03)
Re: How do you create a grammar for a multi-language language? DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2022-03-06)
Re: How do you create a grammar for a multi-language language? DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2022-03-07)
Re: How do you create a grammar for a multi-language language? gah4@u.washington.edu (gah4) (2022-03-06)
Keywords and Reserved Words christopher.f.clark@compiler-resources.com (Christopher F Clark) (2022-03-08)
Re: Keywords and Reserved Words robin51@dodo.com.au (Robin Vowels) (2022-03-10)
Re: Keywords and Reserved Words in Fortran tkoenig@netcologne.de (Thomas Koenig) (2022-03-10)
| List of all articles for this month |
From: Thomas Koenig <tkoenig@netcologne.de>
Newsgroups: comp.compilers
Date: Thu, 10 Mar 2022 07:07:25 -0000 (UTC)
Organization: news.netcologne.de
References: 22-03-004 22-03-009 22-03-015 22-03-016 22-03-017 22-03-021
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="37264"; mail-complaints-to="abuse@iecc.com"
Keywords: Fortran, parse, comment
Posted-Date: 11 Mar 2022 14:47:29 EST

Our moderator wrote


> [Having written production Fortran compilers, I can assure you that to
> do it right is quite ugly.


I can confirm that.


Looking at how a recent compiler does that, I can slightly rephrase
https://gcc.gnu.org/wiki/GFortranHacking :


The front end's action can be grouped into four phases:


Parsing: This converts source code into a stream of tokens which
describe the language. Because Fortran does not have reserved
keywords, the gfortran runs a series of matchers against code
trying to find one that matches a statement. On failing a match
an error message may be queued, and another matcher tried. If all
attempts at matching fail, the error queue is dumped to the user.


Resolution: This resolves things left over from the parsing phase,
such as types of expressions, and compile-time simplification of
constants. Many errors are issued in this phase. At the end of
this phase, the abstract syntax tree is finished.


[...]


This works (sort of) but has the drawback that cleaning up after an
error is error-prone (hah!) so there are a lot of ice-after-invalid
(internal compiler error after invalid code) issues that have emerged
over the years.
[As I recall, first I did a pass to fold continuation cards and mark
quoted and hollerith strings, then a pass to look for an equal sign
not inside parens and not followed by an comma, which said it was an
assignment statement, and then the parsing was straightforward. Eacn
non-assignment statement starts with a keyword and it is easy to tell
from the syntax when to look for another keyword. Repeat for the
statement that follows a logical IF with a special case for the
statement numbers in an arithmetic IF. -John]


Post a followup to this message

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