how to print vm commands in correct order
Posted by kraftwerk1611 on
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/how-to-print-vm-commands-in-correct-order-tp4030962.html
Hi,
A problem that I am having when writing to a vm file is that in order to write 'function x nLocals' command, you need to know the number of local variables for that function.
However by the time I have this information the vm code for subroutine body has already been written to the vm file. If I print the 'function x nLocals' now then it ends up at the end of file.
Same happens with other vm commands of seven.jack file, which are appearing in reverse order for me like the following
call Output.printInt 1
function Main.main 0
What is the solution of this problem?
Also to generate vm code for expressions like (1+(2*3)), is it so that one has to know about two or three next tokens?
Thanks