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 LinkCompletedChildWithParent(int i, EarleyItem parent, EarleyItem child, EarleySet R, SppfNode w) { var k = parent.StartPosition; var z = parent.SppfNode; // var δ = item.Tail; var δ0 = parent.DecoratedProduction.TailFirst; // Λ is child, item is parent var gatherExcludes = GatherExcludes(parent, child); if (gatherExcludes) { return; } // let y = MAKE NODE(A ::= τD · δ, k, i, z, w, V) var productionAdvanced = parent.DecoratedProduction.Increment(); var y = MakeNode(productionAdvanced, k, i, z, w); var newItem = new EarleyItem(productionAdvanced, k, y); // if δ ∈ Σ_N and (A ::= τD · δ, k, y) ̸∈ E_i { if (PrefixInSigma(δ0)) { // add (A ::= τD · δ, k, y) to E_i and R if (_E[i].Add(newItem)) { R.Add(newItem); } } else { // if δ = a_i δ′ { add (A ::= τD · δ, k, y) to Q } } if (i < _a.Count) { var aCurr = _a[i]; if (δ0 == aCurr) { _Q.Add(newItem); } } } }
// if Λ = (B ::= α · Cβ, h, w) { private void Predict(int i, Dictionary <Nonterminal, SppfNode> H, EarleySet R, EarleyItem Λ, Nonterminal C) { //var β = Λ.Tail; var w = Λ.SppfNode; var h = Λ.StartPosition; var β0 = Λ.DecoratedProduction.TailFirst; // for all (C ::= δ) ∈ P { foreach (var production in _grammar.ProductionsFrom(C)) { // if δ ∈ Σ_N and (C ::= ·δ, i, null) ̸∈ E_i { var δ0 = production.Rhs.FirstOrDefault(); var newItem = new EarleyItem(new DecoratedProduction(production, 0), i, null); if (PrefixInSigma(δ0)) { // add (C ::= ·δ, i, null) to E_i and R } if (_E[i].Add(newItem)) { R.Add(newItem); } } else { // if δ = a_i δ′ { add (C ::= · δ, i, null) to Q } if (i < _a.Count) { var aCurr = _a[i]; if (δ0 == aCurr) { _Q.Add(newItem); } } } } // if ((C, v) ∈ H) { if (H.TryGetValue(C, out SppfNode v)) { // let y = MAKE_NODE(B ::= αC · β, h, i, w, v, V) var productionAdvanced = Λ.DecoratedProduction.Increment(); var y = MakeNode(productionAdvanced, h, i, w, v); var newItem = new EarleyItem(productionAdvanced, h, y); // if β ∈ Σ N and (B ::= αC · β, h, y) ̸∈ E_i { if (PrefixInSigma(β0)) { // add(B::= αC · β, h, y) to E_i and R } if (_E[i].Add(newItem)) { R.Add(newItem); } } else { // if β = a_i β′ { add (B ::= αC · β, h, y) to Q } } } if (i < _a.Count) { var aCurr = _a[i]; if (β0 == aCurr) { _Q.Add(newItem); } } } } }