I'm trying to write a right linear context free grammar, in which the difference between numbers of 0's and 1's should be even. For example:
010001 = 4 - 2 = 2 (even)
I had a similar problem. Maybe it will help! I'm trying to write it on prolog. I did other 10 exercises but this is too difficult for me. Any ideas on how to do it?
my code
s --> [].
s --> [1],a.
s --> [0],b.
a --> [1],s.
a --> [0],c.
b --> [1],c.
b --> [0],s.
c --> [].
c --> [1],b.
c --> [0],a.
It's work for many cases but I'm not sure if it is well.