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

David Holroyd dave at badgers-in-foil.co.uk
Sat Aug 19 08:51:53 PDT 2006


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).

I am switching over to named tokens because I need a replacement for the
v2-style literal token constants (per my earlier posts to this list with
subject '[v3] LITERAL_xxx tokens?').


ta,
dave

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


More information about the antlr-interest mailing list