S S / | \ / | \ S or S S and S / | \ | | / | \ S and S r p S or S | | | | p q q r
S -> T implies S | T T -> T or U | U U -> U and V | V V -> p | q | r | (S)
S S / \ / \ S S S S / \ /|\ /|\ / \ S S ( S ) ( S ) S S /|\ /|\ | | /|\ /|\ ( S )( S ) ( S )( S ) | | | |
S -> lambda | ( S ) S
We prove now G is not ambiguous. By structural induction: Consider a string x in L(G). We have two cases:
S // | \ ( S ) S | | ty tz
S -> a b b | a S b b
We prove now that L(G) = L where L = {anb2n | n > 0}
S -> T U T -> lambda | a T b U -> lambda | b U c
We show now that L(G) = L, where L = {akbmcn | m = k + n}.
Let G1 be the subgrammar with productions
T -> lambda | a T band let G2 be the subgrammar with productions
U -> lambda | b U cClearly, L(G) = L(G1)L(G2). In fact, x is in L(G) iff S -> T U ->* x, but this is possible iff there exist y, z such that T ->* y, U ->* z, and x = y z.
Let L1 be the language {akbk | k >= 0} , and let L2 be the language {bncn | n >= 0}. We are going to show that L(G1) = L1 and L(G2) = L2. Since L = L1L2, we can conclude that L(G) = L.