This commit is contained in:
Yaossg 2024-11-17 10:39:58 +08:00
parent fc9ac15c4b
commit dfbeb90387
2 changed files with 38 additions and 3 deletions

12
boot.c
View File

@ -249,7 +249,7 @@ void next_token() {
} else if (ch == '/') { } else if (ch == '/') {
int ch2 = getchar(); int ch2 = getchar();
if (ch2 == '/') { if (ch2 == '/') {
do ch = getchar(); while (ch != '\n' && ch != -1); while ((ch = getchar()) != -1 && ch != '\n');
next_token(); next_token();
return; return;
} else if (ch2 == '*') { } else if (ch2 == '*') {
@ -1238,14 +1238,20 @@ void parse_function(const char* name) {
expect_token(TOKEN_PAREN_RIGHT); expect_token(TOKEN_PAREN_RIGHT);
break; break;
} }
int decl_type = parse_type(); int arg_type = parse_type();
expect_token(TOKEN_ID); expect_token(TOKEN_ID);
args[arg++] = declare_local(token_data, decl_type); int arg_name = token_data;
next_token(); next_token();
if (token_type == TOKEN_BRACKET_LEFT) { if (token_type == TOKEN_BRACKET_LEFT) {
expect_token(TOKEN_BRACKET_RIGHT); expect_token(TOKEN_BRACKET_RIGHT);
next_token(); next_token();
if (arg_type & TYPE_PTR_MASK) {
eprintf("local variable of array of pointers is not supported\n");
exit(1);
} }
arg_type = arg_type | TYPE_PTR_MASK;
}
args[arg++] = declare_local(token_data, arg_type);
if (token_type == TOKEN_COMMA) { if (token_type == TOKEN_COMMA) {
// continue; // continue;
} else if (token_type == TOKEN_PAREN_RIGHT) { } else if (token_type == TOKEN_PAREN_RIGHT) {

29
demo/sort.c Normal file
View File

@ -0,0 +1,29 @@
int printf(const char format[], ...);
int scanf(const char format[], ...);
void sort(int a[], int n) {
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
int t = a[i];
a[i] = a[j];
a[j] = t;
}
}
}
}
int main() {
int n;
int a[100];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
sort(a, n);
for (int i = 0; i < n; i++) {
printf("%d ", a[i]);
}
printf("\n");
return 0;
}