-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
61 lines (50 loc) · 1.77 KB
/
Copy pathmain.cpp
File metadata and controls
61 lines (50 loc) · 1.77 KB
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
#include <iostream>
#include <fstream>
#include <string>
#include "antlr4-runtime.h"
#include "PearlProofLexer.h"
#include "PearlProofParser.h"
#include "PearlProofVisitor.h"
using namespace antlr4;
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " <input_file>" << std::endl;
return 1;
}
std::string inputFile = argv[1];
std::ifstream stream(inputFile);
if (!stream.is_open()) {
std::cerr << "Error: Cannot open file " << inputFile << std::endl;
return 1;
}
ANTLRInputStream input(stream);
PearlProofLexer lexer(&input);
CommonTokenStream tokens(&lexer);
PearlProofParser parser(&tokens);
// Parse the file
PearlProofParser::FileContext* tree = parser.file();
// Check for parse errors
if (parser.getNumberOfSyntaxErrors() > 0) {
std::cerr << "Parse errors encountered" << std::endl;
return 1;
}
// Visit the parse tree
PearlProofASTVisitor visitor;
antlrcpp::Any result = visitor.visitFile(tree);
// Get results
std::vector<CheckResult> results = std::any_cast<std::vector<CheckResult>>(result);
// Output results
bool allPassed = true;
for (const auto& check : results) {
if (check.status == CheckStatus::OK) {
std::cout << "Line " << check.lineNum << ": OK" << std::endl;
} else if (check.status == CheckStatus::UNSUPPORTED) {
std::cout << "Line " << check.lineNum << ": UNSUPPORTED: " << check.message << std::endl;
allPassed = false;
} else {
std::cout << "Line " << check.lineNum << ": ERROR: " << check.message << std::endl;
allPassed = false;
}
}
return allPassed ? 0 : 1;
}