next up previous
Next: Changers Up: Walkers Previous: A Sample Walker: recursionWalker

Invoking a Walker

Each AST node type has its own class which defines a walk member function that accepts an object of (sub)class Walker. By calling this member function of some node with an object of your walker class, you can start traversing the tree from that node. Often, you'll want to run your walker on the entire AST; to do this, you can use the following code segment, where yourWalker is the type name for your walker.

        yourWalker w;
        for (unit_list_p u=CBZ::Program.begin(); u!= CBZ::Program.end(); u++)
                (*u)->walk (w);

This code calls the walk method for each unitNode in the program using your walker.



Adam C. Brown 2006-01-26