Prerequisite: Symbol Table
A Symbol table is a data structure used by the compiler, where each identifier in program’s source code is stored along with information associated with it relating to its declaration. It stores identifier as well as it’s associated attributes like scope, type, line-number of occurrence, etc.
Symbol table can be implemented using various data structures like:
- Hash Table
A common data structure used to implement a symbol table is HashTable.
Operations of Symbol table – The basic operations defined on a symbol table include:
Consider the following C++ function:
// Define a global function
int add(int a, int b)
int sum = 0;
sum = a + b;
Symbol Table for above code:
|a||int||function parameter||b||int||function parameter||sum||int||local|
Below is the C++ implementation of Symbol Table using the concept of Hashing with separate chaining:
**** SYMBOL_TABLE **** if inserted -successfully number inserted -successfully Identifier's Name:if Type:keyword Scope: local Line Number: 4 Identifier Is present if Identifier is deleted number Identifier updated Identifier's Name:number Type:variable Scope: global Line Number: 3 Identifier Is present
- Symbol Table in Compiler
- Lex program to implement a simple Calculator
- Program to implement Linear Extrapolation
- Program to implement Separate Chaining in C++ STL without the use of pointers
- Program to implement Run Length Encoding using Linked Lists
- YACC program to implement a Calculator and recognize a valid Arithmetic expression
- Implement a Dictionary using Trie
- How to Implement Forward DNS Look Up Cache?
- How to Implement Reverse DNS Look Up Cache?
- Implement a Phone Directory
- Sparse Table
- Construction of LL(1) Parsing Table
- Range sum query using Sparse Table
- Permutations to arrange N persons around a circular table
- Range maximum query using Sparse Table
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.