Header Ads Widget

Data structure for symbol table

Data structure for symbol table

  • A compiler contains two type of symbol table: global symbol table and scope symbol table.
  • Global symbol table can be accessed by all the procedures and scope symbol table.

The scope of a name and symbol table is arranged in the hierarchy structure as shown below:

  1. int value=10;  
  2.   
  3. void sum_num()  
  4.      {  
  5.        int num_1;  
  6.        int num_2;  
  7.   
  8.             {  
  9.              int num_3;  
  10.              int num_4;  
  11.             }  
  12.   
  13.        int num_5;  
  14.   
  15.             {  
  16.              int_num 6;  
  17.              int_num 7;  
  18.             }  
  19.      }  
  20.   
  21. Void sum_id  
  22.      {  
  23.        int id_1;  
  24.        int id_2;  
  25.   
  26.             {  
  27.              int id_3;  
  28.              int id_4;  
  29.             }  
  30.   
  31.        int num_5;  
  32.      }  

The above grammar can be represented in a hierarchical data structure of symbol tables:

Data structure for symbol table

The global symbol table contains one global variable and two procedure names. The name mentioned in the sum_num table is not available for sum_id and its child tables.

Data structure hierarchy of symbol table is stored in the semantic analyzer. If you want to search the name in the symbol table then you can search it using the following algorithm:

  • First a symbol is searched in the current symbol table.
  • If the name is found then search is completed else the name will be searched in the symbol table of parent until,
  • The name is found or global symbol is searched.

Post a Comment

0 Comments