[antlr-interest] Implementing ASTVisitor for C#

Wee Li Yen weeliyen at hotmail.com
Mon Aug 17 03:46:01 PDT 2009


Hi,

I have now the C Sharp Parser and C Sharp Lexer. Now I need to implement the ASTVisitor to manipulate AST for C# after parsing in a directory/file.
I am doing sth like this "CSParser.compilation_unit_return x = parser.compilation_unit();" in my main class.

1. The problem now is how do I get the tree / root of the tree out of the compilation unit return to me?

2. From the TreeVisitor (http://www.antlr.org/api/CSharp/class_antlr_1_1_runtime_1_1_tree_1_1_tree_visitor.html), there is a Visit() method which has the traversal logic.
I plan to use it to implement the Action method in the Visitor pattern. 
Then for each visit to the each node (class, method, variables etc), I will write another class which has all the different visits (eg. Visit(class, action) n Visit(method, action)). 
The problem is how do I gain access to the info of class, methods, variables etc of the tree? Through the Adaptor? How do I get the adaptor from the compilation unit?
If not through the Adaptor, what other means can I use?

4. In addition, the Visit() method takes in 2 parameters one of which is an object, the other is a ITreeVisitorAction.
So now what is the object? The tree or the root of the tree?
For the ITreeVisitorAction and ITreeAdaptor, how do I know the right instance of which concrete class (BaseTree or CommonTree or other tree) to use, can I get clues it from the compilation unit as well?


Would be grateful if anyone can help me with at least one of the doubts...

Li Yen


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090817/794bed6c/attachment.html 


More information about the antlr-interest mailing list