From dfbeb90387836ae64c8a48dea19b4df8c051a4e4 Mon Sep 17 00:00:00 2001 From: Yaossg Date: Sun, 17 Nov 2024 10:39:58 +0800 Subject: [PATCH] decay --- boot.c | 12 +++++++++--- demo/sort.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 demo/sort.c diff --git a/boot.c b/boot.c index 9093ce6..1c53544 100644 --- a/boot.c +++ b/boot.c @@ -249,7 +249,7 @@ void next_token() { } else if (ch == '/') { int ch2 = getchar(); if (ch2 == '/') { - do ch = getchar(); while (ch != '\n' && ch != -1); + while ((ch = getchar()) != -1 && ch != '\n'); next_token(); return; } else if (ch2 == '*') { @@ -1238,14 +1238,20 @@ void parse_function(const char* name) { expect_token(TOKEN_PAREN_RIGHT); break; } - int decl_type = parse_type(); + int arg_type = parse_type(); expect_token(TOKEN_ID); - args[arg++] = declare_local(token_data, decl_type); + int arg_name = token_data; next_token(); if (token_type == TOKEN_BRACKET_LEFT) { expect_token(TOKEN_BRACKET_RIGHT); 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) { // continue; } else if (token_type == TOKEN_PAREN_RIGHT) { diff --git a/demo/sort.c b/demo/sort.c new file mode 100644 index 0000000..45fe69b --- /dev/null +++ b/demo/sort.c @@ -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; +} \ No newline at end of file