[antlr-interest] StringTemplate attribute problem in Target Language generator

Terence Parr parrt at cs.usfca.edu
Sun Jul 4 13:17:01 PDT 2010


what is the invalid output? can't help until we know what's wrong.
Ter
On Jul 3, 2010, at 12:52 PM, Alan Condit wrote:

> Hi,
>
> I am trying to get type and name attributes to work for return  
> values specified in a rule. For example,
> if someone specifies the following rule:
> kfloat returns [ double value ]
> 	| KFLOAT
> 	;
>
> In the target language generator I need to be able to generate:
> \@property (assign, getter=get<it.name>, setter=set<it.name>\:)  
> <it.type> <it.name>;
> where <it.type> is "double" and <it.name> is "value" (of course  
> without the quotes)
>
> Currently all I have figured out how to get is:
> double value;
> using:
> <ruleDescriptor.returnScope.attribute:{ <it.dec>; }; separator="\n">
>
> I also need to use the same items to generate the getter and setter  
> methods like:
> @synthesize value;
> - (double)getValue
> {
>    return( value );
> }
>
> - (void)setValue:(double)aVal
> {
>    value = aVal;
> }
>
> So I have been trying something like this:
> <scope.attributes:{\@synthesize <it.name>;}; separator="\n">
>
> <scope.attributes.decl:{<"\n">-  
> (<it.type>)get<it.name><"\n">{<"\n">     
> return( <it.name> );<"\n">}<"\n\n">
> - (void)set<it.name>:(<it.type>)aVal<"\n">{<"\n">    <it.name> =  
> aVal;<"\n">}<"\n\n">}; separator="\n">
>
> Or this:
> <scope.attributes.decl:{
> - (<it.type>)get<it.name>
> {
>    return( <it.name> );
> }
>
> - (void)set<it.name>\:(<it.type>)aVal
> {
>    <it.name> = aVal;
> }
>
> }; separator="\n">
>
> Any help would be greatly appreciated. I am just learning  
> StringTemplate and it may be something simple
> biting me in the butt.
>
> Thanks again,
> Alan
> ---
>
> Alan Condit
> 1085 Tierra Ct.
> Woodburn, OR 97071
>
> Email -- acondit at ipns.com
> Home-Office (503) 982-0906
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list