forked from jasder/antlr
Construct DFA instances with the decision number
This commit is contained in:
parent
d589011ad8
commit
7fb73a3849
|
@ -268,8 +268,7 @@ public class ParserATNSimulator<Symbol> extends ATNSimulator {
|
|||
DFA dfa = decisionToDFA[decision];
|
||||
if ( dfa==null || dfa.s0==null ) {
|
||||
DecisionState startState = atn.decisionToState.get(decision);
|
||||
decisionToDFA[decision] = dfa = new DFA(startState);
|
||||
dfa.decision = decision;
|
||||
decisionToDFA[decision] = dfa = new DFA(startState, decision);
|
||||
return predictATN(dfa, input, outerContext);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -43,7 +43,8 @@ public class DFA {
|
|||
public final Map<DFAState, DFAState> states = new LinkedHashMap<DFAState, DFAState>();
|
||||
@Nullable
|
||||
public DFAState s0;
|
||||
public int decision;
|
||||
|
||||
public final int decision;
|
||||
|
||||
/** From which ATN state did we create this DFA? */
|
||||
@NotNull
|
||||
|
@ -54,7 +55,14 @@ public class DFA {
|
|||
*/
|
||||
// public OrderedHashSet<ATNConfig> conflictSet;
|
||||
|
||||
public DFA(@NotNull DecisionState atnStartState) { this.atnStartState = atnStartState; }
|
||||
public DFA(@NotNull DecisionState atnStartState) {
|
||||
this(atnStartState, 0);
|
||||
}
|
||||
|
||||
public DFA(@NotNull DecisionState atnStartState, int decision) {
|
||||
this.atnStartState = atnStartState;
|
||||
this.decision = decision;
|
||||
}
|
||||
|
||||
/** Find the path in DFA from s0 to s, returning list of states encountered (inclusively) */
|
||||
// public List<DFAState> getPathToState(DFAState finalState, TokenStream input, int start, int stop) {
|
||||
|
|
|
@ -505,8 +505,7 @@ public class TestATNParserPrediction extends BaseTest {
|
|||
TokenStream input = new IntTokenStream(types);
|
||||
ParserInterpreter interp = new ParserInterpreter(g, input);
|
||||
DecisionState startState = atn.decisionToState.get(decision);
|
||||
DFA dfa = new DFA(startState);
|
||||
dfa.decision = decision;
|
||||
DFA dfa = new DFA(startState, decision);
|
||||
int alt = interp.predictATN(dfa, input, ParserRuleContext.EMPTY, false);
|
||||
|
||||
System.out.println(dot.getDOT(dfa, false));
|
||||
|
|
Loading…
Reference in New Issue