示例#1
0
 private RegularLanguageNFAState Subtract(RegularLanguageNFAState left, RegularLanguageNFAState right)
 {
     /* *
      * Include the right-element where the left overlaps it;
      * however, every other point of the right-automation
      * is ignored.
      * * 
      * Where the left and right automation are at an edge
      * point, the automation does not yield an edge due to 
      * the exclusive nature of the operation.
      * */
     RegularLanguageNFAState result = new RegularLanguageNFAState();
     if (left.IsEdge)
     {
         if (right.IsEdge)
             result.ForcedNoEdge = true;
         else
             result.IsEdge = true;
     }
     foreach (var transition in left.OutTransitions.Keys)
     {
         IDictionary<RegularLanguageSet, IFiniteAutomataTransitionNode<RegularLanguageSet, List<RegularLanguageNFAState>>> colliders;
         RegularLanguageSet remainder = right.OutTransitions.GetColliders(transition, out colliders);
         if (!remainder.IsEmpty)
             foreach (var target in left.OutTransitions[transition])
                 result.MoveTo(remainder, target);
         foreach (var collision in colliders.Keys)
             foreach (var leftTarget in left.OutTransitions[transition])
                 foreach (var rightTarget in colliders[collision].Target)
                     result.MoveTo(collision, Subtract(leftTarget, rightTarget));
     }
     return result;
 }
        public void BuildState(Dictionary <ITokenSource, Captures.ICaptureTokenStructuralItem> sourceReplacementLookup)
        {
            var thisReplacement = sourceReplacementLookup.ContainsKey(this) ? (ITokenSource)(sourceReplacementLookup[this]) : (ITokenSource)this;
            var target          = (InlinedTokenExpressionSeries)this.SearchTarget;

            target.BuildState(sourceReplacementLookup);
            RegularLanguageNFAState         current = null;
            Stack <RegularLanguageNFAState> states  = new Stack <RegularLanguageNFAState>(new RegularLanguageNFAState[] { target.State });
            List <RegularLanguageNFAState>  covered = new List <RegularLanguageNFAState>();

            states.Peek().SetInitial(thisReplacement);
            //Step through the sequence until it's finished with the all states
            //associated to the scan operation.
            while (states.Count > 0)
            {
                current = states.Pop();
                if (covered.Contains(current))
                {
                    continue;
                }
                covered.Add(current);
                RegularLanguageSet currentSet = current.OutTransitions.FullCheck;
                if (!currentSet.IsEmpty)
                {
                    foreach (var transition in current.OutTransitions.Values)
                    {
                        foreach (var transitionTarget in transition)
                        {
                            if (!covered.Contains(transitionTarget))
                            {
                                states.Push(transitionTarget);
                            }
                        }
                    }
                    currentSet = currentSet.Complement();
                    if (!(currentSet.IsEmpty))
                    {
                        current.MoveTo(currentSet, target.State);
                    }
                }
            }
            state = target.State;
            List <RegularLanguageNFAState> flatline = new List <RegularLanguageNFAState>();

            RegularLanguageNFAState.FlatlineState(state, flatline);
            foreach (var fState in flatline)
            {
                fState.SetIntermediate(thisReplacement);
            }
            state.SetInitial(thisReplacement);
            foreach (var edge in State.ObtainEdges())
            {
                edge.SetFinal(thisReplacement);
            }
            state.HandleRepeatCycle <RegularLanguageSet, RegularLanguageNFAState, RegularLanguageDFAState, ITokenSource, RegularLanguageNFARootState, IInlinedTokenItem>(this, thisReplacement, OilexerGrammarInliningCore.TokenRootStateClonerCache, OilexerGrammarInliningCore.TokenStateClonerCache);
        }
        public void BuildState(Dictionary <ITokenSource, Captures.ICaptureTokenStructuralItem> sourceReplacementLookup)
        {
            var thisReplacement          = sourceReplacementLookup.ContainsKey(this) ? (ITokenSource)(sourceReplacementLookup[this]) : (ITokenSource)this;
            RegularLanguageNFAState root = new RegularLanguageNFAState();
            RegularLanguageNFAState next = new RegularLanguageNFAState();

            root.SetInitial(thisReplacement);
            root.MoveTo(this.Range, next);
            next.SetFinal(thisReplacement);
            root.HandleRepeatCycle <RegularLanguageSet, RegularLanguageNFAState, RegularLanguageDFAState, ITokenSource, RegularLanguageNFARootState, IInlinedTokenItem>(this, thisReplacement, OilexerGrammarInliningCore.TokenRootStateClonerCache, OilexerGrammarInliningCore.TokenStateClonerCache);
            this.state = root;
        }
 private static void Breakdown(RegularLanguageNFAState targetState, Dictionary <char, List <string> > currentSubsets, RegularLanguageNFAState[] endTargets, bool caseSensitive)
 {
     foreach (var c in currentSubsets.Keys)
     {
         var           currentSet = currentSubsets[c];
         var           transition = new RegularLanguageSet(caseSensitive, c);
         List <string> characters = null;
         Dictionary <char, List <string> > nextSubsets = new Dictionary <char, List <string> >();
         foreach (var str in currentSet)
         {
             if (str == string.Empty)
             {
                 foreach (var state in endTargets)
                 {
                     targetState.MoveTo(transition, state);
                 }
             }
             else
             {
                 char first = str[0];
                 if (!nextSubsets.ContainsKey(first))
                 {
                     nextSubsets.Add(first, characters = new List <string>());
                 }
                 string substr = str.Substring(1);
                 if (!characters.Contains(substr))
                 {
                     characters.Add(substr);
                 }
             }
         }
         if (nextSubsets.Count > 0)
         {
             var nextSubstate = new RegularLanguageNFAState();
             targetState.MoveTo(transition, nextSubstate);
             Breakdown(nextSubstate, nextSubsets, endTargets, caseSensitive);
         }
     }
 }