//============================================================================== // CodeGeneratingVisitor.java //============================================================================== package sample.visitor; /** * Responsibilities:

* * @author Copyright 2003 Nikolas S. Boyd. */ public class CodeGeneratingVisitor implements Node.Visitor, AssignmentNode.Visitor, VariableReferenceNode.Visitor // ... other kinds of AST node Visitors { /** * Visits an AST node and generates code appropriate to the specific * kind of node. * @param node a node in a program AST. */ public void visit(Node node) { // this method should never be called in practice // it's here only to satisfy the selective visitor pattern return; } /** * Visits an AST node and generates code appropriate to the specific * kind of node. * @param node a node in a program AST. */ public void visit(AssignmentNode node) { // ... assignment node code generation return; } /** * Visits an AST node and generates code appropriate to the specific * kind of node. * @param node a node in a program AST. */ public void visit(VariableReferenceNode node) { // ... variable reference node processing return; } // ... visit() methods for each of the other kinds of node Visitors ... } // CodeGeneratingVisitor