nongreedy decisions can't be LL(1)

This commit is contained in:
Terence Parr 2012-11-04 10:37:25 -08:00
parent c073835186
commit a5016b60f9
1 changed files with 12 additions and 5 deletions

View File

@ -59,19 +59,26 @@ public class AnalysisPipeline {
g.decisionLOOK = new ArrayList<IntervalSet[]>(g.atn.getNumberOfDecisions()+1);
for (DecisionState s : g.atn.decisionToState) {
g.tool.log("LL1", "\nDECISION "+s.decision+" in rule "+g.getRule(s.ruleIndex).name);
IntervalSet[] look;
if ( s.nonGreedy ) { // nongreedy decisions can't be LL(1)
look = new IntervalSet[s.getNumberOfTransitions()+1];
}
else {
LL1Analyzer anal = new LL1Analyzer(g.atn);
IntervalSet[] look = anal.getDecisionLookahead(s);
look = anal.getDecisionLookahead(s);
g.tool.log("LL1", "look=" + Arrays.toString(look));
}
Utils.setSize(g.decisionLOOK, s.decision+1);
g.decisionLOOK.set(s.decision, look);
g.tool.log("LL1", "LL(1)? " + disjoint(look));
}
}
/** Return lookahead depth at which lookahead sets are disjoint or return 0 */
/** Return whether lookahead sets are disjoint; no lookahead => not disjoint */
public static boolean disjoint(IntervalSet[] altLook) {
boolean collision = false;
IntervalSet combined = new IntervalSet();
if ( altLook==null ) return false;
for (int a=1; a<altLook.length; a++) {
IntervalSet look = altLook[a];
if ( look==null ) return false; // lookahead must've computation failed