help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to solve this reduce/reduce conflict?


From: Akim Demaille
Subject: Re: how to solve this reduce/reduce conflict?
Date: Thu, 22 Sep 2022 07:08:23 +0200

Hi,

> Le 21 sept. 2022 à 23:31, Lukas Arsalan <cptarse-luke@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!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]