diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-05-22 22:49:26 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-05-22 22:49:26 +0100 |
commit | db37956d3b98b27726035286afc4dd2fd13506b5 (patch) | |
tree | d8b4605bcf9782556f906b3b9c88d4cb8c44def8 /tr8as.c | |
parent | 555d7b7612c1e8beb099cf28ac63af2f36ee46fa (diff) | |
download | tr8vm-db37956d3b98b27726035286afc4dd2fd13506b5.tar.gz tr8vm-db37956d3b98b27726035286afc4dd2fd13506b5.zip |
Fix line parsing
WIP: needs better error reporting
Diffstat (limited to 'tr8as.c')
-rw-r--r-- | tr8as.c | 30 |
1 files changed, 17 insertions, 13 deletions
@@ -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) |