- Timestamp:
- 10/12/11 15:45:04 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization/3.3/Calculator.cs
r6902 r6908 25 25 26 26 private static readonly Regex TokenRegex = 27 new Regex(@" [a-zA-Z0-9._]+|""([^""]|\\"")*""|'([^']|\\')*'|[-+*/<>^]|dup|swap|drop|log|true|false|if|==|not|isnull|null|ismatch|rename");27 new Regex(@"""(\\""|[^""])*""|'(\\'|[^'])*'|[^\s]+"); 28 28 29 29 #endregion … … 61 61 stack.Push(d); 62 62 } else if (token.StartsWith("\"")) { 63 stack.Push(GetVariableValue(variables, token.Substring(1, token.Length - 2).Replace( @"\""", @"""")));63 stack.Push(GetVariableValue(variables, token.Substring(1, token.Length - 2).Replace("\\\"", "\""))); 64 64 } else if (token.StartsWith("'")) { 65 stack.Push(token.Substring(1, token.Length-2).Replace("\ '", "'"));65 stack.Push(token.Substring(1, token.Length-2).Replace("\\'", "'")); 66 66 } else { 67 67 Apply(token, stack, variables); … … 70 70 } catch (Exception x) { 71 71 throw new Exception(string.Format( 72 "Calculation Failed at token #{1}: '{2}' {0}current stack is: {0}{3}", Environment.NewLine, 73 i, tokens[i], string.Join(Environment.NewLine, stack.Select(AsString))), 72 "Calculation of '{1}'{0}failed at token #{2}: '{3}' {0}current stack is: {0}{4}", Environment.NewLine, 73 Formula, i, tokens[i], 74 string.Join(Environment.NewLine, stack.Select(AsString))), 74 75 x); 75 76 } 76 if (stack.Count != 1) throw new Exception(string.Format("Invalid final evaluation stack size {0} (should be 1)", stack.Count)); 77 if (stack.Count != 1) 78 throw new Exception( 79 string.Format("Invalid final evaluation stack size {0} (should be 1) in formula '{1}'", 80 stack.Count, Formula)); 77 81 var result = stack.Pop(); 78 82 if (result is string) return new StringValue((string)result);
Note: See TracChangeset
for help on using the changeset viewer.