Consider the following grammar S-> PQ P-> aP | b Q-> bQ | a Consider the…

Consider the following grammar

S-> PQ

P-> aP | b

Q-> bQ | a

Consider the following statements.

S1: The grammar has different LMD and RMD for string abba.

S2: The grammar is ambiguous.

Select the correct option.

Answer: C. S1 is true but S2 is falseThe grammar has different LMD and RMD for string "abba". LMD: S -> PQ -> aPQ -> abQ -> abbQ -> abba RMD: S -> PQ -> PbQ -> Pba -> aPba -> abba The grammar is…

  1. A.

    Both S1 and S2 are true

  2. B.

    Both S1 and S2 are false

  3. C.

    S1 is true but S2 is false

  4. D.

    S1 is false but S2 is true

Attempted by 56 students.

Show answer & explanation

Correct answer: C

The grammar has different LMD and RMD for string "abba".
LMD: S -> PQ -> aPQ -> abQ -> abbQ -> abba
RMD: S -> PQ -> PbQ -> Pba -> aPba -> abba
The grammar is LL(1) so it cannot be ambiguous.

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…