-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtinyDB.cc
47 lines (40 loc) · 1.21 KB
/
tinyDB.cc
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
#include<string>
#include<variant>
#include<iostream>
#include"../include/def.h"
#include"../include/compiler.h"
using compiler::CompilerFactory;
void handle_status(StatusCode& statusCode) {
switch (statusCode) {
case StatusCode::kSuccess:
break;
case StatusCode::kSuccessAndExit:
std::cout << "Bye~" << std::endl;
exit(static_cast<int>(StatusCode::kSuccessAndExit));
break;
case StatusCode::kUnrecognizedMetaCommand:
std::cerr << "Error: unrecognized meta command, "
<< compiler::requireCheck << std::endl;
break;
case StatusCode::kUnrecognizedSqlStatement:
std::cerr << "Error: unrecognized SQL statement, "
<< compiler::requireCheck << std::endl;
break;
default:
std::cerr << "Fatal Error: Unknown error!" << std::endl;
exit(static_cast<int>(StatusCode::kUnknownError));
break;
}
}
int main() {
auto [parser, interpreter] = CompilerFactory::GetAll();
while (true) {
std::string input;
std::cout << "TinyDB > ";
std::getline(std::cin, input);
auto statement = parser.Parse(input);
auto statusCode = interpreter.Execute(statement);
handle_status(statusCode);
}
return 0;
}