-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSymTab.hpp
More file actions
94 lines (70 loc) · 2.54 KB
/
SymTab.hpp
File metadata and controls
94 lines (70 loc) · 2.54 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef EXPRINTER_SYMTAB_HPP
#define EXPRINTER_SYMTAB_HPP
#include <string>
#include <stack>
#include <map>
// #include <vector>
#include "Descriptor.hpp"
#include "DescriptorFunctions.hpp"
class FunctionDefinition;
// This is a flat and integer-based symbol table. It allows for variables to be
// initialized, determines if a give variable has been defined or not, and if
// a variable has been defined, it returns its value.
class SymTab {
public:
SymTab() = default;
~SymTab() = default;
bool isDefined(std::string vName);
bool erase(std::string vName);
void createEntryFor(std::string, int);
void createEntryFor(std::string, double);
void createEntryFor(std::string, bool);
void createEntryFor(std::string, std::string);
void createEntryFor(std::string, const char*);
void setValueFor(std::string, std::shared_ptr<TypeDescriptor>);
// int getValueFor(std::string vName);
TypeDescriptor *getValueFor(std::string);
void openScope();
void activateScope();
void closeScope();
std::shared_ptr<TypeDescriptor> getReturnValue() { return _returnValue; }
void setReturnValue(std::shared_ptr<TypeDescriptor> rv) { _returnValue = rv; }
void setFunction(std::string fName, std::shared_ptr<FunctionDefinition> fDef) { _functionTable[fName] = fDef; }
std::shared_ptr<FunctionDefinition> getFunction(std::string fName) {
if (_functionTable[fName] == nullptr) {
std::cout << fName << " does not exist!\n";
}
return _functionTable[fName];
}
void printIndividualTable(std::map<std::string, std::shared_ptr<TypeDescriptor>>&, std::string);
void dumpTable();
private:
void addDescriptor(std::string, std::shared_ptr<NumberDescriptor>);
std::map<
std::string,
std::shared_ptr<TypeDescriptor>
> globalSymTab;
std::map<
std::string,
std::shared_ptr<FunctionDefinition>
> _functionTable;
std::stack<
std::map< std::string, std::shared_ptr<TypeDescriptor>
>> symTab;
std::map<std::string, std::shared_ptr<TypeDescriptor>> &previousScope{
globalSymTab
};
bool readFromPreviousScope{false};
// std::vector<
// std::map<std::string, std::shared_ptr<TypeDescriptor>>
// > symTab;
std::shared_ptr<TypeDescriptor> _returnValue;
};
#endif //EXPRINTER_SYMTAB_HPP
// STD MOVE
// template<class _Ty> inline
// constexpr typename remove_reference<_Ty>::type&&
// move(_Ty&& _Arg) _NOEXCEPT
// {
// return (static_cast<typename remove_reference<_Ty>::type&&>(_Arg));
// }