-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptimiser.cpp
72 lines (65 loc) · 1.71 KB
/
optimiser.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
#include "optimiser.hpp"
void optim(std::string& program, std::vector<insn_t>& opt_program)
{
program =
std::regex_replace
(program, std::regex("[ A-Za-z0-9\n]{1,}"), std::string());
replace_all(program, "[-]", "@");
replace_all(program, "[+]", "@");
if(!opt_program.empty()) { opt_program.clear(); }
insn_t temp = { 0, COMMENT };
for(int i = 0; i < program.size(); i++)
{
int count = 1;
while(program[i] == program[i+1])
{
if
(
(program[i] == '[') ||
(program[i] == ']') ||
(program[i] == ',') ||
(program[i] == '\0')
)
{ break; }
count++;
i++;
}
temp.count = count;
switch(program[i])
{
case '[':
temp.type = LBRACKET;
break;
case ']':
temp.type = RBRACKET;
break;
case '>':
temp.type = RIGHT;
break;
case '<':
temp.type = LEFT;
break;
case '+':
temp.type = PLUS;
break;
case '-':
temp.type = MINUS;
break;
case '.':
temp.type = DOT;
break;
case ',':
temp.type = COMMA;
break;
case '@':
temp.type = CLEAR;
break;
default:
temp.type = COMMENT;
break;
}
if(temp.type == COMMENT) { continue; }
opt_program.push_back(temp);
}
return;
}