-
Notifications
You must be signed in to change notification settings - Fork 0
/
scope.h
94 lines (74 loc) · 1.33 KB
/
scope.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
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
/*
* scope.h
*
* Created on: Jan 6, 2013
* Author: azk
*/
#ifndef SCOPE_H_
#define SCOPE_H_
#include <stack>
#include <set>
#include <string>
#include <utility>
//Debug
#include <iostream>
/*==== Variable related definitions ====*/
typedef enum
{
NIS_T,
AGORA_T,
BOOL_T,
INT_T,
ERROR_T
} VarType;
typedef struct
{
std::string name;
VarType type;
int offset;
} Variable;
struct VarComp
{
bool operator() (const Variable& var1, const Variable& var2)
{
if (var1.name.compare(var2.name) >= 0)
return false;
return true;
}
};
typedef std::set<Variable,VarComp> VariableSet;
typedef std::pair<VariableSet::iterator, bool> VarSetRet;
/*==== End of Variable definitions ====*/
/*==== Scope related definitions =====*/
typedef enum
{
MAIN_S,
IF_S,
ELSE_S,
WHILE_S,
NONE
} ScopeType;
struct scope
{
// scope(){std::cout << "creating\n";}
// ~scope(){std::cout << "destroying\n";}
ScopeType scopeType;
VariableSet varSet;
bool breakEncountered;
bool curlyBraced;
};
typedef struct scope* Scope;
typedef std::stack<Scope> ScopeStack;
class ScopeGlobal
{
public:
ScopeStack scopeStack;
ScopeGlobal(){}
~ScopeGlobal();
void addVar(VarType varType, std::string varName)
{
std::cout << "Got: " << varName << " " << (int)varType << std::endl;
}
};
/*==== End of Scope definitions ====*/
#endif /* SCOPE_H_ */