UGC-NET | UGC NET CS 2018 July – II | Question 36
Consider the following two Grammars :
G1 : S → SbS|a
G2 : S → aB|ab, A→GAB|a, B→ABb|b
Which of the following option is correct ?
(A) Only G1 is ambiguous
(B) Only G2 is ambiguous
(C) Both G1 and G 2are ambiguous
(D) Both G1 and G2are not ambiguous
Explanation: A grammar is said to be ambiguous if we can generate more than one parse for same given string.
Here both Grammar G1 and G2 are ambiguous as For G1 we can generate more than one parse tree for the same string “ababa”.
Since G1 is ambiguous and for G2 we can also generate more than one parse the for the string ” ab ” since G2 is also ambiguous.
Option (C) is correct.
Quiz of this Question