summaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/parse.c b/parse.c
index 2bfc7da..a091939 100644
--- a/parse.c
+++ b/parse.c
@@ -22,6 +22,7 @@ static size_t labels_count;
static struct instruction *insts;
static size_t insts_count;
static size_t byte_offset;
+static struct token token_eof = { .type = TOKEN_EOF };
static void emit(const char *fmt, ...)
{
@@ -59,7 +60,7 @@ static int expect(enum TOKEN_TYPE e)
if (cursor) {
observed_desc = get_token_description(cursor->type);
} else {
- observed_desc = "end of file";
+ observed_desc = "(error: unknown)";
}
emit("Error: Expected %s, got %s\n", expected_desc, observed_desc);
return 1;
@@ -73,7 +74,7 @@ void kerchunk()
if (tokens_pos < tokens_count - 1) {
cursor = &tokens[++tokens_pos];
} else {
- cursor = NULL;
+ cursor = &token_eof;
}
}
@@ -500,7 +501,7 @@ int parse(const char *filename_local, FILE* fd_local, struct label **labels_loca
byte_offset = 0;
cursor = tokens;
- while (cursor) {
+ while (cursor && cursor->type != TOKEN_EOF) {
switch(cursor->type) {
case TOKEN_EOL:
kerchunk();