public double CalculateExpressionWithCoordinates(string expression, Cell[,] cells, ReversePolishNotation reversePolishNotation) { string transformatedExpression = ""; string[] parts = reversePolishNotation.DivideExpressionOnParts(expression); foreach (string part in parts) { if (Regex.IsMatch(part, @"^[^A-Z]*$")) { transformatedExpression += part; } else { transformatedExpression += CoordinatesToCellExpression(cells, part); } } return(reversePolishNotation.Calculate((transformatedExpression))); }
public void TransformNumbersOnlyExpressions(Cell[,] cells, int maxSize, ReversePolishNotation reversePolishNotation) { Cell cell = new Cell(); for (int i = 1; i < maxSize; i++) { for (int j = 1; j < maxSize; j++) { cell = cells[i, j]; if (cell.GetExpression() == null) { cell.SetValue(0); } else if (cell.GetExpression()[0] == '-') { cell.SetValue(Convert.ToDouble(cell.GetExpression())); } else if (Regex.IsMatch(cell.GetExpression(), @"^[^A-Z]*$")) { cell.SetValue(reversePolishNotation.Calculate(cell.GetExpression())); } } } }