GateAI
Parsing

GATE CSE 2021 Set 1 · Q5

MCQ1 markMedium

Time

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)O(n^3) time to parse a string of length nn. Which one of the following options is correct?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: C) S1 is true and S2 is true

Parsing

Let us analyze both statements:

  1. Statement S1S_1:

    • All LR(k)\text{LR}(k) grammars (including SLR(1)\text{SLR}(1)) are deterministic and therefore unambiguous.

    • However, the class of SLR(1)\text{SLR}(1) grammars is a strict subset of unambiguous context-free grammars (for instance, LR(1)\text{LR}(1) or LALR(1)\text{LALR}(1) grammars that are not SLR(1)\text{SLR}(1), as well as unambiguous grammars that are not deterministic). Thus, there are unambiguous grammars that are not SLR(1)\text{SLR}(1).

    • Therefore, S1S_1 is true.

  2. Statement S2S_2:

    • General context-free parsing algorithms such as the CYK (Cocke-Younger-Kasami) algorithm or Earley's parser can parse any arbitrary context-free grammar for a string of length nn in at most O(n3)O(n^3) worst-case time.

    • Therefore, S2S_2 is true.

Since both S1S_1 and S2S_2 are true, option (C) is the correct choice.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Parsing previous year question is Q5 of the GATE CSE 2021 Set 1 paper. Find more GATE CSE PYQs on Parsing in Compiler Design, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Parsing PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Parsing in GATE CSE

Parsing has 23 GATE CSE PYQs across 16 papers from 2012 to 2026. 5 of them are 1-mark MCQs like this one, and it is the only one in GATE CSE 2021 Set 1.

How GATE tests Parsing

More from GATE CSE 2021 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2021 Set 1 · Q5 · MCQ

Consider the following statements. S1 : Every SLR(1) grammar is unambiguous but there are certain unambiguous grammars that are not SLR(1). S2 : For any context-free grammar, there is a parser that takes at most O(n3) time to parse a string of length n. Which one of the following options is correct?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.