[antlr-interest] Making multiple passes over a tree
subhobrotosinha at rediffmail.com
Wed Jul 13 04:51:36 PDT 2005
I wanted to know how to make multiple passes over the AST, for example, I want to make atleast two passes over the AST :
firstPass : This pass will walk JUST ONLY OVER the variable declaration rules and build up a symbol table
secondPass : This will walk over the assignment statements and detect semantic errors
Right now, I have each of the passes walking over the full AST again and again, altough each pass has actually a very specific task to do.
So I was thinking if I could somehow make the treeparser such that it will skip over those portions of the AST with which it's not concerned.
For example, in the first pass, I would like to parse JUST THOSE statements which are declaring new variables but not assignent statements...
I HAVE to create the symbol table first because, in my language, the user can reference a variable from a different module (kinda like function) without explicitly declaring it, so I need to write code which will allow the current module to access that external variable.
However, it may also happen that the user has forgotten to declare the variable in any module at all, and hence no storage has been alloc. for that variable, so in that case I need to alert the user of his error (I will also need to tell him where he referenced the undeclared variables).
How do I make this possible in ANTLR - or do I have to keep walking all over the tree at every pass ?
Any suggestions/comments regarding this scenario ?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the antlr-interest