Esempio n. 1
0
 private static void processFinishNode(DState state)
 {
     foreach (var node in state.Nodes)
     {
         if (node.Start.Outputs.Count == 0)
         {
             state.isFinishNode = true;
             break;
         }
     }
 }
Esempio n. 2
0
        private static bool IsStateInCollection(DState state, IEnumerable <DState> states)
        {
            bool ans = false;

            foreach (var sec in states)
            {
                if (IsEqualStates(state, sec))
                {
                    ans = true;
                    break;
                }
            }
            return(ans);
        }
Esempio n. 3
0
        private static DState EqualStateFromCollection(DState state, IEnumerable <DState> states)
        {
            DState ans = null;

            foreach (var sec in states)
            {
                if (IsEqualStates(state, sec))
                {
                    ans = sec;
                    break;
                }
            }
            return(ans);
        }
Esempio n. 4
0
        private static bool IsEqualStates(DState first, DState second)
        {
            bool equal = first.Nodes.Count == second.Nodes.Count;

            if (equal)
            {
                foreach (var node in first.Nodes)
                {
                    if (!second.Nodes.Contains(node))
                    {
                        equal = false;
                    }
                }
            }
            return(equal);
        }
Esempio n. 5
0
        private static DState Move(DState dState, char a)
        {
            DState res = new DState();

            //var epsState = EClosure(dState);
            foreach (var node in dState.Nodes)
            {
                foreach (var link in node.Start.Outputs)
                {
                    if (link.Subj == a)
                    {
                        res.AddNode(link.Destination);
                    }
                }
            }
            var epsState = EClosure(res);

            return(epsState);
        }
Esempio n. 6
0
        private static DState EClosure(DState dState)
        {
            Stack <Node> statesStack = new Stack <Node>();
            DState       res         = new DState();

            foreach (var node in dState.Nodes)
            {
                statesStack.Push(node);
                res.AddNode(node);
            }
            while (statesStack.Count > 0)
            {
                var state = statesStack.Pop();
                foreach (var link in state.Start.Outputs)
                {
                    if (link.Subj == Utils.eps && !res.Nodes.Contains(link.Destination))
                    {
                        res.AddNode(link.Destination);
                        statesStack.Push(link.Destination);
                    }
                }
            }
            return(res);
        }
Esempio n. 7
0
 public void Bind(DState next, char c)
 {
     GraphAutomat.Bind(this, next, c);
 }