diff options
Diffstat (limited to 'src/as_parser.c')
| -rw-r--r-- | src/as_parser.c | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/as_parser.c b/src/as_parser.c index 1044e3f..39f8859 100644 --- a/src/as_parser.c +++ b/src/as_parser.c @@ -16,25 +16,25 @@ // <label> ::= tag ":" // <op> ::= "add" | "sub" | "mul" | "div" | "mod" | "eq" | ... -prog_t parse_prog(allocator_t alct, token_stream_t ts) { - prog_t p = allocate(alct, sizeof(struct prog)); +struct prog * parse_prog(struct allocator * alct, struct token_stream * ts) { + struct prog * p = allocate(alct, sizeof(struct prog)); p->stmts = parse_stmts(alct, ts); return p; } -stmts_t parse_stmts(allocator_t alct, token_stream_t ts) { - stmts_t ss = allocate(alct, sizeof(struct stmts)); - ss->stmts = allocate(alct, sizeof(stmt_t)); +struct stmts * parse_stmts(struct allocator * alct, struct token_stream * ts) { + struct stmts * ss = allocate(alct, sizeof(struct stmts)); + ss->stmts = allocate(alct, sizeof(struct stmt *)); ss->stmts[0] = NULL; int capacity = 0; int len = 0; while (peek_token(alct, ts)->type != TK_ENDOFFILE) { - stmt_t s = parse_stmt(alct, ts); + struct stmt * s = parse_stmt(alct, ts); if (s == NULL) continue; if (len == capacity) { size_t new_capacity = capacity * 2 + 1; - void* new_stmts = allocate(alct, sizeof(stmt_t*) * new_capacity); - memcpy(new_stmts, ss->stmts, sizeof(stmt_t*) * capacity); + void* new_stmts = allocate(alct, sizeof(struct stmt **) * new_capacity); + memcpy(new_stmts, ss->stmts, sizeof(struct stmt **) * capacity); ss->stmts = new_stmts; capacity = new_capacity; } @@ -51,13 +51,13 @@ stmts_t parse_stmts(allocator_t alct, token_stream_t ts) { return ss; } -label_t parse_label(allocator_t alct, token_stream_t ts) { - token_t t = next_token(alct, ts); +struct label * parse_label(struct allocator * alct, struct token_stream * ts) { + struct token * t = next_token(alct, ts); if (t->type != TK_TAG) { fprintf(stderr, "%d:%d expect label.\n", t->line, t->col); exit(-1); } - label_t l = allocate(alct, sizeof(label_t)); + struct label * l = allocate(alct, sizeof(struct label *)); l->name = t->sval; t = next_token(alct, ts); if (t->type != TK_COLON) { @@ -67,9 +67,9 @@ label_t parse_label(allocator_t alct, token_stream_t ts) { return l; } -stmt_t parse_stmt(allocator_t alct, token_stream_t ts) { - token_t t = peek_token(alct, ts); - stmt_t stmt = allocate(alct, sizeof(struct stmt)); +struct stmt * parse_stmt(struct allocator * alct, struct token_stream * ts) { + struct token * t = peek_token(alct, ts); + struct stmt * stmt = allocate(alct, sizeof(struct stmt)); stmt->label = NULL; stmt->instr = NULL; if (t->type == TK_TAG) { @@ -92,8 +92,8 @@ stmt_t parse_stmt(allocator_t alct, token_stream_t ts) { exit(-1); } -enum op parse_op(allocator_t alct, token_stream_t ts) { - token_t t = next_token(alct, ts); +enum op parse_op(struct allocator * alct, struct token_stream * ts) { + struct token * t = next_token(alct, ts); enum op op; if (t->type == TK_OP) { op = str2op(t->sval); @@ -108,9 +108,9 @@ enum op parse_op(allocator_t alct, token_stream_t ts) { return op; } -instr_t parse_instr(allocator_t alct, token_stream_t ts) { - token_t t = peek_token(alct, ts); - instr_t i = allocate(alct, sizeof(struct instr)); +struct instr * parse_instr(struct allocator * alct, struct token_stream * ts) { + struct token * t = peek_token(alct, ts); + struct instr * i = allocate(alct, sizeof(struct instr)); i->tag_name = NULL; i->arg = NULL; i->op = OP_END; @@ -118,7 +118,7 @@ instr_t parse_instr(allocator_t alct, token_stream_t ts) { i->op = parse_op(alct, ts); t = peek_token(alct, ts); if (t->type == TK_ARG) { - arg_t a = allocate(alct, sizeof(struct arg)); + struct arg * a = allocate(alct, sizeof(struct arg)); a->ival = t->ival; a->fval = t->fval; i->arg = a; |
