CS 226: Data Structures, Program #5

Macro Turtle

Assigned: Monday, November 15
Due: Monday, November 22, 11:59 pm (UNGRADED)

(Reminder: Please do not look at each other's source code except for any designated project partner. We will be actively looking for programs that are "too similar", and I do not wish to find any.)

Overview

In this program, you will implement a (2,4)-tree to use as a dictionary. Using this dictionary, you will add a macro facility to the Turtle Commander. The macro facility allows you to define a named list of commands, which may be executed any number of times in the future. The ability to re-use command sets in this way adds substantial power to the Turtle Commander package. In the assignments which follows this one, you will use the macros to define fonts and write out strings.

(2,4)-Tree

Your (2,4)-tree should implement the ordered dictionary ADT as described in your textbook. You do not need to support multiple elements with the same key in your (2,4)-tree. However, this does not mean you do not need to deal with the situation. For example, if the user tries to create a second macro with the same name as an existing macro, you should assume they mean to overwrite the existing macro with the new macro. The elements stored in your (2,4) tree will be some type of command list. You are free to implement this list of turtle commands as an array, a linked list, or whatever is convenient.

Macro Commands

To implement macros, we need to add a few commands to the TurtleCommander:
define <macroname>
endmacro
call <macroname>
undefine <macroname>

The macroname may be any valid name in Java (i.e. it must begin with a letter, followed by a sequence of letters, numbers, and underscores. Capitalization is significant). You may assume it is invalid to begin defining a new macro while already inside a macro definition. However, it is valid to call a macro from inside of a macro, so be carefule of infinite calling loops. You may also assume that undo/redo commands are not allowed inside a macro definition. If you follow a call command with an undo command, it should undo the entire macro (not just the last command inside the macro). The undefine command exercises your ability to remove nodes from a (2,4) tree.

Program Execution

Your TurtleCommander program should execute in the same way as the TurtleCommander in Program #3. You should be able to type into it interactively or redirect standard input from a file or another program as described in that assignment.

If your TurtleCommander from previous assignments still does not function properly, you need to get it to a working state. You may see me or the TAs during office hours, as well as possibly scheduling other times to help you get your program into proper conformance.

As in previous assignments, you should handle error conditions gracefully, without causing the program to crash or exit unless absolutely necessary.

Restrictions

You may use the java.io and java.lang class libraries. You may use the StreamTokeninzer or the StringTokenizer to parse your input, as in previous assignments. You may use the TurtleCommander program provided by us if you choose, but you still must not share code with other students (except in your programming pair). In general, you may not use classes from the java.util library unless you receive permission to do so for some particular class. One exception is the java.util.Random class, which may be useful for testing some of your programs and does not jeopardize the goals of the class.

Submission - Read  this Carefully

This is an ungraded program. The program which follows will be a graded one which builds on this one. Your submission should include a set of .java files and a README.txt file with any information you want to tell the grader about running your program. Your main program class must be called TurtleCommander, and thus it should be compilable using "javac *.java" and runnable with the command "java TurtleCommander". You should submit your program  as a single .zip (zip archive) file. This file should have no directory structure in it -- just the actual files, so extracting them should result in all your original files placed in the current directory. 

To submit, you should follow these steps:

  1. Create the .zip file for submission
  2. Make a new, empty directory
  3. Copy the submission file to the new directory
  4. Extract all the files from your submission file into the new directory
  5. Verify that you can compile and run the program on your test cases in the new directory.
  6. Go to the submissions page
  7. Submit the .zip file, making sure that the file appears in the directory listing displayed in the browser after submission (the file size listed could be slightly different on the recipient SunOS machine from that of a Windows  OS machine, but they should be very similar)
  8. Also in the submissions page, View the submission to be certain that the file is there (you should see basically the same directory listing you saw at the end of step 7).
If anything goes wrong with steps 7 or 8, try repeating them (resubmitting your file overwrites any previous submission and time stamp). If you cannot successfully submit your assignment, immediately send e-mail to the professor andthe head TA explaining the problem (with all details so we can hopefully fix it) and including the submission file as an e-mail (MIME) attachment. It is your responsibility to verify that the assignment is received. If we do not have an assignment or record of its submission, it will receive zero points.

Grading

This program is ungraded, but the following one will be graded based on:
Compiling and running
Proper execution on a number of our test cases (with valid and invalid inputs)
Overall implementation correctness
Comments, style, and readability (informative,  but not extraneous comments are appreciated)
If your program does not compile, you can expect to receive very few points, if any. This should encourage you to take care in your submission process.

Final Words of Encouragement

Good luck with macros! With macros in hand, you can re-use command streams and create even better drawings. The next assignment will extend the macro facility to the creation and use of fonts. As always, get in touch with the TA or a CA if you get stuck, and be sure to let us know as soon as possible if the assignment is unclear. If you're having trouble with fundamental concepts or the CAs can't help you, come see me and I'll get you back on track.

Home
November 15, 2004