-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexecute.h
172 lines (163 loc) · 4.85 KB
/
execute.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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#ifndef COMPILE_H
#define COMPILE_H
#include<iostream>
#include<list>
#include<string>
#include<map>
#include<stack>
#include"variable.h"
#include"keyword.h"
#include"algo.h"
class execute{
public:
list<list<string> > code;
variable var;
keyword key;
algo alg;
stack<string> flow;
int check_balance;
int loop_balance;
execute(list<list<string> > lol);
void executing();
void show_memory();
bool show_file();
};
execute::execute(list<list<string> > lol){
code=lol;
alg.varib=&var;
loop_balance=0;
check_balance=0;
}
void execute::executing(){
list<list<string> >::iterator itr;
for(itr=code.begin();itr != code.end();itr++){
list<string>tl=*itr;
list<string>::iterator it=tl.begin();
advance(it,1);
alg.l=tl;
if(*it=="display"){
alg.display();
}
else if(*it=="fetch"){
alg.fetch();
}
else if(*it=="declare"){
alg.declare();
}
else if(*it=="check"){
check_balance++;
if(!alg.condition()){
int temp=check_balance;
while(check_balance!=(temp-1)){
advance(itr,1);
list<string>tl=*itr;
auto it=tl.begin();
advance(it,1);
if(*it=="check" || *it=="otherwise"){
check_balance++;
}
else if(*it=="checkit" || *it=="leaveit"){
check_balance--;
}
}
advance(itr,1);
list<string>tl=*itr;
auto it_oth=tl.begin();
advance(it_oth,1);
if(*it_oth!="otherwise"){
advance(itr,-1);
}
}
}
else if(*it=="checkit"){
check_balance--;
}
else if(*it=="otherwise"){
check_balance--;
int temp=check_balance;
while(check_balance!=(temp-1)){
advance(itr,1);
list<string>tl=*itr;
auto it=tl.begin();
advance(it,1);
if(*it=="check" || *it=="otherwise"){
check_balance++;
}
else if(*it=="checkit" || *it=="leaveit"){
check_balance--;
}
}
}
else if(*it=="leaveit"){
check_balance--;
}
else if(*it=="loop"){
loop_balance++;
if(alg.condition()){
advance(it,-1);
if(flow.empty()){
flow.push(*it);
}
else{
if(*it!=flow.top()){
flow.push(*it);
}
}
advance(it,1);
}
else{
int temp=loop_balance;
while(loop_balance!=(temp-1)){
advance(itr,1);
list<string>tl=*itr;
auto it=tl.begin();
advance(it,1);
if(*it=="loop"){
loop_balance++;
}
else if(*it=="loopit"){
loop_balance--;
}
}
if(!flow.empty()){
flow.pop();
}
}
}
else if(*it=="loopit"){
int line=(alg.string_to_int(flow.top()))-2;
itr=code.begin();
advance(itr,line);
loop_balance--;
}
else if(*it=="BEGIN"){
}
else if(*it=="END"){
}
else{
alg.expression();
}
}
alg.show_errors();
var.show_errors();
}
void execute::show_memory(){
map<string,string>::iterator it;
cout<<"\nMemory:\n";
for(it=var.variables.begin();it!=var.variables.end();it++){
cout<<it->first<<" = "<<it->second<<"\n";
}
}
bool execute::show_file(){
list<list<string> >::iterator itr;
for (itr=code.begin(); itr != code.end(); itr++){
list<string>tl=*itr;
list<string>::iterator it;
cout<<"\t";
for(it=tl.begin();it!=tl.end();it++){
cout<<*it<<" ";
}
cout<<";"<<endl;
}
}
#endif // COMPILE_H