help-bison
[Top][All Lists]
Advanced

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

Re: Problem with precedence and symbolic tokens


From: Hans Aberg
Subject: Re: Problem with precedence and symbolic tokens
Date: Mon, 17 Mar 2008 19:51:21 +0100

It just looks at the tokens in the rules, so you can't throw in extra rules like you have done below. That is, AddOp must be expanded into two rules "Expr: ...".

Look in the .outout file for the S/R conflicts, and the tokens immediately before and after the parsing position dot ".".

  Hans Aberg


On 17 Mar 2008, at 19:30, T. S. Ferreira wrote:

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


_______________________________________________
address@hidden http://lists.gnu.org/mailman/listinfo/help-bison





reply via email to

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