-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEnv.h
55 lines (38 loc) · 1.02 KB
/
Env.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
#ifndef ENV_H
#define ENV_H
#include <string>
#include <vector>
#include <unordered_map>
namespace lx {
class Expr;
class Frame
{
public:
void add_symbol (const std::string& var, Expr* val);
bool set_symbol (const std::string& var, Expr* val);
const Expr* query_symbol (const std::string& var) const;
private:
std::unordered_map<std::string, Expr*> _variables;
};
class Env
{
public:
Env (Env* upperEnv) :
_upperEnv(upperEnv), _frame()
{}
Env (Env& upperEnv) :
_upperEnv(&upperEnv), _frame()
{}
~Env () = default;
void extend_symbols (std::vector<std::string>& params,
std::vector<Expr*>& args);
const Expr* query_symbol (const std::string& var) const;
bool set_symbol (const std::string& var, Expr* val);
void define_symbol (const std::string& var, Expr* val);
public:
Env* _upperEnv;
private:
Frame _frame;
};
}
#endif // ENV_H