Monday, 1 April 2019

UGC NET Computer Science July 2018 - II Question 36

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 ?

Options:
  1. (1) Only G1 is ambiguous
  2. (2) Only G2 is ambiguous
  3. (3) Both G1 and G2 are ambiguous
  4. (4) Both G1 and G2 are not ambiguous
Answer : (3) Both G1 and G2 are ambiguous

Explanation Question 36

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.

No comments:

Post a Comment

UGC NET Computer Science December 2019 | Question 16

Question 16 In a certain coding language. 'AEIOU' is written as 'TNHDZ'. Using the same coding language. 'BFJPV' wil...

Popular Posts