while (true)
{
// now start to optimize everything.
// first, search the operator with the highest priority..
final InfixOperator op = (InfixOperator) operators.get(0);
int level = op.getLevel();
boolean moreThanOne = false;
for (int i = 1; i < operators.size(); i++)
{
final InfixOperator operator = (InfixOperator) operators.get(i);
final int opLevel = operator.getLevel();
if (opLevel != level)
{
moreThanOne = true;
level = Math.min(opLevel, level);
}
}
if (moreThanOne == false)
{
// No need to optimize the operators ..
break;
}
// There are at least two op-levels in this term.
Term subTerm = null;
for (int i = 0; i < operators.size(); i++)
{
final InfixOperator operator = (InfixOperator) operators.get(i);
if (operator.getLevel() != level)
{
subTerm = null;
continue;
}