コード例 #1
0
        private NDFA <string> Dot(RegEx expression, NDFA <string> automata, ref int stateCounter)
        {
            Convert(expression.leftExp, automata, ref stateCounter);
            Convert(expression.rightExp, automata, ref stateCounter);

            return(automata);
        }
コード例 #2
0
        private NDFA <string> Or(RegEx expression, NDFA <string> automata, ref int stateCounter)
        {
            int firstState  = stateCounter + 1;
            int secondState = stateCounter + 2;

            int startState = stateCounter;

            stateCounter++;

            automata.addTransition(new Transition <string>(startState.ToString(), '$', stateCounter.ToString()));
            Convert(expression.leftExp, automata, ref stateCounter);

            int endFirst = stateCounter;

            stateCounter++;
            automata.addTransition(new Transition <string>(startState.ToString(), '$', stateCounter.ToString()));
            Convert(expression.rightExp, automata, ref stateCounter);

            int endSecond = stateCounter;

            stateCounter++;
            automata.addTransition(new Transition <string>(endFirst.ToString(), '$', stateCounter.ToString()));
            automata.addTransition(new Transition <string>(endSecond.ToString(), '$', stateCounter.ToString()));

            return(automata);
        }
コード例 #3
0
        public RegEx Star()
        {
            RegEx result = new RegEx();

            result.op      = Operator.STAR;
            result.leftExp = this;
            return(result);
        }
コード例 #4
0
        public RegEx Plus()
        {
            RegEx result = new RegEx();

            result.op      = Operator.PLUS;
            result.leftExp = this;
            return(result);
        }
コード例 #5
0
        public static RegEx getExample1()         //aaa of bba
        {
            RegEx exp1 = new RegEx("aaa");
            RegEx exp2 = new RegEx("bba");
            RegEx exp3 = exp1.Or(exp2);

            return(exp3);
        }
コード例 #6
0
        public static RegEx getExample4()
        {
            RegEx exp1 = new RegEx("aaa");
            RegEx exp2 = new RegEx("bba");
            RegEx exp3 = exp1.Dot(exp2.Star());

            return(exp3);
        }
コード例 #7
0
        public RegEx Dot(RegEx exp2)
        {
            RegEx result = new RegEx();

            result.op       = Operator.DOT;
            result.leftExp  = this;
            result.rightExp = exp2;
            return(result);
        }
コード例 #8
0
        private NDFA <string> One(RegEx expression, NDFA <string> automata, ref int stateCounter)
        {
            foreach (char characther in expression.exp)
            {
                automata.addTransition(new Transition <string>(stateCounter.ToString(), characther, (stateCounter + 1).ToString()));
                stateCounter++;
            }

            return(automata);
        }
コード例 #9
0
        public static RegEx getExample2()         //begind met bbaba of een of meerdere keren aa gevolgd 0 of meerdere keren bba
        {
            RegEx exp1 = new RegEx("bbaba");
            RegEx exp2 = new RegEx("aa");
            RegEx exp3 = new RegEx("bba");
            RegEx exp4 = exp1.Or(exp2.Plus());
            RegEx exp5 = exp4.Dot(exp4.Star());

            return(exp5);
        }
コード例 #10
0
        public static RegEx getExample3()
        {
            RegEx exp1 = new RegEx("ababa");
            RegEx exp2 = new RegEx("baba");
            RegEx exp3 = exp1.Dot(exp2);
            RegEx exp4 = new RegEx("aaa");
            RegEx exp5 = new RegEx("bb");
            RegEx exp6 = exp4.Or(exp3.Plus());
            RegEx exp7 = exp6.Dot(exp6.Plus());

            return(exp7);
        }
コード例 #11
0
 public bool Equals(RegEx other)
 {
     if (other == null)
     {
         return(false);
     }
     else if (this.ToString() == other.ToString() && this.exp == other.exp && this.op == other.op && this.leftExp == other.leftExp && this.rightExp == other.rightExp)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #12
0
        private NDFA <string> Plus(RegEx expression, NDFA <string> automata, ref int stateCounter)
        {
            int startState = stateCounter;

            stateCounter++;
            int secondState = stateCounter;

            automata.addTransition(new Transition <string>(startState.ToString(), '$', secondState.ToString()));

            Convert(expression.leftExp, automata, ref stateCounter);

            automata.addTransition(new Transition <string>(stateCounter.ToString(), '$', secondState.ToString()));
            automata.addTransition(new Transition <string>(stateCounter.ToString(), '$', (stateCounter + 1).ToString()));
            stateCounter++;


            return(automata);
        }
コード例 #13
0
        private NDFA <string> Convert(RegEx expression, NDFA <string> automata, ref int stateCounter)
        {
            switch (expression.op)
            {
            case Operator.ONE:
                return(One(expression, automata, ref stateCounter));

            case Operator.OR:
                return(Or(expression, automata, ref stateCounter));

            case Operator.DOT:
                return(Dot(expression, automata, ref stateCounter));

            case Operator.STAR:
                return(Star(expression, automata, ref stateCounter));

            case Operator.PLUS:
                return(Plus(expression, automata, ref stateCounter));
            }
            return(null);
        }