blob: 5edb48cc31b72103608759b2444215b316fcf5f5 (
plain) (
blame)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#include <stdio.h>
#include <string.h>
#include "eval.h"
#include "lex.h"
#include "mem.h"
#include "parse.h"
#include "print.h"
int main(void) {
token_list* tokens;
fuspel* pgm;
expression to_eval, *evaled;
tokens = NULL;
while (!feof(stdin)) {
char program[79];
if (!fgets(program, 79, stdin)) {
if (feof(stdin))
break;
fprintf(stderr, "Couldn't read input.");
exit(EXIT_FAILURE);
}
tokens = lex(tokens, program);
if (!tokens) {
fprintf(stderr, "Couldn't lex program.");
exit(EXIT_FAILURE);
}
}
pgm = parse(tokens);
free_token_list(tokens);
free(tokens);
if (!pgm) {
fprintf(stderr, "Couldn't parse program.");
exit(EXIT_FAILURE);
}
printf("\nParsed program:\n");
print_fuspel(pgm);
printf("\n\n\n");
to_eval.kind = EXPR_NAME;
to_eval.var1 = my_calloc(1, 5);
strcpy(to_eval.var1, "main");
evaled = eval(pgm, &to_eval);
free_expression(&to_eval);
if (evaled) {
print_expression(evaled);
printf("\n");
free_expression(evaled);
free(evaled);
}
free_fuspel(pgm);
free(pgm);
return 0;
}
|