コード例 #1
0
ファイル: NFA.cs プロジェクト: JonathanHiggs/BnfParser
        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);
        }
コード例 #2
0
ファイル: NFA.cs プロジェクト: JonathanHiggs/BnfParser
 public void AddTransition(State source, State target, string label) =>
 store.Add(source, target, label);