help-bison
[Top][All Lists]
Advanced

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

Problem with precedence and symbolic tokens


From: T. S. Ferreira
Subject: Problem with precedence and symbolic tokens
Date: Mon, 17 Mar 2008 15:30:03 -0300

I am trying to use precedences in Bison. After several trials, a
simplified version of the relevant part of my input file is (it is
supposed to produce reversed Polish notation):

------------------------------------------------------------------------------------
%{ ... %}

%left ADD
%left MULT
%right EXP
%left UNARY

%%
...
Expr
        : Expr AddOp  Expr   %prec ADD    { printf("+"); }
        | Expr MultOp Expr   %prec MULT   { printf("*"); }
        | Expr ExpOp  Expr   %prec EXP     { printf("^"); }
        | 'a'                                               { printf("a"); }
        | '(' Expr ')'
        | '-' Expr                  %prec UNARY  { printf("~"); }
        ;
AddOp
        :  '+'
        |  '-'
        ;
MultOp
        :  '*'
        |  '/'
ExpOp
        :  '^'
        ;
%%
...
------------------------------------------------------------------------------

Unfortunately precedences do not seem to work. On the other hand, if I
replace operator nonterminals by (like Addop) their symbols ('+') and
put specs like %left '+', it works (without any %prec).

Any hints?

-- tsf




reply via email to

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