help-bison
[Top][All Lists]
Advanced

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

Re: Tell a rule to shift instead of reduce?


From: Adam Smalin
Subject: Re: Tell a rule to shift instead of reduce?
Date: Tue, 17 Dec 2013 20:00:00 -0500

I tried this

| rval '=' rval ',' rval %prec '.'

I still get the conflict

Conflict between rule 345 and token ',' resolved as reduce (',' < '=').

I tried dprec 1 and 2 on the two lines. Then I changed 1 into 3 to flop
which one is higher. No dice

> A second, more straightforward, idea is to shuffle around your grammar to
focus on the idea of an atomic "rval group":

I tried. It didn't work as I expected because if I were to write a,b = 1+2,
f. The 1+2 is an rval and causes conflicts. If I make the left of '=' vars
then it works but means I can't do "namespace.class.var, namespace2.var2 =
my_tuple"

Why isn't dprec and prec working???!


On Tue, Dec 17, 2013 at 2:51 PM, Chris verBurg <address@hidden>wrote:

> Hey Adam,
>
> I have a couple ideas.  First, you might try updating the precedence of
> ',' for just that one rule:
>
> | rvalLoop ',' rval %prec '='
>
> (though you might need to define a precedence-level higher than both ','
> and '=' for that to work right).
>
> A second, more straightforward, idea is to shuffle around your grammar to
> focus on the idea of an atomic "rval group":
>
> body:
>   recursive-expr // without rval=rval
>   | rvalGroup '=' rvalGroup ;
>
> rvalGroup:
>   rval
>   | rvalGroup ',' rval ;
>
> -Chris
>
>
>
> On Tue, Dec 17, 2013 at 12:25 AM, Adam Smalin <address@hidden>wrote:
>
>> I still need help with this. I rewrote it maybe this will be more clear?
>>
>> I want to allow this
>>
>> var = var
>> var, var = var
>> var = var, var
>>
>> My rules are similar to the below
>>
>> body:
>>     recursive-expr //rval = rval is here
>>   | rval '=' rval ',' rvalLoop
>>   | rval ',' rvalLoop '=' rval
>>
>> rvalLoop:
>>     rval
>>   | rvalLoop ',' rval
>>
>> The problem is '=' is higher precedence than ','. When I write "a=b,c" it
>> reduce when it sees ',' making a=b an rval and rval ',' rval is invalid so
>> my parser fails and "rval '=' rval ',' rvalLoop" is never used. The
>> conflict file shows
>>
>> rval '=' rval . ',' rvalLoop
>> Conflict between rule 352 and token ',' resolved as reduce (',' < '=').
>>
>> How do I say for this rule shift instead of reduce? I don't want to make
>> ',' higher than '=' because it would be wrong when looking into functions.
>> For example func(a,b=2,c) should have b=2 as an expression and not (a,b) =
>> (2,c).
>> _______________________________________________
>> address@hidden https://lists.gnu.org/mailman/listinfo/help-bison
>>
>
>


reply via email to

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