Ejemplo n.º 1
0
 private TransitionMap <State> Rename(TransitionMap <Set <State> > composites, Dictionary <Set <State>, State> map)
 {
     return(new TransitionMap <State>(
                composites.StateTransitions.Select(
                    compositeTransition => new TransitionCollection <State>(
                        map[compositeTransition.Source],
                        compositeTransition.Select(trasition => new Transition <State>(
                                                       map[trasition.Source],
                                                       map[trasition.Target],
                                                       trasition.Label))))));
 }
Ejemplo n.º 2
0
        private TransitionMap <Set <State> > CompsiteDfaTransitions()
        {
            var s0 = EpsilonClosure(Start);

            var workList = new Queue <Set <State> >();

            workList.Enqueue(s0);

            // The transition relation of the DFA
            var result = new TransitionMap <Set <State> >();

            while (workList.Count != 0)
            {
                var S = workList.Dequeue();

                if (result.Contains(S))
                {
                    continue;
                }

                // The S -lab-> T transition relation being constructed for a given S
                var STrans = new Dictionary <string, Set <State> >();

                // For all states in S, consider all transitions state-label -> target
                foreach (var state in S)
                {
                    foreach (var transition in this[state].Where(t => !(t.Label is null)))
                    {
                        if (!STrans.TryGetValue(transition.Label, out var toState))
                        {
                            STrans[transition.Label] = toState = new Set <State>();
                        }

                        toState.Add(transition.Target);
                    }
                }

                var STransClosure = new Dictionary <string, Set <State> >();
                foreach (var entry in STrans)
                {
                    var Tclose = EpsilonClosure(entry.Value);
                    STransClosure.Add(entry.Key, Tclose);
                    workList.Enqueue(Tclose);
                }

                foreach (var kvp in STransClosure)
                {
                    result.Add(S, kvp.Value, kvp.Key);
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
 public NFA(State start, State accept)
 {
     Start  = start;
     Accept = accept;
     store  = new TransitionMap <State>();
 }
Ejemplo n.º 4
0
 private Dictionary <Set <State>, State> RenamerMap(TransitionMap <Set <State> > composites) =>
 composites.States.ToDictionary(s => s, s => new State());
Ejemplo n.º 5
0
 public DFA(State start, Set <State> acceptingStates, TransitionMap <State> transitions)
 {
     Start           = start;
     AcceptingStates = acceptingStates;
     store           = transitions;
 }