CSCE 434 Lecture 26
« previous | Wednesday, October 23, 2013 | next »
Exam on Friday over Chapters 1–4
Symbol Tables
Be sure to allocate enough space (better languages take care of this for you)
Operations:
insert(name,p)
— create record for name at levelp
lookup(name)
— returns pointer or indexdelete(p)
— deletes entry.
Hash Functions
- Ideal uniform distribution
- Avoid collisions as much as possible, but they are inevitable when mapping to a smaller domain.
Dealing with collisions:
- linear rehashing
- quadratic rehashing
- add value of secondary hash
Bucket Hashing
Collisions just added to list at position
Insert at front or at end
Promotion (performance enhancement)
- move item to front on each lookup
- move item up by one position each lookup (proven to work as well as anything else)
Scope Nesting
Levels of Scopes:
- Current scope (innermost scope)
- Open scope (all scopes surrounding the current scope)
- Closed Scope (All other scopes)
Only variables within open scope should be visible for lookup.
New declarations are added to current scope
Closed scope is inaccessible
Use only one table per scope, chain sub-scopes to parent scope
- Stack structure may be used
lookup(name)
will walk up chain of tables until it findsname
.delete(p)
will throw away table for levelp
String Storage
Storing identifiers in symbol table entries requires one of:
- variable sized entries
- hard small limit on size
- much wasted space
Solution: store character strings in a string space and refer to them with simple fixed size descriptors
- maintained by symbol table
- temporary entries added (by scanner) at end of string space.
Procedure Abstraction
Separate compilation:
- allows us to build large programs
- reasonable compile times
- requires independent procedures
Linkage convention:
- "contract"
- Largely machine dependent
- divides responsibility
Procedures inherit a valid run-time environment and that they restore one for their parents
Linkages happen at run time, but code to make linkage generated at compile time
Essentials
- on entry, establish
p
's environment - on call, preserve
p
's environment - on exit, destroy
p
's environment
Procedure Linkages
Each procedure has an activation record or a frame:
- parameters
- return value
- return address
- access link
- (current frame pointer)
- caller frame pointer →
- locals
This assumes call-by-reference