Exemplo n.º 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));
        }
Exemplo n.º 2
0
 public bool AddAlphabet(char alphabet)
 {
     if (!Alphabets.Contains(alphabet))
     {
         Alphabets.Add(alphabet);
         return(true);
     }
     return(false);
 }
Exemplo n.º 3
0
 public bool RemoveAlphabet(char alphabet)
 {
     if (Alphabets.Contains(alphabet))
     {
         RemoveInstructionsInvolvingAlphabet(alphabet);
         Alphabets.Remove(alphabet);
         return(true);
     }
     return(false);
 }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 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);
 }