[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problem with precedence and symbolic tokens
From: |
T. S. Ferreira |
Subject: |
Re: Problem with precedence and symbolic tokens |
Date: |
Mon, 17 Mar 2008 22:27:45 -0300 |
I got it. My application has lots of operators and I was looking for
some way of simplifying my grammar but there seems to be no other way.
Thanks a lot.
-- tsf
On Mon, Mar 17, 2008 at 3:51 PM, Hans Aberg <address@hidden> wrote:
> 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
>
>
--
T. S. Ferreira