aboutsummaryrefslogtreecommitdiff
path: root/tr8as.c
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-05-22 22:49:26 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-05-22 22:49:26 +0100
commitdb37956d3b98b27726035286afc4dd2fd13506b5 (patch)
treed8b4605bcf9782556f906b3b9c88d4cb8c44def8 /tr8as.c
parent555d7b7612c1e8beb099cf28ac63af2f36ee46fa (diff)
downloadtr8vm-db37956d3b98b27726035286afc4dd2fd13506b5.tar.gz
tr8vm-db37956d3b98b27726035286afc4dd2fd13506b5.zip
Fix line parsing
WIP: needs better error reporting
Diffstat (limited to 'tr8as.c')
-rw-r--r--tr8as.c30
1 files changed, 17 insertions, 13 deletions
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)