- Timestamp:
- 08/14/09 11:13:52 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CEDMA-Exporter-715/tools/CedmaExporter/SymbolicExpressionExporter.cs
r2262 r2286 57 57 exported = Export(tree); 58 58 return true; 59 } catch(UnknownFunctionException) { 59 } 60 catch (UnknownFunctionException) { 60 61 exported = ""; 61 62 return false; … … 65 66 private void BuildExportString(IFunctionTree tree) { 66 67 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 } 75 80 } 76 81 … … 78 83 // this is smelly, if there is a cleaner way to have a 'dynamic' visitor 79 84 // 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(); 104 109 throw new UnknownFunctionException(function.Name); 105 110 } … … 118 123 try { 119 124 name = ExportFunction(tree.Function, tree); 120 } catch(UnknownFunctionException) { 125 } 126 catch (UnknownFunctionException) { 121 127 name = "N/A"; 122 128 } … … 181 187 182 188 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 + ")"; 185 191 } 186 192 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 + ")"; 189 195 } 190 196
Note: See TracChangeset
for help on using the changeset viewer.