[antlr-interest] Making multiple passes over a tree

Ric Klaren ric.klaren at gmail.com
Thu Jul 14 01:06:56 PDT 2005


On 13 Jul 2005 11:51:36 -0000, Subhobroto  Sinha
<subhobrotosinha at rediffmail.com> wrote:
>  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...

An antlr treeparser always goes down from the top. So you'd be stuck
with the solution you now have or alternatively you can build parts of
the symbol table during the normal parsing e.g. collect the subtrees
with the variable declarations and run over them separately.

Using the wildcard match symbol '.' you can skip the variable bits
during the normal run of the tree parser.

Cheers,

Ric


More information about the antlr-interest mailing list