Question
Consider the following statements.
: Every SLR(1) grammar is unambiguous but there are certain unambiguous grammars that are not SLR(1).
: For any context-free grammar, there is a parser that takes at most time to parse a string of length .
Which one of the following options is correct?
Official answer and solution
- Official answer
- C
- From
- Official GATE 2021 answer key
Solution
Recall properties of SLR(1) parsing and universal parsing algorithms for general CFGs.
Statement : By definition, any LR (including SLR(1)) parser deterministically constructs a unique rightmost derivation in reverse for any valid string, so every SLR(1) grammar is unambiguous. Furthermore, there are unambiguous grammars that are not SLR(1) (e.g., LR(1) or LALR(1) grammars containing SLR conflicts). Hence is true.
Statement : General CFG parsing algorithms such as the CYK (Cocke-Younger-Kasami) algorithm and Earley's algorithm can parse any arbitrary context-free grammar in at most time for a string of length . Hence is true.
Because both and are true, option C is correct.
C
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2021 Computer Science and Information Technology (CS, Set-1)
- Question
- 15 of 65, printed as CS Q.5
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.