diff --git a/runtime/Java/src/org/antlr/v4/runtime/DefaultErrorStrategy.java b/runtime/Java/src/org/antlr/v4/runtime/DefaultErrorStrategy.java index 71006b39b..838fed58f 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/DefaultErrorStrategy.java +++ b/runtime/Java/src/org/antlr/v4/runtime/DefaultErrorStrategy.java @@ -318,7 +318,8 @@ public class DefaultErrorStrategy implements ANTLRErrorStrategy { // is free to conjure up and insert the missing token ATNState currentState = recognizer.getInterpreter().atn.states.get(recognizer._ctx.s); ATNState next = currentState.transition(0).target; - IntervalSet expectingAtLL2 = recognizer.getInterpreter().atn.nextTokens(next, recognizer._ctx); + ATN atn = recognizer.getInterpreter().atn; + IntervalSet expectingAtLL2 = atn.nextTokens(next, recognizer._ctx); // System.out.println("LT(2) set="+expectingAtLL2.toString(recognizer.getTokenNames())); if ( expectingAtLL2.contains(currentSymbolType) ) { reportMissingToken(recognizer); diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/LL1Analyzer.java b/runtime/Java/src/org/antlr/v4/runtime/atn/LL1Analyzer.java index db479a381..c040bdf68 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/LL1Analyzer.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/LL1Analyzer.java @@ -80,7 +80,7 @@ public class LL1Analyzer { public IntervalSet LOOK(@NotNull ATNState s, @Nullable RuleContext ctx) { IntervalSet r = new IntervalSet(); boolean seeThruPreds = true; // ignore preds; get all lookahead - _LOOK(s, PredictionContext.fromRuleContext(ctx), + _LOOK(s, PredictionContext.fromRuleContext(s.atn, ctx), r, new HashSet(), seeThruPreds); return r; } @@ -109,11 +109,9 @@ public class LL1Analyzer { if ( ctx != PredictionContext.EMPTY ) { // run thru all possible stack tops in ctx for (SingletonPredictionContext p : ctx) { - ATNState invokingState = atn.states.get(p.invokingState); - RuleTransition rt = (RuleTransition)invokingState.transition(0); - ATNState retState = rt.followState; + ATNState returnState = atn.states.get(p.invokingState); // System.out.println("popping back to "+retState); - _LOOK(retState, p.parent, look, lookBusy, seeThruPreds); + _LOOK(returnState, p.parent, look, lookBusy, seeThruPreds); } return; } @@ -124,7 +122,7 @@ public class LL1Analyzer { Transition t = s.transition(i); if ( t.getClass() == RuleTransition.class ) { PredictionContext newContext = - SingletonPredictionContext.create(ctx, s.stateNumber); + SingletonPredictionContext.create(ctx, ((RuleTransition)t).followState.stateNumber); _LOOK(t.target, newContext, look, lookBusy, seeThruPreds); } else if ( t instanceof PredicateTransition ) { diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java b/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java index e6f13df29..00f35d6d6 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java @@ -418,10 +418,8 @@ public class LexerATNSimulator extends ATNSimulator { configs.add(c); continue; } - ATNState invokingState = atn.states.get(ctx.invokingState); - RuleTransition rt = (RuleTransition)invokingState.transition(0); - ATNState retState = rt.followState; - LexerATNConfig c = new LexerATNConfig(retState, config.alt, newContext); + ATNState returnState = atn.states.get(ctx.invokingState); + LexerATNConfig c = new LexerATNConfig(returnState, config.alt, newContext); currentAltReachedAcceptState = closure(input, c, configs, currentAltReachedAcceptState, speculative); } } @@ -457,12 +455,12 @@ public class LexerATNSimulator extends ATNSimulator { @NotNull ATNConfigSet configs, boolean speculative) { - ATNState p = config.state; LexerATNConfig c = null; switch (t.getSerializationType()) { case Transition.RULE: + RuleTransition ruleTransition = (RuleTransition)t; PredictionContext newContext = - SingletonPredictionContext.create(config.context, p.stateNumber); + SingletonPredictionContext.create(config.context, ruleTransition.followState.stateNumber); c = new LexerATNConfig(config, t.target, newContext); break; diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java index 719eee5e0..2727f0543 100755 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java @@ -898,7 +898,7 @@ public class ParserATNSimulator extends ATNSimulator { boolean fullCtx) { // always at least the implicit call to start rule - PredictionContext initialContext = PredictionContext.fromRuleContext(ctx); + PredictionContext initialContext = PredictionContext.fromRuleContext(atn, ctx); ATNConfigSet configs = new ATNConfigSet(fullCtx); for (int i=0; i