|CIT 594 Interpreter
Notes for Part 1
Spring 2008, David Matuszek
<var declaration>requires at least one variable, but a
varnode may have zero children?
A function declaration requires aHow do we handle dot notation, for example,
varnode for its parameters. However, it is possible to declare a function without any parameters, in which case the
varnode is simple a placeholder.
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 specifiesHow do I handle the "special" variables
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.
These should be instance variables of yourIs it necessary to declare
Bugclass, 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).
Every variable, special or not, that is used in a Bugs language program should be accessed via either the
fetch(name)method or the
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
fetchmethod should get the value of special variables from the instance variables, and get the value of nonspecial variables from a HashMap.
storemethod should save the value of special variables into the instance variables, and save the value of nonspecial variables into a HashMap.
fetchmethod to declare a variable; the
varstatement should put it directly into the HashMap (with an initial value of
anglein 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.Is the
All you need is a simple boolean variable (say,
boolean exitingLoop), initally
- When you interpret a
loopstatement, exit the loop when this boolean variable becomes
true. (Then reset it to
- When you interpret an
exit ifstatement, set the boolean variable to
- When you interpret a list of statements, exit the list when the boolean variable becomes
exit ifstatement only allowed inside a
Ideally, yes, but that is difficult to require in the Parser, and not particularly easy in the Interpreter, either.What should I hand in?
When you interpret an
exit ifstatement as described above, and the
exit ifis not within a
loop, that basically ends interpretation of the
<program>. I think this is reasonable behavior.
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.