Exams › GATE › Technical
Consider the following statements. S1: Every SLR(1) grammar is unambiguous, but there are certain unambiguous grammars that are not SLR(1). S2: For every grammar, there is a parser that takes at most linear time to parse a string of length $n$. Which of the following is correct?
- S1 is true and S2 is true
- S1 is true and S2 is false
- S1 is false and S2 is true
- S1 is false and S2 is false
Correct answer: S1 is true and S2 is true
Solution
SLR(1) grammars are indeed unambiguous, and there exist unambiguous grammars that are not SLR(1). Also, for any grammar, parsing can be done in linear time using suitable parser constructions for the fixed grammar. Hence both statements are true.
Related GATE Technical questions
⚔️ Practice GATE Technical free + battle 1v1 →