Let's suppose I want to put an equal number of P balls and D balls in a box. The last ball must always be a D, and the number of D balls in the box can never be greater than the number of P balls.I want to present a context free grammar. Until now I have come with:
S → ε | PS | DS |
But it does not cover cases in which D is bigger than P. I also tried:
S → PSD | ɛ
But like that you can't have patterns like: PDPD, only like PPDD, you can't interleave the P's and D's that wayI would appreciate some help. Thanks.