-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathuOperandGroup.pas
More file actions
87 lines (65 loc) · 1.52 KB
/
uOperandGroup.pas
File metadata and controls
87 lines (65 loc) · 1.52 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
unit uOperandGroup;
interface
uses
uParserValue;
type
{Îïåðàöèè ñëîæåíèÿ, âû÷èòàíèÿ è ò.ä.}
TOperand = class(TValue)
protected
FValue1, FValue2: TValue;
public
constructor Create(const AValue1, AValue2: TValue); reintroduce; virtual;
end;
{Òèïû îïåðàíäîâ}
TOperands = class of TOperand;
{Ñêîáêè. Íàáîð îïåðàíäîâ}
TAddition = class(TOperand)
public
function Value: Double; override;
end;
TSubtraction = class(TOperand)
public
function Value: Double; override;
end;
TMultiplication = class(TOperand)
public
function Value: Double; override;
end;
TDivision = class(TOperand)
public
function Value: Double; override;
end;
const
Operands: array[0..3] of char = ('/','*','-','+');
OperandCount = 4;
OperandChar: array[0..5] of char = ('/','*','-','+','(',')');
OperandCharCount = 6;
FastOperandClass: array[0..3] of TOperands = (TDivision, TMultiplication, TSubtraction, TAddition);
implementation
{ TOperand }
constructor TOperand.Create(const AValue1, AValue2: TValue);
begin
FValue1 := AValue1;
FValue2 := AValue2;
end;
{ TAddition }
function TAddition.Value: Double;
begin
Result := FValue1.Value + FValue2.Value;
end;
{ TSubtraction }
function TSubtraction.Value: Double;
begin
Result := FValue1.Value - FValue2.Value;
end;
{ TMultiplication }
function TMultiplication.Value: Double;
begin
Result := FValue1.Value * FValue2.Value;
end;
{ TDivision }
function TDivision.Value: Double;
begin
Result := FValue1.Value / FValue2.Value;
end;
end.