public string eval(string problem) { problem = "(" + problem + ")"; System.Diagnostics.Debug.WriteLine("Evaluating Problem: " + problem); UnitProblemContextDescription context = getNextUnitProblemContextDescription(problem); while (true) { // .... solve problem in context System.Diagnostics.Debug.WriteLine("Evaluating New Context: " + context.context); context.solution = solveContextProblem(context.context); // .... replace solved context in problem with solution context.problem = replaceSubString(context.problem, context.solution, context.head, context.tail); context = getNextUnitProblemContextDescription(context.problem); // .... if problem is solved if (context.head == context.tail) { if (context.problem == null) { return(""); } else { return(context.problem); } } } }
public UnitProblemContextDescription getNextUnitProblemContextDescription(string problem) { UnitProblemContextDescription context = new UnitProblemContextDescription(); context.problem = problem; for (int i = 0; i < problem.Length; i++) { switch (problem.ElementAt <char>(i)) { case '(': context.head = i; break; case ')': context.tail = i; context.context = problem.Substring(context.head + 1, context.tail - context.head - 1); return(context); } } return(context); }