diff --git a/runtime/Java/src/org/antlr/v4/runtime/ParserInterpreter.java b/runtime/Java/src/org/antlr/v4/runtime/ParserInterpreter.java index 2987697af..84a9350d0 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/ParserInterpreter.java +++ b/runtime/Java/src/org/antlr/v4/runtime/ParserInterpreter.java @@ -148,8 +148,16 @@ public class ParserInterpreter extends Parser { case ATNState.RULE_STOP : // pop; return from rule if ( _ctx.isEmpty() ) { - exitRule(); - return rootContext; + if (startRuleStartState.isPrecedenceRule) { + ParserRuleContext result = _ctx; + Pair parentContext = _parentContextStack.pop(); + unrollRecursionContexts(parentContext.a); + return result; + } + else { + exitRule(); + return rootContext; + } } visitRuleStopState(p);