-
Notifications
You must be signed in to change notification settings - Fork 0
/
SymTab.cpp
46 lines (39 loc) · 1.55 KB
/
SymTab.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
//
// Created by smith on 3/20/2019.
//
#include <iostream>
#include "SymTab.hpp"
void SymTab::setValueFor(std::string vName, TypeDescriptor value) {
// Define a variable by setting its initial value.
if(value.getTypeValue() == 0) { // Int
//std::cout << "[DEBUG] "<< vName << " <- " << value.getIntValue() << std::endl;
symTab[vName] = value.getIntValue();
}
else if(value.getTypeValue() == 1) { // Double
//std::cout << "[DEBUG] "<< vName << " <- " << value.getDoubleValue() << std::endl;
symTab[vName] = value.getDoubleValue();
}
else if(value.getTypeValue() == 2) { // String
//std::cout << "[DEBUG] "<< vName << " <- " << value.getStringValue() << std::endl;
symTab[vName] = value.getStringValue();
}
else if(value.getTypeValue() == 3) { // Bool
//std::cout << "[DEBUG] "<< vName << " <- " << value.getBoolValue() << std::endl;
symTab[vName] = value.getBoolValue();
}
else if(value.getTypeValue() == 4) { // Array
//std::cout << "[DEBUG] "<< vName << " <- " << value << std::endl;
symTab[vName] = value;
}
}
bool SymTab::isDefined(std::string vName) {
return symTab.find(vName) != symTab.end();
}
TypeDescriptor SymTab::getValueFor(std::string vName) {
if( ! isDefined(vName)) {
std::cout << "SymTab::getValueFor: " << vName << " has not been defined.\n";
exit(1);
}
//std::cout << "SymTab::getValueFor: " << vName << " contains " << symTab.find(vName)->second << std::endl;
return symTab.find(vName)->second;
}