Example #1
0
 private void parseProgram(List <string> comandsList)
 {
     for (int i = 0; i < comands.Length; i++)
     {
         for (int j = 0; j < alphabit.Length; j++)
         {
             if (i == 0)
             {
                 ComandDescription newComand = new ComandDescription();
                 newComand.newState  = 0;
                 newComand.newSymbol = 0;
                 newComand.move      = moveType.none;
                 newComand.isEnd     = true;
                 programm[i, j]      = newComand;
             }
             else
             {
                 programm[i, j] = null;
             }
         }
     }
     foreach (var comand in comandsList)
     {
         string[]          comandsPut = comand.Split(new string[] { Constants.simpleArrow }, StringSplitOptions.None);
         string[]          fromData   = comandsPut[0].Split(new char[] { ' ' });
         string[]          toData     = comandsPut[1].Split(new char[] { ' ' });
         ComandDescription newComand  = new ComandDescription();
         newComand.newState  = comandIndex(toData[0]);
         newComand.newSymbol = alphabitIndex(toData[1]);
         newComand.isEnd     = false;
         newComand.move      = toData.Length == 2 ? moveType.none : ((toData[2]).Equals("R") ? moveType.right : moveType.left);
         programm[comandIndex(fromData[0]), alphabitIndex(fromData[1])] = newComand;
     }
 }
Example #2
0
        public bool nextStep()
        {
            ComandDescription currentStep = programm[currentMachineState,
                                                     alphabitIndex(type[zeroPosition + currentPosition])];

            if (currentStep == null)
            {
                //todo  add error sender
                return(false);
            }
            if (currentStep.isEnd)
            {
                //todo  add error sender
                return(false);
            }
            type.RemoveAt(zeroPosition + currentPosition);
            type.Insert(zeroPosition + currentPosition, alphabit[currentStep.newSymbol]);
            switch (currentStep.move)
            {
            case moveType.none:
                break;

            case moveType.left:
                currentPosition--;
                break;

            case moveType.right:
                currentPosition++;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            while ((zeroPosition + currentPosition) < 0)
            {
                type.Insert(0, Constants.emptyTuringSymbol);
                zeroPosition++;
            }
            while ((zeroPosition + currentPosition) >= type.Count)
            {
                type.Add(Constants.emptyTuringSymbol);
            }
            currentMachineState = currentStep.newState;
            if (MoveEvent != null)
            {
                MoveEvent(this, new TuringMoveEventArgs(type, zeroPosition + currentPosition, currentMachineState, alphabitIndex(type[zeroPosition + currentPosition])));
            }

            return(true);
        }
Example #3
0
 private void generateFormalProgram()
 {
     formalProgram             = new FormalTuringProgramm();
     formalProgram.alphabit    = alphabit;
     formalProgram.comandCount = comands.Length;
     formalProgram.comandTable = new string[comands.Length, alphabit.Length];
     formalProgram.comandsName = comands;
     for (int i = 0; i < comands.Length; i++)
     {
         for (int j = 0; j < alphabit.Length; j++)
         {
             ComandDescription programInstruction = programm[i, j];
             string            item;
             if (programInstruction == null)
             {
                 item = "none";
             }
             else
             {
                 item = comands[i] + " '" + alphabit[j] + "'->";
                 if (i > 0)
                 {
                     item += comands[programInstruction.newState] + " '" + alphabit[programInstruction.newSymbol] + "' ";
                     if (programInstruction.move != moveType.none)
                     {
                         item += programInstruction.move == moveType.right ? "R" : "L";
                     }
                 }
                 else
                 {
                     item += "exit";
                 }
             }
             formalProgram.comandTable[i, j] = item;
         }
     }
 }