Implement most of lexer and fix a few parser issues