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.2k
- Engineering Mathematics 5k
- Digital Logic 2k
- Programming & DS 3.6k
- Algorithms 3.1k
- Theory of Computation 3.9k
- Compiler Design 1.5k
- Databases 2.9k
- CO & Architecture 2.5k
- Computer Networks 2.9k
- Non GATE 1k
- Others 1.4k
- Admissions 412
- Exam Queries 419
- Tier 1 Placement Questions 17
- Job Queries 55
- Projects 9

34,942 questions

41,951 answers

119,194 comments

41,470 users