[antlr-interest] [v3] Tree building code generation bug?

David Holroyd dave at badgers-in-foil.co.uk
Mon Aug 21 02:19:45 PDT 2006


On Sat, Aug 19, 2006 at 03:51:53PM +0000, David Holroyd wrote:
> I had a valid gramar with the production,
> 
> methodDefinition[Tree mods]
> 	:	FUNCTION (mode='get'|mode='set')? IDENT
> 		parameterDeclarationList
> 		typeExpression
> 		(block)?
> 		-> ^(METHOD_DEF {$mods}
> 		                $mode? IDENT
> 				parameterDeclarationList
> 				typeExpression
> 				block?)
> 	;
> 
> When I changed that so that the first part reads,
> 
> 	FUNCTION (mode=GET|mode=SET)? IDENT
> 
> (with GET&SET defined in tokens) the resulting generated Java code does
> not compile.
> 
> The problem lies with lines like this,
> 
>     // src/antlr/org/asdt/core/internal/antlr/as3.g3:162:14:
>     // mode= GET
>     {
>     mode=(Token)input.LT(1);
>     match(input,GET,FOLLOW_GET_in_methodDefinition652); if (failed) return retval;
>     if ( backtracking==0 ) list_GET.add(mode);
>     }
>     break;
> 
> ...since no variable named 'list_GET' is defined.  There *is* however a
> variable named 'list_41' (41 is the token type value of the GET token).

For the record...

I've found that a workaround for this is to declare 'proper' tokens,
rather than using the 'tokens' section.

i.e. I get the above problem when the tokens are defined as,

  tokens {
      GET='get';  SET='set';
  }

but it goes away when I replace the above with something like this in
the grammar,

  GET   :   'get';
  SET   :   'set';


ta,
dave

-- 
http://david.holroyd.me.uk/


More information about the antlr-interest mailing list