%% A context-free grammar for strings with an equal number of 0's and 1's in any order. %% s -> 0 a | 1 b | lambda %% a -> 1 | 1s | 0aa This is the "You owe me a 1 rule" %% b -> 0 | 0s | 1bb This is the "You owe me a 0 rule" variable(s). variable(a). variable(b). terminal(0). terminal(1). rule(s, [0, a]). rule(s, [1, b]). rule(s, []). rule(a, [1]). rule(a, [1, s]). rule(a, [0, a, a]). rule(b, [0]). rule(b, [0, s]). rule(b, [1, b, b]).