public override void Convert(iStateCreater <T> creater, T beginState, ref T endState, NDFA <T, char> ndfa)
        {
            T choiceOneBeginState = creater.Next();
            T choiceTwoBeginState = creater.Next();
            T choiceOneEndState   = default(T);
            T choiceTwoEndState   = default(T);

            //Create empty epsilon from begin to begin of the choices
            ndfa.AddTransition(beginState, choiceOneBeginState, ndfa.Epsilon);
            ndfa.AddTransition(beginState, choiceTwoBeginState, ndfa.Epsilon);

            choiceOne.Convert(creater, choiceOneBeginState, ref choiceOneEndState, ndfa);
            choiceTwo.Convert(creater, choiceTwoBeginState, ref choiceTwoEndState, ndfa);

            //Create empty epsilon from end of the coices to end state
            endState = creater.Next();
            ndfa.AddTransition(choiceOneEndState, endState, ndfa.Epsilon);
            ndfa.AddTransition(choiceTwoEndState, endState, ndfa.Epsilon);
        }
예제 #2
0
        public override void Convert(iStateCreater <T> creater, T beginState, ref T endState, NDFA <T, char> ndfa)
        {
            endState = creater.Next();

            if (loopMin == 0)
            {
                ndfa.AddTransition(beginState, endState, ndfa.Epsilon);
            }

            T beginLoopState = creater.Next();
            T endLoopState   = default(T);

            this.block.Convert(creater, beginLoopState, ref endLoopState, ndfa);

            //Epsilon from start to start loop
            ndfa.AddTransition(beginState, beginLoopState, ndfa.Epsilon);
            //Epsilon from end loop to start loop
            ndfa.AddTransition(endLoopState, beginLoopState, ndfa.Epsilon);
            //Epsilon from end loop to end state
            ndfa.AddTransition(endLoopState, endState, ndfa.Epsilon);
        }
예제 #3
0
        private NDFA <string, char> getNDFA()
        {
            NDFA <string, char> ndfa = new NDFA <string, char>(this.alphabetSource.GetTableArray(), 'e');

            foreach (DataGridViewRow dataRow in this.dgvTransitions.Rows)
            {
                if (dataRow.Cells[2].Value == null || dataRow.Cells[2].Value.ToString() == "")
                {
                    continue;
                }

                string from   = dataRow.Cells[0].Value.ToString();
                string to     = dataRow.Cells[1].Value.ToString();
                char   symbol = dataRow.Cells[2].Value.ToString().First();
                ndfa.AddTransition(from, to, symbol);
            }

            foreach (DataGridViewRow dataRow in this.dgvStates.Rows)
            {
                if (dataRow.Cells[0].Value == null || dataRow.Cells[0].Value.ToString() == "")
                {
                    continue;
                }

                string name       = dataRow.Cells[0].Value.ToString();
                bool   startState = (((dataRow.Cells[1]).Value == null) ? false : (bool)(dataRow.Cells[1]).Value);
                bool   endState   = (((dataRow.Cells[2]).Value == null) ? false : (bool)(dataRow.Cells[2]).Value);

                if (startState)
                {
                    ndfa.StartState = name;
                }
                if (endState)
                {
                    ndfa.EndStates.Add(name);
                }
            }

            if (!ndfa.IsMachineValid())
            {
                MessageBox.Show("Machine is not valid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }

            tsbToDFA.Enabled          = true;
            tsbToPng.Enabled          = true;
            tsbToRegram.Enabled       = true;
            tsbVerifyLanguage.Enabled = true;
            return(ndfa);
        }
예제 #4
0
 public override void Convert(iStateCreater <T> creater, T beginState, ref T endState, NDFA <T, char> grammar)
 {
     endState = creater.Next();
     grammar.AddTransition(beginState, endState, terminal);
 }