# ITE bison grammar problem

## "pmatos" <pocm@sat.inesc-id.pt>4 Jun 2005 15:12:02 -0400

From comp.compilers

Related articles
ITE bison grammar problem pocm@sat.inesc-id.pt (pmatos) (2005-06-04)
Re: ITE bison grammar problem pocm@sat.inesc-id.pt (pmatos) (2005-06-04)
Re: ITE bison grammar problem cbarron413@adelphia.net (Carl Barron) (2005-06-05)
Re: ITE bison grammar problem bluemalov_NOSPAM_@hotmail.com (Andrew Wilson) (2005-06-05)
| List of all articles for this month |

 From: "pmatos" Newsgroups: comp.compilers Date: 4 Jun 2005 15:12:02 -0400 Organization: http://groups.google.com Keywords: yacc, question Posted-Date: 04 Jun 2005 15:12:02 EDT

Hi all,

I have right now a big grammar for a language I conveived to simplify
another problem but that's not important right now. The fact is that
I'm left with a reduce/reduce conflict which is rather serious and I
can't solve it. I've managed to create a simple grammars that shows
the conflict:

%left '&' '+'

%token id

%start F
%%

F: "ite" '(' F ',' F ',' F ')'
| E '&' E
| M
| id
;

M: E "==" E;

E: "ite" '(' E ',' E ',' E ')'
| E '+' E
| id
;

%%

(F is formula which represents a boolean value and E is an expression
which represents a numerical value, id is an identifier that can
represent a numerical value or a boolean value but that depends on its
definition, right now, it's a sequecene of chars)

The problem is quite simple to understand... and it happens in the
middle of "ite" (if-then-else), in the expression "ite" the value of
the "ite" is another expression and in the formula "ite" the value of
the "ite" is a boolean value, and because of that if the
formula/expression is a single identifier, which can both be, since in
BOTH there comes a COMMA right away... there's no way to know if we
reduce a formula or expression.

Any ideas on how to solve this issue?

Cheers,

Paulo Matos
[My advice would be to treat them the same syntactically and sort them out
in the semantics. This lets you produce better error messages like "boolean
variable XYZ used for arithmetic" rather than "syntax error". -John]

Post a followup to this message