forked from jasder/antlr
Evaluate preds in SLL before falling back to full context, avoid full context prediction if unique alternative results
This commit is contained in:
parent
691532190c
commit
aba4034051
|
@ -418,6 +418,17 @@ public class ParserATNSimulator extends ATNSimulator {
|
||||||
while ( true ) {
|
while ( true ) {
|
||||||
if ( dfa_debug ) System.out.println("DFA state "+s.stateNumber+" LA(1)=="+getLookaheadName(input));
|
if ( dfa_debug ) System.out.println("DFA state "+s.stateNumber+" LA(1)=="+getLookaheadName(input));
|
||||||
if ( s.requiresFullContext && mode != PredictionMode.SLL ) {
|
if ( s.requiresFullContext && mode != PredictionMode.SLL ) {
|
||||||
|
// IF PREDS, MIGHT RESOLVE TO SINGLE ALT => SLL (or syntax error)
|
||||||
|
if ( s.predicates!=null ) {
|
||||||
|
if ( debug ) System.out.println("DFA state has preds in DFA sim LL failover");
|
||||||
|
input.seek(startIndex);
|
||||||
|
BitSet alts = evalSemanticContext(s.predicates, outerContext, true);
|
||||||
|
if ( alts.cardinality()==1 ) {
|
||||||
|
if ( debug ) System.out.println("Full LL avoided");
|
||||||
|
return alts.nextSetBit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( dfa_debug ) System.out.println("ctx sensitive state "+outerContext+" in "+s);
|
if ( dfa_debug ) System.out.println("ctx sensitive state "+outerContext+" in "+s);
|
||||||
boolean fullCtx = true;
|
boolean fullCtx = true;
|
||||||
ATNConfigSet s0_closure =
|
ATNConfigSet s0_closure =
|
||||||
|
@ -647,6 +658,17 @@ public class ParserATNSimulator extends ATNSimulator {
|
||||||
// Falls through to check predicates below
|
// Falls through to check predicates below
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// IF PREDS, MIGHT RESOLVE TO SINGLE ALT => SLL (or syntax error)
|
||||||
|
if ( D.configs.hasSemanticContext ) {
|
||||||
|
predicateDFAState(D, decState);
|
||||||
|
input.seek(startIndex);
|
||||||
|
BitSet alts = evalSemanticContext(D.predicates, outerContext, true);
|
||||||
|
if ( alts.cardinality()==1 ) {
|
||||||
|
if ( debug ) System.out.println("Full LL avoided");
|
||||||
|
return alts.nextSetBit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// RETRY WITH FULL LL CONTEXT
|
// RETRY WITH FULL LL CONTEXT
|
||||||
if ( debug ) System.out.println("RETRY with outerContext="+outerContext);
|
if ( debug ) System.out.println("RETRY with outerContext="+outerContext);
|
||||||
ATNConfigSet s0_closure =
|
ATNConfigSet s0_closure =
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.antlr.v4.test;
|
package org.antlr.v4.test;
|
||||||
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/** Test parser execution.
|
/** Test parser execution.
|
||||||
|
@ -232,21 +231,6 @@ public class TestParserExec extends BaseTest {
|
||||||
* This test is meant to test the expected solution to antlr/antlr4#42.
|
* This test is meant to test the expected solution to antlr/antlr4#42.
|
||||||
* https://github.com/antlr/antlr4/issues/42
|
* https://github.com/antlr/antlr4/issues/42
|
||||||
*/
|
*/
|
||||||
@Ignore("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")
|
|
||||||
/* Would need to add to execDFA, execATN:
|
|
||||||
// IF PREDS, MIGHT RESOLVE TO SINGLE ALT => SLL (or syntax error)
|
|
||||||
if ( s.predicates!=null ) {
|
|
||||||
if ( debug ) System.out.println("DFA state has preds in DFA sim LL failover");
|
|
||||||
input.seek(startIndex);
|
|
||||||
IntervalSet alts = evalSemanticContext(s.predicates, outerContext, true);
|
|
||||||
if ( alts.size()==1 ) {
|
|
||||||
if ( debug ) System.out.println("Full LL avoided");
|
|
||||||
return alts.getMinElement();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testPredicatedIfIfElse() throws Exception {
|
public void testPredicatedIfIfElse() throws Exception {
|
||||||
String grammar =
|
String grammar =
|
||||||
|
|
Loading…
Reference in New Issue