diff options
Diffstat (limited to 'src/as_parser.c')
| -rw-r--r-- | src/as_parser.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/as_parser.c b/src/as_parser.c index f848730..990bc1c 100644 --- a/src/as_parser.c +++ b/src/as_parser.c @@ -4,6 +4,7 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> // BNF // === @@ -32,8 +33,11 @@ Stmts parseStmts(Allocator alct, TokenStream ts) { Stmt s = parseStmt(alct, ts); if (s == NULL) continue; if (len == capacity) { - capacity = capacity * 2 + 1; - ss->stmts = realloc(ss->stmts, sizeof(Stmt*) * capacity); + size_t newCapacity = capacity * 2 + 1; + void* newStmts = allocate(alct, sizeof(Stmt*) * newCapacity); + memcpy(newStmts, ss->stmts, sizeof(Stmt*) * capacity); + ss->stmts = newStmts; + capacity = newCapacity; } // expect newline if (peekToken(alct, ts)->type == NEWLINE) { @@ -74,6 +78,7 @@ Stmt parseStmt(Allocator alct, TokenStream ts) { if (peekToken(alct, ts)->type == NEWLINE) { return stmt; } + t = peekToken(alct, ts); } if (t->type == OP) { stmt->instr = parseInstr(alct, ts); @@ -84,7 +89,7 @@ Stmt parseStmt(Allocator alct, TokenStream ts) { if (t->type == NEWLINE) { return NULL; } - fprintf(stderr, "%d:%d Expect lable + instruction, lable, or instruction.", t->line, t->col); + fprintf(stderr, "%d:%d Expect lable + instruction, lable, or instruction.\n", t->line, t->col); exit(-1); } @@ -105,9 +110,11 @@ enum op parseOp(Allocator alct, TokenStream ts) { } Instr parseInstr(Allocator alct, TokenStream ts) { - Token t = nextToken(alct, ts); + Token t = peekToken(alct, ts); Instr i = allocate(alct, sizeof(struct instr)); i->tagName = NULL; + i->arg = NULL; + i->op = OPEND; if (t->type == OP) { i->op = parseOp(alct, ts); t = peekToken(alct, ts); |
