For the do...while, follow the model of the while statement in compileWhile(). Note that you will have to add do as a reserved word. while
statements have two jumps: a conditional jump if the expr is false, to
the end, and an unconditional jump from the end of the body back up to
the top. do...while statements
have only one jump: if the expr is true at the end, you jump back up to
the top. Save the position at the top (eg toplabel = cs.getPos()), and
then use it in a cs.emit(opcode, toplabel); you should not need to use cs.pokeLabel().
For procedures, note first that "procedure" is a more accurate term
because they can't return values, but in the syntax I called them
"functions" and they are compiled with compileFunction(). You need to
do two things: have compileFunction put the procedure name into the
symbol table, together with its entry point (what cs.getPos() is
returning at the start of compileFunction(), where f1entry, etc, is
being set).
Then, later, you will have to modify compileIdentStmt(), in the
second half ("// FUNCTION CALL"). Look up the procedure name in your
symbol table instead of using FHack(), and get the location loc. The actual code,
cs.emit(Machine.JSR, loc);
is exactly the same.
For final int constants, the
only change is to compileFactor(), in the isIdent(theToken) case. An
identifier can now be either a variable or a constant (or a
procedure!). If the identifier is a variable, compileFactor will look
up its global/localness and its location as usual. If it's a constant,
though, you'll proceed exactly as in the isNumber(theToken) case of
compileFactor(), except that you'll get the value for theNumber from the symbol table rather than from theToken.
Note that it should be illegal to use a procedure name where a
const/variable is expected, or to use anything but a variable name on
the lefthand side of an assignment, or to use a const/variable where a
procedure name is expected. However, I won't actually test for this.
To submit your project, create a zipfile and email it to me at
pld@cs.luc.edu. This is due by the end of finals week.