Refactor grammar and create AST