[antlr-interest] enum return types for rules?

Cameron Esfahani dirty at apple.com
Mon Jul 16 14:07:58 PDT 2007


I think this is a C runtime-specific issue.

Has anyone used an enum as a return type from a rule?

I'm getting an error from the compiler because I'm using one.

Here is a simplified version of the rule:

size_qualifier returns [ ValueNumberValueWidth Width ]
	:	T_SIZE_8
		{
			$Width = kValueNumberValue8Bit;
		}
	;

And ValueNumberValueWidth is defined as:

typedef enum {
	kValueNumberValue8Bit		= 0x300,
	kValueNumberValue16Bit,
	kValueNumberValue32Bit,
	kValueNumberValue64Bit,
} ValueNumberValueWidth;

When I try and build my tree grammar, I get the following error from  
gcc:

TWalker.c: In function 'size_qualifier':
TWalker.c:1132: error: incompatible types in initialization

Because antlr has generated the following line:

     ValueNumberValueWidth Width = NULL;

I've also gotten some other warnings because of similar constructs.   
One of my rule's returns an unsigned long long.

Again, antlr is generating:

     unsigned long long Number = NULL;

And gcc complains;

TWalker.c: In function 'number':
TWalker.c:1220: warning: initialization makes integer from pointer  
without a cast

Does anyone have any suggestions?

Cameron Esfahani
dirty at apple.com

"In the elder days of Art, Builders wrought with greatest care each  
minute and unseen part; For the gods see everywhere."

"The Builders", H. W. Longfellow



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070716/36507e21/attachment.html 


More information about the antlr-interest mailing list