public ProductionItem( MarkedProduction markedProduction, IReadOnlySet <Terminal <TTokenKind> > lookaheads) { MarkedProduction = markedProduction; Lookaheads = lookaheads ?? Set <Terminal <TTokenKind> > .Empty; }
public override int GetHashCode() { unchecked { var hashCode = MarkedProduction.GetHashCode(); hashCode = (hashCode * 397) ^ Lookaheads.GetHashCode(); return(hashCode); } }
public bool Equals(ProductionItem <TTokenKind> other, ProductionItemComparison comparison) { switch (comparison) { case ProductionItemComparison.MarkedProductionOnly: return(MarkedProduction.Equals(other.MarkedProduction)); // CORE is the same case ProductionItemComparison.LookaheadsOnly: return(Lookaheads.SetEquals(other.Lookaheads)); case ProductionItemComparison.MarkedProductionAndLookaheads: default: return(MarkedProduction.Equals(other.MarkedProduction) && Lookaheads.SetEquals(other.Lookaheads)); } }
/// <summary> /// Get the remaining symbols after the dot symbol in normal order. /// </summary> public IEnumerable <Symbol> GetRemainingSymbolsAfterDotSymbol() => MarkedProduction.GetRemainingSymbolsAfterDotSymbol();
/// <summary> /// Get the symbol after the dot. /// </summary> public TSymbol TryGetDotSymbol <TSymbol>() where TSymbol : Symbol => MarkedProduction.TryGetDotSymbol <TSymbol>();
/// <summary> /// Get the successor item of a shift/goto action created by 'shifting the dot'. /// </summary> public ProductionItem <TTokenKind> WithShiftedDot() // NOTE: we only make a shallow copy of the read-only lookaheads set => new ProductionItem <TTokenKind>(MarkedProduction.WithShiftedDot(), Lookaheads);
/// <summary> /// Does this LR(k) item set contain a kernel item with a given CORE (dotted production). /// </summary> public bool CoreOfKernelContains(MarkedProduction dottedProduction) { return(_anyLookaheads ? KernelItems.Select(item => item.MarkedProduction).Contains(dottedProduction) : _kernelItems.Contains(dottedProduction.AsLr0Item <TTokenKind>())); }