1 | using HeuristicLab.Algorithms.PushGP.Interpreter;
|
---|
2 | using HeuristicLab.Algorithms.PushGP.Stack;
|
---|
3 |
|
---|
4 | namespace HeuristicLab.Algorithms.PushGP.Expressions
|
---|
5 | {
|
---|
6 | /// <summary>
|
---|
7 | /// Pushes TRUE onto the BOOLEAN stack if the top two items are equal, or FALSE otherwise
|
---|
8 | /// </summary>
|
---|
9 | /// <typeparam name="T">Stacktype</typeparam>
|
---|
10 | public abstract class EqualsExpression<T> : StatelessExpression
|
---|
11 | {
|
---|
12 | public void Eval(IStack<T> stack, IStack<bool> booleanStack)
|
---|
13 | {
|
---|
14 | if (stack.Count < 2)
|
---|
15 | return;
|
---|
16 |
|
---|
17 | var items = stack.Pop(2);
|
---|
18 |
|
---|
19 | booleanStack.Push(items[0].Equals(items[1]));
|
---|
20 | }
|
---|
21 | }
|
---|
22 |
|
---|
23 | public class IntegerEqualsExpression : EqualsExpression<long>
|
---|
24 | {
|
---|
25 | protected override string InitStringRepresentation() { return "INTEGER.="; }
|
---|
26 |
|
---|
27 | public override void Eval(IInterpreter interpreter)
|
---|
28 | {
|
---|
29 | Eval(interpreter.IntegerStack, interpreter.BooleanStack);
|
---|
30 | }
|
---|
31 | }
|
---|
32 |
|
---|
33 | public class FloatEqualsExpression : EqualsExpression<double>
|
---|
34 | {
|
---|
35 | protected override string InitStringRepresentation() { return "FLOAT.="; }
|
---|
36 |
|
---|
37 | public override void Eval(IInterpreter interpreter)
|
---|
38 | {
|
---|
39 | Eval(interpreter.FloatStack, interpreter.BooleanStack);
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | public class BooleanEqualsExpression : EqualsExpression<bool>
|
---|
44 | {
|
---|
45 | protected override string InitStringRepresentation() { return "BOOLEAN.="; }
|
---|
46 |
|
---|
47 | public override void Eval(IInterpreter interpreter)
|
---|
48 | {
|
---|
49 | Eval(interpreter.BooleanStack, interpreter.BooleanStack);
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | public class NameEqualsExpression : EqualsExpression<string>
|
---|
54 | {
|
---|
55 | protected override string InitStringRepresentation() { return "NAME.="; }
|
---|
56 |
|
---|
57 | public override void Eval(IInterpreter interpreter)
|
---|
58 | {
|
---|
59 | Eval(interpreter.NameStack, interpreter.BooleanStack);
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | public class ExecEqualsExpression : EqualsExpression<Expression>
|
---|
64 | {
|
---|
65 | protected override string InitStringRepresentation() { return "EXEC.="; }
|
---|
66 |
|
---|
67 | public override void Eval(IInterpreter interpreter)
|
---|
68 | {
|
---|
69 | Eval(interpreter.ExecStack, interpreter.BooleanStack);
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | public class CodeEqualsExpression : EqualsExpression<Expression>
|
---|
74 | {
|
---|
75 | protected override string InitStringRepresentation() { return "CODE.="; }
|
---|
76 |
|
---|
77 | public override void Eval(IInterpreter interpreter)
|
---|
78 | {
|
---|
79 | Eval(interpreter.CodeStack, interpreter.BooleanStack);
|
---|
80 | }
|
---|
81 | }
|
---|
82 | }
|
---|