Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/01/21 13:40:55 (3 years ago)
Author:
chaider
Message:

#3140

  • some more refactoring
  • added possibility to set value of num nodes in infix parser
  • changed displaying style of number
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/InfixExpressionParser.cs

    r18093 r18100  
    8282      knownSymbols = new BidirectionalLookup<string, ISymbol>(StringComparer.InvariantCulture, new SymbolComparer());
    8383
    84     private Num num = new Num();
    85     private RealConstant realConstant = new RealConstant();
     84    private Number number = new Number();
     85    private Constant constant = new Constant();
    8686    private Variable variable = new Variable();
    8787    private BinaryFactorVariable binaryFactorVar = new BinaryFactorVariable();
     
    181181            && str[pos] != ']'
    182182            && str[pos] != '}'
    183             && str[pos] != ',') {
     183            && str[pos] != ','
     184            && str[pos] != '>') {
    184185            sb.Append(str[pos]);
    185186            pos++;
     
    333334          foreach (var negTerm in negTerms) sumNeg.AddSubtree(negTerm);
    334335
    335           var constNode = (NumTreeNode)num.CreateTreeNode();
     336          var constNode = (NumberTreeNode)number.CreateTreeNode();
    336337          constNode.Value = -1.0;
    337338          var prod = GetSymbol("*").CreateTreeNode();
     
    532533        }
    533534      } else if (next.TokenType == TokenType.LeftAngleBracket) {
     535        Token numberTok = null;
    534536        var leftAngleBracket = tokens.Dequeue();
    535537        if (leftAngleBracket.TokenType != TokenType.LeftAngleBracket)
     
    539541        if (idTok.TokenType != TokenType.Identifier || idTok.strVal.ToLower() != "num")
    540542          throw new ArgumentException("string 'num' expected");
     543
     544        if (tokens.Peek().TokenType == TokenType.Eq) {
     545          var equalTok = tokens.Dequeue();
     546          if (tokens.Peek().TokenType != TokenType.Number)
     547            throw new ArgumentException("No value for number specified.");
     548
     549          numberTok = tokens.Dequeue();
     550        }
     551
    541552        var rightAngleBracket = tokens.Dequeue();
    542553        if (rightAngleBracket.TokenType != TokenType.RightAngleBracket)
    543554          throw new ArgumentException("closing bracket > expected");
    544         var numNode = (NumTreeNode)num.CreateTreeNode();
     555        var numNode = (NumberTreeNode)number.CreateTreeNode();
     556        if (numberTok != null) numNode.Value = numberTok.doubleVal;
    545557        return numNode;
    546558      } else if (next.TokenType == TokenType.Number) {
    547559        var numTok = tokens.Dequeue();
    548         var constNode = (RealConstantTreeNode)realConstant.CreateTreeNode();
     560        var constNode = (ConstantTreeNode)constant.CreateTreeNode();
    549561        constNode.Value = numTok.doubleVal;
    550562        return constNode;
Note: See TracChangeset for help on using the changeset viewer.