-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
36 lines (31 loc) · 809 Bytes
/
main.c
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
#include <stdio.h>
#include "parse.h"
int main() {
printf("BC\n");
printf("Author: Adesh Choudhar\n");
while (true) {
printf("> ");
char *expr = read();
if (strcmp(expr, "help") == 0) {
menu();
} else if (strcmp(expr, "exit") == 0) {
printf("Bye!\n");
break;
} else if (expr[0] == '\0') {
continue;
} else if (is_valid_character(expr[0]) || is_valid_value(ORD(expr[0]))) {
Number *res = result(expr);
if (!res) {
throw_error(10);
continue;
}
printf("= ");
show_number(res);
delete_number(res);
} else {
throw_error(10);
}
free(expr);
}
return 0;
}