-
Notifications
You must be signed in to change notification settings - Fork 0
/
stringAcceptanceFA.py
36 lines (34 loc) · 997 Bytes
/
stringAcceptanceFA.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
def Accept(string, first):
global Accepted
if len(string) == 0:
if final_states.__contains__(first):
Accepted = True
return
for neighbor in adj_dict[first]:
if neighbor[0] == string[0]:
Accept(string[1:], neighbor[1])
elif neighbor[0] == '$':
Accept(string, neighbor[1])
return
if __name__ == '__main__':
global states
global sigma
global final_states
global Accepted
Accepted = 0
states = input()[1:-1].split(',')
sigma = input()[1:-1].split(',')
final_states = input()[1:-1].split(',')
NUMBER_OF_RULES = int(input())
adj_dict = dict()
for i in range(len(states)):
adj_dict[states[i]] = list()
for i in range(NUMBER_OF_RULES):
s = input().split(',')
adj_dict[s[0]].append((s[1], s[2]))
string = input().replace('$', '')
Accept(string, states[0])
if Accepted == 1:
print("Accepted")
else:
print("Rejected")