Changeset 14328 for branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Exec/ExecExpandExpression.cs
- Timestamp:
- 10/08/16 12:04:25 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Exec/ExecExpandExpression.cs
r14323 r14328 1 using System. Linq;2 using HeuristicLab.Algorithms.PushGP. Stack;1 using System.Text; 2 using HeuristicLab.Algorithms.PushGP.Interpreter; 3 3 4 namespace HeuristicLab.Algorithms.PushGP.Expressions 4 namespace HeuristicLab.Algorithms.PushGP.Expressions.Exec 5 5 { 6 6 public class ExecExpandExpression : Expression 7 7 { 8 public ExecExpandExpression(Expression[] expressions) : base(OpCode.ExecExpand) 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) 9 14 { 10 this. Expressions = expressions;15 this.expressions = expressions; 11 16 } 12 17 13 public Expression[] Expressions { get;}18 public override bool IsCodeOp { get { return false; } } 14 19 15 public override void Eval(IInterpreter Service interpreterService)20 public override void Eval(IInterpreter interpreter) 16 21 { 17 foreach (var expression in this.Expressions) 18 { 19 interpreterService.ExecStack.Add(expression); 20 } 22 interpreter.ExecStack.Push(this.expressions); 21 23 } 22 24 23 25 public override string ToString() 24 26 { 25 return $"( {string.Join(" ", this.Expressions.Reverse())} )"; 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(); 26 43 } 27 44 }
Note: See TracChangeset
for help on using the changeset viewer.