-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting_do.cpp
88 lines (63 loc) · 1.71 KB
/
testing_do.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include <stack>
#include <string>
#include <map>
#include <functional>
#include <cctype>
#include <sstream>
#include <queue>
#include <optional>
#include <vector>
std::stack<int> intStack;
void do_loop(std::stack<std::string> stringStack){
// 10 0 do i . loop ;
//i . loop ;
std::queue<std::string> looped_queue;
std::string current = stringStack.top();
while(current != "loop"){
current = stringStack.top();
stringStack.pop();
looped_queue.push(current);
}
int start = intStack.top();
intStack.pop();
int end = intStack.top();
intStack.pop();
std::string final_val = "";
if (looped_queue.front() == "i"){
//pop i
looped_queue.pop();
// pop .
looped_queue.pop();
std::string luke = looped_queue.front();
while(!looped_queue.empty()){
std::string extra = looped_queue.front();
looped_queue.pop();
if (extra != "loop" && extra != ";"){
final_val += extra;
}
}
for (int i = start; i < end; i++) {
std::cout << i << " " << final_val << std::endl;
}
} else{
for (int i = start; i < end; i++) {
std::cout << i << std::endl;
}
}
}
int main(){
intStack.push(10);
intStack.push(0);
std::stack<std::string> string_stack;
//funcMap["do"] = do_loop;
//do i . 5 loop ;
//0 5
//1 5
string_stack.push(";");
string_stack.push("loop");
string_stack.push("5");
string_stack.push(".");
string_stack.push("i");
do_loop(string_stack);
}