Ejemplo n.º 1
0
        public static Automaton MakeCharSet(string set)
        {
            if (set.Length == 1)
            {
                return(MakeChar(set[0]));
            }

            var s1 = new State();
            var a  = new Automaton
            {
                Initial = s1,
            };
            var s2 = new State
            {
                Accept = true,
            };

            foreach (var t in set)
            {
                s1.Transitions.Add(new Transition(t, s2));
            }

            a.IsDeterministic = true;
            a.Reduce();

            return(a);
        }
Ejemplo n.º 2
0
        public static Automaton MakeStringUnion(params char[][] strings)
        {
            if (strings.Length == 0)
            {
                return(MakeEmpty());
            }

            Array.Sort(strings, new LexicographicComparer());
            var a = new Automaton
            {
                Initial         = StringUnionOperations.Build(strings),
                IsDeterministic = true,
            };

            a.Reduce();
            a.RecomputeHashCode();
            return(a);
        }