07-08-2012, 04:39 PM
Symbol Table
Symbol Table.pptx (Size: 93.68 KB / Downloads: 28)
Compiler uses symbol table to keep track of scope and binding information about names
Symbol table is changed every time a name is encountered in the source; changes to table occur
if a new name is discovered
if new information about an existing name is discovered
Symbol table must have mechanism to:
add new entries
find existing information efficiently
Symbol Table Entries
Each entry for a declaration of a name
Format need not be uniform because information depends upon the usage of the name
Each entry is a record consisting of consecutive words
To keep records uniform some entries may be outside the symbol table
Information is entered into symbol table at various times
keywords are entered initially
identifier lexemes are entered by lexical analyzer
Symbol table entry may be set up when role of name becomes clear
Attribute values are filled in as information is available
Characters in a name
There is a distinction between token id, lexeme and attributes of the names
It is difficult to work with lexemes
If there is modest upper bound on length then lexemes can be stored in symbol table
If limit is large store lexemes separately
Storage Allocation Information
Information about storage locations is kept in the symbol table
If target is assembly code then assembler can take care of storage for various names
Compiler needs to generate data definitions to be appended to assembly code
If target is machine code then compiler does the allocation
For names whose storage is allocated at runtime no storage allocation is done