Changeset 18171
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/InfixExpressionParser.cs
r18169 r18171 377 377 378 378 private void FoldLeftRecursive(ISymbolicExpressionTreeNode parent) { 379 if (parent.SubtreeCount > 0) {379 if (parent.SubtreeCount > 1) { 380 380 var child = parent.GetSubtree(0); 381 381 FoldLeftRecursive(child); 382 if (parent.Symbol == child.Symbol) {382 if (parent.Symbol == child.Symbol && IsAssociative(parent.Symbol)) { 383 383 parent.RemoveSubtree(0); 384 for (int i=0;i<child.SubtreeCount; i++) {384 for (int i = 0; i < child.SubtreeCount; i++) { 385 385 parent.InsertSubtree(i, child.GetSubtree(i)); 386 386 } … … 443 443 // '<' 'num' [ '=' ['+'|'-'] number ] '>' 444 444 return ParseNumber(tokens); 445 } else if (next.TokenType == TokenType.Operator && (next.strVal == "-" || next.strVal == "+")) {445 } else if (next.TokenType == TokenType.Operator && (next.strVal == "-" || next.strVal == "+")) { 446 446 // ['+' | '-' ] SimpleFact 447 447 if (tokens.Dequeue().strVal == "-") { … … 499 499 if (next.strVal == "+" || next.strVal == "-") { 500 500 if (tokens.Dequeue().strVal == "-") sign = -1.0; 501 } 502 if (tokens.Peek().TokenType != TokenType.Number) {501 } 502 if (tokens.Peek().TokenType != TokenType.Number) { 503 503 throw new ArgumentException("Expected number."); 504 504 } … … 632 632 return exprList.ToArray(); 633 633 } 634 635 private bool IsAssociative(ISymbol sy) { 636 return sy == GetSymbol("+") || sy == GetSymbol("-") || 637 sy == GetSymbol("*") || sy == GetSymbol("/") || 638 sy == GetSymbol("AND") || sy == GetSymbol("OR") || sy == GetSymbol("XOR"); 639 } 634 640 } 635 641 } -
trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/InfixExpressionParserTest.cs
r18170 r18171 145 145 // numeric parameter with sign 146 146 Assert.AreEqual("1", formatter.Format(parser.Parse("-<num=-1.0>"))); 147 148 // nested functions 149 Assert.AreEqual("SIN(SIN(SIN('X1')))", formatter.Format(parser.Parse("SIN(SIN(SIN(X1)))"))); 147 150 } 148 151 }
Note: See TracChangeset
for help on using the changeset viewer.