Types variables in yacc interpreter?
Posted on 1997-06-19
I'm trying to code a once-through interpreter using yacc. One of the requirements is that typed variables be allowed. I've been noodling around through ORA's book on lex and yacc, and they mention using typed variables (through the %union specifier) but don't mention how to mix types in expressions and whatnot. I looked on the net for a similar problem solution, but couldn't find one. Can anyone explain type conversion in yacc (i.e., an expression can be either a float or an int) or point me to a solution?
For example, I need to declare two variables, and then assign the result of a computation to a third, as follows:
y=2; /* conversion from int to float - not a problem */
z=x/y; /* requires specification of intexp '/' floatexp */
It's the last expression that concerns me. I don't how to tell yacc to handle that without specifying every combination of type in the expression grammar, and I'm not sure how to tell yacc than an "expression" can be either an int or a float or a string.