The left-corner chart recognizer accepts exactly the words of the grammar full
This proof shows: correctness.
Notation. G=(V,Σ,P,S) is any context-free grammar and w=a1⋯an. For 0≤i≤k≤n, wi,k=ai+1⋯ak. L(C) is the set of B∈V such that B=C or there are productions C→B1γ1,B1→B2γ2,…,Bm−1→Bγm in P, m≥1, with Bm=B. Note that if B∈L(C) and B→Dγ∈P with D∈V, then D∈L(C). A pair (C,i) is a goal once START(C,i) has been called. "Add" puts an item in a set only if it is not there.
Lemma 1 (soundness). Every item [C,i,B→α∙β]∈E[k] satisfies: (C,i) is a goal, i≤k, B∈L(C), α⇒∗wi,k, and α=ε unless β=ε. Every (C,i,k)∈DONE satisfies: (C,i) is a goal and C⇒∗wi,k.
Proof. By induction on the order of the additions. Line L14 adds [C,k,D→ak+1∙γ] to E[k+1] with D∈L(C), and ak+1⇒∗wk,k+1. Line L15 adds [C,k,D→∙] with D∈L(C) and β=ε. Line L6 adds (C,i,k) for a complete item [C,i,C→α∙], and then C⇒α⇒∗wi,k. It also moves an item [C′,i′,D→γ∙Cδ]∈E[i] that waits on (C,i) to E[k]; by induction γ⇒∗wi′,i, so γC⇒∗wi′,k. Line L7 adds [C,i,D→B∙γ] for a complete item [C,i,B→α∙]∈E[k], with D∈L(C); by induction B⇒α⇒∗wi,k. Line L11 is the same as the move of line L6, for an entry (Y,k,k′)∈DONE, with Y⇒∗wk,k′ by induction. Line L12 extends α by ak+1. In each case the new item keeps its goal, which is a goal by induction, and has a nonempty α unless it comes from line L15. □
Lemma 2 (processing order). Every entry (Y,i,k′) of DONE is added while E[k′] is processed. When line L11 runs for an item of E[k], every entry (Y,k,k′) in DONE has k′=k. Every item ever added to E[k] is processed by the loop of line L4 for this k.
Proof. Line L6 adds (C,i,k) while it processes a complete item of E[k]. So when E[k] is processed, the entries of DONE have ends at most k, and an entry (Y,k,k′) has k′≥k by Lemma 1, so k′=k. Hence items are added to E[k] only by START(⋅,k) (line L15), by START(⋅,k−1) (line L14), by lines L6, L7 and L11 while E[k] is processed, or by line L12 while E[k−1] is processed. START(Y,k) is called at line L2 with k=0 before the loop, or at line L9 while E[k] is processed. So no item is added to E[k] after its loop ends, and the loop visits every item in the order of insertion, including the items added during the loop. □
Lemma 3 (closure). When the loop of line L3 ends, the chart is closed under the rules of lines L6, L7, L9 to L12, L14 and L15: for every item, the items and goals that the line for it would add are present, and for every goal (C,i), the items of START(C,i) are present.
Proof. Every item is processed (Lemma 2), and START runs for every goal. Processing an item adds what lines L7, L9, L10, L11 and L12 require for it. For a complete item [C,i,B→α∙]∈E[k], the first such item for the key (C,i,B,k) is processed fully, and the effects of lines L6 and L7 depend only on this key, so they hold for the other items with the same key. It remains to show the rule of line L6 for an item J that waits on (C,i) and an entry (C,i,k)∈DONE: the moved item must be in E[k]. If J was recorded as waiting (line L10) before (C,i,k) was added, then line L6 moved it when it added the entry. Otherwise the entry was in DONE when line L11 processed J, and line L11 moved it. □
Lemma 4 (completeness). Let (C,i) be a goal, and suppose C⇒∗wi,k. Then (C,i,k)∈DONE when the loop ends.
Proof. By induction on the height of a parse tree T of C with yield wi,k. Let C=B0,B1,…,Bm be the nodes on the left edge of T: Br+1 is the first child of Br, and Bm is the last internal node on this edge. Each Br is in L(C), since each production Br→Br+1⋯ starts with Br+1. Let Br→Xr,1⋯Xr,qr be the production at Br, where Xr,1=Br+1 for r<m, and let i=lr,0≤lr,1≤⋯≤lr,qr be the boundaries of the yields of its children. All nodes on the left edge start at i, and Br ends at lr,qr.
We show by downward induction on r, from r=m to r=0, that the complete item [C,i,Br→Xr,1⋯Xr,qr∙] is in E[lr,qr].
The first item at Br. If r=m and qm=0, START(C,i) adds [C,i,Bm→∙] to E[i] (line L15). If r=m and qm>0, then Xm,1 is a terminal, equal to ai+1, so i<n and START(C,i) adds [C,i,Bm→ai+1∙Xm,2⋯] to E[i+1] (line L14). If r<m, the complete item for Br+1 is in E[lr,1] by the inner induction, and line L7 adds [C,i,Br→Br+1∙Xr,2⋯] to E[lr,1], because Br∈L(C) (Lemma 3).
The other children. Suppose [C,i,Br→Xr,1⋯Xr,t−1∙Xr,t⋯]∈E[lr,t−1] for some 2≤t≤qr. If Xr,t is a terminal, it is alr,t−1+1, and line L12 moves the dot into E[lr,t]. If Xr,t=Y is a nonterminal, then by Lemma 3 the pair (Y,lr,t−1) is a goal (line L9) and the item waits on it (line L10). The subtree of Y is a proper subtree of T, of smaller height, with yield wlr,t−1,lr,t, so by the outer induction (Y,lr,t−1,lr,t)∈DONE. By Lemma 3 (the rule of line L6), the item with the dot after Y is in E[lr,t]. After t=qr, the complete item for Br is in E[lr,qr].
For r=0, the complete item [C,i,C→⋯∙]∈E[k] has B=C, and the rule of line L6 puts (C,i,k) in DONE. □
Termination. There are at most ∣V∣(n+1) goals, and for each set E[k] at most ∣V∣(k+1) goals times ∣G∣ dotted productions, so finitely many items. Each item is processed once, and each step of the processing does a finite amount of work, so the loop ends.
Theorem. LEFT-CORNER(G,w) terminates and returns true if and only if S⇒∗w.
Proof. Termination is shown above. Line L2 makes (S,0) a goal. If line L13 returns true, then (S,0,n)∈DONE and S⇒∗w0,n=w by Lemma 1. If S⇒∗w, then (S,0,n)∈DONE by Lemma 4, and line L13 returns true. ■