Changeset 2287 for trunk/tools


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

Fixed bug in s-expression importer. #719

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/CedmaImporter/SymbolicExpressionImporter.cs

    r2263 r2287  
    1313namespace CedmaImporter {
    1414  public class SymbolicExpressionImporter {
    15 
     15    private const string DIFFSTART = "dif";
     16    private const string VARSTART = "var";
    1617    private Dictionary<string, IFunction> knownFunctions = new Dictionary<string, IFunction>()
    1718      {
     
    5152    private IEnumerable<Token> GetTokenStream(StreamReader reader) {
    5253      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()
    5455             from strToken in strTokens
    5556             let t = Token.Parse(strToken)
     
    6465
    6566    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           return ParseVariable(tokens);
    71         } else if (tokens.Peek().StringValue.Equals("differential")) {
    72           return ParseDifferential(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);
    7374        } else {
    7475          Token curToken = tokens.Dequeue();
    75           IFunctionTree tree = CreateTree(curToken);
     76          tree = CreateTree(curToken);
    7677          while (!tokens.Peek().Equals(Token.RPAR)) {
    7778            tree.AddSubTree(ParseSexp(tokens));
    7879          }
    79           Expect(Token.RPAR, tokens);
    80           return tree;
    8180        }
     81        Expect(Token.RPAR, tokens);
     82        return tree;
    8283      } else if (tokens.Peek().Symbol == TokenSymbol.NUMBER) {
    8384        ConstantFunctionTree t = (ConstantFunctionTree)constant.GetTreeNode();
    8485        t.Value = tokens.Dequeue().DoubleValue;
    8586        return t;
    86       } else {
    87         throw new FormatException("Expected function or constant symbol");
    88       }
     87      } else throw new FormatException("Expected function or constant symbol");
    8988    }
    9089
     
    9594      t.VariableName = tokens.Dequeue().StringValue;
    9695      t.SampleOffset = (int)tokens.Dequeue().DoubleValue;
    97       Expect(Token.RPAR, tokens);
    9896      return t;
    9997    }
     
    105103      t.VariableName = tokens.Dequeue().StringValue;
    106104      t.SampleOffset = (int)tokens.Dequeue().DoubleValue;
    107       Expect(Token.RPAR, tokens);
    108105      return t;
    109106    }
Note: See TracChangeset for help on using the changeset viewer.