Initial commit from sysy-main

This commit is contained in:
Lixuanwang
2025-02-27 23:14:53 +08:00
commit cc523fd30b
1125 changed files with 257793 additions and 0 deletions

2
testdata/functional/21_if_test2.out vendored Executable file
View File

@@ -0,0 +1,2 @@
-5
0

25
testdata/functional/21_if_test2.sy vendored Executable file
View File

@@ -0,0 +1,25 @@
// test if-else-if
int ifElseIf() {
int a;
a = 5;
int b;
b = 10;
if(a == 6 || b == 0xb) {
return a;
}
else {
if (b == 10 && a == 1)
a = 25;
else if (b == 10 && a == -5)
a = a + 15;
else
a = -+a;
}
return a;
}
int main(){
putint(ifElseIf());
return 0;
}

1
testdata/functional/26_while_test1.out vendored Executable file
View File

@@ -0,0 +1 @@
3

18
testdata/functional/26_while_test1.sy vendored Executable file
View File

@@ -0,0 +1,18 @@
int doubleWhile() {
int i;
i = 5;
int j;
j = 7;
while (i < 100) {
i = i + 30;
while(j < 100){
j = j + 6;
}
j = j - 100;
}
return (j);
}
int main() {
return doubleWhile();
}

1
testdata/functional/35_op_priority1.out vendored Executable file
View File

@@ -0,0 +1 @@
40

9
testdata/functional/35_op_priority1.sy vendored Executable file
View File

@@ -0,0 +1,9 @@
//test the priority of add and mul
int main(){
int a, b, c, d;
a = 10;
b = 4;
c = 2;
d = 2;
return c + a * b - d;
}

1
testdata/functional/40_unary_op.out vendored Executable file
View File

@@ -0,0 +1 @@
0

11
testdata/functional/40_unary_op.sy vendored Executable file
View File

@@ -0,0 +1,11 @@
int main() {
int a;
a = 10;
if (+-!!!a) {
a = - - -1;
}
else {
a = 0;
}
return a;
}

2
testdata/functional/44_stmt_expr.out vendored Executable file
View File

@@ -0,0 +1,2 @@
1024
0

13
testdata/functional/44_stmt_expr.sy vendored Executable file
View File

@@ -0,0 +1,13 @@
int k;
const int n = 10;
int main () {
int i = 0;
k = 1;
while (i <= n - 1) {
i = i + 1;
k + 1;
k = k + k;
}
putint(k);
return k;
}

4
testdata/functional/50_short_circuit.in vendored Executable file
View File

@@ -0,0 +1,4 @@
11
10
100
99

2
testdata/functional/50_short_circuit.out vendored Executable file
View File

@@ -0,0 +1,2 @@
11111210
0

21
testdata/functional/50_short_circuit.sy vendored Executable file
View File

@@ -0,0 +1,21 @@
int g = 0;
int func(int n) {
g = g + n;
putint(g);
return g;
}
int main() {
int i;
i = getint();
if (i > 10 && func(i)) i = 1; else i = 0;
i = getint();
if (i > 11 && func(i)) i = 1; else i = 0;
i = getint();
if (i <= 99 || func(i)) i = 1; else i = 0;
i = getint();
if (i <= 100 || func(i)) i = 1; else i = 0;
if (!func(99) && func(100)) i = 1; else i = 0;
return 0;
}

2
testdata/functional/52_scope.out vendored Executable file
View File

@@ -0,0 +1,2 @@
1
0

27
testdata/functional/52_scope.sy vendored Executable file
View File

@@ -0,0 +1,27 @@
int a = 7;
int func() {
int b = a;
int a = 1;
if (a == b) {
a = a + 1;
return 1;
}
else
return 0;
}
int main() {
int result = 0;
int i = 0;
while (i < 100) {
if (func() == 1)
result = result + 1;
i = i + 1;
}
if (result < 100)
putint(1);
else
putint(0);
return 0;
}

14
testdata/functional/73_int_io.in vendored Executable file
View File

@@ -0,0 +1,14 @@
5
4006571
9900
1504379
758219
99336677

6
testdata/functional/73_int_io.out vendored Executable file
View File

@@ -0,0 +1,6 @@
4006571
9900
1504379
758219
99336677
0

52
testdata/functional/73_int_io.sy vendored Executable file
View File

@@ -0,0 +1,52 @@
const int ascii_0 = 48;
int my_getint()
{
int sum = 0, c;
while (1) {
c = getch() - ascii_0;
if (c < 0 || c > 9) {
continue;
} else {
break;
}
}
sum = c;
while (1) {
c = getch() - ascii_0;
if (c >= 0 && c <= 9) {
sum = sum * 10 + c;
} else {
break;
}
}
return sum;
}
void my_putint(int a)
{
int b[16], i = 0;
while (a > 0) {
b[i] = a % 10 + ascii_0;
a = a / 10;
i = i + 1;
}
while (i > 0) {
i = i - 1;
putch(b[i]);
}
}
int main()
{
int n = my_getint();
while (n > 0) {
int m = my_getint();
my_putint(m); putch(10);
n = n - 1;
}
return 0;
}