-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
54 lines (46 loc) · 1.32 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
46
47
48
49
50
51
52
53
54
// ooc_arithmatic_eval.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include "parser.h"
#include "expression.h"
#include <cstdio>
#include <cctype>
#include <cerrno>
#include <cstdlib>
#include <iostream>
#include <string>
#include <string_view>
#include <Windows.h>
int main()
{
using std::string;
auto source = std::vector<std::string>{
string("let complex = 1.48 + + (1>2?1:2) - ( (0.4 * (3+5) < 5) + 5 + 100 ) < 3 ? 1: 2; "),
string("let ba = complex + 3; "),
string("ba * 2.5 + 200 * 4; "),
string("let ba = 300; "),
string("ba - 300 < 0.001; "),
};
//for(;;) {
compiler::Parser parser{ source };
compiler::expression_ptr_t expr;
try {
for (;;) {
if (parser.MovetoNextToken() != compiler::Parser::END) {
expr = compiler::statement(parser);
std::printf("%.2lf\n", expr->exec());
//printExpression(expr);
}
else
break;
}
}
catch (std::runtime_error& e) {
std::cerr << "runtime error: " << e.what() << std::endl;
}
catch (...) {
std::cerr << "unexpected error " << std::endl;
}
//Sleep(50);
//}
return 0;
}