-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSExp.java
More file actions
105 lines (90 loc) · 1.74 KB
/
SExp.java
File metadata and controls
105 lines (90 loc) · 1.74 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//package edu.osu.lisp;
public class SExp {
private int type; /* 1: integer atom; 2: symbolic atom; 3: non-atom */
private int val; /* if type is 1 */
private String name; /* if type is 2 */
private SExp left;
private SExp right; /* if type is 3 */
public boolean isAtom;
public boolean isNIL;
public boolean isT;
/**
* constructor for integer atom
*/
SExp(int num) {
isAtom = true;
setType(1);
setVal(num);
setName(null);
isNIL = false;
setLeft(null);
setRight(null);
}
/**
* constructor for symbolic atom
*/
SExp(String sym) {
isAtom = true;
setType(2);
setName(sym);
isNIL = (name.equalsIgnoreCase("NIL")) ? true : false;
isT = (name.equalsIgnoreCase("T")) ? true : false;
setLeft(null);
setRight(null);
}
/**
* constructor for non-atom
*/
SExp(SExp carSExp, SExp cdrSExp) {
isAtom = false;
setType(3);
isNIL = false;
setLeft(carSExp);
setRight(cdrSExp);
}
/**
* set/get type
*/
public void setType(int type) {
this.type = type;
}
public int getType() {
return this.type;
}
/**
* set/get value
*/
public void setVal(int val) {
this.val = val;
}
public int getVal() {
return this.val;
}
/**
* set/get name
*/
public void setName(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
/**
* set/get left
*/
public void setLeft(SExp s) {
this.left = s;
}
public SExp getLeft() {
return this.left;
}
/**
* set/get right
*/
public void setRight(SExp s) {
this.right = s;
}
public SExp getRight() {
return this.right;
}
}