Re: Why are ambiguous grammars usually a bad idea? Why are languages usually defined and implemented with ambiguous grammars?

gah4 <gah4@u.washington.edu>
Mon, 27 Dec 2021 19:45:06 -0800 (PST)

          From comp.compilers

Related articles
| List of all articles for this month |
From: gah4 <gah4@u.washington.edu>
Newsgroups: comp.compilers
Date: Mon, 27 Dec 2021 19:45:06 -0800 (PST)
Organization: Compilers Central
References: 21-12-003 21-12-008
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="38746"; mail-complaints-to="abuse@iecc.com"
Keywords: parse, design, comment
Posted-Date: 28 Dec 2021 12:39:42 EST
In-Reply-To: 21-12-008

(snip about conflicts in grammars)
(then I wrote)
> As far as I know, the main cause of ambiguous grammar in programming languages
> is the nested if-then-optional-else structure. If you require else, then it isn't ambiguous,
> but people like the optional else. That usually comes out as a shift-reduce conflict,
> and parser generators know how to handle that.


(snip)


> But you already have the reply from John Levine ...
> [See previous message, where we fixed that with "fi" in 1968. -John]


I first learned if-then-else from PL/I, where it was designed in
about 1963. I now suspect that people get used to the one they
learned first, and find it more obvious.


There is also some language, and I forget now which, with an ELIF
construct, such that you can make a nested if-then-else sequence
without the increase of nesting level, and so need only one ENDIF.


IF e THEN s; ELIF e THEN s; ELIF e THEN s; ENDIF;


(No comment on my preference for ENDIF vs. FI.)


[That would also be Algol 68, using "fi"
It didn't need the semicolons because they are separators,
not terminators as in PL/I and C.
If you've written scripts in the Bourne shell or its descendants
such as bash and zsh, it deliberately looks a lot like Algol 68.
A request from your moderator: if anyone is planning another round
in the semicolon terminator vs. separator war, please don't.
-John]


Post a followup to this message

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