-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathast.cpp
More file actions
48 lines (40 loc) · 1.21 KB
/
ast.cpp
File metadata and controls
48 lines (40 loc) · 1.21 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
#include <iostream>
#include <lexer/lexer.h>
using namespace dt::lexer;
#include <parser/parser.h>
using namespace dt::parser;
#include <evaluator/evaluator.h>
using namespace dt::evaluator;
#include <executor/executor.h>
using namespace dt::executor;
/**
* ast抽象语法树 test
* @return
*/
int main()
{
std::shared_ptr<Lexer> lexer(new Lexer("./../sql.txt"));
std::shared_ptr<Parser> parser(new Parser(lexer));
std::shared_ptr<Environment> env(new Environment());
std::shared_ptr<Evaluator> evaluator(new Evaluator());
std::shared_ptr<dt::execution::RootNode> root = std::make_shared<dt::execution::RootNode>();
std::shared_ptr<Executor> executor(new Executor());
// 构建ast
std::shared_ptr<dt::ast::Program> program = parser->parse_program();
// auto ps = program->m_statements;
// for (auto & p : ps)
// {
// // 递归构建执行计划
// evaluator->eval(p, env.get(), root);
//
// // 递归运行执行计划
// executor->execute_plan(root);
//
// root = std::make_shared<dt::execution::RootNode>();
// }
Json json = program->json();
std::ofstream ofs("./../sql.json");
ofs << json.str();
ofs.close();
return 0;
}