Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/01/13 12:08:25 (10 years ago)
Author:
jkarder
Message:

#2069:

  • refactored grammar and symbols
  • fixed cloning and storable ctors
  • fixed plugin dependencies
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  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
    2224using HeuristicLab.Common;
    2325using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2628namespace HeuristicLab.Problems.Robocode {
    2729  [StorableClass]
    28   public class IfStatement : CodeNode {
     30  public class IfStat : CodeNode {
    2931    public override int MinimumArity { get { return 2; } }
    3032    public override int MaximumArity { get { return 3; } }
     
    3739
    3840    [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) { }
    4343
    44     public IfStatement()
    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 = ")";
    4848    }
    4949
    5050    public override IDeepCloneable Clone(Cloner cloner) {
    51       return new IfStatement(this, cloner);
     51      return new IfStat(this, cloner);
    5252    }
    5353
    54     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    55       string condition = "", ifTrue = "", ifElse = "";
    56       foreach (ISymbolicExpressionTreeNode c 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) {
    5757        if (c.Symbol is LogicalExpression)
    5858          condition = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    59         else if (c.Symbol is Block)
     59        else if (c.Symbol is Stat)
    6060          ifTrue = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    61         else if (c.Symbol is ElseStatement || c.Symbol is DoNothing)
     61        else if (c.Symbol is ElseStat || c.Symbol is EmptyEvent || c.Symbol is DoNothing)
    6262          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");
    6564      }
    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;
    6866    }
    6967  }
Note: See TracChangeset for help on using the changeset viewer.