Monday 7 December 2015

Q63,p3,j15. Given the following grammar.

A->aA|ε.
B->bB/ε.
G1: S->AB|aaB.
G2:S->A|B.
A->aAb|ab.
B->abB|ε.
Which is correct.
options.
A) G1 is ambigious and G2 is unambigious.
B)G1 is unambigious and G2 is ambigious.
C) Both are ambigious.
D) Both are unambigious.

Answer C.

Explanation.
Let the string is aab.
it can be derived by.
S->AB->aAB->aaAB->aaεB->aaεbB->aaεbε.
and
we can derive in this way also.
S->aaB->aabB->aabε.
G1 is ambigious because we have two different tree structure.

Similarly G2.
let w=ab.
then S->A->ab.
and
S->B->abB->abε.
so we get two tree for a same string. so G2 is also ambigious.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.