🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #162

Re: FORTRAN, was Comment delimiters

#162
From: John Levine
Date: Sat, 17 Oct 2026 03:49
28 lines
2518 bytes
According to EricP  <ThatWouldBeTelling@thevillage.com>:
>I am under the impression that many Fortran 77 compilers used
>hand written lexer and a recursive decent parser.
>The parser passes some local context to the lexer to let it know,
>for example, which set of keywords are active at that point.
>Anyway, that is how I would do it.

I wrote a production FORTRAN 77 compiler.  It had a hand written lexer
and a yacc parser.

It made a prepass over each statement to combine continuation cards and to tell
whether it's an assignment statement or statement function (they're
syntactically the same) or something else. Once it knows that, the lexer is
straightforward using feedback from the parser to know what tokens are allowed
at each point.  As I recall there were about a dozen states, most of which were
simple, e.g., after a DO keyword the next thing has to be a digit string
which is a statement number.

The prepass was needed to disambiguate DO10I=1.10 and also to handle stuff like this:

10    FORMAT(I10,A5)       // a format statement

20    FORMAT(I10,A5) = 42  // an assignment statement

-- 
Regards,
John Levine, johnl@taugh.com, Primary Perpetrator of "The Internet for Dummies",
Please consider the environment before reading this e-mail. https://jl.ly
Technical Details
Message-ID: <11aur90$2b0g$1@gal.iecc.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!weretis.net!feeder9.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!not-for-mail
References: <1791742457-5857@newsgrouper.org> <HZQzS.6$TYg.3@fx21.iad> <2026Oct15.081750@mips.complang.tuwien.ac.at> <9ysAS.182538$QPx3.16043@fx17.iad>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!weretis.net!feeder9.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!not-for-mail
From: John Levine <johnl@taugh.com>
Newsgroups: comp.arch
Subject: Re: FORTRAN, was Comment delimiters
Date: Sat, 17 Oct 2026 03:49:53 -0000 (UTC)
Organization: Taughannock Networks
Message-ID: <11aur90$2b0g$1@gal.iecc.com>
References: <1791742457-5857@newsgrouper.org> <HZQzS.6$TYg.3@fx21.iad> <2026Oct15.081750@mips.complang.tuwien.ac.at> <9ysAS.182538$QPx3.16043@fx17.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 17 Oct 2026 03:49:53 -0000 (UTC)
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
	logging-data="76816"; mail-complaints-to="abuse@iecc.com"
In-Reply-To: <1791742457-5857@newsgrouper.org> <HZQzS.6$TYg.3@fx21.iad> <2026Oct15.081750@mips.complang.tuwien.ac.at> <9ysAS.182538$QPx3.16043@fx17.iad>
Cleverness: some
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: johnl@iecc.com (John Levine)