示例#1
0
 public OutputWindow(DFABuilder dfaBuilder, bool stepByStepMode)
 {
     InitializeComponent();
     _dfa = dfaBuilder.Dfa;
     if (_dfa.States.Count >= 25)
     {
         MessageBox.Show("Warning! There are more than 25 states generated. The proper working of the application is not guaranteed.");
     }
     _mainViewModel = new MainViewModel();
     _dfaBuilder = dfaBuilder;
     this.DataContext = _mainViewModel;
     _steps = dfaBuilder.Steps;
     if (stepByStepMode)
     {
         btnNextStep.IsEnabled = true;
     }
     else
     {
         btnNextStep.IsEnabled = false;
         generateContentDot(_steps.Count);
         BitmapImage bmp = dot2bmp(_beginDot + _contentDot + _endDot);
         imgGraph.Source = bmp;
         foreach (Transition t in _dfa.Transitions)
         {
             _mainViewModel.Transitions.Add(t);
         }
         foreach (State s in _dfa.States)
         {
             _mainViewModel.Labels.Add(Tuple.Create(s.QLabel, s.RegexLabel));
         }
     }
 }
示例#2
0
 public SimulationWindow(DFABuilder dfaBuilder)
 {
     InitializeComponent();
     _dfaBuilder = dfaBuilder;
     _dfa = _dfaBuilder.Dfa;
     _steps = _dfaBuilder.Steps;
     this.DataContext = new MainViewModel(_dfa);
 }
示例#3
0
        public void buildDFA(string re)
        {
            Dfa = new DFA(new RegularExpression(re));
            var newStates = new HashSet<State>();
            var newTransitions = new List<Transition>();
            var newSteps = new List<Step>();

            int added = 0;
            do
            {
                added = 0;
                newStates.Clear();
                newTransitions.Clear();
                newSteps.Clear();
                foreach (State state in Dfa.States)
                {
                    foreach (char c in Dfa.Alphabet)
                    {
                        RegularExpression newRegEx = Derive(new RegularExpression(state.RegexLabel), c);
                        State newState = null;
                        newState = new State(newRegEx, IsExpressionFinal(newRegEx));
                        newStates.Add(newState);
                        newTransitions.Add(new Transition(state.RegexLabel, newState.RegexLabel, c));
                        Step newStep = new Step(state, newState, c);
                        newSteps.Add(newStep);
                    }
                }

                foreach (State state in newStates)
                {
                    bool hasSubstring = false;
                    foreach (State s1 in Dfa.States)
                    {
                        if(state.RegexLabel.Contains(s1.RegexLabel) && state.RegexLabel != s1.RegexLabel)
                        {
                            hasSubstring = true;
                            break;
                        }
                    }
                    State equivalent = null;
                    if (hasSubstring)
                    {
                        var testWindow = new UserInteraction(state.RegexLabel, Dfa.States);
                        if (testWindow.ShowDialog() == false)
                        {
                            equivalent = testWindow.GetSelectedState();
                        }
                        if (equivalent == null)
                        {
                            if (Dfa.addState(state))
                            {
                                added++;
                            }
                        }
                        else
                        {
                            // update transitions
                            foreach (Transition t in Dfa.Transitions)
                            {
                                if (t.From == state.RegexLabel)
                                    t.From = equivalent.RegexLabel;
                                if (t.To == state.RegexLabel)
                                    t.To = equivalent.RegexLabel;
                            }
                            foreach (Transition t in newTransitions)
                            {
                                if (t.From == state.RegexLabel)
                                    t.From = equivalent.RegexLabel;
                                if (t.To == state.RegexLabel)
                                    t.To = equivalent.RegexLabel;
                            }
                            //update steps
                            foreach (Step step in Steps)
                            {
                                if (step.From.RegexLabel == state.RegexLabel)
                                    step.From.RegexLabel = equivalent.RegexLabel;
                                if (step.To.RegexLabel == state.RegexLabel)
                                    step.To.RegexLabel = equivalent.RegexLabel;
                            }
                            foreach (Step step in newSteps)
                            {
                                if (step.From.RegexLabel == state.RegexLabel)
                                    step.From.RegexLabel = equivalent.RegexLabel;
                                if (step.To.RegexLabel == state.RegexLabel)
                                    step.To.RegexLabel = equivalent.RegexLabel;
                            }
                            if (Dfa.addState(equivalent))
                            {

                                added++;
                            }
                        }
                    }
                    if (Dfa.addState(state))
                    {

                        added++;
                    }
                }
                foreach (Transition t in newTransitions)
                {
                    bool isTransitionAlreadyPresent = false;

                    foreach (Transition t1 in Dfa.Transitions)
                    {
                        if (t1.From == t.From && t1.To == t.To && t.Over == t1.Over)
                        {
                            isTransitionAlreadyPresent = true;
                            break;
                        }
                    }

                    if (isTransitionAlreadyPresent)
                        continue;
                    Dfa.Transitions.Add(t);
                }

                foreach (Step step in newSteps)
                {

                    bool isStepAlreadyPresent = false;

                    foreach (Step s1 in Steps)
                    {
                        if (step.From.RegexLabel == s1.From.RegexLabel && step.To.RegexLabel == s1.To.RegexLabel && step.Over == s1.Over)
                        {
                            isStepAlreadyPresent = true;
                            break;
                        }
                    }

                    if (isStepAlreadyPresent)
                        continue;
                    Steps.Add(step);
                }

            } while (added != 0);
        }
示例#4
0
 public MainViewModel(DFA dfa)
 {
     foreach (Transition t in dfa.Transitions)
     {
         _transitions.Add(t);
     }
     foreach(State s in dfa.States)
     {
         _labels.Add(Tuple.Create(s.QLabel, s.RegexLabel));
     }
 }