/****************************/ /* Turing Machine Simulator */ /* by Ryo Kashima */ /* January 2009 */ /****************************/ #include #include #define WAIT 100000000 #define TAPE_SIZE 30 #define HEAD_START_POINT 10 #define COMMAND_SIZE 100 #define BLANK '.' #define COMMENT '%' #define TAPE_START '<' #define TAPE_END '>' #define COMMAND_START '{' #define COMMAND_END '}' #define LEFT 'L' #define RIGHT 'R' char next_char(void); void initialize(void); int input_success(void); void action(void); void display_command(void); void display_tape(void); void wait(void); char tape[TAPE_SIZE]; char state; int head; int last_command; struct command { char state; char read; char write; char move; char next_state; }; struct command command_table[COMMAND_SIZE]; main() { initialize(); if (input_success()) { action(); } } void initialize(void) { int i; for (i=0; i= TAPE_SIZE) { printf("Out of tape.\n"); return; } } state = command_table[i].next_state; matching = 1; break; } } if (matching == 0) { return; } } } /* action */ void display_tape(void) { int i; printf("%c: ", state); for (i=0; i %c\n", command_table[i].state, command_table[i].read, command_table[i].write, command_table[i].move, command_table[i].next_state); } printf("\n"); } char next_char(void) { int c; c = getchar(); while (isspace(c) || (c == COMMENT)) { if (c == COMMENT) { while ((c = getchar()) != COMMENT){} } c = getchar(); } return(c); } void wait(void) { long i; for (i=1; i<=WAIT; i++) {} }