-
Notifications
You must be signed in to change notification settings - Fork 0
/
implementing DFAs.py
45 lines (43 loc) · 1.47 KB
/
implementing DFAs.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
def abstract_machine(input_list):
n= len(input_list)
print('\nStarted abstract machine for L((a|b)*abb)')
print('\nVerifying string '+input_list)
print('\nEntered state A')
for l in range(n-3):
if input_list[l] == 'a':
print("\nPass")
elif input_list[l] == 'b':
print('\nPass')
else:
print('\nUnknown symbol encountered in state A')
print('\nTrapped and exited')
exit()
if input_list[n - 3] == 'a':
print('\nPass')
else:
print('\nUnknown or wrong symbol encountered in state A')
print('\nTrapped and exited')
exit()
print('\nExited state A')
print('\nEntered state B')
if input_list[n-2] == 'b':
print('Pass')
else:
print('\nUnknown or wrong symbol encountered in state B')
print('\nTrapped and exited')
exit()
print('\nExited state B')
print('\nEntered state C')
if input_list[n-1] == 'b':
print('Pass')
else:
print('\nUnknown or wrong symbol encountered in state C')
print('\nTrapped and exited')
exit()
print('\nExited state C')
print('\nEntered Final state and terminating')
print('\nString '+input_list+' is accepted')
exit(0)
if __name__ == "__main__":
s=input('Enter string ending with abb : ')
abstract_machine(s)