title: How to visualize an Abstract Syntax Tree graphically?
body: <p>I wrote a simple compiler in C++ and want to visualize the Abstract Syntax Tree it produces. Currently, I dump the AST in a super long string similar to something below:</p>
  
  <p><code>
  Program(decls=[ConstDecl(type=BasicTypeKind::Int, value=Num(n=1, loc=Location(1, 21)), name=positive, loc=Location(1, 10)), ConstDecl(type=BasicTypeKind::Int, value=Num(n=-1, loc=Location(2, 21)), name=negative, loc=Location(2, 10)), ConstDecl(type=BasicTypeKind::Int, value=Num(n=100, loc=Location(3, 26)), name=max_heap_size, loc=Location(3, 10)), ConstDecl(type=BasicTypeKind::Character, value=Char(c=99, loc=Location(4, 23)), name=...
  </code></p>
  
  <p>As you can see, this dump isn't very human friendly in terms of visualization. One cannot naturally relate the notion a <strong>tree</strong> to such a long string. I tried the approach to pretty-print the AST and found <a href="https://github.com/asottile/astpretty" rel="nofollow noreferrer">astpretty</a>, which is for Python. It aims a lot in debugging but what if I want an illustration of the AST? A graphical format surely fits better.</p>
  
  <p>Actually I have the picture about what the output I am looking forward. <code>Graphviz</code> does a great job on this field and various graphs the C++ document tool <code>Doxygen</code> generates are very close to my purpose conceptually.</p>
  
  <p>Putting these together, I want a way to turn an AST in memory as C++ objects into decent graphic output (static one is ok). Any good starting point?</p>
  
  <p><strong>Edit:</strong> as comments said, dumping my AST in format <code>Graphviz</code> recognizes is a good starting point. I will try do it this way until new and more concrete problems arise. Thanks guys.</p>