Langlib

Langlib.Grammars.RightRegular.Definition

Right-Regular (Type-3) Grammar Definitions #

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

Grammar restriction #

An unrestricted grammar allows rules of the form α A β → γ where α, β, γ are arbitrary strings of terminals and nonterminals. A right-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 RG_rule (T N : Type) :

A production rule in a right-regular grammar.

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

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

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

      • nt : Type

        Type of nonterminals

      • initial : self.nt

        Start symbol

      • rules : List (RG_rule T self.nt)

        Production rules

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

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

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

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

          Equations
          Instances For
            def RG_transforms {T : Type} (g : RG_grammar T) (w₁ w₂ : List (symbol T g.nt)) :

            One step of right-regular grammar derivation.

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

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

              Reflexive-transitive closure of RG_transforms.

              Equations
              Instances For
                def RG_generates {T : Type} (g : RG_grammar T) (w : List T) :

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

                Equations
                Instances For
                  def RG_language {T : Type} (g : RG_grammar T) :

                  The language generated by a right-regular grammar.

                  Equations
                  Instances For
                    theorem RG_deri_self {T : Type} (g : RG_grammar T) {w : List (symbol T g.nt)} :
                    theorem RG_deri_of_tran {T : Type} {g : RG_grammar T} {u v : List (symbol T g.nt)} (h : RG_transforms g u v) :
                    theorem RG_deri_of_deri_tran {T : Type} {g : RG_grammar T} {u v w : List (symbol T g.nt)} (huv : RG_derives g u v) (hvw : RG_transforms g v w) :
                    theorem RG_deri_of_deri_deri {T : Type} {g : RG_grammar T} {u v w : List (symbol T g.nt)} (huv : RG_derives g u v) (hvw : RG_derives g v w) :