CSCE 434 Lecture 17
Jump to navigation
Jump to search
« previous | Wednesday, October 2, 2013 | next »
Recording Types
Symbol Table
A symbol table is basically a stack of maps from identifiers to their declarations
- Adding Declarations: new entry in map at top of stack
- Adding Scopes: new map at top of stack
- Lookup: check top. If not found, check down stack
Program
: DeclList
{
$$ = new Program($1);
$$->check();
}
;
Every node should know how to check itself.
Type-checking happens depth-first traversal:
parse tree for "x*3 + y - j/7" expr (+) : int -> int -> int |-- expr (*) : int -> int -> int | |-- x -> lookup | `-- 3 : int `-- expr (-) : int -> int -> int |-- y -> lookup `-- expr (/) : int -> int -> int |-- j -> lookup `-- 7 : int