CIT 594 Interpreter Notes for Part 1
Spring 2008, David Matuszek

How is it that a <var declaration> requires at least one variable, but a var node may have zero children?
A function declaration requires a var node for its parameters. However, it is possible to declare a function without any parameters, in which case the var node is simple a placeholder.
How do we handle dot notation, for example, willy.x?
Ignore it for Part 1. We'll deal with that in Part 2.
I used "do" as the string value in the root of the AST for <do statement>. Is that correct?
No. The assignment clearly specifies "call".

A function always returns a value. When a function is called from within an expression, the value is used in the expression. When the function is called from a do statement, the value is ignored.

How do I handle the "special" variables x, y, and angle?
These should be instance variables of your Bug class, and your Java code can access them in the usual way.

After declaring a variable, there are only two things you can do with it: Fetch it (get its value) or store it (give it a new value).

variable, special or not, that is used in a Bugs language program should be accessed via either the fetch(name)method or the store(name, value) method.
If a nonspecial variable is used without first having been declared, you should throw a RuntimeException. You can tell if it has been declared by seeing if it is in the HashMap. This means that you can't use the fetch method to declare a variable; the var statement should put it directly into the HashMap (with an initial value of 0.0).
Is it necessary to declare x, y, and angle in a var declaration before I use them?
No. In fact, it would be a good idea to throw a RuntimeException if any of these variables occurs in a var declaration.
What should the default (initial) "color" instance variable be set to?
How do I exit from a loop?
When I spoke in class about how to implement the Interpreter, I thought it would be necessary to put a special "$exitingLoop" variable in the HashMap. I was wrong.

All you need is a simple boolean variable (say, boolean exitingLoop), initally false.
Is the exit if statement only allowed inside a loop statement?
Ideally, yes, but that is difficult to require in the Parser, and not particularly easy in the Interpreter, either.

When you interpret an exit if statement as described above, and the exit if is not within a loop, that basically ends interpretation of the <program>. I think this is reasonable behavior.
What should I hand in?
You should hand in all source files necessary to run your program. Also include all your JUnit test files. The Tree class should be in its own package; the Recognizer/Parser/Interpreter should be in a separate package.

In Eclipse you can highlight your Interpreter project, Export as a Jar file, check your Interpreter and Tree packages, and expand them to include the source files. Then post the jar file. In NetBeans it's probably easiest to just create a zip file containing the two packages.