-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlisp.c
65 lines (55 loc) · 940 Bytes
/
lisp.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stddef.h>
#include "libef.h"
int g_buf = -1;
int getChar(void) {
int r;
if (g_buf >= 0) {
r = g_buf;
g_buf = -1;
} else {
r = getchar();
if (r == -1)
exit(0);
}
return r;
}
int peekChar(void) {
if (g_buf >= 0)
return g_buf;
int c = getchar();
g_buf = c;
return c;
}
void ungetChar(int c) {
g_buf = c;
}
const int g_close_char = ')';
#include "lisp_common.c"
Atom* parse(void) {
skipWS();
int c = getChar();
if (c == '(') {
return parseList();
} else if (c == '-' || (c >= '0' && c <= '9')) {
return parseInt(c);
} else if (c == ';') {
while (c != '\n') {
c = getChar();
}
return parse();
} else {
return parseStr(c);
}
}
int main() {
int buf[2];
buf[0] = 't';
buf[1] = '\0';
g_t = createStr(buf);
while (1) {
Atom* expr = parse();
Atom* result = eval(expr, NULL);
printExpr(result);
putchar('\n');
}
}