| CIT 594 Interpreter
Notes for Part 1 Spring 2008, David Matuszek |
<var declaration>
requires at least one variable, but a var
node 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 thevarnode is simple a placeholder.
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 specifiesHow do I handle the "special" variables"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.
x,
y, and angle?These should be instance variables of yourIs it necessary to declareBugclass, 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 thefetch(name)method or thestore(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
- The
fetchmethod should get the value of special variables from the instance variables, and get the value of nonspecial variables from a HashMap.- The
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; thevarstatement should put it directly into the HashMap (with an initial value of0.0).
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?Color.BLACK.
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), initallyfalse.
- When you interpret a
loopstatement, exit the loop when this boolean variable becomestrue. (Then reset it tofalse.)- When you interpret an
exit ifstatement, set the boolean variable totrue.- When you interpret a list of statements, exit the list when the boolean variable becomes
true.
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.What should I hand in?
When you interpret anexit ifstatement as described above, and theexit ifis not within aloop, 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.