Exemple #1
0
 public ProductionItem(
     MarkedProduction markedProduction,
     IReadOnlySet <Terminal <TTokenKind> > lookaheads)
 {
     MarkedProduction = markedProduction;
     Lookaheads       = lookaheads ?? Set <Terminal <TTokenKind> > .Empty;
 }
Exemple #2
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = MarkedProduction.GetHashCode();
         hashCode = (hashCode * 397) ^ Lookaheads.GetHashCode();
         return(hashCode);
     }
 }
Exemple #3
0
        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));
            }
        }
Exemple #4
0
 /// <summary>
 /// Get the remaining symbols after the dot symbol in normal order.
 /// </summary>
 public IEnumerable <Symbol> GetRemainingSymbolsAfterDotSymbol() => MarkedProduction.GetRemainingSymbolsAfterDotSymbol();
Exemple #5
0
 /// <summary>
 /// Get the symbol after the dot.
 /// </summary>
 public TSymbol TryGetDotSymbol <TSymbol>() where TSymbol : Symbol => MarkedProduction.TryGetDotSymbol <TSymbol>();
Exemple #6
0
 /// <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);
Exemple #7
0
 /// <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>()));
 }