Exemple #1
0
        public override void Convert(iStateCreater <T> creater, T beginState, ref T endState, NDFA <T, char> grammar)
        {
            T leftEndState = default(T);

            left.Convert(creater, beginState, ref leftEndState, grammar);
            right.Convert(creater, leftEndState, ref endState, grammar);
        }
Exemple #2
0
 public Regex(char[] alphabet, string regex, iStateCreater <T> stateCreater)
     : base(alphabet)
 {
     this.Root = this.readString(regex);
     if (this.Root == null)
     {
         throw new ArgumentException("Regex is not valid", "regex");
     }
     this.StateCreater = stateCreater;
 }
        public override void Convert(iStateCreater <T> creater, T beginState, ref T endState, NDFA <T, char> ndfa)
        {
            T choiceOneBeginState = creater.Next();
            T choiceTwoBeginState = creater.Next();
            T choiceOneEndState   = default(T);
            T choiceTwoEndState   = default(T);

            //Create empty epsilon from begin to begin of the choices
            ndfa.AddTransition(beginState, choiceOneBeginState, ndfa.Epsilon);
            ndfa.AddTransition(beginState, choiceTwoBeginState, ndfa.Epsilon);

            choiceOne.Convert(creater, choiceOneBeginState, ref choiceOneEndState, ndfa);
            choiceTwo.Convert(creater, choiceTwoBeginState, ref choiceTwoEndState, ndfa);

            //Create empty epsilon from end of the coices to end state
            endState = creater.Next();
            ndfa.AddTransition(choiceOneEndState, endState, ndfa.Epsilon);
            ndfa.AddTransition(choiceTwoEndState, endState, ndfa.Epsilon);
        }
Exemple #4
0
        public override void Convert(iStateCreater <T> creater, T beginState, ref T endState, NDFA <T, char> ndfa)
        {
            endState = creater.Next();

            if (loopMin == 0)
            {
                ndfa.AddTransition(beginState, endState, ndfa.Epsilon);
            }

            T beginLoopState = creater.Next();
            T endLoopState   = default(T);

            this.block.Convert(creater, beginLoopState, ref endLoopState, ndfa);

            //Epsilon from start to start loop
            ndfa.AddTransition(beginState, beginLoopState, ndfa.Epsilon);
            //Epsilon from end loop to start loop
            ndfa.AddTransition(endLoopState, beginLoopState, ndfa.Epsilon);
            //Epsilon from end loop to end state
            ndfa.AddTransition(endLoopState, endState, ndfa.Epsilon);
        }
Exemple #5
0
 public override void Convert(iStateCreater <T> creater, T beginState, ref T endState, NDFA <T, char> grammar)
 {
     endState = creater.Next();
     grammar.AddTransition(beginState, endState, terminal);
 }
 public abstract void Convert(iStateCreater <T> creater, T beginState, ref T endState, NDFA <T, char> grammar);
Exemple #7
0
 public Regex(char[] alphabet, RegularExpressionPart <T> root, iStateCreater <T> stateCreater)
     : base(alphabet)
 {
     this.Root         = root;
     this.StateCreater = stateCreater;
 }