From c25bc8bff130460980496593f001143c9a6d6b37 Mon Sep 17 00:00:00 2001 From: sejo Date: Thu, 2 Sep 2021 16:15:36 -0500 Subject: [PATCH] initial commit --- Makefile | 2 + README.md | 0 machines/contador-alternado.txt | 7 +++ machines/contador.txt | 6 +++ machines/parentesis.txt | 16 ++++++ machines/paridad.txt | 11 ++++ machines/test.txt | 7 +++ turingsim.c | 93 +++++++++++++++++++++++++++++++++ 8 files changed, 142 insertions(+) create mode 100644 Makefile create mode 100644 README.md create mode 100644 machines/contador-alternado.txt create mode 100644 machines/contador.txt create mode 100644 machines/parentesis.txt create mode 100644 machines/paridad.txt create mode 100644 machines/test.txt create mode 100644 turingsim.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ad09d47 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +build: + cc -std=c89 -Wall turingsim.c -o turingsim diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/machines/contador-alternado.txt b/machines/contador-alternado.txt new file mode 100644 index 0000000..505adda --- /dev/null +++ b/machines/contador-alternado.txt @@ -0,0 +1,7 @@ +0 +0000001 +0 +2 +00110 +10000 +80 diff --git a/machines/contador.txt b/machines/contador.txt new file mode 100644 index 0000000..3361c65 --- /dev/null +++ b/machines/contador.txt @@ -0,0 +1,6 @@ +0 +0000001 +0 +1 +00010 +80 diff --git a/machines/parentesis.txt b/machines/parentesis.txt new file mode 100644 index 0000000..49fcfcf --- /dev/null +++ b/machines/parentesis.txt @@ -0,0 +1,16 @@ +a +A(()())A +1 +11 +a)bX1 +a(a(0 +aAcA1 +aXaX0 +b)b)1 +b(aX0 +bAH00 +bXbX1 +c(H00 +cAH10 +cXcX1 +80 \ No newline at end of file diff --git a/machines/paridad.txt b/machines/paridad.txt new file mode 100644 index 0000000..9170d04 --- /dev/null +++ b/machines/paridad.txt @@ -0,0 +1,11 @@ +a +101100B +0 +6 +a0a00 +a1b00 +aBH00 +b0b00 +b1a00 +bBH10 +80 \ No newline at end of file diff --git a/machines/test.txt b/machines/test.txt new file mode 100644 index 0000000..974d6cf --- /dev/null +++ b/machines/test.txt @@ -0,0 +1,7 @@ +a +0000001 +0 +2 +a0a10 +a1a10 +4 diff --git a/turingsim.c b/turingsim.c new file mode 100644 index 0000000..aee9c72 --- /dev/null +++ b/turingsim.c @@ -0,0 +1,93 @@ +#include + +#define TAPE_SIZE 80 +#define RULES_SIZE 256 + +typedef struct { + char state; /* current state */ + char symbol; /* current symbol */ + int head; /* index of head */ + char tape[TAPE_SIZE]; /* tape of characters */ + int nrules; /* number of rules */ + /* state, symbol, new state, new symbol, direction (even right, odd left ) */ + char rules[RULES_SIZE][5]; +} Machine; + +Machine m; +int nsteps; + +int main(int argc, char *argv[]){ + int i,n=0; + FILE *f; + + if(!(f = fopen(argv[1], "r"))){ + fprintf(stderr, "failed to load file\n"); + return 1; + } + printf("%s\n\n", argv[1]); + + /* read machine description */ + printf("initial state: "); + fscanf(f,"%c",&m.state); + printf("%c\n",m.state); + + printf("initial tape: "); + fscanf(f,"%s",m.tape); + printf("%s\n",m.tape); + + printf("initial position of head: "); + fscanf(f,"%d",&m.head); + m.head = (m.head+TAPE_SIZE)%TAPE_SIZE; + printf("%d\n",m.head); + + printf("number of rules: "); + fscanf(f,"%d",&m.nrules); + printf("%d\n",m.nrules); + + for(i=0; i