Reputation: 4847
I am trying to write a parser for a simple language that recognizes integer and float expressions using ocamlyacc. However I want to introduce the possiblity of having variables. So i defined the token VAR in my lexer.mll file which allows it to be any alphanumneric string starting with a capital letter.
expr:
| INT { $1 }
| VAR { /*Some action */}
| expr PLUS expr { $1 + $3 }
| expr MINUS expr { $1 - $3 }
/* and similar rules below for real expressions differently */
Now i have a similar definition for real numbers. However when i run this file, I get 2 reduce/reduce conflict because if i just enter a random string(identified as token VAR). The parser would not know if its a real or an integer type of variable as the keyword VAR is present in defining both int and real expressions in my grammar.
Var + 12 /*means that Var has to be an integer variable*/
Var /*Is a valid expression according to my grammar but can be of any type*/
How do I eliminate this reduce/reduce conflict without losing the generality of variable declaration and mainting the 2 data types available to me.
Upvotes: 0
Views: 202