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 04:18:18 -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 04:18:18 -0800 (PST)
Organization: Compilers Central
References: 21-12-003
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="3690"; mail-complaints-to="abuse@iecc.com"
Keywords: parse, design, comment
Posted-Date: 27 Dec 2021 21:28:59 EST
In-Reply-To: 21-12-003

On Sunday, December 26, 2021 at 7:19:08 PM UTC-8, Roger L Costello wrote:


> I am reading the (excellent) book "flex & bison" by John Levine. Chapter 7
> talks about conflicts in grammars: shift/reduce and reduce/reduce conflicts.


> At the end of the chapter are a few exercises/questions. I'd like to check
> with you on whether my answers to the questions are accurate and complete.


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.


Otherwise, the usual regular expression has an ambiguity which is often cured
by taking the longest of the possible matches. It seems to me that more often
I want the shorter match, though.


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


Post a followup to this message

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