-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
41 lines (32 loc) · 1.23 KB
/
main.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
import sys
from dfa.examples import PREDEFINED_FINITE_AUTOMATA, PFA_TYPES, PFA_INFO
# Program exit codes
TOO_FEW_ARGS = -2
UNDEFINED_FINITE_AUTOMATON_TYPE = -1
ALRIGHT = 0
REQUIRED_ARGC = 2
if __name__ == "__main__":
if len(sys.argv) != REQUIRED_ARGC:
print("Required call format: python main.py <type>\n"
"Example: python main.py a\n"
"Try again!")
sys.exit(TOO_FEW_ARGS)
finite_automation_type = sys.argv[1].lower()
if finite_automation_type not in PFA_TYPES:
print(f"The type of finite state machine you have selected is not included "
f"in the available ones: {PFA_TYPES}\nTry again!")
sys.exit(UNDEFINED_FINITE_AUTOMATON_TYPE)
print(f"\nYour choice is: {PFA_INFO[finite_automation_type]}\n")
print("Note: Press <Ctrl+C> or <Ctrl+Z> to exit from program") # May not work in IDE, try Ctrl+F2 instead
finite_automaton = PREDEFINED_FINITE_AUTOMATA[finite_automation_type]
try:
while True:
string_to_check = input(">> ")
finite_automaton.check_ownership(string_to_check)
except KeyboardInterrupt:
print()
except EOFError:
pass
finally:
print("Bye")
sys.exit(ALRIGHT)