I am making a simple calculator using flex, bison.
I have developed a grammar in which two types of expression - integer expression and actual expression.
Grammar is similar to this:
exp -> IntExp | RealExp intExp - & gt; INT | IntExp '+' intExp realExp - & gt; Real | RealExp '+' realExp | IntExp '+' realExp | RealExp '+' intExp This is not LLRR (1).
For example, consider the string 'INT' + 'real' INT 'is' +' on INT and based on this, it can tell that the string is an intExp or a real expression.
I tried to write the grammar again to solve the ambiguity but nothing came of it.
I know that I can make computation during parsing and in the form of a parse tree. Then with type inquiry, this issue can be solved but it seems that there is a little too much for such a simple problem.
Can a season be made to control such ambiguity? Or can a grammar be rewritten in a better way?
No, if it is not LALR (1) then it is not. However, you can not have a type of mismatch error in your language. Then why is there different presentations for int and real expression? Just node values have an integer, a real and a type code.
No comments:
Post a Comment