Exemplo n.º 1
0
        Graph ProcessOperation(Graph initGraph, Operation op, Stack<Word> opStack)
        {
            // create base graph if not done already.
            if(initGraph == null){
                //start of our graph
                initGraph = Graph.CreateNewGraph(opStack.Pop());
            }

            //if kleene operation, do it here.
            if (op.Mapping == OperationType.Kleene) {
                initGraph = initGraph.Kleene ();
            }

            //now process each operation
            while(opStack.Count != 0){
                //get next letter to work with.
                var wordToAdd = opStack.Pop();

                //depending on the mapped type, do operation on graph
                //with the new letter.
                if(op.Mapping == OperationType.Concat)
                    initGraph = initGraph.Concat(wordToAdd);
                else if(op.Mapping == OperationType.Union)
                    initGraph = initGraph.Union(wordToAdd);
            }

            //return the created graph.
            return initGraph;
        }
Exemplo n.º 2
0
            public void NewInitialShouldBeFinal()
            {
                var m1Start = new GraphState () {
                    IsFinal = true
                };

                var m1 = new Graph () {
                    StartState = m1Start
                };

                var ndfa = m1.Kleene ();
                ndfa.StartState.IsFinal.Should ().BeTrue ();
            }
Exemplo n.º 3
0
            public void StateNumbersCorrect()
            {
                var m1 = new Graph () {
                    StartState =  new GraphState () {
                        IsFinal = false,
                        StateNumber = 0
                    }
                };

                m1.StartState.Out.Add (new GraphStateConnection () {
                    ConnectedBy = new Word('a'),
                    Start = m1.StartState,
                    End = new GraphState() {
                        StateNumber = 1
                    }
                });

                var ndfa = m1.Kleene ();
                ndfa.StartState.Out [0].End.StateNumber.Should ().Be (0);
                ndfa.StartState.Out [0].End.Out[0].End.StateNumber.Should ().Be (1);
                ndfa.StartState.StateNumber.Should ().Be (2);
            }
Exemplo n.º 4
0
            public void HasLoopConnection()
            {
                var m1Start = new GraphState () {
                    IsFinal = true
                };

                var m1 = new Graph () {
                    StartState = m1Start
                };

                var ndfa = m1.Kleene();
                var self = ndfa.StartState.Out [0].End.Out [0].End;
                self.Should ().Be (ndfa.StartState);
            }