Langlib

Langlib.Grammars.LR.Rightmost

Rightmost derivations #

This file supplies the structural facts about rightmost derivations which are independent of the LR conflict condition. In particular, an ordinary context-free derivation whose result is a terminal word can always be scheduled rightmost.

Counted rightmost derivations #

inductive CF_grammar.DerivesRightmostIn {T : Type} (G : CF_grammar T) :
List (symbol T G.nt)List (symbol T G.nt)Prop

A rightmost derivation using exactly n production steps. Unlike DerivesRightmost, this relation retains the measure needed for well-founded arguments which trace a surviving nonterminal back through its ancestors.

Instances For
    theorem CF_grammar.DerivesRightmostIn.derives {T : Type} {G : CF_grammar T} {n : } {u v : List (symbol T G.nt)} (h : G.DerivesRightmostIn n u v) :
    theorem CF_grammar.DerivesRightmostIn.trans {T : Type} {G : CF_grammar T} {m n : } {u v w : List (symbol T G.nt)} (huv : G.DerivesRightmostIn m u v) (hvw : G.DerivesRightmostIn n v w) :
    G.DerivesRightmostIn (m + n) u w

    Context closure #

    theorem CF_grammar.RewritesRightmost.append_left {T N : Type} {r : N × List (symbol T N)} {u v : List (symbol T N)} (h : RewritesRightmost r u v) (pre : List (symbol T N)) :
    RewritesRightmost r (pre ++ u) (pre ++ v)
    theorem CF_grammar.ProducesRightmost.append_left {T : Type} {G : CF_grammar T} {u v : List (symbol T G.nt)} (h : G.ProducesRightmost u v) (pre : List (symbol T G.nt)) :
    G.ProducesRightmost (pre ++ u) (pre ++ v)
    theorem CF_grammar.DerivesRightmost.append_left {T : Type} {G : CF_grammar T} {u v : List (symbol T G.nt)} (h : G.DerivesRightmost u v) (pre : List (symbol T G.nt)) :
    G.DerivesRightmost (pre ++ u) (pre ++ v)

    Rightmost derivations of adjacent pieces can be scheduled from right to left. This is the basic commutation principle used below.

    Terminal sentential forms #

    Splitting rightmost derivations #

    theorem CF_grammar.ProducesRightmost.append_cases {T : Type} {G : CF_grammar T} {u v x : List (symbol T G.nt)} (h : G.ProducesRightmost (u ++ v) x) :
    (∃ (u' : List (symbol T G.nt)) (wv : List T), v = List.map symbol.terminal wv x = u' ++ v G.ProducesRightmost u u') ∃ (v' : List (symbol T G.nt)), x = u ++ v' G.ProducesRightmost v v'

    A rightmost step in an append either occurs in the right component, or it occurs in the left component after the right component is already terminal.

    theorem CF_grammar.ProducesRightmost.preimage_nonterminal {T : Type} {G : CF_grammar T} {y p q : List (symbol T G.nt)} {A : G.nt} (h : G.ProducesRightmost y (p ++ [symbol.nonterminal A] ++ q)) :
    (∃ (q₀ : List (symbol T G.nt)), y = p ++ [symbol.nonterminal A] ++ q₀ G.ProducesRightmost q₀ q) rG.rules, ∃ (p₀ : List (symbol T G.nt)) (α : List (symbol T G.nt)) (β : List (symbol T G.nt)) (t : List T), r.2 = α ++ [symbol.nonterminal A] ++ β p = p₀ ++ α q = β ++ List.map symbol.terminal t y = p₀ ++ [symbol.nonterminal r.1] ++ List.map symbol.terminal t

    Trace a nonterminal in the result of one rightmost step. It was either already to the left of the rewritten (rightmost) nonterminal, or it occurs in the right-hand side of the rule used by the step.

    A derivation of an append to a terminal word uniquely separates into rightmost derivations of its two components.

    Ancestry of a surviving nonterminal #

    A nonterminal surviving in a right-sentential form is either the untouched start symbol, or descends from a concrete occurrence in the right-hand side of a rule. The rule's suffix derives exactly the terminal segment immediately following that occurrence; the remaining terminal suffix was already present when the rule was applied.

    theorem CF_grammar.derivesRightmostIn_nonterminal_ancestry {T : Type} (G : CF_grammar T) {n : } {p : List (symbol T G.nt)} {A : G.nt} {s : List T} (h : G.DerivesRightmostIn n [symbol.nonterminal G.initial] (p ++ [symbol.nonterminal A] ++ List.map symbol.terminal s)) :
    p = [] A = G.initial s = [] ∃ (m : ), rG.rules, ∃ (p₀ : List (symbol T G.nt)) (α : List (symbol T G.nt)) (β : List (symbol T G.nt)) (t : List T) (z : List T), m < n r.2 = α ++ [symbol.nonterminal A] ++ β p = p₀ ++ α s = z ++ t G.DerivesRightmostIn m [symbol.nonterminal G.initial] (p₀ ++ [symbol.nonterminal r.1] ++ List.map symbol.terminal t) G.DerivesRightmost β (List.map symbol.terminal z)

    Counted form of derivesRightmost_nonterminal_ancestry. In the non-base case the parent prehandle is reached in strictly fewer steps than the displayed surviving configuration. This strict measure supports terminating reverse item-closure and ancestry arguments even when the grammar contains cycles.

    Equivalence with unrestricted scheduling on terminal results #

    Every context-free derivation ending in terminals has a rightmost scheduling.