protected ParseInfo interp() throws RecognitionException, IOException {
		if ( grammarFileName==null && (parserGrammarFileName==null && lexerGrammarFileName==null) ) {
			return null;
		}
		Grammar g;
		LexerGrammar lg = null;
		DefaultToolListener listener = new DefaultToolListener(new Tool());
		if (grammarFileName != null) {
			String grammarContent = Files.readString(Path.of(grammarFileName));
			g = new IgnoreTokenVocabGrammar(grammarFileName, grammarContent, null, listener);
		}
		else {
			String lexerGrammarContent = Files.readString(Path.of(lexerGrammarFileName));
			lg = new LexerGrammar(lexerGrammarContent, listener);
			String parserGrammarContent = Files.readString(Path.of(parserGrammarFileName));
			g = new IgnoreTokenVocabGrammar(parserGrammarFileName, parserGrammarContent, lg, listener);
		}

		Charset charset = ( encoding == null ? Charset.defaultCharset () : Charset.forName(encoding) );
		CharStream charStream = null;
		if ( inputFileName==null ) {
			charStream = CharStreams.fromStream(System.in, charset);
		}
		else {
			try {
				charStream = CharStreams.fromPath(Paths.get(inputFileName), charset);
			}
			catch (NoSuchFileException nsfe) {
				System.err.println("Can't find input file "+inputFileName);
				System.exit(1);
			}
		}

		LexerInterpreter lexEngine = (lg!=null) ?
				lg.createLexerInterpreter(charStream) :
				g.createLexerInterpreter(charStream);

		CommonTokenStream tokens = new CommonTokenStream(lexEngine);

		tokens.fill();

		if ( showTokens ) {
			for (Token tok : tokens.getTokens()) {
				if ( tok instanceof CommonToken ) {
					System.out.println(((CommonToken)tok).toString(lexEngine));
				}
				else {
					System.out.println(tok.toString());
				}
			}
		}

		GrammarParserInterpreter parser = g.createGrammarParserInterpreter(tokens);
		if ( profileFileName!=null ) {
			parser.setProfile(true);
		}
		parser.setTrace(trace);

		Rule r = g.rules.get(startRuleName);
		if (r == null) {
			System.err.println("No such start rule: "+startRuleName);
			return null;
		}
		ParseTree t = parser.parse(r.index);
		ParseInfo parseInfo = parser.getParseInfo();

		if ( printTree ) {
			System.out.println(t.toStringTree(parser));
		}
		if ( gui ) {
			Trees.inspect(t, parser);
		}
		if ( profileFileName!=null ) {
			dumpProfilerCSV(parser, parseInfo);
		}

		return parseInfo;
	}
Interpret a lexer/parser, optionally printing tree string and dumping profile info

 $ java org.antlr.v4.gui.Interpreter [X.g4|XParser.g4 XLexer.g4] startRuleName inputFileName
       [-tree]
       [-gui]
       [-trace]
       [-encoding encoding]
       [-tokens]
       [-profile filename.csv]
tool/src/org/antlr/v4/gui/Interpreter.java