Reduce/Reduce Conflict ?

"Ashwin" <ashwin21_99@hotmail.com>
21 Feb 2003 01:22:51 -0500

          From comp.compilers

Related articles
Reduce/Reduce Conflict ? ashwin21_99@hotmail.com (Ashwin) (2003-02-21)
Re: Reduce/Reduce Conflict ? matt@NOSPAMbeastrider.com (Matt) (2003-02-24)
Re: Reduce/Reduce Conflict ? snicol@apk.net (Scott Nicol) (2003-02-24)
Re: Reduce/Reduce Conflict ? slk14@earthlink.net (SLK Parsers) (2003-03-02)
| List of all articles for this month |
From: "Ashwin" <ashwin21_99@hotmail.com>
Newsgroups: comp.compilers
Date: 21 Feb 2003 01:22:51 -0500
Organization: Posted via Supernews, http://www.supernews.com
Keywords: parse, question
Posted-Date: 21 Feb 2003 01:22:50 EST

Hi,


I have grammar defined for C#. Tools I am using are Lex and Bison. And
the problem is with a reduce/reduce conflict which leads to a major
parse error. The problem is arising due to the conflicting grammar in
case of ParenthesizedExpression, and Cast Expression. When Bison
encounters a Close Parenthesis which appears in both cases. It is not
able to decide whether to reduce using Expression which points into
Parenthesized Expression. Or Type which point into CastExpression. Say
for example my input to be parsed is as follows.


              1) a = (foo) b
              2) a = (a + (foo))


Gives me a parse error in the second case because, the default path it
takes is Type. So If the statement ends after close paren as in the second
case, it gives me an error unexpected close paren, since it is expecting an
identifier to follow.


  I dont know how to solve this. If someone can help me. I have grammar
defined at the end if it can help.


Thank you in advance.
Ashwin.


The Grammar is as follows:


PrimaryExpression:
        ParenthesizedExpression
        | CastExpression
        ;


ParenthesizedExpression:
        OPENPAREN Expression CLOSEPAREN
        ;


CastExpression:
        OPENPAREN Type CLOSEPAREN IDENTIFIER
        ;


Expression:
        IDENTIFIER
        ;


Type:
        IDENTIFIER
        ;


Post a followup to this message

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