-
Notifications
You must be signed in to change notification settings - Fork 0
/
Expression.cpp
104 lines (82 loc) · 2.2 KB
/
Expression.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
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
#include "Value.hpp"
#include "Expression.hpp"
Value* Expression::evaluate(Context&)
{
}
Value* VariableExpression::evaluate(Context& context)
{
return context.getVariableReference(identifier);
}
Value* SelectExpression::evaluate(Context& context)
{
return selector->select(context.getVariableReference(identifier), &context);
}
Value* ConstExpression::evaluate(Context& context)
{
return value;
}
Value* BinaryOperatorExpression::evaluate(Context& context)
{
Value* leftValue = leftOperand->evaluate(context);
Value* rightValue = rightOperand->evaluate(context);
switch (Operator)
{
case BinaryOperator::PLUS:
return leftValue->plus(rightValue);
break;
case BinaryOperator::MINUS:
return leftValue->minus(rightValue);
break;
case BinaryOperator::DIV:
return leftValue->div(rightValue);
break;
case BinaryOperator::MOD:
return leftValue->mod(rightValue);
break;
case BinaryOperator::DIVIDE:
return leftValue->divide(rightValue);
break;
case BinaryOperator::MULTIPLY:
return leftValue->multiply(rightValue);
break;
case BinaryOperator::OR:
return leftValue->orOperator(rightValue);
break;
case BinaryOperator::AND:
return leftValue->andOperator(rightValue);
break;
case BinaryOperator::EQUAL:
return leftValue->equal(rightValue);
break;
case BinaryOperator::NOT_EQUAL:
return leftValue->notEqual(rightValue);
break;
case BinaryOperator::LESS:
return leftValue->less(rightValue);
break;
case BinaryOperator::GREATER:
return leftValue->greater(rightValue);
break;
case BinaryOperator::LESS_EQUAL:
return leftValue->lessEqual(rightValue);
break;
case BinaryOperator::GREATER_EQUAL:
return leftValue->greaterEqual(rightValue);
break;
}
throw unknown_operator("Got unknown operator during BinaryOperatorExpression evaluation");
}
Value* UnaryOperatorExpression::evaluate(Context& context)
{
Value* operandValue = operand->evaluate(context);
switch (Operator)
{
case UnaryOperator::NEGATION:
return operandValue->negation();
break;
case UnaryOperator::COMPLEMENT:
return operandValue->complement();
break;
}
throw unknown_operator("Got unknown operator during UnaryOperatorExpression evaluation");
}