[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!
- how to solve this reduce/reduce conflict?, Lukas Arsalan, 2022/09/21
- Re: how to solve this reduce/reduce conflict?,
Akim Demaille <=
- Re: how to solve this reduce/reduce conflict?, Lukas Arsalan, 2022/09/22
- Re: how to solve this reduce/reduce conflict?, Hans Åberg, 2022/09/22
- Re: how to solve this reduce/reduce conflict?, Lukas Arsalan, 2022/09/22
- Re: how to solve this reduce/reduce conflict?, Hans Åberg, 2022/09/22
- Re: how to solve this reduce/reduce conflict?, Lukas Arsalan, 2022/09/22
- Re: how to solve this reduce/reduce conflict?, Hans Åberg, 2022/09/22
- Re: how to solve this reduce/reduce conflict?, Derek Clegg, 2022/09/22
- Re: how to solve this reduce/reduce conflict?, Evan Lavelle, 2022/09/23
- Re: how to solve this reduce/reduce conflict?, AW, 2022/09/23
- Re: how to solve this reduce/reduce conflict?, lostbits, 2022/09/23