Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/EqualsExpressions.cs @ 14392

Last change on this file since 14392 was 14392, checked in by pkimmesw, 8 years ago

#2665 Full Push 3.0 instruction set and tests; Added first benchmark test (count odds) for random walk tests;

File size: 2.6 KB
Line 
1using HeuristicLab.Algorithms.PushGP.Interpreter;
2using HeuristicLab.Algorithms.PushGP.Stack;
3
4namespace 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> : Expression
11    {
12        public EqualsExpression(string stringRepresentation) : base(stringRepresentation)
13        { }
14
15        public void Eval(IStack<T> stack, IStack<bool> booleanStack)
16        {
17            if (stack.Count < 2)
18                return;
19
20            var items = stack.Pop(2);
21
22            booleanStack.Push(items[0].Equals(items[1]));
23        }
24    }
25
26    public class IntegerEqualsExpression : EqualsExpression<long>
27    {
28        public IntegerEqualsExpression() : base("INTEGER.=")
29        { }
30
31        public override void Eval(IInterpreter interpreter)
32        {
33            this.Eval(interpreter.IntegerStack, interpreter.BooleanStack);
34        }
35    }
36
37    public class FloatEqualsExpression : EqualsExpression<double>
38    {
39        public FloatEqualsExpression() : base("FLOAT.=")
40        { }
41
42        public override void Eval(IInterpreter interpreter)
43        {
44            this.Eval(interpreter.FloatStack, interpreter.BooleanStack);
45        }
46    }
47
48    public class BooleanEqualsExpression : EqualsExpression<bool>
49    {
50        public BooleanEqualsExpression() : base("BOOLEAN.=")
51        { }
52
53        public override void Eval(IInterpreter interpreter)
54        {
55            this.Eval(interpreter.BooleanStack, interpreter.BooleanStack);
56        }
57    }
58
59    public class NameEqualsExpression : EqualsExpression<string>
60    {
61        public NameEqualsExpression() : base("NAME.=")
62        { }
63
64        public override void Eval(IInterpreter interpreter)
65        {
66            this.Eval(interpreter.NameStack, interpreter.BooleanStack);
67        }
68    }
69
70    public class ExecEqualsExpression : EqualsExpression<Expression>
71    {
72        public ExecEqualsExpression() : base("EXEC.=")
73        { }
74
75        public override void Eval(IInterpreter interpreter)
76        {
77            this.Eval(interpreter.ExecStack, interpreter.BooleanStack);
78        }
79    }
80
81    public class CodeEqualsExpression : EqualsExpression<Expression>
82    {
83        public CodeEqualsExpression() : base("CODE.=")
84        { }
85
86        public override void Eval(IInterpreter interpreter)
87        {
88            this.Eval(interpreter.CodeStack, interpreter.BooleanStack);
89        }
90    }
91}
Note: See TracBrowser for help on using the repository browser.