Finite-state machine builder