-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSymbol.h
38 lines (33 loc) · 1.03 KB
/
Symbol.h
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
#pragma once
#include <string>
#include <vector>
#include <cstdlib>
class SymbolTableClass{
struct Variable {
std::string mLabel;
int mValue;
};
public:
SymbolTableClass();
bool Exists(std::string s);
// returns true if <s> is already in the symbol table.
void AddEntry(std::string s);
// adds <s> to the symbol table,
// or quits if it was already there
int GetValue(std::string s);
// returns the current value of variable <s>, when
// interpreting. Meaningless for Coding and Executing.
// Prints a message and quits if variable s does not exist.
void SetValue(std::string s, int v);
// sets variable <s> to the given value, when interpreting.
// Meaningless for Coding and Executing.
// Prints a message and quits if variable s does not exist.
int GetIndex(std::string s);
// returns the index of where variable <s> is.
// returns -1 if variable <s> is not there.
int GetCount();
// returns the current number of variables in the symbol
// table.
private:
std::vector<Variable> sTable;
};