Ejemplo n.º 1
0
        internal static Automaton MakeInterval(int min, int max, int digits)
        {
            var    a = new Automaton();
            string x = Convert.ToString(min, CultureInfo.CurrentCulture);
            string y = Convert.ToString(max, CultureInfo.CurrentCulture);

            if (min > max || (digits > 0 && y.Length > digits))
            {
                throw new ArgumentException();
            }

            int d  = digits > 0 ? digits : y.Length;
            var bx = new StringBuilder();

            for (int i = x.Length; i < d; i++)
            {
                bx.Append('0');
            }

            bx.Append(x);
            x = bx.ToString();
            var by = new StringBuilder();

            for (int i = y.Length; i < d; i++)
            {
                by.Append('0');
            }

            by.Append(y);
            y = by.ToString();
            ICollection <State> initials = new List <State>();

            a.Initial = BasicAutomata.Between(x, y, 0, initials, digits <= 0);
            if (digits <= 0)
            {
                List <StatePair> pairs = (from p in initials
                                          where a.Initial != p
                                          select new StatePair(a.Initial, p)).ToList();
                a.AddEpsilons(pairs);
                a.Initial.AddTransition(new Transition('0', a.Initial));
                a.IsDeterministic = false;
            }
            else
            {
                a.IsDeterministic = true;
            }

            a.CheckMinimizeAlways();
            return(a);
        }