[antlr-interest] Referring tree nodes in rules

Liviu U liviu.u at gmail.com
Fri Jul 6 10:40:01 PDT 2007


Hi all,

With great help from you guys and the book I managed to put up a subset of
C# parser.
In order to build the tree, i resorted to creation of a new TreeAdapter and
custom node classes for the elements i was interested in.
Methods overriden were Create and AddChild.

In AddChild method my code looks llike this:

                NodeClass cls = (t as NodeClass);
                if ( cls != null)
                {
                        if (ct.Token.Type == CSharpParser.TK_TYPEIDENT)
                            cls.Name = (ct as NodeTypeIdent).Name;

                        if (ct.Token.Type == CSharpParser.TK_METHOD)
                            cls.methods.Add(ct as NodeMethod);

                        return;
                }

I want to put the class name from the typeident node, and add the methods to
the class method collection.

Question: Can this code be moved inside the grammar file, somehow? Could the
nodes be referreed there?
I don't really want to a tree grammar.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070706/9a79ff20/attachment.html 


More information about the antlr-interest mailing list