-
Notifications
You must be signed in to change notification settings - Fork 0
/
show.c
48 lines (45 loc) · 798 Bytes
/
show.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
#include <stdio.h>
#include "stlc.h"
void
showterm(const term_t *term, const type_t *type, term_t t)
{
if (ISVAR(t)) {
printf("%ld", BINDER(t));
}
else if (ISAPP(t)) {
putchar('(');
showterm(term, type, LEFT(t));
putchar(' ');
showterm(term, type, RIGHT(t));
putchar(')');
}
else {
putchar('(');
printf("\\%ld", t);
if (type) {
putchar(':');
showtype(term, type, ATOM(t));
}
putchar('.');
putchar(' ');
showterm(term, type, BODY(t));
putchar(')');
}
}
void
showtype(const term_t *term, const type_t *type, type_t x)
{
while (ISATOM(x) && VALUE(x) != NIL)
x = VALUE(x);
if (ISATOM(x)) {
printf("%ld", ~x);
}
else {
putchar('(');
showtype(term, type, DOM(x));
putchar('-');
putchar('>');
showtype(term, type, COD(x));
putchar(')');
}
}