> On 1 May 2016, at 13:14, Matthias Simon <m...@5nord.de> wrote:

> I have a grammar with some conflicts between the return statement and the 
> declaration (due to missing semicolons). I thought I could resolve this issue 
> by giving the primary-production in expr a context-dependent precedence, but 
> it had no effect on the conflicts. I still have a conflict for the FOO and 
> the BAR token. Can somebody explain to me why?

Try the grammar below. In short, only shift-reduce conflicts can be resolved, 
and only when they are close enough in the grammar - two tokens appearing in 
the same state around the parsing dot in the .output file. If that is not the 
case, the grammar must be rewritten, or using GLR.


%token ID
%token FOO
%token BAR
%token RETURN

%left '+'
%left '*'

%%

stmts:
  stmt
| stmts stmt
;

stmt:
  RETURN
| expr RETURN
;

expr:
  primary
| expr '+' expr
| expr '*' expr
;

primary:
   ID
 | FOO
 | BAR
 ;

%%




_______________________________________________
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to