-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymbolTable.cpp
35 lines (35 loc) · 972 Bytes
/
symbolTable.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
#include "symbolTable.h"
// add a variable to the table by copy
void symbolTable::addVariable(variable v) {
variables[v.myName()] = v;
}
// get a pointer to a variable that is in the table
variable* symbolTable::getVariable(string s) {
if(isVariable(s)) {
return &(variables[s]);
} else {
return nullptr;
}
}
// update the value of a variable that is in the table
void symbolTable::updateVariable(string s, double d) {
if(isVariable(s)) {
variables[s].setValue(d);
} else {
// no such variable error
return;
}
}
// check if a string is a name of a variable in the table
bool symbolTable::isVariable(string s){
if(variables.find(s) != variables.end()) {
return true;
} else {
return false;
}
}
// bind a variable to a strings that is inputed.
void symbolTable::bindVariable(string name, string bindTo) {
variable* var = this->getVariable(name);
binded[bindTo] = *var;
}