Пример #1
0
        // Constructor
        public Menu(AppConfiguration cfg, ref TuringMachine turingMachine)
        {
	        config = cfg;
	        tm = turingMachine;
	        saveInputStringsOnExit = false;
	        loadInputStrings(cfg.FilenameBase + ".str");	
        }
Пример #2
0
        static void Main(string[] args)
        {

	        // Acquire filename passed as argument
	        string filename = "../test";
	        if (args.Count() == 2) {
		        filename = args[1];
	        } else {
//		        Console.WriteLine( "\nYou must pass a single filename argument.\nExample: <application> <filename>\n" );
        //		exit(1);
	        }
	
	        // Setup configuration
	        AppConfiguration config = new AppConfiguration();
	        config.HelpOn = false;	// default (NO messages)
	        config.MaxTransitions = 1; // Max number of transitions to perform at a time (default 1)
	        config.MaxIdChars = 32; // Max number of cells to the left and to the right of the tape head to display in instantaneous description. (default: 32 in each direction)
	        config.FilenameBase = filename;
	
        //	cout << setfill('_') << setw(28) << "" << endl;
        //	cout << "Hello, Turing Machine World!\n";
		
	        // Load Turing Machine Object
	        TuringMachine tm = new TuringMachine(filename);

	        // Validate loaded definition
	        if (!tm.is_valid_definition()) 
            {
		        Console.WriteLine(  "Invalid definition: Shutting down.\n" );
		        return;
	        }
	
	        // Load Menu System
	        Menu menu = new Menu(config, ref tm);
	
	        // Application Loop
	        while (menu.menuLoop()) {
				
	        }
	
            return;            
        }
Пример #3
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:");

        }
Пример #4
0
 void TestDefinition(List<string> definition)
  {
      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.IsTrue(transition_function.load(ref definition), "Failed to parse transition function.");
      Assert.IsTrue(tm.LoadInitialState(ref definition), "Failed to parse initial state.");
      Assert.IsTrue(tape.load(ref definition), "Failed to load tape.");
      Assert.IsTrue(final_states.load(ref definition), "Failed to parse final states.");
  }
Пример #5
0
        public void TestDefinitionNoBlank()
        {

            TuringMachine tm = new TuringMachine("");
            Assert.IsFalse(tm.loadDefinition("testNoBlank.def"), "Test 5.1.7 failed, Blank character found.");
        }
Пример #6
0
        public void TestDefinitionNoInitial()
        {

            TuringMachine tm = new TuringMachine("");
            Assert.IsFalse(tm.loadDefinition("testNoInitial.def"), "Test 5.1.6 failed, Initial character found.");
        }
Пример #7
0
        public void TestDefinitionNoTransition()
        {

            TuringMachine tm = new TuringMachine("");
            Assert.IsFalse(tm.loadDefinition("testNoTransition.def"), "Test 5.1.5 failed, Transitions found.");
        }
Пример #8
0
        public void TestDefinitionNoTape()
        {

            TuringMachine tm = new TuringMachine("");
            Assert.IsFalse(tm.loadDefinition("testNoTape.def"), "Tests 5.1.4 failed, Tape characters found");
        }
Пример #9
0
        public void TestDefinitionNoState()
        {

            TuringMachine tm = new TuringMachine("");
            Assert.IsFalse(tm.loadDefinition("testNoState.def"), "Test 5.1.2 failed, States found.");
        }
Пример #10
0
        public void TestDefinitionValid()
        {

            TuringMachine tm = new TuringMachine("");
            Assert.IsTrue(tm.loadDefinition("testValid.def"), "Test 5.1.1 failed, Valid defintion not loaded.");
        }
Пример #11
0
        public void TestDefinitionNoFinal()
        {

            TuringMachine tm = new TuringMachine("");
            Assert.IsFalse(tm.loadDefinition("testNoFinal.def"), "Test 5.1.8 failed, Final states found.");
        }       
Пример #12
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.");
        }