private bool LeoReducer(EarleyItem completed, int setNumber) { int position = completed.GetOrignPosition(); Symbol lhs = completed.GetRule().GetLeftHandSideOfRule(); EarleySet set = Sets[position]; LeoItem transitiveItem = set.FindLeoItemBySymbol(lhs); if (transitiveItem == null) { return(false); } EarleyItem newEarleyItem = new EarleyItem( setNumber, transitiveItem.GetDottedRule(), transitiveItem.GetOrignPosition() ); EarleyItem current = Sets[transitiveItem.GetOrignPosition()].GetEarleyItemList() .Find(el => el.GetDottedRule().Equals(transitiveItem.GetDottedRule()) && el.GetOrignPosition() == transitiveItem.GetOrignPosition()); if (current.GetCurrentPrevSymbolList() != null && current.GetCurrentPrevSymbolList().Count > 0) { newEarleyItem.AddPredecessorLink(current, position); } newEarleyItem.AddReducerLink(completed, position); AddToSet( newEarleyItem, setNumber, "LeoReducer" ); return(true); }
private void EarleyReducer(EarleyItem completed, int setNumber) { int position = completed.GetOrignPosition(); EarleySet set = Sets[position]; List <EarleyItem> items = set.GetEarleyItemList(); for (int j = 0; j < items.Count; j++) { EarleyItem current = items[j]; Symbol next = current.GetCurrentNextSymbol(); if (next != null && next.Equals(completed.GetRule().GetLeftHandSideOfRule())) { EarleyItem newEarleyItem = new EarleyItem( setNumber, new DottedRule(current.GetRule(), current.GetRulePosition() + 1), current.GetOrignPosition() ); if (current.GetCurrentPrevSymbolList() != null && current.GetCurrentPrevSymbolList().Count > 0) { newEarleyItem.AddPredecessorLink(current, position); } newEarleyItem.AddReducerLink(completed, position); AddToSet(newEarleyItem, setNumber, "EarleyReducer"); } } }
private void Scanner(EarleyItem current, int setNumber, Char inputSymbol) { Symbol nextSymbol = current.GetCurrentNextSymbol(); if (nextSymbol != null && nextSymbol.Equals(inputSymbol.ToString())) { EarleyItem newEarleyItem = new EarleyItem( setNumber + 1, new DottedRule(current.GetRule(), current.GetRulePosition() + 1), current.GetOrignPosition() ); if (newEarleyItem.GetCurrentPrevSymbolList() != null && newEarleyItem.GetCurrentPrevSymbolList().Count > 0) { newEarleyItem.AddPredecessorLink(current, setNumber); } AddToSet(newEarleyItem, setNumber + 1, "Scanner"); } }
private void BuildTree(TreeNode parent, EarleyItem current) { current.SetItemIsProcessed(); Symbol lhs = current.GetRule().GetLeftHandSideOfRule(); List <Symbol> prev = current.GetCurrentPrevSymbolList(); int setNumber = current.GetSetNumber(); if (IsEmptyRule(current)) { if (!parent.DoesChildExists(new TreeNode(lhs, setNumber, setNumber))) { parent.AddChild(new TreeNode(_grammar.GetNullStringSymbol(), setNumber, setNumber)); } } else if (prev.Count == 1 && IsLastSymbolBeforeDotTerminal(prev)) { Symbol symBeforeDot = prev[prev.Count - 1]; if (!parent.DoesChildExists(new TreeNode(symBeforeDot, setNumber, setNumber))) { parent.AddChild(new TreeNode(symBeforeDot, setNumber - 1, setNumber)); } } else if (prev.Count == 1 && IsLastSymbolBeforeDotNonTerminal(prev)) { Symbol symBeforeDot = prev[prev.Count - 1]; TreeNode newNode = new TreeNode(symBeforeDot, current.GetOrignPosition(), setNumber); if (!parent.DoesChildExists(newNode)) { parent.AddChild(newNode); } current.GetReducerLinks().ForEach(el => { if (el._label == current.GetOrignPosition() && !el._link.IsItemProcessed()) { BuildTree(newNode, el._link); } }); } else if (IsLastSymbolBeforeDotTerminal(prev)) { Symbol symBeforeDot = prev[prev.Count - 1]; TreeNode newNode = new TreeNode(symBeforeDot, setNumber - 1, setNumber); if (!parent.DoesChildExists(newNode)) { parent.AddChild(newNode); } TreeNode newComplexNode = new TreeNode( new DottedRule(current.GetRule(), current.GetRulePosition() - 1), current.GetOrignPosition(), setNumber - 1 ); if (!parent.DoesChildExists(newComplexNode)) { parent.AddChild(newComplexNode); } current.GetPredecessorLinks().ForEach(link => { if (link._label == setNumber - 1 && !link._link.IsItemProcessed()) { BuildTree(newComplexNode, link._link); } }); } else if (IsLastSymbolBeforeDotNonTerminal(prev)) { Symbol symBeforeDot = prev[prev.Count - 1]; current.GetReducerLinks().ForEach(item => { TreeNode newNode = new TreeNode(symBeforeDot, item._label, setNumber); if (!parent.DoesChildExists(newNode)) { parent.AddChild(newNode); } if (!item._link.IsItemProcessed()) { BuildTree(newNode, item._link); } TreeNode newComplexNode = new TreeNode( new DottedRule(current.GetRule(), current.GetRulePosition() - 1), current.GetOrignPosition(), item._label ); if (!parent.DoesChildExists(newComplexNode)) { parent.AddChild(newComplexNode); } current.GetPredecessorLinks().ForEach(predItem => { if (!predItem._link.IsItemProcessed()) { BuildTree(newComplexNode, predItem._link); } }); }); } ; }