GATE CS 2021 (Forenoon) — Question 36

Compiler DesignSyntax-Directed Translation & Runtime EnvironmentsMCQ2 marks · −2/3 if wrongMedium

Consider the following grammar (that admits a series of declarations, followed by expressions) and the associated syntax directed translation (SDT) actions, given as pseudo-code: \(P \rightarrow D^* E^*\) \(D \rightarrow \text{int ID } \{\text{record that ID.lexeme is of type int}\}\) \(D \rightarrow \text{bool ID } \{\text{record that ID.lexeme is of type bool}\}\) \(E \rightarrow E_1 + E_2 \text{ } \{\text{check that } E_1.\text{type} = E_2.\text{type} = \text{int; set } E.\text{type} := \text{int}\}\) \(E \rightarrow !E_1 \text{ } \{\text{check that } E_1.\text{type} = \text{bool; set } E.\text{type} := \text{bool}\}\) \(E \rightarrow \text{ID } \{\text{set } E.\text{type} := \text{int}\}\) With respect to the above grammar, which one of the following choices is correct?
  1. A
    The actions can be used to correctly type-check any syntactically correct program.
  2. B
    The actions can be used to type-check syntactically correct integer variable declarations and integer expressions.
  3. C
    The actions can be used to type-check syntactically correct boolean variable declarations and boolean expressions.
  4. D
    The actions will lead to an infinite loop.
Practise the full 2021-FN paper
Challenge a friend: WhatsApp Telegram
Recommended book · affiliate linkCompilers: Principles, Techniques & ToolsThe "Dragon Book" for parsing, syntax-directed translation and code generation.
Practise more on Syntax-Directed Translation & Runtime EnvironmentsTimed, in the real exam interface · free to start

A GATE question every morning

One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.

Join
Stuck? Ask in the student group