GATE Computer ScienceModerateGATE CS (PYQ pattern)
For the production A → B C D (A.i, B.i, C.i, D.i inherited; A.s, B.s, C.s, D.s synthesised), which rule set makes the SDD L-attributed?
- A. B.i = A.i; C.i = D.s; A.s = C.s
- B. C.i = B.s; D.i = C.i + B.i; A.s = D.s
- C. B.i = A.i; D.i = A.s + C.s; A.s = B.s
- D. C.i = A.i; B.i = C.i; A.s = B.s + C.s
Correct answer: B. C.i = B.s; D.i = C.i + B.i; A.s = D.s
L-attributed: an inherited attribute of a child may use only the parent's inherited attributes and attributes of children to its left. C.i = B.s and D.i = C.i + B.i use left siblings only, and A.s may use anything. C.i = D.s uses a right sibling; D.i = A.s uses the parent's synthesised attribute (which is computed after D); B.i = C.i uses a right sibling.
More Compiler Design questions
- Productions are numbered (1) S → ( L ); (2) S → x; (3) L → S; (4) L → L , S. A shift-reduce parser parses "( x , ( x ) )". In which order…
- A table-driven LL(1) parser for S → A B C; A → a | ε; B → b | ε; C → c | ε parses "a c". Each pop of a non-terminal (expanding it) and…
- For G: S → a E c | a F d | b F c | b E d; E → e; F → e, what is the smallest k for which G is LL(k), and is G LALR(1)?
- Live-variable analysis is used to find dead assignments (target not live immediately after the statement) in 1: x = a + b; 2: if c > 0…
- A DAG is built for the basic block x = a b; y = b a; z = x + y; a = z − x; w = a b; v = y + x (+ and commutative, a new leaf for each…
- In the LL(1) table of S → i E t S Z | a; Z → e S | ε; E → b the only multiply-defined cell is M[Z, e]. A parser generator resolves it by…