StatisticsParserATNSimulator.java 文件源码

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

项目:goworks 作者:
@Override
protected int execATN(DFA dfa, TokenStream input, int startIndex, SimulatorState initialState) {
    int result = super.execATN(dfa, input, startIndex, initialState);
    if (!reportedLookahead) {
        int stopIndex = input.index();
        int k;
        if (startIndex == stopIndex) {
            k = 1;
        } else if (startIndex == stopIndex - 1) {
            k = 2;
        } else {
            k = 0;
            for (int i = startIndex; i <= stopIndex; i++) {
                input.seek(i);
                if (input.LT(1).getChannel() == Token.DEFAULT_CHANNEL) {
                    k++;
                }
            }
        }

        if (!initialState.useContext) {
            totalLookaheadSll[dfa.decision] += k;
            minLookaheadSll[dfa.decision] = Math.min(minLookaheadSll[dfa.decision], k);
            maxLookaheadSll[dfa.decision] = Math.max(maxLookaheadSll[dfa.decision], k);
        }
        else {
            totalLookaheadLl[dfa.decision] += k;
            minLookaheadLl[dfa.decision] = Math.min(minLookaheadLl[dfa.decision], k);
            maxLookaheadLl[dfa.decision] = Math.max(maxLookaheadLl[dfa.decision], k);
        }

        reportedLookahead = true;
    }

    return result;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号