-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
58 lines (48 loc) · 1.23 KB
/
main.cpp
File metadata and controls
58 lines (48 loc) · 1.23 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
/**
* @file main.cpp
* @brief Main entry point
* @author Soroosh Sardashti <sardashtisoroosh@gmail.com>
* @date 2026-03-08
*/
#include "Layout.h"
#include "SVGEmitter.h"
#include <fstream>
#include <iostream>
#include <sstream>
void run_file(std::ifstream &file) {
std::stringstream ss;
ss << file.rdbuf();
std::string sourceString = ss.str();
Tokenizer tokenizer(sourceString);
tokenizer.Tokenize();
// for (auto &token : tokenizer.getTokens()) {
// printToken(token);
// }
Parser parser(tokenizer.getTokens());
auto pr = parser.parse();
// printProgram(pr);
Layout layout;
auto result = layout.compute(pr.getGraphDecls().getBody());
result.print();
SVGEmitter emitter;
auto svg = emitter.emit(result);
std::ofstream output("outputtest.svg");
if (!output) {
std::cerr << "Could not write output.svg\n";
return;
}
output << svg;
}
int main(int argc, char *argv[]) {
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << "<filename>\n";
return 1;
}
std::ifstream file(argv[1]);
if (!file) {
std::cerr << "Could not open file: " << argv[1] << "\n";
return 1;
}
run_file(file);
return 0;
}