-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnv.h
More file actions
46 lines (37 loc) · 844 Bytes
/
Env.h
File metadata and controls
46 lines (37 loc) · 844 Bytes
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
//
// Created by Anirudh Lath on 3/20/22.
//
#ifndef MSDSCRIPT_ENV_H
#define MSDSCRIPT_ENV_H
#include <string>
#include "pointer.h"
class Val;
CLASS(Env) {
public:
static PTR(Env)empty;
virtual PTR(Val)lookup(std::string find_name) = 0;
};
class EmptyEnv : public Env {
PTR(Val)lookup(std::string find_name) {
throw std::runtime_error("free variable: "
+ find_name);
}
};
class ExtendedEnv : public Env {
std::string name;
PTR(Val)val;
PTR(Env)rest;
public:
ExtendedEnv(std::string name,
PTR(Val)val,
PTR(Env)rest);
PTR(Val)lookup(std::string find_name) {
if (find_name == name) {
return val;
}
else {
return rest->lookup(find_name);
}
}
};
#endif //MSDSCRIPT_ENV_H