mono/mono · warning

%s: 1 rule never reduced

Error message

%s: 1 rule never reduced

What it means

Emitted by unused_rules() in mcs/jay/mkpar.c:249 (singular branch) when exactly one grammar rule is never selected as a reduction in any parser state. After building LALR tables, jay scans every state's actions; a rule whose `rules_used` entry stays 0 is unreachable from the start symbol, so it can never fire. It is a warning — generation completes, but the rule is dead weight.

Source

Thrown at mcs/jay/mkpar.c:249

	rules_used[i] = 0;

    for (i = 0; i < nstates; ++i)
    {
	for (p = parser[i]; p; p = p->next)
	{
	    if (p->action_code == REDUCE && p->suppressed == 0)
		rules_used[p->number] = 1;
	}
    }

    nunused = 0;
    for (i = 3; i < nrules; ++i)
	if (!rules_used[i]) ++nunused;

    if (nunused)
    {
	if (nunused == 1)
	    fprintf(stderr, "%s: 1 rule never reduced\n", myname);
	else
	    fprintf(stderr, "%s: %d rules never reduced\n", myname, nunused);
     }
}

static void
remove_conflicts (void)
{
    register int i;
    register int symbol;
    register action *p, *pref;

    SRtotal = 0;
    RRtotal = 0;
    SRconflicts = NEW2(nstates, short);
    RRconflicts = NEW2(nstates, short);
    for (i = 0; i < nstates; i++)
    {

View on GitHub (pinned to 0f53e9e151)

Solutions

  1. Delete the unreachable production, or reference its LHS nonterminal from a reachable rule.
  2. If the rule is intended, connect it to the start symbol's derivation.
  3. Re-run jay; a clean run confirms no unreachable rules remain.

Example fix

// before
start : a ;
a : 'x' ;
b : 'y' ;   /* b never reached -> 1 rule never reduced */
// after
start : a ;
a : 'x' ;
Defensive patterns

Strategy: validation

Validate before calling

# Build with -v and assert the unused-rule warning is absent from stderr.
jay -v -c -o Parser.cs grammar.jay 2>jay.log
grep -q 'rule never reduced' jay.log && { echo 'unreachable rule detected'; cat jay.log; exit 1; } || true

Prevention

When it happens

Trigger: A production that is not reachable from the start symbol via any chain of nonterminals, leaving exactly one such rule.

Common situations: Leftover experimental productions after refactoring; a nonterminal defined but never referenced; an alternative superseded by another rule.

Related errors


AI-assisted analysis of mono/mono@0f53e9e151 (2026-08-13). Data as JSON: /api/errors/9a84e52c8b0005ec. Report an issue: GitHub.