Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/14/09 11:13:52 (15 years ago)
Author:
gkronber
Message:

Fixed a bug in the s-expression exporter. Improved exporter UI. #715 & #719

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/CEDMA-Exporter-715/tools/CedmaExporter/SymbolicExpressionExporter.cs

    r2262 r2286  
    5757        exported = Export(tree);
    5858        return true;
    59       } catch(UnknownFunctionException) {
     59      }
     60      catch (UnknownFunctionException) {
    6061        exported = "";
    6162        return false;
     
    6566    private void BuildExportString(IFunctionTree tree) {
    6667      builder.Append(currentIndent);
    67       builder.Append("(" + ExportFunction(tree.Function, tree) + " ");
    68       currentIndent += "  ";
    69       foreach(IFunctionTree subTree in tree.SubTrees) {
    70         builder.Append("\n");
    71         BuildExportString(subTree);
    72       }
    73       builder.Append(")");
    74       currentIndent = currentIndent.Remove(0, 2);
     68      if (tree.SubTrees.Count == 0) {
     69        builder.Append(ExportFunction(tree.Function, tree));
     70      } else {
     71        builder.Append("(" + ExportFunction(tree.Function, tree) + " ");
     72        currentIndent += "  ";
     73        foreach (IFunctionTree subTree in tree.SubTrees) {
     74          builder.Append("\n");
     75          BuildExportString(subTree);
     76        }
     77        builder.Append(")");
     78        currentIndent = currentIndent.Remove(0, 2);
     79      }
    7580    }
    7681
     
    7883      // this is smelly, if there is a cleaner way to have a 'dynamic' visitor
    7984      // please let me know! (gkronber 14.10.2008)
    80       if(function is Addition) return ((Addition)function).ExportToScheme();
    81       if(function is And) return ((And)function).ExportToScheme();
    82       if(function is Average) return ((Average)function).ExportToScheme();
    83       if(function is Constant) return ((Constant)function).ExportToScheme(tree);
    84       if(function is Cosinus) return ((Cosinus)function).ExportToScheme();
    85       if(function is Differential) return ((Differential)function).ExportToScheme(tree, dataset);
    86       if(function is Division) return ((Division)function).ExportToScheme();
    87       if(function is Equal) return ((Equal)function).ExportToScheme();
    88       if(function is Exponential) return ((Exponential)function).ExportToScheme();
    89       if(function is GreaterThan) return ((GreaterThan)function).ExportToScheme();
    90       if(function is IfThenElse) return ((IfThenElse)function).ExportToScheme();
    91       if(function is LessThan) return ((LessThan)function).ExportToScheme();
    92       if(function is Logarithm) return ((Logarithm)function).ExportToScheme();
    93       if(function is Multiplication) return ((Multiplication)function).ExportToScheme();
    94       if(function is Not) return ((Not)function).ExportToScheme();
    95       if(function is Or) return ((Or)function).ExportToScheme();
    96       if(function is Power) return ((Power)function).ExportToScheme();
    97       if(function is Signum) return ((Signum)function).ExportToScheme();
    98       if(function is Sinus) return ((Sinus)function).ExportToScheme();
    99       if(function is Sqrt) return ((Sqrt)function).ExportToScheme();
    100       if(function is Subtraction) return ((Subtraction)function).ExportToScheme();
    101       if(function is Tangens) return ((Tangens)function).ExportToScheme();
    102       if(function is Variable) return ((Variable)function).ExportToScheme(tree, dataset);
    103       if(function is Xor) return ((Xor)function).ExportToScheme();
     85      if (function is Addition) return ((Addition)function).ExportToScheme();
     86      if (function is And) return ((And)function).ExportToScheme();
     87      if (function is Average) return ((Average)function).ExportToScheme();
     88      if (function is Constant) return ((Constant)function).ExportToScheme(tree);
     89      if (function is Cosinus) return ((Cosinus)function).ExportToScheme();
     90      if (function is Differential) return ((Differential)function).ExportToScheme(tree, dataset);
     91      if (function is Division) return ((Division)function).ExportToScheme();
     92      if (function is Equal) return ((Equal)function).ExportToScheme();
     93      if (function is Exponential) return ((Exponential)function).ExportToScheme();
     94      if (function is GreaterThan) return ((GreaterThan)function).ExportToScheme();
     95      if (function is IfThenElse) return ((IfThenElse)function).ExportToScheme();
     96      if (function is LessThan) return ((LessThan)function).ExportToScheme();
     97      if (function is Logarithm) return ((Logarithm)function).ExportToScheme();
     98      if (function is Multiplication) return ((Multiplication)function).ExportToScheme();
     99      if (function is Not) return ((Not)function).ExportToScheme();
     100      if (function is Or) return ((Or)function).ExportToScheme();
     101      if (function is Power) return ((Power)function).ExportToScheme();
     102      if (function is Signum) return ((Signum)function).ExportToScheme();
     103      if (function is Sinus) return ((Sinus)function).ExportToScheme();
     104      if (function is Sqrt) return ((Sqrt)function).ExportToScheme();
     105      if (function is Subtraction) return ((Subtraction)function).ExportToScheme();
     106      if (function is Tangens) return ((Tangens)function).ExportToScheme();
     107      if (function is Variable) return ((Variable)function).ExportToScheme(tree, dataset);
     108      if (function is Xor) return ((Xor)function).ExportToScheme();
    104109      throw new UnknownFunctionException(function.Name);
    105110    }
     
    118123      try {
    119124        name = ExportFunction(tree.Function, tree);
    120       } catch(UnknownFunctionException) {
     125      }
     126      catch (UnknownFunctionException) {
    121127        name = "N/A";
    122128      }
     
    181187
    182188    public static string ExportToScheme(this Variable variable, IFunctionTree tree, Dataset ds) {
    183       return "variable " + tree.GetLocalVariable(Variable.WEIGHT).Value + " " +
    184         ds.GetVariableName(int.Parse(tree.GetLocalVariable(Variable.INDEX).Value.ToString())) + " " + tree.GetLocalVariable(Variable.OFFSET).Value;
     189      return "(variable " + tree.GetLocalVariable(Variable.WEIGHT).Value + " " +
     190        ds.GetVariableName(int.Parse(tree.GetLocalVariable(Variable.INDEX).Value.ToString())) + " " + tree.GetLocalVariable(Variable.OFFSET).Value + ")";
    185191    }
    186192    public static string ExportToScheme(this Differential differential, IFunctionTree tree, Dataset ds) {
    187       return "differential " + tree.GetLocalVariable(Differential.WEIGHT).Value + " " +
    188         ds.GetVariableName(int.Parse(tree.GetLocalVariable(Differential.INDEX).Value.ToString())) + " " + tree.GetLocalVariable(Differential.OFFSET).Value;
     193      return "(differential " + tree.GetLocalVariable(Differential.WEIGHT).Value + " " +
     194        ds.GetVariableName(int.Parse(tree.GetLocalVariable(Differential.INDEX).Value.ToString())) + " " + tree.GetLocalVariable(Differential.OFFSET).Value + ")";
    189195    }
    190196
Note: See TracChangeset for help on using the changeset viewer.