-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonManager.py
56 lines (42 loc) · 1.28 KB
/
jsonManager.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
import json
from tokenize import String
from typing import Dict
NFA = {
"StartingState": "S1",
"S1": {
"IsTerminating": False,
}
}
DFA = {
"StartingState": "S1",
}
minDFA = {
"StartingState": "S1",
}
def addTransition(currentState: String, goingState: String, transition: String, stateData: Dict):
# add the new state if it's not available
createNewState (goingState,stateData)
createNewState(currentState, stateData)
state = stateData[currentState]
# check if the transition is not available
if state.get(transition) != None:
# if transition is not available
for end in state[transition]:
if (end == goingState):
return
state[transition].append(goingState)
else:
# if transition not available
state.update({transition: [goingState]})
def createNewState(state: String, stateData: Dict):
if stateData.get(state) != None:
return
else:
stateData.update({state: {"IsTerminating": False}})
def createJSONFile(fileName: String, stateData: Dict):
with open(fileName, "w") as outfile:
json.dump(stateData, outfile, indent= 4)
def readJSONFile (fileName):
file = open (fileName, "r")
inData = json.loads(file.read())
return inData