Lexer state machine