-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControlFlow.h
92 lines (81 loc) · 2.07 KB
/
ControlFlow.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
#ifndef H_CONTROLFLOW
#define H_CONTROLFLOW
#include "stdafx.h"
#include <stack>
#define SEQUENTIAL 4096
#define WHILE 4097
#define FOR 4098
#define IF 4099
#define ELIF 4100
#define ELSE 4101
#define LEAF 4102
#define RETURN 4103
#define BREAK 4104
#define CONTINUE 4015
#define FOREACH 4016
#define ERROR (-0x7f7f7f)
struct RuaCommand {
int cmd;
uint para;
};
typedef std::vector<RuaCommand> RuaSentence;
struct RuaControlFLow {
int type;
std::vector<RuaSentence> cmds;
std::vector<RuaControlFLow> cfs;
RuaControlFLow(int t): type(t) {}
/*void Print(RuaSentence st) {
for (auto cmd : st) printf("%d, %d; ", cmd.cmd, cmd.para);
}
void Print() {
switch (type)
{
case FOR:
printf("FOR ( ");
Print(cmds[0]);
printf(" || ");
Print(cmds[1]);
printf(" || ");
Print(cmds[2]);
printf(" ) \n { ");
cfs[0].Print();
printf(" } \n");
break;
case SEQUENTIAL:
for(auto st : cfs) {
st.Print();
putchar('\n');
}
for(auto st : cmds) {
Print(st);
putchar('\n');
}
break;
case IF:
printf("IF ( ");
Print(cmds[0]);
printf(" ) \n { ");
cfs[0].Print();
for (int i = 1; i < cmds.size(); i++) {
printf(" } \n ELSEIF ( ");
Print(cmds[1]);
printf(" ) \n { ");
cfs[i].Print();
}
if (cfs.size() > cmds.size()) {
printf(" } \n ELSE { ");
cfs[cfs.size() - 1].Print();
}
printf(" } \n");
break;
case WHILE:
printf("WHILE ( ");
Print(cmds[0]);
printf(" ) \n { ");
cfs[0].Print();
printf(" }\n");
break;
}
}*/
};
#endif //H_CONTROLFLOW