beginning of the terminal bnf parser implementation