Symbol Table
Symbol Table
Symbol Table
What is the Symbol Table symbol table is a data structure used by a language translator such as a compiler or interpreter
Table
name : attributes : Collect attributes when a name is declared. Provide information when a name is used. Two issues:
This requires three functions: lookup(s): returns the index of the entry for string s, or 0 if there is no entry
insert(s,t): add a new entry for string s (of token t), and return its index delete(s): deletes s from the table (or, typically, hides it)
01 PROGRAM Main 02 GLOBAL a,b 03 PROCEDURE P (PARAMETER x) 04 LOCAL a 05 BEGIN {P} 06 a 07 b 08 x 09 END {P} 10 BEGIN{Main} 11 Call P(a) 12 END {Main}
Symbol Table
Each piece of info associated with a name is called an
Type
Storage allocation info (number of bytes). Line number where declared Lines where referenced.
Scope.
Symbol Table
A name can represent
Variable Type Constant Parameter Record Record Field Procedure Array Label file
Symbol Table
Different Classes of Symbols have different Attributes
Variable, Type, Constant, parameter, record field.
Type is one of attributes.
Procedure or function.
Number of parameters, parameters themselves, result type.
Array
# of Dimensions, Array bounds.
File
record size, record type
Other attributes
A scope of a variable can be represented by
A number (Scope is just one of attributes) A different symbol table is constructed for different scope.
Thank you