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 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); }
internal ProcessDetailsReport(EarleySet earleySet) { _leoItemsList = new List <string>(); List <LeoItem> setLeoItems = earleySet.GetLeoItemList(); for (int i = 0; i < setLeoItems.Count; i++) { _leoItemsList.Add(setLeoItems[i].ToString()); } ; _earleyItemsList = earleySet.GetEarleyItemReportList(); _isParserReportValid = true; _errorDescription = new ErrorDescription(ErrorCode.NO_ERROR); }
internal static void PrintSets(List <EarleySet> setsToPrint, bool all) { if (setsToPrint == null) { return; } for (int i = 0; i < setsToPrint.Count; i++) { Console.WriteLine("\n <=============================SET=================================> " + i); EarleySet set = setsToPrint[i]; List <EarleyItem> items = set.GetEarleyItemList(); for (int k = 0; k < items.Count; k++) { EarleyItem e = items[k]; if (!all) { if (e.IsCompleted()) { Console.WriteLine("\t\t" + e.ToString()); } } else { Console.WriteLine((e.IsCompleted() ? "\t\t" : "\t") + e.ToString()); } } Console.WriteLine("\n <--------> "); List <LeoItem> transitiveItems = set.GetLeoItemList(); for (int k = 0; k < transitiveItems.Count; k++) { LeoItem e = transitiveItems[k]; Console.WriteLine(e.ToString()); } Console.WriteLine("\n <=====================================================================> " + i); } }
private void UpdateSetsBeforeReparse(String input, int position) { for (int i = position; i < lastInputString.Length; i++) { Sets[i] = new EarleySet(); } int extra = input.Length - Sets.Count + 1; if (extra > 0) { for (int i = 0; i < extra; i++) { Sets.Add(new EarleySet()); } } else if (extra < 0) { for (int i = lastInputString.Length - extra; i < lastInputString.Length; i++) { Sets.RemoveAt(i); } } }
private void RunMarpa(String input, int fromPosition) { for (int i = fromPosition; i <= input.Length; i++) { EarleySet set = Sets[i]; List <EarleyItem> items = set.GetEarleyItemList(); for (int j = 0; j < items.Count; j++) { EarleyItem current = items[j]; if (current.IsCompleted()) { Completer(current, i); } else { bool condition = Grammar.DoesBelongToTerminals(current.GetCurrentNextSymbol()); if (!condition) { Predictor(current, i); } else if (input.Length > i) { Scanner(current, i, input[i]); } } } if (i + 1 < Sets.Count && Sets[i + 1].GetEarleyItemList().Count == 0) { errorHandler.AddNewError(ErrorCode.UNRECOGNISED_SYMBOL, input[i], i); return; } } }
private LeoItem FindLeoItemPredecessor(EarleyItem earleyItem) { EarleySet predecessorSet = Sets[earleyItem.GetOrignPosition()]; return(predecessorSet.FindLeoItemBySymbol(earleyItem.GetRule().GetLeftHandSideOfRule())); }