I am building a compiler for a toy Java language (Decaf) and I am having trouble with defining a bool. When I try to analyze a boolean, it always returns false, whether or not I wrote false.
Flex code:
true|false {
yylval.boolConstant = yytext;
return T_BoolConstant;
}
Input code:
bool x = true;
bool y = false;
Output:
true T_BoolConstant (value = false)
false T_BoolConstant (value = false)
I tried searching on SO but this was the closest I could get to a proper answer:
Simulating Booleans in Bison with C
Thank you!
EDIT: The output is coded in a separate c file that prints the string found in the test code, what kind of value it is (in this case it is a boolean or BooleanConstant) and then the value of the token that was saved. Sorry for any confusion.
I believe you need to convert the strings
"true"
and"false"
into the boolean constantstrue
andfalse
. Otherwise you're just storing strings.Here is a similar question with a different approach.