ParserATNSimulator.java 文件源码

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

项目:Scratch-ApuC 作者:
/** Look through a list of predicate/alt pairs, returning alts for the
 *  pairs that win. A {@code NONE} predicate indicates an alt containing an
 *  unpredicated config which behaves as "always true." If !complete
 *  then we stop at the first predicate that evaluates to true. This
 *  includes pairs with null predicates.
 */
protected BitSet evalSemanticContext(@NotNull DFAState.PredPrediction[] predPredictions,
                                  ParserRuleContext outerContext,
                                  boolean complete)
{
    BitSet predictions = new BitSet();
    for (DFAState.PredPrediction pair : predPredictions) {
        if ( pair.pred==SemanticContext.NONE ) {
            predictions.set(pair.alt);
            if (!complete) {
                break;
            }
            continue;
        }

        boolean fullCtx = false; // in dfa
        boolean predicateEvaluationResult = evalSemanticContext(pair.pred, outerContext, pair.alt, fullCtx);
        if ( debug || dfa_debug ) {
            System.out.println("eval pred "+pair+"="+predicateEvaluationResult);
        }

        if ( predicateEvaluationResult ) {
            if ( debug || dfa_debug ) System.out.println("PREDICT "+pair.alt);
            predictions.set(pair.alt);
            if (!complete) {
                break;
            }
        }
    }

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


问题


面经


文章

微信
公众号

扫码关注公众号