Changeset 2287 for trunk/tools/CedmaImporter
- Timestamp:
- 08/14/09 11:14:26 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/CedmaImporter/SymbolicExpressionImporter.cs
r2263 r2287 13 13 namespace CedmaImporter { 14 14 public class SymbolicExpressionImporter { 15 15 private const string DIFFSTART = "dif"; 16 private const string VARSTART = "var"; 16 17 private Dictionary<string, IFunction> knownFunctions = new Dictionary<string, IFunction>() 17 18 { … … 51 52 private IEnumerable<Token> GetTokenStream(StreamReader reader) { 52 53 return from line in GetLineStream(reader) 53 let strTokens = line.Split(new string[] { " " , "\t", Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries).AsEnumerable()54 let strTokens = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).AsEnumerable() 54 55 from strToken in strTokens 55 56 let t = Token.Parse(strToken) … … 64 65 65 66 private HeuristicLab.GP.Interfaces.IFunctionTree ParseSexp(Queue<Token> tokens) { 66 Expect(Token.LPAR, tokens);67 68 if (tokens.Peek().Symbol == TokenSymbol.SYMB) {69 if (tokens.Peek().StringValue. Equals("variable")) {70 returnParseVariable(tokens);71 } else if (tokens.Peek().StringValue. Equals("differential")) {72 returnParseDifferential(tokens);67 if (tokens.Peek().Symbol == TokenSymbol.LPAR) { 68 IFunctionTree tree; 69 Expect(Token.LPAR, tokens); 70 if (tokens.Peek().StringValue.StartsWith(VARSTART)) { 71 tree = ParseVariable(tokens); 72 } else if (tokens.Peek().StringValue.StartsWith(DIFFSTART)) { 73 tree = ParseDifferential(tokens); 73 74 } else { 74 75 Token curToken = tokens.Dequeue(); 75 IFunctionTreetree = CreateTree(curToken);76 tree = CreateTree(curToken); 76 77 while (!tokens.Peek().Equals(Token.RPAR)) { 77 78 tree.AddSubTree(ParseSexp(tokens)); 78 79 } 79 Expect(Token.RPAR, tokens);80 return tree;81 80 } 81 Expect(Token.RPAR, tokens); 82 return tree; 82 83 } else if (tokens.Peek().Symbol == TokenSymbol.NUMBER) { 83 84 ConstantFunctionTree t = (ConstantFunctionTree)constant.GetTreeNode(); 84 85 t.Value = tokens.Dequeue().DoubleValue; 85 86 return t; 86 } else { 87 throw new FormatException("Expected function or constant symbol"); 88 } 87 } else throw new FormatException("Expected function or constant symbol"); 89 88 } 90 89 … … 95 94 t.VariableName = tokens.Dequeue().StringValue; 96 95 t.SampleOffset = (int)tokens.Dequeue().DoubleValue; 97 Expect(Token.RPAR, tokens);98 96 return t; 99 97 } … … 105 103 t.VariableName = tokens.Dequeue().StringValue; 106 104 t.SampleOffset = (int)tokens.Dequeue().DoubleValue; 107 Expect(Token.RPAR, tokens);108 105 return t; 109 106 }
Note: See TracChangeset
for help on using the changeset viewer.