- Get link
- X
- Other Apps
Which ONE of the following statements is FALSE regarding the symbol table?
The correct answer is option (C) Symbol table is not required after the parsing phase. This statement is false.
The symbol table is a crucial data structure used throughout multiple phases of compilation, not just during parsing. It is heavily relied upon by the semantic analyzer for type checking and scope resolution, and by the code generator for allocating memory and retrieving variable addresses. Therefore, the statement that it is not required after parsing is definitively false.
To understand why option (C) is false, let's look at the role of the symbol table across the phases of a compiler.
What is a Symbol Table?
A symbol table is a data structure used by a compiler to store information about various source code entities like variable names, function names, constants, and labels. The stored information typically includes the entity's type, scope, and memory location.
Interaction with Compiler Phases
The symbol table acts as a central database that is accessed and updated by almost all phases of the compiler.
Analysis of Each Statement:
- (A) Symbol table is responsible for keeping track of the scope of variables. This is TRUE. This is a fundamental purpose of the symbol table. It records the scope in which a variable is declared to enforce visibility rules (e.g., a variable declared inside a function is not visible outside it).
- (B) Symbol table can be implemented using a binary search tree. This is TRUE. While hash tables are very popular for their O(1) average lookup time, other data structures like linked lists and binary search trees are also valid implementations. A BST could be useful if there is a need to list identifiers in alphabetical order.
- (D) Symbol table is created during the lexical analysis phase. This is TRUE. The process begins here. The lexical analyzer identifies identifiers (tokens) and passes them to the parser. The parser and semantic routines then work together to insert these identifiers and their attributes (like type, scope) into the symbol table.
- (C) Symbol table is not required after the parsing phase. This is FALSE. The parsing (or syntax analysis) phase primarily checks the grammatical structure of the code. The phases that follow rely heavily on the symbol table:
- Semantic Analysis: Uses the symbol table to check for type mismatches (e.g., trying to add an integer to a string), undeclared variables, and scope violations.
- Code Generation: Uses the symbol table to look up the memory address or offset assigned to each variable to generate the final machine code or assembly code.
- Optimization: May use information from the symbol table to perform certain optimizations.
- Aho, A. V., Lam, M. S., Sethi, R., & Ullman, J. D. (2006). Compilers: Principles, Techniques, and Tools (2nd ed.). Pearson/Addison Wesley. (Often called the "Dragon Book"). Chapter 2 and 7.
- Get link
- X
- Other Apps
Comments
Post a Comment
Ask you doubt here