[antlr-interest] Collecting Values in Lists

Michael Bedward michael.bedward at gmail.com
Thu Apr 9 22:38:19 PDT 2009


Hi Behdad,

I'm sorry - I didn't read your question properly.  Here is an example
that might be more relevant...

grammar Test;

x returns [List<Integer> values]
@init {
$values = new ArrayList<Integer>();
}
	:	e=y {$values.add($e.value)} (',' e=y {$values.add($e.value)} )*
	;

y returns [int value]
	: DIGIT+ { $value = Integer.parseInt($text); }
	;

DIGIT	:	'0'..'9'
	;
	
WS	:	(' ' | '\t' | '\n' | '\r') { $channel=HIDDEN; }
	;

Hope this helps
Michael


More information about the antlr-interest mailing list