-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
45 lines (39 loc) · 1 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
#include <fstream>
#include <iostream>
#include "kotlin_array/lexer.hpp"
#include "kotlin_array/parser.hpp"
#include "kotlin_array/token.hpp"
#include <pfw/graphviz.hpp>
#include <pfw/mmap_buffer.hpp>
int main() {
using namespace kotlin_array;
using namespace pfw;
auto buf_res = MakeMmap("test.txt");
if (!buf_res) {
std::cerr << buf_res.error();
return -1;
}
auto buf = std::move(buf_res.value());
Lexer lex(buf.begin(), buf.end());
while (true) {
auto t = lex.NextToken();
if (!t) {
std::cerr << t.error();
break;
}
Token tok = t.value();
std::cout << tok << "\n";
if (tok.index() == 0) {
break;
}
}
Parser p(buf.begin(), buf.end());
auto ast_res = p.Parse();
if (!ast_res) {
std::cerr << ast_res.error();
return -1;
}
auto ast = std::move(ast_res.value());
auto out = std::ofstream("ast.dot");
pfw::graphviz::AstToDot(out, ast);
}