public void ChartEnqueShouldAvoidDuplication() { ProductionExpression L = "L"; var aToZ = new RangeTerminal('a', 'z'); L.Rule = L + aToZ | aToZ; var grammar = new GrammarExpression(L, new[] { L }).ToGrammar(); var chart = new Chart(); var firstState = new NormalState(grammar.Productions[0], 0, 1); var secondState = new NormalState(grammar.Productions[0], 0, 1); chart.Enqueue(0, firstState); chart.Enqueue(0, secondState); Assert.AreEqual(1, chart.EarleySets[0].Predictions.Count); }
public void Test_Chart_That_Enqueue_Avoids_Duplicates() { var grammar = new GrammarBuilder("L") .Production("L", r => r .Rule("L", new RangeTerminal('a', 'z')) .Rule(new RangeTerminal('a','z'))) .ToGrammar(); var chart = new Chart(); var firstState = new State(grammar.Productions[0], 0, 1); var secondState = new State(grammar.Productions[0], 0, 1); chart.Enqueue(0, firstState); chart.Enqueue(0, secondState); Assert.AreEqual(1, chart.EarleySets[0].Predictions.Count); }
private void Initialize() { Location = 0; _chart = new Chart(); foreach (var startProduction in Grammar.StartProductions()) { var startState = new NormalState(startProduction, 0, 0); if (_chart.Enqueue(0, startState)) Log("Start", 0, startState); } ReductionPass(Location); }