I faced this problen when I am trying to run .y file
Phase2.y:119.10-26: warning: type clash on default action: <symp> != <>
line 119 in .y file we have
`
factor : LPAREN exp RPAREN
| INT_LITERAL {
strcpy($$.type ,"int");
strcpy($$.name,"");
}
`
I saw simple explanation when I am trying to found something to help but not clear for me
any help? thank you
......................................
That rule contains two productions. The first production does not have a semantic action, so the default action is used. The default action is { $$ = $1; }
Bison tries to verify that the default action is correctly typed. In this case, $$
is factor
, which you have probably declared to be %type <symp> factor
. $1
is LPAREN
, which you have presumably declared to be an untyped token (that is, a token with no semantic value). Both of those declarations are correct, but that means that $$ = $1;
is nonsense; you can't assign $$
from a non-value.
You probably meant to use the expr
as the value of the first production. It's $2
, since expr
is the second symbol on the right-hand side of the production. (You can also write it as $expr
, which might be more clear.)
So the rule should read:
factor : LPAREN exp RPAREN { $$ = $2; }
| INT_LITERAL {
strcpy($$.type ,"int");
strcpy($$.name,"");
}
Except that the semantic action for the second production is ignoring the value of the INT_LITERAL
token, which seems unlikely to be correct.