Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Exec/ExecExpandExpression.cs @ 14328

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

#2665 Set .NET version to 4.5, C# version to 5.0, Added expression templates and factory

File size: 1.2 KB
Line 
1using System.Text;
2using HeuristicLab.Algorithms.PushGP.Interpreter;
3
4namespace HeuristicLab.Algorithms.PushGP.Expressions.Exec
5{
6    public class ExecExpandExpression : Expression
7    {
8        private const string prefix = "( ";
9        private const string postifx = " )";
10        private const string delimiter = " ";
11
12        private readonly Expression[] expressions;
13        public ExecExpandExpression(Expression[] expressions)
14        {
15            this.expressions = expressions;
16        }
17
18        public override bool IsCodeOp { get { return false; } }
19
20        public override void Eval(IInterpreter interpreter)
21        {
22            interpreter.ExecStack.Push(this.expressions);
23        }
24
25        public override string ToString()
26        {
27            if (this.expressions.Length == 0)
28            {
29                return string.Empty;
30            }
31
32            var sb = new StringBuilder();
33            sb.Append(prefix);
34
35            for (var i = this.expressions.Length - 1; i > 0; i--)
36            {
37                sb.Append(this.expressions[i] + delimiter);
38            }
39
40            sb.Append(this.expressions[0] + postifx);
41
42            return sb.ToString();
43        }
44    }
45}
Note: See TracBrowser for help on using the repository browser.