-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_assign.c
More file actions
48 lines (44 loc) · 1.19 KB
/
test_assign.c
File metadata and controls
48 lines (44 loc) · 1.19 KB
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
#include <stdio.h> // fprintf()
#include <setjmp.h> // setjmp()
#include "bcode.h"
#include "eval.h"
FILE *Debug;
jmp_buf Recovery;
int main() {
char buffer[ 256 ], *ptr;
byte_t bytes[ 256 ];
int ret;
word_t val;
bcode_t b;
Debug = stderr;
eval_init(&Recovery);
while (1) {
printf("\n");
fprintf(Debug, "\n");
if ((ret = setjmp(Recovery)) != 0) {
printf("*** eval() error: %s\n", eval_result(ret));
continue;
}
ptr = fgets(buffer, 256, stdin);
if (ptr == 0 || *buffer == 0 || *buffer == '\n')
break;
token_source(buffer);
ret = bcode_compile(bytes);
if (ret < 0) {
printf("*** bcode_compile() error: %s\n", bcode_result(-ret));
continue;
}
bcode_start(bytes);
bcode_read(&b);
if (b.inst == BCODE_INQ) {
val = eval();
printf("eval() returns %d\n", val);
} else if (b.type == BCODE_TYPE_VARIABLE)
eval_assign(b.idx + 1);
else if (b.inst == BCODE_AT)
eval_assign(0);
else
printf("*** Syntax error\n");
}
return 0;
}