[antlr-interest] Making multiple passes over a tree

Subhobroto Sinha subhobrotosinha at rediffmail.com
Wed Jul 13 04:51:36 PDT 2005


  
Hello

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
etc...

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 ?

Regards

Subhobroto Sinha
http://www.geocities.com/subhobrotosinha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050713/7a5d50d5/attachment-0001.html


More information about the antlr-interest mailing list