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 902c43841..3b9e0f6de 100755 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java @@ -432,7 +432,7 @@ public class ParserATNSimulator extends ATNSimulator { loop: while ( true ) { if ( dfa_debug ) System.out.println("DFA state "+s.stateNumber+" LA(1)=="+getLookaheadName(input)); - if ( s.isCtxSensitive && !SLL ) { + if ( s.requiresFullContext && !SLL ) { if ( dfa_debug ) System.out.println("ctx sensitive state "+outerContext+" in "+s); boolean loopsSimulateTailRecursion = true; boolean fullCtx = true; @@ -464,7 +464,7 @@ public class ParserATNSimulator extends ATNSimulator { } // t is not updated if one of these states is reached - assert !s.isCtxSensitive && !s.isAcceptState; + assert !s.requiresFullContext && !s.isAcceptState; // if no edge, pop over to ATN interpreter, update DFA and return if ( s.edges == null || t >= s.edges.length || t < -1 || s.edges[t+1] == null ) { @@ -506,7 +506,7 @@ public class ParserATNSimulator extends ATNSimulator { throw noViableAlt(input, outerContext, s.configs, startIndex); } s = target; - if (!s.isCtxSensitive && !s.isAcceptState) { + if (!s.requiresFullContext && !s.isAcceptState) { input.consume(); t = input.LA(1); } @@ -674,6 +674,9 @@ public class ParserATNSimulator extends ATNSimulator { } else { // SLL CONFLICT; RETRY WITH FULL LL CONTEXT + // (it's possible SLL with preds could resolve to single alt + // which would mean we could avoid full LL, but not worth + // code complexity.) if ( debug ) System.out.println("RETRY with outerContext="+outerContext); // don't look up context in cache now since we're just creating state D loopsSimulateTailRecursion = true; @@ -689,7 +692,7 @@ public class ParserATNSimulator extends ATNSimulator { D.configs.conflictingAlts.getMinElement(), greedy); // not accept state: isCtxSensitive - D.isCtxSensitive = true; // always force DFA to ATN simulate + D.requiresFullContext = true; // always force DFA to ATN simulate D.prediction = ATN.INVALID_ALT_NUMBER; addDFAEdge(dfa, previousD, t, D); return predictedAlt; // all done with preds, etc... @@ -766,6 +769,7 @@ public class ParserATNSimulator extends ATNSimulator { } } + // all adds to dfa are done after we've created full D state addDFAEdge(dfa, previousD, t, D); if ( D.isAcceptState ) return predictedAlt; diff --git a/runtime/Java/src/org/antlr/v4/runtime/dfa/DFASerializer.java b/runtime/Java/src/org/antlr/v4/runtime/dfa/DFASerializer.java index 0b06d4c5a..3f8316d5f 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/dfa/DFASerializer.java +++ b/runtime/Java/src/org/antlr/v4/runtime/dfa/DFASerializer.java @@ -89,7 +89,7 @@ public class DFASerializer { stateStr = ":s"+n+"=>"+s.prediction; } } - else if ( s.isCtxSensitive ) { + else if ( s.requiresFullContext) { stateStr = "s"+n+"^"; } return stateStr; diff --git a/runtime/Java/src/org/antlr/v4/runtime/dfa/DFAState.java b/runtime/Java/src/org/antlr/v4/runtime/dfa/DFAState.java index 496384af2..a1fa88c8e 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/dfa/DFAState.java +++ b/runtime/Java/src/org/antlr/v4/runtime/dfa/DFAState.java @@ -89,7 +89,7 @@ public class DFAState { * Future execDFA() invocations immediately jumped doing full context * prediction if this field is true. */ - public boolean isCtxSensitive; + public boolean requiresFullContext; /** During SLL parsing, this is a list of predicates associated with the * ATN configurations of the DFA state. When we have predicates, diff --git a/tool/src/org/antlr/v4/tool/DOTGenerator.java b/tool/src/org/antlr/v4/tool/DOTGenerator.java index 236f59dcc..97a20215e 100644 --- a/tool/src/org/antlr/v4/tool/DOTGenerator.java +++ b/tool/src/org/antlr/v4/tool/DOTGenerator.java @@ -139,7 +139,7 @@ public class DOTGenerator { if ( s.isAcceptState ) { buf.append("=>").append(s.prediction); } - if ( s.isCtxSensitive ) { + if ( s.requiresFullContext) { buf.append("^"); } if ( grammar!=null && grammar.tool.verbose_dfa ) { diff --git a/tool/test/org/antlr/v4/test/TestParserExec.java b/tool/test/org/antlr/v4/test/TestParserExec.java index f113883d1..e151f78f3 100644 --- a/tool/test/org/antlr/v4/test/TestParserExec.java +++ b/tool/test/org/antlr/v4/test/TestParserExec.java @@ -199,13 +199,9 @@ public class TestParserExec extends BaseTest { */ @Test public void testIfIfElse() throws Exception { - /* - With the predicate, this looks to be context sensitive to the full - LL prediction because that edge literally disappears. With SLL - prediction, it sees a conflict. Even though there's a predicate, - it can't be sure that context would not resolve the conflict. Hence, - it retries with full context and sees no conflict. - */ + // Sam's works here but mine doesn't since I fail over to LL even + // though SLL + preds evals to single alt; i could avoid but + // code complexity wasn't worth it. see branch SLL-w-preds-avoids-LL String grammar = "grammar T;\n" + "s : stmt EOF ;\n" +