-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidentifier.cpp
70 lines (62 loc) · 1.91 KB
/
identifier.cpp
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
#include "identifier.h"
Identifier::Identifier(const Identifier &source){
name = source.name;
v_string = source.v_string;
type = source.type;
v_int = source.v_int;
v_double = source.v_double;
v_bool = source.v_bool;
}
//Identifier::Identifier(const Token &source){
// switch(source.get_type()){
// case IDENTIFIER:
// name = source.name;
// v_string = source.v_string;
// type = source.type;
// v_int = source.v_int;
// v_double = source.v_double;
// v_bool = source.v_bool;
// break;
// case BOOL:
//
// }
//
//}
IdentifierStack::IdentifierStack(int depth, bool log){
size = depth;
data = new Identifier[depth];
first_free = data;
block_indentions.push(0);
push(Identifier("Responce"));
push(Identifier("Environment"));
logging = log;
}
void IdentifierStack::push(Identifier what){
if(first_free - data == size)
throw bad_jaba(E_GLOBAL, "identifier stack overflow");
*(first_free++) = what;
}
Identifier* IdentifierStack::get(string name){
for(int i = first_free - data; i > 0; i--){
if(data[i-1].get_name() == name)
return data + i - 1;
}
return 0;
}
void IdentifierStack::drop(){
if(block_indentions.size() <= 1)
throw bad_jaba(E_GLOBAL, "attempt to drop the whole identifier stack");
first_free = data + block_indentions.top();
if(logging) clog << "block dropped @ " << block_indentions.top() << " from bottom" << endl;
block_indentions.pop();
}
void IdentifierStack::set_block(){
block_indentions.push(first_free - data);
if(logging) clog << "block set @ " << first_free - data << " from bottom" << endl;
}
bool IdentifierStack::defined_in_cur_block(string name){
for(int i = block_indentions.top(); i < first_free - data; i++)
if(data[i].get_name() == name)
return true;
return false;
}