[antlr-interest] AST rewrite bug C# target

Floris van Nee floris.vannee at gmail.com
Sat May 9 01:55:40 PDT 2009


Hi all,
thanks for all the answers!

ANTLR can handle the generics - I haven't had any problems with that yet,
but C# gave compile errors about the identifier 'ids'. It is fixed now
though, thanks to Sam, $ids does work. I thought the $ wasn't neccessary,
because in normal mode (not output=AST) it just works without the dollar
sign.

There's one more error left though, in rules like:
type_qualifier returns [List<string> ids]
: v=VOID
{
$ids = new List<String>() { "System", "Void" };
}
| qual=qualifier
{
$ids = qual;
}
;

Here I want to assign the value of qual (which should be of type
List<string>) to $ids. In output=AST mode qual is of type qualifier_return,
instead of List<string>, but in normal mode it compiles correctly. What am I
doing wrong here then?

Thanks!
Floris

On Fri, May 8, 2009 at 11:10 PM, Johannes Luber <JALuber at gmx.de> wrote:

> > 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090509/edf5581b/attachment.html 


More information about the antlr-interest mailing list