generic state-machine lexer in c