I cannot reproduce this. Given the class:
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.*;
public class Main {
public static void main(String[] args) throws Exception {
TestLexer lexer = new TestLexer(new ANTLRFileStream("test.txt"));
// `test.txt` contains your input, btw
TestParser parser = new TestParser(new CommonTokenStream(lexer));
ParseTree tree = parser.node();
ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(new MyListener(), tree);
}
}
and testing at follows:
java -cp antlr-4.2.1-complete.jar org.antlr.v4.Tool Test.g4 javac -cp .:antlr-4.2.1-complete.jar *.java java -cp .:antlr-4.2.1-complete.jar Main
I see 5
being printed on my console.