public void process() throws Exception {
//		System.out.println("exec "+grammarName+"."+startRuleName);
		String lexerName = grammarName+"Lexer";
		ClassLoader cl = Thread.currentThread().getContextClassLoader();
		Class<? extends Lexer> lexerClass = null;
		try {
			lexerClass = cl.loadClass(lexerName).asSubclass(Lexer.class);
		}
		catch (java.lang.ClassNotFoundException cnfe) {
			// might be pure lexer grammar; no Lexer suffix then
			lexerName = grammarName;
			try {
				lexerClass = cl.loadClass(lexerName).asSubclass(Lexer.class);
			}
			catch (ClassNotFoundException cnfe2) {
				System.err.println("Can't load "+lexerName+" as lexer or parser");
				return;
			}
		}

		Constructor<? extends Lexer> lexerCtor = lexerClass.getConstructor(CharStream.class);
		Lexer lexer = lexerCtor.newInstance((CharStream)null);

		Class<? extends Parser> parserClass = null;
		Parser parser = null;
		if ( !startRuleName.equals(LEXER_START_RULE_NAME) ) {
			String parserName = grammarName+"Parser";
			parserClass = cl.loadClass(parserName).asSubclass(Parser.class);
			Constructor<? extends Parser> parserCtor = parserClass.getConstructor(TokenStream.class);
			parser = parserCtor.newInstance((TokenStream)null);
		}

		Charset charset = ( encoding == null ? Charset.defaultCharset () : Charset.forName(encoding) );
		if ( inputFiles.size()==0 ) {
			CharStream charStream = CharStreams.fromStream(System.in, charset);
			process(lexer, parserClass, parser, charStream);
			return;
		}
		for (String inputFile : inputFiles) {
	                CharStream charStream = CharStreams.fromPath(Paths.get(inputFile), charset);
			if ( inputFiles.size()>1 ) {
				System.err.println(inputFile);
			}
			process(lexer, parserClass, parser, charStream);
		}
	}
Run a lexer/parser combo, optionally printing tree string or generating
 postscript file. Optionally taking input file.

 $ java org.antlr.v4.runtime.misc.TestRig GrammarName startRuleName
       [-tree]
       [-tokens] [-gui] [-ps file.ps]
       [-trace]
       [-diagnostics]
       [-SLL]
       [input-filename(s)]
tool/src/org/antlr/v4/gui/TestRig.java