public static String parentheticRepresentation(Tree T, Position v) {
String s = v.element().toString(); // elements must implement toString
if (T.isInternal(v)) {
Iterator children = T.children(v);
// open parenthesis and recursively process the first subtree
s += " ( " + parentheticRepresentation(T, (Position) children.next());
while (children.hasNext())
// recursively process the remaining subtrees
s += ", " + parentheticRepresentation(T, (Position) children.next());
s += " )"; // close parenthesis
}
return s;
}