Two derivation so it is ambiguous

Gammer is ambiguous. But above statement requires

Refer --> Option(A) for https://gateoverflow.in/711/gate2001-1-18

ping @kenzou

The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

+13 votes

- Remove left-recursion from the following grammar: $S \rightarrow Sa \mid Sb \mid a \mid b$
- Consider the following grammar:

$S \rightarrow aSbS\mid bSaS \mid ∊$

Construct all possible parse trees for the string abab. Is the grammar ambiguous?

+23 votes

Best answer

- $S \rightarrow aS'\mid bS'$

$S' \rightarrow aS' \mid bS' \mid \epsilon$

- $S \rightarrow aSbS \rightarrow abS \rightarrow abaSbS \rightarrow ababS \rightarrow abab$

$S \rightarrow aSbS \rightarrow abSaSbS \rightarrow abaSbS \rightarrow ababS \rightarrow abab$

The above two derivations corresponds to two different parse trees and hence the grammar is ambiguous.

0

Two derivation so it is ambiguous

Gammer is ambiguous. But above statement requires

Refer --> Option(A) for https://gateoverflow.in/711/gate2001-1-18

ping @kenzou

- All categories
- General Aptitude 1.4k
- Engineering Mathematics 5.9k
- Digital Logic 2.3k
- Programming & DS 4.3k
- Algorithms 3.7k
- Theory of Computation 4.6k
- Compiler Design 1.7k
- Databases 3.4k
- CO & Architecture 2.9k
- Computer Networks 3.4k
- Non GATE 1.2k
- Others 1.3k
- Admissions 506
- Exam Queries 482
- Tier 1 Placement Questions 22
- Job Queries 64
- Projects 16

40,927 questions

47,580 answers

146,433 comments

62,311 users