State machine based parser