Langlib

Langlib.Grammars.LR.Definition

LR(k) Grammars #

This file defines the grammar-side deterministic context-free notion used in parser theory, as a restriction of the repository's own context-free grammars (CF_grammar). The key definition is CF_grammar.IsLRk: after a rightmost derivation step, the reducible handle is uniquely determined by the already-built sentential prefix and by k terminal lookahead symbols.

This is the grammar-side class intended to match DPDAs. The full equivalence with is_DCF requires the two standard constructions:

Those constructions are not encoded here yet.

A context-free rule is, in this development, a pair r : g.nt × List (symbol T g.nt) whose first component r.1 is the left-hand nonterminal and whose second component r.2 is the right-hand output string.

def CF_grammar.RewritesRightmost {T N : Type} (r : N × List (symbol T N)) (u v : List (symbol T N)) :

A rightmost use of a context-free rule r = (input, output).

The rule rewrites an occurrence of r.1 whose suffix contains terminals only.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    def CF_grammar.ProducesRightmost {T : Type} (g : CF_grammar T) (u v : List (symbol T g.nt)) :

    A single rightmost derivation step in a context-free grammar.

    Equations
    Instances For
      @[reducible, inline]
      abbrev CF_grammar.DerivesRightmost {T : Type} (g : CF_grammar T) :
      List (symbol T g.nt)List (symbol T g.nt)Prop

      Rightmost derivation: reflexive-transitive closure of rightmost production.

      Equations
      Instances For
        def CF_grammar.lrLookahead {T : Type} (k : ) (w : List T) :

        The k terminal symbols visible as LR lookahead.

        Equations
        Instances For
          def CF_grammar.IsLRk {T : Type} (g : CF_grammar T) (k : ) :

          Semantic LR(k) condition for a context-free grammar.

          If two rightmost derivations reach configurations where one more rightmost step creates the same sentential prefix, and their remaining terminal suffixes have the same k-symbol lookahead, then the reducible handle and rule are identical. The terminal suffixes themselves need not be equal beyond the visible lookahead.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            theorem CF_grammar.IsLRk.mono {T : Type} (g : CF_grammar T) {k l : } (hkl : k l) (hg : g.IsLRk k) :
            g.IsLRk l

            LR lookahead is monotone: a grammar that is LR(k) is also LR(l) for any l ≥ k.

            def is_LRk {T : Type} (k : ) (L : Language T) :

            Language class generated by an LR(k) grammar.

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

              Language class generated by an LR(k) grammar for some finite k.

              Equations
              Instances For
                def LR {T : Type} :

                The class of LR languages.

                Equations
                Instances For
                  theorem is_LR_of_is_LRk {T : Type} {k : } {L : Language T} (h : is_LRk k L) :

                  Every LR(k) language is an LR language.

                  theorem is_LRk_mono {T : Type} {k l : } (hkl : k l) {L : Language T} (h : is_LRk k L) :
                  is_LRk l L

                  LR language classes are monotone in the amount of lookahead.