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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
In case you wish to attend live classes with industry experts, please refer Geeks Classes Live