|
|
@ -35,6 +35,11 @@ long eval(mpc_ast_t* t) {
|
|
35
|
35
|
}
|
|
36
|
36
|
|
|
37
|
37
|
int main(int argc, char** argv) {
|
|
|
38
|
int debug_mode = 0;
|
|
|
39
|
if (getenv("DEBUG")) {
|
|
|
40
|
debug_mode = 1;
|
|
|
41
|
}
|
|
|
42
|
|
|
38
|
43
|
mpc_parser_t* Number = mpc_new("number");
|
|
39
|
44
|
mpc_parser_t* Operator = mpc_new("operator");
|
|
40
|
45
|
mpc_parser_t* Expr = mpc_new("expr");
|
|
|
@ -58,7 +63,9 @@ lang : /^/ <expr>+ /$/ ; \
|
|
58
|
63
|
mpc_result_t r;
|
|
59
|
64
|
if (mpc_parse("<stdin>", input, Lang, &r)) {
|
|
60
|
65
|
mpc_ast_t* t = r.output;
|
|
61
|
|
mpc_ast_print(t->children[1]);
|
|
|
66
|
if (debug_mode) {
|
|
|
67
|
mpc_ast_print(t->children[1]);
|
|
|
68
|
}
|
|
62
|
69
|
long result = eval(t->children[1]);
|
|
63
|
70
|
printf("%li\n", result);
|
|
64
|
71
|
mpc_ast_delete(r.output);
|