From db37956d3b98b27726035286afc4dd2fd13506b5 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Mon, 22 May 2023 22:49:26 +0100 Subject: Fix line parsing WIP: needs better error reporting --- tr8as.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'tr8as.c') diff --git a/tr8as.c b/tr8as.c index 43a2534..8e9fc1b 100644 --- a/tr8as.c +++ b/tr8as.c @@ -1299,7 +1299,7 @@ static uint8_t parse_dec(As *as, char **c) uint8_t wlen; uint8_t r1; - /* INC r1 */ + /* DEC r1 */ if (!next_word(as, c, word, &wlen)) return 0; @@ -1667,16 +1667,19 @@ static uint8_t parse(As *as, char *c) uint8_t wlen; uint8_t i; + c = skip_whitespace(c); + + /* comment */ + if (*c == ';') + return 1; + if (!next_word(as, &c, word, &wlen)) return 0; + /* empty line */ if (wlen == 0) return 1; - /* comment */ - if (word[0] == ';') - return 1; - /* new label */ if (*c == ':') { @@ -1686,7 +1689,7 @@ static uint8_t parse(As *as, char *c) } else { - /* instructions */ + /* instruction */ for (i = 0; insts[i].parse; i++) if (!strcasecmp(insts[i].id, word)) { @@ -1699,18 +1702,19 @@ static uint8_t parse(As *as, char *c) return error_l("Parse error", &as->loc, word); } - /* EOL */ - if (!next_word(as, &c, word, &wlen)) - return 0; + /* can be followed by a comment or EOL */ - if (wlen == 0) + c = skip_whitespace(c); + + /* comment */ + if (*c == ';') return 1; - /* or comment */ - if (word[0] == ';') + /* EOL */ + if (!*c) return 1; - return error_l("Parse error", &as->loc, word); + return error_l("Parse error", &as->loc, "expected end of line"); } static uint8_t asm(As *as, const char *filename, FILE *in) -- cgit v1.2.3