help!! transforming to LALR(1)

Joao Abreu <>
24 Mar 2005 21:20:26 -0500

          From comp.compilers

Related articles
help!! transforming to LALR(1) (Joao Abreu) (2005-03-24)
| List of all articles for this month |

From: Joao Abreu <>
Newsgroups: comp.compilers
Date: 24 Mar 2005 21:20:26 -0500
Organization: Compilers Central
Keywords: LALR, question, comment
Posted-Date: 24 Mar 2005 21:20:26 EST

    Hi everyone,

In good time I found this group. I'm trying to build a LALR(1) grammar
to use with SableCC, but i'm having reduce-reduce problems which i'm
not managing to resolve. I have little experience building grammars
and i haven't found much usefull help :-(

The reduce-reduce giving me the more problems right now is here:

atomic =
        {boolean} boolean_literal |
        {predicate} predicate |
        {equality} [left]:basic eq [right]:basic |
        {paren} l_parenthese formula r_parenthese;

predicate =
        identifier l_parenthese term_list? r_parenthese;

basic =
        {integer} decimal_integer_literal |
        {variable} identifier |
        {call} call |
        {paren} l_parenthese term r_parenthese;

call = identifier l_parenthese term_list? r_parenthese;



It seems the problem is in the fact that "predicate" and "call" have
the same structure. When i replace the parentises in "predicate" with
brackets the error is gone. The message that is outputed is this:


[java] reduce/reduce conflict in state [stack: TSpecificationToken TIdentifier PSorts TAxiomsToken TIdentifier TLParenthese TRParenthese *] on TRParenthese in

  [java] [ PCall = TIdentifier TLParenthese TRParenthese * ] followed by TRParenthese (reduce),

[java] [ PPredicate = TIdentifier TLParenthese TRParenthese * ] followed by TRParenthese (reduce)


I have no ideia what to do :-\ Can any one help?

Also can anyone help me find practical instructions for building a
LALR(1) (a Grammars for Dummies would be ok :P )?

All help is welcome,

[If the two rules match the same thing and can occur in the same place,
how is the compiler supposed to tell the difference? My suggestion would
be to combine them into one rule and tell the difference semantically.

Post a followup to this message

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