Add basic structure and core function for generating the FSM; fix a bug in fixing path to end state;