Symbol Table & its usage by various phases of compiler

 Symbol Table :

  • When names are found, they will be entered into a symbol table, which will hold all relevant information about identifiers, function names, objects, classes, interfaces, etc. 
  • This information will be used later by the semantic analyzer and the code generator. 

USAGE OF SYMBOL TABLE BY VARIOUS PHASES OF COMPILER :



  • Lexical Analysis: Creates new entries in the table about token. 
  • Syntax Analysis: Adds information regarding attribute type, scope, dimension, line of reference, etc in the table. 
  • Semantic Analysis: Uses available information in the table to check for semantics i.e. to verify that expressions and assignments are semantically correct(type checking) and update it accordingly. 
  • Intermediate Code generation: Refers symbol table for knowing how much memory and what type is allocated and table helps in adding temporary variable information. 
  • Code Optimization: Uses information present in symbol table for machine dependent optimization. 
  • Target Code generation: Generates code by using address information of identifier present in the table. 


SYMBOL TABLE :


Symbol table: data structure used by a compiler to keep track of semantics of names. 


  • Determine whether the variable is defined already or not. 
  • Determine the scope. 
  • The effective context where a name is valid. 
  • Where it is stored: storage address. 
  • Type checking for semantic correctness determination. 

 

Operations: 

  • Find / Lookup /Search: Access the information associated with given name. 
  • Insert: add a name into the table. 
  • Delete: remove a name when its scope is closed

Post a Comment

Previous Post Next Post