Question

Consider the following statements.

S1S_1: Every SLR(1) grammar is unambiguous but there are certain unambiguous grammars that are not SLR(1).

S2S_2: For any context-free grammar, there is a parser that takes at most O(n3)\mathcal{O}(n^3) time to parse a string of length nn.

Which one of the following options is correct?

Choose one option
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 S1S_1: 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 S1S_1 is true.

Statement S2S_2: 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 O(n3)\mathcal{O}(n^3) time for a string of length nn. Hence S2S_2 is true.

Because both S1S_1 and S2S_2 are true, option C is correct.

Final answer

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.