-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscope.cpp
More file actions
51 lines (42 loc) · 901 Bytes
/
scope.cpp
File metadata and controls
51 lines (42 loc) · 901 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
47
48
49
50
51
//
// Created by maruf on 4/9/22.
//
#include "scope.h"
int gcounter = 0;
scope::scope(std::shared_ptr<scope> parent)
{
this->parent_scope_ = parent;
}
void scope::set(std::string identifier, std::shared_ptr<value> val)
{
assert(identifier.length() > 0);
value_map_[identifier] = val;
}
std::shared_ptr<value> scope::get(std::string identifier)
{
if (value_map_.find(identifier) == value_map_.end())
{
if (this->parent_scope_ == nullptr)
{
return std::make_shared<value>();
}
else
{
return parent_scope_->get(identifier);
}
}
return value_map_[identifier];
}
scope::~scope()
{
}
void scope::print()
{
for(auto i: value_map_)
{
std::cout << i.first << " = ";
i.second->print();
std::cout << std::endl;
}
std::cout << "-----------------" << std::endl;
}