Keeping track of local information
. when a nested procedure is seen, processing of declaration in enclosing procedure is temporarily suspended
. assume following language
P D
D D ;D | id : T | proc id ;D ; S
. a new symbol table is created when procedure declaration
D proc id ; D1 ; S is seen
. entries for D1 are created in the new symbol table
. the name represented by id is local to the enclosing procedure
Until now, it has been discussed how declarations are processed when the language is such that it allows all the declarations in a procedure to be processed as a group. A single symbol table is used and a global variable offset is used to keep track of the next available relative address.
In a language with nested procedures, names local to each procedure can be assigned relative addresses. Multiple symbol tables are used. When a procedure declaration is seen, processing of declarations in the enclosing procedure is temporarily suspended. Consider the following language:
P -> D
D -> D; D | id : T | proc id ; D ;S
Whenever a procedure declaration D proc id ; D1 ; S is processed, a new symbol table with a pointer to the symbol table of the enclosing procedure in its header is created and the entries for declarations in D1 are created in the new symbol table. The name represented by id is local to the enclosing procedure and is hence entered into the symbol table of the enclosing procedure.
|