Symbol Table

Symbol Table Introduction:

Why are Symbol Tables used in a compiler?
  • A compiler records the identifiers used in the source program and collects the information about various attributes of those identifiers
  • Symbol Table stores the information about an identifier along with their attributes
  • Attributes provide information about the identifier type, its scope and in the case of procedure names, such as the number and type of its arguments, the method for passing each argument (by reference) and the type returned if any
  • To store or retrieve the information about an identifier quickly at compile time as well as at runtime environment
  • To achieve compile time efficiency
  • To verify that used identifier have been declared

  • The Symbol Table is a data structure containing a record for each variable name or identifier with fields for the attributes of the name
  • The data structure should be designed to allow the compiler to find the record for each name quickly and to store or retrieve data from that record quickly

Symbol Table used by various Phases
Symbol Table is used by various phased as:
Lexical Analyzer phase: Stores the information of identifiers such as its lexeme, its type, its position in storage etc, into symbol table if it is already not present
Syntax analyzer phase: Symbol Table is used to verify the information about the tokens being generated while checking syntax of the source code
Semantic Analyzer phase: Symbol Table is used for type compatibility or type checking issues
Code generation Phase: Symbol Table is used to know the runtime space allocated and the type of runtime space allocated.

Symbol Table Format:
A Symbol Table format that associates lexical names with their attributes is shown:
Names
Attributes
Variables, Constants
Type, Size, line number where declared, scope, lifetime, binding, address
Procedure/Functions
Number of parameters, return types
Array
Number of dimensions, array bounds
Table: Names and their Attributes



Share on Google Plus

About Data Sciences by Venu

Hi, My name is Venugopala Chary and I'm Currently working as Associate Professor in Reputed Engineerng College, Hyderabad. I have B.Tech and M.tech in regular from JNTU Hyderabad. I have 11 Years of Teaching Experience for both B.Tech and M.Tech Courses.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment