Exemple #1
0
        public static NFA AnyOf(NFA left, NFA right)
        {
            var result = new NFA();

            result.AddState(0, false);
            result.AddTransition(0, result.Add(left), Epsilon);
            result.AddTransition(0, result.Add(right), Epsilon);
            return(result);
        }
Exemple #2
0
        public static NFA Concat(NFA left, NFA right)
        {
            var result = new NFA();

            result.Add(left);

            var leftFinals = result.final.ToArray();

            result.final.Clear();

            int rightInitial = result.Add(right);

            foreach (var final in leftFinals)
            {
                result.AddTransition(final, rightInitial, Epsilon);
            }
            return(result);
        }
Exemple #3
0
        public static NFA Star(NFA input)
        {
            var result = new NFA();

            var newFinal = result.NewState();

            result.AddState(newFinal, true);

            var start  = result.Add(input);
            var finals = result.final.Where(h => h != newFinal).ToArray();

            foreach (var final in finals)
            {
                result.AddTransition(final, start, Epsilon);
            }
            result.AddTransition(newFinal, start, Epsilon);

            return(result);
        }