[antlr-interest] (no subject)

Cameron Esfahani dirty at apple.com
Mon Aug 6 20:32:03 PDT 2007


I'm trying to add support for arithmetic operations to my grammar.  I  
took the rules from the C grammar.  Everything seems fine in my  
parser grammar, but when I try and add the relevant pieces to my tree  
grammar, I get the following error:

error(210):  The following sets of rules are mutually left-recursive  
[exclusive_or_expression, unary_expression, primary_expression,  
shift_expression, inclusive_or_expression, numeric_expression,  
and_expression, cast_expression, multiplicative_expression,  
additive_expression, postfix_expression]

Here is the portion from the 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
	|	unary_operator whitespace! cast_expression
	;

postfix_expression
	:	primary_expression
	;

unary_operator
	:	'~'
	|	'!'
	;

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

and here is the portion from the tree grammar:

numeric_expression
	:	inclusive_or_expression
	;

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

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

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

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

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

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

cast_expression
	:	unary_expression
	;

unary_expression
	:	postfix_expression
	|	unary_operator cast_expression
	;

postfix_expression
	:	primary_expression
	;

unary_operator
	:	'~'
	|	'!'
	;

primary_expression
	:	^( T_NUM number_size )
	|	numeric_expression
	;

Did I do it correctly?

Cameron Esfahani
dirty at apple.com

Linus is dumb.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070806/96e832c7/attachment.html 


More information about the antlr-interest mailing list