Simple lexer written in JavaScript