-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnvironment.h
30 lines (26 loc) · 912 Bytes
/
Environment.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
#ifndef ENVIRONMENT_H
#define ENVIRONMENT_H
#include "Utils.h"
#include "Token.h"
#include "RuntimeError.h"
interface IEnvironment {
public:
virtual void define(const String& name, const Object& value) const = 0;
virtual Object get(const Token& name) const = 0;
virtual void assign(Token name, Object value) const = 0;
virtual void assign(String name, Object value) const = 0;
virtual void deleteVar(String name) = 0;
};
class Environment : public IEnvironment {
public:
explicit Environment();
void define(const String& name, const Object& value) const override;
Object get(const Token& name) const override;
void assign(Token name, Object value) const override;
void assign(String name, Object value) const override;
void deleteVar(String name) override;
private:
mutable Map<String, Object> values{};
std::shared_ptr<Environment> enclosing{};
};
#endif