public (Item?, ParseAction) FindTransitionOfItemOn(Item item, Symbol symbol) { var(target, action) = FindTransitionOfItemOnUnchecked(item, symbol); return(TransitionIsValidForItem(action, item, symbol) ? (target, action) : (null, ParseAction.MakeDiscard())); }
private (Item?, ParseAction) FindTransitionOfItemOnUnchecked(Item item, Symbol symbol) { var productionLen = item.Production.Ingredients.Length; if (item.DotPos < productionLen && symbol == item.Production.Ingredients[item.DotPos]) { return(item.ShiftedByOne(), ParseAction.MakeShift()); } if (item.DotPos >= productionLen && symbol == item.Follow) { if (symbol == Symbol.EndOfInput && item.Production.Product == Symbol.ExtendedStartSymbol) { return(null, ParseAction.MakeAccept()); } return(null, ParseAction.MakeReduce(item.Production)); } return(null, ParseAction.MakeDiscard()); }