Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Code/CodeIfExpression.cs @ 14320

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

#2665 Added Interpreter, Parser, 16 Examples, Expressions needed for the examples

File size: 873 bytes
Line 
1using HeuristicLab.Algorithms.PushGP.Stack;
2
3namespace HeuristicLab.Algorithms.PushGP.Expressions
4{
5    public class CodeIfExpression : Expression
6    {
7        public CodeIfExpression() : base(OpCode.CodeIf)
8        { }
9
10        public override void Eval(IInterpreterService interpreterService)
11        {
12            // not enough arguments on stack
13            if (interpreterService.BooleanStack.Count == 0 ||
14                interpreterService.CodeStack.Count < 2)
15                return;
16
17            var condition = interpreterService.BooleanStack.Pop();
18            var expressionFalse = interpreterService.CodeStack.Pop();
19            var expressionTrue = interpreterService.CodeStack.Pop();
20
21            interpreterService.ExecStack.Push(condition
22                ? expressionTrue
23                : expressionFalse);
24        }
25    }
26}
Note: See TracBrowser for help on using the repository browser.