When I execute the below grammar with the input (3), I obtain this parse tree:

It doesn’t recognize the closing parentheses. What might be the problem
term
: IDENT | '(' term ')' | INTEGER
;
INTEGER : '0'..'9'+;
IDENT : ('a'..'z' | 'A'..'Z')('a'..'z' | 'A'..'Z' | '0'..'9')*;
WS : (' ' | '\t' | '\r' | '\n' | '\f')+{$channel = HIDDEN;};
There’s no problem with your grammar. It looks like you’re using the Eclipse ANTLR-plugin, which in its turn uses the interpreter from ANTLRWorks. This interpreter is notoriously buggy: if you get unexpected behavior, always run a manual test, or use ANTLRWorks’ debugger, which debugs the input
"(3)"like this:To start the debugger in ANTLRWors, choose menu Run >> Debug, or press CTL + D.