Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/01/13 12:08:25 (11 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/WhileStat.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 WhileLoop : CodeNode {
     30  public class WhileStat : CodeNode {
    2931    public override int MinimumArity { get { return 2; } }
    3032    public override int MaximumArity { get { return 2; } }
     
    3739
    3840    [StorableConstructor]
    39     private WhileLoop(bool deserializing) : base(deserializing) { }
    40     private WhileLoop(WhileLoop original, Cloner cloner)
    41       : base(original, cloner) {
     41    protected WhileStat(bool deserializing) : base(deserializing) { }
     42    protected WhileStat(WhileStat original, Cloner cloner) : base(original, cloner) { }
    4243
    43     }
    44 
    45     public WhileLoop()
    46       : base("WhileLoop", "A WhileLoop.") {
    47       this.Prefix = "while(";
    48       this.Suffix = ")";
     44    public WhileStat()
     45      : base("WhileStat", "A while statement.") {
     46      Prefix = "while (";
     47      Suffix = ")";
    4948    }
    5049
    5150    public override IDeepCloneable Clone(Cloner cloner) {
    52       return new WhileLoop(this, cloner);
     51      return new WhileStat(this, cloner);
    5352    }
    5453
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       string condition = "", ifTrue = "";
    57       foreach (ISymbolicExpressionTreeNode c in children) {
     54    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     55      string condition = string.Empty, ifTrue = string.Empty;
     56      foreach (var c in children) {
    5857        if (c.Symbol is LogicalExpression)
    5958          condition = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    60         else if (c.Symbol is Block)
     59        else if (c.Symbol is Stat || c.Symbol is EmptyEvent || c.Symbol is DoNothing)
    6160          ifTrue = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    62         else
    63           throw new System.Exception("Unexpected Child node.");
     61        else throw new ArgumentException("Unexpected children.", "children");
    6462      }
    65       return this.Prefix + " " + condition + " " + this.Suffix +
    66           "\r\n" + ifTrue + "\r\n";
     63      return Prefix + condition + Suffix + Environment.NewLine + ifTrue + Environment.NewLine;
    6764    }
    6865  }
Note: See TracChangeset for help on using the changeset viewer.