ANTLR visit method not being invoked
<p>I am working on a project using antlr generated code in Java. When I create a parse tree, it generates the correct tree. But when I pass that tree to visit method, the visit method returns null.</p>

<p><strong>Grammar File:</strong></p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>grammar Formula;

formula : expression+ EOF;

expression
    : ID '(' term (',' term)* ')'                               # doPredicate
    | '(' expression ')'                                        # doParenthesis
    | '~' expression                                            # doNot
    | expression '=&gt;' expression                                # doThen
    | expression '&lt;=&gt;' expression                               # doIFF
    | expression '&lt;=' expression                                # doIF
    | expression '?' expression ':' expression                  # doITE
    | expression '&amp;' expression                                 # doAnd
    | expression '|' expression                                 # doOr
    | expression '^' expression                                 # doXor
    | 'forall' VAR 'in' (range_expr | set_expr)  expression     # doExpandAnd
    | 'exists' VAR 'in' (range_expr | set_expr)  expression     # doExpandOr
    | TRUE                                                      # newTrueBoolean
    | FALSE                                                     # newFalseBoolean
    | VAR                                                       # newVariable
    | ID                                                        # newIdentifier
    ;

term
    : ID                                              # newTermID
    | VAR                                             # newTermVar
    | int_expr                                        # doIntExpr
    ;

int_expr
    : '(' int_expr ')'                                # parenthesizedIntExpression
    | '|' int_expr '|'                                # absValueExpression
    | '-' int_expr                                    # unaryMinusExpression
    | int_expr op=( '*' | '/' | '%' ) int_expr        # multiplicativeExpression
    | int_expr op=( '+' | '-' ) int_expr              # additiveExpression
    | VAR                                             # newIntVariable
    | NUMBER                                          # newInteger
    ;

range_expr 
    : '{' (int_expr '..' int_expr) '}' ;

set_expr 
    : '{' term (',' term)*  '}' ;

// Tokens
TRUE            : 'True';
FALSE           : 'False';
ID              : LETTER ALPHANUM*;
VAR             : '_' LETTER ALPHANUM*;
NUMBER          : DIGIT+;

// Drops whitespaces and comments
WS              : [ \t\n\r]+ -&gt; skip ;
COMMENTS        : ('/*' .*? '*/' | '//' ~'\n'* '\n' ) -&gt; skip;

// Fragments
fragment DIGIT    : '0' .. '9';
fragment UPPER    : 'A' .. 'Z';
fragment LOWER    : 'a' .. 'z';
fragment LETTER   : LOWER | UPPER;
fragment WORD     : LETTER | '_' | '$' | '#' | '.';
fragment ALPHANUM : WORD | DIGIT;</code></pre>
</div>
</div>
</p>

<p><strong>FormulaTreeVisitor.java</strong></p>

<p>public class FormulaTreeVisitor extends FormulaBaseVisitor {</p>

<pre><code>@Override
public String visitFormula(FormulaParser.FormulaContext ctx) {
    // TODO Auto-generated method stub
    System.out.println("Hi");
    super.visitFormula(ctx);
    System.out.println("Hi");
    return "Hi";
}   
</code></pre>

<p>}</p>

<p><strong>Test.java</strong></p>

<p>public class Test {</p>

<pre><code>/**
 * @param args
 */
public static void main(String[] args) {
    ANTLRInputStream in = new ANTLRInputStream("a|b");
    FormulaLexer lexer = new FormulaLexer(in);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    FormulaParser parser = new FormulaParser(tokens);

    ParseTree tree = parser.formula(); 
    System.out.println(tree.toStringTree(parser));
    FormulaTreeVisitor eval = new FormulaTreeVisitor();
    String f = eval.visit(tree);
    System.out.println(f);

    //show AST in GUI
    JFrame frame = new JFrame("Antlr AST");
    JPanel panel = new JPanel();
    TreeViewer viewr = new TreeViewer(Arrays.asList(
            parser.getRuleNames()),tree);
    viewr.setScale(1.5);//scale a little
    panel.add(viewr);
    frame.add(panel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(200,200);
    frame.setVisible(true);
}
</code></pre>

<p>}</p>

<p><strong>Output in Console:</strong></p>

<p>(formula (expression (expression a) | (expression b)) )
null</p>

<p>The visitFormula method in the FormulaTreeVisitor class is never invoked. Moreover the eval.visit(tree) returns null. Can someone help me how to get the visitFormula method get invoked so that I can implement my logic. </p>