postfix chain
This commit is contained in:
parent
3910fc3413
commit
fc9ac15c4b
2 changed files with 58 additions and 6 deletions
17
boot.c
17
boot.c
|
@ -249,12 +249,16 @@ void next_token() {
|
|||
} else if (ch == '/') {
|
||||
int ch2 = getchar();
|
||||
if (ch2 == '/') {
|
||||
while ((ch = getchar()) != '\n');
|
||||
do ch = getchar(); while (ch != '\n' && ch != -1);
|
||||
next_token();
|
||||
return;
|
||||
} else if (ch2 == '*') {
|
||||
while (1) {
|
||||
ch = getchar();
|
||||
if (ch == -1) {
|
||||
eprintf("expecting '*/'\n");
|
||||
exit(1);
|
||||
}
|
||||
if (ch == '*') {
|
||||
ch = getchar();
|
||||
if (ch == '/') {
|
||||
|
@ -773,7 +777,7 @@ int parse_postfix_expr() {
|
|||
store_t0(reg);
|
||||
printf(" addi t0, t0, %d\n", step_of(type));
|
||||
store_t0(lhs);
|
||||
return reg;
|
||||
lhs = reg;
|
||||
} else if (token_type == TOKEN_DEC) {
|
||||
int type = local_type[lhs];
|
||||
int reg = next_reg(type);
|
||||
|
@ -781,11 +785,11 @@ int parse_postfix_expr() {
|
|||
store_t0(reg);
|
||||
printf(" addi t0, t0, -%d\n", step_of(type));
|
||||
store_t0(lhs);
|
||||
return reg;
|
||||
lhs = reg;
|
||||
} else if (token_type == TOKEN_BRACKET_LEFT) {
|
||||
int rhs = parse_expr();
|
||||
expect_token(TOKEN_BRACKET_RIGHT);
|
||||
return indirection_of(asm_add(lhs, rhs));
|
||||
lhs = indirection_of(asm_add(lhs, rhs));
|
||||
} else if (token_type == TOKEN_PAREN_LEFT) {
|
||||
int arg = 0;
|
||||
int args[8];
|
||||
|
@ -817,12 +821,13 @@ int parse_postfix_expr() {
|
|||
load_address(0, lhs);
|
||||
printf(" jalr t0\n");
|
||||
printf(" mv t0, a0\n");
|
||||
return materialize_t0(local_type[lhs]);
|
||||
lhs = materialize_t0(local_type[lhs]);
|
||||
} else {
|
||||
unget_token();
|
||||
return lhs;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return lhs;
|
||||
}
|
||||
|
||||
int parse_prefix_expr() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue