-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenvironment.cpp
More file actions
46 lines (35 loc) · 855 Bytes
/
environment.cpp
File metadata and controls
46 lines (35 loc) · 855 Bytes
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
#include "environment.hpp"
#include <map>
#include <exception>
#include "expression.hpp"
namespace environment {
Expression & Environment::get(const Symbol symbol) {
if (map.find(symbol) != map.end()) {
return map[symbol];
} else {
throw LookupException(symbol);
}
}
void Environment::set(const Symbol symbol, Expression expr) {
if (map.find(symbol) == map.end()) {
map[symbol] = expr;
} else {
throw SetException(symbol);
}
}
void Environment::reset() {
map.clear();
}
Symbol LookupException::getSymbol() {
return this->symbol;
}
const char * LookupException::what () const noexcept {
return symbol.c_str();
}
Symbol SetException::getSymbol() {
return this->symbol;
}
const char * SetException::what () const noexcept {
return symbol.c_str();
}
}