This Python script implements a Finite Automaton class capable of handling Deterministic Finite Automata (DFA). TheFiniteAutomaton class is defined with methods to check if the automaton is a DFA and to determine if a given input string is accepted.
TheFiniteAutomaton class is initialized with the following parameters:
states: Set of states in the automaton.alphabet: Set of symbols in the input alphabet.transitions: Dictionary representing the transitions between states based on input symbols.start_state: The initial state of the automaton.final_states: Set of final/accepting states.
is_dfa(): Checks if the automaton is a Deterministic Finite Automaton (DFA).
accept_input(input_string): Accepts an input string and determines if it is accepted by the automaton. Returns a tuple of acceptance status and the sequence of visited states.
The script includes a functionread_transition_file(file_path) to read transition information from a file and convert it into a dictionary used by theFiniteAutomaton class.
To use the script, create an instance of theFiniteAutomaton class with the necessary parameters, and interactively test input strings.
python main.pyThe script prompts the user to enter a string and outputs whether the string is accepted or not, along with the sequence of visited states.File Structuremain.py: The main Python script containing the FiniteAutomaton class and themain()functionfor interactive testing.transitions.txt: Example file containing transition information.Feel free to modify the automaton parameters and transition file to suit your specific use case.