Wednesday, February 27, 2002

We nee dto look into symbol tables
METHOD 2 - SYMBOL TABLE OF LISTS/STACKS
Idea: Maintain a single symtab. Individual stacks, one for each name,
replace stack(list) of symbol tables. When parsing block b, stack
associated w/ each name x includes info about decl of x in b or in
scopes that enclose b. Level # attribute is used to determine whether
a decl was made in b's scope or in an enclosing scope.

(1) On block entry: increment level # (after entering proc name into symbol
table)
(2) See decl of x: look up x in symtab;
if x is there, fetch level # from the top of stack entry
if that level# = current level # then multi decl'd
else /* x is there, top of stack level # not equal current */
push (current level # and other attributes)
else /* x not in symbol table */
add x to symtab;
push (current level # and other attributes) onto x's stack
(3) See use of x: lookup x in symtab if not there or stack is empty then error.
(4) On scope exit:
(a) Scan entries in symtab popping every top-of-stack entry that has
current level #
(b) decrement level #

0 Comments:

Post a Comment

<< Home