Screen Mode
Tokens:
Keywords of the language, special characters/punctuation, user defined identifiers used for different meanings, constants
Identifiers:
Identifiers are user defined variables, memory location labels parameter names names of subroutines (functions or procedures) which are associated with entry points of the routines' code array or structure names field names; file names; enumerated type values constant names; type names Need a global structure to store identifiers and their associated meanings (attributes) for future reference. This structure provides more information that the grammar and syntax directed translation of the language would not normally be able to carry.
Reserved words
These may be stored here too. You have to look up an identifier and reserved words have the same syntax as an identifier.
jcsites.juniata.edu/faculty/rhodes/lt/sytbmgmt.htm
1/7
7/10/13
Scoping rules
The symbol table must be able to handle the scoping rules of the language.
Program components
Declarative statements- define identifiers and their attributes Imperative statements - uses identifiers assuming their attributes Languages and their explicit declarative statements Pascal, Ada C, C++, Java, PL/I FORTRAN COBOL VAR statement statements beginning with a type TYPE, DIMENSION statement DATA DIVISION
2/7
jcsites.juniata.edu/faculty/rhodes/lt/sytbmgmt.htm
7/10/13
Implicit Declarations
Some languages have implicit declarations FORTRAN or PL/I SUM = SUM + I (first encounter assumes declaration with default attributes) APL, BASIC, LISP (most interpreted languages)
Actions on declarations
Declarative statements generally do not translate to (or directly associated with) any executable code. They may allocate space at designated times, however. Symbols can be monitored, especially in languages that require declaration statements SUBSEQUENT FIRST ENCOUNTER CONCLUSION ENCOUNTER Declaration Declaration Declaration Reference (in imperative statement) Reference (in imperative stmt) Declaration None NA Continue--this is the expected case Multiple declarations error unless appropriate within scoping rules Unused warning message Undefined error
String Management
How to efficiently store names of identifiers
jcsites.juniata.edu/faculty/rhodes/lt/sytbmgmt.htm 3/7
7/10/13
Name Searching
Functions:
- enter new name into table Declaration of name - return error if already there - add new attributes as found Use - expect name to be found - return position of entry in table - delete entries
Entry of new scope - allow new declarations or redefined declarations Exit of scope
Goals:
jcsites.juniata.edu/faculty/rhodes/lt/sytbmgmt.htm 4/7
7/10/13
1. efficiency of declaration entry, insertion of new name 2. efficiency of retrieval, lookup 3. sorted list of symbol table dump Most important would be #2
Approaches:
n is the number of entries in the symbol table for the analysis below n' is the number of entries in the current [local] block
1. Linear access
Assuming error free source file Time(declaration) = k or O(1) [k is some constant] Time (reference) kn/2 or O(n) To check for errors Time(declaration) ~= kn'/2 Time(reference) ~= kn/2 Time(block entry) = O(1) Time(block exit) = O(n') or O(1) if display used Time(sort) = O(n log n)
jcsites.juniata.edu/faculty/rhodes/lt/sytbmgmt.htm
5/7
7/10/13
3. Tree access
- assumes a more random encounter of names BACPCDBQCDE - entries of symbol table are organized into tree structure - have forest of trees - each tree constitutes a block Average Time(decl) = O(log n) Average Time (ref) = O(log n) Worst case Time(decl) = T(ref) = O(n) Time(sort) = 0 Time(entry) = O(1) Time(exit) = O(n')
4. Hash tables
use a hash function on name to find location in symbol table symbol table is organized like a table of stacks since some identifiers in different block will collide Time(declaration) = O(1) or O(n') Time(reference) = O(b) where b is the chain depth Time(entry) = O(1) Time(exit) = O(n) or O(n') if second link connects block's ids
7/10/13
inaccessible entries
jcsites.juniata.edu/faculty/rhodes/lt/sytbmgmt.htm
7/7