-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymboltable.hh
101 lines (83 loc) · 2.09 KB
/
symboltable.hh
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
95
96
97
98
99
100
101
#ifndef SYMBOL_TABLE_HH
#define SYMBOL_TABLE_HH
#include<string>
#include<list>
using namespace std;
class SymbolTableEntry;
typedef enum
{
INT,
DOUBLE
} DataType;
extern DataType a;
typedef enum
{
LOCAL
} TableScope;
class SymbolTable
{
list<SymbolTableEntry *> varTable;
TableScope scope;
//data members added for code generation
int totalSize;
public:
SymbolTable();
~SymbolTable();
TableScope getTableScope();
void setTableScope(TableScope);
void print(ostream &);
void pushSymbol(SymbolTableEntry *);
bool variableInSymbolListCheck(string);
SymbolTableEntry & getSymbolTableEntry(string variablename);
//functions added for code generation
int getSizeOfType(DataType);
void assignOffsetsToSymbols();
int size();
};
class SymbolTableEntry
{
string variablename;
DataType variabledatatype;
TableScope scope;
int lineNumber;
//data members added for code generation
int startOffset;
int endOffset;
RegisterDescriptor * registerDescription;
public:
SymbolTableEntry();
SymbolTableEntry(string &, DataType , int);
~SymbolTableEntry();
int getLineNumber();
void setSymbolScope(TableScope sp);
TableScope getSymbolScope();
DataType getDataType();
void setDataType(DataType);
string getVariableName();
//functions added for code generation
void setStartOffset(int num);
int getStartOffset();
void setEndOffset(int num);
int getEndOffset();
RegisterDescriptor * getRegister();
void setRegister(RegisterDescriptor * reg);
};
class toks{
string tok_name;
string tok;
int lineno;
public:
toks(string tn,string t,int l){
tok_name=tn;
tok=t;
lineno=l;
}
void print(ostream & o){
o<<"Token Name: ";
o.width(8);
o<<tok_name<<"\t";
o<<"Token: "<<tok<<"\t";o.width(8);
o<<"Lineno: "<<lineno<<"\n";
}
};
#endif