GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Productions of the grammar are numbered: (1) E → E + T; (2) E → T; (3) T → T * F; (4) T → F; (5) F → ( E ); (6) F → id. An LR parser parses "id * ( id + id ) * id". In which order are the productions used for reductions (first reduction first)?
- A. 2, 3, 3, 4, 6, 5, 1, 2, 4, 6, 4, 6, 6
- B. 2, 3, 6, 3, 5, 1, 4, 6, 2, 4, 6, 4, 6
- C. 6, 4, 6, 4, 2, 6, 4, 1, 5, 3, 6, 3, 2
- D. 6, 6, 4, 6, 4, 2, 1, 5, 6, 4, 3, 3, 2
Correct answer: C. 6, 4, 6, 4, 2, 6, 4, 1, 5, 3, 6, 3, 2
A bottom-up parser reduces the handles of a rightmost derivation in reverse; the production numbers in reduction order are 6, 4, 6, 4, 2, 6, 4, 1, 5, 3, 6, 3, 2. Preorder of the tree gives the leftmost derivation instead.
More Compiler Design questions
- In 1: i = 0; 2: L1: if i >= n goto L3; 3: if i > k goto L2; 4: t = a b; 5: x = t + 1; 6: L2: y = a + b; 7: i = i + 1; 8: goto L1; 9: L3…
- 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.)
- 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 +…