-
Notifications
You must be signed in to change notification settings - Fork 0
/
inputparser.py
59 lines (49 loc) · 1.47 KB
/
inputparser.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
54
55
56
57
58
59
from input import *
class InputParser:
parser = None
@staticmethod
def getParser():
if (InputParser.parser == None):
InputParser.parser = InputParser()
return InputParser.parser
def parse(self, input) -> Input:
# print(input)
file = input
file = file.split('\n')
head = file[0]
head = head.split()
prio = head[0] == "True"
result = InputBuilder()
result.setPrimitive(prio)
try:
result.setTQ(int(head[1]))
except:
result.setTQ(None)
for line in file[1:]:
data = line.split()
i = 0
job = JobBuilder()
if (data[i].isalpha()):
job.setName(data[i])
i += 1
if (prio):
job.setPriority(int(data[i]))
i += 1
job.setArrivalTime(int(data[i]))
i += 1
seq = SequenceBuilder()
for c in data[i:]:
seq.addtoSeq(self.parseTime(c))
seq = seq.getSequence()
job.setSequence(seq)
job = job.getJob()
result.addJob(job)
result = result.getInput()
return result
def parseTime(self, text: str):
if (text[0] == 'c'):
return CPUBurst(int(text[1:]))
elif (text[0] == 'i'):
return IOWait(int(text[2:]))
else:
raise Exception("Unable to parse time")