class documentation

class Automaton(Generic[State, Input, Output]): (source)

Constructor: Automaton(initial)

View In Hierarchy

A declaration of a finite state machine.

Note that this is not the machine itself; it is immutable.

Method __init__ Initialize the set of transitions and the initial state.
Method addTransition Add the given transition to the outputSymbol. Raise ValueError if there is already a transition with the same inState and inputSymbol.
Method allTransitions All transitions.
Method initialState.setter Set this automaton's initial state. Raises a ValueError if this automaton already has an initial state.
Method inputAlphabet The full set of symbols acceptable to this automaton.
Method outputAlphabet The full set of symbols which can be produced by this automaton.
Method outputForInput A 2-tuple of (outState, outputSymbols) for inputSymbol.
Method states All valid states; "Q" in the mathematical description of a state machine.
Method unhandledTransition All unhandled transitions will be handled by transitioning to the given error state and error-handling output symbols.
Property initialState Return this automaton's initial state.
Instance Variable _initialState Undocumented
Instance Variable _transitions Undocumented
Instance Variable _unhandledTransition Undocumented
def __init__(self, initial: State | None = None): (source)

Initialize the set of transitions and the initial state.

def addTransition(self, inState: State, inputSymbol: Input, outState: State, outputSymbols: tuple[Output, ...]): (source)

Add the given transition to the outputSymbol. Raise ValueError if there is already a transition with the same inState and inputSymbol.

def allTransitions(self) -> frozenset[tuple[State, Input, State, Sequence[Output]]]: (source)

All transitions.

@initialState.setter
def initialState(self, state: State): (source)

Set this automaton's initial state. Raises a ValueError if this automaton already has an initial state.

def inputAlphabet(self) -> set[Input]: (source)

The full set of symbols acceptable to this automaton.

def outputAlphabet(self) -> set[Output]: (source)

The full set of symbols which can be produced by this automaton.

def outputForInput(self, inState: State, inputSymbol: Input) -> tuple[State, Sequence[Output]]: (source)

A 2-tuple of (outState, outputSymbols) for inputSymbol.

def states(self) -> frozenset[State]: (source)

All valid states; "Q" in the mathematical description of a state machine.

def unhandledTransition(self, outState: State, outputSymbols: Sequence[Output]): (source)

All unhandled transitions will be handled by transitioning to the given error state and error-handling output symbols.

@property
initialState: State = (source)

Return this automaton's initial state.

_initialState: State = (source)

Undocumented

_transitions: set[tuple[State, Input, State, Sequence[Output]]] = (source)

Undocumented

_unhandledTransition: tuple[State, Sequence[Output]] | None = (source)

Undocumented