-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
69 lines (57 loc) · 2.35 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
from manager import Manager
from json import loads
import argparse
parser = argparse.ArgumentParser("Well-formatted formulas checker")
parser.add_argument('-i', metavar='i', required=True,
type=str, help="The input.")
parser.add_argument('-p', dest='p', action="store_true", required=False,
help="Use it only if you want to parse, every command will also parse the input.")
parser.add_argument('-s', dest='s', action="store_true",
required=False, help="Will check the syntax of the input.")
parser.add_argument('-e', dest='e', action="store_true", required=False,
help="Will evaluate the input with the provided config, if it's missing will evaluate all interpretations.")
parser.add_argument('-c', metavar='c', required=False, type=loads,
help="The config for one evaluation. The format is {\\\"P\\\": \\\"False\\\", \\\"Q\\\": \\\"True\\\"}.")
parser.add_argument('-t', dest='t', action="store_true",
required=False, help="Will print the tree.")
parser.add_argument('-r', dest='r', action="store_true", required=False,
help="Will print the reconstructed version of the input.")
parser.add_argument('-o', dest='o', required=False, type=str,
help="Will output to this file if specified, but it will also print to console. It works only for evaluation.")
parser.add_argument('-k', dest='k',action="store_true", required=False,
help="Will evaluate if the formula is Valid/Satisfiable/Not Satisfiable")
args = parser.parse_args()
def __init__():
args.i = args.i.strip()
# i
m = Manager(args.i)
# p
if args.p == True:
m.parse()
# s
if args.s == True:
m.validate()
m.check_syntax()
if args. k == True:
if args.e == True:
m.sat_not_sat(True)
else:
m.sat_not_sat()
elif args.e == True:
# c
if args.c != None:
m.update_evaluator(args.c)
m.evaluate(True)
else:
m.evaluate_all_interpretations()
# t
if args.t == True:
m.print_tree()
# r
if args.r == True:
print(m.reconstruct())
if args.o != None:
with open(args.o, "w", encoding="utf-8") as f:
f.write(m.output)
if __name__ == "__main__":
__init__()