java类org.antlr.v4.runtime.dfa.DFA的实例源码

PrintStreamErrorListener.java 文件源码 项目:antlr4-regressionTestRig 阅读 19 收藏 0 点赞 0 评论 0
/**
 * {@inheritDoc}
 * <p>
 * We simply increment the number of Ambiguity warnings.
 */
 @Override
public void reportAmbiguity(Parser recognizer,
                      DFA dfa,
                      int startIndex,
                      int stopIndex,
                      boolean exact,
                      BitSet ambigAlts,
                      ATNConfigSet configs) {
    numAmbiguityWarnings++;
  }
PrintStreamErrorListener.java 文件源码 项目:antlr4-regressionTestRig 阅读 18 收藏 0 点赞 0 评论 0
/**
* {@inheritDoc}
* <p>
* We simply increment the number of Strong Context warnings.
*/
@Override
public void reportAttemptingFullContext(Parser recognizer,
                                  DFA dfa,
                                  int startIndex,
                                  int stopIndex,
                                  BitSet conflictingAlts,
                                  ATNConfigSet configs) {
   numStrongContextWarnings++;
 }
PrintStreamErrorListener.java 文件源码 项目:antlr4-regressionTestRig 阅读 25 收藏 0 点赞 0 评论 0
/**
* {@inheritDoc}
* <p>
* We simply increment the number of Weak Context warnings.
*/
@Override
public void reportContextSensitivity(Parser recognizer,
                              DFA dfa,
                              int startIndex,
                              int stopIndex,
                              int prediction,
                              ATNConfigSet configs) {
   numWeakContextWarnings++;
 }
StatisticsParserErrorListener.java 文件源码 项目:goworks 阅读 24 收藏 0 点赞 0 评论 0
@Override
public void reportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, boolean exact, BitSet ambigAlts, ATNConfigSet configs) {
    BitSet sllPredictions = getConflictingAlts(_sllConflict, _sllConfigs);
    int sllPrediction = sllPredictions.nextSetBit(0);
    BitSet llPredictions = getConflictingAlts(ambigAlts, configs);
    int llPrediction = llPredictions.cardinality() == 0 ? ATN.INVALID_ALT_NUMBER : llPredictions.nextSetBit(0);
    if (recognizer.getInterpreter() instanceof StatisticsParserATNSimulator) {
        if (sllPrediction != llPrediction) {
            ((StatisticsParserATNSimulator)recognizer.getInterpreter()).nonSll[dfa.decision]++;
        }

        ((StatisticsParserATNSimulator)recognizer.getInterpreter()).ambiguousResult[dfa.decision]++;
    }
}
StatisticsParserErrorListener.java 文件源码 项目:goworks 阅读 23 收藏 0 点赞 0 评论 0
@Override
public void reportContextSensitivity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, int prediction, SimulatorState acceptState) {
    BitSet sllPredictions = getConflictingAlts(_sllConflict, _sllConfigs);
    int sllPrediction = sllPredictions.nextSetBit(0);
    if (sllPrediction != prediction && recognizer.getInterpreter() instanceof StatisticsParserATNSimulator) {
        ((StatisticsParserATNSimulator)recognizer.getInterpreter()).nonSll[dfa.decision]++;
    }
}
StatisticsParserATNSimulator.java 文件源码 项目:goworks 阅读 23 收藏 0 点赞 0 评论 0
@Override
protected int execDFA(DFA dfa, TokenStream input, int startIndex, SimulatorState state) {
    int result = super.execDFA(dfa, input, startIndex, state);
    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 (!state.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;
}
StatisticsParserATNSimulator.java 文件源码 项目:goworks 阅读 25 收藏 0 点赞 0 评论 0
@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;
}
StatisticsParserATNSimulator.java 文件源码 项目:goworks 阅读 20 收藏 0 点赞 0 评论 0
@Override
protected SimulatorState computeReachSet(DFA dfa, SimulatorState previous, int t, PredictionContextCache contextCache) {
    if (previous.useContext) {
        totalTransitions[decision]++;
        computedTransitions[decision]++;
        fullContextTransitions[decision]++;
    }

    return super.computeReachSet(dfa, previous, t, contextCache);
}
TreeCorrectionParserATNSimulator.java 文件源码 项目:goworks 阅读 22 收藏 0 点赞 0 评论 0
@Override
public SimulatorState getStartState(DFA dfa, TokenStream input, ParserRuleContext outerContext, boolean useContext) {
    // force execATN for special decisions
    if (getSuppressedSet(startIndex).isNil()) {
        return null;
    }

    return super.getStartState(dfa, input, outerContext, useContext);
}
TreeCorrectionParserATNSimulator.java 文件源码 项目:goworks 阅读 24 收藏 0 点赞 0 评论 0
@Override
protected DFAState addDFAEdge(DFA dfa, DFAState fromState, int t, IntegerList contextTransitions, ATNConfigSet toConfigs, PredictionContextCache contextCache) {
    if (!getSuppressedSet(startIndex).isNil()) {
        DFAState to = addDFAState(dfa, toConfigs, contextCache);
        return to;
    }

    return super.addDFAEdge(dfa, fromState, t, contextTransitions, toConfigs, contextCache);
}


问题


面经


文章

微信
公众号

扫码关注公众号