I wrote a simple C-like grammar in Bison, and I have a weird problem.
In the following rule:
declaration: "identifier" length init_values
{symbolTable.add($3,$4,$5);}
I want to get the int values of length
and init_values
, which are nonterminals, to store them in the symbol table. identifier
is a token, and its literal value is stored correctly. However, I'm getting some integer values like 66236273 for the other symbols.
The nonterminal rules are:
length: "number" {};
init_values: "number" {};
I tried using tokens directly instead of nonterminals, but the parser couldn't differentiate between number
and length
and so on. It just parsed all integers as number
, which made it crash.
Does anyone know how to get the actual values of these? i.e. the number values, which I was able to find in the last rules, but somehow they get lost when the parser goes a step back to the first rule.