-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
75 lines (61 loc) · 2.34 KB
/
main.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
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
#include <string.h>
#include "test/ParseTester/ParseTester.h"
#include "visitors/ToStringVisitor.h"
#include "visitors/ToPropLTLVisitor.h"
#include "visitors/ToJsonVisitor.h"
using namespace ParseTest;
using json = nlohmann::json;
using namespace boost::filesystem;
using namespace antlr4;
using namespace vastgenvisitor;
using namespace vast;
int main(int argc, const char **argv) {
if (argc <= 1) {
cout << "WARNING: Passed no arguments! Pass a path or --parseTests!\n";
return 0;
}
if (strcmp(argv[1], "--parseTests") == 0) { // make strncmp?
ParseTester *pt = new ParseTester();
pt->runTests();
} else {
std::ifstream specfile (argv[1]);
std::string spec((std::istreambuf_iterator<char>(specfile)),
(std::istreambuf_iterator<char>()));
std::cout<<"Parsing the specfile with ANTLR \n";
ANTLRInputStream input(spec.c_str());
VLexer lexer(&input);
CommonTokenStream tokens(&lexer);
VParser parser(&tokens);
VParser::SpecContext* tree = parser.spec();
std::cout<<"Creating the VAST using (parse tree) VASTGenVisitor \n";
VASTGenVisitor visitor;
VAST* ast = visitor.visitSpec(tree);
//Using the ToString visitor.
std::cout<<"Converting VAST to String using the VAST ToStringVisitor \n";
vastvisitor::ToStringVisitor tsvisitor;
string vastString = std::any_cast<std::string>(tsvisitor.visit(ast));
std::cout<<vastString <<"\n";
//Using the ToPropLTL visitor.
std::cout<<"Converting VAST to propostional LTL using the VAST ToPropLTLVisitor \n";
vastvisitor::ToPropLTLVisitor tpvisitor;
try{
string vastPropString = std::any_cast<std::string>(tpvisitor.visit(ast));
std::cout<<vastPropString<< "\n";
std::map<string, VAST*> atomMap = tpvisitor.getMap();
tpvisitor.printMap();
}
catch(const char* txtException){
std::cout<<"Exception: "<<txtException<<"\n";
}
// Using the ToJson visitor.
std::cout<<"Converting VAST to JSON using the VAST ToJsonVisitor \n";
vastvisitor::ToJsonVisitor tjvisitor;
json vastJsonString = std::any_cast<json>(tjvisitor.visit(ast));
std::cout<<vastJsonString<<"\n \n";
// Using the inbuilt Json function.
std::cout<<"Converting VAST to JSON without using any visitor \n";
json ast_json = ast->toJson();
std::cout << ast_json << "\n \n";
}
return 0;
}