

Scope ManagementĪ compiler maintains two types of symbol tables: a global symbol table which can be accessed by all the procedures and scope symbol tables that are created for each scope in the program. If the symbol exists in the symbol table, it returns its attributes stored in the table. This method returns 0 (zero) if the symbol does not exist in the symbol table.

The basic format should match the following: lookup(symbol) The format of lookup() function varies according to the programming language. if it is declared before it is being used.Lookup() operation is used to search a name in the symbol table to determine: Should be processed by the compiler as: insert(a, int) The insert() function takes the symbol and its attributes as arguments and stores the information in the symbol table.

This information contains the value, state, scope, and type about the symbol. The format or structure in which the names are stored depends upon the compiler in hand.Īn attribute for a symbol in the source code is the information associated with that symbol. This operation is used to add information in the symbol table about unique names occurring in the source code. This operation is more frequently used by analysis phase, i.e., the first half of the compiler where tokens are identified and names are stored in the table.

OperationsĪ symbol table, either linear or hash, should provide the following operations. A symbol table can be implemented in one of the following ways:Īmong all, symbol tables are mostly implemented as hash tables, where the source code symbol itself is treated as a key for the hash function and the return value is the information about the symbol. If a compiler is to handle a small amount of data, then the symbol table can be implemented as an unordered list, which is easy to code, but it is only suitable for small tables only. The attribute clause contains the entries related to the name. It maintains an entry for each name in the following format: įor example, if a symbol table has to store information about the following variable declaration: static int interest To determine the scope of a name (scope resolution).Ī symbol table is simply a table which can be either linear or a hash table. To implement type checking, by verifying assignments and expressions in the source code are semantically correct. To verify if a variable has been declared. To store the names of all entities in a structured form at one place. Symbol table is used by both the analysis and the synthesis parts of a compiler.Ī symbol table may serve the following purposes depending upon the language in hand: Symbol table is an important data structure created and maintained by compilers in order to store information about the occurrence of various entities such as variable names, function names, objects, classes, interfaces, etc.
