-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmachineReader.py
More file actions
38 lines (34 loc) · 1.4 KB
/
machineReader.py
File metadata and controls
38 lines (34 loc) · 1.4 KB
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
from io import *
from finiteMachine import *
class MachineReader:
def __init__(self):
self.document = None
self.machines = []
return
def readFile(self, file):
self.document = open(file, "r")
for line in self.document:
if line[0] == "M":
fsm_id = line[1]
fsm = FiniteMachine(int(fsm_id))
self.machines.append(fsm)
sub_list = line.split(":")
state_list = sub_list[1].split(",")
for token in state_list:
state = State(int(token[1]))
fsm.add_state(state)
elif line[0] == "t":
transition_list = line.split(":")
for m in transition_list[1]:
if m == "+" or m == "-":
k = line.index(m)
index_or = int(line[k-1])
original_state = fsm.states[index_or]
index_dest = int(line[k+3])
destination_state = fsm.states[index_dest]
transition = Transition(int(fsm_id), original_state, destination_state, m, line[k+1])
fsm.states[int(line[k-1])].add_transition(transition)
else:
print("ERROR: The file provides incorrect information\n")
return
return self.machines