-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterpreter.cpp
48 lines (42 loc) · 1.09 KB
/
interpreter.cpp
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
#include "interpreter.h"
Interpreter::Interpreter()
{
db = DatalogDatabase();
}
void Interpreter::run(char * infile, ostream& out, interpreter_level level)
{
Parser p = Parser();
p.parse(infile);
// cout << p.prog->toString() << endl;
db.addRelations(p.prog->schemes);
out << "Scheme Evaluation" << endl << endl;
db.loadFacts(p.prog->facts);
out << "Fact Evaluation" << endl << endl;
db.dump_relations(out);
// cout << "loaded facts " << endl;
// cout << "DB DUMP" << endl << db.toString() << endl;
if (level != PROJ3)
{
out << "Rule Evaluation" << endl << endl;
db.addRules(p.prog->rules);
}
switch(level){
case PROJ3:
// do nothing
cout << endl;
break;
case PROJ4:
// use a dumb algorithm to add facts to the database
db.bruteEvalRules(out);
break;
case PROJ5:
// use a smart algorithm to add facts to the database
db.smartEvalRules(out);
default:
break;
}
if (level != PROJ3) db.dump_relations(out);
out << "Query Evaluation" << endl << endl;
// evaluate queries
db.evalQueries(p.prog->queries, out);
}