Joseph Bergin 1/12/99 1
GCL SymbolTable A Chain of Hash Tables based on java.util.Hashtable - - PowerPoint PPT Presentation
GCL SymbolTable A Chain of Hash Tables based on java.util.Hashtable - - PowerPoint PPT Presentation
GCL SymbolTable A Chain of Hash Tables based on java.util.Hashtable Joseph Bergin 1/12/99 1 Hash Tables Keys are used index buckets anObject to determine 0 the location in which to store a Value. hasher max Joseph Bergin 1/12/99
Joseph Bergin 1/12/99 2
Hash Tables
max anObject
hasher
index buckets
Keys are used to determine the location in which to store a Value.
Joseph Bergin 1/12/99 3
Self Organizing Hash Table
- Can achieve constant average time
lookup if buckets have bounded average length.
- Can guarantee this if we periodically
double number of hash buckets and re-hash all elements.
È Can be done so as to minimize movement of items.
Joseph Bergin 1/12/99 4
Self Organizing Hash Table
2 * max
newhasher
index max anObject
hasher
index
n n n + max
Provided by java.util.Hashtable
Joseph Bergin 1/12/99 5
Hashtable Chain
2 * max newhasher index max anObject hasher index n n n + max 2 * max newhasher index max anObject hasher index n n n + max 2 * max newhasher index max anObject hasher index n n n + max 2 * max newhasher index max anObject hasher index n n n + maxModule 1 public Module 2 public Module 2 private Function 1 locals
Conceptual view of GCL.SymbolTable
A scope (reference) is passed to each statement for lookups and to each declaration for insertion. This is always the topmost scope.
Joseph Bergin 1/12/99 6
Using the SymbolTable
- When enter a new
scope execute scoper.enter (push
- n a new ÒscopeÓ)
- When exit that
scope execute scoper.exit (pop that ÒscopeÓ)
- New names are
entered into the topmost scope
- Searching starts at
any desired scope, as long as you have a reference to that
- scope. Search
continues through following scopes.
Joseph Bergin 1/12/99 7
Entering into the SymbolTable
- A given identifier can be entered only
- nce into each scope.
- The chain is to permit the same name
to be redefined in a new context in the program.
- A chain is used so that the Symboltable
is stack like. Lookups find the most recent definition of a name.
Joseph Bergin 1/12/99 8
SymbolTable Entries
- Keys in the SymbolTable are Strings,
representing the identifiers in the program.
- Values asociated with the identifiers
depend on what that identifier represents (variable, type, function...)
Joseph Bergin 1/12/99 9
SymbolTable Entries
SymTabEntry
VariableEntry TypeEntry
...
(location, type) (type description) (name, level)