UGC-NET | UGC NET CS 2015 Jun – III | Question 63
Given the following grammars:
G1: S → AB|aaB
A → aA | ∈
B → bB | ∈
G2: S → A|B
A → aAb | ab
B → abB | ∈
Which of the following is correct?
(A)
G 1 is ambiguous and G 2 is unambiguous grammars
(B)
G 1 is unambiguous and G 2 is ambiguous grammars
(C)
both G 1 and G 2 are ambiguous grammars
(D)
both G 1 and G 2 are unambiguous grammars
Answer: (C)
Explanation:
G1: S → AB|aaB
A → aA | ∈
B → bB | ∈
Let\’s generate aab
S → aaB
S → aabB
S → aab. one way
S → AB
S → aAB
S → aaAB
S → aaB
S → aabB
S → aab another way.
G1 is ambiguous because we can generate same string by two different ways.
G2: S → A|B
A → aAb | ab
B → abB | ∈
Let\’s generate ab.
S → A
A → aAb
A → ab. One way.
S → B
B → abB
B → ab. another way.
G2 is ambiguous because we can generate same string by two different ways.
So, option (C) is correct.
Quiz of this Question
Please comment below if you find anything wrong in the above post
Last Updated :
10 Nov, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...