void execParse() throws Exception {
		if ( grammarFileName==null && (parserGrammarFileName==null && lexerGrammarFileName==null) ) {
			System.err.println("No grammar specified");
			return;
		}

		if ( inputFileName==null ) {
			System.err.println("No input file specified");
			return;
		}

		String grammarName =
				grammarFileName.substring(grammarFileName.lastIndexOf('/')+1, grammarFileName.length());
		grammarName = grammarName.substring(0, grammarName.indexOf(".g4"));
		if ( grammarFileName!=null ) {
			String grammar = new String(Files.readAllBytes(Paths.get(grammarFileName)));

			String input = new String(Files.readAllBytes(Paths.get(inputFileName)));

			RuntimeTestDescriptor descriptor = new RuntimeTestDescriptor(
					GrammarType.CompositeParser,
					"TraceATN-" + grammarFileName,
					"",
					input,
					"",
					"",
					startRuleName,
					grammarName,
					grammar,
					null,
					false,
					true,
					false,
					PredictionMode.LL,
					true,
					null,
					null);

			RuntimeRunner runner = getRunner(targetName);

			String result = test(descriptor, runner, targetName);
			System.out.println(result);
		}
	}
Run a lexer/parser and dump ATN debug/trace information

 java org.antlr.v4.test.runtime.TraceATN [X.g4|XParser.g4 XLexer.g4] startRuleName -target [Java|Cpp|...] inputFileName


In preparation, run this so we get right jars before trying this script:

cd ANTLR-ROOT-DIR
mvn install -DskipTests=true
cd runtime-tests
mvn install jar:test-jar -DskipTests=true

Run shell script with

scripts/traceatn.sh /tmp/JSON.g4 json /tmp/foo.json

Here is scripts/traceatn.sh:

export ANTLRJAR=/Users/parrt/.m2/repository/org/antlr/antlr4/4.11.2-SNAPSHOT/antlr4-4.11.2-SNAPSHOT-complete.jar
export TESTJAR=/Users/parrt/.m2/repository/org/antlr/antlr4-runtime-testsuite/4.11.2-SNAPSHOT/antlr4-runtime-testsuite-4.11.2-SNAPSHOT-tests.jar
java -classpath $ANTLRJAR:$TESTJAR org.antlr.v4.test.runtime.TraceATN $@
runtime-testsuite/test/org/antlr/v4/test/runtime/TraceATN.java