Re: Reduce/reduce conflicts on A -> e (empty) productions

Chris F Clark <>
9 Jun 2004 00:28:48 -0400

          From comp.compilers

Related articles
Reduce/reduce conflicts on A -> e (empty) productions (Chuck Batson) (2004-06-06)
Re: Reduce/reduce conflicts on A -> e (empty) productions (Chuck Batson) (2004-06-09)
Re: Reduce/reduce conflicts on A -> e (empty) productions (Chris F Clark) (2004-06-09)
Re: Reduce/reduce conflicts on A -> e (empty) productions (Hans Aberg) (2004-06-15)
| List of all articles for this month |

From: Chris F Clark <>
Newsgroups: comp.compilers
Date: 9 Jun 2004 00:28:48 -0400
Organization: The World Public Access UNIX, Brookline, MA
References: 04-06-019
Keywords: LALR, parse
Posted-Date: 09 Jun 2004 00:28:48 EDT

Chuck Batson asks an insightful question about what to do (in a parser
generator) with the following grammar's reduce-reduce conflict:

1) S -> 'Q' foo 'R'
2) foo -> empty1 empty2
3) empty1 ->
4) empty2 ->

Acording to Ullman in "Deterministic Parsing of Ambiguous Grammars"
the way to resolve this is to reduce the rule that is lexically first
in the grammar (or lexically last, as long as one is consistent). This
allows writing grammars that use reduce-reduce conflict resolution to
handle special cases. That's what most yacc-alike's do.

However, this is one place that LL parser generators do a better job
than LALR ones. The LL solution is to note that empty1 and empty2 are
nullable non-terminals, and thus foo is also nullable. Once, noting
that, if one has sees a Q then an R in the input, one knows that the
null version of foo (and the two empties) is desired.

It is possible (and not all that difficult) to make this process
rigorous and there are variants of the SLR, LALR, and related
generation algorithms that take this property into account. I call
such variants SLLR, LALLR (etc.). The hierarchy being the LLR
grammars (as opposed to the LL or LR ones). It is fairly easy to
show that the variants have the property that they parse all LL
grammars (for any fixed k) as well as their LR variants. I know I
should write this up sometime, but other things are more pressing.

Hope this helps,

Chris Clark Internet :
Compiler Resources, Inc. Web Site :
23 Bailey Rd voice : (508) 435-5016
Berlin, MA 01503 USA fax : (978) 838-0263 (24 hours)

Post a followup to this message

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