Skip to content

class PDA(Automaton, metaclass=ABCMeta)

Classes and methods for working with all pushdown automata.

PDA

Bases: Automaton

An abstract base class for pushdown automata.

iter_transitions() abstractmethod

Iterate over all transitions in the automaton. Each transition is a tuple of the form (from_state, to_state, (input_symbol, stack_top_symbol, stack_push_symbols))

show_diagram(input_str=None, with_machine=True, with_stack=True, path=None, *, layout_method='dot', horizontal=True, reverse_orientation=False, fig_size=None, font_size=14.0, arrow_size=0.85, state_separation=0.5)

Generates the graph associated with the given PDA. Args: - input_str (str, optional): String list of input symbols. Defaults to None. - with_machine (bool, optional): Constructs the diagram with states and transitions. Ignored if input_str is None. Default to True. - with_stack (bool, optional): Constructs the diagram with stack and its operations. Ignored if input_str is None. Default to True. - path (str or os.PathLike, optional): Path to output file. If None, the output will not be saved. - horizontal (bool, optional): Direction of node layout. Defaults to True. - reverse_orientation (bool, optional): Reverse direction of node layout. Defaults to False. - fig_size (tuple, optional): Figure size. Defaults to None. - font_size (float, optional): Font size. Defaults to 14.0. - arrow_size (float, optional): Arrow head size. Defaults to 0.85. - state_separation (float, optional): Node distance. Defaults to 0.5. Returns: AGraph corresponding to the given automaton.

validate()

Raises an exception if this automaton is not internally consistent.

Raises:

Type Description
InvalidStateError

If this PDA has invalid states in the transition dictionary.

MissingStateError

If this PDA has states missing from the transition dictionary.

InvalidSymbolError

If this PDA has invalid symbols in the transition dictionary.

InvalidAcceptanceModeError

If this PDA has an invalid acceptance mode.