-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnvironment.hpp
More file actions
30 lines (25 loc) · 775 Bytes
/
Environment.hpp
File metadata and controls
30 lines (25 loc) · 775 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
// Copyright 2020 <Copyright hulin>
#ifndef ENVIRONMENT_HPP_
#define ENVIRONMENT_HPP_
#include <map>
#include <string>
#include <memory>
#include "./Token.hpp"
using std::map;
using std::string;
using std::shared_ptr;
class Environment: public std::enable_shared_from_this<Environment> {
public:
Environment() = default;
explicit Environment(shared_ptr<Environment> enclosing);
void define(string name, Object value);
void assign(Token name, Object value);
Object get(Token name);
Object getAt(int distance, string name);
void assignAt(int distance, Token name, Object value);
shared_ptr<Environment> ancestor(int distance);
shared_ptr<Environment> enclosing;
private:
map<string, Object> values;
};
#endif // ENVIRONMENT_HPP_