Langlib

Langlib.Grammars.LeftRegular.Definition

Left-Regular (Type-3) Grammar Definitions #

This file defines left-regular grammars as a restricted variant of the unrestricted (Type-0) grammar framework. A left-regular grammar is a variant of the Type-3 class in the Chomsky hierarchy, generating exactly the regular languages.

Grammar restriction #

A left-regular grammar restricts every production rule to one of three forms:

where A, B are nonterminals and a is a terminal symbol.

Main declarations #

References #

inductive LG_rule (T N : Type) :

A production rule in a left-regular grammar.

  • cons A a B represents the rule A → B a.
  • single A a represents the rule A → a.
  • epsilon A represents the rule A → ε.
Instances For
    def instDecidableEqLG_rule.decEq {T✝ N✝ : Type} [DecidableEq T✝] [DecidableEq N✝] (x✝ x✝¹ : LG_rule T✝ N✝) :
    Decidable (x✝ = x✝¹)
    Equations
    Instances For
      structure LG_grammar (T : Type) :

      A left-regular (Type-3) grammar over terminal alphabet T.

      This is a variant of the most restricted class in the Chomsky hierarchy. Every production has the form A → Ba, A → a, or A → ε.

      • nt : Type

        Type of nonterminals

      • initial : self.nt

        Start symbol

      • rules : List (LG_rule T self.nt)

        Production rules

      Instances For
        def LG_rule.lhs {T N : Type} :
        LG_rule T NN

        Extract the left-hand-side nonterminal from a left-regular rule.

        Equations
        Instances For
          def LG_rule.output {T N : Type} :
          LG_rule T NList (symbol T N)

          Convert an LG rule to its output as a list of symbols.

          • A → Ba outputs [B, a]
          • A → a outputs [a]
          • A → ε outputs []
          Equations
          Instances For
            def LG_transforms {T : Type} (g : LG_grammar T) (w₁ w₂ : List (symbol T g.nt)) :

            One step of left-regular grammar derivation.

            Rewrites a nonterminal A in context u ++ [A] ++ v according to a rule.

            Equations
            Instances For
              def LG_derives {T : Type} (g : LG_grammar T) :
              List (symbol T g.nt)List (symbol T g.nt)Prop

              Reflexive-transitive closure of LG_transforms.

              Equations
              Instances For
                def LG_generates {T : Type} (g : LG_grammar T) (w : List T) :

                A word (list of terminals) is generated by a left-regular grammar.

                Equations
                Instances For
                  def LG_language {T : Type} (g : LG_grammar T) :

                  The language generated by a left-regular grammar.

                  Equations
                  Instances For
                    def is_LG {T : Type} (L : Language T) :

                    A language is left-regular if it is generated by some left-regular grammar.

                    Equations
                    Instances For
                      def LG {T : Type} :

                      The class of left-regular languages.

                      Equations
                      Instances For
                        theorem LG_deri_self {T : Type} (g : LG_grammar T) {w : List (symbol T g.nt)} :
                        theorem LG_deri_of_tran {T : Type} {g : LG_grammar T} {u v : List (symbol T g.nt)} (h : LG_transforms g u v) :
                        theorem LG_deri_of_deri_tran {T : Type} {g : LG_grammar T} {u v w : List (symbol T g.nt)} (huv : LG_derives g u v) (hvw : LG_transforms g v w) :
                        theorem LG_deri_of_deri_deri {T : Type} {g : LG_grammar T} {u v w : List (symbol T g.nt)} (huv : LG_derives g u v) (hvw : LG_derives g v w) :