Skip to content

Commit 6c7cf91

Browse files
committed
Initial commit
1 parent 2667f61 commit 6c7cf91

File tree

153 files changed

+14630
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+14630
-0
lines changed

.gitignore

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/

README.md

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# GAMBA tools
2+
3+
The `gambatools` package is a Python 3 package that aims to
4+
support education in theoretical computer science at
5+
[Eindhoven University of Technology](https://www.tue.nl/en/).
6+
It contains a library for
7+
DFAs, NFAs, PDAs, Turing machines, context free grammars and
8+
regular expressions. Moreover, the package provides Jupyter notebooks with
9+
exercises. The library has been developed by Wieger Wesselink,
10+
and it was designed together with Erik de Vink.
11+
12+
# GAMBA
13+
The code was developed as part of the GAMBA project, which stands for:
14+
*Grammars and Automata Made Boffo and Assessible*. The goals of the project are
15+
to support
16+
17+
* practising and assessing formal language techniques
18+
* self-paced learning outside contact hours
19+
* immediate feedback while practising
20+
* automated grading for assessment
21+
22+
(*boffo*: extremely successful, sensational)
23+
24+
# License
25+
The code is distributed under the `GPL-3.0-or-later` license.
26+
27+
# Installation
28+
The package can be installed using
29+
```
30+
pip install gambatools
31+
```
32+
The required python packages can be found in `requirements.txt`.
33+
34+
# Rendering images
35+
For visualization the [graphviz](https://pypi.org/project/graphviz/) python
36+
package is used. **To render the generated DOT source code, you also need to install
37+
Graphviz**. See the [Graphviz website](https://graphviz.org/) for further instructions.
38+
Make sure that the directory containing the `dot` executable is on your systems’ path.
39+
40+
# Documentation
41+
The file `doc/specifications.pdf` contains formal specifications
42+
of the algorithms in the library. Note that the code maps almost one-to-one
43+
to the specifications, so in order to understand the code please consult the
44+
pseudocode specifications.
45+
46+
# Notebooks
47+
The directory `notebooks` contains a number of Jupyter notebooks
48+
with exercises. In `notebooks/with-answers` the correct answers are
49+
already given, while in `notebooks/without-answers` they have been
50+
left out.
51+
The answers to the exercises are checked automatically.
52+
Whenever the user makes a mistake, appropriate feedback is given.
53+
54+
![NFA to DFA](doc/images/nfa2dfa.png)
55+
56+
For specifying a DFA, NFA, etc. a line based textual input format is used,
57+
see the example below. The documentation contains a section that describes
58+
the syntax, while in the `examples` directory a number of examples can be found.
59+
```
60+
input_symbols 0 1
61+
states qA qB qC qD
62+
63+
initial qA
64+
final qC
65+
66+
qA qB 0
67+
qA qD 1
68+
qB qB 0
69+
qB qC 1
70+
qC qB 0
71+
qC qC 1
72+
qD qD 0
73+
qD qD 1
74+
```
75+
76+
# Notebook generation
77+
For convenience there is a mechanism to automatically generate notebooks from
78+
templates.
79+
The notebooks in `notebooks/with-answers` and `notebooks/without-answers`
80+
have been generated using the commands
81+
```
82+
make_notebook.py -o without-answers notebooks.batch
83+
make_notebook.py --with-answers -o with-answers notebooks.batch
84+
```
85+
The templates contain tags of the form `<<tag>>` that are substituted by
86+
the `make_notebook.py` script. This generation is still experimental, and
87+
there is currently no documentation available for this.
88+
89+
# Contact
90+
If you are interested in using the package for education or have questions
91+
or feedback, the authors can be reached by email:
92+
<e.p.d.vink@tue.nl> or <j.w.wesselink@tue.nl>.

doc/images/nfa2dfa.png

70.2 KB
Loading

doc/specifications.pdf

345 KB
Binary file not shown.

examples/cfg1.cfg

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
%% language = \lbrace \, a^{\mkern1mu n} \mkern1mu b^{\mkern1mu m} c^{\mkern1mu \ell} \mid n = m \lor m = \ell \lor n = \ell \, \rbrace
2+
%% accepted = _ aaa bb c aabb bc aabc aabbbcc aaaccc
3+
%% rejected = bcc aab aabbbc ccaaabb bbccaa abab cb aaacccc
4+
%% question = Give a CFG that generates the language $@language@$.
5+
6+
S -> XC | AY | Z
7+
X -> aXb | ε
8+
Y -> bYc | ε
9+
Z -> aZc | B
10+
A -> aA | ε
11+
B -> bB | ε
12+
C -> cC | ε

examples/cfg2.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
S -> ASA | aB
2+
A -> B | S
3+
B -> b | ε

examples/chomsky1.cfg

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
T -> AC | AS | SA | DB | a
2+
S -> AS | SA | DB | a | AC
3+
B -> b
4+
A -> AC | AS | SA | DB | a | b
5+
C -> SA
6+
D -> a

examples/complement.dfa

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
%% language = \{ \, w \in \{a,b\}^\ast \mid \#_a(w) \geqslant 2 \, \}
2+
3+
input_symbols a b
4+
states q0 q1 q2
5+
initial q0
6+
final q2
7+
q0 q0 b
8+
q0 q1 a
9+
q1 q1 b
10+
q1 q2 a
11+
q2 q2 a b

examples/dfa1.dfa

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
%% Sipser Exercise 1.6a
2+
%% 0.(0+1)*.1
3+
4+
%% question = Give a DFA that generates the language $@language@$.
5+
%% language = \{ w \in {0,1}^\ast \mid w \text{ starts with } 0 \text{ and ends with } 1 \}
6+
7+
%% selected_word = 0101
8+
9+
input_symbols 0 1
10+
states qA qB qC qD
11+
12+
initial qA
13+
final qC
14+
15+
qA qB 0
16+
qA qD 1
17+
qB qB 0
18+
qB qC 1
19+
qC qB 0
20+
qC qC 1
21+
qD qD 0
22+
qD qD 1
23+

examples/dfa2.dfa

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
%% alphabet = \{a,b\}
2+
3+
initial q0
4+
final q1
5+
q0 q1 a
6+
q1 q1 a b
7+
q0 q2 b
8+
q2 q2 a b

examples/intersection1.dfa

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
%% language = \{ \, w \in \{a,b\}^\ast \mid \mbox{$\#_a(w)$ even} \, \}
2+
3+
input_symbols a b
4+
states q0 q1
5+
initial q0
6+
final q0
7+
q0 q0 b
8+
q0 q1 a
9+
q1 q0 a
10+
q1 q1 b

examples/intersection2.dfa

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
%% language = \{ \, w \in \{a,b\}^\ast \mid \#_b(w) \geqslant 2 \, \}
2+
3+
input_symbols a b
4+
states q0 q1 q2
5+
initial q0
6+
final q2
7+
q0 q0 a
8+
q0 q1 b
9+
q1 q1 a
10+
q1 q2 b
11+
q2 q2 a b

examples/nfa1.nfa

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
%% language = \{ w \in \{0,1\}^* \mid \#_0(w) \geq 2, \#_1(w) \leq 1 \}^*
2+
%% question = Give an NFA that accepts the language $@language@$.
3+
4+
initial s6
5+
final s2 s5 s6
6+
s0 s1 0
7+
s0 s3 1
8+
s1 s2 0
9+
s1 s4 1
10+
s2 s0 ε
11+
s2 s2 0
12+
s2 s5 1
13+
s3 s4 0
14+
s4 s5 0
15+
s5 s0 ε
16+
s5 s5 0
17+
s6 s0 ε

examples/nfa2.nfa

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
%% question = Give the DFA obtained from the given NFA using the NFA to DFA procedure. Use set notation like `{q0,q1}` (without spaces) for the states in the DFA.
2+
3+
input_symbols a b
4+
initial q0
5+
final q2
6+
q0 q0 a b
7+
q0 q1 ε
8+
q1 q1 a
9+
q1 q2 b

examples/pda-simple.pda

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
%% language = \{ \, a^{\mkern1mu n} b^{\mkern1mu n} \mid n \geqslant 0 \, \}
2+
%% question = Give a PDA that accepts the language $@language@$.
3+
4+
initial q0
5+
final q3
6+
7+
q0 q1 e,e$
8+
q1 q1 a,eX
9+
q1 q2 e,ee
10+
q2 q2 b,Xe
11+
q2 q3 e,$e

examples/pda1.pda

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
%% language = \{ w \in \{a,b\}^\ast \mid \#_a(w) = 2\#_b(w) \}
2+
%% question = Give a PDA that generates the language $@language@$.
3+
4+
initial q0
5+
final q6
6+
q0 q1 ε,ε$
7+
q1 q2 ε,$$
8+
q1 q3 ε,$$
9+
q1 q6 ε,$ε
10+
q2 q1 ε,$$
11+
q2 q2 a,nε
12+
q2 q5 b,εn
13+
q3 q1 ε,$$
14+
q3 q3 a,εp
15+
q3 q4 b,pε
16+
q4 q3 ε,pε
17+
q4 q5 ε,$$
18+
q5 q2 ε,εn

examples/pda2.pda

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
%% language = \{ w \in \{a,b\}^\ast \mid \#_a(w) = 2\#_b(w) \}
2+
%% question = Give a PDA that generates the language $@language@$.
3+
4+
epsilon ε
5+
initial q0
6+
final q6
7+
q0 q1 ε,ε$
8+
q1 q2 ε,$$
9+
q1 q3 ε,$$
10+
q1 q6 ε,$ε
11+
q2 q1 ε,$$
12+
q2 q2 a,nε
13+
q2 q5 b,εn
14+
q3 q1 ε,$$
15+
q3 q3 a,εp
16+
q3 q4 b,pε
17+
q4 q3 ε,pε
18+
q4 q5 ε,$$
19+
q5 q2 ε,εn

0 commit comments

Comments
 (0)