[antlr-interest] Dealing with lists in a in tree grammar action

Cameron Esfahani dirty at apple.com
Wed Jul 11 23:05:30 PDT 2007


I've reached the stage in my tree grammar that I want to start  
keeping information in parallel structures.  Ones that are more  
optimized for the work I need to do after the tree grammar walker has  
finished.

But I've reached a small impasse when I'm trying to handle lists in  
an action for a rule in my tree grammar.

Here is a small portion from my tree grammar.  An array can have one  
or more elements in it.  What I'd like to do in my action for  
"elements" is gather each of the "value" and add them to a list.

array
	:	elements
	;

elements
	:	value+
	;

value
	:	^( T_STR STRING )
	|	^( T_HEXSTREAM STREAM )
	|	^( T_SYMREF IDENTIFIER )
	|	^( T_NUM number_size )
	|	^( T_OBJ object )
	|	^( T_ARRAY array )
	|	T_TRUE
	|	T_FALSE
	|	T_NULL
	;

I had hoped that I could do the following (this is using the C  
runtime, so I'm using it's types):

elements returns[ pANTLR3_VECTOR List ]
	:	v += value+
		{
			$List = $v;
		}
	;

But I get the following error from ANTLR:

error(134): TWalker.g:58:4: rule '+=' list labels are not allowed w/o  
output option: v

And, eventually, I get an error with the C runtime:

TWalker.c:969: error: 'struct TWalker_Ctx_struct' has no member named  
'vectors'

But I'm not worried about that yet.

I've read the documentation about "+=" only being applicable in AST  
or template outputs.  And so I'm stuck.

Does anyone have any suggestions on how to handle this?

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/20070711/5c9e6ed1/attachment.html 


More information about the antlr-interest mailing list