Created
April 19, 2022 19:36
-
-
Save theAlgorithmist/325d602f379944f5d1de7ebde057b5b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* The current state of a machine with a given name | |
*/ | |
export interface FSMState | |
{ | |
name: string; | |
isAcceptance: boolean; | |
transition: string; | |
} | |
/** | |
* Define a state machine | |
*/ | |
export interface StateMachineDefinition | |
{ | |
name: string; | |
initialState?: string; | |
alphabet: Array<string>; | |
states: Array<FSMState>; | |
initialData?: object; | |
} | |
/** | |
* A State transition consists of a 'from' state, a 'to' state, and optional data of a specified type | |
*/ | |
export interface StateTransition<T> | |
{ | |
from: string; | |
to: string; | |
data?: T; | |
} | |
/** | |
* Output from a state transition is the 'to' state and optional data obtained from the transition function | |
*/ | |
export interface FSMStateOutput<T> | |
{ | |
to: string; | |
data?: T; | |
} | |
/** | |
* The transition function is Mealy-style, that is a transition to a new state is based on prior state and | |
* input data. Since state is optional in this interface, pass the state name as data and a Moore-style | |
* machine can be implemented. | |
*/ | |
export interface transFunction<T> | |
{ | |
(data: T, state?: string): FSMStateOutput<T>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment