コード例 #1
0
        public override Regexp Normalize()
        {
            var disj = GetDisjuncts();

            disj.Sort();
            Regexp re = null;

            foreach (var d in disj)
            {
                if (re == null)
                {
                    re = d.Normalize();
                }
                else
                {
                    re = new REUnion(d.Normalize(), re);
                }
            }

            if (re.GetDisjuncts().Count == disj.Count)
            {
                return(re);
            }
            else
            {
                return(re.Normalize());
            }
        }
コード例 #2
0
        public override Regexp Normalize()
        {
            var r1 = r.Normalize();

            Regexp dj = null;

            foreach (var d in r1.GetDisjuncts())
            {
                Regexp sol = null;
                if (!(d is REStar) && !(d is REPlus) && !(d is REQMark))
                {
                    sol = d;
                }
                else
                {
                    if (d is REStar)
                    {
                        var v = d as REStar;
                        sol = v.r;
                    }
                    else
                    {
                        if (d is REPlus)
                        {
                            var v = d as REPlus;
                            sol = v.r;
                        }
                        else
                        {
                            var v = d as REQMark;
                            sol = v.r;
                        }
                    }
                }
                if (dj == null)
                {
                    dj = sol;
                }
                else
                {
                    dj = new REUnion(sol, dj);
                }
            }
            if (dj.GetDisjuncts().Count != r.GetDisjuncts().Count)
            {
                return(new REStar(dj).Normalize());
            }

            return(new REStar(dj));
        }