|
|
This post was updated on .
I'm having trouble understanding why I'm having to implement an argCount variable, rather than rely on the symbol table. I guess the information is not readily available in a one-pass compiler - like I would need it to be. Could someone shed some light on this?
EDIT** I cannot for the life of me figure out how to properly increment the arg counter. Whenever I get one right, another is wrong. HELP!!
|
|
OK, I solved it. WOW. I have to admit, this stage of the course doesn't have a lot of direction like the others do. This is def. the hardest for me.
You think that spending all that time writing the analyzer and designing the symbol table would provide you with enough information to "take it on home," as they say, but really it doesn't....
|
Administrator
|
If you are talking about the argument count for function calls, watch out for nested functions as in
do four(a,b,c,two(x,y));
The argCount variable can't be an object variable because the nested call to parseExpressionList() will screw up the value for the outer parseExpressionList().
I solved this problem by having parseEpressionList() use a local variable for the expression count and return that value so that parseFunctionCall() [or whatever] would get the correct value regardless of nesting.
--Mark
|
|
Haven’t gotten there yet, and until I see the error, I prob won’t solve it. On Dec 1, 2016, at 2:57 PM, cadet1620 [via Nand2Tetris Questions and Answers Forum] < [hidden email]> wrote:
If you are talking about the argument count for function calls, watch out for nested functions as in
do four(a,b,c,two(x,y));
The argCount variable can't be an object variable because the nested call to parseExpressionList() will screw up the value for the outer parseExpressionList().
I solved this problem by having parseEpressionList() use a local variable for the expression count and return that value so that parseFunctionCall() [or whatever] would get the correct value regardless of nesting.
--Mark
|
|
So, I'm jew a few lines off from matching SquareGame.vm. However, I have a question: since there was no concrete test for our symbol table implementation, I am wondering if this is the correct representation for the class-scope symbol table of SquareGame class:
CLASS-SCOPE SYMBOL TABLE
(direction, int, field, 4)
(square, Square, field, 3)
(size, int, field, 2)
(y, int, field, 1)
(x, int, field, 0)
Does this look right? My brain is a little foggy right now...
Edit: My guess is it's not. It's counting the symbol table of Square class... I think it should look like this:
CLASS-SCOPE SYMBOL TABLE
(direction, int, field, 4)
(square, Square, field, 3)
, so that the second line of SquareGame.vm is "push constant 2", rather than what I have "push constant 5"
|
Administrator
|
Your edit is close. Symbol table should be:
(direction, int, field, 1)
(square, Square, field, 0)
Jack files should be compiled independently. The same output .vm files should result from compiling all the files in the directory at once, or compiling each file one at a time.
When compiling a directory, you need to start with a new, empty, symbol table for each file.
--Mark
|
|
Boom. Worked like a charm. Onto 'Average' ! Almost done!!
|
|