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: Hans Åberg
Subject: Re: how to solve this reduce/reduce conflict?
Date: Thu, 22 Sep 2022 17:54:28 +0200

> On 22 Sep 2022, at 16:52, Lukas Arsalan <cptarse-luke@yahoo.com> wrote:
> 
> On 2022-09-22T07:57:45UTC Hans Åberg <haberg-1@telia.com> wrote:
>> On 22 Sep 2022, at 08:30, Lukas Arsalan <cptarse-luke@yahoo.com> wrote:
>>> [1] -1 --> "num"
>>> [2] 1-2 --> "num" "-" "num"
>>> [3] (-1^-2) --> "(" "num" "^" "num" ")"
>>> [4] 1--2 --> "num" "-" "num"
>>> [5] 1---3 --> "num" "-" "-" "num"
>>> [6] 1-2^3 --> "num" "-" "num" "^" "num"
>>> I do not think that it is possible, to do that with regular expressions...
>>> 
>> I think it is not possible, so therefore one expects -2⁴ to be parsed as 
>> -(2⁴).
>> 
> I found that `%s nosinum` for the ll-file...
> Now I can do things like this:
> "+"                     BEGIN(INITIAL); return yy::parser::make_ADD(loc);
> "("                     BEGIN(INITIAL); return yy::parser::make_BROP(loc);
> ")"                     BEGIN(nosinum); return yy::parser::make_BRCL(loc);
> {bint}                  BEGIN(nosinum); return make_INT(yytext,loc);
> {float}                 BEGIN(nosinum); return make_FLOAT(yytext,loc);
> <INITIAL>[+-]?{bint}    BEGIN(nosinum); return make_INT(yytext,loc);
> <INITIAL>[+-]?{float}   BEGIN(nosinum); return make_FLOAT(yytext,loc);
> 
> and i removed the SNUM token...
> 
> now it seems to work just right.. 🥳
> 
> it even handles the whitespaces to my liking... 😋
> 
> but i do not know what kind of formal language that is now...

Context switches are best avoided unless absolutely necessary, in my 
experience. So if one designs ones own language, it might be good to try to 
avoid them by a change in the grammar.

It might be confusing with -2^4 meaning (-2)^4, because in 1 - 2^4, it should 
be 1 - (2^4), and 1 -2^4 would be an error if two number cannot follow each 
other.





reply via email to

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