complete the ContextFreeGrammar class