[antlr-interest] Subrule alternatives - MismatchedTokenException	cannot be explained
    st3 
    stempuro2 at gmail.com
       
    Mon Aug 30 13:01:28 PDT 2010
    
    
  
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.
    
    
More information about the antlr-interest
mailing list