Beispiel #1
0
 internal void removeDigrams(HashSet <Digram> removedDigrams)
 {
     foreach (var digram in removedDigrams)
     {
         if (!FirstOccurances.ContainsKey(digram))
         {
             continue;
         }
         //Debug.Assert(!FirstOccurances[digram].IsRule);
         if (!FirstOccurances[digram].IsRule)
         {
             FirstOccurances.Remove(digram);
         }
     }
 }
Beispiel #2
0
        internal OverlapInfo NonOverlappingOccurenceFound(LinkedListNode <Symbol> linkedListNode)
        {
            var digram = new Digram(linkedListNode);

            if (!FirstOccurances.ContainsKey(digram))
            {
                return(OverlapInfo.NotFound);
            }

            var foundEntry = FirstOccurances[digram];

            if (this.RuleAnchors.ContainsKey(linkedListNode.List) && this.RuleAnchors[linkedListNode.List].Rule == foundEntry.Rule)
            {
                return(OverlapInfo.Overlaps);
            }

            return(foundEntry.Overlaps(linkedListNode) ? OverlapInfo.Overlaps : OverlapInfo.Found);
        }
Beispiel #3
0
        internal RecursionPoint setRule(LinkedListNode <Symbol> linkedListNode, Rule rule)
        {
            RecursionPoint todo = new RecursionPoint();

            var adigramEntry = new DigramEntry(linkedListNode);
            var olddigram    = new Digram(linkedListNode.List.First);

            {
                var prev = adigramEntry.StartPoint.Previous;
                if (prev != null)
                {
                    todo.RemovedDigrams.Add(new Digram(prev));
                }

                var next = adigramEntry.StartPoint.Next;
                if (next != null && next.Next != null)
                {
                    todo.RemovedDigrams.Add(new Digram(next));
                }
            }

            adigramEntry.Rule = rule;



            var symbolpntr = rule.Symbols.First;

            bool substituted = false;

            while (symbolpntr != null)
            {
                var symbol = symbolpntr.Value;
                if (!symbol.IsTerminal)
                {
                    Rule pointedRule = (symbol as RuleInstance).Content;
                    pointedRule.deuse();

                    if (pointedRule.Count <= 1)
                    {
                        Debug.Assert(pointedRule.ID != rule.ID);
                        Debug.Print("substituting a rule:" + pointedRule.ID);
                        Debug.Print("into a rule:" + rule.ID);

                        substituted = true;

                        todo.DigramsToCheck.Add(symbolpntr.Previous);


                        var digram = new Digram(pointedRule.Symbols.First);
                        if (FirstOccurances.ContainsKey(digram))
                        {
                            FirstOccurances.Remove(digram);
                        }

                        if (RuleAnchors.ContainsKey(pointedRule.Symbols))
                        {
                            RuleAnchors.Remove(pointedRule.Symbols);
                        }

                        var movedsymbol = pointedRule.Symbols.First;
                        while (movedsymbol != null)
                        {
                            var next = movedsymbol.Next;
                            symbolpntr.List.AddBefore(symbolpntr, movedsymbol.Value);
                            todo.DigramsToCheck.Add(symbolpntr.Previous);
                            movedsymbol = next;
                        }
                        symbolpntr = symbolpntr.Previous;
                        rule.Symbols.Remove(symbolpntr.Next);
                    }
                }
                symbolpntr = symbolpntr.Next;
            }

            if (substituted)
            {
                Debug.Print("Removing old substitute rule " + olddigram.ToString());
                this._FirstOccurances.Remove(olddigram);
                todo.DigramsToCheck.Add(adigramEntry.StartPoint.Previous);
                todo.DigramsToCheck.Add(adigramEntry.StartPoint);
            }
            else
            {
                if (adigramEntry.StartPoint.List.First.Next == adigramEntry.StartPoint.List.Last &&
                    this.RuleAnchors.ContainsKey(adigramEntry.StartPoint.List))
                {
                    Debug.Print("refreshin a substitute rule:" + adigramEntry.ToString() + " -> " + this.RuleAnchors[adigramEntry.StartPoint.List].ToString());
                    this.FirstOccurances[new Digram(adigramEntry.StartPoint)] = this.RuleAnchors[adigramEntry.StartPoint.List];
                }
                else
                {
                    todo.DigramsToCheck.Add(adigramEntry.StartPoint.Previous);
                    todo.DigramsToCheck.Add(adigramEntry.StartPoint);
                }
            }

            return(todo);
        }