-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSExpression.cpp
84 lines (68 loc) · 1.78 KB
/
SExpression.cpp
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
//
// Created by Kalyan Khandrika on 3/2/17.
//
#include "SExpression.h"
map<string,SExpression*> SExpression::identifiers;
void SExpression::InitializeDefaultSymbolizAtoms(){
SExpression * nilExp = new SExpression(SYMBOLICATOM);
nilExp->setName("NIL");
identifiers["NIL"] = nilExp;
SExpression * trueExp = new SExpression(SYMBOLICATOM);
trueExp->setName("T");
identifiers["T"] = trueExp;
}
void SExpression::DeleteSymbolicAtoms(){
for(auto it = identifiers.begin();it != identifiers.end(); it++){
SExpression * symAtom = it->second;
it->second = NULL;
delete(symAtom);
}
}
SExpression* SExpression::symbolicAtom(string str){
if(identifiers.find(str) == identifiers.end() || identifiers[str] == NULL){
SExpression * ne = new SExpression(SYMBOLICATOM);
ne->setName(str);
identifiers[str] = ne;
return ne;
}
else
return identifiers[str];
}
SExpression::~SExpression(){
if(getType() == NONATOM){
delete getLeft();
delete getRight();
}
}
SExpression::SExpression(SExpType aType):type(aType){
}
SExpType SExpression::getType() const {
return type;
}
void SExpression::setType(SExpType type) {
SExpression::type = type;
}
int SExpression::getVal() const {
return val;
}
void SExpression::setVal(int val) {
SExpression::val = val;
}
const string &SExpression::getName() const {
return name;
}
void SExpression::setName(const string &name) {
SExpression::name = name;
}
SExpression *SExpression::getLeft() const {
return left;
}
void SExpression::setLeft(SExpression *left) {
SExpression::left = left;
}
SExpression *SExpression::getRight() const {
return right;
}
void SExpression::setRight(SExpression *right) {
SExpression::right = right;
}