forked from ceramisch/automatesfinis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tp3automates.py
executable file
·61 lines (46 loc) · 1.2 KB
/
tp3automates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
"""
Applies Kleene's star, concatenation and union of automata.
"""
from automaton import Automaton, EPSILON, State, error, warn
import sys
import pdb # for debugging
##################
def kleene(a1:Automaton)->Automaton:
# TODO: implement Kleene's star
return a1
##################
def concat(a1:Automaton, a2:Automaton)->Automaton:
# TODO: implement concatenation
return a1
##################
def union(a1:Automaton, a2:Automaton)->Automaton:
# TODO: implement union
return a1
##################
if __name__ == "__main__" :
if len(sys.argv) != 3:
usagestring = "Usage: {} <automaton-file1.af> <automaton-file2.af>"
error(usagestring.format(sys.argv[0]))
# First automaton, argv[1]
a1 = Automaton("dummy")
a1.from_txtfile(sys.argv[1])
a1.to_graphviz(a1.name+".gv")
print(a1)
# Second automaton, argv[2]
a2 = Automaton("dummy")
a2.from_txtfile(sys.argv[2])
a2.to_graphviz(a2.name+".gv")
print(a2)
a1star = kleene(a1)
print()
print(a1star)
a1star.to_graphviz("a1star.gv")
a1a2 = concat(a1, a2)
print()
print(a1a2)
a1a2.to_graphviz("a1a2.gv")
a1ora2 = union(a1, a2)
print()
print(a1ora2)
a1ora2.to_graphviz("a1ora2.gv")