Pyautomata is a python project made to simulate the execution of a Deterministic Finite Automata (DFA). This repository includes the core library and a GUI made with PySimpleGUI. At the root of this repository there is a main.py
file to run the project completely integrated.
To install this program, run the following commands on Linux:
git clone https://github.com/aiwaverse/pyautomata-git
cd pytautomata-git
pip install -r requirements.txt
Tkinter is required for this project, it's included on Windows, and can be installed on other operational systems, often the package is named python3-tk
or python3-tkinter
On other operational systems, to install the instructions are the same:
- Clone this repository
- Enter the folder
- Use pip to install the requirements on requirements.txt
This program requires a DFA file, the expected format is:
<M>=({<q0>,...,<qn>},{<s1>,...,<sn>},Prog,<ini>,{<f0>,...,<fn>})
Prog
(<q0>,<s1>)=<q1>
...
(<qn>,<sn>)=<q0>
Where:
<M>
is the automata name.{<q0>,...,<qn>}
are the automata states.{<s1>,...,<sn>}
are the alphabet symbols.<ini>
is the initial state.{<f0>,...,<fn>}
are the final (accepting) states.(<qn>,<sn>)=<q0>
is a transiction, each line contains one, and together they make the program function of the Automata.
It is of extreme importance that the file has the exact same formatting, specially containing no spaces on the file.
The program can also verify a file of word pairs, with the following expected format:
<w0>,<w2>
<w2>,<w3>
Where wn
is a word in the language of the automata.
The program can be run directly with Python:
python main.py
You must them browse and submit the file where the automata is defined:
You may now test for individual words, where the result will appear in a new window, alongside the path the program used to aprove the words, or, if it was rejected, the reason why.
You can also verify using a file of word pairs, where the result will be all pairs that had both words accepted.
It can also be used inside other Python codes:
import pyautomata
p = pyautomata.AutomataParser(file_name="automata.txt")
description, function_program = p.parse()
aut = pyautomata.Automata(function_program, **description)
print(aut.check_word("aab")) # will print the result