add bnf grammar and refactoring of structure