public static NFA_GRAPH Create_NFAKleeneClosure(NFA_GRAPH nfaGraph) { NFA_GRAPH newGraph = null; if (nfaGraph != null) { nfaGraph.startNode.nodeType = NODE_TYPE.TRANSITIONING; nfaGraph.endNode.nodeType = NODE_TYPE.TRANSITIONING; NODE startNode = NODE.CreateNode(NODE_TYPE.START); NODE endNode = NODE.CreateNode(NODE_TYPE.END); EDGE endEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, endNode); nfaGraph.endNode.edges.Add(endEdge); EDGE endToStartEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, nfaGraph.startNode); nfaGraph.endNode.edges.Add(endToStartEdge); EDGE newStartToStartEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, nfaGraph.startNode); startNode.edges.Add(newStartToStartEdge); EDGE newStartToNewEndEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, endNode); startNode.edges.Add(newStartToNewEndEdge); newGraph = new NFA_GRAPH(startNode, endNode); } return(newGraph); }
Create_NFAOneChar (char character) { NODE startNode = NODE.CreateNode(NODE_TYPE.START); NODE endNode = NODE.CreateNode(NODE_TYPE.END); EDGE edge = new EDGE(character, endNode); startNode.edges.Add(edge); NFA_GRAPH newGraph = new NFA_GRAPH(startNode, endNode); return(newGraph); }
public static NFA_GRAPH Create_NFAUnion(NFA_GRAPH graphOne, NFA_GRAPH graphTwo) { NFA_GRAPH newGraph = null; if (graphOne == null && graphTwo != null) { newGraph = graphTwo; } else if (graphOne != null && graphTwo == null) { newGraph = graphOne; } else if (graphOne != null && graphTwo != null) { NODE startNode = NODE.CreateNode(NODE_TYPE.START); NODE endNode = NODE.CreateNode(NODE_TYPE.END); graphOne.startNode.nodeType = NODE_TYPE.TRANSITIONING; graphTwo.startNode.nodeType = NODE_TYPE.TRANSITIONING; graphOne.endNode.nodeType = NODE_TYPE.TRANSITIONING; graphTwo.endNode.nodeType = NODE_TYPE.TRANSITIONING; EDGE startOneEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, graphOne.startNode); EDGE startTwoEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, graphTwo.startNode); startNode.edges.Add(startOneEdge); startNode.edges.Add(startTwoEdge); EDGE endOneEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, endNode); EDGE endTwoEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, endNode); graphOne.endNode.edges.Add(endOneEdge); graphTwo.endNode.edges.Add(endTwoEdge); newGraph = new NFA_GRAPH(startNode, endNode); } return(newGraph); }