diff --git a/test/21_if_test2.sy b/test/21_if_test2.sy new file mode 100644 index 0000000..bf7b8fa --- /dev/null +++ b/test/21_if_test2.sy @@ -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; +} \ No newline at end of file diff --git a/test/25_while_if.sy b/test/25_while_if.sy new file mode 100644 index 0000000..47b8b79 --- /dev/null +++ b/test/25_while_if.sy @@ -0,0 +1,31 @@ +int get_one(int a) { + return 1; +} + +int deepWhileBr(int a, int b) { + int c; + c = a + b; + while (c < 75) { + int d; + d = 42; + if (c < 100) { + c = c + d; + if (c > 99) { + int e; + e = d * 2; + if (get_one(0) == 1) { + c = e * 2; + } + } + } + } + return (c); +} + +int main() { + int p; + p = 2; + p = deepWhileBr(p, p); + putint(p); + return 0; +} \ No newline at end of file diff --git a/test/30_continue.sy b/test/30_continue.sy new file mode 100644 index 0000000..b20cd55 --- /dev/null +++ b/test/30_continue.sy @@ -0,0 +1,16 @@ +//test continue +int main(){ + int i; + i = 0; + int sum; + sum = 0; + while(i < 100){ + if(i == 50){ + i = i + 1; + continue; + } + sum = sum + i; + i = i + 1; + } + return sum; +} \ No newline at end of file diff --git a/test/33_while_if_test3.sy b/test/33_while_if_test3.sy new file mode 100644 index 0000000..ef16dfa --- /dev/null +++ b/test/33_while_if_test3.sy @@ -0,0 +1,25 @@ +int deepWhileBr(int a, int b) { + int c; + c = a + b; + while (c < 75) { + int d; + d = 42; + if (c < 100) { + c = c + d; + if (c > 99) { + int e; + e = d * 2; + if (1 == 1) { + c = e * 2; + } + } + } + } + return (c); +} + +int main() { + int p; + p = 2; + return deepWhileBr(p, p); +} diff --git a/test/37_op_priority3.sy b/test/37_op_priority3.sy new file mode 100644 index 0000000..e04c930 --- /dev/null +++ b/test/37_op_priority3.sy @@ -0,0 +1,7 @@ +//test the priority of unary operator and binary operator +int main(){ + int a, b; + a = 10; + b = 30; + return a - -5 + b + -5; +} \ No newline at end of file diff --git a/test/41_unary_op2.sy b/test/41_unary_op2.sy new file mode 100644 index 0000000..a824266 --- /dev/null +++ b/test/41_unary_op2.sy @@ -0,0 +1,14 @@ +int main() { + int a, b; + a = 070; + b = 0x4; + a = a - - 4 + + b; + if (+-!!!a) { + a = - - -1; + } + else { + a = 0 + + b; + } + putint(a); + return 0; +} \ No newline at end of file diff --git a/test/42_empty_stmt.sy b/test/42_empty_stmt.sy new file mode 100644 index 0000000..a8c161f --- /dev/null +++ b/test/42_empty_stmt.sy @@ -0,0 +1,5 @@ +int main() { + int a = 10; + ; + return a * 2 + 1; +} diff --git a/test/44_stmt_expr.sy b/test/44_stmt_expr.sy new file mode 100644 index 0000000..a5f5bb5 --- /dev/null +++ b/test/44_stmt_expr.sy @@ -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; +} diff --git a/test/50_short_circuit.sy b/test/50_short_circuit.sy new file mode 100644 index 0000000..322855d --- /dev/null +++ b/test/50_short_circuit.sy @@ -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; +}