GATE Computer ScienceHardGATE CS (PYQ pattern)
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 always choosing Z → ε. Which of the strings w1 = i b t a, w2 = i b t a e a, w3 = i b t i b t a e a, w4 = i b t i b t a e a e a does the resulting parser accept?
- A. w1 and w2 only
- B. w1, w2 and w3 only
- C. all four strings
- D. w1 only
Correct answer: D. w1 only
With Z → ε chosen on lookahead e, no Z ever consumes an e. After the innermost S is parsed, every pending Z on the stack is popped as ε while e is still the lookahead, and finally $ meets e: an error. So any string containing e is rejected; only w1 is accepted. (Choosing Z → e S instead accepts all four, binding each else to the nearest then.)
More Compiler Design questions
- 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…
- Consider the grammar G with productions S → A B C; A → a | ε; B → b | ε; C → c | ε. Which of the following statements is/are true? I. G is…
- int x = 1; int g() { x = x + 1; return x; } int f(int n) { int x = n; if (n == 0) return g(); int r = f(n − 1); return r + g(); } What…
- The standard algorithm removes all left recursion from S → A a | b; A → A c | S d | e, taking the non-terminals in the order S, A…
- int i = 1; int A[0..2] = {5, 6, 7}; void f(x, y) { x = x + 1; y = 10; } The call f(i, A[i]) uses copy-in/copy-out (value-result), copying…