computeTargetState method
Compute a target state for an edge in the DFA, and attempt to add the computed state and corresponding edge to the DFA.
@param input The input stream @param s The current DFA state @param t The next input symbol
@return The computed target DFA state for the given input symbol
t
. If t
does not lead to a valid DFA state, this method
returns {@link #ERROR}.
Implementation
DFAState computeTargetState(CharStream input, DFAState s, int t) {
ATNConfigSet reach = OrderedATNConfigSet();
// if we don't find an existing DFA state
// Fill reach starting from closure, following t transitions
getReachableConfigSet(input, s.configs, reach, t);
if (reach.isEmpty) {
// we got nowhere on t from s
if (!reach.hasSemanticContext) {
// we got nowhere on t, don't throw out this knowledge; it'd
// cause a failover from DFA later.
addDFAEdge(s, t, ATNSimulator.ERROR);
}
// stop when we can't match any more char
return ATNSimulator.ERROR;
}
// Add an edge from s to target DFA found/created for reach
return addDFAEdgeByConfig(s, t, reach);
}