-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprint.c
56 lines (51 loc) · 1.56 KB
/
print.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
#include <stdio.h>
#include "anicca.h"
#include "symbol.h"
#include "print.h"
VO print(A y) { C *cv; I yn=AN(y), *iv; D *dv; Z *zv; V *vv; A *bv; SY *sy;
if (!y) { printf("NULL"); R; }
switch (AT(y)) {
case BOOL: { cv=BAV(y); DO(yn, printf("%d ",(I)cv[i])); break; }
case NAME:
case CHAR: { cv=CAV(y); DO(yn, printf("%c",cv[i])); break; }
case INT: { iv=IAV(y); DO(yn, printf("%d ",iv[i])); break; }
case FLT: { dv=DAV(y); DO(yn, printf("%f ",dv[i])); break; }
case CMPX: {
zv=ZAV(y); DO(yn, printf("%fj%f ",ZR(zv[i]),ZI(zv[i]))); break;
}
/* TODO?: fancy line drawings */
case BOX: {
bv=AAV(y);
DO(AN(y), printf("(<");
print(bv[i]);
printf(")%s", (i+1 == AN(y))?"":",")
);
break;
}
case VERB: case ADV: case CONJ: {
vv=VAV(y);
printf("%c ", vv->id);
if (VF(vv)) { print(vv->f);
if (VG(vv)) { print(vv->g);
if (VH(vv)) { print(vv->h); };
}
};
break;
}
case SYMB: {
sy=SYAV(y);
DO(AN(y), printf("(<");
printf("nm: "); print(sy->name); printf(" vl: "); print(sy->value);
printf(")%s", (i+1 == AN(y))?"":",");
sy++;
);
break;
}
case LPAR: { printf("LPAR"); break; }
case RPAR: { printf("RPAR"); break; }
case ASGN: { intf(y) ? printf("=:") : printf("=."); break; }
case MARK: { break; }
default: { printf("HUH?"); break; }
}
}
VO println(A y) { if (!(AT(y)&MARK)) { print(y); printf("\n"); } }