|
|
|
|
|
|
|
|
1
|
#include <math.h>
|
|
1
|
#include <stdio.h>
|
2
|
#include <stdio.h>
|
|
2
|
|
3
|
|
|
3
|
#include <editline/readline.h>
|
4
|
#include <editline/readline.h>
|
|
|
|
|
|
|
9
|
if (strcmp(op, "-") == 0) { return x - y; }
|
10
|
if (strcmp(op, "-") == 0) { return x - y; }
|
|
10
|
if (strcmp(op, "*") == 0) { return x * y; }
|
11
|
if (strcmp(op, "*") == 0) { return x * y; }
|
|
11
|
if (strcmp(op, "/") == 0) { return x / y; }
|
12
|
if (strcmp(op, "/") == 0) { return x / y; }
|
|
|
|
13
|
if (strcmp(op, "%") == 0) { return x % y; }
|
|
|
|
14
|
if (strcmp(op, "^") == 0) { return pow(x, y); }
|
|
|
|
15
|
if (strcmp(op, "min") == 0) { return x < y ? x : y; }
|
|
|
|
16
|
if (strcmp(op, "max") == 0) { return x > y ? x : y; }
|
|
12
|
return 0;
|
17
|
return 0;
|
|
13
|
}
|
18
|
}
|
|
14
|
|
19
|
|
|
|
|
|
|
|
38
|
mpca_lang(MPC_LANG_DEFAULT,
|
43
|
mpca_lang(MPC_LANG_DEFAULT,
|
|
39
|
"\
|
44
|
"\
|
|
40
|
number : /-?[0-9]+(\\.[0-9]+)?/ ; \
|
45
|
number : /-?[0-9]+(\\.[0-9]+)?/ ; \
|
|
41
|
operator : '+' | '-' | '*' | '/' | /[a-zA-Z-]+/ ; \
|
|
|
|
|
|
46
|
operator : '+' | '-' | '*' | '/' | '%' | '^' | /[a-zA-Z-]+/ ; \
|
|
42
|
expr : <number> | '(' <operator> <expr>+ ')' ; \
|
47
|
expr : <number> | '(' <operator> <expr>+ ')' ; \
|
|
43
|
lang : /^/ <expr>+ /$/ ; \
|
48
|
lang : /^/ <expr>+ /$/ ; \
|
|
44
|
",
|
49
|
",
|