diff --git a/tool/src/org/antlr/v4/analysis/AnalysisPipeline.java b/tool/src/org/antlr/v4/analysis/AnalysisPipeline.java index 0a7d99bdd..3d93c0946 100644 --- a/tool/src/org/antlr/v4/analysis/AnalysisPipeline.java +++ b/tool/src/org/antlr/v4/analysis/AnalysisPipeline.java @@ -59,19 +59,26 @@ public class AnalysisPipeline { g.decisionLOOK = new ArrayList(g.atn.getNumberOfDecisions()+1); for (DecisionState s : g.atn.decisionToState) { g.tool.log("LL1", "\nDECISION "+s.decision+" in rule "+g.getRule(s.ruleIndex).name); - LL1Analyzer anal = new LL1Analyzer(g.atn); - IntervalSet[] look = anal.getDecisionLookahead(s); - g.tool.log("LL1", "look=" + Arrays.toString(look)); + 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); + 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)); + 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