-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
49 lines (37 loc) · 984 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
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "expression.h"
#include "environment.h"
#include "evaluate.h"
#include "reader.h"
void repl(FILE *input, environment_t **env, int interactive) {
int check = 0;
do {
if (check == 0 && interactive < 2) {
printf("evaluate> ");
}
expression_t *ptr = read_expression(input);
if (ptr != NULL) {
//print_expression(ptr); printf(" = "); print_expression(evaluate_expression(ptr, env)); printf("\n");
print_expression(evaluate_expression(ptr, env)); printf("\n");
if (check != 0) {
check = 0;
}
} else {
check = 1;
}
} while (1);
}
int main(int argc, char *argv[]) {
FILE *input = ((argc > 1) ? fopen(argv[1], "r") : stdin);
if (!input) {
fprintf(stderr, "[%s] failed to open file\n", __func__);
exit(EXIT_FAILURE);
}
environment_t *env = init_environment();
repl(input, &env, argc);
fclose(input);
return EXIT_SUCCESS;
}