refactor grammar to introduce lr parser