GATE Computer ScienceEasyGATE CS (PYQ pattern)
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 LR(1) but not SLR(1).
- A. I only
- B. I and III only
- C. II only
- D. I and IV only
Correct answer: A. I only
The string a c b has two parse trees (a S then S b, or S b then a S), so the grammar is ambiguous; ambiguous grammars are never LL(1) or LR(k).
More Compiler Design questions
- 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…
- For G: S → x S y | x y | S S, which statements are true? I. G is ambiguous. II. The canonical LR(1) table has more multiply-defined cells…