-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
49 lines (42 loc) · 1021 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 "hm.h"
void test() {
test_vector();
test_map();
test_tokenize1();
test_parse1();
test_parse2();
test_parse3();
test_parse4();
test_parse5();
}
int main(int argc, char **argv) {
if (argc < 2) {
error("missing argument");
}
if (strcmp(argv[1], "--test") == 0) {
test();
printf("Test succeeded\n");
return 0;
}
FILE *fp;
if ((fp = fopen(argv[1], "rb")) == NULL) {
error("at open the file");
}
fseek(fp, 0, SEEK_END);
int length = ftell(fp);
fseek(fp, 0, SEEK_SET);
char *buf = malloc(length);
fread(buf, length, 1, fp);
Vector *tokens = tokenize(buf);
Node *nd = parse(tokens);
TEnv *te = new_typing_env();
annotate_node(te, nd);
Vector *equations = new_vector();
gen_equation(te, nd, equations);
Vector *subst = unify_all_equations(te, equations);
if (subst == NULL) {
error("unify failed");
}
print_typed_node(nd, subst);
return 0;
}