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

Cameron Esfahani dirty at apple.com
Thu Jul 12 17:38:29 PDT 2007


Does anyone have any ideas or suggestions?

On Jul 11, 2007, at 11:05 PM, Cameron Esfahani wrote:

> 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

"You only live once, and the way I live, once is enough"

Frank Sinatra



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


More information about the antlr-interest mailing list