AI Glossary / Natural language and speech / Advanced
Indexed grammar
Definition
An indexed grammar is a formal grammar in which nonterminal symbols can carry stacks of index symbols. Its rules can manipulate those stacks and pass copies to newly introduced nonterminals. This extends the expressive possibilities of context-free grammars and provides a precise way to describe some dependencies among different parts of a string.
What it means
A nonterminal represents an unfinished part of a derivation. In an indexed grammar, that unfinished part also has a local stack that stores symbolic information.
The indices are formal symbols, not database indexes, search keywords, or numeric positions in a document. Their role is to influence which derivation steps are possible.
The formalism originated with Alfred Aho. Presentations use different but related notation, so it is essential to distinguish a grammar rule from the stack-decorated expressions that occur while applying it. The grammar has finitely many rules even though its derivations can build arbitrarily long stacks.
How it works
A convenient presentation has three rule forms. A stack-preserving expansion replaces one nonterminal with a string of terminals and nonterminals, giving each new nonterminal a copy of the existing stack.
A push rule places a designated index at the top of the stack while changing the nonterminal. A pop rule applies only when a designated index is on top, removes it, and passes the remaining stack to any new nonterminals.
Terminal symbols do not carry stacks. A successful derivation begins with the start symbol and ends with a string containing only terminals.
Stack copying is a central distinction: separate branches can receive equivalent stored information and then process their own copies. This is not one shared mutable stack that every branch changes simultaneously.
Three practical examples
- A formal-language lesson constructs equal-sized blocks of three different symbols using one stored count copied to three branches.
- A grammar researcher compares indexed grammars with restricted variants that limit how stack information is passed.
- A verification exercise traces a push and a pop to check that a derivation uses the required top index rather than an arbitrary deeper stack symbol.
Think of it this way
Think of a task that prepares a stack of instruction cards and copies it for several teams. Each team follows its own copy, allowing their outputs to reflect the same initial information. The analogy is bounded because indexed grammars use exact formal rewrite rules, not independent judgment or real-world communication among teams.
Worked example
Here is a constructed grammar idea for strings aⁿbⁿcⁿ with n at least zero. Let z mark the bottom of a stack and f record one count. Put the top of the stack on the left, and let σ stand for any remaining stack.
Start by changing S[ε] into P[z]. Repeatedly use P[σ] → P[fσ] to choose a count, then use P[σ] → A[σ]B[σ]C[σ] to copy that stack into three branches.
The first branch uses A[fσ] → aA[σ], the second B[fσ] → bB[σ], and the third C[fσ] → cC[σ]. Each branch finishes by removing its nonterminal when z is on top: A[zσ], B[zσ], or C[zσ] becomes ε.
For two pushes, the shared starting information is ffz. The branches therefore yield aa, bb, and cc, producing aabbcc. Zero pushes yield the empty string.
The nine rule schemas are finite; σ is explanatory notation for inherited stack content, not an instruction to write infinitely many grammar rules. Every f produces one terminal in each branch, which explains why the three block lengths agree.
Illustrative case study
In a fictional project, Larch Formal Methods teaches grammar expressiveness with a derivation visualizer. Students first attempt to coordinate three symbol blocks, then inspect how an indexed representation copies a stored count.
The visualizer displays each branch's stack separately. When one branch pops an f, the other two copies remain unchanged, preventing the mistaken impression that they share a single destructively updated object.
The imagined tool illustrates the formal mechanism. It does not claim a commercial application or that this full grammar class is necessary for an ordinary business text-processing requirement.
Common misconceptions and mistakes
Indexed grammar does not mean a grammar that has been cataloged or assigned database identifiers.
The index alphabet and rule set are finite, while derived stack lengths may be unbounded.
A pop rule examines the top symbol; it is not permission to remove any chosen index from the middle.
Ordinary indexed grammars and linear indexed grammars are not interchangeable. The latter restrict how inherited stack information is passed to children.
Greater expressive power does not automatically mean simpler grammar development, faster parsing, or better linguistic predictions.
Business use
This is mainly a theoretical concept relevant to specialist language-processing research and formal specifications. For a business team, its practical value is understanding what a proposed grammar mechanism can express and why additional memory changes a formal model's behavior.
Start from the actual dependencies a task requires. A stronger formalism can bring extra implementation and analysis costs, so evaluate the specific representation and algorithms rather than treating expressive power as an automatic product advantage.
People also ask
Does every nonterminal have its own stack?
In a derivation, each nonterminal occurrence is associated with stack content. Expansions can create separate occurrences with copied content.
Can an indexed grammar express context-free behavior?
Yes. A context-free grammar can be represented without making substantive use of the extra stack mechanism.
Do the indices appear in the final output?
No. The generated language consists of terminal strings; indices guide derivation rather than becoming ordinary output symbols unless separately represented as terminals.
Check your understanding
In the worked grammar, one branch has already popped an f. Must the other branches lose an f at the same time?
Answer: No. They received copies of the stack. Each branch processes its own copy according to its rules, while the equal initial counts constrain their eventual block lengths.
Related terms
- Indexed language
- Context-free grammar
- Formal language
- nonterminal
- stack
- derivation
- linear indexed grammar
- nested stack automaton
Learn next
trace the example with one and three pushes and verify the resulting strings. Then compare ordinary and linear indexed grammars, focusing on which right-hand-side nonterminals may inherit the existing stack.
More in Natural language and speech
- Implicature - An implicature is something a speaker communicates indirectly, beyond what the utterance explicitly says.
- Implicit argument - An implicit argument is a participant associated with a predicate's meaning that is not overtly expressed in the relevant phrase or clause.
- Indefinite reference - Indefinite reference is the use of an expression, often a noun phrase such as “a technician” or “some packages,” without presenting its referent as already...
- Inflectional morphemes - Inflectional morphemes are grammatical meaning-bearing units that mark forms of a word, such as number, tense, or agreement, rather than primarily creating...
- Intelligent character recognition - Intelligent character recognition, or ICR, refers to character-recognition methods that use learned or adaptive pattern-recognition techniques, often for...
- Intentional stance - The intentional stance is a strategy for predicting a system's behavior by treating it as an agent with beliefs and goals, then asking what it would...
Sources
Brough, Ciobanu, Elder, and Zetzsche, “Permutations of context-free, ET0L and indexed languages,” original research, Definition 3.1: https://pure.hw.ac.uk/ws/files/15010440/hal_01352858.pdf. Vijay-Shanker, original thesis discussion of indexed and linear indexed grammars: https://www.cs.cornell.edu/courses/cs6740/2010sp/vijayashanker-thesis.pdf. The nine-rule example above is an original construction. Independent source review: Definition 3.1 of Brough and colleagues was read for all three rule forms, inherited stack copies, top-symbol removal and terminal-language semantics.
Previous: Indexed access Next: Indexed language