balance brackets

This commit is contained in:
Denis Molony 2016-03-15 07:09:04 +11:00
parent 9e72f55cbf
commit 95d3930c53
2 changed files with 18 additions and 6 deletions

View File

@ -100,8 +100,6 @@ class Cell implements Comparable<Cell>, Value
expressionText = "24";
else if (address.sortValue == 259)
expressionText = "11.9";
else if (address.sortValue == 579)
expressionText = "D9*G5/(1-((1+G5)^-D4))";
}
String getText (int colWidth, char defaultFormat)
@ -181,8 +179,12 @@ class Cell implements Comparable<Cell>, Value
@Override
public double getValue ()
{
if (type != CellType.VALUE)
return 0;
if (value == null)
createValue ();
return value.getValue ();
}

View File

@ -176,10 +176,20 @@ class Expression implements Value
if (leftBracket != rightBracket)
{
System.out.printf ("**** Unbalanced brackets: left:%d, right:%d ****%n",
leftBracket, rightBracket);
System.out.println (input);
return "@ERROR()";
if (rightBracket > leftBracket)
{
System.out.printf ("**** Unbalanced brackets: left:%d, right:%d ****%n",
leftBracket, rightBracket);
System.out.println (input);
return "@ERROR()";
}
// System.out.printf ("Old expression:[%s]%n", line);
while (rightBracket < leftBracket)
{
line = line + ")";
rightBracket++;
}
// System.out.printf ("New expression:[%s]%n", line);
}
return line;
}