title: JavaCC dump method to print AST
body: <p>I am using JavaCC to print an AST in a particular format.
  I need it to be like this :</p>
  
  <pre><code>LetNode( Identier(X), ExprNode( PlusNode( IntegerLiteral(8), IntegerLiteral(2) ))) 
  </code></pre>
  
  <p>but  I am getting:</p>
  
  <pre><code>Start(LetNode(Identifier(x)(ExprNode(IntegerLiteral(5)(PlusNode(IntegerLiteral(5)()))
  </code></pre>
  
  <p>I am using the dump method to print this:</p>
  
  <pre><code>public void dump(String prefix) {
    System.out.print(toString(prefix));
    System.out.print("(");
    if (children != null) {
  
      for (int i = 0; i &lt; children.length; ++i) {
        SimpleNode n = (SimpleNode)children[i];
        if (n != null) {
          n.dump(prefix +"");
        }
      }
      System.out.print(")");
    }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The output without any modification is :</p>
  
  <pre><code>Start
    Sxl
     Statement
      VariableDecl
       Identifier
       Type
       Expression
        SimpleExpression
         Term
          Factor
           Literal
            IntegerLiteral
         AdditiveOp
         Term
          Factor
           Literal
            IntegerLiteral
  </code></pre>
  
  <p>My method:</p>
  
  <pre><code>void AdditiveOp():
  {}  
  {
     (Plus() /*#Add(2)*/ | Minus() | Or())
  
  }
  
  void Plus():
  {
  }
  {
    (&lt; PLUS &gt;)
    #PlusNode
  }
  </code></pre>
  
  <p>If I remove the /* */ it does not work as it says it expects something else not +</p>
  
  <p>Any help would be greatly appreciated!</p>