Langlib

Langlib.Grammars.ContextFree.UnrestrictedCharacterization

Context-Free Grammars as Unrestricted Grammars #

This file gives an alternative characterization of context-free grammars as unrestricted grammars satisfying an additional structural property on their rules.

Overview #

A standard unrestricted grammar has rules of the form input_L ++ [nonterminal input_N] ++ input_R → output_string where there are no restrictions on the relationship between the left- and right-hand sides.

A context-free grammar is one where each rule has no context: i.e., for every rule, input_L = [] and input_R = []. In other words, each rule rewrites a single nonterminal A to a string γ, independently of the surrounding context.

This file proves that the unrestricted characterization agrees with the CF_grammar presentation.

Main declarations #

Forward direction: CF_grammar → context-free unrestricted grammar #

def grammar_of_cfg {T : Type} (g : CF_grammar T) :

Convert a context-free grammar to the corresponding unrestricted grammar with empty left and right contexts in every rule.

Equations
  • One or more equations did not get rendered due to their size.
Instances For

    The unrestricted grammar obtained from a context-free grammar (via grammar_of_cfg) satisfies the context-free property.

    Every language generated by a CF_grammar satisfies the default unrestricted characterization.

    Backward direction: context-free unrestricted grammar → CF_grammar #

    def cfrule_of_grule {T N : Type} (r : grule T N) :
    N × List (symbol T N)

    Convert an unrestricted grammar rule (from a context-free unrestricted grammar) into a context-free rule (a pair of nonterminal and output string).

    Equations
    Instances For

      Construct a CF_grammar from a context-free unrestricted grammar.

      Equations
      Instances For
        theorem cfg_of_grammar_transforms_iff {T : Type} (g : grammar T) (hg : grammar_context_free g) (w₁ w₂ : List (symbol T g.nt)) :
        CF_transforms (cfg_of_grammar g hg) w₁ w₂ grammar_transforms g w₁ w₂
        theorem cfg_of_grammar_derives_iff {T : Type} (g : grammar T) (hg : grammar_context_free g) (w₁ w₂ : List (symbol T g.nt)) :
        CF_derives (cfg_of_grammar g hg) w₁ w₂ grammar_derives g w₁ w₂

        The derivation relation of the constructed CF_grammar coincides with that of the original unrestricted grammar.

        The language of the constructed CF_grammar equals that of the original grammar.

        Every language satisfying the default unrestricted characterization is generated by a CF_grammar.

        Equivalence #

        The default unrestricted characterization of context-freeness agrees with the CF_grammar characterization.