GATE Computer ScienceEasyGATE CS (PYQ pattern)
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 each match of a terminal is one move. How many moves does it make before reaching $ on both stack and input?
- A. 4
- B. 6
- C. 7
- D. 5
Correct answer: B. 6
4 expansions and 2 terminal matches (including expansions to ε) give 6 moves.
More Compiler Design questions
- 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…
- In the LL(1) table of S → A B C; A → a | ε; B → b | ε; C → c | ε, how many cells hold an ε-production, and how many cells of the column…