GATE CS 2022 (Forenoon) — Question 65

Compiler DesignSyntax-Directed Translation & Runtime EnvironmentsNAT2 marksHard

Consider the following grammar along with translation rules. \(S \rightarrow S_1 \# T\) \{S.val = S_1.val * T.val\} \(S \rightarrow T\) \{S.val = T.val\} \(T \rightarrow T_1 \% R\) \{T.val = T_1.val \div R.val\} \(T \rightarrow R\) \{T.val = R.val\} \(R \rightarrow \text{id}\) \{R.val = id.val\} Here \# and \% are operators and id is a token that represents an integer and id.val represents the corresponding integer value. The set of non-terminals is \(\{S, T, R, P\}\) and a subscripted non-terminal indicates an instance of the non-terminal. Using this translation scheme, the computed value of S.val for root of the parse tree for the expression 20#10%5#8%2%2 is __________.
Practise the full 2022-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