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: Sun, 22 Dec 2013 15:17:30 -0500

> Please, post a self contained and minimal example.

Ok. I didn't test it by parsing actual code. I only looked at the conflict


%left ','
%right '='
%left '.'

%%

program:
    newline_many global_loop newline_many
global_loop:
      global_expr
    | global_loop global_expr
global_expr:
    VAR '(' ')' code_block

code_block: '{' newline_many body newline_one_or_more '}'

newline_many: | newline_many '\n'
newline_one_or_more: '\n' | newline_one_or_more '\n'
body:
      body_expr
    | body newline_one_or_more body_expr
    | body_expr '=' body_expr ',' body_expr %prec '.'
    | body_expr ',' body_expr '=' body_expr
    | body_expr ',' body_expr '=' body_expr ',' body_expr
body_expr:
      body_expr '=' body_expr
    | body_expr '.' VAR
    | VAR

%%



state 27

   12 body: body_expr '=' body_expr . ',' body_expr
   15 body_expr: body_expr . '=' body_expr
   15          | body_expr '=' body_expr .  [',', '\n']
   16          | body_expr . '.' VAR

    '='  shift, and go to state 29
    '.'  shift, and go to state 22

    $default  reduce using rule 15 (body_expr)

    Conflict between rule 15 and token ',' resolved as reduce (',' < '=').
    Conflict between rule 15 and token '=' resolved as shift (%right '=').
    Conflict between rule 15 and token '.' resolved as shift ('=' < '.').

As you can see it says "Conflict between rule 15 and token ',' resolved as
reduce (',' < '=').". As you can see my rule is written as "| body_expr '='
body_expr ',' body_expr %prec '.'"




On Sun, Dec 22, 2013 at 2:35 PM, Akim Demaille <address@hidden> wrote:

>
> Le 22 déc. 2013 à 18:40, Adam Smalin <address@hidden> a écrit :
>
> > I forgot to CC this to the group a few days ago.
> >
> > >The token precedences apply to the tokens immediately before and after
> the parsing ‘.’ (as in the .output file) in the shift/reduce conflicting
> rules. The grammar must be written so that the tokens appear in such a
> position.
> >
> > | rval '=' rval %prec '.' ',' rval
>
> That's bad style, move your "%prec '.'" at the end of the rule.
> It means the same, but it's clearer.  And therefore notice that
> now, this rule has the precedence of '.', not that of '='.
>
> > conflict file:
> >
> >
> > rval '=' rval . ',' rval
> > Conflict between rule 343 and token ',' resolved as reduce (',' < '=').
>
> So it's bizarre that in that conditions bison still refers to '='.
>
> > Shouldn't it have worked? I tried putting %prec at the end of the line
> and after the ',' as well and it failed. I tried multiple places at once
> and got an error saying only one %prec per line.
>
> Please, post a self contained and minimal example.


reply via email to

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