gcl symboltable
play

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


  1. GCL SymbolTable A Chain of Hash Tables based on java.util.Hashtable Joseph Bergin 1/12/99 1

  2. 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 2

  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 3

  4. Self Organizing Hash Table index index anObject 0 0 hasher newhasher n n max n + max Provided by java.util.Hashtable 2 * max Joseph Bergin 1/12/99 4

  5. Hashtable Chain Module 1 public Function 1 locals Module 2 private Module 2 public index index index index index index index index anObject anObject anObject anObject 0 0 0 0 0 0 0 0 hasher newhasher hasher newhasher hasher newhasher hasher newhasher n n n n n n n n max max max max n + max n + max n + max n + max 2 * max 2 * max 2 * max 2 * max 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 5

  6. Using the SymbolTable ● When enter a new ● New names are scope execute entered into the scoper.enter (push topmost scope on a new ÒscopeÓ) ● Searching starts at ● When exit that any desired scope, scope execute as long as you have scoper.exit (pop that a reference to that ÒscopeÓ) scope. Search continues through following scopes. Joseph Bergin 1/12/99 6

  7. Entering into the SymbolTable ● A given identifier can be entered only once 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 7

  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 8

  9. SymbolTable Entries SymTabEntry (name, level) ... VariableEntry TypeEntry (location, type) (type description) SymbolTable.lookupId returns one of these objects Joseph Bergin 1/12/99 9

Recommend


More recommend