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
    Magnetic Tape Storage - Data Storage For 30 Years
    NAD C546BEE – A Well-Built And Talented CD Player
    Optical Zoom: Better Than Digital?
    Retro Chic 1981 Minox 35 GT
    Through The Looking Glass (Part 2)
    Through The Looking Glass (Part 1)
    Pure Sensia 200D Connect – Internet Radio
    Samsung HW-E551 Soundbar - Convincing Cinema Sound
    Sansui CDD-201V – New Budget CD Player
    No Windows 7 Setup DVD Supplied With Your PC? No Problem!
    Most View
    iPad SDK : Popovers - The Font Size Popover
    Top 5 HD TVs
    Gorilla Gondola
    Windows 7 : Fine-Tuning the Settings for Windows Media Center
    Hashing Algorithms: Extending the .NET Framework (part 1)
    SQL Server 2008 : Explaining XML - XML Schema
    Visual Studio 2010 : Introducing the Visual Studio Extensibility - Building a Visual Studio Package
    Visual Studio 2010 : Understanding Solutions and Projects (part 3)
    Deploying the Client for Microsoft Exchange Server 2010 : Preparing the Deployment
    Implementing Security in Windows 7 : Delete Your Browsing History
    Exchange Server 2010 : Developments in High Availability (part 3) : Backup and restore
    The New iPad
    Choosing a super-zoom camera (part 5)
    Apple's Undiscovered Country : The Future Of The Ipad
    Understanding Application Domains
    Programming with DirectX : Projection Transformations
    IBM WebSphere Process Server 7 and Enterprise Service Bus 7 : Monitoring WPS/WESB applications
    Fujifilm Released The First Version Of CSC
    Microsoft SQL Server 2008 R2 : Using FILESTREAM Storage (part 1) - Enabling FILESTREAM Storage
    Publishing ASP.NET Web Applications : MSDeploy Publish