-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheval_repl.cpp
More file actions
executable file
·64 lines (50 loc) · 1.54 KB
/
eval_repl.cpp
File metadata and controls
executable file
·64 lines (50 loc) · 1.54 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
62
63
64
#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;
#include <iostream>
#include <string>
const std::string prompt = "<<";
int main()
{
std::shared_ptr<dt::execution::RootNode> root;
std::shared_ptr<Executor> executor(new Executor());
std::cout << "Welcome to DTimeDB!" << std::endl;
std::shared_ptr<Environment> env(new Environment());
// 递归向下求值
std::shared_ptr<Evaluator> evaluator(new Evaluator());
while (true)
{
root = std::make_shared<dt::execution::RootNode>();
std::cout << prompt;
std::string text;
std::getline(std::cin, text);
if (text == "exit") // 退出出口
{
std::cout << "Bye!" << std::endl;
return 0;
}
// 词法分析器
std::shared_ptr<Lexer> lexer(new Lexer(text.c_str(), text.size()));
// 语法分析器
std::shared_ptr<Parser> parser(new Parser(lexer));
// 构建抽象语法树
auto program = parser->parse_program();
auto errors = parser->errors();
if (!errors.empty())
{
for (auto & error : errors)
{
std::cout << error << std::endl;
}
continue;
}
// 递归向下求值
auto evaluated = evaluator->eval(program, env.get(), root);
executor->execute_plan(root);
}
}