Changeset 8778
- Timestamp:
- 10/10/12 12:10:22 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization/3.3/RunCollectionModification/Calculator.cs
r7228 r8778 3 3 using System.Globalization; 4 4 using System.Linq; 5 using System.Text; 5 6 using System.Text.RegularExpressions; 6 7 using HeuristicLab.Common; … … 8 9 using HeuristicLab.Data; 9 10 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 10 using System.Text;11 11 12 12 namespace HeuristicLab.Optimization { … … 21 21 [Storable] 22 22 public string Formula { 23 get { return string.Join(" ", tokens); }23 get { return tokens == null ? string.Empty : string.Join(" ", tokens); } 24 24 set { tokens = Tokenize(value).ToList(); } 25 25 } … … 56 56 int i = 0; 57 57 try { 58 for (; i <tokens.Count; i++) {58 for (; i < tokens.Count; i++) { 59 59 var token = tokens[i]; 60 60 double d; … … 64 64 stack.Push(GetVariableValue(variables, token.Substring(1, token.Length - 2).Replace("\\\"", "\""))); 65 65 } else if (token.StartsWith("'")) { 66 stack.Push(token.Substring(1, token.Length -2).Replace("\\'", "'"));66 stack.Push(token.Substring(1, token.Length - 2).Replace("\\'", "'")); 67 67 } else { 68 68 Apply(token, stack, variables); 69 69 } 70 70 } 71 } catch (Exception x) { 71 } 72 catch (Exception x) { 72 73 throw new Exception(string.Format( 73 74 "Calculation of '{1}'{0}failed at token #{2}: {3} {0}current stack is: {0}{4}", Environment.NewLine, 74 Formula, i, TokenWithContext(tokens, i, 3), 75 Formula, i, TokenWithContext(tokens, i, 3), 75 76 string.Join(Environment.NewLine, stack.Select(AsString))), 76 77 x); … … 89 90 private string TokenWithContext(List<string> tokens, int i, int context) { 90 91 var sb = new StringBuilder(); 91 if (i > context +1)92 if (i > context + 1) 92 93 sb.Append("... "); 93 94 int prefix = Math.Max(0, i - context); … … 104 105 private static void Apply(string token, Stack<object> stack, IDictionary<string, IItem> variables) { 105 106 switch (token) { 106 case "null": 107 case "true": 107 case "null": stack.Push(null); break; 108 case "true": stack.Push(true); break; 108 109 case "false": stack.Push(false); break; 109 110 … … 186 187 try { 187 188 stack.Push(func(a)); 188 } catch (Exception) { 189 } 190 catch (Exception) { 189 191 stack.Push(a); 190 192 throw; … … 199 201 try { 200 202 stack.Push(func(a, b)); 201 } catch (Exception) { 203 } 204 catch (Exception) { 202 205 stack.Push(b); 203 206 stack.Push(a); … … 214 217 try { 215 218 stack.Push(func(a, b, c)); 216 } catch (Exception) { 219 } 220 catch (Exception) { 217 221 stack.Push(a); 218 222 stack.Push(b);
Note: See TracChangeset
for help on using the changeset viewer.