GATE / CS ARCHIVE

GATE CSE 2020 / QUESTION 9

GATE CSE 2020 Q9

Compiler Design · Compiler Phases, Linking & Loading · Full GATE CSE 2020 paper

GATE 2020, Q9 1 mark · MCQ
Report issue

Compiler Phases, Linking & Loading

Question 9, GATE 2020: Test I: symbol tables are accessed only in lexical and syntax analysis. II: supporting recursion necessarily requires heap allocation. III: declaration-before-use errors are detected during syntax analysis. Options: A I only; B I and III; C II only; D none.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Worked explanation

A symbol table records information such as declarations, types and locations. Type checking needs that information in semantic analysis, and code generation may need offsets and storage locations, so “only” makes I false. Recursive calls need distinct activation records, but their last-in-first-out lifetimes are exactly what a runtime stack handles; a heap is not logically necessary. Finally, syntax checks whether token sequences fit grammatical productions, whereas whether a particular name has already been declared depends on the binding environment. That contextual condition belongs to semantic analysis in the conventional compiler-phase distinction used here.

Derivation and answer

Semantic analysis and code generation also consult symbol-table information, refuting I. Ordinary nested recursion can be supported with stack activation records and does not inherently need a heap, refuting II. Declaration-before-use is a contextual semantic condition, not ordinary context-free syntax checking, refuting III. Thus none, D.

Original paper, page 5 · Answer key