Question Details

Consider the following grammar: S → aSbS | bS | ϵ. Which of the following is true?

Options

A

Grammar is ambiguous

B

abab is having only one parse tree

C

abb is ambiguous string

D

None of these

Show Answer

Correct Answer :

Option A

Grammar is ambiguous

Solution :

The correct option is: Grammar is ambiguous.

A grammar is defined as ambiguous if there exists at least one string in its language that has more than one leftmost derivation, more than one rightmost derivation, or more than one distinct parse tree.

Let us consider the given grammar rules:
S → aSbS | bS | ϵ

To prove that the grammar is ambiguous, we can demonstrate that a simple string generated by this grammar, such as "ab", has more than one distinct parse tree (or leftmost derivation).

Let's derive the string "ab" using two different leftmost derivations:

Leftmost Derivation 1:
S ⇒ aSbS (using S → aSbS)
S ⇒ a(ϵ)bS (replacing the first S with ϵ)
S ⇒ abS
S ⇒ ab(ϵ) (replacing S with ϵ)
S ⇒ ab

Leftmost Derivation 2:
S ⇒ aSbS (using S → aSbS)
S ⇒ aSb(ϵ) (replacing the second S with ϵ)
S ⇒ aSb
S ⇒ a(ϵ)b (replacing S with ϵ)
S ⇒ ab

Since the string "ab" can be derived using two distinct leftmost derivations, it has two distinct parse trees. Therefore, the grammar is ambiguous.

Unlock Our Free Library

Access expert-curated educational resources and study materials—completely free.

Ask AI Tutor
5 left
Q1 View Question & Options
AI Tutor is solving this question...
Reading question context & options...