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?
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!



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; } ;

-- 
View this message in context: 
http://antlr.1301665.n2.nabble.com/Subrule-alternatives-MismatchedTokenException-cannot-be-explained-tp5479806p5479806.html
Sent from the ANTLR mailing list archive at Nabble.com.

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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to