-
Notifications
You must be signed in to change notification settings - Fork 0
/
Expression.h
45 lines (45 loc) · 1.89 KB
/
Expression.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
class Expression{
public:
vector<String<25>> postfix;
void input(char *str) {
vector<char> operator_stack;
String<25> key;
for (char c; (c = *str); ++str) {
switch (c) {
case '|':
for (; !operator_stack.empty() && operator_stack.back() != '('; operator_stack.pop_back())
postfix.push_back(String<25>(operator_stack.back()));
operator_stack.push_back(c);
break;
case '&':
for (; !operator_stack.empty() && operator_stack.back() != '|' && operator_stack.back() != '('; operator_stack.pop_back())
postfix.push_back(String<25>(operator_stack.back()));
operator_stack.push_back(c);
break;
case '!':
for (; !operator_stack.empty() && operator_stack.back() == '!'; operator_stack.pop_back())
postfix.push_back(String<25>(operator_stack.back()));
operator_stack.push_back(c);
break;
case '(':
operator_stack.push_back('(');
break;
case ')':
for (; operator_stack.back() != '('; operator_stack.pop_back())
postfix.push_back(String<25>(operator_stack.back()));
operator_stack.pop_back();
break;
case '[':
key.input_ex(str);
postfix.push_back(key);
break;
default:
key.input(str), --str;
postfix.push_back(key);
break;
}
}
for (; !operator_stack.empty(); operator_stack.pop_back())
postfix.push_back(String<25>(operator_stack.back()));
}
};