Changeset 16428 for branches/2845_EnhancedProgress/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/InfixExpressionParser.cs
- Timestamp:
- 12/21/18 10:31:49 (6 years ago)
- Location:
- branches/2845_EnhancedProgress
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2845_EnhancedProgress
- Property svn:mergeinfo changed
-
branches/2845_EnhancedProgress/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
-
branches/2845_EnhancedProgress/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/InfixExpressionParser.cs
r16311 r16428 42 42 /// Expr = ['-' | '+'] Term { '+' Term | '-' Term } 43 43 /// Term = Fact { '*' Fact | '/' Fact } 44 /// Fact = '(' Expr ')' 45 /// | 'LAG' '(' varId ',' ['+' | '-' ] number ')' 46 /// | funcId '(' ArgList ')' 47 /// | VarExpr | number 44 /// Fact = SimpleFact [ '^' SimpleFact ] 45 /// SimpleFact = '(' Expr ')' 46 /// | '{' Expr '}' 47 /// | 'LAG' '(' varId ',' ['+' | '-' ] number ') 48 /// | funcId '(' ArgList ')' 49 /// | VarExpr 50 /// | number 48 51 /// ArgList = Expr { ',' Expr } 49 52 /// VarExpr = varId OptFactorPart … … 95 98 { "*", new Multiplication()}, 96 99 { "-", new Subtraction()}, 100 { "^", new Power() }, 101 { "ABS", new Absolute() }, 97 102 { "EXP", new Exponential()}, 98 103 { "LOG", new Logarithm()}, 99 { "POW", new Power() },104 { "POW", new Power() }, 100 105 { "ROOT", new Root()}, 101 106 { "SQR", new Square() }, 102 107 { "SQRT", new SquareRoot() }, 108 { "CUBE", new Cube() }, 109 { "CUBEROOT", new CubeRoot() }, 103 110 { "SIN",new Sine()}, 104 111 { "COS", new Cosine()}, … … 119 126 { "DAWSON", new Dawson()}, 120 127 { "EXPINT", new ExponentialIntegralEi()}, 128 { "AQ", new AnalyticQuotient() }, 121 129 { "MEAN", new Average()}, 122 130 { "IF", new IfThenElse()}, … … 167 175 && str[pos] != '*' 168 176 && str[pos] != '/' 177 && str[pos] != '^' 169 178 && str[pos] != ')' 170 179 && str[pos] != ']' 180 && str[pos] != '}' 171 181 && str[pos] != ',') { 172 182 sb.Append(str[pos]); … … 227 237 pos++; 228 238 yield return new Token { TokenType = TokenType.Operator, strVal = "*" }; 239 } else if (str[pos] == '^') { 240 pos++; 241 yield return new Token { TokenType = TokenType.Operator, strVal = "^" }; 229 242 } else if (str[pos] == '(') { 230 243 pos++; … … 239 252 pos++; 240 253 yield return new Token { TokenType = TokenType.RightBracket, strVal = "]" }; 254 } else if (str[pos] == '{') { 255 pos++; 256 yield return new Token { TokenType = TokenType.LeftPar, strVal = "{" }; 257 } else if (str[pos] == '}') { 258 pos++; 259 yield return new Token { TokenType = TokenType.RightPar, strVal = "}" }; 241 260 } else if (str[pos] == '=') { 242 261 pos++; … … 360 379 } 361 380 362 /// Fact = '(' Expr ')' 363 /// | 'LAG' '(' varId ',' ['+' | '-' ] number ')' 364 /// | funcId '(' ArgList ')' 365 /// | VarExpr | number 381 // Fact = SimpleFact ['^' SimpleFact] 382 private ISymbolicExpressionTreeNode ParseFact(Queue<Token> tokens) { 383 var expr = ParseSimpleFact(tokens); 384 var next = tokens.Peek(); 385 if (next.TokenType == TokenType.Operator && next.strVal == "^") { 386 tokens.Dequeue(); // skip; 387 388 var p = GetSymbol("^").CreateTreeNode(); 389 p.AddSubtree(expr); 390 p.AddSubtree(ParseSimpleFact(tokens)); 391 expr = p; 392 } 393 return expr; 394 } 395 396 397 /// SimpleFact = '(' Expr ')' 398 /// | '{' Expr '}' 399 /// | 'LAG' '(' varId ',' ['+' | '-' ] number ')' 400 /// | funcId '(' ArgList ') 401 /// | VarExpr 402 /// | number 366 403 /// ArgList = Expr { ',' Expr } 367 404 /// VarExpr = varId OptFactorPart … … 370 407 /// varVal = ident | ' ident ' | " ident " 371 408 /// ident = '_' | letter { '_' | letter | digit } 372 private ISymbolicExpressionTreeNode Parse Fact(Queue<Token> tokens) {409 private ISymbolicExpressionTreeNode ParseSimpleFact(Queue<Token> tokens) { 373 410 var next = tokens.Peek(); 374 411 if (next.TokenType == TokenType.LeftPar) { 375 tokens.Dequeue();412 var initPar = tokens.Dequeue(); // match par type 376 413 var expr = ParseExpr(tokens); 377 414 var rPar = tokens.Dequeue(); 378 415 if (rPar.TokenType != TokenType.RightPar) 379 throw new ArgumentException("expected )"); 416 throw new ArgumentException("expected closing parenthesis"); 417 if (initPar.strVal == "(" && rPar.strVal == "}") 418 throw new ArgumentException("expected closing )"); 419 if (initPar.strVal == "{" && rPar.strVal == ")") 420 throw new ArgumentException("expected closing }"); 380 421 return expr; 381 422 } else if (next.TokenType == TokenType.Identifier) { … … 424 465 if (rPar.TokenType != TokenType.RightPar) 425 466 throw new ArgumentException("expected )"); 467 426 468 427 469 return funcNode;
Note: See TracChangeset
for help on using the changeset viewer.