Can't get the number of local variables the functions have in parsing subroutine declaration?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Can't get the number of local variables the functions have in parsing subroutine declaration?

Henoktes722
class Main {  
 function void main() {
       var int x, y;
       do Output.printInt(1 + (2 * 3));
       return;
 }
}

I'm having a hard time to complete the project. Here writeFunction called first and writes, "function Main.main 2". But we can't get the number of local variables the function have, since we are on subroutineDeclaration. So to actually get the number of local variables we need to call compileSubroutineBody then compileVarDec. So I can't get how to design the project to get the desired value.
Reply | Threaded
Open this post in threaded view
|

Re: Can't get the number of local variables the functions have in parsing subroutine declaration?

WBahn
Administrator
function Bob
Henoktes722 wrote
class Main {  
 function void main() {
       var int x, y;
       do Output.printInt(1 + (2 * 3));
       return;
 }
}

I'm having a hard time to complete the project. Here writeFunction called first and writes, "function Main.main 2". But we can't get the number of local variables the function have, since we are on subroutineDeclaration. So to actually get the number of local variables we need to call compileSubroutineBody then compileVarDec. So I can't get how to design the project to get the desired value.
So when you generate the VM code

function main 2

consider if it is required that all parts of this line have to be generated before you call subroutineDeclaration.

Perhaps part of it can and then the rest can be the first thing that is output by subroutineDeclaration.