Lecture 3 Ambiguous and Unambiguous Grammar-1
Lecture 3 Ambiguous and Unambiguous Grammar-1
Unambiguous Grammar :
--Sakshi Surve
Ambiguity :
Ambiguous means Open to more than one
interpretation , Not having one obvious meaning
w = id + id x id
Now, let us write the rightmost derivations for this string w.
Solution-
Let us consider a string w generated by the given grammar-
w = abba
Now, let us draw parse trees for this string w.
Since two different parse trees exist for string w,
therefore the given grammar is ambiguous.
∑ = { a , b }
L = { w € L | w begins with a }
L = { a , aa, ab, aab, aba, aaa, ………}
S -> aA
A -> aA | bA | €
For ‘a’
Derivation of ‘a’
S aA
S a
a A
€
S -> aA
A -> aA | bA | €
For generating ‘aa’
S
a A
Derivation of ‘aa’
S aA
a A aaA
aa
€
S -> aA Derivation of ‘aba’
A -> aA | bA | € S aA
abA
For generating ‘aba’ abaA
S aba
b A V = {S, A}
T = { a,b }
a A
P
S= S
€
This is an example of Unambiguous Grammar
Example 6 :
Consider the following example :
S → aB / bA
A → aS / bAA / a
B → bS / aBB / b