Question
Consider the following statements.
I. Symbol table is accessed only during lexical analysis and syntax analysis.
II. Compilers for programming languages that support recursion necessarily need heap storage for memory allocation in the run-time environment.
III. Errors violating the condition 'any variable must be declared before its use' are detected during syntax analysis.
Which of the above statements is/are TRUE?
Official answer and solution
- Official answer
- D
- From
- Official GATE 2020 answer key
Solution
Analyze each statement in terms of compiler phases, symbol table usage, run-time environments, and semantic checking.
Statement I: 'Symbol table is accessed only during lexical analysis and syntax analysis.'
- The symbol table is a central data structure used throughout almost every compiler phase. Semantic analysis uses it to perform type checking and scope resolution; intermediate code generation uses it for address assignment; and code optimization/generation use it for register allocation and memory layouts.
- Hence, the symbol table is not accessed only during lexical and syntax analysis. Statement I is FALSE.
Statement II: 'Compilers for programming languages that support recursion necessarily need heap storage for memory allocation in the run-time environment.'
- Recursion requires a call stack (activation records pushed on call and popped on return) adhering to LIFO discipline.
- Heap storage is required only for dynamic memory allocation whose lifetime is independent of the call stack (e.g., manual allocation with malloc/new). Languages with recursion but without dynamic memory require only a stack, not a heap.
- Therefore, heap storage is not strictly necessary for recursion. Statement II is FALSE.
Statement III: 'Errors violating the condition any variable must be declared before its use are detected during syntax analysis.'
- Syntax analysis checks grammatical structure according to context-free grammar rules.
- Enforcing that an identifier is declared before its use is a context-sensitive requirement, checked during semantic analysis via symbol table lookups.
- Thus, this error is detected during semantic analysis, not syntax analysis. Statement III is FALSE.
Since all three statements are false, the correct answer is 'None of I, II, and III'.
D
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2020 Computer Science and Information Technology (CS)
- Question
- 19 of 65, printed as CS Q.9
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.