Current Scope?

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

Current Scope?

peterxu422
Why is there a need for the Current Scope? I am referring to page 239 in the API for the SymbolTable for subroutines VarCount(), KindOf(), and TypeOf(), where under the Function column refers to a current scope.

This is confusing because on page 226 it says that the compiler (at least for C compilers) checks whether the identifier is declared locally in the subroutine and if not then it checks whether it is declared globally in the file. Shouldn't we use the same approach for the Jack Compiler, by checking if the identifier exists in the subroutine Scope and if it isn't then check if it exists in the Class Scope? But for the Symbol table functions above it says to only check if they exist in the current Scope, which would be either the subroutine Scope or the class Scope, not both.
Reply | Threaded
Open this post in threaded view
|

Re: Current Scope?

cadet1620
Administrator
peterxu422 wrote
Why is there a need for the Current Scope? I am referring to page 239 in the API for the SymbolTable for subroutines VarCount(), KindOf(), and TypeOf(), where under the Function column refers to a current scope.

This is confusing because on page 226 it says that the compiler (at least for C compilers) checks whether the identifier is declared locally in the subroutine and if not then it checks whether it is declared globally in the file. Shouldn't we use the same approach for the Jack Compiler, by checking if the identifier exists in the subroutine Scope and if it isn't then check if it exists in the Class Scope? But for the Symbol table functions above it says to only check if they exist in the current Scope, which would be either the subroutine Scope or the class Scope, not both.
My SymbolTable code does, in fact, search first the subroutine scope and then the class scope and return the information for the symbol if it exists in either scope.

Since there is no defined interface to the SymbolTable to select which scope is being searched, I don't know how else you would find statics and fields when parsing at subroutine scope.

--Mark