Indexed Grammar Definitions #
This file defines indexed grammars (Aho, 1968), their derivation relation, and the induced language predicate.
An indexed grammar extends context-free grammars by attaching a stack of flags (index symbols) to each nonterminal in a sentential form. Productions can push flags onto, or pop flags from, these stacks.
Main declarations #
IndexedGrammar— the grammar structureIndexedGrammar.SententialForm— sentential forms with stacked nonterminalsIndexedGrammar.Transforms— one-step derivationIndexedGrammar.Derives— reflexive–transitive closure ofTransformsIndexedGrammar.Language— the generated language
References #
- A. V. Aho, "Indexed grammars — an extension of context-free grammars", JACM 15(4), 1968.
A symbol on the right-hand side of an indexed production. A nonterminal can optionally have a flag pushed onto its inherited stack.
- terminal {T N F : Type} : T → IRhsSymbol T N F
- nonterminal {T N F : Type} : N → Option F → IRhsSymbol T N F
Instances For
Equations
- instDecidableEqIRhsSymbol.decEq (IRhsSymbol.terminal a) (IRhsSymbol.terminal b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
- instDecidableEqIRhsSymbol.decEq (IRhsSymbol.terminal a) (IRhsSymbol.nonterminal a_1 a_2) = isFalse ⋯
- instDecidableEqIRhsSymbol.decEq (IRhsSymbol.nonterminal a a_1) (IRhsSymbol.terminal a_2) = isFalse ⋯
- instDecidableEqIRhsSymbol.decEq (IRhsSymbol.nonterminal a a_1) (IRhsSymbol.nonterminal b b_1) = if h : a = b then h ▸ if h : a_1 = b_1 then h ▸ isTrue ⋯ else isFalse ⋯ else isFalse ⋯
Instances For
A production rule of an indexed grammar.
lhs: the nonterminal on the left-hand side.consume: ifsome f, the rule can only fire whenfis on top of the nonterminal's stack, and pops it; ifnone, no flag is consumed.rhs: the right-hand side; each nonterminal inherits the (possibly modified) stack of the left-hand side, with an optional additional flag push.
- lhs : N
- consume : Option F
- rhs : List (IRhsSymbol T N F)
Instances For
A symbol in a sentential form of an indexed grammar: either a terminal or a nonterminal equipped with its current flag stack.
- terminal {T : Type} {g : IndexedGrammar T} : T → g.ISym
- indexed {T : Type} {g : IndexedGrammar T} : g.nt → List g.flag → g.ISym
Instances For
Expand the right-hand side of a rule, distributing the given stack σ to every
nonterminal (and pushing any specified flag on top).
Equations
- One or more equations did not get rendered due to their size.
Instances For
One step of indexed-grammar transformation.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Any number of steps of indexed-grammar transformation.
Equations
Instances For
A word (list of terminals) is generated by the grammar if it can be derived from the initial nonterminal (with empty stack).
Equations
Instances For
The language generated by the grammar.