-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdemo.cpp
More file actions
83 lines (78 loc) · 1.73 KB
/
demo.cpp
File metadata and controls
83 lines (78 loc) · 1.73 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
#include "obfacros.hpp"
// test for IF/IF_ELSE
size_t test_case_1(int a, int b) {
size_t ret = 0;
FUNCTION_START(ret)
#define SET_RET_FLAG(bit) ret |= (1 << bit)
IF_ELSE(b == 1,
SET_RET_FLAG(1);
) ELSE (
SET_RET_FLAG(2);
IF(a == 1, SET_RET_FLAG(3));
SET_RET_FLAG(4);
);
SET_RET_FLAG(0);
#undef SET_RET_FLAG
FUNCTION_END;
return ret;
}
// test for BLOCK && WHILE
std::string test_case_2(int a) {
std::string ret;
int b;
FUNCTION_START(ret)
WHILE(a > 0,
BLOCK(b = 0);
WHILE(b < a,
BLOCK(ret += '*');
BLOCK(b++);
);
BLOCK(ret += '\n');
BLOCK(a--);
);
FUNCTION_END;
return ret;
}
// test for FOR(BLOCK and _WHILE used)
std::string test_case_3(int a) {
std::string ret;
int b;
FUNCTION_START(ret)
FOR(, a > 0, a--,
FOR(b = 0, b < a, b++,
IF_ELSE(a%2, ret += '*')
ELSE(ret += '#');
);
ret += '\n';
);
FUNCTION_END;
return ret;
}
std::string test_case_prime_numbers(int n) {
std::string ret = "2 ";
int c, count, i = 3;
FUNCTION_START(ret)
FOR(count = 2, count <= n, ,
FOR(c = 2, c <= i - 1, c++,
IF(i%c == 0, goto for_break);
);
for_break:
IF(c == i,
BLOCK(ret += std::to_string(i));
BLOCK(ret += ' ');
BLOCK(count++);
);
i++;
);
FUNCTION_END;
return ret;
}
int main() {
std::cout << test_case_1(0, 0) << " = " << 21 << std::endl;
std::cout << test_case_1(0, 1) << " = " << 3 << std::endl;
std::cout << test_case_1(1, 0) << " = " << 29 << std::endl;
std::cout << test_case_1(1, 1) << " = " << 3 << std::endl;
std::cout << test_case_2(5) << std::endl;
std::cout << test_case_3(5) << std::endl;
std::cout << test_case_prime_numbers(10) << std::endl;
}