[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reduce conflict on TKAs




Well, I have not looked very carefully at your grammar,  but one trick you
can use is change the grammar to make it a little more general,  and then
use a second pass over the tree to weed out any bad trees,  or to decide
which alternative it really should have been.

for example,

instead of

 prod :  A column_reference k_A B |
         A qualified_name k_A C 

you could allow something a bit more general like:

 prod :  A something_else k_A B |
         A something_else k_A c

where something_else is defined to include at least column_references 
and qualified names.

Then, after you build the tree, you go back and check that all of the
something_else productions really led to a column_reference or a
qualified_name,  and you give an error message if they did not.

Cheers, Laurie


On Wed, 17 Feb 1999, Chad Loder wrote:

> Etienne,
> 
> Thanks. I found that message and I understand the problem. Is there any way to
> locally increase the lookahead (either in the grammar or effectively, using
> Java code)? What should my strategy be in dealing with this problem? I
> don't think I can eliminate the ambiguity from the grammar.
> 
> Any help is appreciated. I am really feeling my lack of grounding in this
> field.
> 
> P.S. - I have used hypermail to transform the SableCC mailing list archive
> into HTML format for easier browsing. It can be found at
> 	http://www.ccs.neu.edu/home/cloder/sable-archive/
> 
> I am afraid that it will be forever out of date, because I don't have enough
> time to update the archive.
> 
> 	c
> 
> On Tue, 16 Feb 1999, Etienne Gagnon wrote:
> 
> > Hi Chad.
> > 
> > You are right about your interpretation. 
> > 
> > Instead of re-explaining the error message, I will direct you to the
> > mailing list archive. 
> > 
> > Look for the message:
> > 
> > Subject: Re: BIG BUG
> > Date: Tue, 29 Dec 1998 12:27:43 -0500
> > From: Etienne Gagnon <egagnon@sprynet.com>
> > 
> > It contains an explanation of the SableCC's conflict error messages.
> > 
> > If you want to learn about LALR(1), you have to buy a book about
> > compilers/parsers. It can't be explained in a few lines.
> > 
> > Hint: A reduce/reduce conflict means that in a particular situation, the
> > parse stack contains a valid sequence for 2 reductions, given the
> > lookahead.
> > 
> > So, in your case, the parser is not able to determine if it should
> > reduce the identifier to a column_reference or to a qualified_name, when
> > it is followed by a k_a.
> > 
> > Here's an example that would exhibit this conflict:
> > prod = A column_reference k_a B | 
> >        A qualified_name k_a C;
> > 
> > So, by having a single token of lookahead, the parser cannot determine
> > which alternative is being parsed, and therefore do not know if your
> > identifier is a column_reference or a qualified name.
> > 
> > Etienne
> > 
> > 
> > -- 
> > 
> > ----------------------------------------------------------------------
> > Etienne Gagnon, M.Sc.                   e-mail: gagnon@sable.mcgill.ca
> > Author of SableCC:                 http://www.sable.mcgill.ca/sablecc/
> > ----------------------------------------------------------------------
> > 
> 
> ----------------------------------------------------
> | Chad Loder - Somerville, MA, USA                 |
> | EMail:     cloder@acm.org                        |
> | Home Page: http://www.ccs.neu.edu/home/cloder    |
> ----------------------------------------------------
> 
> 
>