Changeset 10011 for branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Statements/IfStat.cs
- Timestamp:
- 10/01/13 12:08:25 (10 years ago)
- Location:
- branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Statements
- Files:
-
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Statements/IfStat.cs
r9999 r10011 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 22 24 using HeuristicLab.Common; 23 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 26 28 namespace HeuristicLab.Problems.Robocode { 27 29 [StorableClass] 28 public class IfStat ement: CodeNode {30 public class IfStat : CodeNode { 29 31 public override int MinimumArity { get { return 2; } } 30 32 public override int MaximumArity { get { return 3; } } … … 37 39 38 40 [StorableConstructor] 39 private IfStatement(bool deserializing) : base(deserializing) { } 40 private IfStatement(IfStatement original, Cloner cloner) 41 : base(original, cloner) { 42 } 41 protected IfStat(bool deserializing) : base(deserializing) { } 42 protected IfStat(IfStat original, Cloner cloner) : base(original, cloner) { } 43 43 44 public IfStat ement()45 : base("IfStatement", "An IfStatement.") {46 this.Prefix = "if(";47 this.Suffix = ")";44 public IfStat() 45 : base("IfStatement", "An if statement.") { 46 Prefix = "if ("; 47 Suffix = ")"; 48 48 } 49 49 50 50 public override IDeepCloneable Clone(Cloner cloner) { 51 return new IfStat ement(this, cloner);51 return new IfStat(this, cloner); 52 52 } 53 53 54 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {55 string condition = "", ifTrue = "", ifElse = "";56 foreach ( ISymbolicExpressionTreeNodec in children) {54 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 55 string condition = string.Empty, ifTrue = string.Empty, ifElse = string.Empty; 56 foreach (var c in children) { 57 57 if (c.Symbol is LogicalExpression) 58 58 condition = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees); 59 else if (c.Symbol is Block)59 else if (c.Symbol is Stat) 60 60 ifTrue = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees); 61 else if (c.Symbol is ElseStat ement || c.Symbol is DoNothing)61 else if (c.Symbol is ElseStat || c.Symbol is EmptyEvent || c.Symbol is DoNothing) 62 62 ifElse = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees); 63 else 64 throw new System.Exception("Unexpected Child node."); 63 else throw new ArgumentException("Unexpected children.", "children"); 65 64 } 66 return this.Prefix + " " + condition + " " + this.Suffix + 67 "\r\n" + ifTrue + "\r\n" + ifElse + "\r\n"; 65 return Prefix + condition + Suffix + Environment.NewLine + ifTrue + Environment.NewLine + ifElse + Environment.NewLine; 68 66 } 69 67 }
Note: See TracChangeset
for help on using the changeset viewer.