Changeset 18093 for branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer
- Timestamp:
- 11/24/21 13:40:39 (3 years ago)
- Location:
- branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/InfixExpressionParser.cs
r17902 r18093 57 57 /// </summary> 58 58 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 }; 60 60 private class Token { 61 61 internal double doubleVal; … … 82 82 knownSymbols = new BidirectionalLookup<string, ISymbol>(StringComparer.InvariantCulture, new SymbolComparer()); 83 83 84 private Constant constant = new Constant(); 84 private Num num = new Num(); 85 private RealConstant realConstant = new RealConstant(); 85 86 private Variable variable = new Variable(); 86 87 private BinaryFactorVariable binaryFactorVar = new BinaryFactorVariable(); … … 265 266 pos++; 266 267 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 = ">"}; 267 274 } else { 268 275 throw new ArgumentException("Invalid character: " + str[pos]); … … 326 333 foreach (var negTerm in negTerms) sumNeg.AddSubtree(negTerm); 327 334 328 var constNode = ( ConstantTreeNode)constant.CreateTreeNode();335 var constNode = (NumTreeNode)num.CreateTreeNode(); 329 336 constNode.Value = -1.0; 330 337 var prod = GetSymbol("*").CreateTreeNode(); … … 524 531 } 525 532 } 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; 526 546 } else if (next.TokenType == TokenType.Number) { 527 547 var numTok = tokens.Dequeue(); 528 var constNode = ( ConstantTreeNode)constant.CreateTreeNode();548 var constNode = (RealConstantTreeNode)realConstant.CreateTreeNode(); 529 549 constNode.Value = numTok.doubleVal; 530 550 return constNode; -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/SymbolicExpressionImporter.cs
r17180 r18093 85 85 }; 86 86 87 Constant constant = new Constant();87 Num num = new Num(); 88 88 Variable variable = new Variable(); 89 89 LaggedVariable laggedVariable = new LaggedVariable(); … … 161 161 return tree; 162 162 } else if (tokens.Peek().Symbol == TokenSymbol.NUMBER) { 163 ConstantTreeNode t = (ConstantTreeNode)constant.CreateTreeNode();163 NumTreeNode t = (NumTreeNode)num.CreateTreeNode(); 164 164 t.Value = tokens.Dequeue().DoubleValue; 165 165 return t;
Note: See TracChangeset
for help on using the changeset viewer.