-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.cpp
More file actions
86 lines (72 loc) · 2.19 KB
/
env.cpp
File metadata and controls
86 lines (72 loc) · 2.19 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "env.hpp"
namespace environnement{
std::string null("null");
int error = 0;
char *hadelerror[]={"New declaration","Not A number","Variable not declared in this scope"};
bool is_null(std::string& b){
return &b == &null;
}
int env::new_number(const char * id,const char * val){
bool found = namesList.find(id);
if(found){
error = 1;
return -1;
}
if( numbersList.new_number(id,val) == -1){
error = 2;
return -1;
};
namesList.add(id,"NUMBER");
error = 0;
return 1;
}
int env::delete_var(const char * id){
names::base name = namesList.get(id);
if(names::is_null(name)){
error = 3;
return -1;
}
if(name.is("NUMBER")){
numbersList.del(id);
}
error = 0;
return 1;
}
std::string env::get(const char * id){
names::base name = namesList.get(id);
std::string val;
if(names::is_null(name)){
error = 3;
return null;
}
if(name.is("NUMBER")){
error = 0;
val = numbersList.get(id).c_str();
}
return val;
}
std::string env::update(const char * id,const char * value){
names::base name = namesList.get(id);
std::string val;
if(names::is_null(name)){
error = 3;
return null;
}
if(name.is("NUMBER")){
if(number::testdigite(value)){
error = 0;
val = numbersList.set(id,value).c_str();
}else{
error = 2;
return null;
}
}
return val;
}
env::env(/* args */)
{
}
env::~env()
{
}
}