Proofs: Parse chart
These are the human proofs of Parse chart, at full length.
FILL adds exactly the sound edges, so READ decides membership and returns a parse tree full
This proof shows: correctness.
Statement. Let be any context-free grammar and . Call an edge sound if
(P) for some , and (D) .
When FILL stops, the chart contains exactly the sound edges. Consequently READ finds a complete edge if and only if , and in that case following the backpointers terminates and yields a parse tree of . FILL itself stops, because there are at most edges and each is pushed on the agenda once.
Proof.
Step 1 (only sound edges). By induction on the order in which edges are added. L5 adds : (P) holds with and (D) is . Prediction at L7, from a sound , adds : from we get (P), and (D) is trivial. The scan at L9 appends to , so (D) holds for , and (P) is unchanged. The fundamental rule at L8 or L10 combines with , both sound: , and (P) is that of the active edge.
Step 2 (the fundamental rule fires). Suppose the edges and are both added. Each is pushed on the agenda once and popped later. If was added before is popped, L8 finds in COMPLETE when is popped. Otherwise was popped, hence added and put into WAITING at L3, before was added, and L10 finds when is popped. Either way is added.
Step 3 (all sound edges). Let be sound. Take a tree for the derivation in (P), with root and frontier , and at its leaf attach a node with the children , where the children in get the subtrees of a derivation and the children in stay leaves. Call the result . In , every leaf to the left of the last child of is a terminal or .
Walk depth first, from left to right, and record an event when the walk enters an inner node and an event when it has finished the -th child of . Stop at the event . For each recorded event , all leaves to the left of and all leaves below the first children of are terminals or : they lie to the left of the end of in . So with the number of terminals to the left of and the number up to the end of the -th child, the event names the edge , where is the production of and . The last event names . We show by induction along the walk that each named edge is added.
- for the root: is , , and L5 adds .
- for a node that is the -th child of its parent : the event came before, so , whose dot is before the label of , is added, and when it is popped, prediction at L7 adds .
- with and a terminal -th child: the event came before; when its edge is popped, the next input token is that terminal, and the scan at L9 adds .
- with and a nonterminal -th child : this child lies to the left of the end of , so it is an inner node, with a production ; the events and came before, so their edges and are added, and by Step 2 the fundamental rule adds .
So is added. Together with Step 1, the chart holds exactly the sound edges.
Step 4 (READ). A complete edge is sound iff for a production , that is, iff ; (P) holds trivially. By Steps 1 and 3, READ finds such an edge iff . Every backpointer of an edge names edges that were already in the chart when was added, so the relation "is named by a backpointer of" is contained in the order of insertion and has no cycle; following backpointers from any edge reaches only finitely many edges and stops. For an edge built by L8, L9 or L10, the backpointer is the shorter edge for and the child, a token or a complete edge for ; for an edge built by L5 or L7, it is empty. Unfolding the chain of an edge therefore lists children with and consecutive spans from to , each a token equal to its terminal or a complete edge for its nonterminal. By induction on the insertion order, the tree built from is a parse tree with root and yield , so the tree read from is a parse tree of .