GATE Computer ScienceEasyGATE CS (PYQ pattern)
For the grammar S → X Y Z; X → a X | ε; Y → b Y | X; Z → c | ε, what is FIRST(S)? (ε counts as a member if S is nullable.)
- A. {$, a, b, c, ε}
- B. {a, b, c}
- C. {a, b, ε}
- D. {a, b, c, ε}
Correct answer: D. {a, b, c, ε}
S → X Y Z with X, Y and Z all nullable (Y can derive X, which can derive ε, and Z → ε), so FIRST(S) collects a, b, c and also ε.
More Compiler Design questions
- The statement r = (a + b) (b + a) − (a + b) / c is turned into a DAG (+ and commutative, − and / not), and three-address code is generated…
- For S′ → S; S → a S a | b S b | c, the canonical LR(1) states with identical cores are merged to obtain LALR(1). The LALR state whose only…
- Which of the following about intermediate representations is/are true? I. In triples, an operand that is a result of another statement is…
- Backpatching with no fall-through optimisation, numbering from 100, for: if (!(p < q)) x = 1; while (i < n) { if (a < b || c < d) k = k +…
- An LR parser for E → id | E [ E ] | ( E ) parses "( id ) [ id ]". Each shift and each reduce is one move (the final accept is not a move)…
- SDD: S → ( S S ) | a. Inherited attribute S.d: the root has S.d = 0 and each child of a node gets parent.d + 1. Synthesised S.v: for a →…