-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstates.py
53 lines (42 loc) · 1.48 KB
/
states.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
46
47
48
49
50
51
52
53
class State:
def __init__(self, state_identifier):
self.state_identifier = state_identifier
self.transitions = list()
self.final = False
self.starting_state = False
self.dead_state = False
def add_transition(self, symbol, state_identifier):
self.transitions.append((symbol, state_identifier))
def set_final(self):
self.final = True
def set_starting(self):
self.starting_state = True
def set_dead(self):
self.dead_state = True
def get_transition(self, symbol):
for transition in self.transitions:
if transition[0] == symbol:
return transition[1]
return None
def get_multiples_transitions(self, symbol):
transitions = []
for transition in self.transitions:
if transition[0] == symbol:
transitions.append(transition[1])
if len(transitions) == 0:
return None
return transitions
def get_transitions(self):
return self.transitions
def remove_transition(self, symbol, state_identifier):
for transition in self.transitions:
if transition[0] == symbol and transition[1] == state_identifier:
self.transitions.remove(transition)
return True
return False
def is_final(self):
return self.final
def is_dead(self):
return self.dead_state
def is_starting(self):
return self.starting_state