Compiler Design

Compiler Design Questions Answers GATE 2022

Compiler Design GATE Question Answers with Explanation.

Q1 – Which one of the following statements is TRUE? (GATE 2022)
1. The LALR(1) parser for a grammar G cannot have reduce-reduce conflict if the LR(1) parser for G does not have reduce-reduce conflict.
2. Symbol table is accessed only during the lexical analysis phase.
3. Data flow analysis is necessary for run-time memory management.
4. LR(1) parsing is sufficient for deterministic context-free languages.

Ans – (4)

Explanation –

Q2 – Consider the augmented grammar with {+, *, (, ), id} as the set of terminals.
S’ -> S
S -> S + R | R
R -> R* P | P
P -> (S) | id
If I0 is the set of two LR(0) items {[S’ -> S. ], [S -> S. + R]}, then goto(closure(I0 ), +) contains exactly __________ items. (GATE 2022)

Ans – (5) 

Explanation –

Q3 – Consider the following grammar along with translation rules.

CD Q65 GATE 2022

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 _____________. (GATE 2022)

Ans – (80)

Explanation –