Skip to content

Instantly share code, notes, and snippets.

@theAlgorithmist
Created April 19, 2022 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theAlgorithmist/325d602f379944f5d1de7ebde057b5b9 to your computer and use it in GitHub Desktop.
Save theAlgorithmist/325d602f379944f5d1de7ebde057b5b9 to your computer and use it in GitHub Desktop.
/**
* 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