[antlr-interest] error(10): internal error: TWalker.g : java.lang.IllegalArgumentException: Can't find template tokenRefRuleRoot.st

Cameron Esfahani dirty at apple.com
Thu Aug 9 19:50:08 PDT 2007


Based on some comments, I realized that I didn't understand tree  
grammars as well as I thought.  So looking back at section 8.2 in the  
ANTLR book, specifically at the implementations of CMinus.g and  
CMinusWalker.g, I realized that more complicated tree grammars don't  
look very similar to the parser grammar.

Here is the relevant portion from my parser grammar:

numeric_expression
	:	inclusive_or_expression
	;

inclusive_or_expression
	:	exclusive_or_expression ( whitespace! '|'^ whitespace!  
exclusive_or_expression )*
	;

exclusive_or_expression
	:	and_expression ( whitespace! '^'^ whitespace! and_expression )*
	;

and_expression
	:	shift_expression ( whitespace! '&'^ whitespace! shift_expression )*
	;

shift_expression
	:	additive_expression
		(
			whitespace!
			( '<<'^ | '>>'^ ) whitespace! additive_expression
		)*
	;

additive_expression
	:	multiplicative_expression
		(
			whitespace!
			( '+'^ | '-'^ ) whitespace! multiplicative_expression
		)*
	;

multiplicative_expression
	:	cast_expression
		(
			whitespace!
			( '*'^ | '/'^ | '%'^ ) whitespace! cast_expression
		)*
	;

cast_expression
	:	unary_expression
	;

unary_expression
	:	postfix_expression
	|	( '~'^ | '!'^ ) whitespace! cast_expression
	;

postfix_expression
	:	primary_expression
	;

primary_expression
	:	number_size -> ^( T_NUM number_size )
	|	'('! whitespace! numeric_expression whitespace! ')'!
	;

and here is the corresponding portion from the tree grammar:

numeric_expression
	:	^( '|' numeric_expression numeric_expression )
	|	^( '^' numeric_expression numeric_expression )
	|	^( '&' numeric_expression numeric_expression )
	|	^( '<<' numeric_expression numeric_expression )
	|	^( '>>' numeric_expression numeric_expression )
	|	^( '+' numeric_expression numeric_expression )
	|	^( '-' numeric_expression numeric_expression )
	|	^( '*' numeric_expression numeric_expression )
	|	^( '/' numeric_expression numeric_expression )
	|	^( '%' numeric_expression numeric_expression )
	|	^( '~' numeric_expression )
	|	^( '!' numeric_expression )
	|	^( T_NUM number_size )
	;

It doesn't give me that warning anymore, and I think it is correct...

Any comments?

Cameron Esfahani
dirty at apple.com

"Most people are bad programmers," says Joy. "The honest truth is  
that having a lot of people staring at the code does not find the  
really nasty bugs. The really nasty bugs are found by a couple of  
really smart people who just kill themselves. Most people looking at  
the code won't see anything ... You can't have thousands of people  
contributing and achieve a high standard."

Bill Joy on the myth of Linux's much touted "power in the masses"  
development benefits.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070809/10c29889/attachment-0001.html 


More information about the antlr-interest mailing list