GATE Computer ScienceHardGATE CS (PYQ pattern)
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 item is S → c · is the merge of how many canonical LR(1) states, and what is its lookahead set?
- A. 3 states; {a, b, $}
- B. 2 states; {a, b}
- C. 3 states; {a, b}
- D. 1 state; {a, b, $}
Correct answer: A. 3 states; {a, b, $}
c can be the whole sentence (lookahead $), the middle of a…a (lookahead a) or of b…b (lookahead b). Each context reaches S → c· through a different LR(1) state, so three LR(1) states merge into one LALR state with lookaheads {a, b, $}.
More Compiler Design questions
- 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 →…
- A Pascal-like scanner uses longest match (ties to the earlier rule) with rules: FLOAT = [0-9]+.[0-9]; INT = [0-9]+; RANGE = ..; DOT =…
- SDD: S → ( S S ) | a. S.d is inherited: root d = 0, children get parent.d + 1. For a → a: S.v = S.d if S.d is even, otherwise −S.d. For S…