summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Murphy <tylerm@tylerm.dev>2023-04-13 22:24:28 -0400
committerTyler Murphy <tylerm@tylerm.dev>2023-04-13 22:24:28 -0400
commitd067119a905dc1ef5a1c276ed3650147bb6b9038 (patch)
tree618578c95cc1a7b391b804354d877904d2c77911
parentupdate readme (diff)
downloadbrainfucked-d067119a905dc1ef5a1c276ed3650147bb6b9038.tar.gz
brainfucked-d067119a905dc1ef5a1c276ed3650147bb6b9038.tar.bz2
brainfucked-d067119a905dc1ef5a1c276ed3650147bb6b9038.zip
funny valgrind
-rw-r--r--src/interpreter.c1
-rw-r--r--src/program.c11
-rw-r--r--src/program.h3
3 files changed, 5 insertions, 10 deletions
diff --git a/src/interpreter.c b/src/interpreter.c
index 7255a4c..a6ad544 100644
--- a/src/interpreter.c
+++ b/src/interpreter.c
@@ -136,7 +136,6 @@ next:
break;
case LeaveTape:
case Eof:
- case Invalid:
return;
}
diff --git a/src/program.c b/src/program.c
index aa113b6..dcec0f7 100644
--- a/src/program.c
+++ b/src/program.c
@@ -64,7 +64,8 @@ retest:
case EOF:
return Eof;
default:
- return Invalid;
+ c = next_char();
+ goto retest;
}
}
@@ -80,16 +81,12 @@ void program_init(char* file_path, Program* program) {
program->data = malloc(capacity * sizeof(Symbol));
program->len = 0;
+ program->index = 0;
Symbol s;
while(true) {
s = next_symbol();
- if (s == Invalid) {
- printf("error: invalid symbol at character %d\n", count);
- exit(EXIT_FAILURE);
- }
-
if (program->len == capacity) {
capacity *= 2;
program->data = realloc(program->data, capacity * sizeof(Symbol));
@@ -118,7 +115,7 @@ void program_next(Program* program, Symbol* symbol) {
}
void program_last(Program* program, Symbol* symbol) {
- if (program->index == 0) {
+ if (program->index < 1) {
*symbol = Eof;
return;
}
diff --git a/src/program.h b/src/program.h
index 7b40712..23f4d74 100644
--- a/src/program.h
+++ b/src/program.h
@@ -19,8 +19,7 @@ typedef enum {
PutString,
GetString,
Clear,
- Eof,
- Invalid
+ Eof
} Symbol;
typedef struct {