title: What Does the ANTLR ParseTree accept() method do?
body: <p>I´m studying how to build a typechecker using ANTLR´s Tree walker. I saw there´s an accept method. This method is sometimes used  in compilers books when showing examples of a type checker implementation</p>
  
  <pre><code>public Type visit(Plus n) {
  if (! (n.e1.accept(this) instanceof IntegerType) )
  error.complain("Left side of LessThan must be of type integer");
  if (! (n.e2.accept(this) instanceof IntegerType) )
  error.complain("Right side of LessThan must be of type integer");
  return new IntegerType();
  }
  </code></pre>
  
  <p>That piece of code is from the book Modern Compiler Implementation In Java. But I don´t really understand what n.e1.accept(this) does.Every node of the tree has this method in ANTLR.</p>
  
  <p>I´ve checked ANTLR v4 docs and the explanation is not really clear;</p>
  
  <pre><code>The ParseTreeVisitor needs a double dispatch method.
  </code></pre>
  
  <p>Can someone explain me what this does?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I researched a bit more and it is not an ANTLR specific question, I think this can be considered as a duplicate question so maybe it is a good idea to remove it:</p>
  
  <p><a href="https://stackoverflow.com/questions/9132178/what-is-the-point-of-accept-method-in-visitor-pattern">What is the point of accept() method in Visitor pattern?</a></p>