Problem 2
a) baab
Consider leftmost derivation : <S> => <A>a<B>b => ba<B>b => baab
d) bbaab
Consider leftmost derivation : <S> =><A>a<B>b => <A>ba<B>b => bba<B>b => bbaab
b) and c) are not part of this grammar
Problem 1)
A grammar is abmiguous if it produces atleast two different derivation of any language accepted by it.
Now, consider a language A = A*B+C
Consider Left Most Derivation
A = A*B+C
=> <id> = A*B+C
=> <id> = <id>*B+C
=> <id> = <expr> * B + C
=> <id> = <expr> * <id> +C
=> <id> = <expr> * <expr> + C
=> <id> = <expr> + C
=> <id> = <expr> + <id>
=> <id> = <expr> + <expr>
=> <id> = <expr>
=> <assign>
Now, consider rightmost derivation
A= A* B + C
=> A= A*B+ <id>
=>A=A*B+<expr>
=> A=A*<id>+<expr>
=> A = A * <expr> +<expr>
=> A= A* <expr>
=> A = <id> * <expr>
=> A = <expr> * <expr>
=> A = <expr>
=> <id> = <expr>
=> <assign>
Hence, grammar is ambiguous as atleast two different derivation exist for a language. Above example states that a expression 5*4+6, will be treated both as (5*4)+6 and 5*(4+6). Therefore grammar is ambiguous.