Beispiel #1
0
        public bool hasCorrectInput(string input)
        {
            // get initial state
            var current = InitialState;

            // loop to get next state
            foreach (char c in input)
            {
                if (current == null)
                {
                    return(false);
                }

                if (!Alphabets.Contains(c))
                {
                    throw new ArgumentException("Character is not in alphabet list!");
                }
                else
                {
                    current = Table.GetNextStates(current, c);
                }
            }

            // check if the current state is final
            return(isFinalState(current));
        }
 public bool AddAlphabet(char alphabet)
 {
     if (!Alphabets.Contains(alphabet))
     {
         Alphabets.Add(alphabet);
         return(true);
     }
     return(false);
 }
 public bool RemoveAlphabet(char alphabet)
 {
     if (Alphabets.Contains(alphabet))
     {
         RemoveInstructionsInvolvingAlphabet(alphabet);
         Alphabets.Remove(alphabet);
         return(true);
     }
     return(false);
 }
 public bool RemoveInstruction(Instruction instruction)
 {
     if (States.Contains(instruction.CurrentState) && States.Contains(instruction.NextState) && Alphabets.Contains(instruction.Input))
     {
         if (Instructions.Contains(instruction))
         {
             Instructions.Remove(instruction);
             return(true);
         }
         return(false);
     }
     return(false);
 }
 public override bool AddInstruction(Instruction instruction)
 {
     if (States.Contains(instruction.CurrentState) && States.Contains(instruction.NextState) && Alphabets.Contains(instruction.Input))
     {
         if (!Instructions.Contains(instruction))
         {
             Instructions.Add(instruction);
             return(true);
         }
         return(false);
     }
     return(false);
 }