Langlib

Langlib.Grammars.LR.Equivalence.Items

Finite canonical LR(k) items #

This file supplies the finite data used by the canonical viable-prefix automaton. Productions are represented by positions in the grammar's rule list, rather than by their (possibly infinitely typed) nonterminals. Thus the item and parser-state types are finite without imposing a Fintype instance on the grammar's nonterminal type.

@[reducible, inline]

A production occurrence in the finite rule list.

Equations
Instances For
    def CF_grammar.LRk.ruleAt {T : Type} (G : CF_grammar T) (i : RuleIndex G) :
    G.nt × List (symbol T G.nt)

    The production represented by a rule-list index.

    Equations
    Instances For
      @[simp]
      theorem CF_grammar.LRk.ruleAt_mem {T : Type} (G : CF_grammar T) (i : RuleIndex G) :
      @[reducible, inline]
      abbrev CF_grammar.LRk.Position {T : Type} (G : CF_grammar T) (i : RuleIndex G) :

      A dot position in a production, including the completed position just past the right-hand side.

      Equations
      Instances For
        @[reducible, inline]

        Exactly k symbols of terminal lookahead. none is the explicit end-of-input marker; after the first none, all semantically reachable lookaheads are also none. Keeping the ambient function type unrestricted makes finiteness immediate, while well-formedness is enforced by the semantic relations below.

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

          Observe the first k terminals of a suffix, padding with the explicit EOF marker.

          Equations
          Instances For

            The all-EOF lookahead.

            Equations
            Instances For
              def CF_grammar.LRk.prependLookahead {T : Type} (k : ) (z : List T) (u : Lookahead T k) :

              Prefix a finite terminal word to a padded lookahead.

              Equations
              Instances For
                @[simp]
                theorem CF_grammar.LRk.observe_append {T : Type} (k : ) (z s : List T) :
                observe k (z ++ s) = prependLookahead k z (observe k s)
                @[reducible, inline]
                abbrev CF_grammar.LRk.Item {T : Type} (G : CF_grammar T) (k : ) :

                A canonical LR item [A → α · β, u].

                The first component identifies the production, the second its dot position, and the third the padded terminal lookahead.

                Equations
                Instances For
                  def CF_grammar.LRk.Item.rule {T : Type} {G : CF_grammar T} {k : } (i : Item G k) :

                  The production index of an item.

                  Equations
                  Instances For
                    def CF_grammar.LRk.Item.position {T : Type} {G : CF_grammar T} {k : } (i : Item G k) :

                    The dot position of an item.

                    Equations
                    Instances For
                      def CF_grammar.LRk.Item.lookahead {T : Type} {G : CF_grammar T} {k : } (i : Item G k) :

                      The terminal lookahead of an item.

                      Equations
                      Instances For
                        def CF_grammar.LRk.Item.before {T : Type} {G : CF_grammar T} {k : } (i : Item G k) :
                        List (symbol T G.nt)

                        Symbols before the dot.

                        Equations
                        Instances For
                          def CF_grammar.LRk.Item.after {T : Type} {G : CF_grammar T} {k : } (i : Item G k) :
                          List (symbol T G.nt)

                          Symbols at and after the dot.

                          Equations
                          Instances For
                            def CF_grammar.LRk.Item.next? {T : Type} {G : CF_grammar T} {k : } (i : Item G k) :

                            The symbol immediately after the dot, if any.

                            Equations
                            Instances For
                              def CF_grammar.LRk.Item.Complete {T : Type} {G : CF_grammar T} {k : } (i : Item G k) :

                              An item is complete when its dot is just past the right-hand side.

                              Equations
                              Instances For
                                def CF_grammar.LRk.Advances {T : Type} {G : CF_grammar T} {k : } (i : Item G k) (X : symbol T G.nt) (j : Item G k) :

                                Relational dot advancement. A relational presentation avoids dependent casts between the position types while retaining a finite decidable relation.

                                Equations
                                Instances For
                                  def CF_grammar.LRk.Item.afterNext {T : Type} {G : CF_grammar T} {k : } (i : Item G k) :
                                  List (symbol T G.nt)

                                  The right-hand suffix after the nonterminal immediately following an item's dot.

                                  Equations
                                  Instances For
                                    def CF_grammar.LRk.CanFollow {T : Type} (G : CF_grammar T) (k : ) (beta : List (symbol T G.nt)) (u v : Lookahead T k) :

                                    A lookahead v can follow a just-opened nonterminal when the remaining sentential suffix is beta and the enclosing item has lookahead u.

                                    This semantic FIRST_k relation is deliberately stated with rightmost derivations. It is a finite decidable table by classical choice because its arguments range over the finite item universe.

                                    Equations
                                    Instances For
                                      def CF_grammar.LRk.ClosureStep {T : Type} (G : CF_grammar T) (k : ) (i j : Item G k) :

                                      One epsilon-closure edge between canonical items.

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For
                                        noncomputable def CF_grammar.LRk.closure {T : Type} [Fintype T] (G : CF_grammar T) (k : ) (I : Finset (Item G k)) :
                                        Finset (Item G k)

                                        Epsilon closure of a finite item set.

                                        Equations
                                        Instances For
                                          @[simp]
                                          theorem CF_grammar.LRk.mem_closure {T : Type} [Fintype T] (G : CF_grammar T) (k : ) (I : Finset (Item G k)) (j : Item G k) :
                                          j closure G k I iI, Relation.ReflTransGen (ClosureStep G k) i j
                                          theorem CF_grammar.LRk.subset_closure {T : Type} [Fintype T] (G : CF_grammar T) (k : ) (I : Finset (Item G k)) :
                                          I closure G k I
                                          @[simp]
                                          theorem CF_grammar.LRk.closure_closure {T : Type} [Fintype T] (G : CF_grammar T) (k : ) (I : Finset (Item G k)) :
                                          closure G k (closure G k I) = closure G k I
                                          noncomputable def CF_grammar.LRk.goto {T : Type} [Fintype T] (G : CF_grammar T) (k : ) (I : Finset (Item G k)) (X : symbol T G.nt) :
                                          Finset (Item G k)

                                          Canonical goto on one grammar symbol.

                                          Equations
                                          Instances For
                                            @[simp]
                                            theorem CF_grammar.LRk.mem_goto {T : Type} [Fintype T] (G : CF_grammar T) (k : ) (I : Finset (Item G k)) (X : symbol T G.nt) (j : Item G k) :
                                            j goto G k I X iclosure G k I, Advances i X j