/**
* Add an edge to the DFA, if possible. This method calls
* {@link #addDFAState} to ensure the {@code to} state is present in the
* DFA. If {@code from} is {@code null}, or if {@code t} is outside the
* range of edges that can be represented in the DFA tables, this method
* returns without adding the edge to the DFA.
*
* <p>If {@code to} is {@code null}, this method returns {@code null}.
* Otherwise, this method returns the {@link DFAState} returned by calling
* {@link #addDFAState} for the {@code to} state.</p>
*
* @param dfa The DFA
* @param from The source state for the edge
* @param t The input symbol
* @param to The target state for the edge
*
* @return If {@code to} is {@code null}, this method returns {@code null};
* otherwise this method returns the result of calling {@link #addDFAState}
* on {@code to}
*/
protected DFAState addDFAEdge(@NotNull DFA dfa,
@Nullable DFAState from,
int t,
@Nullable DFAState to)
{
if ( debug ) {
System.out.println("EDGE "+from+" -> "+to+" upon "+getTokenName(t));
}
if (to == null) {
return null;
}
to = addDFAState(dfa, to); // used existing if possible not incoming
if (from == null || t < -1 || t > atn.maxTokenType) {
return to;
}
synchronized (from) {
if ( from.edges==null ) {
from.edges = new DFAState[atn.maxTokenType+1+1];
}
from.edges[t+1] = to; // connect
}
if ( debug ) {
System.out.println("DFA=\n"+dfa.toString(parser!=null?parser.getTokenNames():null));
}
return to;
}
ParserATNSimulator.java 文件源码
java
阅读 32
收藏 0
点赞 0
评论 0
项目:Scratch-ApuC
作者:
评论列表
文章目录