antlr/antlr4 · error · NotSupportedException

The current parser does not support an ATN with bypass alter

Error message

The current parser does not support an ATN with bypass alternatives.

What it means

Error "The current parser does not support an ATN with bypass alternatives." thrown in antlr/antlr4.

Source

Thrown at runtime/CSharp/src/Parser.cs:569

        /// lazily.
        /// </summary>
        /// <remarks>
        /// The ATN with bypass alternatives is expensive to create so we create it
        /// lazily.
        /// </remarks>
        /// <exception cref="System.NotSupportedException">
        /// if the current parser does not
        /// implement the
        /// <see cref="Recognizer{Symbol, ATNInterpreter}.SerializedAtn()"/>
        /// method.
        /// </exception>
        [return: NotNull]
        public virtual ATN GetATNWithBypassAlts()
        {
            int[] serializedAtn = SerializedAtn;
            if (serializedAtn == null)
            {
                throw new NotSupportedException("The current parser does not support an ATN with bypass alternatives.");
            }
            lock (this)
            {
                if ( bypassAltsAtnCache!=null ) {
                    return bypassAltsAtnCache;
                }
                ATNDeserializationOptions deserializationOptions = new ATNDeserializationOptions();
                deserializationOptions.GenerateRuleBypassTransitions = true;
                bypassAltsAtnCache = new ATNDeserializer(deserializationOptions).Deserialize(serializedAtn);
                return bypassAltsAtnCache;
            }
        }

        /// <summary>The preferred method of getting a tree pattern.</summary>
        /// <remarks>
        /// The preferred method of getting a tree pattern. For example, here's a
        /// sample use:
        /// <pre>

View on GitHub (pinned to 7d5770395b)

Solutions

  1. Remove the bypassAlternatives option from the grammar (options { contextSuperClass=...; }) or use the full Parser instead of the interpreter/optimized path that rejects bypass ATNs.
  2. Regenerate the parser without bypass alternatives when using this runtime path.

Example fix

// grammar MyGrammar; // remove: options { contextSuperClass=...; }

When it happens

Trigger: Parser created with an ATN containing bypass alternatives (generated with -atn), which the standard parser cannot simulate.

Common situations: Do not generate the grammar with the -atn bypass option when using the standard Parser; use ParserInterpreter for such ATNs.


AI-assisted analysis of antlr/antlr4@7d5770395b (2026-08-14). Data as JSON: /api/errors/0d9825c48942d0e1. Report an issue: GitHub.