[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: I cant resolve my reduce/reduce comflicts
From: |
Christian Schoenebeck |
Subject: |
Re: I cant resolve my reduce/reduce comflicts |
Date: |
Fri, 13 Aug 2021 15:08:37 +0200 |
On Freitag, 13. August 2021 13:13:17 CEST Guenther Sohler wrote:
> Hi group,
>
> I got another issue with bison regarding resolving my conflicts.
> right now i have 50 conflicts and
> I can't appear to resolve them even though i have carefully read
> the chapter at
> https://www.oreilly.com/library/view/flex-bison/9780596805418/ch07.html
> which actually explains conflicts and the outputfile very well, i like it!
>
> I believe thes conflict arise because in my case because in my grammar
> have these rules:
>
>
> expression:
> '(' expression ')
>
> | lvalue
>
> lvalue:
> '(' lvalue ')'
Correct, that's clearly a conflict. You should get rid of one of them.
> So there are two ways to turn '(' lvalue' ')' into expression
> and i feel i need both of them.
This specific grammar part is about math formulas. Like always, there is not
the one way to handle this, but a common solution is to split that part of the
grammar at least into a symbol for "unary operations" i.e. rules which only
have one operand like:
+operand
-operand
(operand)
...
and a separate symbol (or more) for "binary operations" i.e. rules that have
two operands like:
operand1 + operand2
operand1 - operand2
operand1 * operand2
...
> the conflict can be waived in my opinion, because both codes do the same
> "nothing" .
> The Braces are jsut to define precedence in C code and still i want to
> resolve the issue.
Well, that depends on whether you are going to add actions to them. If you
don't need any actions there then you might ignore those conflicts. But if you
are going to add actions for handling math formulas then you probably want the
order in which the actions are executed to be correct, otherwise it would
yield in wrong results when evaluating expressions.
Best regards,
Christian Schoenebeck