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 70f715353..804e07349 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java @@ -290,9 +290,12 @@ public class LexerATNSimulator extends ATNSimulator { getReachableConfigSet(input, s.configs, reach, t); if ( reach.isEmpty() ) { // we got nowhere on t from s - // we got nowhere on t, don't throw out this knowledge; it'd - // cause a failover from DFA later. - addDFAEdge(s, t, ERROR); + if (!reach.hasSemanticContext) { + // we got nowhere on t, don't throw out this knowledge; it'd + // cause a failover from DFA later. + addDFAEdge(s, t, ERROR); + } + // stop when we can't match any more char return ERROR; }