implementation of a context-free grammar, and the change to the CNF