help-bison
[Top][All Lists]
Advanced

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

Re: Using %prec to resolve shift-reduce


From: Hans Åberg
Subject: Re: Using %prec to resolve shift-reduce
Date: Wed, 30 Nov 2016 22:53:57 +0100

> On 30 Nov 2016, at 22:40, Simon Richter <address@hidden> wrote:
> 
>>> %token IF "if"
>>> %token ELSE "else"
> 
>> This can be resolved by adding
>>  %nonassoc "then"
>>  %nonassoc "else"
> 
> Yes, that is what I'm doing, except that I need to give a precedence to
> the closing parenthesis because there is no explicit "then" keyword.
> 
> This is why I'd like to use %prec here, in order to avoid inadvertently
> introducing a precedence in an unrelated place and hiding errors.

The Bison precedence system looks at the output state and compares the token 
before the parsing dot ".". So that is probably why you still get an 
shift/reduce conflict with
>   if_statement:
>        "if" /* expr omitted */ statement                       %prec LOWER |
>        "if" /* expr omitted */ statement "else" statement      %prec HIGHER;
as the ";" is not part of it.

The workaround is transforming the grammar. The Bison manual section 5.4 
Context-Dependent Precedence does not seem to help here.





reply via email to

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