LexerATNSimulator.java 文件源码

java
阅读 22 收藏 0 点赞 0 评论 0

项目:Scratch-ApuC 作者:
/**
 * 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
 * {@code t}. If {@code t} does not lead to a valid DFA state, this method
 * returns {@link #ERROR}.
 */
@NotNull
protected DFAState computeTargetState(@NotNull CharStream input, @NotNull DFAState s, int t) {
    ATNConfigSet reach = new 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, ERROR);
        }

        // stop when we can't match any more char
        return ERROR;
    }

    // Add an edge from s to target DFA found/created for reach
    return addDFAEdge(s, t, reach);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号