Question:medium

Consider the following statements.
\[ S_1:\ \text{Every SLR(1) grammar is unambiguous but there are certain unambiguous grammars that are not SLR(1).} \] \[ S_2:\ \text{For any context-free grammar, there is a parser that takes at most } O(n^3) \text{ time to parse a string of length } n. \] Which one of the following options is correct?

Show Hint

All LR grammars are unambiguous, but the converse is not true. General CFG parsing can always be done in polynomial time.
Updated On: Jan 30, 2026
  • $S_1$ is true and $S_2$ is false
  • $S_1$ is false and $S_2$ is true
  • $S_1$ is true and $S_2$ is true
  • $S_1$ is false and $S_2$ is false
Show Solution

The Correct Option is C

Solution and Explanation

Step 1: Analyze Statement S1.
SLR(1) grammars form a proper subclass of LR grammars. Since LR parsers generate a unique rightmost derivation in reverse, all LR (and hence SLR(1)) grammars are unambiguous.

However, the converse is not true. There exist grammars that are unambiguous but do not satisfy the stricter FOLLOW-set conditions required for SLR(1) parsing.

Therefore, there exist unambiguous grammars that are not SLR(1), making statement S1 true.


Step 2: Analyze Statement S2.
For arbitrary context-free grammars, general parsing algorithms are available.

Algorithms such as the CYK (Cocke–Younger–Kasami) algorithm and Earley’s parser can parse any context-free grammar in O(n³) time in the worst case, where n is the length of the input string.

Hence, S2 is also true.


Final Conclusion:
Since both statements S1 and S2 are true, the correct option is:

Final Answer: (C)

Was this answer helpful?
0