From 7453ddaf72339b195c6cd75dee6e3f4186c0ceed Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Mon, 24 Jun 2013 14:55:52 -0500 Subject: [PATCH] closureBusy set is only necessary to prevent infinite recursion for right-recursive SLL rules (fixes #282) --- .../src/org/antlr/v4/runtime/atn/ParserATNSimulator.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java index 987efd831..39130b19c 100755 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java @@ -1063,8 +1063,6 @@ public class ParserATNSimulator extends ATNSimulator { { if ( debug ) System.out.println("closure("+config.toString(parser,true)+")"); - if ( depth != 0 && !closureBusy.add(config) ) return; // avoid infinite recursion - if ( config.state instanceof RuleStopState ) { // We hit rule end. If we have context info, use it // run thru all possible stack tops in ctx @@ -1144,6 +1142,12 @@ public class ParserATNSimulator extends ATNSimulator { // track how far we dip into outer context. Might // come in handy and we avoid evaluating context dependent // preds if this is > 0. + + if (!closureBusy.add(c)) { + // avoid infinite recursion for right-recursive rules + continue; + } + c.reachesIntoOuterContext++; configs.dipsIntoOuterContext = true; // TODO: can remove? only care when we add to set per middle of this method assert newDepth > Integer.MIN_VALUE;