-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
38 lines (32 loc) · 792 Bytes
/
example.py
File metadata and controls
38 lines (32 loc) · 792 Bytes
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
#!/usr/bin/python
# Autogenerated DFA code using fsm-code-designer
import sys
def step(label, c):
'''
Finds the next label to be accessed while
stepping through the DFA.
@param label: the current label/state the DFA is on
@param c: the next read character
'''
if c == '0' and label == '0':
return '1'
if c == '0' and label == '1':
return '0'
if c == '1' and label == '0':
return '1'
if c == '1' and label == '1':
return '0'
sys.exit('invalid label')
def run(string):
'''
Runs the given DFA on a certain string.
@param string: the string to run the DFA on
'''
state = '0'
for c in string:
state = step(state, c)
return state in ['0']
if __name__ == '__main__':
if len(sys.argv) <= 1:
sys.exit('No string provided to run against.')
print(run(sys.argv[1]))