Exemple #1
0
        protected EarleyItem(DottedRule dottedRule, int origin, IForestNode parseNode)
        {
            DottedRule = dottedRule;
            Origin     = origin;
            ParseNode  = parseNode;

            this.hashCode = (DottedRule, Origin).GetHashCode();
        }
 private int ComputeHashCode()
 {
     return(HashCode.Compute(
                DottedRule.GetHashCode(),
                Origin.GetHashCode(),
                Recognized.GetHashCode(),
                Reduction.GetHashCode(),
                Index.GetHashCode()));
 }
Exemple #3
0
 private void Seed(IEnumerable <Production> productions)
 {
     foreach (var production in productions)
     {
         var rules = new DottedRule[production.Count + 1];
         this.index.Add(production, rules);
         for (var dot = 0; dot <= production.Count; dot++)
         {
             rules[dot] = new DottedRule(production, dot);
         }
     }
 }
Exemple #4
0
        public bool Contains(DottedRule dottedRule, int origin)
        {
            if (dottedRule.IsComplete)
            {
                return(CompletionContains(dottedRule, origin));
            }

            var currentSymbol = dottedRule.PostDotSymbol;

            return(currentSymbol is NonTerminal
                       ? PredictionsContains(dottedRule, origin)
                       : ScansContains(dottedRule, origin));
        }
Exemple #5
0
        public EarleyItem NewState(DottedRule dottedRule, int origin, IForestNode parseNode = null)
        {
            if (dottedRule.IsComplete)
            {
                return(new CompletedState(dottedRule, origin, parseNode));
            }

            if (dottedRule.PostDotSymbol is NonTerminal)
            {
                return(new PredictionState(dottedRule, origin, parseNode));
            }

            return(new ScanState(dottedRule, origin, parseNode));
        }
Exemple #6
0
 public bool Contains(DottedRule rule, int origin)
 {
     return(this.lookup.TryGetValue(rule, out var origins) && origins.TryGetValue(origin, out var _));
 }
Exemple #7
0
 public PredictionState(DottedRule dottedRule, int origin, IForestNode parseNode)
     : base(dottedRule, origin, parseNode)
 {
 }
Exemple #8
0
 public DottedRule GetNext(DottedRule dottedRule)
 {
     return(Get(dottedRule.Production, dottedRule.Dot + 1));
 }
Exemple #9
0
 private bool ScansContains(DottedRule rule, int origin)
 {
     return(this.scans.Contains(rule, origin));
 }
Exemple #10
0
 private bool PredictionsContains(DottedRule rule, int origin)
 {
     return(this.predictions.Contains(rule, origin));
 }
Exemple #11
0
 private bool CompletionContains(DottedRule rule, int origin)
 {
     return(this.completions.Contains(rule, origin));
 }
Exemple #12
0
 protected override bool ThisEquals(EarleyItem other)
 {
     return(DottedRule.Equals(other.DottedRule) && Origin.Equals(other.Origin));
 }
Exemple #13
0
 public bool Contains(int location, DottedRule dottedRule, int origin)
 {
     return(GetEarleySet(location).Contains(dottedRule, origin));
 }
Exemple #14
0
 public CompletedState(DottedRule dottedRule, int origin, IForestNode parseNode)
     : base(dottedRule, origin, parseNode)
 {
 }