Example #1
0
        // return (R[i])(R[i+1])....(R[len-1])
        private RegEx <T> ConcatRegexes(int depth)
        {
            if (depth == Regexes.Length - 1)
            {
                return(Regexes [depth]);
            }

            return(RegExFactory.Concat(Regexes [depth], ConcatRegexes(depth + 1)));
        }
Example #2
0
        private static RegEx <char> ParseConcat()
        {
            var left = ParseStar();

            if (left == null)
            {
                return(null);
            }

            var right = ParseConcat();

            if (right != null)
            {
                return(RegExFactory.Concat(left, right));
            }

            return(left);
        }
Example #3
0
        private RegEx <T> ComputeDerivative(int depth, T c)
        {
            // the last one
            if (depth == Regexes.Length - 1)
            {
                return(Regexes[depth].Derivative(c));
            }

            // (R[i])^a(R[i+1])....
            var this_level = RegExFactory.Concat(
                Regexes [depth].Derivative(c),
                ConcatRegexes(depth + 1)
                );

            // first can be skipped
            if (Regexes [depth].HasEpsilon())
            {
                return(RegExFactory.Union(this_level, ComputeDerivative(depth + 1, c)));
            }

            // cannot be skipped
            return(this_level);
        }
Example #4
0
        private static RegEx <char> ParseStar()
        {
            var left = ParseAtom();

            if (HasPrefix("*") || HasPrefix("+"))
            {
                bool star = false;

                while (HasPrefix("*") || HasPrefix("+"))
                {
                    star |= HasPrefix("+");
                    Eat(1);
                }

                if (left == null)
                {
                    throw new ParseError("Unassigned +/-.");
                }

                return(star ? RegExFactory.Concat(left, RegExFactory.Star(left)) : RegExFactory.Star(left));
            }

            return(left);
        }
Example #5
0
 // star(X)^a = concat(X^a, star(X))
 public override RegEx <T> Derivative(T c)
 {
     return(RegExFactory.Concat(Regex.Derivative(c), RegExFactory.Star(Regex)));
 }