antlr/antlr4 · error · FailedPredicateException

precpred(_ctx, {0})

Error message

precpred(_ctx, {0})

What it means

Error "precpred(_ctx, {0})" thrown in antlr/antlr4.

Source

Thrown at runtime/CSharp/src/ParserInterpreter.cs:270

					if (!Sempred(RuleContext, predicateTransition.ruleIndex, predicateTransition.predIndex))
                    {
                        throw new FailedPredicateException(this);
                    }
                    break;
                }

                case TransitionType.ACTION:
                {
                    ActionTransition actionTransition = (ActionTransition)transition;
					Action(RuleContext, actionTransition.ruleIndex, actionTransition.actionIndex);
                    break;
                }

                case TransitionType.PRECEDENCE:
                {
					if (!Precpred(RuleContext, ((PrecedencePredicateTransition)transition).precedence))
                    {
                        throw new FailedPredicateException(this, string.Format("precpred(_ctx, {0})", ((PrecedencePredicateTransition)transition).precedence));
                    }
                    break;
                }

                default:
                {
                    throw new NotSupportedException("Unrecognized ATN transition type.");
                }
            }
            State = transition.target.stateNumber;
        }

        protected internal virtual void VisitRuleStopState(ATNState p)
        {
            RuleStartState ruleStartState = _atn.ruleToStartState[p.ruleIndex];
            if (ruleStartState.isPrecedenceRule)
            {
                Tuple<ParserRuleContext, int> parentContext = _parentContextStack.Pop();

View on GitHub (pinned to 7d5770395b)

Solutions

  1. This is an internal ATN simulation failure; regenerate the parser with an up-to-date ANTLR tool matching the runtime version.
  2. If triggered by a grammar construct, simplify left-recursive rules using precedence predicates and report the grammar to the ANTLR project.

Example fix

// regenerate: antlr4 -Dlanguage=CSharp MyGrammar.g4 with matching tool/runtime versions

When it happens

Trigger: ParserInterpreter evaluates a precedence predicate via precpred(_ctx, precedence) during adaptive prediction.

Common situations: Indicates left-recursive rule precedence checks; ensure the ATN matches the grammar's left-recursive rules.


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