Reimplementing parser from scratch