refactor lexical analyzer