public List<String> getRuleInvocationStack(RuleContext p) {
		String[] ruleNames = getRuleNames();
		List<String> stack = new ArrayList<String>();
		while ( p!=null ) {
			// compute what follows who invoked us
			int ruleIndex = p.getRuleIndex();
			if ( ruleIndex<0 ) stack.add("n/a");
			else stack.add(ruleNames[ruleIndex]);
			p = p.parent;
		}
		return stack;
	}
Return List&lt;String&gt; of the rule names in your parser instance
 leading up to a call to the current rule.  You could override if
 you want more details such as the file/line info of where
 in the ATN a rule is invoked.

 This is very useful for error messages.
runtime/Java/src/org/antlr/v4/runtime/Parser.java