private void ProcessQ(int i) { if (i < _a.Count) { // create an SPPF node v labelled(a_i, i, i + 1) var v2 = new SppfWord(_a[i], i, i + 1); // while Q ̸= ∅ { while (!_Q.IsEmpty) { // remove an element, Λ = (B ::= α · a_i β, h, w) say, from Q var Λ = _Q.TakeOne(); if (Λ.DecoratedProduction.NextWord != _a[i]) { throw new Exception(); // continue; } var h = Λ.StartPosition; var w = Λ.SppfNode; var β0 = Λ.DecoratedProduction.TailFirst; // let y = MAKE NODE(B ::= α a_i · β, h, i + 1, w, v, V) var productionAdvanced = Λ.DecoratedProduction.Increment(); var y = MakeNode(productionAdvanced, h, i + 1, w, v2); var newItem = new EarleyItem(productionAdvanced, h, y); // if β ∈ Σ_N { add (B ::= α a_i · β, h, y) to E_i+1 } if (PrefixInSigma(β0)) { _E[i + 1].Add(newItem); } // if β = a_i+1 β′ { add (B ::= α a_i · β, h, y) to Q′ } else { if (i + 1 < _a.Count) { var aNext = _a[i + 1]; if (β0 == aNext) { _QPrime.Add(newItem); } } } } } }
private void ProcessR(int i, Dictionary <Nonterminal, SppfNode> H, EarleySet R) { // while R ̸= ∅ { while (!R.IsEmpty) { // remove an element, Λ say, from R var Λ = R.TakeOne(); var nextWord = Λ.DecoratedProduction.NextWord; // if Λ = (B ::= α · Cβ, h, w) { if (nextWord is Nonterminal C) { Predict(i, H, R, Λ, C); } // if Λ = (D ::= α·, h, w) { else if (nextWord == null) { Complete(i, H, R, Λ); } else { throw new Exception("Didn't expect a terminal"); } } }