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 ?
Answer : (3) Both G1 and G2 are ambiguous G1 : S → SbS|a
G2 : S → aB|ab, A→GAB|a, B→ABb|b
Which of the following option is correct ?
Solution:
Both G1 and G2 are ambiguous
As both grammars have two derivations for same string:
G1 : S → SbS|a
Grammer G1 Derivation-1:
S → SbS
SbSbS
ababa
Grammer G1 Derivation-2:
S → SbS
SbSbS
ababa
G2 : S → aB|ab, A→AB|a, B→ABb|b
Grammer G2 Derivation-1:
S → aB
aABb
aABBb
aABABbb
aababbb
Grammer G2 Derivation-2:
S → aB
aABb
aAABbb
aABABbb
aababbb
Both G1 and G2 are ambiguous as both grammars have two derivations for same string as shown in above.
So, Option (3) is correct answer.