Exemplo n.º 1
0
        private bool rejected;                  //	True if the input string was rejected

        #endregion

        

        ///////////////////////////////////
        // Constructor. Takes a string argument which is the general name of
        // the definition Turing Machine Definition without any file extensions.
        // Both the definition file and the input string file must have this same
        // exact name with .def and .str extensions respectively.
        ///////////////////////////////////
        public TuringMachine(string definitionfilename)
        {
            initial_state = "";
	        current_state = "";
	        original_input_string = "";
	        number_of_transitions = 0;
	        valid = false;
	        used = false;
	        operating = false;
	        accepted = false;
	        rejected = false;

            tape = new Tape();
            final_states = new FinalStates();
            input_alphabet = new InputAlphabet();
            states = new States();
            tape_alphabet = new TapeAlphabet();
            transition_function = new TransitionFunction();

	        if(loadDefinition(definitionfilename + ".def")) 
            {
		        // Additional Setup
	        } 
            else 
            {
//		        Exit(1);
	        }
        }
Exemplo n.º 2
0
        ///////////////////////////////////////////////////////////////
        //Test method:              CheckForDuplicateStates
        //Test ID:                  5.2.1
        ///////////////////////////////////////////////////////////////
        public void ParseDefinition_CheckForDuplicateStates()
        {
            List<string> definition = new List<string>()
            {
                "S1 S1",
                "INPUT_ALPHABET:"
            };

            States test_state = new States();

            Assert.IsFalse(test_state.load(ref definition), "Failed to detect duplicate states.");
        }
Exemplo n.º 3
0
        public void ParseDefinition_CheckCaseSensitivityForStates()
        {
            List<string> definition = new List<string>()
            {
                "state1 STATE1",
                "INPUT_ALPHABET:"
            };

            States test_state = new States();
            test_state.load(ref definition);
            Assert.IsTrue(test_state.is_element("state1"));
            Assert.IsTrue(test_state.is_element("STATE1"));
        }
Exemplo n.º 4
0
        public void ParseDefinition_TransFunct_InvalidChar()
        {
            List<string> definition = new List<string>() 
            {
                "description stuff1",
                "description stuff2",
                "STATES: S1 S2 S3 S4",
                "INPUT_ALPHABET: a b",
                "TAPE_ALPHABET: a b x y -",
                "TRANSITION_FUNCTION:",
                "s0 a   s1 X R",
                "s0 Y   s3 Y R",
                "s1 a   s1 a R",
                "s1 b   s2 Y L",
                "s1 Y   s1 Y R", 
                "s2 a   s2 a L",
                "s2 X   s0 X R",
                "s2 Y   s2 Y L",
                "s3 Y   s3 Y R",
                "s3 -   s4 - R",
                "INITIAL_STATE: s0",
                "BLANK_CHARACTER: -",
                "FINAL_STATES: s4"
            };
            Tape tape = new Tape();
            FinalStates final_states = new FinalStates();
            InputAlphabet input_alphabet = new InputAlphabet();
            States states = new States();
            TapeAlphabet tape_alphabet = new TapeAlphabet();
            TransitionFunction transition_function = new TransitionFunction();
            TuringMachine tm = new TuringMachine("");

            Assert.IsTrue(tm.parseDescription(ref definition), "Failed to parse description");
            Assert.IsTrue(states.load(ref definition), "Failed to parse states.");
            Assert.IsTrue(input_alphabet.load(ref definition), "Failed to parse input alphabet");
            Assert.IsTrue(tape_alphabet.load(ref definition), "Failed to parse tape alphabet");
            Assert.IsFalse(transition_function.load(ref definition), "Should not accept transition with a state not in STATES:");

        }
Exemplo n.º 5
0
        public void ParseDefinition_CheckForAtLeastOneState()
        {
            List<string> definition = new List<string>()
            {
                "",
                "INPUT_ALPHABET:"
            };

            States test_state = new States();

            Assert.IsFalse(test_state.load(ref definition), "Failed to detect null states in definition file.");

        }
Exemplo n.º 6
0
 public void ParseDefinition_InvalidStates()
 {
     List<string> definition = new List<string>() 
     {
         " ",
         "INPUT_ALPHABET: a b",      // Need to have next keyword so it's detected
     };
     States states = new States();
     Assert.IsFalse(states.load(ref definition), "Should fail to parse states.");
 }
Exemplo n.º 7
0
 public void ParseDefinition_ValidStates()
 {
     List<string> definition = new List<string>() 
     {
         //"description stuff1",
         //"description stuff2",     // Assume definition was already extracted
         "STATES: S1 S2 S3 S4",
         "INPUT_ALPHABET: a b",      // Need to have next keyword so it's detected
         //"TAPE_ALPHABET: a b x y -",
         //"TRANSITION_FUNCTION:",
         //"s0 a   s1 X R",
         //"s0 Y   s3 Y R",
         //"s1 a   s1 a R",
         //"s1 b   s2 Y L",
         //"s1 Y   s1 Y R", 
         //"s2 a   s2 a L",
         //"s2 X   s0 X R",
         //"s2 Y   s2 Y L",
         //"s3 Y   s3 Y R",
         //"s3 -   s4 - R",
         //"INITIAL_STATE: s0",
         //"BLANK_CHARACTER: -",
         //"FINAL_STATES: s4"
     };
     States states = new States();
     Assert.IsTrue(states.load(ref definition), "Failed to parse states.");
     Assert.IsTrue(states.is_element("S1"), "S1 not found");
     Assert.IsTrue(states.is_element("S2"), "S2 not found");
     Assert.IsTrue(states.is_element("S3"), "S3 not found");
     Assert.IsTrue(states.is_element("S4"), "S4 not found");
 }
Exemplo n.º 8
0
        public void ParseDefinition_CheckForValidStateCharacters()
        {
            List<string> definition = new List<string>()
            {
                "$",
                "INPUT_ALPHABET:"
            };

            States test_state = new States();

            Assert.IsFalse(test_state.load(ref definition), "Failed to detect invalid input alphabet character.");
        }
Exemplo n.º 9
0
        public void ParseDefinition_BlankChar_NotInAlphabet()
        {
            List<string> definition = new List<string>() 
            {
                "a b x y -",
                "TRANSITION_FUNCTION:",
                "s0 a   s1 X R",
                "s0 Y   s3 Y R",
                "s1 a   s1 a R",
                "s1 b   s2 Y L",
                "s1 Y   s1 Y R", 
                "s2 a   s2 a L",
                "s2 X   s0 X R",
                "s2 Y   s2 Y L",
                "s3 Y   s3 Y R",
                "s3 -   s4 - R",
                "INITIAL_STATE: s0",
                "BLANK_CHARACTER: +",
                "FINAL_STATES: s4"
            };
            Tape tape = new Tape();
            FinalStates final_states = new FinalStates();
            InputAlphabet input_alphabet = new InputAlphabet();
            States states = new States();
            TapeAlphabet tape_alphabet = new TapeAlphabet();
            TransitionFunction transition_function = new TransitionFunction();
            TuringMachine tm = new TuringMachine("");

            Assert.IsTrue(tape_alphabet.load(ref definition), "Failed to parse tape alphabet");
            Assert.IsTrue(transition_function.load(ref definition), "Failed to parse transition function.");
            Assert.IsTrue(tm.LoadInitialState(ref definition), "Failed to parse initial state.");
            Assert.IsFalse(tape.load(ref definition), "Should not load a blank char that's not in tape alphabet.");
        }