Lab 7 -- Visitors

For this lab assignment, you are to redo portions of labs 5 & 6 using Visitors as follows:

  1. Delete all the execute methods from the Instruction hierarchy.
  2. Add accept methods to the Instruction hierarchy that take an argument of type InstructionVisitor.
  3. Write the interface (or abstract class) InstructionVisitor.
  4. Write two visitors: the first visitor should just execute each instruction it visits; the second visitor should also execute each instruction it visits and then print the instruction, the value of the program counter, the value of the accumulator, and the values of the arithmetic and logic unit flags.
  5. Change the step and run methods in the class Machine to take and use visitor arguments.
  6. Make any other changes that you need. Turn in all the "interesting" code that you write. In particular, it is sufficient to turn in the code for one or two instructions since they will all be similar.

Extra Credit:

The new organization of the code makes it easy to add new visitors that operate on instructions. It is considerably harder (though not impossible) to add a new instruction to the machine without modifying any code. Try adding an instruction MULTIPLY to the machine: you cannot update any existing code. Hint: The book: A Little Java with Patterns has the solution.

Turn in your code during class on Monday, May 24th.


Visited times since March 23, 1999 (or the last crash).

Last modified: 05/12/99 17:34:25

yreimer@cs.uoregon.edu