help-bison
[Top][All Lists]
Advanced

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

Problems understanding %prec


From: Matthias Simon
Subject: Problems understanding %prec
Date: Sun, 01 May 2016 13:14:00 +0200
User-agent: Roundcube Webmail/0.9.5

Hi,

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?

Cheers,
Matthias

This is the grammar:

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

/* resolve RETURN-primary conflict as shift */
%nonassoc RETURN
%nonassoc ID

%left '+'
%left '*'

%%

stmts
    :       stmt
    | stmts stmt
    ;

stmt
    : RETURN
    | RETURN expr /* conflict */
    | primary     /* conflict */
    ;

primary
    : ID
    | FOO
    | BAR
    ;

expr
    : primary %prec ID /* give tokens of primary the precedence of ID */
    | expr '+' expr
    | expr '*' expr
    ;

%%




reply via email to

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