GCL SymbolTable A Chain of Hash Tables based on java.util.Hashtable - - PowerPoint PPT Presentation

gcl symboltable
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Joseph Bergin 1/12/99 1

GCL SymbolTable

A Chain of Hash Tables based on java.util.Hashtable

slide-2
SLIDE 2

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.

slide-3
SLIDE 3

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.

slide-4
SLIDE 4

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

slide-5
SLIDE 5

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 + max

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

slide-6
SLIDE 6

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.

slide-7
SLIDE 7

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.

slide-8
SLIDE 8

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

slide-9
SLIDE 9

Joseph Bergin 1/12/99 9

SymbolTable Entries

SymTabEntry

VariableEntry TypeEntry

...

(location, type) (type description) (name, level)

SymbolTable.lookupId returns one of these objects