-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
107 lines (96 loc) · 3.21 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import pathlib as pl
from iddl.RunProgram import run, run2, run3,runTranslatorTest,runInterpTest
def runFile(filename):
resultList = []
filePath = str(pl.Path().resolve()) + \
'\\InputFiles' + '\\' + filename + '.txt'
resultFile = pl.Path(filePath)
if not (resultFile):
return False
with open(filePath) as f:
text = f.readlines()
for line in text:
if '#' in line:
continue
if line == '\n':
continue
result, error = run2(filename, line)
if error:
print(error.as_string())
break
else:
resultList.append(result)
return resultList
def writeFile(fileName, filePath, result, multipleLines, writeMethod):
with open(filePath, writeMethod) as f:
f.write("Theorem \" " + fileName + ' \"\n\nProblem\n\n')
if multipleLines:
for line in result:
f.write(line + '\n')
else:
f.write(result + '\n')
f.write("\nEnd.")
f.write("\nEnd.")
def printToFile(result, multipleLines):
fileName = input('\tFile name? > ')
fileNameKX = fileName + '.kyx'
filePath = str(pl.Path().resolve()) + \
'\\OutputFiles' + '\\' + fileNameKX
resultFile = pl.Path(filePath)
if resultFile.is_file():
rewrite = input(
'\t' +
fileName +
' already exists. Rewrite file? y/n > ').lower()
if rewrite:
writeFile(fileName, filePath, result, multipleLines, 'w')
print("File at %s successfully rewritten.\n" % filePath)
return filePath
else:
printToFile(result)
else:
writeFile(fileName, filePath, result, multipleLines, 'a')
print("File at %s successfully created.\n" % filePath)
return filePath
def availableCommands():
availableCmds = (
'Commands:' +
'\n -> help: lists available commands.' +
'\n -> q: exits the program.' +
'\n -> run: prompts for a file of formulas to be translated.\n')
return availableCmds
def main():
resultList = []
print('Starting idDL2dDL... \nType "help" for available commands.')
while True:
text = input('Intervals > ')
text = text.strip()
if text == "q":
print("Exiting...")
break
elif text.lower() == 'help'.lower():
print(availableCommands())
continue
elif text.lower() == 'run'.lower():
fn = input('Enter file name: ')
fn = fn.strip()
result = runFile(fn)
if not result:
continue
toFile = input('Generate file with results? y/n > ').lower()
if toFile == 'y'.lower():
printToFile(result, True)
continue
else:
continue
result, error = run2('<stdin>', text)
if error:
print(error.as_string())
else:
toFile = input('Generate file with results? y/n > ').lower()
if toFile == 'y'.lower():
printToFile(result, False)
continue
else:
continue
main()