Greetings!

On Mon, 2010-08-30 at 13:01 -0700, st3 wrote:
> Hi,
> 
> I have a simple grammar - which includes a '+' or '-' operation on a
> variable (ID) or constant (INT).
> The "add" rule is obviously: "mult" (+/- "mult"). 
> 
> However, the way I need the "add" rule defined throws the
> MismatchedTokenException:
> ----------------------------------------------------------------------------
> add   :       mult    
>               ( 
>                       ('+' mult) 
>                       | 
>                       ('-' mult) 
>               )*
>       ;
> 
> while this way to define "add" rule works just fine:
> ----------------------------------------------------------------------------
> add   :       mult ( ( '+' | '-' ) mult)*     ;
> 
> 
> Can you please give some insights white Antlr 3.0 does not like the first
> way to define "add" rule?

unable to reproduce.

both ways work equally well for me when i run the org.antlr.Tool from
the command line on the Dummy.g grammar you supplied. both get a warning
about no start rule that can end in EOF, but is easily fixed by adding a
rule:

start : expr EOF ;

I am currently using ANTLR 3.1.2 (because I happen to need a python
target) perhaps there is a difference in the versions? (i doubt it)


> The reason I need it this way is to use tree rewrites.
> 
> I tried using syntactic predicates but they error out. I have consulted
> Anltr reference book as well - however nothing obvious jumped at me.
> 
> Full grammar below.
> 
> Thanks a lot for your help!

hope this helps...
   -jbb

> 
> 
> 
> grammar Dummy;
> 
> expr : add ';' ;
> 
> add   :       mult    
>               ( 
>                       ('+' mult) 
>                       | 
>                       ('-' mult) 
>               )*
>       ;
> 
> //add :       mult ( ( '+' | '-' ) mult)*     ;
> 
> mult  :       constant
>               |       variable
>               |       '(' expr ')'
>               ;
>                                               
> variable      :       ID;     
> constant      :       INT;
> 
> ID  : ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* ;
> INT : '0'..'9'+;
> WS  :   ( ' ' | '\t' | '\r' | '\n' ) { $channel=HIDDEN; } ;
> 




List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to