Changeset 14765 for branches/symbreg-factors-2650
- Timestamp:
- 03/18/17 14:39:32 (8 years ago)
- Location:
- branches/symbreg-factors-2650
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/InfixExpressionParser.cs
r14761 r14765 48 48 /// ArgList = Expr { ',' Expr } 49 49 /// VarExpr = varId OptFactorPart 50 /// OptFactorPart = [ ('=' varVal | '[' number {','number } ']' ) ]50 /// OptFactorPart = [ ('=' varVal | '[' ['+' | '-' ] number {',' ['+' | '-' ] number } ']' ) ] 51 51 /// varId = ident | ' ident ' | " ident " 52 52 /// varVal = ident | ' ident ' | " ident " … … 366 366 /// ArgList = Expr { ',' Expr } 367 367 /// VarExpr = varId OptFactorPart 368 /// OptFactorPart = [ ('=' varVal | '[' number {','number } ']' ) ]368 /// OptFactorPart = [ ('=' varVal | '[' ['+' | '-' ] number {',' ['+' | '-' ] number } ']' ) ] 369 369 /// varId = ident | ' ident ' | " ident " 370 370 /// varVal = ident | ' ident ' | " ident " … … 440 440 } else if(tokens.Peek().TokenType == TokenType.LeftBracket) { 441 441 // factor variable 442 var factorVariableNode = (FactorVariableTreeNode) 442 var factorVariableNode = (FactorVariableTreeNode)factorVar.CreateTreeNode(); 443 443 factorVariableNode.VariableName = idTok.strVal; 444 444 … … 446 446 var weights = new List<double>(); 447 447 // at least one weight is necessary 448 var sign = 1.0; 449 if(tokens.Peek().TokenType == TokenType.Operator) { 450 var opToken = tokens.Dequeue(); 451 if(opToken.strVal == "+") sign = 1.0; 452 else if(opToken.strVal == "-") sign = -1.0; 453 else throw new ArgumentException(); 454 } 448 455 if(tokens.Peek().TokenType != TokenType.Number) throw new ArgumentException("number expected"); 449 456 var weightTok = tokens.Dequeue(); 450 weights.Add( weightTok.doubleVal);457 weights.Add(sign * weightTok.doubleVal); 451 458 while(tokens.Peek().TokenType == TokenType.Comma) { 452 459 // skip comma 453 460 tokens.Dequeue(); 461 if(tokens.Peek().TokenType == TokenType.Operator) { 462 var opToken = tokens.Dequeue(); 463 if(opToken.strVal == "+") sign = 1.0; 464 else if(opToken.strVal == "-") sign = -1.0; 465 else throw new ArgumentException(); 466 } 454 467 weightTok = tokens.Dequeue(); 455 468 if(weightTok.TokenType != TokenType.Number) throw new ArgumentException("number expected"); 456 weights.Add( weightTok.doubleVal);469 weights.Add(sign * weightTok.doubleVal); 457 470 } 458 471 var rightBracketToken = tokens.Dequeue(); -
branches/symbreg-factors-2650/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/InfixExpressionParserTest.cs
r14761 r14765 111 111 Console.WriteLine(formatter.Format(parser.Parse("x[1, 2] * y [1, 2]"))); 112 112 113 Console.WriteLine(formatter.Format(parser.Parse("x [+1.0] * y"))); 114 Console.WriteLine(formatter.Format(parser.Parse("x [-1.0] * y"))); 115 Console.WriteLine(formatter.Format(parser.Parse("x [-1.0, -2.0] * y [+1.0, +2.0]"))); 116 113 117 Console.WriteLine(formatter.Format(parser.Parse("x='bla' * y"))); 114 118 Console.WriteLine(formatter.Format(parser.Parse("x = 'bla'"))); 115 119 Console.WriteLine(formatter.Format(parser.Parse("x = \"bla\""))); 116 120 Console.WriteLine(formatter.Format(parser.Parse("1.0 * x = bla"))); 117 Console.WriteLine(formatter.Format(parser.Parse("1.0 * \"x\" = bla + y = \"bla2\""))); 121 Console.WriteLine(formatter.Format(parser.Parse("-1.0 * x = bla"))); 122 Console.WriteLine(formatter.Format(parser.Parse("+1.0 * \"x\" = bla + y = \"bla2\""))); 118 123 } 119 124 }
Note: See TracChangeset
for help on using the changeset viewer.