🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #168

Re: Comment delimiters

#168
From: EricP
Date: Sat, 17 Oct 2026 14:06
98 lines
5339 bytes
On 2026-Oct-16 13:56, Anton Ertl wrote:
> EricP <ThatWouldBeTelling@thevillage.com> writes:
>> On 2026-Oct-15 02:17, Anton Ertl wrote:
>>> 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.
> 
> A backtracking parser is relatively easy and the memory needs for
> parsing just a single statement are small, too.  For an example of how
> short a parser generator for a backtracking parser framework can be,
> look at the second example in
> <https://bernd-paysan.de/screenful.html>.
> 
>> 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 reason why I think of a backtracking parser is that it seems the
> easiest way to be able to handle both
> 
> DO101I=1.100
> 
> and
> 
> DO101I=1,100
> 
> (examples given on
> <https://en.wikipedia.org/wiki/Fortran#Fixed_layout_and_punched_cards>)

F77 already had structured IF THEN ELSE IF THEN ELSE END IF.
DEC F77 enhanced DO drops the loop end statement number and
used END DO instead, and added DO WHILE END DO.
(This one change alone de-rats-nests the source tremendously by
eliminating all the loop label numbers so that label numbers
were only used for unstructured GOTO and FORMAT statements
which are infrequent.)

DEC F77 had a number of enhancements which made the language
more friendly, like tab in column 1 skips to the start of a
statement or ! anywhere is a comment to end of line.
These were adopted by many other F77 compiler vendors
presumably because they wanted to get their customers.
Later many became ANSI standard.

>> 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.
> 
> Interesting, but did the FORTRAN team come up with that?  According to
> <https://fortran-lang.discourse.group/t/has-anyone-played-with-sales-fortran-classification-algorithm-lately/7802>
> the algorithm was published in 1971.
> 
>> 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.
> 
> Searching around, I found little about "order of evaluation" when it
> comes to parenthesis in FORTRAN, although I remember hearing or
> reading about the significance of parentheses in FORTRAN several
> times.  But does it have any relevance beyond determining that a+(b+c)
> is evalutated as
> 
> t=b+c
> r=a+t
> 
> rather than
> 
> t=a+b
> r=t+c
> 
> If not, that rule just disallows reassociation, but reassociation is
> not something I have seen in common subexpression elimination (or,
> more generally, partial redundancy elimination) algorithms anyway.

Parenthesis can be used to force an order of execution.
The parenthesis ordering rule is also data type dependent.
It applies to integer, logical (also integer) and real but not strings.

#1  a + b + c    Unordered
#2  (a+b) + c    a+b before +c
#3  a + (b+c)    b+c before +a

This would interact with common subexpression elimination.
Above would not be able to optimize all 3 expressions to 1.
It can replace #1 with #2 or #3, but not both.

I'm not sure but I think parenthesis also could block optimizations
like a*b+a*c => a*(b+c) but (a*b)+(a*c) might not be optimized.
Technical Details
Message-ID: <zhLAS.37514$1l6.27878@fx42.iad>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx42.iad.POSTED!not-for-mail
References: <1791742457-5857@newsgrouper.org> <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> <9ysAS.182538$QPx3.16043@fx17.iad> <2026Oct16.195605@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!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx42.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
From: EricP <ThatWouldBeTelling@thevillage.com>
Subject: Re: Comment delimiters
Newsgroups: comp.arch
References: <1791742457-5857@newsgrouper.org> <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>
 <9ysAS.182538$QPx3.16043@fx17.iad>
 <2026Oct16.195605@mips.complang.tuwien.ac.at>
Content-Language: en-CA
In-Reply-To: <2026Oct16.195605@mips.complang.tuwien.ac.at>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 98
Message-ID: <zhLAS.37514$1l6.27878@fx42.iad>
X-Complaints-To: abuse@UsenetServer.com
NNTP-Posting-Date: Sat, 17 Oct 2026 14:06:23 UTC
Date: Sat, 17 Oct 2026 10:06:21 -0400
X-Received-Bytes: 5107