From 607865f4a8b5662606bd3d361b6a194b016775fc Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Thu, 25 May 2023 21:43:18 +0100 Subject: Suport for assembly "line" label: instr ; comment And all are optional. --- tr8as.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'tr8as.c') diff --git a/tr8as.c b/tr8as.c index c09cf48..6d43bdc 100644 --- a/tr8as.c +++ b/tr8as.c @@ -1588,6 +1588,9 @@ static uint8_t parse(As *as, char *c) char word[MAX_ID + 1]; uint8_t i; + /* A valid assembler line can have a label, an instruction and a comment, + * and all of them are optional. */ + c = skip_whitespace(c); /* comment or empty line */ @@ -1603,22 +1606,29 @@ static uint8_t parse(As *as, char *c) c++; if (!new_label(as, word)) return 0; - } - else - { - /* instruction */ - for (i = 0; insts[i].parse; i++) - if (!strcasecmp(insts[i].id, word)) - { - if (!insts[i].parse(as, &c)) - return 0; - break; - } - if (!insts[i].parse) - return error_l("Parse error", &as->loc, word); + c = skip_whitespace(c); + + /* comment or EOL */ + if (!*c || *c == ';') + return 1; + + if (!next_word(as, &c, word)) + return 0; } + /* instruction */ + for (i = 0; insts[i].parse; i++) + if (!strcasecmp(insts[i].id, word)) + { + if (!insts[i].parse(as, &c)) + return 0; + break; + } + + if (!insts[i].parse) + return error_l("Parse error", &as->loc, word); + c = skip_whitespace(c); /* comment or EOL */ -- cgit v1.2.3