refactor grammar for easier integration into parser.