protected String processSubExpression(
String exp, int pos, String token, int closingParenPos, List<TreeNode> nodes) {
// recursive call for sub expression
String subExp = exp.substring(pos, closingParenPos);
TreeNode subTree = parse(subExp);
subTree.hasParens = true;
if (token != null && token.length() > 0) {
// there was some leading token before the parenthesized expression.
pushNodesForToken(token, nodes);
token = "";
nodes.add(new TreeNode(MathOperator.TIMES.getSymbol(), opDef));
}
else if (!nodes.isEmpty() && nodes.get(nodes.size() - 1).hasParens) {
nodes.add(new TreeNode(MathOperator.TIMES.getSymbol(), opDef));
}
nodes.add(subTree);
return token;
}