DESKTOP

Algorithms for Compiler Design: VARIOUS APPROACHES TO SYMBOL TABLE ORGANIZATION

7/24/2010 8:06:48 PM
7.6 VARIOUS APPROACHES TO SYMBOL TABLE ORGANIZATION
There are several methods of organizing the symbol table. These methods are discussed below.

1 The Linear List

A linear list of records is the easiest way to implement a symbol table. The new names are added to the table in the order that they arrive. Whenever a new name is to be added to the table, the table is first searched linearly or sequentially to check whether or not the name is already present in the table. If the name is not present, then the record for new name is created and added to the list at a position specified by the available pointer, as shown in the Figure 1.

Click To expand
Figure 1: A new record is added to the linear list of records.

To retrieve the information about the name, the table is searched sequentially, starting from the first record in the table. The average number of comparisons, p, required for search are p = (n + 1)/2 for successful search and p = n for an unsuccessful search, where n is the number of records in symbol table. The advantage of this organization is that it takes less space, and additions to the table are simple. This method's disadvantage is that it has a higher accessing time.

2 Search Trees

A search tree is a more efficient approach to symbol table organization. We add two links, left and right, in each record, and these links point to the record in the search tree. Whenever a name is to be added, first the name is searched in the tree. If it does not exist, then a record for the new name is created and added at the proper position in the search tree. This organization has the property of alphabetical accessibility; that is, all the names accessible from namei will, by following a left link, precede name1 in alphabetical order. Similarly, all the name accessible from namei will follow namei in alphabetical order by following the right link (see Figure 2). The expected time needed to enter n names and to make m queries is proportional to (m + n) log2n; so for greater numbers of records (higher n) this method has advantages over linear list organization.

Click To expand
Figure 2: The search tree organization approach to a symbol table.

3 Hash Tables

A hash table is a table of k pointers numbered from zero to k1 that point to the symbol table and a record within the symbol table. To enter a name into symbol table, we find out the hash value of the name by applying a suitable hash function. The hash function maps the name into an integer between zero and k1, and using this value as an index in the hash table, we search the list of the symbol table records that is built on that hash index. If the name is not present in that list, we create a record for name and insert it at the head of the list. When retrieving the information associated with the name, the hash value of the name is first obtained, and then the list that was built on this hash value is searched for information about the name (Figure 3).

Click To expand
Figure 3: Hash table method of symbol table organization.

Other  
  •  Algorithms for Compiler Design: REPRESENTING THE SCOPE INFORMATION IN THE SYMBOL TABLE
  •  Algorithms for Compiler Design: ACTIVATION OF THE PROCEDURE AND THE ACTIVATION RECORD
  •  Algorithms for Compiler Design: STACK ALLOCATION
  •  Algorithms for Compiler Design: ERROR RECOVERY IN LR PARSING
  •  Algorithms for Compiler Design: PREDICTIVE PARSING ERROR RECOVERY
  •  Algorithms for Compiler Design: LOOP OPTIMIZATION
  •  Algorithms for Compiler Design: ELIMINATING INDUCTION VARIABLES
  •  Algorithms for Compiler Design: ELIMINATING LOCAL COMMON SUBEXPRESSIONS
  •  Algorithms for Compiler Design:
  •  Algorithms for Compiler Design
  •  Algorithms for Compiler Design: THE MACHINE MODEL
  •  Algorithms for Compiler Design: STRAIGHTFORWARD CODE GENERATION
  •  Algorithms for Compiler Design: USING DAG FOR CODE GENERATION
  •  Algorithms for Compiler Design: USING ALGEBRAIC PROPERTIES TO REDUCE THE REGISTER REQUIREMENT
  •  Algorithms for Compiler Design: PEEPHOLE OPTIMIZATION
  •  Algorithms for Compiler Design: IMPLEMENTATION OF THE TRANSLATIONS SPECIFIED BY SYNTAX-DIRECTED DEFINITIONS
  •  Algorithms for Compiler Design: L-ATTRIBUTED DEFINITIONS
  •  Algorithms for Compiler Design: SYNTAX-DIRECTED TRANSLATION SCHEMES
  •  Algorithms for Compiler Design: INTERMEDIATE CODE GENERATION
  •  Algorithms for Compiler Design: REPRESENTING THREE-ADDRESS STATEMENTS
  •  
    Top 10
    Installing the Exchange Server 2010 prerequisites
    Algorithms for Compiler Design:
    Business Intelligence in SharePoint 2010 with Business Connectivity Services : Consuming External Content Types (part 3) - Business Connectivity Services Web Parts
    Windows Azure : Static reference data (part 2) - Performance disadvantages of a chatty interface & Caching static data
    The Membership Data Store
    Optimizing an Exchange Server 2010 Environment - Analyzing and Monitoring Core Elements
    Algorithms for Compiler Design: IMPLEMENTATION in Bottom-up Parsing
    Collaborating Within an Exchange Server Environment Using Microsoft Office SharePoint Server 2007 : Customizing and Developing MOSS Sites
    Microsoft Malicious Software Removal Tool
    Modifying Display Appearance and Video Settings
    Most View
    BizTalk 2006 : Building a Resequencing Aggregator
    Windows Server 2008 : Transport-Level Security - Using IPSec Encryption with Windows Server 2008 R2
    Windows 7 : Understanding User Account Control and Its Impact on Performance
    Algorithms for Compiler Design: THE LR PARSER
    Port-Binding Shellcode
    Building Android Apps: Web SQL Database (part 4) - Deleting Rows
    Silverlight : Play a Video
    Windows Phone 7 Development : Understanding Trial and Full Modes (part 1) - Using the IsTrial Method
    iPhone Application Development : Understanding Interface Builder
    Server 2008 : Hardening Server Security
    Managing Local User Accounts and Groups in Vista
    Using Windows Phone 7 Technologies : Retrieving Accelerometer Data (part 1)
    iPhone Application Development : Creating User Interfaces
    Programming with DirectX : Textures in Direct3D 10 (part 1) - Textures Coordinates
    Installing SQL Server 2008
    Defensive Database Programming with SQL Server: The Ticket-Tracking System (part 2) - Removing the performance hit of ON UPDATE CASCADE
    Android’s Securable IPC Mechanisms
    Windows 7 :Navigating Your Computer with the Address Bar (part 1) - Accessing Locations on Your Computer
    Advanced ASP.NET : Component-Based Programming - The ObjectDataSource
    Windows 7 : Using Advanced Security Options (part 2) - Configuring Windows Defender