private E_CLOSURE_NODE Perform_MoveToOperation(E_CLOSURE_NODE eClosureNode, Dictionary <char, Stack <NODE> > moveToDictionary)
        {
            E_CLOSURE_NODE eClosureNode_it = Find_EClosureNode(eClosureNode);
            E_CLOSURE_NODE return_eClosureNode;

            if (eClosureNode_it != null)
            {
                eClosureNode.Delete();

                return_eClosureNode = eClosureNode_it;
            }
            else
            {
                eClosureNodes.Add(eClosureNode.NodeID, eClosureNode);

                foreach (KeyValuePair <char, Stack <NODE> > moveTo in moveToDictionary)
                {
                    EDGE newEClosureEdge = new EDGE(moveTo.Key, Get_EClosureNode(moveTo.Value));
                    eClosureNode.edges.Add(newEClosureEdge);
                }

                return_eClosureNode = eClosureNode;
            }

            return(return_eClosureNode);
        }
        private E_CLOSURE_NODE Find_EClosureNode(E_CLOSURE_NODE eClosureNode)
        {
            bool isEqual;

            foreach (KeyValuePair <int, E_CLOSURE_NODE> EClosureDicElement in eClosureNodes)
            {
                isEqual = true;

                if (EClosureDicElement.Value.NFANodes.Count == eClosureNode.NFANodes.Count)
                {
                    for (int i = 0; i < eClosureNode.NFANodes.Count; i++)
                    {
                        if (EClosureDicElement.Value.NFANodes[i].NodeID != eClosureNode.NFANodes[i].NodeID)
                        {
                            isEqual = false;
                        }
                    }
                }
                else
                {
                    isEqual = false;
                }
                if (isEqual)
                {
                    return(EClosureDicElement.Value);
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        public E_CLOSURE_NODE Get_EClosureNode(Stack <NODE> NFANodesStack)
        {
            E_CLOSURE_NODE eClosureNode = null;
            Dictionary <char, Stack <NODE> > moveToDictionary = new Dictionary <char, Stack <NODE> >();

            eClosureNode = Perform_EClosureOperation(NFANodesStack, moveToDictionary);
            eClosureNode = Perform_MoveToOperation(eClosureNode, moveToDictionary);

            return(eClosureNode);
        }
        private E_CLOSURE_NODE Perform_EClosureOperation(Stack <NODE> NFANodesStack, Dictionary <char, Stack <NODE> > moveToDictionary)
        {
            HashSet <NODE> visitedNodes     = new HashSet <NODE>();
            NODE           nodeUnderProcess = null;
            E_CLOSURE_NODE eClosureNode     = null;

            if (NFANodesStack.Count() != 0)
            {
                eClosureNode = E_CLOSURE_NODE.Create_Node(NODE_TYPE.TRANSITIONING);

                while (NFANodesStack.Count() != 0)
                {
                    nodeUnderProcess = NFANodesStack.Pop();

                    eClosureNode.NFANodes.Add(nodeUnderProcess);

                    if (nodeUnderProcess.nodeType == NODE_TYPE.END)
                    {
                        eClosureNode.nodeType = NODE_TYPE.END;
                    }

                    if (nodeUnderProcess.nodeType == NODE_TYPE.START)
                    {
                        eClosureNode.nodeType = NODE_TYPE.START;
                    }

                    foreach (EDGE edge in nodeUnderProcess.edges)
                    {
                        if (!visitedNodes.Contains(edge.nextNode))
                        {
                            visitedNodes.Add(edge.nextNode);

                            if (edge.transitionCharacter == CONSTANTS.EMPTY_SYMBOL)
                            {
                                NFANodesStack.Push(edge.nextNode);
                            }
                            else
                            {
                                if (!moveToDictionary.ContainsKey(edge.transitionCharacter))
                                {
                                    moveToDictionary.Add(edge.transitionCharacter, new Stack <NODE>());
                                }
                                moveToDictionary[edge.transitionCharacter].Push(edge.nextNode);
                            }
                        }
                    }
                }

                eClosureNode.NFANodes.OrderBy(NFANode => NFANode.NodeID);
            }

            return(eClosureNode);
        }
Ejemplo n.º 5
0
        public E_CLOSURE_GRAPH(NFA_GRAPH nfaGraph)
        {
            if (nfaGraph != null)
            {
                nodesStack = new Stack <NODE>();
                nodesStack.Push(nfaGraph.startNode);

                StartNode = Get_EClosureNode(nodesStack);
            }

            E_CLOSURE_NODE.ClearCount();
        }
Ejemplo n.º 6
0
        private void Get_DFAGraphFromEClosureGraph(E_CLOSURE_GRAPH eClosureGraph)
        {
            HashSet <E_CLOSURE_NODE> visitedNodes           = new HashSet <E_CLOSURE_NODE>();
            Stack <E_CLOSURE_NODE>   EClosureNodesToProcess = new Stack <E_CLOSURE_NODE>();
            Stack <NODE>             NodesToProcess         = new Stack <NODE>();

            E_CLOSURE_NODE eClosureNodeInProcess = null;
            NODE           node    = null;
            NODE           newNode = null;

            EClosureNodesToProcess.Push(eClosureGraph.StartNode);

            startNode = NODE.CreateNode(eClosureGraph.StartNode.nodeType, eClosureGraph.StartNode.NodeID);
            NodesToProcess.Push(startNode);

            while (EClosureNodesToProcess.Count != 0)
            {
                eClosureNodeInProcess = EClosureNodesToProcess.Pop();
                node = NodesToProcess.Pop();
                visitedNodes.Add(eClosureNodeInProcess);
                DFANodes.Add(node);

                foreach (EDGE edge in eClosureNodeInProcess.edges)
                {
                    if (!visitedNodes.Contains((E_CLOSURE_NODE)edge.nextNode))
                    {
                        newNode = NODE.CreateNode(edge.nextNode.nodeType, edge.nextNode.NodeID);
                    }
                    else
                    {
                        newNode = DFANodes.Find(findNode => findNode.NodeID == edge.nextNode.NodeID);
                    }
                    node.edges.Add(new EDGE(edge.transitionCharacter, newNode));

                    if (!visitedNodes.Contains((E_CLOSURE_NODE)edge.nextNode))
                    {
                        EClosureNodesToProcess.Push((E_CLOSURE_NODE)edge.nextNode);
                        NodesToProcess.Push(newNode);
                    }
                }
            }
        }