[antlr-interest] Stringtemplate : parallel multi-valued attribute iteration

Terence Parr parrt at cs.usfca.edu
Fri May 7 13:16:06 PDT 2010


Hiya. ok, first question, why not just pass the lists? why create an array?
Ter
On May 7, 2010, at 1:08 PM, Bill Andersen wrote:

> 
> On May 7, 2010, at 15:56 , Terence Parr wrote:
> 
>> Hi Bill. that should work.  Can you show us how you set attributes types, vars?
>> Ter
> 
> 	  classDef(vars={ds.vars()},types={ds.types()}...)
> 
> where 'ds' is an instance of a support class for the parser.  It collects up variable references and types as parsing proceeds into two linked lists
> 
> 		List<String> vars = new LinkedList<String>();
> 		List<String> types = new LinkedList<String>();
> 
> 		public String[] vars() {
> 			return vars.toArray(new String[vars.size()]);
> 		}
> 		
> 		public String[] types() {
> 			return types.toArray(new String[types.size()]);
> 		}
> 
> and then converts those lists to arrays for passing into the template.
> 
>> On May 7, 2010, at 12:40 PM, Bill Andersen wrote:
>> 
>>> Folks
>>> 
>>> I have a template defined in a group file
>>> 
>>> classDef(vars,types,body) ::= <<
>>> public class Foo {
>>> 
>>> <vars,types:{ var,type | <type> <var> = null; }>
>>> <body>
>>> 
>>> }
>>>>> 
>>> 
>>> and I pass in a (Java) array of strings as values for the 'vars' and 'types' attributes.  So given
>>> 
>>> 	vars = ["v1","v2"]
>>> 	types = ["T1","T2"]
>>> 
>>> I'd like the output for the iterator on 'vars' and 'types' to be
>>> 
>>> T1 v1 = null;
>>> T2 v2 = null;
>>> 
>>> except that I'm seeing instead the output
>>> 
>>> [Ljava.lang.String;@63b9240e [Ljava.lang.String;@fee4648 = null; 
>>> 
>>> Iterating on one of the multi-valued attributes alone yields correct results.  I'm using the ANTLR 3.2 jars.  Any help appreciated.
>>> 
>>> 	.bill
>>> 
>>> 
>>> Bill Andersen 
>>> Highfleet, Inc. (www.highfleet.com)
>>> 3600 O'Donnell Street, Suite 600
>>> Baltimore, MD 21224
>>> Office: +1.410.675.1201
>>> Cell: +1.443.858.6444
>>> Fax: +1.410.675.1204
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>>> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>> 
> 
> Bill Andersen 
> Highfleet, Inc. (www.highfleet.com)
> 3600 O'Donnell Street, Suite 600
> Baltimore, MD 21224
> Office: +1.410.675.1201
> Cell: +1.443.858.6444
> Fax: +1.410.675.1204
> 
> 
> 
> 
> 



More information about the antlr-interest mailing list