diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-05-25 21:43:18 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-05-25 21:43:18 +0100 |
commit | 607865f4a8b5662606bd3d361b6a194b016775fc (patch) | |
tree | 82281bdefc009eaabe81fccdffb8b87732e899c5 | |
parent | fe0e86d475b825d855e58662bef3bcedab5eab60 (diff) | |
download | tr8vm-607865f4a8b5662606bd3d361b6a194b016775fc.tar.gz tr8vm-607865f4a8b5662606bd3d361b6a194b016775fc.zip |
Suport for assembly "line"
label: instr ; comment
And all are optional.
-rw-r--r-- | tr8as.c | 36 |
1 files changed, 23 insertions, 13 deletions
@@ -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 */ |