A library/desktop/console application for working with finite state automatons. Pytomaton is a project for passing Python programming course in FMI. It contains virtually all the main operations of (non-)deterministic finite automatons learned in Languages, automata and computability course in FMI. All the algorithms are a straight-forward implementations of standard automatons construction definitions.
-
Install tkinter
- On Windows: it comes by default with Python
- On Mac:
brew install python-tk
- On Linux: refer to your distribution. Some information here
-
Clone repository
git clone https://github.com/kristian3551/Pytomaton.git
-
Install Python dependencies
pip install -r requirements.txt
-
Install latest version of
Graphviz
from here. -
Run from root of repository
python main.py
!!! Make sure you add Graphviz binary folder to the Path variable on Windows! It is located by default in C:\Program files\Graphviz\bin
.
The class Automaton in module src/automaton
provides all the logic for working with automatons themselves.
Basic automaton functionality:
- Adding/removing automaton states
- Managing transitions
- Managing starting and final states
- Checking if a word is in automaton language
Constructions preserving language regularity: all of the methods return a new automaton (not nessecarrily deterministic)
- Union (crating a new non-deterministic automaton)
- Concatenation (crating a new non-deterministic automaton)
- Kleene star (crating a new non-deterministic automaton)
- Intersection: only working with deterministic automatons.
- Complement: only working with deterministic automatons.
- Reverse: returns a new automaton with language L(A)^rev
More constructions:
- Determinization of automatons
- Minimization of automatons (relies on Bzozowski's theorem)
Working with files
- Saving/loading an automaton from file in right format (the format implemented in
stream-format
method in the Automaton class)
The class RegExpr in module src/regexpr
provides all the logic for working with regular expressions in the context of the formal definition (not the built-in RegEx).
Supported functionalities are:
- Validating regular expression (follows the inductive definition of a regular expression)
- Processing regular expression and building an automaton (instance of Automaton class) with the same language: the regular expression is converted to reverse polish notation and then parsed to an automaton in the
compile
method
The class Controller in module src/controller
represents the application itself. An instance if the Controller class holds all of the application's supported functionality (not necessarily all of the implemented functionality in Automaton and RegExpr classes). It holds the logic for creating a .png file from an automaton using Graphviz
library. The .png is saved in database folder. All the automatons in Controller are saved by default in database/automatons.txt
in right format. If you want, you can change it by modifying DEFAULT_DATABASE_PATH
constant in Controller.
The classes in src/app.py
implement the GUI in the application. Tkinter is used for creating the graphical interface.
As the GUI is not the most intuitive (mostly because of the static nature of Tkinter) here are some hints how to use it:
-
Creating automatons:
First, you write the name you want to associate with the automaton in the topmost input field. Second, in the other input field type one of the three options: automaton name, regex or empty.
If you type a name of an automaton, you have to click on one of the construction options (union, concat, etc.) and then the automaton becomes the constructed one from both automatons.
If you write some regex, then a minimal deterministic automaton is created with language the language of the regex.
If you write 'empty', then you can create a custom automaton from scratch. -
Modifying automatons:
If you want to modify state, you have to write the name of the state in the state entry.
If you want to work with transitions, you have to type '{state1} {some letter} {state2}' in the transition entry. -
All of the messages are display on the top of the main window (right above the name entry).
-
If you want to create automaton with existing name, it will be overrided.
You can run all the tests in tests/
by typing python -m pytest -s
in terminal.
- Make GUI more beautiful
- Implementing algorithm for building a regex for an automaton using Kleene's theorem
- Adding more advanced automaton constructions