Context-free grammar to pushdown automaton #
This file proves the grammar-to-automaton direction of the PDA = CFG equivalence.
From a grammar G it builds the single-state PDA M G (state Q.loop, stack
alphabet Symbol T G.NT, start symbol nonterminal G.initial) that simulates
leftmost derivations: ε-moves replace a nonterminal by a rule right-hand side
(M_consumes_nonterminal) and input-moves pop a matching terminal
(M_consumes_terminal). The main result pda_of_cfg proves
G.language = (M G).acceptsByEmptyStack, with the two inclusions given by
M_reaches_off_G_derives and G_derives_of_M_reaches.
@[reducible, inline]
abbrev
CFG_to_PDA.transition_fun
{T : Type}
[DecidableEq T]
(G : ContextFreeGrammar T)
[Fintype G.NT]
:
Equations
Instances For
@[reducible, inline]
Equations
- CFG_to_PDA.transition_fun' G x✝ (Symbol.nonterminal N) = {x : CFG_to_PDA.Q × List (CFG_to_PDA.S G) | ∃ (α : List (CFG_to_PDA.S G)) (_ : { input := N, output := α } ∈ G.rules), ({ }, α) = x}
- CFG_to_PDA.transition_fun' G x✝ Z = ∅
Instances For
@[reducible, inline]
abbrev
CFG_to_PDA.M
{T : Type}
[DecidableEq T]
[Fintype T]
(G : ContextFreeGrammar T)
[Fintype G.NT]
:
PDA' G
Equations
- One or more equations did not get rendered due to their size.
Instances For
theorem
CFG_to_PDA.M_consumes_terminal
{T : Type}
[DecidableEq T]
[Fintype T]
{G : ContextFreeGrammar T}
[Fintype G.NT]
(a : T)
(w : List T)
(α : List (S G))
:
theorem
CFG_to_PDA.M_consumes_nonterminal
{T : Type}
[DecidableEq T]
[Fintype T]
{G : ContextFreeGrammar T}
[Fintype G.NT]
{r : ContextFreeRule T G.NT}
(h : r ∈ G.rules)
(w : List T)
(α : List (S G))
:
theorem
CFG_to_PDA.M_consumes_terminal_string
{T : Type}
[DecidableEq T]
[Fintype T]
{G : ContextFreeGrammar T}
[Fintype G.NT]
(w w' : List T)
(α : List (S G))
:
theorem
CFG_to_PDA.G_rule_of_M_consumes_nonterminal
{T : Type}
[DecidableEq T]
[Fintype T]
{G : ContextFreeGrammar T}
[Fintype G.NT]
{w w' : List T}
{α β : List (S G)}
{N : G.NT}
:
theorem
CFG_to_PDA.M_terminal_stack_of_read
{T : Type}
[DecidableEq T]
[Fintype T]
{G : ContextFreeGrammar T}
[Fintype G.NT]
(a : T)
(w : List T)
(α β : List (S G))
:
theorem
CFG_to_PDA.M_deterministic_step_of_terminal_stack_cons
{T : Type}
[DecidableEq T]
[Fintype T]
{G : ContextFreeGrammar T}
[Fintype G.NT]
(a : T)
(w v : List T)
(β β' : List (S G))
:
theorem
CFG_to_PDA.M_deterministic_of_terminal_stack_cons
{T : Type}
[DecidableEq T]
[Fintype T]
{G : ContextFreeGrammar T}
[Fintype G.NT]
(a : T)
(w : List T)
(β : List (S G))
:
theorem
CFG_to_PDA.M_deterministic_of_terminal_stack
{T : Type}
[DecidableEq T]
[Fintype T]
{G : ContextFreeGrammar T}
[Fintype G.NT]
(w v : List T)
(β : List (S G))
:
theorem
CFG_to_PDA.M_reaches_off_G_derives
{T : Type}
[DecidableEq T]
[Fintype T]
{G : ContextFreeGrammar T}
[Fintype G.NT]
(α : List (Symbol T G.NT))
(w : List T)
(h : G.DerivesLeftmost α (List.map Symbol.terminal w))
:
theorem
CFG_to_PDA.G_derives_of_M_reaches
{T : Type}
[DecidableEq T]
[Fintype T]
{G : ContextFreeGrammar T}
[Fintype G.NT]
{α : List (Symbol T G.NT)}
{w : List T}
(h : PDA.Reaches { state := { }, input := w, stack := α } { state := { }, input := [], stack := [] })
:
G.Derives α (List.map Symbol.terminal w)
theorem
CFG_to_PDA.pda_of_cfg
{T : Type}
[DecidableEq T]
[Fintype T]
(G : ContextFreeGrammar T)
[Fintype G.NT]
: