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: Mon, 23 Dec 2013 08:38:59 -0500

Oh crap! It's looking at the token ',' and not the other rules (rule 12).
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
I want to rule 12 to trump rule 15. Rule 15 precedence should definitely
stay the same. F!

So it's impossible for me to ask bison to shift during rule 12 when
possible? This reminds me of when I first learned regular expressions and
about 'greedy' patterns. F. Alright I guess I'll do lvals as you suggested.
Darn I was hoping it is possible for me to override rules :(


On Mon, Dec 23, 2013 at 6:06 AM, Akim Demaille <address@hidden> wrote:

>
> Le 22 déc. 2013 à 21:17, Adam Smalin <address@hidden> a écrit :
>
> > > 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
> >
> > %%
>
> Honestly, I find your grammar hard to read.  Plenty of
> opportunities for ambiguities here, not just conflicts.  It
> shows a lot of redundancy, which calls for refactoring.  Have
> another look at my proposal with lvals and rvals.
>
> > 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 '.'"
>
> You are referring to rule 12, bison is referring to rule 15.
> Rule 15 has no explicit precedence token, so the last one is
> issued, '=', whose precedence is greater than that of ','.
>
> The output file includes:
>
>     0 $accept: program $end
>
>     1 program: newline_many global_loop newline_many
>
>     2 global_loop: global_expr
>     3            | global_loop global_expr
>
>     4 global_expr: "VAR" '(' ')' code_block
>
>     5 code_block: '{' newline_many body newline_one_or_more '}'
>
>     6 newline_many: %empty
>     7             | newline_many '\n'
>
>     8 newline_one_or_more: '\n'
>     9                    | newline_one_or_more '\n'
>
>    10 body: body_expr
>    11     | body newline_one_or_more body_expr
>    12     | body_expr '=' body_expr ',' body_expr
>    13     | body_expr ',' body_expr '=' body_expr
>    14     | body_expr ',' body_expr '=' body_expr ',' body_expr
>
>    15 body_expr: body_expr '=' body_expr
>    16          | body_expr '.' "VAR"
>    17          | "VAR"
>
>


reply via email to

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