Use the pumping lemma to prove this is not a context-free language.
Consider s = ap b2p cp
Then we consider vxy
, |vxy|<=p, |vy|>0
and uvixyiz in L
We have the possibilities
- vxy = aj, j<=p
- vxy = aj bk, j+k<=p
- vxy = bj, j<=p
- vxy = bj ck, j+k<=p
- vxy = cj, j <=p
In any case, there are no constants u
and v
s.t. the string is in L, because there can only be two symbols in vxy
and we would then need a variable amount of the third to show in up u
or v
Your proposed automata fails on AAAC, returning true. It doesn't guarantee that you have twice as many B's as A's.