> %token  ATOM
> %left   '+'
> %left   REP
>
> block:    ATOM
>        | REP block
>        | block block %prec '+'

>    5 block: REP block .
>    6      | block . block
>
>    ATOM  shift, and go to state 3
>
>    ATOM      [reduce using rule 5 (block)]

This says that yacc isn't sure how to decide,
having read REP block, between shifting ATOM
or applying the REP block reduction.

>    6 block: block . block
>    6      | block block .
>
>    ATOM  shift, and go to state 3
>
>    ATOM      [reduce using rule 6 (block)]

This says that yacc isn't sure how to decide,
having read block block, between shifting ATOM
or applying the block block reduction.

To know how to decide, yacc needs a precedence
for the thing being shifted and the rule.  You've
given precedences for each rule (REP block has
REP's precedence, and block block has +'s thanks
to the override) but not to ATOM.

Concretely, when yacc sees REP block ATOM
it isn't sure whether that's (REP block) ATOM or
REP (block ATOM).

Instead of

> %token  ATOM
> %left   '+'
> %left   REP

you probably want

%left '+'
%left REP
%nonassoc ATOM

This wasn't an issue in the first grammar because the shift/reduce
decision had to be made when looking at the '+' instead
of when looking at ATOM, and the '+' did have a precedence.

Russ

Reply via email to