Langlib

Langlib.Grammars.Indexed.Definition

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 #

References #

inductive IRhsSymbol (T N F : Type) :

A symbol on the right-hand side of an indexed production. A nonterminal can optionally have a flag pushed onto its inherited stack.

Instances For
    def instDecidableEqIRhsSymbol.decEq {T✝ N✝ F✝ : Type} [DecidableEq T✝] [DecidableEq N✝] [DecidableEq F✝] (x✝ x✝¹ : IRhsSymbol T✝ N✝ F✝) :
    Decidable (x✝ = x✝¹)
    Equations
    Instances For
      structure IRule (T N F : Type) :

      A production rule of an indexed grammar.

      • lhs : the nonterminal on the left-hand side.
      • consume : if some f, the rule can only fire when f is on top of the nonterminal's stack, and pops it; if none, 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.
      Instances For
        structure IndexedGrammar (T : Type) :

        An indexed grammar that generates words over the alphabet T.

        • nt : type of nonterminals
        • flag : type of index symbols (flags)
        • initial : the start nonterminal
        • rules : the list of production rules
        Instances For
          inductive IndexedGrammar.ISym {T : Type} (g : IndexedGrammar T) :

          A symbol in a sentential form of an indexed grammar: either a terminal or a nonterminal equipped with its current flag stack.

          Instances For
            def IndexedGrammar.expandRhs {T : Type} (g : IndexedGrammar T) (rhs : List (IRhsSymbol T g.nt g.flag)) (σ : List g.flag) :

            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
              def IndexedGrammar.Transforms {T : Type} (g : IndexedGrammar T) (w₁ w₂ : List g.ISym) :

              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.

                    Equations
                    Instances For
                      theorem IndexedGrammar.deri_self {T : Type} (g : IndexedGrammar T) (w : List g.ISym) :
                      g.Derives w w
                      theorem IndexedGrammar.deri_of_tran {T : Type} {g : IndexedGrammar T} {w₁ w₂ : List g.ISym} (h : g.Transforms w₁ w₂) :
                      g.Derives w₁ w₂
                      theorem IndexedGrammar.deri_of_deri_deri {T : Type} {g : IndexedGrammar T} {w₁ w₂ w₃ : List g.ISym} (h₁ : g.Derives w₁ w₂) (h₂ : g.Derives w₂ w₃) :
                      g.Derives w₁ w₃
                      theorem IndexedGrammar.deri_of_deri_tran {T : Type} {g : IndexedGrammar T} {w₁ w₂ w₃ : List g.ISym} (h₁ : g.Derives w₁ w₂) (h₂ : g.Transforms w₂ w₃) :
                      g.Derives w₁ w₃
                      theorem IndexedGrammar.deri_of_tran_deri {T : Type} {g : IndexedGrammar T} {w₁ w₂ w₃ : List g.ISym} (h₁ : g.Transforms w₁ w₂) (h₂ : g.Derives w₂ w₃) :
                      g.Derives w₁ w₃
                      theorem IndexedGrammar.deri_with_prefix {T : Type} {g : IndexedGrammar T} (p : List g.ISym) {w₁ w₂ : List g.ISym} (h : g.Derives w₁ w₂) :
                      g.Derives (p ++ w₁) (p ++ w₂)
                      theorem IndexedGrammar.deri_with_suffix {T : Type} {g : IndexedGrammar T} (s : List g.ISym) {w₁ w₂ : List g.ISym} (h : g.Derives w₁ w₂) :
                      g.Derives (w₁ ++ s) (w₂ ++ s)