getPredsForAmbigAlts method
Implementation
List<SemanticContext?>? getPredsForAmbigAlts(
BitSet ambigAlts,
ATNConfigSet configs,
int nalts,
) {
// REACH=[1|1|[]|0:0, 1|2|[]|0:1]
/* altToPred starts as an array of all null contexts. The entry at index i
* corresponds to alternative i. altToPred[i] may have one of three values:
* 1. null: no ATNConfig c is found such that c.alt==i
* 2. SemanticContext.NONE: At least one ATNConfig c exists such that
* c.alt==i and c.semanticContext==SemanticContext.NONE. In other words,
* alt i has at least one unpredicated config.
* 3. Non-NONE Semantic Context: There exists at least one, and for all
* ATNConfig c such that c.alt==i, c.semanticContext!=SemanticContext.NONE.
*
* From this, it is clear that NONE||anything==NONE.
*/
final altToPred = List<SemanticContext?>.filled(nalts + 1, null);
for (var c in configs) {
if (ambigAlts[c.alt]) {
altToPred[c.alt] =
SemanticContext.or(altToPred[c.alt], c.semanticContext);
}
}
var nPredAlts = 0;
for (var i = 1; i <= nalts; i++) {
if (altToPred[i] == null) {
altToPred[i] = EmptySemanticContext.Instance;
} else if (altToPred[i] != EmptySemanticContext.Instance) {
nPredAlts++;
}
}
// // Optimize away p||p and p&&p TODO: optimize() was a no-op
// for (int i = 0; i < altToPred.length; i++) {
// altToPred[i] = altToPred[i].optimize();
// }
if (debug) log('getPredsForAmbigAlts result $altToPred');
// nonambig alts are null in altToPred
if (nPredAlts == 0) return null;
return altToPred;
}