GATE Computer ScienceHardGATE CS (PYQ pattern)
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 are the productions used for reductions?
- A. 2, 3, 2, 1, 3, 4, 1
- B. 2, 3, 2, 3, 1, 4, 1
- C. 2, 3, 4, 2, 3, 1, 1
- D. 2, 2, 3, 3, 1, 4, 1
Correct answer: B. 2, 3, 2, 3, 1, 4, 1
x → S (2), S → L (3). Then , ( x ): x → S (2), S → L (3) inside the inner parentheses, ( L ) → S (1). Now the stack is ( L , S, so L , S → L (4), and finally ( L ) → S (1). This is the rightmost derivation in reverse.
More Compiler Design questions
- 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…
- Which of the following is/are true for the grammar S → a S | S b | c? I. It is ambiguous. II. It is LL(1). III. It is SLR(1). IV. It is…