Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/24/21 13:40:39 (3 years ago)
Author:
chaider
Message:

#3041

  • Renaming Constant Symbol to Num, behaves like before
  • Adding new Symbol RealConstant (Constant), this symbol behaves now like a real constant, won't be changed by parameter optimization or manipulators
  • Refactored classes part1
File:
1 edited

Legend:

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

    r17902 r18093  
    5757  /// </summary>
    5858  public sealed class InfixExpressionParser {
    59     private enum TokenType { Operator, Identifier, Number, LeftPar, RightPar, LeftBracket, RightBracket, Comma, Eq, End, NA };
     59    private enum TokenType { Operator, Identifier, Number, LeftPar, RightPar, LeftBracket, RightBracket, LeftAngleBracket, RightAngleBracket, Comma, Eq, End, NA };
    6060    private class Token {
    6161      internal double doubleVal;
     
    8282      knownSymbols = new BidirectionalLookup<string, ISymbol>(StringComparer.InvariantCulture, new SymbolComparer());
    8383
    84     private Constant constant = new Constant();
     84    private Num num = new Num();
     85    private RealConstant realConstant = new RealConstant();
    8586    private Variable variable = new Variable();
    8687    private BinaryFactorVariable binaryFactorVar = new BinaryFactorVariable();
     
    265266          pos++;
    266267          yield return new Token { TokenType = TokenType.Comma, strVal = "," };
     268        } else if (str[pos] == '<') {
     269          pos++;
     270          yield return new Token {TokenType = TokenType.LeftAngleBracket, strVal = "<"};
     271        } else if (str[pos] == '>') {
     272          pos++;
     273          yield return new Token {TokenType = TokenType.RightAngleBracket, strVal = ">"};
    267274        } else {
    268275          throw new ArgumentException("Invalid character: " + str[pos]);
     
    326333          foreach (var negTerm in negTerms) sumNeg.AddSubtree(negTerm);
    327334
    328           var constNode = (ConstantTreeNode)constant.CreateTreeNode();
     335          var constNode = (NumTreeNode)num.CreateTreeNode();
    329336          constNode.Value = -1.0;
    330337          var prod = GetSymbol("*").CreateTreeNode();
     
    524531          }
    525532        }
     533      } else if (next.TokenType == TokenType.LeftAngleBracket) {
     534        var leftAngleBracket = tokens.Dequeue();
     535        if (leftAngleBracket.TokenType != TokenType.LeftAngleBracket)
     536          throw new ArgumentException("opening bracket < expected");
     537
     538        var idTok = tokens.Dequeue();
     539        if (idTok.TokenType != TokenType.Identifier || idTok.strVal.ToLower() != "num")
     540          throw new ArgumentException("string 'num' expected");
     541        var rightAngleBracket = tokens.Dequeue();
     542        if (rightAngleBracket.TokenType != TokenType.RightAngleBracket)
     543          throw new ArgumentException("closing bracket > expected");
     544        var numNode = (NumTreeNode)num.CreateTreeNode();
     545        return numNode;
    526546      } else if (next.TokenType == TokenType.Number) {
    527547        var numTok = tokens.Dequeue();
    528         var constNode = (ConstantTreeNode)constant.CreateTreeNode();
     548        var constNode = (RealConstantTreeNode)realConstant.CreateTreeNode();
    529549        constNode.Value = numTok.doubleVal;
    530550        return constNode;
Note: See TracChangeset for help on using the changeset viewer.