refactoring grammar parser