title: Parse a formula using ANTLR4
body: <p>I am trying to parse a mathematical formula to a subset of LaTeX using ANTLR4. For example it should parse <code>(a+4)/(b*10)</code> to <code>\frac{a+4}{b\cdot 10}</code>.</p>
  
  <p>My simple grammar creates a tree like this:</p>
  
  <p><img src="https://i.stack.imgur.com/e0RSC.png" alt="antlr tree"></p>
  
  <p>Now I am trying to implement parse tree listeners to somehow construct the LaTeX String while the tree is traversed. Here, I am failing because to construct a String like <code>\frac{}{}</code> it has to be built recursively. The parse tree walker, however, visits one tree node after the other (in a breadth-first way as far as I can tell).</p>
  
  <p>I've read about parse tree <em>visitors</em> that might be what I need. But I wasn't able to find some examples how these visitors are applied.</p>
  
  <p>Could you provide an example how parse tree listeners/visitors can be used in this particular case? Do you think my approach to use ANTLR for the parser makes sense in the first place?</p>