help-bison
[Top][All Lists]
Advanced

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

Re: Problems understanding %prec


From: Hans Åberg
Subject: Re: Problems understanding %prec
Date: Sun, 1 May 2016 16:02:40 +0200

> On 1 May 2016, at 13:14, Matthias Simon <address@hidden> 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
 ;

%%






reply via email to

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