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
- Program to implement Linear Extrapolation
- Lex program to implement a simple Calculator
- Program to implement Run Length Encoding using Linked Lists
- YACC program to implement a Calculator and recognize a valid Arithmetic expression
- Sparse Table
- How to Implement Reverse DNS Look Up Cache?
- Implement a Phone Directory
- How to Implement Forward DNS Look Up Cache?
- Range sum query using Sparse Table
- Summed Area Table - Submatrix Summation
- Permutations to arrange N persons around a circular table
- Compiler Design | Construction of LL(1) Parsing Table
- Range Minimum Query (Square Root Decomposition and 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 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.