I'm stuck on this question. I'm struggling on how to keep track of the number of a and d I have generated.
The professor hasn't given the correction.
I have seen similar questions but the condition is different, I can't find the grammar. Is it possible to prove that it is not context free?
EDIT: taking inspiration from other slightly similar solved question, here's my solution, but I think it could be factorized/improved
S -> S1 | S2 // S1 is the case where I will try to pair a with c (i.e when there more c than d), S2 is the case where I will try to pair d with b (i.e when there are more b than a) S1 -> XY X -> aXc | Z // for each a generate a c Z -> aZb | epsilon // for each a generate a b Y -> cYd | epsilon // for each d generate c // since all the b's have been generated along with a's, i did not find a way to pair d's with b's S2 -> UV U -> aUb | epsilon V -> bVd | W W -> cWd | epislon