-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymbol.cpp
More file actions
69 lines (60 loc) · 1.39 KB
/
Copy pathSymbol.cpp
File metadata and controls
69 lines (60 loc) · 1.39 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
#include "Symbol.h"
#include <cstdlib>
#include <iostream>
SymbolTableClass::SymbolTableClass(){
}
bool SymbolTableClass::Exists(std::string s){
for( int i = 0; i < sTable.size(); i++){
if ( s == sTable[i].mLabel){
return true;
}
}
return false;
}
void SymbolTableClass::AddEntry(std::string s){
if (!Exists(s)){
Variable newVar;
newVar.mLabel = s;
newVar.mValue = 0;
sTable.push_back(newVar);
}
else{
std::cerr << "Error duplicate variable.";
exit(1);
}
}
int SymbolTableClass::GetValue(std::string s){
if (Exists(s)){
for( int i = 0; i < sTable.size(); i++){
if ( s == sTable[i].mLabel){
return sTable[i].mValue;
}
}
}
std::cerr << "Variable" << s << "does not exists.";
exit(1);
}
void SymbolTableClass::SetValue(std::string s, int v){
if (Exists(s)){
for( int i = 0; i < sTable.size(); i++){
if ( s == sTable[i].mLabel){
sTable[i].mValue = v;
}
}
}
else{
std::cerr << "Error setting value";
exit(1);
}
}
int SymbolTableClass::GetIndex(std::string s){
for( int i = 0; i < sTable.size(); i++){
if ( s == sTable[i].mLabel){
return i;
}
}
return -1;
}
int SymbolTableClass::GetCount(){
return sTable.size();
}