Skip to content

Recursive Grammar

A generative grammar in which a nonterminal can return to itself through a nonempty chain of productions, directly or indirectly.

Version
v2 · 2026-11-14 · History
Domain-specific #
13559
Domain group
Applied Sciences & Engineering
Origin domain
Computer Science & Software Engineering
Subdomains
Formal Language Theory, Grammar and Parsing → Computer Science & Software Engineering
Aliases
Recursive generative grammar

Core Idea

A recursive grammar has a rule path that returns to a nonterminal it started from. In a context-free grammar, this means \(A\Rightarrow^{+}xAy\) for some nonterminal \(A\). The positive number of steps distinguishes a real production cycle from the trivial zero-step fact that \(A\) equals itself. Recursion may be direct or pass through other nonterminals.[1]

Such a cycle is not automatically an infinite language. A relevant cycle must be reachable, able to finish in terminals, and add terminal material to yield indefinitely many different strings. The grammar \(S\to A\mid a,\;A\to S\mid b\) recurs but generates only \(a\) and \(b\): going around the unit cycle changes no output length. Reachability is thus a consequence qualifier, not the definition of a cycle anywhere in the grammar.[2]

How would you explain it like I'm…

Rules That Use Themselves

A grammar is a set of rules for building sentences. In a recursive grammar, a rule can use itself again while it's being used — like a rule for 'a sentence' that can put another 'sentence' inside it: 'Mom said that Dad said that it's raining.'

The Rule-Inside-a-Rule Grammar

A grammar is a set of rules for building strings, like sentences or computer code. In a recursive grammar, a part can show up again inside itself while the rules are being used. For example, a rule might say "a list is an item, or an item followed by a list." This can happen in one rule or through a loop of several rules. A loop doesn't always mean you can make endlessly many different strings, though; the loop has to actually add something new each time around.

Recursive Production Rules

A recursive grammar is a generative grammar in which a nonterminal — a building block like 'Expression' — can reappear while it is being expanded. In a context-free grammar, that means A can derive, in one or more steps, a string containing A again (A ⇒+ xAy). The return can be direct, in a single rule, or indirect, through several other nonterminals; drawing which nonterminals lead to which, a cycle shows the recursion. Recursion is a property of the rules, not of the language they make. A cycle alone doesn't guarantee infinitely many strings: it must be reachable, able to finish, and actually add material each time around. Where the recursion appears also matters — left recursion can make a simple top-down parser call itself forever without reading input.

 

A recursive grammar is a generative grammar in which some nonterminal can reappear during its own expansion; for a context-free grammar, the diagnostic is a nonzero-step derivation A ⇒+ xAy, with x and y possibly empty. The '+' matters, since every symbol trivially derives itself in zero steps. Recursion can be direct, within one production, or indirect, via several nonterminals; in the dependency graph, where an edge records that expanding one nonterminal introduces another, a cycle is the structural witness. It is a property of the rule system rather than the language: the same finite language may have both recursive and acyclic grammars. A cycle also does not by itself imply an infinite language — a unit-production cycle can loop without adding terminals. Inferring infiniteness requires the cycle to be reachable from the start symbol, able to complete a terminal derivation, and able to produce genuine growth (after normalization). Recursion also has a position: left recursion stalls naive recursive-descent parsing, while right and center embedding yield different parse shapes, and recursion alone fixes neither parser choice nor associativity.

Scope of Application

Formal-language theory uses recursion to distinguish cyclic grammars from acyclic grammars that describe finite languages. Compiler design cares where the cycle occurs: left recursion such as \(E\to E+T\mid T\) can make a naive recursive-descent parser call itself before consuming input. A center-embedded rule such as \(S\to(S)\mid x\) is recursive without being left-recursive. Linguistic grammars can similarly describe potential phrase or clause embedding, although grammatical possibility is not the same as actual utterance use.[3][4]

Clarity

Think of each nonterminal as a node. In the original Hasselt paper's Example 1, \(S\to AG,\ A\to BD,\ B\to CE,\ C\to AF\mid c,\ D\to d,\ E\to e,\ F\to f,\ G\to g\). The path \(A\to B\to C\to A\) returns; immediate exit yields \(cedg\), while one completed cycle yields \(cedfedg\). The added \(fed\) supplies actual terminal growth. By contrast, unit rules \(S\to A,\;A\to S\) return without adding terminals.[1]

Manages Complexity

A few rules can encode arbitrarily deep nested structure without listing every depth. The dependency-cycle view also separates recursion from other concerns: whether a cycle is reachable, whether it can terminate, whether it grows the language, and whether it obstructs a particular parser. An acyclic grammar can still compactly encode an enormous finite set through shared subexpressions.[3]

Abstract Reasoning

Find a positive-step derivation returning a nonterminal to itself. Test reachability from the start and an exit to terminals only when making claims about the generated language. To prove infinitely many strings, exhibit repeatable terminal growth; to diagnose recursive-descent trouble, look specifically for leftmost recurrence before input consumption.[2][4]

Knowledge Transfer

Recursive data schemas and nested protocols have a similar self-returning shape, but the grammar-theoretic claims about terminal strings and parser behavior do not transfer without additional definitions. Formal Grammar is the approved strict parent; the child adds rule-level self-return. Recursion remains a conceptual prime neighbor without an installed edge, while left recursion is a narrower grammatical form.

Relationships to Other Abstractions

Local relationship map for Recursive GrammarParents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.Recursive GrammarDOMAINDomain-specific abstraction: Formal Grammar — is a kind ofFormal GrammarDOMAIN

Current abstraction Recursive Grammar Domain-specific

Parents (1) — outgoing typed relations

  • Recursive Grammar is a kind of Formal Grammar Domain-specific

    A recursive grammar is a formal grammar whose productions permit a nonterminal to return to itself after a nonzero derivation.

Hierarchy path (1) — routes to 1 parentless root

Neighborhood in Abstraction Space

Recursive Grammar sits in a sparse region of the domain-specific corpus (66th percentile for distinctiveness): few abstractions share its structure, so a faithful description tends to retrieve it precisely.

Family — Grammar Derivation & Word Complexity (9 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-11-14

References

[1] Original CFG dependency-graph research, Section 2. registry ↩a ↩b

[2] University of Mississippi notes on CFG language finiteness, Section 8.2.6. registry ↩a ↩b

[3] Nederhof and Satta, “Parsing Non-Recursive Context-Free Grammars”, abstract and Section 2. registry ↩a ↩b

[4] Cornell University, “Grammars and Parsing”, left-recursion section. registry ↩a ↩b