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.
Instances For
Uniform stack-suffix extension #
Equations
Instances For
Equations
- IndexedGrammar.appendStackSuffixes suffix w = List.map (IndexedGrammar.ISym.appendStackSuffix suffix) w
Instances For
A grammar has no ε-productions.
Instances For
A grammar has terminals isolated: each rule's RHS either is a single terminal, or consists entirely of nonterminals (with optional flag annotations).
Equations
- g.TerminalsIsolated = ∀ r ∈ g.rules, (∃ (a : T), r.rhs = [IRhsSymbol.terminal a]) ∨ ∀ s ∈ r.rhs, ∃ (n : g.nt) (f : Option g.flag), s = IRhsSymbol.nonterminal n f
Instances For
The start symbol does not appear on the right-hand side of any rule.
Equations
- g.StartNotOnRhs' = ∀ r ∈ g.rules, ∀ s ∈ r.rhs, match s with | IRhsSymbol.nonterminal n a => n ≠ g.initial | IRhsSymbol.terminal a => True
Instances For
A rule has separated flag operations.
Equations
- One or more equations did not get rendered due to their size.
Instances For
All rules in the grammar have separated flag operations.
Equations
- g.FlagsSeparated = ∀ r ∈ g.rules, IndexedGrammar.IRule.FlagsSeparated r
Instances For
A production rule is in normal form with respect to a start symbol s.
Equations
- One or more equations did not get rendered due to their size.
Instances For
An indexed grammar is in normal form if every production rule is in normal form with respect to the start symbol.
Equations
- g.IsNormalForm = ∀ r ∈ g.rules, IndexedGrammar.IRule.IsNF r g.initial