Lecture 40

Using Visitors

The visitor pattern allows the user to build a data structures so that it is easy to add operations later.

Expression tree files

The following code provides the implementation of an expression tree that supports visitors. The following code provides an abstract class for a visitor as well as implementations of visitors to perform interpretation of arithmetic expressions along with visitors to perform various ways of printing the expressions.

Parser

This code builds the expression trees. We did not discuss it in class, but it is needed to run the code The following code is for an applet that creates a window to type in expressions. The value is displayed in the applet and the results of pretty printing in both inorder and postorder are displayed in the console window.