One of the features the compiler for my programming language is supposed to have is the ability to draw AST-es, to make it easier to detect when syntax doesn't mean exactly what the programmer meant. That part of my compiler is runnable in a browser, you can see it here.
Thus far, I've come up with an algorithm that successfully draws diagrams like this one:
However, it fails to print good diagrams for expressions with "deeper" AST-es, such as even:
1+2+3+4+5The diagram it draws for that one is a lot wider than what's needed to make it legible, so much so that it's illegible because of that.
So, which algorithm would you use to draw AST-es?