ExpressionContainer.hh
5.11 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#ifndef EXPRESSIONCONTAINER_HH_
#define EXPRESSIONCONTAINER_HH_
namespace AMDA {
namespace parser {
struct op_power{};
struct op_powerTen{};
struct Operator {
explicit Operator(std::string ihmSymbol, std::string kernelSymbol) : ihmSymbol(ihmSymbol), kernelSymbol(kernelSymbol) {};
std::string ihmSymbol = "";
std::string kernelSymbol = "";
};
namespace Expression{
typedef std::string var;
template <typename tag> struct binop;
template <typename tag> struct funcop;
struct BinaryOperation;
struct UnaryOperation;
struct FunctionOperation;
typedef boost::variant<
var,
boost::recursive_wrapper<UnaryOperation>,
boost::recursive_wrapper<BinaryOperation>,
boost::recursive_wrapper<FunctionOperation>,
boost::recursive_wrapper<funcop<op_power> >,
boost::recursive_wrapper<binop<op_powerTen> >
> ExpressionContainer;
struct FunctionOperation
{
explicit FunctionOperation(std::string func, const ExpressionContainer& arg1) : func(func) {
args.push_back(arg1);
}
explicit FunctionOperation(std::string func, const ExpressionContainer& arg1, const ExpressionContainer& arg2) : func(func) {
args.push_back(arg1);
args.push_back(arg2);
}
explicit FunctionOperation(std::string func, const ExpressionContainer& arg1, const ExpressionContainer& arg2, const ExpressionContainer& arg3) : func(func) {
args.push_back(arg1);
args.push_back(arg2);
args.push_back(arg3);
}
std::string func;
std::vector<ExpressionContainer> args;
};
struct UnaryOperation
{
explicit UnaryOperation(Operator op, const ExpressionContainer& e) : op(op), e(e) {}
Operator op;
ExpressionContainer e;
};
struct BinaryOperation
{
explicit BinaryOperation(const ExpressionContainer& l, Operator op, const ExpressionContainer& r) : l(l), op(op), r(r) { }
ExpressionContainer l;
Operator op;
ExpressionContainer r;
};
struct NotOperation : UnaryOperation
{
explicit NotOperation(const ExpressionContainer& e) : UnaryOperation(Operator("!","!"), e) {}
};
struct MinusSignOperation : UnaryOperation
{
explicit MinusSignOperation(const ExpressionContainer& e) : UnaryOperation(Operator("-","-"), e) {}
};
struct PlusSignOperation : UnaryOperation
{
explicit PlusSignOperation(const ExpressionContainer& e) : UnaryOperation(Operator("+","+"), e) {}
};
struct ConstantOperation : UnaryOperation
{
explicit ConstantOperation(const ExpressionContainer& e) : UnaryOperation(Operator("@",""), e) {}
};
struct PowerTenOperation : BinaryOperation
{
explicit PowerTenOperation(const ExpressionContainer& l, const ExpressionContainer& r) : BinaryOperation(l, Operator("e","e"), r) { }
};
struct SumOperation : BinaryOperation
{
explicit SumOperation(const ExpressionContainer& l, const ExpressionContainer& r) : BinaryOperation(l, Operator("+","+"), r) { }
};
struct DifferenceOperation : BinaryOperation
{
explicit DifferenceOperation(const ExpressionContainer& l, const ExpressionContainer& r) : BinaryOperation(l, Operator("-","-"), r) { }
};
struct FactorOperation : BinaryOperation
{
explicit FactorOperation(const ExpressionContainer& l, const ExpressionContainer& r) : BinaryOperation(l, Operator("*","*"), r) { }
};
struct DivisionOperation : BinaryOperation
{
explicit DivisionOperation(const ExpressionContainer& l, const ExpressionContainer& r) : BinaryOperation(l, Operator("/","/"), r) { }
};
struct EqualOperation : BinaryOperation
{
explicit EqualOperation(const ExpressionContainer& l, const ExpressionContainer& r) : BinaryOperation(l, Operator("=","=="), r) { }
};
struct UnequalOperation : BinaryOperation
{
explicit UnequalOperation(const ExpressionContainer& l, const ExpressionContainer& r) : BinaryOperation(l, Operator("!=","!="), r) { }
};
struct GreaterOperation : BinaryOperation
{
explicit GreaterOperation(const ExpressionContainer& l, const ExpressionContainer& r) : BinaryOperation(l, Operator(">",">"), r) { }
};
struct GreaterOrEqualOperation : BinaryOperation
{
explicit GreaterOrEqualOperation(const ExpressionContainer& l, const ExpressionContainer& r) : BinaryOperation(l, Operator(">=",">="), r) { }
};
struct LowerOperation : BinaryOperation
{
explicit LowerOperation(const ExpressionContainer& l, const ExpressionContainer& r) : BinaryOperation(l, Operator("<","<"), r) { }
};
struct LowerOrEqualOperation : BinaryOperation
{
explicit LowerOrEqualOperation(const ExpressionContainer& l, const ExpressionContainer& r) : BinaryOperation(l, Operator("<=","<="), r) { }
};
struct AndOperation : BinaryOperation
{
explicit AndOperation(const ExpressionContainer& l, const ExpressionContainer& r) : BinaryOperation(l, Operator("&","&&"), r) { }
};
struct OrOperation : BinaryOperation
{
explicit OrOperation(const ExpressionContainer& l, const ExpressionContainer& r) : BinaryOperation(l, Operator("|","||"), r) { }
};
template <typename tag> struct binop
{
explicit binop(const ExpressionContainer& l, const ExpressionContainer& r) : oper1(l), oper2(r) { }
ExpressionContainer oper1, oper2;
};
template <typename tag> struct funcop
{
explicit funcop(const ExpressionContainer& l, const ExpressionContainer& r) : oper1(l), oper2(r) { }
ExpressionContainer oper1, oper2;
};
} /* namespace Expression */
} /* namespace parser */
} /* namespace AMDA */
#endif