Re: ITE bison grammar problem

"pmatos" <pocm@sat.inesc-id.pt>
4 Jun 2005 23:41:58 -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" <pocm@sat.inesc-id.pt>
Newsgroups: comp.compilers
Date: 4 Jun 2005 23:41:58 -0400
Organization: http://groups.google.com
References: 05-06-028
Keywords: yacc, comment
Posted-Date: 04 Jun 2005 23:41:58 EDT

pmatos wrote:


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


Opps, I made a mistake in the post. of course the ite condition must be
a boolean value, i.e. a formula so:


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


Just found another error in the grammar. Of course, I can only apply &
to boolean values, i.e. formulas. so the corrected grammar is:
%left '&' '+'


%token id


%start F
%%


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


M: E "==" E;


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


%%


However, the real issue remains. There's a reduce/reduce conflict due
to the ite and identifier. Since I can't syntactically distinguish
identifiers, what should I do?


> [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]


How can I do that? Putting id only in F will permit id to be a
condition in ite, and will make numerical vars impossible. Putting it
only in E won't allow id to be a condition and won't allow us to have
boolean variables.


[Combine E and F, don't try to enforce types in the parser. -John]


Post a followup to this message

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