1
2
3
4
5
6
7
8public
9abstract
10class SExpr {
11
12
13
14
15
16 public final static
17 SExpr nil = new Nil();
18
19
20
21
22
23 public final static
24 SExpr t = new Symbol("#t");
25
26
27
28
29
30 public static
31 SExpr mkSymbol(String s) {
32 if (s.equals("#t"))
33 return t;
34
35 return
36 new Symbol(s);
37 }
38
39 public static
40 SExpr mkNumber(long n) {
41 return
42 new Number(n);
43 }
44
45 public static
46 SExpr mkPair(SExpr l, SExpr r) {
47 return
48 l.cons(r);
49 }
50
51
52
53
54 public
55 SExpr car() {
56 throw
57 new IllegalArgumentException("car applied to an atom");
58 }
59
60 public
61 SExpr cdr() {
62 throw
63 new IllegalArgumentException("cdr applied to an atom");
64 }
65
66
67
68
69
70
71 public
72 SExpr cons(SExpr e2) {
73 return
74 new Pair(this, e2);
75 }
76
77
78
79
80
81
82
83 public
84 SExpr isAtom() {
85 return
86 nil;
87 }
88
89 public
90 SExpr isPair() {
91 return
92 nil;
93 }
94
95 public
96 SExpr isList() {
97 return
98 nil;
99 }
100
101
102
103 public
104 SExpr isNull() {
105 return
106 this == nil
107 ? t
108 : nil;
109 }
110
111
112 public
113 SExpr isEqual(SExpr e2) {
114 return
115 nil;
116 }
117
118}
119