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 CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Symbol Table in Compiler
- Various implementations of Symbol Table
- Program to implement Linear Extrapolation
- Program to implement Run Length Encoding using Linked Lists
- Lex program to implement a simple Calculator
- YACC program to implement a Calculator and recognize a valid Arithmetic expression
- Program to implement Separate Chaining in C++ STL without the use of pointers
- How to Implement Reverse DNS Look Up Cache?
- How to Implement Forward DNS Look Up Cache?
- Implement a Phone Directory
- Implement a Dictionary using Trie
- How to implement text Auto-complete feature using Ternary Search Tree
- Range Minimum Query (Square Root Decomposition and Sparse Table)
- Summed Area Table - Submatrix Summation
- Permutations to arrange N persons around a circular table
- Sparse Table
- Range sum query using Sparse Table
- Construction of LL(1) Parsing Table
- Range maximum query using Sparse Table
- C program to detect tokens in a C program
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.