(Thanks to Venkita Subramonian for figuring out how to get the inner class visitors to work.)

We are using the Visitor pattern to traverse ASTs in this course. In writing your code generator, you are not confined to using a single visitor.

Recall that the Visitor pattern performs a double dispatch: the method that executes is a function of the visitor and the object being visited. Thus, the code for a given Visitor should not try to do too much, but should perform a specialized function for the visitor and AST node involved.

When specialized processing is needed, say for

then you should use an inner class visitor, which should be declared "protected", and apply that visitor to the appropriate nodes.