-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cxx
61 lines (54 loc) · 1.43 KB
/
main.cxx
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
#include "eval.h"
#include "mp_env.h"
#include "lexer.hxx"
#include "parser.hxx"
#include <fstream>
int
main (int argc, char **argv)
{
if (argc != 2)
{
fprintf(stderr, "MPlus BSD 3 Clause license\nRun like this: mplus [MPlus script]\n");
return 1;
}
try
{
std::ifstream s(argv[1], std::ios::in);
if (s.is_open() == false)
{
fprintf(stderr, "File %s cannot be read\n", argv[1]);
return 2;
}
istream_wrapper wrap(s);
parser_info info(wrap);
// // Uncomment and add #include <chrono> to time the parse routine
// auto start = std::chrono::high_resolution_clock::now();
auto tree = parse(info);
// std::chrono::duration<double, std::milli> duration = std::chrono::high_resolution_clock::now() - start;
// printf("Parsing took %gms\n", duration.count());
// // Uncomment to print tree parse tree!
// {
// auto str = expr_to_str(tree);
// printf("%s\n", str);
// free(str);
// }
auto env = new_mp_env(nullptr);
init_default_env(env);
auto ret = eval(env, tree);
{
auto str = expr_to_str(ret);
printf("%s\n", str);
free(str);
}
dealloc(&ret);
auto denv = reinterpret_cast<rt_data_t *>(env);
dealloc(&denv);
dealloc(&tree);
}
catch (std::exception &err)
{
fprintf(stderr, "error: %s\n", err.what());
return 1;
}
return 0;
}