add procedure to grammar; refactor grammar