Refactoring the grammar definition