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 {