[antlr-interest] AST rewrite bug C# target

Johannes Luber JALuber at gmx.de
Fri May 8 14:10:23 PDT 2009


> Hi all,
> I think I've come across another bug in the C# target when rewriting ASTs
> in
> tree grammars.
> 
> I have included two files needed to reproduce the bug. The behaviour is
> this:
> 
> It happens when a tree grammar is created with rules which return values,
> like:
> 
> qualifier returns [List<string> ids]
> : ^(fqual=FQUALIFIER IDENTIFIER+ ARRAY?)
> {
> ids = new List<String>() { "System", "Void" };
> }
> ;
> 
> The C# compiler complains about the variable ids which it cannot find.
> Also, when you reference the return value of such a rule somewhere, as in
> qual=qualifier, you will have a variable qual with type qualifier_return,
> instead of List<string>.
> 
> I guess this is a bug in the C# target of ANTLR - but if it's not, what
> should I do to make the code compile correctly?
> I am using the latest version of ANTLR (3.1.3)
> 
> Thanks,
> Floris


I thought that escaping one or two of the angle brackets would work (e.g. "List\<string\>"). If not, you can define an alias in the @header-section:

alias StringList = System.Collections.Generic.List<string>;

and use StringList in the ANTLR grammar.

Johannes
-- 
Neu: GMX FreeDSL Komplettanschluss mit DSL 6.000 Flatrate + Telefonanschluss für nur 17,95 Euro/mtl.!* http://dslspecial.gmx.de/freedsl-surfflat/?ac=OM.AD.PD003K11308T4569a


More information about the antlr-interest mailing list