-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.txt
63 lines (48 loc) · 2.56 KB
/
example.txt
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
61
62
63
/*
# states = {'q0', 'q1', 'q2'}
# alphabet = ['a', 'b']
# final_states = ['q2']
# transitions = {'q0': {'a': 'q1', 'b': 'q0'}, 'q1': {'a': 'q2', 'b': 'q1'}, 'q2': {'a': '', 'b': ''}}
states = ['q1', 'q0', 'q01', 'q010', 'q0101']
alphabet = ['0', '1']
final_states = ['q0101']
transitions = {'q1': {'0': 'q0', '1': 'q1'}, 'q0': {'0': 'q0', '1': 'q01'}, 'q01': {'0': 'q010', '1': 'q1'}, 'q010': {'0': 'q0', '1': 'q0101'}, 'q0101': {'0': 'q0101', '1': 'q0101' },}
init_state = 'q1'
# a1 = AFD(states, alphabet, 'q0', final_states, transitions)
a1 = AFD(states, alphabet, init_state, final_states, transitions)
# e1 = 'bbabbba'
# e2 = 'ab'
# e3 = 'a'
# e4 = 'aa'
# e5 = 'bbabbaa'
e1 = '0'
e2 = '0101'
e3 = '11111100110101'
e4 = '111111001'
e5 = '1111000010001010101010'
print(e1, 'is', 'valid!' if a1.is_input_valid(e1) else 'not valid!\n')
print(e2, 'is', 'valid!' if a1.is_input_valid(e2) else 'not valid!\n')
print(e3, 'is', 'valid!' if a1.is_input_valid(e3) else 'not valid!\n')
print(e4, 'is', 'valid!' if a1.is_input_valid(e4) else 'not valid!\n')
print(e5, 'is', 'valid!' if a1.is_input_valid(e5) else 'not valid!\n')
ex =
gr = {'S': ['aA', 'bB', 'b'], 'A': ['aS'], 'B': ['bB', 'b']}
ab = ['a', 'b']
nt = ['S', 'A', 'B']
states = ['S', 'A', 'B', 'C']
alphabet = ['a', 'b']
init_state = 'S'
final_states = ['A']
tr = {'S': {'a': 'A', 'b': 'B'}, 'A': {'a': 'S', 'b': 'C'}, 'B': {'a': 'C', 'b': 'S'}, 'C': {'a': 'B', 'b': 'A'}}
COM EPSILON
states = ['q0', 'q1','q2','q3', 'q4']
ab = ['a', 'b']
init = 'q0'
final = ['q3']
# transitions = {'q0': {'a': ['q0', 'q1'] , 'b': ['q2'], '&': 'q3'}, 'q1': {'a': ['q1'], 'b': ['q3'], '&': 'q3'}, 'q2': {'a': ['-'], 'b': ['q2', 'q3'], '&': 'q2'}, 'q3': {'a': ['q1', 'q3'], 'b': ['q2', 'q3'], '&': 'q4'}, 'q4': {'a': ['q4'], 'b': ['q2'], '&': 'q3'}}
# transitions = {'q0': {'0': ['q0'], '1': ['q0', 'q1'] , '&': 'q1'}, 'q1': {'0': ['q2'] , '1': ['-'], '&': 'q2'}, 'q2': {'0': ['-'], '1': ['q3'], '&': 'q2'}, 'q3': {'0': ['q3'], '1': ['q3'], '&': 'q3'}}
# tr = {'q0': {'0': ['q0'], '1': ['q0', 'q1'] , '&': 'q1'}, 'q1': {'0': ['q2'] , '1': '', '&': 'q2'}, 'q2': {'0': ['-'], '1': ['q3'], '&': 'q3'}, 'q3': {'0': ['q3'], '1': ['q3'], '&': 'q3'}}
ex4 = {'p': {'a': [], 'b': ['q'], 'c': ['r'], '&': ['p', 'q']}, 'q': {'a': ['p'], 'b': ['r'] , 'c': ['p', 'q'] , '&': ['q']}, 'r': {'a': [], 'b': [], 'c': [], '&': ['r']}}
ex3 = {'p': {'a': ['p'], 'b': ['q'], 'c': ['r'], '&': ['p']}, 'q': {'a': ['q'], 'b': ['r'] , 'c': [] , '&': ['p']}, 'r': {'a': ['r'], 'b': [], 'c': ['p'], '&': ['q']}}
oi = NFA(st, ab, init, final, ex3, True)
oi2 = NFA(st, ab, init, final, ex4, True)