[antlr-interest] Re: Is it because of buggy antlr?

lgcraymer <lgc at mail1.jpl.nasa.gov> lgc at mail1.jpl.nasa.gov
Mon Jan 20 21:34:08 PST 2003


Sanjiv--

Actually, there is a bug in your grammar.  Change expr to

expr
   :
   e1 ( ( PLUS | MINUS ) e1 )*
   ;


and it might work.  "|" separates alternative blocks so that your 
version gives

expr
   :
   e1
   (      PLUS
   |      MINUS e1
   )+
   ;
so that P1 - p2 would work, but not P1 + p2.

--Loring

--- In antlr-interest at yahoogroups.com, "rmsanjivp <rmsanjivp at y...>" 
<rmsanjivp at y...> wrote:
> Consider the following rules:
> 
> expr
>  : e1 (PLUS | MINUS e1)*
>  ;
> 
> e1
>  : e0 ( POWER e1)? // to make POWER tree as right associative
>  ;
> 
> e0: ID;
> 
> 
> For the following parser the generated code in C++ when compiled and 
> run gives unexpected token for input "P1 + p2"
> 
> If the right associative part is changed to
> 
> e1
>  : e0 ( POWER e0)*
>  ;
> 
> then all works fine except that the operator POWER is treated as 
> right associative.
> 
> Any idea how to make an operator left associative?
> 
> Thanks,
> Sanjiv


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list