🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #151

Re: Comment delimiters

#151
From: EricP
Date: Fri, 16 Oct 2026 16:46
101 lines
6020 bytes
On 2026-Oct-15 02:17, Anton Ertl wrote:
> EricP <ThatWouldBeTelling@thevillage.com> writes:
>> Old FORTRAN is difficult to parse because
>> a) it did not separate the language into lexical and syntax levels
>> b) it was white space oblivious except in quoted strings
>> c) there were no reserved words - keywords were statement
>>     position and sometimes semantic context dependent.
>> d) statements were based on punch cards BUT because
>>     continuation cards used the absence of a C in column 6
>>     to indicate the start of a new statement, parsers have to
>>     always look ahead to see in the next card has a C and
>>     then "unget" the card if not.
> 
> Given that the original FORTRAN worked on an IBM 704, I think that the
> designers made it as easy (and with as little memory) to parse as they
> could, given the state of the art at the time.  Concerning the points:
> 
> a) I guess that the division into lexical and syntax levels had not
>     been developed at the time; and even later, e.g., Wirth does not
>     make this distinction in his language definitions, using EBNF down
>     to the lexical level (although he does define reserved words).
> 
> b) Without this distinction, if you ignore white space at all, you
>     either ignore it everywhere, or give it a special role in your
>     syntax.  Ignoring is probably simpler.
> 
> c) The programming language community took quite a while until it
>     arrived at reserved words.  E.g., while Algol 60 was specified in
>     BNF, being modern in that regard, it does not have reserved words,
>     just symbols that are distinct from all identifiers; i.e., you
>     could have an identifier like IF in Algol 60, distinct from the
>     symbol 'IF', and it's up to the implementation how to distinguish
>     them.  Anyway, without a) reserved words make no sense.
> 
> d) Does the original FORTRAN support continuation cards?

Yes. Fortran's continuation card is LL(1) and behaves the same as
an ISA with start bits - you have to look ahead to find out
that you didn't need to look ahead, and unget the card.

Statement terminators like ; act like ISA stop bits and don't need lookahead.

>> The classic ambiguous parsing example being
>>
>>    DO I = 1,100
>>    DOI = 1.100
>>
>> depends on the presence or absence of a "naked comma" later in the
>> statement to decide whether there is a keyword DO and a variable I,
>> or a variable DOI. A "naked comma" is a comma not enclosed inside
>> a quoted character or string, or inside a possibly nested parenthesis.
> 
> My guess as to how this stuff was parsed:
> 
> Deal with the first columns as appropriate.  For the rest: Remove any
> white space.  Use a backtracking parser that tries to match a rule at
> a time; for the DO statement, simply compare the start with "DO".  If
> a rule does not match, look at the next rule.
> 
> The result is messy, especially when you want to extend the language.

A backtracking parser sounds like way overkill.

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.

The first thing a Fortran compiler does is scan ahead loading card
statements into a card buffer array from the (possibly nested INCLUDE)
source files until it sees a non-continue card, which it ungets.

Then it checks the format of the cards is ok and extracts things like
a label from columns 2:5.

Compacting out comments and white space is unnecessary -
the hand written lexer knows to skip over them.
There is a method called "Sale's Algorithm" which was published
in CACM in the 1960's which describes how to lex up to Fortran 77.

The parser knows which statement it is working on so can tell the
lexer what options it should handle at the point.
There could be a post pass over the AST to patch up ambiguous
constructs that require semantic context to fix.

After that it is pretty standard AST processing.
The only semantic difference I can think of immediately is
Fortran's parenthesis rule that forces an order of evaluation
and would interact with optimizations like common subexpressions.

>> People learned a lot of what not to do in language design
>>from old FORTRAN.
> 
> And probably also what to do.  Backus was on the Algol-60 committee,
> and the B in BNF stands for his name.  I would not be surprised if the
> structure of the parser in the FORTRAN compiler gave him ideas for
> BNF.
> 
> - anton
Technical Details
Message-ID: <9ysAS.182538$QPx3.16043@fx17.iad>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer04.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx17.iad.POSTED!not-for-mail
References: <1791742457-5857@newsgrouper.org> <11agm4p$2tfut$1@dont-email.me> <11ahs8q$38ir0$4@dont-email.me> <11aig3c$3hdcn$1@dont-email.me> <11aiqc0$3kr94$3@dont-email.me> <179190779286.25645.14465927900754526737@media.vsta.org> <179190779286.25645.14465927900754526737@media.vsta.org> <vandys@vsta.org> <jwvjynl2cg0.fsf-monnier+comp.arch@gnu.org> <808vclt9i2mso89n1itvnvos5j88g1mopl@4ax.com> <6acfc2b2.1547984@news.eternal-september.org> <HZQzS.6$TYg.3@fx21.iad> <2026Oct15.081750@mips.complang.tuwien.ac.at>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer04.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx17.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: Comment delimiters
Newsgroups: comp.arch
References: <1791742457-5857@newsgrouper.org> <11agm4p$2tfut$1@dont-email.me>
 <11ahs8q$38ir0$4@dont-email.me> <11aig3c$3hdcn$1@dont-email.me>
 <11aiqc0$3kr94$3@dont-email.me>
 <179190779286.25645.14465927900754526737@media.vsta.org>
 <179190779286.25645.14465927900754526737@media.vsta.org> <vandys@vsta.org>
 <jwvjynl2cg0.fsf-monnier+comp.arch@gnu.org>
 <808vclt9i2mso89n1itvnvos5j88g1mopl@4ax.com>
 <6acfc2b2.1547984@news.eternal-september.org> <HZQzS.6$TYg.3@fx21.iad>
 <2026Oct15.081750@mips.complang.tuwien.ac.at>
Content-Language: en-CA
From: EricP <ThatWouldBeTelling@thevillage.com>
In-Reply-To: <2026Oct15.081750@mips.complang.tuwien.ac.at>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 101
Message-ID: <9ysAS.182538$QPx3.16043@fx17.iad>
X-Complaints-To: abuse@UsenetServer.com
NNTP-Posting-Date: Fri, 16 Oct 2026 16:47:01 UTC
Date: Fri, 16 Oct 2026 12:46:57 -0400
X-Received-Bytes: 5788