|Question on %nonassoc-directive in LALR(1) parser generators firstname.lastname@example.org (2008-09-26)|
|Re: Question on %nonassoc-directive in LALR(1) parser generators email@example.com (firstname.lastname@example.org) (2008-09-27)|
|Re: Question on %nonassoc-directive in LALR(1) parser generators cfc@shell01.TheWorld.com (Chris F Clark) (2008-09-27)|
|Re: Question on %nonassoc-directive in LALR(1) parser generators email@example.com (Chris Dollin) (2008-09-29)|
|From:||Chris F Clark <cfc@shell01.TheWorld.com>|
|Date:||Sat, 27 Sep 2008 14:05:19 -0400|
|Organization:||The World Public Access UNIX, Brookline, MA|
|Posted-Date:||27 Sep 2008 16:41:40 EDT|
> Even his own parser generator occs (implemented in this book) and the
> parser generator Anagram (http://www.parsifalsoft.com/) use this
> (faulty?) approach: They always accept inputs like "x=x=x" when '=' is
> declared non-associative, and I'm not sure now if this is a mistake in
> Holubs book or a misunderstanding by me. The way yacc implements this
> table is, in my opinion
> Associativity of conflict symbol | Perform
> Left-associative | reduce
> Right-associative | shift
> Non-associative | [remove shift from action table]
> Am I right now or who made the mistake here?
The intent of non-assoc is to make "x=x=x" an error and the way to
implement that is to put an error action in the SR-table at the
location you are indicating. So, I believe you are correct here.
Putting a reduce there makes the grammar left associative. (If I can
keep my associativities straight.) Putting a shift there makes the
grammar right associative.
In some cases, (not this instance but other SR-coflicts) doing both,
shifting and reducing to create two paths in the parse forest, makes
the grammar GLR. Also, you can use additional lookahead in the GLR
instances to sometimes resolve the conflict, which can make the tables
As a rhetorical question, I'll ask why you can't use lookahead in the
cse you describe to use the conflict?
The answer being, that because the instance you describe is a
recursive application of a binary operator. In recursive applications
of binary operatos the lookahead doesn't provide additional
information. You can reduce the same sentences picking either left or
right. You simply build different trees for them.
In this case, associativity operators give approximately the right
level of control, although you might want to apply them more locally
than globally. In other cases, it is better to use lookahead (or GLR)
to guide the choice because the lookahead can tell you which strings
you are not allowing as sentences. In many of those case, selecting
shift allows the larger set of strings as belonging to the grammar.
However, if I recall correctly, it is possible to construct cases,
where the reduce option actually selects that grammar that has more
strings in it.
One of the subtly(*) good features of Yacc++ is how it handles these
conflicts. (Subtly meaning here, a good feature that goes (and should
go) essentially unnoticed because it simply does the right thing
without drawing attention to itself.) We actually spent a fair amount
of time looking at different types of conflicts and determining what
the parser generator should do with them. ELR has more kinds of
conflicts than LR does, especially if one is doing LR(k) parsing.
As to the Holub book, despite its errors, I think it is a good book.
To me the errors are simply a reflection of how difficult it is to do
parsing right. It is a much more subtle problem than most people
Hope this helps,
Chris Clark Internet: firstname.lastname@example.org
Compiler Resources, Inc. or: email@example.com
23 Bailey Rd Web Site: http://world.std.com/~compres
Berlin, MA 01503 voice: (508) 435-5016
USA fax: (978) 838-0263 (24 hours)
Return to the
Search the comp.compilers archives again.