Changeset 2216 for branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/SymbolicExpressionExporter.cs
- Timestamp:
- 07/30/09 19:41:58 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/SymbolicExpressionExporter.cs
r2212 r2216 22 22 using System.Text; 23 23 using HeuristicLab.GP.Interfaces; 24 using System; 25 using System.Collections.Generic; 24 26 25 27 namespace HeuristicLab.GP.StructureIdentification { 26 public class SymbolicExpressionExporter : IFunctionTree Exporter, IFunctionTreeNameGenerator {28 public class SymbolicExpressionExporter : IFunctionTreeSerializer, IFunctionTreeNameGenerator { 27 29 private StringBuilder builder; 28 30 private string currentIndent; … … 48 50 } catch(UnknownFunctionException) { 49 51 exported = ""; 52 return false; 53 } 54 } 55 56 public IFunctionTree Import(string tree) { 57 Queue<string> tokens = new Queue<string>(tree.Split(' ', '\n', '\t')); 58 return ParseTree(tokens); 59 } 60 61 private IFunctionTree ParseTree(Queue<string> tokens) { 62 Expect("(", tokens); 63 string funSymb = tokens.Peek(); 64 double constValue; 65 if (double.TryParse(funSymb, out constValue)) { 66 throw new UnknownFunctionException(funSymb); 67 } 68 switch (funSymb) { 69 case "variable": return ParseVariable(tokens); 70 case "differential": return ParseDifferential(tokens); 71 default: 72 IFunctionTree fNode = ParseFunction(tokens); 73 Expect(")", tokens); 74 return fNode; 75 } 76 77 } 78 79 private IFunctionTree ParseFunction(Queue<string> tokens) { 80 throw new UnknownFunctionException(tokens.Dequeue()); 81 } 82 83 private IFunctionTree ParseDifferential(Queue<string> tokens) { 84 throw new UnknownFunctionException(tokens.Dequeue()); 85 } 86 87 private IFunctionTree ParseVariable(Queue<string> tokens) { 88 throw new UnknownFunctionException(tokens.Dequeue()); 89 } 90 91 private void Expect(string p, Queue<string> tokens) { 92 throw new NotImplementedException(); 93 } 94 95 public bool TryImport(string tree, out IFunctionTree importedTree) { 96 try { 97 importedTree = Import(tree); 98 return true; 99 } 100 catch (UnknownFunctionException) { 101 importedTree = null; 50 102 return false; 51 103 }
Note: See TracChangeset
for help on using the changeset viewer.