refactoring collecting of grammar symbols