-
Notifications
You must be signed in to change notification settings - Fork 0
/
Expression.hpp
154 lines (121 loc) · 3.17 KB
/
Expression.hpp
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
#pragma once
#include "Context.hpp"
#include "Identifier.hpp"
#include "Value.hpp"
#include <vector>
class Selector;
class Context;
class Expression
{
public:
Expression() {}
virtual ~Expression() {}
virtual Value* evaluate(Context&);
};
class ExpressionSequence
{
public:
ExpressionSequence() {}
~ExpressionSequence() {}
void addExpression(Expression* expression)
{
expressions.push_back(expression);
}
std::vector<Expression*> expressions;
};
class VariableExpression : public Expression
{
public:
VariableExpression(Identifier identifier): identifier(identifier) {}
virtual ~VariableExpression() {}
virtual Value* evaluate(Context& context);
Identifier identifier;
};
class SelectExpression : public Expression
{
public:
SelectExpression(Identifier identifier, Selector* selector):
identifier(identifier), selector(selector) {}
virtual ~SelectExpression() {}
virtual Value* evaluate(Context& context);
Identifier identifier;
Selector* selector;
};
class ConstExpression : public Expression
{
public:
ConstExpression(Value* value): value(value) {}
virtual ~ConstExpression() {}
virtual Value* evaluate(Context& context);
Value* value;
};
enum class BinaryOperator
{
PLUS = 1,
MINUS = 2,
DIV = 3,
MOD = 4,
DIVIDE = 5,
MULTIPLY = 6,
OR = 7,
AND = 8,
EQUAL = 9,
NOT_EQUAL = 10,
LESS = 11,
GREATER = 12,
LESS_EQUAL = 13,
GREATER_EQUAL = 14
};
namespace binary_operator {
Value* plus(Value* leftOperand, Value* rightOperand);
Value* minus(Value* leftOperand, Value* rightOperand);
Value* div(Value* leftOperand, Value* rightOperand);
Value* mod(Value* leftOperand, Value* rightOperand);
Value* multiply(Value* leftOperand, Value* rightOperand);
Value* orOperator(Value* leftOperand, Value* rightOperand);
Value* andOperator(Value* leftOperand, Value* rightOperand);
Value* equal(Value* leftOperand, Value* rightOperand);
Value* notEqual(Value* leftOperand, Value* rightOperand);
Value* less(Value* leftOperand, Value* rightOperand);
Value* greater(Value* leftOperand, Value* rightOperand);
Value* lessEqual(Value* leftOperand, Value* rightOperand);
Value* greaterEqual(Value* leftOperand, Value* rightOperand);
}; // namespace binary_operator
class BinaryOperatorExpression : public Expression
{
public:
BinaryOperatorExpression(Expression* leftOperand,
BinaryOperator Operator,
Expression* rightOperand) : leftOperand(leftOperand),
Operator(Operator),
rightOperand(rightOperand)
{
}
virtual ~BinaryOperatorExpression() {}
virtual Value* evaluate(Context& context);
Expression* leftOperand;
BinaryOperator Operator;
Expression* rightOperand;
};
enum class UnaryOperator
{
NEGATION = 1,
COMPLEMENT = 2
};
namespace unary_operator {
Value* negation(Value* operand);
Value* complement(Value* operand);
}; // namespace unary_operator
class UnaryOperatorExpression : public Expression
{
public:
UnaryOperatorExpression(Expression* operand,
UnaryOperator Operator) : operand(operand),
Operator(Operator)
{
}
virtual ~UnaryOperatorExpression() {}
virtual Value* evaluate(Context& context);
Expression* operand;
UnaryOperator Operator;
};