From a9054f0a64b6ae0463eff199ca42b5d62a28acd6 Mon Sep 17 00:00:00 2001 From: Yaossg Date: Sun, 8 Dec 2024 15:40:44 +0800 Subject: [PATCH] fix prefix and div-assign --- boot.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/boot.c b/boot.c index ac401de..7c8641d 100644 --- a/boot.c +++ b/boot.c @@ -427,7 +427,7 @@ void next_token() { int ch2 = getchar(); if (ch2 == '=') { token_type = TOKEN_DIV_ASSIGN; - } if (ch2 == '/') { + } else if (ch2 == '/') { do ch = getchar(); while (ch != -1 && ch != '\n'); next_token(); return; @@ -1253,7 +1253,7 @@ int parse_postfix_expr() { int parse_prefix_expr() { next_token(); if (token_type == TOKEN_AND) { - int reg = parse_postfix_expr(); + int reg = parse_prefix_expr(); int type = reg_type[reg]; if (type & TYPE_PTR_MASK) { fprintf(stderr, "cannot take address of a pointer\n"); @@ -1261,7 +1261,7 @@ int parse_prefix_expr() { } return addressof(reg); } else if (token_type == TOKEN_MUL) { - int reg = parse_postfix_expr(); + int reg = parse_prefix_expr(); int type = reg_type[reg]; if (!(type & TYPE_PTR_MASK)) { fprintf(stderr, "cannot dereference a non-pointer\n"); @@ -1273,20 +1273,20 @@ int parse_prefix_expr() { } return dereference(reg); } else if (token_type == TOKEN_SUB) { - int reg = parse_postfix_expr(); + int reg = parse_prefix_expr(); return asm_r_arith("neg", reg); } else if (token_type == TOKEN_COMPL) { - int reg = parse_postfix_expr(); + int reg = parse_prefix_expr(); return asm_r_arith("not", reg); } else if (token_type == TOKEN_NOT) { - int reg = parse_postfix_expr(); + int reg = parse_prefix_expr(); return asm_r(TYPE_INT, "seqz", reg); } else if (token_type == TOKEN_INC) { - int reg = parse_postfix_expr(); + int reg = parse_prefix_expr(); _asm_ri("addi", reg, reg, step_of(reg_type[reg])); return reg; } else if (token_type == TOKEN_DEC) { - int reg = parse_postfix_expr(); + int reg = parse_prefix_expr(); _asm_ri("addi", reg, reg, -step_of(reg_type[reg])); return reg; } else { @@ -1989,8 +1989,6 @@ void dump_string_table() { printf("\\t"); } else if (ch == '\r') { printf("\\r"); - } else if (ch == '\0') { - printf("\\0"); } else if (ch == '\\') { printf("\\\\"); } else if (ch == '\'') {