Introduction
Symbol table operations include inserting, searching, and deleting symbols. Data structure used for symbol tables include hash tables, binary search trees, and linked lists. The choice of data structure depends on the requirements of the application and the characteristics of the symbols being stored.
The main work of a compiler is to convert a program written in a source language(high-level) to a low-level language(Object or Machine Language). While converting the codes, the compiler does not change the logic of the code. Compiler Design is the set of principles that guide the translation, analysis, and optimization process. Since the compiler does various tasks while accessing variables and dynamically allocating memory, it requires a symbol table for convenience. Let us dive deeper into this!
Also see, Phases of Compiler
What is Symbol Table?
Symbol Table is a vital data structure created and maintained by the compiler to keep track of the semantics of variables. A symbol table stores information about the scope and necessary details on names and instances of several entities, like names of variables and functions, classes, objects, etc. Devices will have a challenging time determining addresses or understanding anything about the program if the symbol table has been stripped before the translation into an executable.
Also see Scope Information
Objectives of Symbol Table Operations and Data Structures
A symbol table serves the following objectives:
- It verifies whether a variable has been declared.
- It stores all entities' names in a structured form in a single place.
- It determines the scope of a name.
- It implements type checking by verifying whether the assignments and expressions in the source code are semantically correct or not.
- It may be included in a process output to be used later during debugging sessions.
- It serves as a resource for creating a diagnostic report during or after program execution.
Also Read - Symbol Table Operations ,hash function in data structure
Format of Symbol Table
A symbol table is simply a table which can be either linear or a hash table. Each item in the symbol table has properties like name, kind, type, and others, like the image added below.