Hi, > Le 21 sept. 2022 à 23:31, Lukas Arsalan <cptarse-l...@yahoo.com> a écrit : > > exp: > "-" "num" { $$ = -*new Float($2); std::cout << "NUMinv" << $$ > << std::endl; } > | "num" { $$ = new Float($1); std::cout << "num" << $$ << > std::endl; } > | "-" exp { $$ = -*$2; std::cout << "inv" << $$ << std::endl; }
This snippet is clearly ambiguous, since it allows two different parses of -1, which -Wcex nicely showed. If I were you, I would handle this in the scanner. IOW, the scanner should be extended to support signed literals, and process that initial `-`. So the grammar would no longer include `exp: "num"`. Your actions look quite badly typed. And `std::endl` should seldom be used, `'\n'` is enough. Cheers!