├── README.md ├── ir-test └── test.sh ├── mips-test └── test.sh ├── prepare ├── build.sh ├── include │ └── sysy_header.h ├── out │ └── test │ │ ├── testfile1.txt.exe │ │ ├── testfile2.txt.exe │ │ ├── testfile3.txt.exe │ │ └── testfile4.txt.exe └── test │ ├── input1.txt │ ├── input2.txt │ ├── input3.txt │ ├── input4.txt │ ├── output1.txt │ ├── output2.txt │ ├── output3.txt │ ├── output4.txt │ ├── testfile1.txt │ ├── testfile2.txt │ ├── testfile3.txt │ ├── testfile4.txt │ └── testfiles.zip ├── src ├── Compiler.java ├── backend │ ├── AbsoluteAddress.java │ ├── Address.java │ ├── AsciizDirective.java │ ├── ColorScheduler.java │ ├── Directive.java │ ├── Element.java │ ├── Imm.java │ ├── LoopScheduler.java │ ├── MIPSCode.java │ ├── Reg.java │ ├── RegAllocator.java │ ├── RegScheduler.java │ ├── RelativeAddress.java │ ├── SymbolList.java │ ├── TagTable.java │ ├── Translator.java │ └── WordDirective.java ├── exceptions │ └── SysYException.java ├── frontend │ ├── AssignNode.java │ ├── BinaryExprNode.java │ ├── BlockItemNode.java │ ├── BlockNode.java │ ├── BranchNode.java │ ├── BreakNode.java │ ├── ConstNode.java │ ├── ContNode.java │ ├── DeclNode.java │ ├── DefNode.java │ ├── ExprNode.java │ ├── FuncBlockNode.java │ ├── FuncCallNode.java │ ├── FuncDefNode.java │ ├── FuncParamNode.java │ ├── GetIntNode.java │ ├── GlobalNode.java │ ├── ICodeInfo.java │ ├── LValNode.java │ ├── LoopNode.java │ ├── NopNode.java │ ├── ParserController.java │ ├── ParserUnit.java │ ├── PrintNode.java │ ├── ReturnNode.java │ ├── StmtNode.java │ ├── SymbolTable.java │ ├── SyntaxNode.java │ ├── SyntaxTreeBuilder.java │ ├── Token.java │ ├── TokenSupporter.java │ ├── Tokenizer.java │ ├── UnaryExprNode.java │ └── VarDefNode.java ├── midend │ ├── AddrValue.java │ ├── AssignBinaryOperation.java │ ├── AssignUnaryOperation.java │ ├── Assignment.java │ ├── BasicBlock.java │ ├── BasicBlockOptimizer.java │ ├── Branch.java │ ├── CallFunction.java │ ├── Declaration.java │ ├── Definite.java │ ├── Exit.java │ ├── FlowGraph.java │ ├── FuncEntry.java │ ├── GetInt.java │ ├── ImmValue.java │ ├── IntermediateCode.java │ ├── IntermediateVirtualMachine.java │ ├── IntroSpace.java │ ├── Jump.java │ ├── LabelTable.java │ ├── Load.java │ ├── Move.java │ ├── Nop.java │ ├── Optimizer.java │ ├── ParameterFetch.java │ ├── Print.java │ ├── ProbablyCombinable.java │ ├── ProbablyConst.java │ ├── PushArgument.java │ ├── Return.java │ ├── Save.java │ ├── Usage.java │ ├── Value.java │ └── WordValue.java └── utils │ ├── LinkedNode.java │ ├── Pair.java │ └── SimpleIO.java └── testcases ├── A ├── input1.txt ├── input10.txt ├── input11.txt ├── input12.txt ├── input13.txt ├── input14.txt ├── input15.txt ├── input16.txt ├── input17.txt ├── input18.txt ├── input19.txt ├── input2.txt ├── input20.txt ├── input21.txt ├── input22.txt ├── input23.txt ├── input24.txt ├── input25.txt ├── input26.txt ├── input3.txt ├── input4.txt ├── input5.txt ├── input6.txt ├── input7.txt ├── input8.txt ├── input9.txt ├── output1.txt ├── output10.txt ├── output11.txt ├── output12.txt ├── output13.txt ├── output14.txt ├── output15.txt ├── output16.txt ├── output17.txt ├── output18.txt ├── output19.txt ├── output2.txt ├── output20.txt ├── output21.txt ├── output22.txt ├── output23.txt ├── output24.txt ├── output25.txt ├── output26.txt ├── output3.txt ├── output4.txt ├── output5.txt ├── output6.txt ├── output7.txt ├── output8.txt ├── output9.txt ├── testfile1.txt ├── testfile10.txt ├── testfile11.txt ├── testfile12.txt ├── testfile13.txt ├── testfile14.txt ├── testfile15.txt ├── testfile16.txt ├── testfile17.txt ├── testfile18.txt ├── testfile19.txt ├── testfile2.txt ├── testfile20.txt ├── testfile21.txt ├── testfile22.txt ├── testfile23.txt ├── testfile24.txt ├── testfile25.txt ├── testfile26.txt ├── testfile3.txt ├── testfile4.txt ├── testfile5.txt ├── testfile6.txt ├── testfile7.txt ├── testfile8.txt └── testfile9.txt ├── B ├── input1.txt ├── input10.txt ├── input11.txt ├── input12.txt ├── input13.txt ├── input14.txt ├── input15.txt ├── input16.txt ├── input17.txt ├── input18.txt ├── input19.txt ├── input2.txt ├── input20.txt ├── input21.txt ├── input22.txt ├── input23.txt ├── input24.txt ├── input25.txt ├── input26.txt ├── input27.txt ├── input3.txt ├── input4.txt ├── input5.txt ├── input6.txt ├── input7.txt ├── input8.txt ├── input9.txt ├── output1.txt ├── output10.txt ├── output11.txt ├── output12.txt ├── output13.txt ├── output14.txt ├── output15.txt ├── output16.txt ├── output17.txt ├── output18.txt ├── output19.txt ├── output2.txt ├── output20.txt ├── output21.txt ├── output22.txt ├── output23.txt ├── output24.txt ├── output25.txt ├── output26.txt ├── output27.txt ├── output3.txt ├── output4.txt ├── output5.txt ├── output6.txt ├── output7.txt ├── output8.txt ├── output9.txt ├── testfile1.txt ├── testfile10.txt ├── testfile11.txt ├── testfile12.txt ├── testfile13.txt ├── testfile14.txt ├── testfile15.txt ├── testfile16.txt ├── testfile17.txt ├── testfile18.txt ├── testfile19.txt ├── testfile2.txt ├── testfile20.txt ├── testfile21.txt ├── testfile22.txt ├── testfile23.txt ├── testfile24.txt ├── testfile25.txt ├── testfile26.txt ├── testfile27.txt ├── testfile3.txt ├── testfile4.txt ├── testfile5.txt ├── testfile6.txt ├── testfile7.txt ├── testfile8.txt └── testfile9.txt └── C ├── input1.txt ├── input10.txt ├── input11.txt ├── input12.txt ├── input13.txt ├── input14.txt ├── input15.txt ├── input16.txt ├── input17.txt ├── input18.txt ├── input19.txt ├── input2.txt ├── input20.txt ├── input21.txt ├── input22.txt ├── input23.txt ├── input24.txt ├── input25.txt ├── input26.txt ├── input27.txt ├── input28.txt ├── input29.txt ├── input3.txt ├── input4.txt ├── input5.txt ├── input6.txt ├── input7.txt ├── input8.txt ├── input9.txt ├── output1.txt ├── output10.txt ├── output11.txt ├── output12.txt ├── output13.txt ├── output14.txt ├── output15.txt ├── output16.txt ├── output17.txt ├── output18.txt ├── output19.txt ├── output2.txt ├── output20.txt ├── output21.txt ├── output22.txt ├── output23.txt ├── output24.txt ├── output25.txt ├── output26.txt ├── output27.txt ├── output28.txt ├── output29.txt ├── output3.txt ├── output4.txt ├── output5.txt ├── output6.txt ├── output7.txt ├── output8.txt ├── output9.txt ├── testfile1.txt ├── testfile10.txt ├── testfile11.txt ├── testfile12.txt ├── testfile13.txt ├── testfile14.txt ├── testfile15.txt ├── testfile16.txt ├── testfile17.txt ├── testfile18.txt ├── testfile19.txt ├── testfile2.txt ├── testfile20.txt ├── testfile21.txt ├── testfile22.txt ├── testfile23.txt ├── testfile24.txt ├── testfile25.txt ├── testfile26.txt ├── testfile27.txt ├── testfile28.txt ├── testfile29.txt ├── testfile3.txt ├── testfile4.txt ├── testfile5.txt ├── testfile6.txt ├── testfile7.txt ├── testfile8.txt └── testfile9.txt /ir-test/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd /home/coekjan/prj/mipsysy-compiler/ir-test || exit 1 3 | path=$1 4 | li=$(find ../testcases/"$path" -name "testfile*.txt") 5 | for fn in $li 6 | do 7 | n=$(echo "$fn" | tr -cd "0-9") 8 | cp ../testcases/"$path"/testfile"$n".txt ./testfile.txt 9 | cp ../testcases/"$path"/input"$n".txt ./input.txt 10 | cp ../testcases/"$path"/output"$n".txt ./std.txt 11 | echo "> RUNNING $1 | testfile$n.txt" 12 | java -jar ../out/artifacts/mipsysy_compiler_jar/mipsysy-compiler.jar -ea --ir < ./input.txt > ./out.txt 13 | if ! diff ./std.txt ./out.txt --suppress-common-lines --side-by-side --ignore-all-space --ignore-blank-lines 14 | then 15 | echo WRONG ANSWER! 16 | exit 1 17 | fi 18 | done 19 | 20 | echo "$1" ACCEPTED! -------------------------------------------------------------------------------- /mips-test/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd /home/coekjan/prj/mipsysy-compiler/mips-test || exit 1 3 | path=$1 4 | li=$(find ../testcases/"$path" -name "testfile*.txt") 5 | for fn in $li 6 | do 7 | n=$(echo "$fn" | tr -cd "0-9") 8 | cp ../testcases/"$path"/testfile"$n".txt ./testfile.txt 9 | cp ../testcases/"$path"/input"$n".txt ./input.txt 10 | cp ../testcases/"$path"/output"$n".txt ./std.txt 11 | echo "> Compiling $1 | testfile$n.txt" 12 | java -jar ../out/artifacts/mipsysy_compiler_jar/mipsysy-compiler.jar -ea 13 | echo "> Compilation finished! Running testfile$n.txt" 14 | java -jar ../Mars-Compile-2021.jar ./mips.txt nc mc Default < ./input.txt > ./out.txt 15 | if ! diff ./std.txt ./out.txt --suppress-common-lines --side-by-side --ignore-all-space --ignore-blank-lines 16 | then 17 | echo WRONG ANSWER! 18 | exit 1 19 | fi 20 | done 21 | 22 | echo "$1" ACCEPTED! -------------------------------------------------------------------------------- /prepare/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo '#include "sysy_header.h"' > tmp.c 3 | cat $1 >> tmp.c 4 | gcc tmp.c -I ./include -o out/$1.exe 5 | rm tmp.c -------------------------------------------------------------------------------- /prepare/include/sysy_header.h: -------------------------------------------------------------------------------- 1 | #ifndef __SYSY__ 2 | #define __SYSY__ 3 | 4 | #include 5 | 6 | static inline int getint() { 7 | int x; 8 | scanf("%d", &x); 9 | return x; 10 | } 11 | 12 | #endif -------------------------------------------------------------------------------- /prepare/out/test/testfile1.txt.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coekjan/MIPSysY-Compiler/772e50d5f4ac1114c8a9f880264a659d99575cb2/prepare/out/test/testfile1.txt.exe -------------------------------------------------------------------------------- /prepare/out/test/testfile2.txt.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coekjan/MIPSysY-Compiler/772e50d5f4ac1114c8a9f880264a659d99575cb2/prepare/out/test/testfile2.txt.exe -------------------------------------------------------------------------------- /prepare/out/test/testfile3.txt.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coekjan/MIPSysY-Compiler/772e50d5f4ac1114c8a9f880264a659d99575cb2/prepare/out/test/testfile3.txt.exe -------------------------------------------------------------------------------- /prepare/out/test/testfile4.txt.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coekjan/MIPSysY-Compiler/772e50d5f4ac1114c8a9f880264a659d99575cb2/prepare/out/test/testfile4.txt.exe -------------------------------------------------------------------------------- /prepare/test/input1.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 0 3 | 1 4 | 6 5 | 8 6 | 20 7 | 30 8 | -------------------------------------------------------------------------------- /prepare/test/input2.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 0 3 | 1 4 | 2 5 | 3 6 | 4 7 | 5 8 | 10 9 | 11 10 | 30 11 | 20 12 | -------------------------------------------------------------------------------- /prepare/test/input3.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 19123412 53 3 | 12142344 89 4 | 12354123 35 5 | 32151245 65 6 | 21532521 93 7 | 21654212 13 8 | 12312654 89 9 | 56335232 87 10 | 15687643 78 11 | 56323432 78 12 | -------------------------------------------------------------------------------- /prepare/test/input4.txt: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /prepare/test/output1.txt: -------------------------------------------------------------------------------- 1 | 19373372 2 | a[n] = a[n - 1] + a[n - 2] (for different init values) 3 | /* input = 0 */ 4 | Error! 5 | /* input = 1 */ 6 | 1 1 7 | 1 0 8 | when a[0] = 0, a[1] = 1 ==> a[1] = 1 9 | when a[0] = 1, a[1] = 1 ==> a[1] = 1 10 | when a[0] = 1, a[1] = 2 ==> a[1] = 2 11 | when a[0] = 1, a[1] = 3 ==> a[1] = 3 12 | when a[0] = 3, a[1] = 4 ==> a[1] = 4 13 | when a[0] = 1, a[1] = -1 ==> a[1] = -1 14 | ////////////////////////////////////// 15 | /* input = 6 */ 16 | 13 8 17 | 8 5 18 | when a[0] = 0, a[1] = 1 ==> a[6] = 8 19 | when a[0] = 1, a[1] = 1 ==> a[6] = 13 20 | when a[0] = 1, a[1] = 2 ==> a[6] = 21 21 | when a[0] = 1, a[1] = 3 ==> a[6] = 29 22 | when a[0] = 3, a[1] = 4 ==> a[6] = 47 23 | when a[0] = 1, a[1] = -1 ==> a[6] = -3 24 | ////////////////////////////////////// 25 | /* input = 8 */ 26 | 34 21 27 | 21 13 28 | when a[0] = 0, a[1] = 1 ==> a[8] = 21 29 | when a[0] = 1, a[1] = 1 ==> a[8] = 34 30 | when a[0] = 1, a[1] = 2 ==> a[8] = 55 31 | when a[0] = 1, a[1] = 3 ==> a[8] = 76 32 | when a[0] = 3, a[1] = 4 ==> a[8] = 123 33 | when a[0] = 1, a[1] = -1 ==> a[8] = -8 34 | ////////////////////////////////////// 35 | /* input = 20 */ 36 | 10946 6765 37 | 6765 4181 38 | when a[0] = 0, a[1] = 1 ==> a[20] = 6765 39 | when a[0] = 1, a[1] = 1 ==> a[20] = 10946 40 | when a[0] = 1, a[1] = 2 ==> a[20] = 17711 41 | when a[0] = 1, a[1] = 3 ==> a[20] = 24476 42 | when a[0] = 3, a[1] = 4 ==> a[20] = 39603 43 | when a[0] = 1, a[1] = -1 ==> a[20] = -2584 44 | ////////////////////////////////////// 45 | /* input = 30 */ 46 | 1346269 832040 47 | 832040 514229 48 | when a[0] = 0, a[1] = 1 ==> a[30] = 832040 49 | when a[0] = 1, a[1] = 1 ==> a[30] = 1346269 50 | when a[0] = 1, a[1] = 2 ==> a[30] = 2178309 51 | when a[0] = 1, a[1] = 3 ==> a[30] = 3010349 52 | when a[0] = 3, a[1] = 4 ==> a[30] = 4870847 53 | when a[0] = 1, a[1] = -1 ==> a[30] = -317811 54 | ////////////////////////////////////// 55 | /****************** END ******************/ 56 | -------------------------------------------------------------------------------- /prepare/test/output3.txt: -------------------------------------------------------------------------------- 1 | 19373372 2 | input > 19123412 53 3 | input > 12142344 89 4 | input > 12354123 35 5 | input > 32151245 65 6 | input > 21532521 93 7 | input > 21654212 13 8 | input > 12312654 89 9 | input > 56335232 87 10 | input > 15687643 78 11 | input > 56323432 78 12 | 19123412 -> 53 13 | 12142344 -> 89 14 | 12354123 -> 35 15 | 32151245 -> 65 16 | 21532521 -> 93 17 | 21654212 -> 13 18 | 12312654 -> 89 19 | 56335232 -> 87 20 | 15687643 -> 78 21 | 56323432 -> 78 22 | swap <19123412 53> <-> <12142344 89> 23 | swap <12142344 89> <-> <21532521 93> 24 | swap <19123412 53> <-> <32151245 65> 25 | swap <32151245 65> <-> <12142344 89> 26 | swap <12354123 35> <-> <19123412 53> 27 | swap <19123412 53> <-> <32151245 65> 28 | swap <32151245 65> <-> <12312654 89> 29 | swap <12354123 35> <-> <19123412 53> 30 | swap <19123412 53> <-> <32151245 65> 31 | swap <32151245 65> <-> <56335232 87> 32 | swap <12354123 35> <-> <19123412 53> 33 | swap <19123412 53> <-> <32151245 65> 34 | swap <32151245 65> <-> <15687643 78> 35 | swap <21654212 13> <-> <12354123 35> 36 | swap <12354123 35> <-> <19123412 53> 37 | swap <19123412 53> <-> <32151245 65> 38 | swap <32151245 65> <-> <56323432 78> 39 | swap <21654212 13> <-> <12354123 35> 40 | swap <12354123 35> <-> <19123412 53> 41 | swap <19123412 53> <-> <32151245 65> 42 | swap <21654212 13> <-> <12354123 35> 43 | swap <12354123 35> <-> <19123412 53> 44 | swap <21654212 13> <-> <12354123 35> 45 | 9 46 | 21532521 -> 93 47 | 12142344 -> 89 48 | 12312654 -> 89 49 | 56335232 -> 87 50 | 15687643 -> 78 51 | 56323432 -> 78 52 | 32151245 -> 65 53 | 19123412 -> 53 54 | 12354123 -> 35 55 | 21654212 -> 13 56 | -------------------------------------------------------------------------------- /prepare/test/output4.txt: -------------------------------------------------------------------------------- 1 | 19373372 2 | fact[10] = 3628800 3 | fact[1] = 1 4 | fact[2] = 2 5 | fact[3] = 6 6 | fact[4] = 24 7 | fact[5] = 120 8 | fact[6] = 720 9 | fact[7] = 5040 10 | fact[8] = 40320 11 | -------------------------------------------------------------------------------- /prepare/test/testfile2.txt: -------------------------------------------------------------------------------- 1 | int fib_matrix[2][2] = {{1, 1}, {1, 0}}; 2 | const int __x = 0, __y = 9; 3 | 4 | void __vec_mul(int res[], int mat[][2], int vec[]) { 5 | res[0] = vec[0] * mat[0][0] + vec[1] * mat[0][1]; 6 | res[1] = vec[0] * mat[1][0] + vec[1] * mat[1][1]; 7 | return; 8 | } 9 | 10 | void __mat_mul(int res[][2], int x[][2], int y[][2]) { 11 | res[0][0] = x[0][0] * y[0][0] + x[0][1] * y[1][0]; 12 | res[0][1] = x[0][0] * y[0][1] + x[0][1] * y[1][1]; 13 | res[1][0] = x[1][0] * y[0][0] + x[1][1] * y[1][0]; 14 | res[1][1] = x[1][0] * y[0][1] + x[1][1] * y[1][1]; 15 | return; 16 | } 17 | 18 | int __power(int n, int cur[][2], int res[][2]) { 19 | if (n == 1) { 20 | res[0][0] = cur[0][0]; 21 | res[0][1] = cur[0][1]; 22 | res[1][0] = cur[1][0]; 23 | res[1][1] = cur[1][1]; 24 | return 0; 25 | } else { 26 | __mat_mul(res, cur, fib_matrix); 27 | cur[0][0] = res[0][0]; 28 | cur[0][1] = res[0][1]; 29 | cur[1][0] = res[1][0]; 30 | cur[1][1] = res[1][1]; 31 | return __power(n - 1, cur, res); 32 | } 33 | return 0; 34 | } 35 | 36 | int power(int n, int res[][2]) { 37 | if (n < 1) return -1; 38 | int temp[2][2] = {{1, 1}, {1, 0}}; 39 | return __power(n, temp, res); 40 | } 41 | 42 | int main() { 43 | const int down = 0; 44 | int n; 45 | n = getint(); 46 | { 47 | } 48 | int tmp[2] = {0, 0}; 49 | int res[2][2]; 50 | int vec_list[6][2] = {{1, 0}, {1, 1}, {2, 1}, {3, 1}, {4, 3}, {-1, 1}}; 51 | printf("19373372\n"); 52 | printf("a[n] = a[n - 1] + a[n - 2] (for different init values)\n"); 53 | while (n > down) { 54 | int p; 55 | ; 56 | p = getint(); 57 | int ret = power(p, res); 58 | printf("/* input = %d */\n", p); 59 | if (!ret) { 60 | int i = 0; 61 | while (1) { 62 | __vec_mul(tmp, res, vec_list[i]); 63 | printf("when a[0] = %d, a[1] = %d ==> a[%d] = %d\n", vec_list[i][1], vec_list[i][0], p, tmp[1]); 64 | i = i + 1; 65 | if (i >= 6 && i != 0) break; 66 | else continue; 67 | } 68 | } 69 | printf("//////////////////////////////////////\n"); 70 | n = n - 1; 71 | } 72 | printf("/****************** END ******************/\n"); 73 | printf("");printf("");printf("");printf(""); 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /prepare/test/testfile3.txt: -------------------------------------------------------------------------------- 1 | int array[100][2]; 2 | int len = 0; 3 | 4 | void swap(int i, int j) { 5 | printf("swap <%d %d> <-> <%d %d>\n", array[i][0], array[i][1], array[j][0], array[j][1]); 6 | int tmp[2] = {array[i][0], array[i][1]}; 7 | array[i][0] = array[j][0]; 8 | array[i][1] = array[j][1]; 9 | array[j][0] = tmp[0]; 10 | array[j][1] = tmp[1]; 11 | return; 12 | } 13 | 14 | void sort() { 15 | int i, j; 16 | i = 0; 17 | while (i < len - 1) { 18 | int f = 0; 19 | j = i + 1; 20 | while (j < len) { 21 | if (array[i][1] < array[j][1]) { 22 | swap(i, j); 23 | f = 1; 24 | } else if (array[i][1] == array[j][1]) { 25 | if (array[i][0] > array[j][0]) { 26 | swap(i, j); 27 | f = 1; 28 | } 29 | } 30 | j = j + 1; 31 | } 32 | if (!f) { 33 | printf("%d\n", i); 34 | return; 35 | } 36 | i = i + 1; 37 | } 38 | printf("%d\n", i); 39 | return; 40 | } 41 | 42 | int main() { 43 | len = getint(); 44 | int i; 45 | printf("19373372\n"); 46 | i = 0; 47 | { 48 | int i = 100; 49 | } 50 | while (i < len) { 51 | int x; 52 | x = getint(); 53 | int y; 54 | y = getint(); 55 | printf("input > %d %d\n", x, y); 56 | array[i][0] = x; 57 | array[i][1] = y; 58 | i = i + 1; 59 | } 60 | i = 0; 61 | while (i < len) { 62 | printf("%d -> %d\n", array[i][0], array[i][1]); 63 | i = i + 1; 64 | } 65 | sort(); 66 | i = 0; 67 | while (i < len) { 68 | printf("%d -> %d\n", array[i][0], array[i][1]); 69 | i = i + 1; 70 | } 71 | printf("");printf("");printf("");printf("");printf(""); 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /prepare/test/testfile4.txt: -------------------------------------------------------------------------------- 1 | int __fact(int x, int r) { 2 | if (x <= 1) return r; 3 | else return __fact(x - 1, (r * x) % 19260817); 4 | return 0; 5 | } 6 | 7 | int fact(int x) { 8 | return __fact(x, 1); 9 | } 10 | 11 | int main() { 12 | int x; 13 | x = getint(); 14 | printf("19373372\n"); 15 | printf("fact[%d] = %d\n", x, fact(x)); 16 | printf("fact[1] = %d\n", fact(1)); 17 | printf("fact[2] = %d\n", fact(2)); 18 | printf("fact[3] = %d\n", fact(3)); 19 | printf("fact[4] = %d\n", fact(4)); 20 | printf("fact[5] = %d\n", fact(5)); 21 | printf("fact[6] = %d\n", fact(6)); 22 | printf("fact[7] = %d\n", fact(7)); 23 | printf("fact[8] = %d\n", fact(8)); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /prepare/test/testfiles.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coekjan/MIPSysY-Compiler/772e50d5f4ac1114c8a9f880264a659d99575cb2/prepare/test/testfiles.zip -------------------------------------------------------------------------------- /src/backend/AbsoluteAddress.java: -------------------------------------------------------------------------------- 1 | package backend; 2 | 3 | public class AbsoluteAddress extends Address { 4 | public final String label; 5 | 6 | public AbsoluteAddress(String label) { 7 | this.label = label; 8 | } 9 | 10 | @Override 11 | String display() { 12 | return label; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/backend/Address.java: -------------------------------------------------------------------------------- 1 | package backend; 2 | 3 | public abstract class Address { 4 | abstract String display(); 5 | 6 | @Override 7 | public String toString() { 8 | return display(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/backend/AsciizDirective.java: -------------------------------------------------------------------------------- 1 | package backend; 2 | 3 | public class AsciizDirective extends Directive { 4 | public final String string; 5 | 6 | public AsciizDirective(String label, String string) { 7 | super(label); 8 | this.string = string; 9 | } 10 | 11 | @Override 12 | String stringify() { 13 | return label + ": .asciiz \"" + string + "\""; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/backend/Directive.java: -------------------------------------------------------------------------------- 1 | package backend; 2 | 3 | public abstract class Directive extends MIPSCode { 4 | public final String label; 5 | 6 | public Directive(String label) { 7 | this.label = label; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/backend/Element.java: -------------------------------------------------------------------------------- 1 | package backend; 2 | 3 | public abstract class Element { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/backend/Imm.java: -------------------------------------------------------------------------------- 1 | package backend; 2 | 3 | public class Imm extends Element { 4 | public static final Imm ZERO_IMM = new Imm(0); 5 | 6 | public final int value; 7 | 8 | public Imm(int value) { 9 | this.value = value; 10 | } 11 | 12 | @Override 13 | public String toString() { 14 | return String.valueOf(value); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/backend/LoopScheduler.java: -------------------------------------------------------------------------------- 1 | package backend; 2 | 3 | import midend.IntermediateCode; 4 | import midend.Value; 5 | import utils.Pair; 6 | 7 | import java.util.*; 8 | 9 | public class LoopScheduler implements RegScheduler { 10 | private final Map cur = new HashMap<>(); 11 | private final List inUse = new LinkedList<>(); 12 | private final List free = new LinkedList<>(regs); 13 | 14 | @Override 15 | public Pair overflow(IntermediateCode code, Collection holdRegs) { 16 | assert !inUse.isEmpty(); 17 | final Reg reg = getReg(inUse, holdRegs); 18 | final Value v = cur.remove(reg); 19 | inUse.remove(reg); 20 | free.add(0, reg); 21 | return Pair.of(v, reg); 22 | } 23 | 24 | private Reg getReg(List from, Collection holdRegs) { 25 | for (Reg r : from) { 26 | if (!holdRegs.contains(r)) return r; 27 | } 28 | return null; 29 | } 30 | 31 | @Override 32 | public Optional allocReg(Value name, Collection holdRegs) { 33 | final Reg r; 34 | if (!free.isEmpty()) { 35 | r = free.remove(0); 36 | inUse.add(0, r); 37 | } else { 38 | return Optional.empty(); 39 | } 40 | cur.put(r, name); 41 | return Optional.of(r); 42 | } 43 | 44 | @Override 45 | public void remove(Reg reg) { 46 | inUse.remove(reg); 47 | free.add(0, reg); 48 | cur.remove(reg); 49 | } 50 | 51 | @Override 52 | public void clear() { 53 | cur.clear(); 54 | inUse.clear(); 55 | free.clear(); 56 | free.addAll(regs); 57 | } 58 | 59 | @Override 60 | public Optional find(Value name) { 61 | for (Reg r : inUse) { 62 | if (cur.get(r).equals(name)) { 63 | return Optional.of(r); 64 | } 65 | } 66 | return Optional.empty(); 67 | } 68 | 69 | @Override 70 | public Map current() { 71 | return cur; 72 | } 73 | 74 | @Override 75 | public void switchContext(String context) { 76 | clear(); 77 | } 78 | 79 | @Override 80 | public boolean active(IntermediateCode code, Value value) { 81 | return true; 82 | } 83 | 84 | @Override 85 | public boolean isGlobalReg(Reg reg) { 86 | return false; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/backend/RelativeAddress.java: -------------------------------------------------------------------------------- 1 | package backend; 2 | 3 | public class RelativeAddress extends Address { 4 | public final Reg base; 5 | public final int offset; 6 | 7 | RelativeAddress(Reg base, int offset) { 8 | this.base = base; 9 | this.offset = offset; 10 | } 11 | 12 | @Override 13 | String display() { 14 | return offset + "(" + base + ")"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/backend/SymbolList.java: -------------------------------------------------------------------------------- 1 | package backend; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class SymbolList { 7 | private final List globalDirectives = new ArrayList<>(); 8 | public final TagTable tagTable = new TagTable(); 9 | 10 | public void insertDirective(Directive directive) { 11 | globalDirectives.add(directive); 12 | } 13 | 14 | public String displayDirectives() { 15 | return ".data\n" + globalDirectives.stream().map(Directive::toString) 16 | .reduce((a, b) -> a + "\n" + b).orElse(""); 17 | } 18 | 19 | public List getGlobalDirectives() { 20 | return globalDirectives; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/backend/TagTable.java: -------------------------------------------------------------------------------- 1 | package backend; 2 | 3 | import java.util.*; 4 | 5 | public class TagTable { 6 | private final Map tagsMap = new HashMap<>(); 7 | private final Map> codeMap = new HashMap<>(); 8 | 9 | public MIPSCode find(String tag) { 10 | if (tagsMap.containsKey(tag)) return tagsMap.get(tag); 11 | throw new IllegalArgumentException(); 12 | } 13 | 14 | public Optional> find(MIPSCode code) { 15 | if (codeMap.containsKey(code)) return Optional.of(codeMap.get(code)); 16 | else return Optional.empty(); 17 | } 18 | 19 | public void assign(String tag, MIPSCode code) { 20 | tagsMap.put(tag, code); 21 | if (!codeMap.containsKey(code)) { 22 | codeMap.put(code, new LinkedList<>()); 23 | } 24 | codeMap.get(code).add(0, tag); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/backend/WordDirective.java: -------------------------------------------------------------------------------- 1 | package backend; 2 | 3 | import midend.Value; 4 | 5 | import java.util.Collections; 6 | import java.util.List; 7 | import java.util.Optional; 8 | 9 | public class WordDirective extends Directive { 10 | public final Value name; 11 | public final List values; 12 | 13 | public WordDirective(Value name, List values) { 14 | super(name.symbol.substring(0, name.symbol.indexOf('%') >= 0 ? name.symbol.indexOf('%') : name.symbol.length())); 15 | this.name = name; 16 | this.values = Collections.unmodifiableList(values); 17 | } 18 | 19 | @Override 20 | String stringify() { 21 | final Optional valueList = values.stream().map(Object::toString).reduce((x, y) -> x + ", " + y); 22 | assert valueList.isPresent(); 23 | return label + ": .word " + valueList.get(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/exceptions/SysYException.java: -------------------------------------------------------------------------------- 1 | package exceptions; 2 | 3 | public class SysYException extends Exception { 4 | 5 | public enum Code { 6 | a, b, c, d, e, f, g, h, i, j, k, l, m, u 7 | } 8 | 9 | public final Code code; 10 | 11 | public SysYException(Code code) { 12 | this.code = code; 13 | } 14 | 15 | public String stringify() { 16 | return code.name(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/frontend/BlockItemNode.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | 6 | public interface BlockItemNode extends SyntaxNode { 7 | default List findRet() { 8 | return Collections.emptyList(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/frontend/BreakNode.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | import exceptions.SysYException; 4 | import midend.IntermediateCode; 5 | import midend.Jump; 6 | import midend.LabelTable; 7 | import utils.Pair; 8 | 9 | public class BreakNode implements StmtNode { 10 | public final int line; 11 | 12 | public BreakNode(int line) { 13 | this.line = line; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | return "BREAK"; 19 | } 20 | 21 | @Override 22 | public SymbolTable check(SymbolTable symbolTable, boolean inLoop) throws SysYException { 23 | if (!inLoop) { 24 | errors.add(Pair.of(line, SysYException.Code.m)); 25 | } 26 | return symbolTable; 27 | } 28 | 29 | @Override 30 | public Pair simplify(SymbolTable symbolTable) { 31 | return Pair.of(symbolTable, this); 32 | } 33 | 34 | @Override 35 | public Pair iCode(LabelTable lt, SymbolTable st, String lpBegin, String lpEnd, int tc) { 36 | final IntermediateCode breakJump = new Jump(lpEnd); 37 | return Pair.of(st, new ICodeInfo(breakJump, breakJump, null, tc)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/frontend/ConstNode.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | import exceptions.SysYException; 4 | import midend.*; 5 | import utils.Pair; 6 | 7 | public class ConstNode implements ExprNode { 8 | public static final ConstNode ZERO = new ConstNode(0); 9 | public static final ConstNode IGNR = new ConstNode(Integer.MAX_VALUE); 10 | 11 | public final int constant; 12 | 13 | public ConstNode(Token constToken) { 14 | this(Integer.parseInt(constToken.content)); 15 | } 16 | 17 | public ConstNode(int constant) { 18 | this.constant = constant; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return String.valueOf(constant); 24 | } 25 | 26 | @Override 27 | public SymbolTable check(SymbolTable symbolTable, boolean inLoop) throws SysYException { 28 | return symbolTable; 29 | } 30 | 31 | @Override 32 | public Pair simplify(SymbolTable symbolTable) { 33 | return Pair.of(symbolTable, this); 34 | } 35 | 36 | @Override 37 | public Pair iCode(LabelTable lt, SymbolTable st, String lpBegin, String lpEnd, int tc) { 38 | final WordValue word = new WordValue(String.valueOf(tc + 1)); 39 | final IntermediateCode con = new Move(true, word, new ImmValue(constant)); 40 | return Pair.of(st, new ICodeInfo(con, con, word, tc + 1)); 41 | } 42 | 43 | @Override 44 | public ReturnType getRetType(SymbolTable symbolTable) { 45 | return ReturnType.INT; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/frontend/ContNode.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | import exceptions.SysYException; 4 | import midend.IntermediateCode; 5 | import midend.Jump; 6 | import midend.LabelTable; 7 | import utils.Pair; 8 | 9 | public class ContNode implements StmtNode { 10 | public final int line; 11 | 12 | public ContNode(int line) { 13 | this.line = line; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | return "CONTINUE"; 19 | } 20 | 21 | @Override 22 | public SymbolTable check(SymbolTable symbolTable, boolean inLoop) throws SysYException { 23 | if (!inLoop) { 24 | errors.add(Pair.of(line, SysYException.Code.m)); 25 | } 26 | return symbolTable; 27 | } 28 | 29 | @Override 30 | public Pair simplify(SymbolTable symbolTable) { 31 | return Pair.of(symbolTable, this); 32 | } 33 | 34 | @Override 35 | public Pair iCode(LabelTable lt, SymbolTable st, String lpBegin, String lpEnd, int tc) { 36 | final IntermediateCode contJump = new Jump(lpBegin); 37 | return Pair.of(st, new ICodeInfo(contJump, contJump, null, tc)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/frontend/DefNode.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | import exceptions.SysYException; 4 | import midend.LabelTable; 5 | import utils.Pair; 6 | 7 | import java.util.Collections; 8 | import java.util.LinkedList; 9 | import java.util.List; 10 | import java.util.Objects; 11 | 12 | public class DefNode implements SyntaxNode { 13 | public final String name; 14 | public final int line; 15 | public final Pair dimensions; 16 | public final List initValues; 17 | 18 | public DefNode(Token identifier, Pair dimensions, List initValues) { 19 | this(identifier.content, identifier.line, dimensions, initValues); 20 | } 21 | 22 | public DefNode(String name, int line, Pair dimensions, List initValues) { 23 | this.name = name; 24 | this.line = line; 25 | this.dimensions = dimensions; 26 | this.initValues = Collections.unmodifiableList(initValues); 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return name + dimensions.toString() + " := {" + initValues.stream() 32 | .map(Objects::toString).reduce((x, y) -> x + ", " + y).orElse("") + "}"; 33 | } 34 | 35 | @Override 36 | public SymbolTable check(SymbolTable symbolTable, boolean inLoop) throws SysYException { 37 | dimensions.first.check(symbolTable, inLoop); 38 | dimensions.second.check(symbolTable, inLoop); 39 | for (ExprNode initValue : initValues) { 40 | initValue.check(symbolTable, inLoop); 41 | } 42 | return symbolTable; 43 | } 44 | 45 | @Override 46 | public Pair simplify(SymbolTable symbolTable) { 47 | final ExprNode f = (ExprNode) dimensions.first.simplify(symbolTable).second; 48 | final ExprNode s = (ExprNode) dimensions.second.simplify(symbolTable).second; 49 | final List simInit = new LinkedList<>(); 50 | for (ExprNode initValue : initValues) { 51 | final Pair p = initValue.simplify(symbolTable); 52 | simInit.add((ExprNode) p.second); 53 | } 54 | return Pair.of(symbolTable, new DefNode(name, line, Pair.of(f, s), simInit)); 55 | } 56 | 57 | @Override 58 | public Pair iCode(LabelTable lt, SymbolTable st, String lpBegin, String lpEnd, int tc) { 59 | // Should not be called 60 | throw new IllegalAccessError(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/frontend/ExprNode.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | import exceptions.SysYException; 4 | 5 | public interface ExprNode extends StmtNode { 6 | enum ReturnType { 7 | VOID, INT, DIM1, DIM2 8 | } 9 | 10 | ReturnType getRetType(SymbolTable symbolTable) throws SysYException; 11 | } 12 | -------------------------------------------------------------------------------- /src/frontend/FuncBlockNode.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | import exceptions.SysYException; 4 | import midend.IntermediateCode; 5 | import midend.LabelTable; 6 | import midend.Return; 7 | import utils.Pair; 8 | 9 | import java.util.List; 10 | 11 | public class FuncBlockNode extends BlockNode { 12 | public final boolean hasReturn; 13 | public final int endLine; 14 | 15 | public FuncBlockNode(List items, boolean hasReturn, int endLine) { 16 | super(items); 17 | this.hasReturn = hasReturn; 18 | this.endLine = endLine; 19 | } 20 | 21 | @Override 22 | public Pair simplify(SymbolTable symbolTable) { 23 | final Pair p = super.simplify(symbolTable); 24 | final BlockNode blockNode = (BlockNode) p.second; 25 | return Pair.of(p.first, new FuncBlockNode(blockNode.items, hasReturn, endLine)); 26 | } 27 | 28 | @Override 29 | public SymbolTable check(SymbolTable symbolTable, boolean inLoop) throws SysYException { 30 | super.check(symbolTable, inLoop); 31 | if (hasReturn && (items.isEmpty() || !(items.get(items.size() - 1) instanceof ReturnNode))) { 32 | errors.add(Pair.of(endLine, SysYException.Code.g)); 33 | } 34 | final List returnNodes = findRet(); 35 | if (!hasReturn) { 36 | for (ReturnNode node : returnNodes) { 37 | if (node.returnValue != null) { 38 | errors.add(Pair.of(node.line, SysYException.Code.f)); 39 | } 40 | } 41 | } 42 | return symbolTable; 43 | } 44 | 45 | @Override 46 | public Pair iCode(LabelTable lt, SymbolTable st, String lpBegin, String lpEnd, int tc) { 47 | final Pair p = super.iCode(lt, st, lpBegin, lpEnd, tc); 48 | final IntermediateCode ret = new Return(); 49 | p.second.second.link(ret); 50 | return Pair.of(p.first, new ICodeInfo(p.second.first, ret, null, p.second.tempCount)); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/frontend/FuncParamNode.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | import exceptions.SysYException; 4 | import midend.*; 5 | import utils.Pair; 6 | 7 | import static frontend.ConstNode.ZERO; 8 | 9 | public class FuncParamNode implements SyntaxNode { 10 | public final String name; 11 | public final int line; 12 | public final Pair dimensions; 13 | 14 | public FuncParamNode(Token identifier, Pair dimensions) { 15 | this(identifier.content, identifier.line, dimensions); 16 | } 17 | 18 | public FuncParamNode(String name, int line, Pair dimensions) { 19 | this.name = name; 20 | this.line = line; 21 | this.dimensions = dimensions; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return name + dimensions.toString(); 27 | } 28 | 29 | @Override 30 | public SymbolTable check(SymbolTable symbolTable, boolean inLoop) throws SysYException { 31 | dimensions.first.check(symbolTable, inLoop); 32 | dimensions.second.check(symbolTable, inLoop); 33 | return symbolTable; 34 | } 35 | 36 | @Override 37 | public Pair simplify(SymbolTable symbolTable) { 38 | final ExprNode f = (ExprNode) dimensions.first.simplify(symbolTable).second; 39 | final ExprNode s = (ExprNode) dimensions.second.simplify(symbolTable).second; 40 | return Pair.of(symbolTable, new FuncParamNode(name, line, Pair.of(f, s))); 41 | } 42 | 43 | @Override 44 | public Pair iCode(LabelTable lt, SymbolTable st, String lpBegin, String lpEnd, int tc) { 45 | if (dimensions.first == ZERO && dimensions.second == ZERO) { 46 | final IntermediateCode word = new ParameterFetch(new WordValue(name + "%" + st.tellDepth())); 47 | return Pair.of(st, new ICodeInfo(word, word, null, tc)); 48 | } else { 49 | final IntermediateCode addr = new ParameterFetch(new AddrValue(name + "%" + st.tellDepth())); 50 | return Pair.of(st, new ICodeInfo(addr, addr, null, tc)); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/frontend/GetIntNode.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | import exceptions.SysYException; 4 | import midend.*; 5 | import utils.Pair; 6 | 7 | import java.util.Collections; 8 | 9 | public class GetIntNode extends FuncCallNode { 10 | public GetIntNode(Token identifier) { 11 | super(identifier, Collections.emptyList()); 12 | } 13 | 14 | public GetIntNode(String name, int line) { 15 | super(name, line, Collections.emptyList()); 16 | } 17 | 18 | @Override 19 | public SymbolTable check(SymbolTable symbolTable, boolean inLoop) throws SysYException { 20 | return symbolTable; 21 | } 22 | 23 | @Override 24 | public Pair simplify(SymbolTable symbolTable) { 25 | return Pair.of(symbolTable, this); 26 | } 27 | 28 | @Override 29 | public ReturnType getRetType(SymbolTable symbolTable) { 30 | return ReturnType.INT; 31 | } 32 | 33 | @Override 34 | public Pair iCode(LabelTable lt, SymbolTable st, String lpBegin, String lpEnd, int tc) { 35 | final IntermediateCode head = new GetInt(); 36 | final Value res = new WordValue(String.valueOf(tc + 1)); 37 | final IntermediateCode assign = new Move(true, res, new WordValue(Return.RET_SYM)); 38 | head.link(assign); 39 | return Pair.of(st, new ICodeInfo(head, assign, res, tc + 1)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/frontend/ICodeInfo.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | import midend.IntermediateCode; 4 | import midend.Value; 5 | import utils.Pair; 6 | 7 | public class ICodeInfo extends Pair { 8 | public final Value finalSym; 9 | public final int tempCount; 10 | 11 | public ICodeInfo(IntermediateCode first, IntermediateCode second, Value finalSym, int tempCount) { 12 | super(first, second); 13 | this.finalSym = finalSym; 14 | this.tempCount = tempCount; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/frontend/NopNode.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | import exceptions.SysYException; 4 | import midend.IntermediateCode; 5 | import midend.LabelTable; 6 | import midend.Nop; 7 | import utils.Pair; 8 | 9 | public class NopNode implements StmtNode { 10 | public static final NopNode NOP = new NopNode(); 11 | 12 | private NopNode() { 13 | } 14 | 15 | @Override 16 | public String toString() { 17 | return "NOP"; 18 | } 19 | 20 | @Override 21 | public SymbolTable check(SymbolTable symbolTable, boolean inLoop) throws SysYException { 22 | return symbolTable; 23 | } 24 | 25 | @Override 26 | public Pair simplify(SymbolTable symbolTable) { 27 | return Pair.of(symbolTable, this); 28 | } 29 | 30 | @Override 31 | public Pair iCode(LabelTable lt, SymbolTable st, String lpBegin, String lpEnd, int tc) { 32 | final IntermediateCode nop = new Nop(); 33 | return Pair.of(st, new ICodeInfo(nop, nop, null, tc)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/frontend/ParserUnit.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | public class ParserUnit { 8 | public final String name; 9 | public final List derivations; 10 | 11 | public ParserUnit(String name, List units) { 12 | this.name = name; 13 | this.derivations = Collections.unmodifiableList(new ArrayList<>(units)); 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | return derivations.stream() 19 | .map(ParserUnit::toString) 20 | .reduce((s1, s2) -> s1 + "\n" + s2).orElse("") + "\n<" + name + ">"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/frontend/PrintNode.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | import exceptions.SysYException; 4 | import midend.*; 5 | import utils.Pair; 6 | 7 | import java.util.LinkedList; 8 | import java.util.List; 9 | 10 | public class PrintNode extends FuncCallNode { 11 | public final String strNode; 12 | 13 | public PrintNode(Token identifier, String strNode, List arguments) { 14 | super(identifier, arguments); 15 | this.strNode = strNode; 16 | } 17 | 18 | public PrintNode(String name, int line, String strNode, List arguments) { 19 | super(name, line, arguments); 20 | this.strNode = strNode; 21 | } 22 | 23 | @Override 24 | public SymbolTable check(SymbolTable symbolTable, boolean inLoop) throws SysYException { 25 | for (ExprNode node : arguments) { 26 | node.check(symbolTable, inLoop); 27 | } 28 | if (strNode.split("%d").length - 1 != arguments.size()) { 29 | errors.add(Pair.of(line, SysYException.Code.l)); 30 | } 31 | return symbolTable; 32 | } 33 | 34 | @Override 35 | public Pair simplify(SymbolTable symbolTable) { 36 | final List simArgs = new LinkedList<>(); 37 | for (ExprNode exprNode : arguments) { 38 | simArgs.add((ExprNode) exprNode.simplify(symbolTable).second); 39 | } 40 | return Pair.of(symbolTable, new PrintNode(name, line, strNode, simArgs)); 41 | } 42 | 43 | @Override 44 | public ReturnType getRetType(SymbolTable symbolTable) { 45 | return ReturnType.VOID; 46 | } 47 | 48 | @Override 49 | public Pair iCode(LabelTable lt, SymbolTable st, String lpBegin, String lpEnd, int tc) { 50 | int tempCount = tc; 51 | IntermediateCode last = new Nop(); 52 | final IntermediateCode head = last; 53 | final List args = new LinkedList<>(); 54 | for (int i = arguments.size() - 1; i >= 0; i--) { 55 | final ExprNode exprNode = arguments.get(i); 56 | final ICodeInfo code = exprNode.iCode(lt, st, lpBegin, lpEnd, tempCount).second; 57 | args.add(code.finalSym); 58 | tempCount = code.tempCount; 59 | last.link(code.first); 60 | last = code.second; 61 | } 62 | for (Value arg : args) { 63 | last = last.link(new PushArgument(arg)); 64 | } 65 | final IntermediateCode print = new Print(strNode); 66 | last.link(print); 67 | return Pair.of(st, new ICodeInfo(head, print, null, tempCount)); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/frontend/ReturnNode.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | import exceptions.SysYException; 4 | import midend.IntermediateCode; 5 | import midend.LabelTable; 6 | import midend.Return; 7 | import utils.Pair; 8 | 9 | import java.util.Collections; 10 | import java.util.List; 11 | 12 | public class ReturnNode implements StmtNode { 13 | public final int line; 14 | public final ExprNode returnValue; 15 | 16 | public ReturnNode(int line) { 17 | this(line, null); 18 | } 19 | 20 | public ReturnNode(int line, ExprNode returnValue) { 21 | this.line = line; 22 | this.returnValue = returnValue; 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | if (returnValue == null) { 28 | return "RETURN"; 29 | } 30 | return "RETURN " + returnValue; 31 | } 32 | 33 | @Override 34 | public List findRet() { 35 | return Collections.singletonList(this); 36 | } 37 | 38 | @Override 39 | public SymbolTable check(SymbolTable symbolTable, boolean inLoop) throws SysYException { 40 | if (returnValue != null) returnValue.check(symbolTable, inLoop); 41 | return symbolTable; 42 | } 43 | 44 | @Override 45 | public Pair simplify(SymbolTable symbolTable) { 46 | if (returnValue != null) return Pair.of(symbolTable, 47 | new ReturnNode(line, (ExprNode) returnValue.simplify(symbolTable).second)); 48 | return Pair.of(symbolTable, this); 49 | } 50 | 51 | @Override 52 | public Pair iCode(LabelTable lt, SymbolTable st, String lpBegin, String lpEnd, int tc) { 53 | if (returnValue != null) { 54 | final ICodeInfo exprCode = returnValue.iCode(lt, st, lpBegin, lpEnd, tc).second; 55 | final IntermediateCode ret = new Return(exprCode.finalSym); 56 | exprCode.second.link(ret); 57 | return Pair.of(st, new ICodeInfo(exprCode.first, ret, null, exprCode.tempCount)); 58 | } else { 59 | final IntermediateCode ret = new Return(); 60 | return Pair.of(st, new ICodeInfo(ret, ret, null, tc)); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/frontend/StmtNode.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | public interface StmtNode extends BlockItemNode { 4 | } 5 | -------------------------------------------------------------------------------- /src/frontend/SyntaxNode.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | import exceptions.SysYException; 4 | import midend.LabelTable; 5 | import utils.Pair; 6 | 7 | import java.util.LinkedList; 8 | import java.util.List; 9 | 10 | public interface SyntaxNode { 11 | List> errors = new LinkedList<>(); 12 | 13 | SymbolTable check(SymbolTable symbolTable, boolean inLoop) throws SysYException; 14 | 15 | // should be called after check 16 | Pair simplify(SymbolTable symbolTable); 17 | 18 | Pair iCode(LabelTable lt, SymbolTable st, String lpBegin, String lpEnd, int tc); 19 | } 20 | -------------------------------------------------------------------------------- /src/frontend/TokenSupporter.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | import java.util.*; 4 | 5 | public class TokenSupporter implements Cloneable { 6 | public final List tokens; 7 | private int pointer; 8 | 9 | public TokenSupporter(List tokens) { 10 | this.tokens = Collections.unmodifiableList(new ArrayList<>(tokens)); 11 | } 12 | 13 | public boolean isEmpty() { 14 | return pointer == tokens.size(); 15 | } 16 | 17 | public int size() { 18 | return tokens.size() - pointer; 19 | } 20 | 21 | public Token get(int index) { 22 | return tokens.get(pointer + index); 23 | } 24 | 25 | public Optional take() { 26 | return isEmpty() ? Optional.empty() : Optional.of(tokens.get(pointer++)); 27 | } 28 | 29 | public void pushBack() { 30 | pointer = pointer == 0 ? 0 : pointer - 1; 31 | } 32 | 33 | public Optional prev() { 34 | return pointer == 0 ? Optional.empty() : Optional.of(tokens.get(pointer - 1)); 35 | } 36 | 37 | @Override 38 | public TokenSupporter clone() { 39 | try { 40 | return (TokenSupporter) super.clone(); 41 | } catch (CloneNotSupportedException e) { 42 | throw new AssertionError(); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/frontend/Tokenizer.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | import exceptions.SysYException; 4 | import utils.Pair; 5 | 6 | import java.io.IOException; 7 | import java.util.LinkedList; 8 | import java.util.List; 9 | import java.util.Optional; 10 | import java.util.regex.Matcher; 11 | import java.util.regex.Pattern; 12 | 13 | public class Tokenizer { 14 | public static final List> errors = new LinkedList<>(); 15 | 16 | public static List lex(String code) throws SysYException { 17 | final List tokens = new LinkedList<>(); 18 | final Optional make = Token.typePatterns.entrySet().stream() 19 | .map(e -> "(?<" + e.getKey().toString() + ">" + e.getValue() + ")") 20 | .reduce((s1, s2) -> s1 + "|" + s2); 21 | assert make.isPresent(); 22 | final Pattern pattern = Pattern.compile(make.get() + "|(?.)"); 23 | final Matcher matcher = pattern.matcher(code); 24 | int lineNumber = 1; 25 | extract: while (matcher.find()) { 26 | for (Token.Type t: Token.Type.values()) { 27 | String content = matcher.group(t.toString()); 28 | if (content != null) { 29 | lineNumber += content.chars().boxed().filter(c -> c == '\n').count(); 30 | if (t == Token.Type.STRCON) { 31 | for (int i = 1; i < content.length() - 1; ++i) { 32 | int ascii = content.charAt(i); 33 | if (ascii == 32 || ascii == 33 || ascii >= 40 && ascii <= 126) { 34 | if (ascii == 92 && content.charAt(i + 1) != 'n') { 35 | errors.add(Pair.of(lineNumber, SysYException.Code.a)); 36 | } 37 | } else if (ascii == 37) { 38 | if (content.charAt(i + 1) != 'd') errors.add(Pair.of(lineNumber, SysYException.Code.a)); 39 | } else { 40 | errors.add(Pair.of(lineNumber, SysYException.Code.a)); 41 | } 42 | } 43 | } 44 | if (!Token.Type.ignore(t)) { 45 | tokens.add(new Token(content, t, lineNumber)); 46 | } 47 | continue extract; 48 | } 49 | } 50 | throw new SysYException(SysYException.Code.u); 51 | } 52 | return tokens; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/frontend/VarDefNode.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | import utils.Pair; 4 | 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | public interface VarDefNode extends SyntaxNode { 9 | Map>> getInfo(); 10 | } 11 | -------------------------------------------------------------------------------- /src/midend/AddrValue.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | public class AddrValue extends Value { 4 | public AddrValue(String symbol) { 5 | super(symbol); 6 | } 7 | 8 | @Override 9 | public String toString() { 10 | return "&" + super.toString(); 11 | } 12 | 13 | @Override 14 | int get(IntermediateVirtualMachine machine) { 15 | return machine.findVar(this); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/midend/Assignment.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | import java.util.List; 4 | 5 | public interface Assignment { 6 | Value left(); 7 | 8 | List right(); 9 | } 10 | -------------------------------------------------------------------------------- /src/midend/BasicBlock.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | import utils.LinkedNode; 4 | import utils.Pair; 5 | 6 | public class BasicBlock extends LinkedNode { 7 | public static BasicBlock allocNopBlock() { 8 | final IntermediateCode nop = new Nop(); 9 | return new BasicBlock(nop, nop); 10 | } 11 | 12 | private Pair pair; 13 | 14 | public BasicBlock(Pair iCodePair) { 15 | pair = iCodePair; 16 | } 17 | 18 | public BasicBlock(IntermediateCode head, IntermediateCode tail) { 19 | this(Pair.of(head, tail)); 20 | } 21 | 22 | public IntermediateCode getHead() { 23 | return pair.first; 24 | } 25 | 26 | public IntermediateCode getTail() { 27 | return pair.second; 28 | } 29 | 30 | public Pair getPair() { 31 | return pair; 32 | } 33 | 34 | public void setHead(IntermediateCode code) { 35 | pair = Pair.of(code, pair.second); 36 | } 37 | 38 | public void setTail(IntermediateCode code) { 39 | pair = Pair.of(pair.first, code); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/midend/CallFunction.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | public class CallFunction extends IntermediateCode { 4 | public final String label; 5 | 6 | public CallFunction(String label) { 7 | this.label = label; 8 | } 9 | 10 | @Override 11 | String display() { 12 | return "call " + label; 13 | } 14 | 15 | @Override 16 | IntermediateCode execute(IntermediateVirtualMachine machine, LabelTable labelTable) { 17 | final IntermediateCode fun = labelTable.find(label); 18 | machine.callFuncWithLink(next); 19 | return fun; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/midend/Definite.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | public interface Definite { 4 | Value getDef(); 5 | } 6 | -------------------------------------------------------------------------------- /src/midend/Exit.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | public class Exit extends IntermediateCode { 4 | @Override 5 | String display() { 6 | return "exit"; 7 | } 8 | 9 | @Override 10 | IntermediateCode execute(IntermediateVirtualMachine machine, LabelTable labelTable) { 11 | return this; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/midend/FlowGraph.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | import java.util.*; 4 | 5 | public class FlowGraph { 6 | private final Map> blockNext = new HashMap<>(); 7 | private final Map> blockPrev = new HashMap<>(); 8 | private final Map blockLabels = new HashMap<>(); 9 | private final Map codeToBlock = new HashMap<>(); 10 | 11 | public void link(BasicBlock from, BasicBlock to) { 12 | if (!blockNext.containsKey(from)) { 13 | blockNext.put(from, new ArrayList<>()); 14 | } 15 | if (!blockPrev.containsKey(to)) { 16 | blockPrev.put(to, new ArrayList<>()); 17 | } 18 | blockNext.get(from).add(to); 19 | blockPrev.get(to).add(from); 20 | } 21 | 22 | public void put(IntermediateCode code, BasicBlock block) { 23 | codeToBlock.put(code, block); 24 | } 25 | 26 | public BasicBlock getBlock(IntermediateCode code) { 27 | return codeToBlock.get(code); 28 | } 29 | 30 | public List nextOf(BasicBlock block) { 31 | return blockNext.getOrDefault(block, Collections.emptyList()); 32 | } 33 | 34 | public List prevOf(BasicBlock block) { 35 | return blockPrev.getOrDefault(block, Collections.emptyList()); 36 | } 37 | 38 | public void addBlockLabel(String label, BasicBlock block) { 39 | blockLabels.put(label, block); 40 | } 41 | 42 | public BasicBlock getBlockByLabel(String label) { 43 | return blockLabels.get(label); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/midend/FuncEntry.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | public class FuncEntry extends IntermediateCode { 4 | public final String label; 5 | public final int paraNum; 6 | 7 | public FuncEntry(String label, int paraNum) { 8 | this.label = label; 9 | this.paraNum = paraNum; 10 | } 11 | 12 | @Override 13 | String display() { 14 | return label + "(para_num: " + paraNum + ")"; 15 | } 16 | 17 | @Override 18 | IntermediateCode execute(IntermediateVirtualMachine machine, LabelTable labelTable) { 19 | return next; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/midend/GetInt.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | 6 | public class GetInt extends IntermediateCode implements Definite, Assignment { 7 | @Override 8 | String display() { 9 | return "call getint"; 10 | } 11 | 12 | @Override 13 | IntermediateCode execute(IntermediateVirtualMachine machine, LabelTable labelTable) { 14 | machine.setReturnValue(machine.getInt()); 15 | return next; 16 | } 17 | 18 | @Override 19 | public Value getDef() { 20 | return new WordValue(Return.RET_SYM); 21 | } 22 | 23 | @Override 24 | public Value left() { 25 | return getDef(); 26 | } 27 | 28 | @Override 29 | public List right() { 30 | return Collections.emptyList(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/midend/ImmValue.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | public class ImmValue extends Value { 4 | public final int value; 5 | 6 | public ImmValue(int value) { 7 | super(String.valueOf(value)); 8 | this.value = value; 9 | } 10 | 11 | @Override 12 | int get(IntermediateVirtualMachine machine) { 13 | return value; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/midend/IntermediateCode.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | import utils.LinkedNode; 4 | 5 | import java.util.Objects; 6 | 7 | public abstract class IntermediateCode extends LinkedNode { 8 | private static int count = 0; 9 | private final int id = count++; 10 | 11 | abstract String display(); 12 | 13 | abstract IntermediateCode execute(IntermediateVirtualMachine machine, LabelTable labelTable); 14 | 15 | @Override 16 | public String toString() { 17 | return display(); 18 | } 19 | 20 | @Override 21 | public boolean equals(Object o) { 22 | if (this == o) return true; 23 | if (o == null || getClass() != o.getClass()) return false; 24 | IntermediateCode that = (IntermediateCode) o; 25 | return id == that.id; 26 | } 27 | 28 | @Override 29 | public int hashCode() { 30 | return Objects.hashCode(id); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/midend/IntroSpace.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | import utils.Pair; 4 | 5 | public interface IntroSpace { 6 | Pair getSize(); 7 | } 8 | -------------------------------------------------------------------------------- /src/midend/Jump.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | public class Jump extends IntermediateCode implements ProbablyConst { 4 | public final String label; 5 | 6 | public Jump(String label) { 7 | this.label = label; 8 | } 9 | 10 | @Override 11 | String display() { 12 | return "jump " + label; 13 | } 14 | 15 | @Override 16 | IntermediateCode execute(IntermediateVirtualMachine machine, LabelTable labelTable) { 17 | return labelTable.find(label); 18 | } 19 | 20 | private boolean isBranchToNext(LabelTable lt) { 21 | final IntermediateCode target = lt.find(label); 22 | IntermediateCode p = target.getPrev(); 23 | while (p != null) { 24 | if (!(p instanceof Nop)) { 25 | break; 26 | } 27 | p = p.getPrev(); 28 | } 29 | return p == this; 30 | } 31 | 32 | @Override 33 | public IntermediateCode simplify(LabelTable lt) { 34 | if (isBranchToNext(lt)) { 35 | return new Nop(); 36 | } else { 37 | return new Jump(label); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/midend/LabelTable.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | import java.util.*; 4 | 5 | public class LabelTable /* yielded by ast */ { 6 | private int labelCount = 0; 7 | private final Map labelsMap = new HashMap<>(); 8 | private final Map> instMap = new HashMap<>(); 9 | 10 | public IntermediateCode find(String label) { 11 | if (labelsMap.containsKey(label)) return labelsMap.get(label); 12 | throw new IllegalArgumentException(); 13 | } 14 | 15 | public Optional> find(IntermediateCode code) { 16 | if (instMap.containsKey(code)) return Optional.of(instMap.get(code)); 17 | return Optional.empty(); 18 | } 19 | 20 | public String createLabel() { 21 | return "@label_" + labelCount++; 22 | } 23 | 24 | public String createLabel(boolean loop, boolean begin) { 25 | if (loop) { 26 | if (begin) return "@label_loop_begin_" + labelCount++; 27 | else return "@label_loop_end_" + labelCount++; 28 | } else { 29 | return createLabel(); 30 | } 31 | } 32 | 33 | public void assignLabelToCode(String label, IntermediateCode targetInstruction) { 34 | labelsMap.put(label, targetInstruction); 35 | if (!instMap.containsKey(targetInstruction)) { 36 | instMap.put(targetInstruction, new LinkedList<>()); 37 | } 38 | instMap.get(targetInstruction).add(0, label); 39 | } 40 | 41 | public void reassignCode(IntermediateCode bfr, IntermediateCode aft) { 42 | find(bfr).ifPresent(l -> { 43 | instMap.put(aft, new LinkedList<>(l)); 44 | l.forEach(s -> labelsMap.put(s, aft)); 45 | }); 46 | } 47 | 48 | public void removeLabel(String label) { 49 | final IntermediateCode code = labelsMap.get(label); 50 | if (code != null) { 51 | labelsMap.remove(label); 52 | instMap.get(code).remove(label); 53 | } 54 | } 55 | 56 | public void minifyLabels(Collection usedLabels, Collection within) { 57 | final Set unusedLabels = new HashSet<>(); 58 | within.forEach(l -> { 59 | if (!usedLabels.contains(l) && l.startsWith("@")) { 60 | unusedLabels.add(l); 61 | } 62 | }); 63 | unusedLabels.forEach(this::removeLabel); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/midend/Load.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | import utils.Pair; 4 | 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | public class Load extends IntermediateCode implements IntroSpace, Definite, Usage { 9 | public final boolean temporary; 10 | public final Value left; 11 | public final AddrValue base; 12 | 13 | public Load(boolean temporary, Value left, AddrValue base) { 14 | this.temporary = temporary; 15 | this.left = left; 16 | this.base = base; 17 | } 18 | 19 | @Override 20 | String display() { 21 | return (temporary ? "temp " : "save ") + left + " <- *" + base; 22 | } 23 | 24 | @Override 25 | IntermediateCode execute(IntermediateVirtualMachine machine, LabelTable labelTable) { 26 | machine.updateVar(left, machine.load(base.get(machine))); 27 | return next; 28 | } 29 | 30 | @Override 31 | public Pair getSize() { 32 | return Pair.of(left, temporary ? 1 : 0); 33 | } 34 | 35 | @Override 36 | public Value getDef() { 37 | return left; 38 | } 39 | 40 | @Override 41 | public List getUse() { 42 | return Collections.singletonList(base); 43 | } 44 | 45 | @Override 46 | public Load replaceUse(List uses) { 47 | return new Load(temporary, left, (AddrValue) uses.get(0)); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/midend/Move.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | import utils.Pair; 4 | 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | public class Move extends IntermediateCode implements Assignment, IntroSpace, Definite, Usage { 9 | public final boolean temporary; 10 | public final Value left; 11 | public final Value right; 12 | 13 | public Move(boolean temporary, Value left, Value right) { 14 | this.temporary = temporary; 15 | this.left = left; 16 | this.right = right; 17 | } 18 | 19 | @Override 20 | String display() { 21 | return (temporary ? "temp " : "save ") + left.toString() + " <- " + right.toString(); 22 | } 23 | 24 | @Override 25 | IntermediateCode execute(IntermediateVirtualMachine machine, LabelTable labelTable) { 26 | if (temporary) machine.createVar(left); 27 | machine.updateVar(left, right.get(machine)); 28 | return next; 29 | } 30 | 31 | @Override 32 | public Pair getSize() { 33 | return Pair.of(left, temporary ? 1 : 0); 34 | } 35 | 36 | @Override 37 | public Value getDef() { 38 | return left; 39 | } 40 | 41 | @Override 42 | public List getUse() { 43 | return Collections.singletonList(right); 44 | } 45 | 46 | @Override 47 | public Move replaceUse(List uses) { 48 | return new Move(temporary, left, uses.get(0)); 49 | } 50 | 51 | @Override 52 | public Value left() { 53 | return left; 54 | } 55 | 56 | @Override 57 | public List right() { 58 | return Collections.singletonList(right); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/midend/Nop.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | public class Nop extends IntermediateCode { 4 | @Override 5 | String display() { 6 | return "nop"; 7 | } 8 | 9 | @Override 10 | IntermediateCode execute(IntermediateVirtualMachine machine, LabelTable labelTable) { 11 | return next; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/midend/ParameterFetch.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | import utils.Pair; 4 | 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | public class ParameterFetch extends IntermediateCode implements IntroSpace, Definite, Assignment, Usage { 9 | public final Value name; 10 | 11 | public ParameterFetch(Value name) { 12 | this.name = name; 13 | } 14 | 15 | @Override 16 | String display() { 17 | return "para " + name.toString(); 18 | } 19 | 20 | @Override 21 | IntermediateCode execute(IntermediateVirtualMachine machine, LabelTable labelTable) { 22 | machine.createVar(name); 23 | machine.updateVar(name, machine.popArg()); 24 | return next; 25 | } 26 | 27 | @Override 28 | public Pair getSize() { 29 | return Pair.of(name, 1); 30 | } 31 | 32 | @Override 33 | public Value left() { 34 | return name; 35 | } 36 | 37 | @Override 38 | public List right() { 39 | return Collections.singletonList(name); 40 | } 41 | 42 | @Override 43 | public Value getDef() { 44 | return name; 45 | } 46 | 47 | @Override 48 | public List getUse() { 49 | return Collections.singletonList(name); 50 | } 51 | 52 | @Override 53 | public ParameterFetch replaceUse(List uses) { 54 | return new ParameterFetch(uses.get(0)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/midend/Print.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | public class Print extends IntermediateCode { 4 | public final String string; 5 | 6 | public Print(String string) { 7 | this.string = string; 8 | } 9 | 10 | @Override 11 | String display() { 12 | return "printf " + string; 13 | } 14 | 15 | @Override 16 | IntermediateCode execute(IntermediateVirtualMachine machine, LabelTable labelTable) { 17 | char[] str = string.toCharArray(); 18 | for (int i = 1; i < str.length - 1; ++i) { 19 | if (str[i] == '%' && i < str.length - 2 && str[i + 1] == 'd') { 20 | System.out.print(machine.popArg()); 21 | ++i; 22 | } else if (str[i] == '\\' && i < str.length - 2 && str[i + 1] == 'n') { 23 | System.out.print('\n'); 24 | ++i; 25 | } else { 26 | System.out.print(str[i]); 27 | } 28 | } 29 | return next; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/midend/ProbablyCombinable.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | public interface ProbablyCombinable { 4 | boolean isCombinable(); 5 | 6 | IntermediateCode combine(); 7 | } 8 | -------------------------------------------------------------------------------- /src/midend/ProbablyConst.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | public interface ProbablyConst { 4 | IntermediateCode simplify(LabelTable lt); 5 | } 6 | -------------------------------------------------------------------------------- /src/midend/PushArgument.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | 6 | public class PushArgument extends IntermediateCode implements Usage { 7 | public final Value name; 8 | 9 | public PushArgument(Value name) { 10 | this.name = name; 11 | } 12 | 13 | @Override 14 | String display() { 15 | return "push " + name; 16 | } 17 | 18 | @Override 19 | IntermediateCode execute(IntermediateVirtualMachine machine, LabelTable labelTable) { 20 | machine.pushArg(name.get(machine)); 21 | return next; 22 | } 23 | 24 | @Override 25 | public List getUse() { 26 | return Collections.singletonList(name); 27 | } 28 | 29 | @Override 30 | public PushArgument replaceUse(List uses) { 31 | return new PushArgument(uses.get(0)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/midend/Return.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | import java.util.Collections; 4 | import java.util.Optional; 5 | import java.util.List; 6 | 7 | public class Return extends IntermediateCode implements Usage { 8 | public static final String RET_SYM = "%ret%"; 9 | 10 | public final Value name; 11 | 12 | public Return() { 13 | this(null); 14 | } 15 | 16 | public Return(Value name) { 17 | this.name = name; 18 | } 19 | 20 | private Optional getName() { 21 | return name == null ? Optional.empty() : Optional.of(name.toString()); 22 | } 23 | 24 | @Override 25 | String display() { 26 | return getName().map(s -> "return " + s).orElse("return"); 27 | } 28 | 29 | @Override 30 | IntermediateCode execute(IntermediateVirtualMachine machine, LabelTable labelTable) { 31 | return machine.returnWithValue(name != null ? name.get(machine) : 0); 32 | } 33 | 34 | @Override 35 | public List getUse() { 36 | return name == null ? Collections.emptyList() : Collections.singletonList(name); 37 | } 38 | 39 | @Override 40 | public Return replaceUse(List uses) { 41 | return uses.isEmpty() ? new Return() : new Return(uses.get(0)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/midend/Save.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | public class Save extends IntermediateCode implements Usage { 7 | public final AddrValue base; 8 | public final Value right; 9 | 10 | public Save(AddrValue base, Value right) { 11 | this.base = base; 12 | this.right = right; 13 | } 14 | 15 | @Override 16 | String display() { 17 | return "*" + base + " <- " + right; 18 | } 19 | 20 | @Override 21 | IntermediateCode execute(IntermediateVirtualMachine machine, LabelTable labelTable) { 22 | machine.save(machine.findVar(base), right.get(machine)); 23 | return next; 24 | } 25 | 26 | @Override 27 | public List getUse() { 28 | return Arrays.asList(base, right); 29 | } 30 | 31 | @Override 32 | public Save replaceUse(List uses) { 33 | return new Save((AddrValue) uses.get(0), uses.get(1)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/midend/Usage.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | import java.util.List; 4 | 5 | public interface Usage { 6 | List getUse(); 7 | 8 | T replaceUse(List uses); 9 | } 10 | -------------------------------------------------------------------------------- /src/midend/Value.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | import java.util.Objects; 4 | 5 | public abstract class Value { 6 | public final String symbol; 7 | 8 | public Value(String symbol) { 9 | this.symbol = symbol; 10 | } 11 | 12 | public static Value pack(Value v1, Value v2, String val) { 13 | if (v1 instanceof AddrValue || v2 instanceof AddrValue) { 14 | return new AddrValue(val); 15 | } 16 | return new WordValue(val); 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | return symbol; 22 | } 23 | 24 | abstract int get(IntermediateVirtualMachine machine); 25 | 26 | @Override 27 | public boolean equals(Object o) { 28 | if (this == o) return true; 29 | if (o == null || getClass() != o.getClass()) return false; 30 | Value value = (Value) o; 31 | return Objects.equals(symbol, value.symbol); 32 | } 33 | 34 | @Override 35 | public int hashCode() { 36 | return Objects.hash(symbol); 37 | } 38 | 39 | public boolean isGlobal() { 40 | return symbol.endsWith("%1"); 41 | } 42 | 43 | public boolean isTemp() { 44 | return Character.isDigit(symbol.charAt(0)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/midend/WordValue.java: -------------------------------------------------------------------------------- 1 | package midend; 2 | 3 | public class WordValue extends Value { 4 | public WordValue(String symbol) { 5 | super(symbol); 6 | } 7 | 8 | @Override 9 | public String toString() { 10 | return "$" + super.toString(); 11 | } 12 | 13 | @Override 14 | int get(IntermediateVirtualMachine machine) { 15 | return machine.findVar(this); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/utils/LinkedNode.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | public abstract class LinkedNode> { 4 | protected T next; 5 | protected T prev; 6 | 7 | @SuppressWarnings("unchecked") 8 | public T link(T node) { 9 | node.prev = (T) this; 10 | this.next = node; 11 | return node; 12 | } 13 | 14 | public T getPrev() { 15 | return prev; 16 | } 17 | 18 | public T getNext() { 19 | return next; 20 | } 21 | 22 | // replace with a list 23 | public T replaceWith(T node /* head node of a list */) { 24 | prev.link(node); 25 | T p = node; 26 | while (p.next != null) { 27 | p = p.next; 28 | } 29 | if (next != null) p.link(next); 30 | return p; 31 | } 32 | 33 | public void remove() { 34 | if (next != null) prev.link(next); 35 | else prev.next = null; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/utils/Pair.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import java.util.Objects; 4 | 5 | public class Pair { 6 | public static Pair of(S f, V s) { 7 | return new Pair<>(f, s); 8 | } 9 | 10 | public final T first; 11 | public final U second; 12 | 13 | public Pair(T first, U second) { 14 | this.first = first; 15 | this.second = second; 16 | } 17 | 18 | @Override 19 | public boolean equals(Object o) { 20 | if (this == o) { 21 | return true; 22 | } 23 | if (o == null || getClass() != o.getClass()) { 24 | return false; 25 | } 26 | Pair pair = (Pair) o; 27 | return Objects.equals(first, pair.first) && Objects.equals(second, pair.second); 28 | } 29 | 30 | @Override 31 | public int hashCode() { 32 | return Objects.hash(first, second); 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return "<" + first.toString() + ", " + second.toString() + ">"; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/utils/SimpleIO.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import java.io.*; 4 | import java.util.Scanner; 5 | import java.util.StringJoiner; 6 | 7 | public class SimpleIO { 8 | @FunctionalInterface 9 | public interface OutputHandler { 10 | String handle(U o); 11 | } 12 | 13 | public static String input(String filename) throws IOException { 14 | final InputStream stream = new FileInputStream(filename); 15 | final Scanner scanner = new Scanner(stream); 16 | final StringJoiner stringJoiner = new StringJoiner("\n"); 17 | while (scanner.hasNextLine()) { 18 | stringJoiner.add(scanner.nextLine()); 19 | } 20 | scanner.close(); 21 | stream.close(); 22 | return stringJoiner.toString(); 23 | } 24 | 25 | public static void output(String filename, T obj, OutputHandler handler) throws FileNotFoundException { 26 | final PrintWriter writer = new PrintWriter(filename); 27 | writer.println(handler.handle(obj)); 28 | writer.close(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /testcases/A/input10.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 -------------------------------------------------------------------------------- /testcases/A/input11.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 2 3 | 1 -------------------------------------------------------------------------------- /testcases/A/input12.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coekjan/MIPSysY-Compiler/772e50d5f4ac1114c8a9f880264a659d99575cb2/testcases/A/input12.txt -------------------------------------------------------------------------------- /testcases/A/input13.txt: -------------------------------------------------------------------------------- 1 | 123 2 | 456 3 | 12 4 | 324 -------------------------------------------------------------------------------- /testcases/A/input14.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 0 3 | 1 4 | 6 5 | 8 6 | 20 7 | 30 8 | -------------------------------------------------------------------------------- /testcases/A/input15.txt: -------------------------------------------------------------------------------- 1 | 200 2 | -------------------------------------------------------------------------------- /testcases/A/input16.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 60 7 | 70 8 | 80 9 | 90 10 | 100 11 | 1100 12 | 1200 13 | 1300 14 | 1400 15 | 1500 16 | 16000 17 | 17000 18 | 18000 19 | 19000 20 | 24000 21 | 20000 22 | 21000 23 | 22000 24 | 23000 25 | 25000 26 | 0 27 | 1 28 | 550 -------------------------------------------------------------------------------- /testcases/A/input17.txt: -------------------------------------------------------------------------------- 1 | 33 2 | 28 3 | 501 4 | 233 5 | 114 6 | 711 7 | 266 8 | 500 9 | 77 -------------------------------------------------------------------------------- /testcases/A/input18.txt: -------------------------------------------------------------------------------- 1 | 9 2 | 8 3 | 7 4 | 6 5 | 5 6 | 4 7 | 3 8 | 2 9 | 1 10 | -------------------------------------------------------------------------------- /testcases/A/input19.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /testcases/A/input2.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 1998 3 | 3 4 | 23 5 | 2021 6 | 9 7 | 23 8 | 168 9 | 5 10 | 21 11 | 2020 12 | 1 13 | 1 14 | 2010 15 | 2 16 | 28 17 | 2010 18 | 1 19 | 1 20 | 1998 21 | 2 22 | 25 23 | 1997 24 | 5 25 | 24 26 | -------------------------------------------------------------------------------- /testcases/A/input20.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 1 -------------------------------------------------------------------------------- /testcases/A/input21.txt: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /testcases/A/input22.txt: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testcases/A/input23.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 -------------------------------------------------------------------------------- /testcases/A/input24.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 3 4 | -------------------------------------------------------------------------------- /testcases/A/input25.txt: -------------------------------------------------------------------------------- 1 | 24 2 | 27 3 | 342526 4 | -------------------------------------------------------------------------------- /testcases/A/input26.txt: -------------------------------------------------------------------------------- 1 | 3 -------------------------------------------------------------------------------- /testcases/A/input3.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /testcases/A/input4.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coekjan/MIPSysY-Compiler/772e50d5f4ac1114c8a9f880264a659d99575cb2/testcases/A/input4.txt -------------------------------------------------------------------------------- /testcases/A/input5.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coekjan/MIPSysY-Compiler/772e50d5f4ac1114c8a9f880264a659d99575cb2/testcases/A/input5.txt -------------------------------------------------------------------------------- /testcases/A/input6.txt: -------------------------------------------------------------------------------- 1 | 4 -------------------------------------------------------------------------------- /testcases/A/input7.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 2 3 | 12 4 | 23 5 | 34 6 | 45 7 | 2 8 | 2 9 | 34 10 | 45 11 | 56 12 | 67 13 | 1 14 | 3 15 | 4 16 | 1 17 | 1 18 | 1 19 | 1 20 | 2 21 | 2 22 | 2 23 | 2 24 | 3 25 | 3 26 | 3 27 | 3 28 | 1 29 | 2 30 | 4 31 | 4 32 | 3 33 | 1 34 | 1 35 | 2 36 | 3 37 | 3 38 | 12 39 | 23 40 | 54 41 | 32 42 | 12 43 | 21 44 | 34 45 | 12 46 | 54 47 | 2 48 | 2 49 | 1 50 | 1 51 | 1 52 | 1 53 | 2 54 | 34 55 | 54 56 | 2 57 | 3 58 | 1 59 | 2 60 | 2 61 | 2 62 | 1 63 | 3 64 | 12 65 | 23 66 | 34 67 | 3 68 | 4 69 | 1 70 | 1 71 | 2 72 | 3 73 | 4 74 | 3 75 | 2 76 | 12 77 | 23 78 | 23 79 | 34 80 | 45 81 | 56 82 | 1 83 | 1 84 | 5 85 | 12 86 | 23 87 | 34 88 | 45 89 | 56 90 | 1 91 | 3 92 | 12 93 | 23 94 | 34 95 | 3 96 | 1 97 | 1 98 | 1 99 | 1 100 | 1 101 | 2 102 | 2 103 | 2 104 | 2 105 | 14 106 | 325 107 | 231434 108 | 1233 109 | 2 110 | 2 111 | 810975 112 | 114514 113 | 13 114 | 31 115 | 3 -------------------------------------------------------------------------------- /testcases/A/input8.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 -------------------------------------------------------------------------------- /testcases/A/input9.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 12 -------------------------------------------------------------------------------- /testcases/A/output10.txt: -------------------------------------------------------------------------------- 1 | 19373528 2 | f2() flag : 3 3 | f2() flag : 3 4 | flag = 1 : c1 = 3, c2 = -1 5 | f2() flag : 2 6 | f2() flag : 4 7 | flag = 0 : c1 = 13, c2 = -1 8 | f2() flag : 2 9 | f2() flag : 4 10 | flag = 0 : c1 = 23, c2 = -1 -------------------------------------------------------------------------------- /testcases/A/output11.txt: -------------------------------------------------------------------------------- 1 | 19182620 2 | 0 3 | 1 4 | 2 5 | 2 6 | 1 7 | 2 8 | 19182620 9 | 19182620 10 | 19182620 11 | -------------------------------------------------------------------------------- /testcases/A/output12.txt: -------------------------------------------------------------------------------- 1 | 19182636 2 | ! is ok 3 | < is ok 4 | > is ok 5 | <= is ok 6 | >= is ok 7 | == != is ok 8 | or is ok 9 | the priority of and/or is ok 10 | 6 7 11 | -------------------------------------------------------------------------------- /testcases/A/output13.txt: -------------------------------------------------------------------------------- 1 | 19373330 2 | max of mnpq is 456 3 | i or m ? 456 4 | out1 456 out2 229044 5 | sum of array var33 is 5583 6 | squ sum of s3 3 7 | max of four number 314721 8 | Kirov reporrrting 1 9 | For the Union 7 10 | okmotherfuckeroveridontwanttobehornyanymoreijustwanttobehappy 11 | -------------------------------------------------------------------------------- /testcases/A/output14.txt: -------------------------------------------------------------------------------- 1 | 19373372 2 | a[n] = a[n - 1] + a[n - 2] (for different init values) 3 | /* input = 0 */ 4 | Error! 5 | /* input = 1 */ 6 | 1 1 7 | 1 0 8 | when a[0] = 0, a[1] = 1 ==> a[1] = 1 9 | when a[0] = 1, a[1] = 1 ==> a[1] = 1 10 | when a[0] = 1, a[1] = 2 ==> a[1] = 2 11 | when a[0] = 1, a[1] = 3 ==> a[1] = 3 12 | when a[0] = 3, a[1] = 4 ==> a[1] = 4 13 | when a[0] = 1, a[1] = -1 ==> a[1] = -1 14 | ////////////////////////////////////// 15 | /* input = 6 */ 16 | 13 8 17 | 8 5 18 | when a[0] = 0, a[1] = 1 ==> a[6] = 8 19 | when a[0] = 1, a[1] = 1 ==> a[6] = 13 20 | when a[0] = 1, a[1] = 2 ==> a[6] = 21 21 | when a[0] = 1, a[1] = 3 ==> a[6] = 29 22 | when a[0] = 3, a[1] = 4 ==> a[6] = 47 23 | when a[0] = 1, a[1] = -1 ==> a[6] = -3 24 | ////////////////////////////////////// 25 | /* input = 8 */ 26 | 34 21 27 | 21 13 28 | when a[0] = 0, a[1] = 1 ==> a[8] = 21 29 | when a[0] = 1, a[1] = 1 ==> a[8] = 34 30 | when a[0] = 1, a[1] = 2 ==> a[8] = 55 31 | when a[0] = 1, a[1] = 3 ==> a[8] = 76 32 | when a[0] = 3, a[1] = 4 ==> a[8] = 123 33 | when a[0] = 1, a[1] = -1 ==> a[8] = -8 34 | ////////////////////////////////////// 35 | /* input = 20 */ 36 | 10946 6765 37 | 6765 4181 38 | when a[0] = 0, a[1] = 1 ==> a[20] = 6765 39 | when a[0] = 1, a[1] = 1 ==> a[20] = 10946 40 | when a[0] = 1, a[1] = 2 ==> a[20] = 17711 41 | when a[0] = 1, a[1] = 3 ==> a[20] = 24476 42 | when a[0] = 3, a[1] = 4 ==> a[20] = 39603 43 | when a[0] = 1, a[1] = -1 ==> a[20] = -2584 44 | ////////////////////////////////////// 45 | /* input = 30 */ 46 | 1346269 832040 47 | 832040 514229 48 | when a[0] = 0, a[1] = 1 ==> a[30] = 832040 49 | when a[0] = 1, a[1] = 1 ==> a[30] = 1346269 50 | when a[0] = 1, a[1] = 2 ==> a[30] = 2178309 51 | when a[0] = 1, a[1] = 3 ==> a[30] = 3010349 52 | when a[0] = 3, a[1] = 4 ==> a[30] = 4870847 53 | when a[0] = 1, a[1] = -1 ==> a[30] = -317811 54 | ////////////////////////////////////// 55 | /****************** END ******************/ 56 | -------------------------------------------------------------------------------- /testcases/A/output15.txt: -------------------------------------------------------------------------------- 1 | 19373354 2 | 2 -402114823 3 | 3 423174272 4 | 5 375872692 5 | 7 915987033 6 | 11 -34179219 7 | 13 1498631475 8 | 17 -1060809599 9 | 19 423174272 10 | 23 915987033 11 | 29 1498631475 12 | 31 1640319187 13 | 37 375872692 14 | 41 -2143283456 15 | 43 -34179219 16 | 47 1640319187 17 | 53 375872692 18 | 59 -34179219 19 | 61 1498631475 20 | 67 423174272 21 | 71 915987033 22 | 73 -2143283456 23 | 79 1640319187 24 | 83 423174272 25 | 89 -2143283456 26 | 97 -1060809599 27 | 101 375872692 28 | 103 915987033 29 | 107 -34179219 30 | 109 1498631475 31 | 113 -1060809599 32 | 127 1640319187 33 | 131 423174272 34 | 137 -2143283456 35 | 139 -34179219 36 | 149 375872692 37 | 151 915987033 38 | 157 1498631475 39 | 163 423174272 40 | 167 915987033 41 | 173 1498631475 42 | 179 423174272 43 | 181 375872692 44 | 191 1640319187 45 | 193 -1060809599 46 | 197 375872692 47 | 199 915987033 48 | -------------------------------------------------------------------------------- /testcases/A/output16.txt: -------------------------------------------------------------------------------- 1 | 19373459 2 | val20: 0, val21:5369, val22:4821, val23:4682, val24:8093 3 | val30: 0, val32: 7303, val34: 6137 4 | val40: 0, val42:-1, val43:0, val44:-1 5 | -------------------------------------------------------------------------------- /testcases/A/output17.txt: -------------------------------------------------------------------------------- 1 | 19373487 2 | the result is:4 3 | the result is:4 4 | out of range!! 5 | the result is:6 6 | the result is:4 7 | out of range!! 8 | the result is:6 9 | the result is:5 10 | the result is:4 -------------------------------------------------------------------------------- /testcases/A/output18.txt: -------------------------------------------------------------------------------- 1 | 19373311 2 | 123 3 | 123 4 | 123 5 | 123 6 | 123 7 | 4 5 6 8 | 36 9 | 16 10 | 10 11 | 63 12 | 36 13 | 1 2 3 14 | 4 5 6 15 | 7 8 9 16 | -------------------------------------------------------------------------------- /testcases/A/output19.txt: -------------------------------------------------------------------------------- 1 | 19373135 2 | global g_var_6[1][0]:1, g_var_6[1][1]:1 3 | local l_var_4:1, l_var_5:1, l_var_6:1, l_var_7:10, l_var_8:100 4 | exp l_var_4:1 5 | exp l_var_5:0 6 | exp l_var_6:0 7 | if l_var_4:3 8 | while l_var_5:0 9 | while l_var_5:0 10 | getint l_var_6:1 -------------------------------------------------------------------------------- /testcases/A/output2.txt: -------------------------------------------------------------------------------- 1 | 16061069 2 | input groups 3 | input your birth year,month,day,ep:1998 1 1 4 | input current year,month,day,ep:2020 2 2 5 | you have lived 8585 days 6 | input your birth year,month,day,ep:1998 1 1 7 | input current year,month,day,ep:2020 2 2 8 | you have lived 676288 days 9 | input your birth year,month,day,ep:1998 1 1 10 | input current year,month,day,ep:2020 2 2 11 | please input time legally 12 | input your birth year,month,day,ep:1998 1 1 13 | input current year,month,day,ep:2020 2 2 14 | please input time legally 15 | -------------------------------------------------------------------------------- /testcases/A/output20.txt: -------------------------------------------------------------------------------- 1 | 19373163 2 | -+-114514 = 114514 3 | -+-114514 > 0 4 | -+- 6 + 7 * (6 -9) / 3 / 2 = 3 5 | var10[1] = 3 6 | var13 = 1 7 | func1() = 0 8 | func3(+-12) = -12 9 | func4(1, var4, var6) = 3 10 | func4(const1, var6[1], var6) = -2 11 | -------------------------------------------------------------------------------- /testcases/A/output21.txt: -------------------------------------------------------------------------------- 1 | 19373384 2 | const and var // decl and def test 3 | expected result: 579, output: 579 4 | function (def and )call test 5 | expected result: {{589, 21}, {599, 31}}, output: {{589, 21}, {599, 31}} 6 | LExp test, falling into infinite loop indicates an error -- pass 7 | simple echo test, get a integer and read back: 42 8 | 9 | 10 | ================================================================================ 11 | PASSED 12 | ================================================================================ 13 | -------------------------------------------------------------------------------- /testcases/A/output22.txt: -------------------------------------------------------------------------------- 1 | 19373408 all weak points 2 | L and Eq is ok (no params) 3 | Rel is ok (with params) 4 | Add is ok 5 | getint is ok 6 | -1 7 | -1 8 | 1 9 | 1 10 | -------------------------------------------------------------------------------- /testcases/A/output23.txt: -------------------------------------------------------------------------------- 1 | 19373421 2 | const_var1+const_var2=:3 3 | const_array1[1]=:2 4 | array2[0]:=3 5 | g(2):=6 6 | 123456789 7 | 1 8 | 5 9 | 6 10 | AK!!! -------------------------------------------------------------------------------- /testcases/A/output24.txt: -------------------------------------------------------------------------------- 1 | 19373235 2 | Testing Short-circuit evaluation : 0 1 1 0 1 0 1 1 0 1 1 1 3 | Testing func_pass_array(int a[][4) ...... 4 | 1 2 3 4 5 | 5 6 7 8 6 | 10 11 12 13 7 | Testing func_pass_PartArray(int a[]) ...... 5 6 7 8 8 | Testing func_pass_arrayElement(int a) ...... 3 9 | Testing complex calculate ...... result = -10. 10 | Testing D2array traversal and assignment. 11 | Array array_E: 12 | 0 1 2 13 | 1 2 3 14 | Testing func_if_D2array(a[][3], b) ...... 15 | 0 1 3 16 | 1 2 0 17 | Loop 7 times, once continue, once break. Symbol j = 5. func_while(x, y)is done! 18 | -------------------------------------------------------------------------------- /testcases/A/output25.txt: -------------------------------------------------------------------------------- 1 | 19373341 2 | m = 3, n = 24, mm = 27, nn = 342526 3 | max of mm and nn: 342526; min of mm and nn: 27 4 | mainConst1 = 10 5 | Sum of normalConst: 35 6 | 24 is even! 7 | Sum of array: 3 8 | sum of array: 24 9 | Contains odd! 10 | 27 and 342526 contains at least an odd! 11 | -------------------------------------------------------------------------------- /testcases/A/output26.txt: -------------------------------------------------------------------------------- 1 | 19373630 2 | 1 3 | 120 4 | 720 5 | 5040 6 | 1 7 | 2 8 | 4 9 | 3 10 | 30250 11 | -------------------------------------------------------------------------------- /testcases/A/output3.txt: -------------------------------------------------------------------------------- 1 | 19373734 2 | 19373734 3 | 19373734 4 | 19373734 5 | 19373734 6 | 19373734 7 | 19373734 8 | 19373734 9 | 19373734 10 | 19373734 -------------------------------------------------------------------------------- /testcases/A/output4.txt: -------------------------------------------------------------------------------- 1 | 19231258 OK1 2 | OK2 3 | OK3 4 | OK4 5 | OK5 6 | OK6 7 | OK7 8 | OK8 9 | OK9 -------------------------------------------------------------------------------- /testcases/A/output5.txt: -------------------------------------------------------------------------------- 1 | 19231011 2 | start checking for logic expressions 3 | check for AND calculation: successfully! 4 | check for OR calculation: successfully! 5 | check for short-circuit calculation: successfully! 6 | end checking 7 | -------------------------------------------------------------------------------- /testcases/A/output6.txt: -------------------------------------------------------------------------------- 1 | 19231248-250 2 | 19231248 3 | 19231248 4 | 19231248 5 | 19231248 6 | 19231248 7 | 19231248 8 | 19231248 9 | 19231248 10 | 19231248 11 | -------------------------------------------------------------------------------- /testcases/A/output7.txt: -------------------------------------------------------------------------------- 1 | 19182604 2 | 0 3 | 1 4 | 2 5 | 3 6 | 4 7 | 5 8 | 6 9 | 7 10 | 8 11 | 12 | -------------------------------------------------------------------------------- /testcases/A/output8.txt: -------------------------------------------------------------------------------- 1 | 19182619 2 | CscanfOK 3 | DscanfOK 4 | sb:2 5 | continueOK 6 | breakOK 7 | 0Func2OK 8 | Func3OK 9 | Func4OK 10 | end -------------------------------------------------------------------------------- /testcases/A/output9.txt: -------------------------------------------------------------------------------- 1 | 19373573 2 | 4 3 | 6 4 | judgeB 2,3 = -1 5 | Hello 12 6 | 10 7 | 0-1 8 | -10 9 | 01 10 | 10 11 | 31 -------------------------------------------------------------------------------- /testcases/A/testfile10.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | const int c_common = 10, c_array[3] = {1, 2, 3}; 4 | const int c_matrix[3][3] = {{1, 2, 3}, {1, 2, 3}, {1, 2, 3}}; 5 | int v_common, v_array[3], v_matrix[3][3]; 6 | int v_commonInit = 10; 7 | int v_arrayInit[3] = {1, 2, 3}; 8 | int v_matrixInit[3][3] = {{1, 2, 3}, {1, 2, 3}, {1, 2, 3}}; 9 | 10 | 11 | 12 | void print(int output) { 13 | printf("\nf2() flag : %d", output); 14 | return; 15 | } 16 | 17 | int f0() { 18 | return 1; 19 | } 20 | 21 | int f1(int a[], int b[][3], int c[]) { 22 | return a[0] + b[0][0] + c[0]; 23 | } 24 | 25 | int f2(int a, int b) { 26 | int c; 27 | int flag; 28 | int a1[2] = {1, 2}; 29 | int a2[3][3] = {{1, 2, 3}, {1, 2, 3}, {1, 2, 3}}; 30 | c = -(a*b) + a/b + (a%b) -1 + f1(a1, a2, a2[0]) - +f0(); 31 | 32 | if (a > 10 && b > 10) { 33 | print(1); 34 | flag = 0; 35 | } 36 | if (a > 10 && b <= 10) { 37 | print(2); 38 | flag = 0; 39 | } 40 | if (a <= 10 && b <= 10) { 41 | print(3); 42 | flag = 1; 43 | } 44 | if (a <= 10 && b > 10) { 45 | print(4); 46 | flag = 1; 47 | } 48 | return flag; 49 | } 50 | 51 | int main() { 52 | printf("19373528 "); 53 | ; 54 | { 55 | } 56 | int a,b,flag1,flag2,flag,i; 57 | a = getint(); 58 | b = getint(); 59 | i=0; 60 | if (a != b) { 61 | while (i < 3) { 62 | int c1; 63 | int c2; 64 | c1 = a + b; 65 | c2 = a - b; 66 | 67 | flag1=f2(c1,c2); 68 | flag2=f2(c2,c1); 69 | 70 | if (flag1 == 0 || !flag2) { 71 | flag = 0; 72 | } else { 73 | flag = 1; 74 | } 75 | printf("\nflag = %d : c1 = %d, c2 = %d", flag, c1, c2); 76 | i = i + 1; 77 | a = a + 5; 78 | b = b + 5; 79 | if (i >= 10) { 80 | continue; 81 | } 82 | if (i < 0) { 83 | break; 84 | } 85 | } 86 | } 87 | return 0; 88 | } 89 | 90 | 91 | -------------------------------------------------------------------------------- /testcases/A/testfile11.txt: -------------------------------------------------------------------------------- 1 | 2 | void de() 3 | { 4 | return; 5 | } 6 | 7 | int keke(int i,int j) 8 | { 9 | i=i+j; 10 | return 0; 11 | } 12 | 13 | int jian() 14 | { 15 | int x,y,z; 16 | x=getint(); 17 | y=getint(); 18 | z=x-y; 19 | return z; 20 | } 21 | 22 | int main() 23 | { 24 | printf("19182620\n"); 25 | int a,b,c,d, e,f,g=+1,h,j,k,l,o=-1; 26 | int i=2,n,m,flag=0; 27 | n=getint(); 28 | while(i=e) 71 | { 72 | if(e<=f) 73 | { 74 | if(f!=g) 75 | { 76 | if(c>1) 77 | { 78 | a=1; 79 | } 80 | 81 | 82 | } 83 | 84 | } 85 | } 86 | } 87 | keke(a,b); 88 | 89 | printf("%d\n%d\n%d\n%d\n",d,e,f,g); 90 | printf("19182620\n"); 91 | printf("19182620\n"); 92 | printf("19182620\n"); 93 | return 0; 94 | } 95 | -------------------------------------------------------------------------------- /testcases/A/testfile12.txt: -------------------------------------------------------------------------------- 1 | int main(){ 2 | printf("19182636\n"); 3 | 4 | int a = 5; 5 | int b = 6; 6 | int s1[6] = {0,1,2,3,6,12}; 7 | int s2[2][3] = {{10,11,12},{13,14,15}}; 8 | 9 | if(!s1[0]==1 && !(s1[0]*2) && !0){ 10 | printf("! is ok\n"); 11 | } else { 12 | printf("! has problem\n"); 13 | } 14 | 15 | if(a+b < s1[5]&& s1[3]-s1[0] < s2[1][2]/a==0 && bs1[1]){ 16 | printf("< is ok\n"); 17 | } else { 18 | printf("< has problem\n"); 19 | } 20 | 21 | if(a*b > s1[2]*s2[1][2]==0 && (s2[0][1]-s1[2])%a > s2[1][2]/a && s1[5]>a+b+2>0==0 && s1[5]>a+b < s1[1]==0){ 22 | printf("> is ok\n"); 23 | } else { 24 | printf("> has problem\n"); 25 | } 26 | 27 | if(a<=b && a<=b+s1[1] && a<=b<=s1[0]==0 && a<=b>=s1[2]<1){ 28 | printf("<= is ok\n"); 29 | } else { 30 | printf("<= has problem\n"); 31 | } 32 | 33 | if(b>=a+1 && b>=s1[4]+s1[1]!=1 && a<=b>=s1[1]+1==0 && a>=b>=s1[0]<=s1[0]!=1){ 34 | printf(">= is ok\n"); 35 | } else{ 36 | printf(">= has problem\n"); 37 | } 38 | 39 | if(a != b && a==b==0 && a>b == a=b == s1[2] != s1[0] != s1[4]){ 40 | printf("== != is ok\n"); 41 | } else { 42 | printf("== != has problem\n"); 43 | } 44 | 45 | if(s1[3] == s2[0][1] || a>=b || a+7%4 < b*3){ 46 | printf("or is ok\n"); 47 | } else { 48 | printf("or has problem\n"); 49 | } 50 | 51 | if(a/2 s1[5] && b > s1[5]){ 52 | printf("the priority of and/or is ok\n"); 53 | } else { 54 | printf("the priority of and/or has problem\n"); 55 | } 56 | 57 | if(a < b || +a){ 58 | a = a + 1; 59 | if(s1[0]= 0 && y < 5) { 25 | return 1; 26 | } 27 | return 0; 28 | } 29 | 30 | int check(int x, int y) { 31 | if (0 > x || 5 <= x || !Check(y)) return 0; 32 | if (Map[x][y]) { 33 | return 1; 34 | } else return 0; 35 | return 0; 36 | } 37 | 38 | void dfs(int x, int y, int base, int height[][5]) { 39 | if (val[x][y] != 0) { 40 | return; 41 | } 42 | val[x][y] = CalcMod(base * height[x][y] % Mod + Mod); 43 | if (val[x][y] == 0) val[x][y] = 1; 44 | int t1 = 0, t2 = 0; 45 | if (check(x + dx[0], y + dy[0])) { 46 | dfs(x + dx[0], y + dy[0], val[x][y], height); 47 | t1 = 1; 48 | } 49 | if (check(x + dx[1], y + dy[1])) { 50 | dfs(x + dx[1], y + dy[1], val[x][y], height); 51 | t2 = 1; 52 | } 53 | if (t1 != 0 || t2 != 0) return; 54 | val[x][y] = -1; 55 | } 56 | 57 | int main() { 58 | printf("19373459\n"); 59 | int i = 0, j; 60 | int height[5][5]; 61 | while (i < 5) { 62 | j = 0; 63 | while (j < 5) { 64 | height[i][j] = getint(); 65 | j = j + 1; 66 | } 67 | i = i + 1; 68 | if (i == 5) break; 69 | else continue; 70 | } 71 | i = 0; 72 | ; 73 | i; 74 | while(i < 2) { 75 | strP[i] = getint(); 76 | i = i + 1; 77 | } 78 | base = getint(); 79 | dfs(strP[0], strP[1], base, height); 80 | printf("val20: %d, val21:%d, val22:%d, val23:%d, val24:%d\n", val[2][0], val[2][1], val[2][2], val[2][3], val[2][4]); 81 | printf("val30: %d, val32: %d, val34: %d\n", val[3][0], val[3][2], val[3][4]); 82 | printf("val40: %d, val42:%d, val43:%d, val44:%d\n", val[4][0], val[4][2], val[4][3], val[4][4]); 83 | return 0; 84 | } -------------------------------------------------------------------------------- /testcases/A/testfile17.txt: -------------------------------------------------------------------------------- 1 | const int hehe[2][7] = {{1, 2, 5, 10, 20, 50, 100}, {1, 5, 10, 20, 50, 100, 200}}; 2 | 3 | int min(int a, int b) { 4 | if (a > b) return b; 5 | return a; 6 | } 7 | 8 | int inner1(int dp[][501], int target, int size, int num[]) { 9 | int i = 1, j = 1; 10 | while (i < size) { 11 | j = -+-1; 12 | while (j <= target) { 13 | if (j < num[i]) { 14 | dp[i][j] = dp[i - 1][j]; 15 | }else if(j == num[i]) { 16 | dp[i][j] = 1; 17 | }else{ 18 | if(dp[i - 1][j] != 0 && dp[i][j - num[i]] != 0) { 19 | dp[i][j] = min(dp[i-1][j], dp[i][j - num[i]]+1); 20 | }else{ 21 | if (dp[i - 1][j]!=0) dp[i][j] = dp[i - 1][j]; 22 | else dp[i][j] = dp[i][j - num[i]]; 23 | } 24 | } 25 | j = j + 1; 26 | } 27 | 28 | i = i + 1; 29 | } 30 | return dp[size - 1][target]; 31 | } 32 | 33 | int smallmoney(int num[], int target, int size) { 34 | int dp[11][501]; 35 | int i = 1, j = 1; 36 | 37 | dp[0][0] = 0; 38 | while (i <= target) { 39 | if (i % num[0] == 0) { 40 | dp[0][i] = i/num[0]; 41 | } else { 42 | dp[0][i] = 0; 43 | } 44 | i = i + 1; 45 | } 46 | i = 1; 47 | while (i < size) { 48 | dp[i][0] = 0; 49 | i = i + 1; 50 | } 51 | 52 | return inner1(dp, target, size, num); 53 | } 54 | 55 | int main() { 56 | int nums[2][7] = {{1, 2, 5, 10, 20, 50, 100}, {1, 5, 10, 20, 50, 100, 200}}; 57 | int i = 0, size = 9, max = 501; 58 | 59 | printf("19373487\n"); 60 | 61 | while (i < size) { 62 | int n; 63 | n = getint(); 64 | if (n >= max || n < 0) 65 | printf("out of range!!\n"); 66 | else { 67 | printf("the result is:%d\n", smallmoney(nums[0], n, 7)); 68 | } 69 | i = i + 1; 70 | } 71 | 72 | return 0; 73 | } -------------------------------------------------------------------------------- /testcases/A/testfile18.txt: -------------------------------------------------------------------------------- 1 | 2 | const int eye[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, D = 3; 3 | const int base[3] = {1, 0, 0}; 4 | int va[3][3], vb[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, vc[3] = {4, 5, 6}, vd[3], badname; 5 | 6 | int vdot(int x[], int y[]) { 7 | int d = 0, sum = 0; 8 | int useless; 9 | while (1 || 0) { 10 | sum = sum + x[d] * y[d] / 1; 11 | useless = sum % 2 - 3; 12 | d = d + 1; 13 | if (d == D || 0 && ! - sum < 7 + 1 || + sum > 8 - 1) break; 14 | else if (1) continue; 15 | else ; 16 | } 17 | return sum; 18 | } 19 | 20 | void print_id(int id) { 21 | printf("%d\n", id); 22 | if (0 && 4 > 5) return; 23 | } 24 | 25 | 26 | void print_vec(int x[]) { 27 | printf("%d %d %d\n", x[0], x[1], x[2]); 28 | } 29 | 30 | void uselessfunc() { 31 | int i = 0; 32 | i = i + 2 - 5 %2; 33 | if (i >= 3); 34 | } 35 | 36 | void print_mat(int m[][3]) { 37 | int dt = 0; 38 | while (!0) { 39 | print_vec(m[dt]); 40 | dt = dt + 1; 41 | if (dt < 3 && 1) {continue;} 42 | else if (1)break; 43 | else {} 44 | } 45 | } 46 | int main() { 47 | print_id(19373311); 48 | int d1 = 0; 49 | while (d1 != D || d1 < D) { 50 | int d2 = 0; 51 | while (d2 <= D - 1) { 52 | va[d1][d2] = getint(); 53 | d2 = d2 + 1; 54 | } 55 | d1 = d1 + 1; 56 | } 57 | int cd = 5; 58 | while (cd) { 59 | cd = cd - 1; 60 | printf("123\n"); 61 | } 62 | print_vec(vc); 63 | int ans; 64 | ans = vdot(va[0], vc); 65 | printf("%d\n", ans); 66 | ans = vdot(va[1], vb[0]); 67 | printf("%d\n", ans); 68 | ans = vdot(va[2], vb[0]); 69 | printf("%d\n", ans); 70 | ans = vdot(va[0], vb[2]); 71 | printf("%d\n", ans); 72 | ans = vdot(va[0], vb[1]); 73 | printf("%d\n", ans); 74 | print_mat(vb); 75 | uselessfunc(); 76 | return 0; 77 | } 78 | 79 | -------------------------------------------------------------------------------- /testcases/A/testfile2.txt: -------------------------------------------------------------------------------- 1 | const int month_days[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; 2 | 3 | 4 | int get_days(int year,int month,int day){ 5 | int flag = 0; 6 | int i = 0; 7 | int days = 0; 8 | if(!(year%4) && (year%100)){ 9 | flag = 1; 10 | }else{ 11 | if(year%400 == 0){ 12 | flag = 1; 13 | } 14 | } 15 | while(i < month - 1){ 16 | days = days + month_days[i]; 17 | i = i + 1; 18 | } 19 | days = days + day; 20 | if(month > 2){ 21 | days = days + flag; 22 | } 23 | return days; 24 | } 25 | 26 | int main(){ 27 | int groups; 28 | int birth_year; 29 | int birth_month; 30 | int birth_day; 31 | int cur_year; 32 | int cur_month; 33 | int cur_day; 34 | int year; 35 | printf("16061069\n"); 36 | printf("input groups\n"); 37 | groups = getint(); 38 | while(groups != 0){ 39 | int live_days = 0; 40 | printf("input your birth year,month,day,ep:1998 1 1\n"); 41 | birth_year = getint(); 42 | birth_month = getint(); 43 | birth_day = getint(); 44 | printf("input current year,month,day,ep:2020 2 2\n"); 45 | cur_year = getint(); 46 | cur_month = getint(); 47 | cur_day = getint(); 48 | year = birth_year; 49 | if(cur_year < birth_year){ 50 | printf("please input time legally\n"); 51 | }else{ 52 | while(year < cur_year){ 53 | if(year%400 == 0){ 54 | live_days = live_days + 366; 55 | }else{ 56 | if(!(year%100) || (year%4)){ 57 | live_days = live_days + 365; 58 | }else{ 59 | live_days = live_days + 366; 60 | } 61 | } 62 | year = year + 1; 63 | } 64 | live_days = live_days - get_days(birth_year,birth_month,birth_day) + get_days(cur_year,cur_month,cur_day); 65 | if(live_days >= 0){ 66 | printf("you have lived %d days\n",live_days); 67 | }else{ 68 | printf("please input time legally\n"); 69 | } 70 | } 71 | groups = groups - 1; 72 | } 73 | return 0; 74 | } -------------------------------------------------------------------------------- /testcases/A/testfile21.txt: -------------------------------------------------------------------------------- 1 | /*/* 2 | * /testfile created with ``heart'' by 19373384 3 | * 4 | / 5 | */ 6 | void _ (){ 7 | const int _C= (-5*8)+ + 300/1- -7; 8 | printf ( "19%d384\n", _C + 120%121 - 14);// print 19373384 9 | return; 10 | } 11 | int DoNotCall(){ 12 | while(1){} 13 | return -1; 14 | } 15 | int addN(int p0, int N){ 16 | int i = 0; 17 | while(1){ 18 | if(i == 0){ 19 | i = i + 1; 20 | continue; 21 | }else{ 22 | p0 = p0 + 1; 23 | if(i == N){ 24 | break; 25 | } 26 | i = i + 1; 27 | } 28 | } 29 | return p0; 30 | } 31 | int add2(int p0){ 32 | return addN(p0, 2); 33 | } 34 | void aAddN(int a[], int length, int N){ 35 | int i = 0; 36 | while(i < length){ 37 | a[i] = addN(a[i], N); 38 | i = i + 1; 39 | } 40 | } 41 | void addBoardcast(int a[][2], int b[], int length){ 42 | int i = 0; 43 | while(i < length){ 44 | int j = 0; 45 | while(j < 2){ 46 | a[i][j] = a[i][j] + b[j]; 47 | j = j + 1; 48 | } 49 | i = i + 1; 50 | } 51 | } 52 | int main( ) 53 | {/*//*//*PrintId*/_();;{}/*//"*/ 54 | 55 | printf("const and var // decl and def test\n"); 56 | int f0; 57 | int f1[2]; 58 | int f2[2][2]; 59 | int g0 = 2, g1[2] = {5, 6}, g2[2][2] = {{7, 10}, {27, 96}}; 60 | const int h1[2] = {1, 3}, h11[2] = {2, 4}; 61 | const int h2[2][2] = {{h11[0], h1[1]}, {h1[0], h11[1]}}; 62 | f1[0] = g1[1]; 63 | f0 = h2[0][1] + f1[0] * g2[1][1]; 64 | printf("expected result: 579, output: %d\n", f0); 65 | if(579 != f0){ 66 | return 1; 67 | } 68 | 69 | printf("function (def and )call test\n"); 70 | f1[0] = add2(f0); 71 | f1[1] = addN(h1[1], 5); 72 | aAddN(f1, 2, 3); 73 | f2[0][0] = 5; 74 | f2[0][1] = 10; 75 | f2[1][0] = 15; 76 | f2[1][1] = 20; 77 | addBoardcast(f2, f1, 2); 78 | printf("expected result: {{589, 21}, {599, 31}}, output: {{%d, %d}, {%d, %d}}\n", f2[0][0], f2[0][1], f2[1][0], f2[1][1]); 79 | if(f2[0][0] != 589) return 2; 80 | if(f2[0][1] != 21) return 2; 81 | if(f2[1][0] != 599) return 2; 82 | if(f2[1][1] != 31) return 2; 83 | 84 | printf("LExp test, falling into infinite loop indicates an error -- "); 85 | if(0 || 2 < 1 || 1 > 1 || 3 >= 5 || 7 <= 6 || 9 == 10 || 1 || DoNotCall()); 86 | if(!0 && !2 && DoNotCall()); 87 | printf("pass\n"); 88 | 89 | printf("simple echo test, get a integer and read back: "); 90 | int gk; 91 | gk = getint(); 92 | printf("%d\n", gk); 93 | 94 | printf("\n\n================================================================================\n PASSED \n================================================================================\n"); 95 | return 0; 96 | } 97 | -------------------------------------------------------------------------------- /testcases/A/testfile23.txt: -------------------------------------------------------------------------------- 1 | const int global_const_var = 0; 2 | int glbal_var; 3 | int f() { 4 | return 0; 5 | } 6 | int g(int x) { 7 | int g_var; 8 | g_var = 3; 9 | return x*g_var; 10 | } 11 | void h(int x,int y[],int z[][3]) { 12 | return; 13 | } 14 | int func() { 15 | int func_var1; 16 | func_var1 = getint(); 17 | printf("123456789\n"); 18 | printf("%d\n",func_var1); 19 | func_var1 = 1+1; 20 | ; 21 | 3; 22 | { 23 | } 24 | if(1) { 25 | } 26 | if(1) { 27 | } else { 28 | } 29 | while(1){ 30 | if(1){ 31 | break; 32 | } 33 | continue; 34 | } 35 | return 1; 36 | } 37 | int main() { 38 | printf("19373421\n"); 39 | const int const_var1 = 1, const_var2 = 2; 40 | const int const_array1[2] = {1,2}; 41 | const int const_array2[2] = {}; 42 | const int const_array3[2][2] = {{1,1},{2,2}}; 43 | printf("const_var1+const_var2=:%d\n",const_var1+const_var2); 44 | printf("const_array1[1]=:%d\n",const_array1[1]); 45 | int var1; 46 | int var2,var3; 47 | int var4 = 1; 48 | int array1[2]; 49 | int array2[2] = {3,4}; 50 | int array4[2][2]; 51 | int array5[2][2] = {{3,3},{4,4}}; 52 | int array6[3][3] = {{1,1,1},{2,2,2},{3,3,3}}; 53 | printf("array2[0]:=%d\n",array2[0]); 54 | var1 = 1; 55 | array2[1] = 1; 56 | array5[1][1] = 1; 57 | (1); 58 | var1; 59 | 3; 60 | f(); 61 | g(1); 62 | printf("g(2):=%d\n",g(2)); 63 | h(1,array2,array6); 64 | -3; 65 | +3; 66 | h(1,array6[1],array6); 67 | 3+3*3+3/3-3%3; 68 | if(1<2){ 69 | if(1>2){ 70 | if(1<=2){ 71 | if(1>=2){ 72 | if(!1){ 73 | } 74 | } 75 | } 76 | } 77 | } 78 | if(1<2){ 79 | if(1<2==1){ 80 | if(3!=4){ 81 | } 82 | } 83 | } 84 | if(1!=2&&3==3){ 85 | if(1==2||3==4){ 86 | } 87 | } 88 | func(); 89 | var1 = getint(); 90 | var2 = getint(); 91 | printf("%d\n%d\n",var1+var2,var1*var2); 92 | printf("AK!!!"); 93 | return 0; 94 | } -------------------------------------------------------------------------------- /testcases/A/testfile3.txt: -------------------------------------------------------------------------------- 1 | 2 | //test exp 3 | //test exp 4 | //test exp 5 | //test exp 6 | const int ca = 1, caa = 1; 7 | const int cc[3] = { 1,2,3 }; 8 | const int ce[2][3] = { {1,2,3},{4,5,6} }; 9 | int aa = 1, aaa = 1; 10 | int ab; 11 | int ac[10]; 12 | int ad[3] = { 1,2,3 }; 13 | int ae[10][10]; 14 | int af[2][3] = { {1,2,3},{4,5,6} }; 15 | int func1() { 16 | return 0; 17 | } 18 | int func2(int a) { 19 | 20 | int b = 1; 21 | int c = a * b; 22 | int d = c + a * b; 23 | int e = d / c; 24 | int f = e % d; 25 | int g = func1(); 26 | int h = g; 27 | if (!g) 28 | h = 1; 29 | int i = -a; 30 | int j = +b; 31 | int k[10]; 32 | int l[3] = { 1,2,3 }; 33 | int m[10][10]; 34 | int n[2][3] = { {1,2,3},{4,5,6} }; 35 | c = a - b; 36 | g = n[0][1]; 37 | i = l[1]; 38 | if (a == b && c == d) 39 | a = 1; 40 | if (a == b || c == d) 41 | a = 1; 42 | if (a == b) 43 | c = 1; 44 | if (a != b) 45 | c = 1; 46 | f = a; 47 | 48 | return f; 49 | } 50 | //test func 51 | //test func 52 | //test func 53 | //test func 54 | void func3(int a[]) { 55 | return; 56 | } 57 | void func4(int a, int b[][3]) { 58 | printf("%d\n", a); 59 | } 60 | void func5(int a, int b) { 61 | 62 | func3(ad); 63 | } 64 | int func6(int a, int b) { 65 | func5(12, 13); 66 | func5(ce[0][1], ce[0][2]); 67 | return 0; 68 | } 69 | int func7() { 70 | int a = 1; 71 | if(a == 100) { 72 | a = 1; 73 | } 74 | if (a >= 1) a = 1; 75 | if (a <= 1) a = 1; 76 | if (a > 1) a = 1; 77 | if (a < 1) a = 1; 78 | if (a == 1) a = 2; 79 | else a = 3; 80 | if (a != 1) a = 2; 81 | else a = 3; 82 | while (a == 5) 83 | a = 4; 84 | while (a == 6) 85 | break; 86 | while (a == 100) 87 | continue; 88 | a = getint(); 89 | return a; 90 | } 91 | void func10() { 92 | 93 | } 94 | int main() 95 | { 96 | printf("19373734\n"); 97 | printf("19373734\n"); 98 | printf("19373734\n"); 99 | printf("19373734\n"); 100 | printf("19373734\n"); 101 | printf("19373734\n"); 102 | printf("19373734\n"); 103 | printf("19373734\n"); 104 | printf("19373734\n"); 105 | printf("19373734"); 106 | int number1 = func2(3); 107 | int b = (12 + 3); 108 | ; 109 | return 0; 110 | } 111 | -------------------------------------------------------------------------------- /testcases/A/testfile4.txt: -------------------------------------------------------------------------------- 1 | int getlogictrue() { 2 | return 1; 3 | } 4 | int main() { 5 | printf("19231258 "); 6 | if (!0 == 1 && 1 == 1) { 7 | printf("OK1\n"); 8 | } 9 | if (1 == 1 && 1 == 1 && 1 == 1 || 2 == 1 && 1 == 1) { 10 | printf("OK2\n"); 11 | } 12 | if (+-1 == -+-+0 && 1 == 1 && 2 == 2) { 13 | ; 14 | } else { 15 | printf("OK3\n"); 16 | } 17 | if (1 || 2 == 3) { 18 | printf("OK4\n"); 19 | } 20 | if (0 || 0 && 3) { 21 | ; 22 | } else { 23 | printf("OK5\n"); 24 | } 25 | if (0 || 1 && 2) { 26 | printf("OK6\n"); 27 | } 28 | if (1 >= 0 == 1 && 1 || 2 && 3 == 1 > 0) { 29 | printf("OK7\n"); 30 | } else { 31 | printf("OK7\n"); 32 | } 33 | if (1 + 1 > 0 != !1 && 7 || 8 && !7 == 0) { 34 | printf("OK8\n"); 35 | } 36 | if (!(getlogictrue() * 1) >= 0) { 37 | printf("OK9\n"); 38 | } 39 | return 0; 40 | } -------------------------------------------------------------------------------- /testcases/A/testfile8.txt: -------------------------------------------------------------------------------- 1 | const int a=0; 2 | const int b=10,c=100; 3 | const int A[2]={0,1}; 4 | const int B[5][5]={{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; 5 | int p =0; 6 | void Func5(int g) 7 | { 8 | return ; 9 | } 10 | void Func4(int N[][2]) 11 | { 12 | printf("Func4OK\n"); 13 | return ; 14 | } 15 | void Func3(int M[]) 16 | { 17 | printf("Func3OK\n"); 18 | return ; 19 | } 20 | int Func2(int z) 21 | { 22 | z=z*(z/z)%z; 23 | printf("%d",z); 24 | printf("Func2OK\n"); 25 | return z; 26 | } 27 | int Func1(int x,int y) 28 | { 29 | if(x!=y) 30 | { 31 | if(x>=y) 32 | { 33 | printf("fb:%d\n",x); 34 | return x; 35 | } 36 | else 37 | { 38 | printf("sb:%d\n",y); 39 | return y; 40 | } 41 | } 42 | printf("Func1OK\n"); 43 | return -1; 44 | } 45 | void Func0() 46 | { 47 | int m,n,i=0,j; 48 | int C[2]; 49 | int D[2][2]; 50 | m=getint(); 51 | n=getint(); 52 | while(i<2||i<2) 53 | { 54 | C[i]=getint(); 55 | i=i+1; 56 | 57 | } 58 | printf("CscanfOK\n"); 59 | while(!1); 60 | +8; 61 | i=0; 62 | 63 | while(i<=1) 64 | { 65 | j=0; 66 | while(j<2) 67 | { 68 | D[i][j]=getint(); 69 | j=j+1; 70 | } 71 | i=i+1; 72 | } 73 | printf("DscanfOK\n"); 74 | m=Func1(m,n); 75 | if(m==-1) 76 | { 77 | printf("same\n"); 78 | return ; 79 | } 80 | i=0; 81 | while(1) 82 | { 83 | if(i==0&&i>-1) 84 | { 85 | i=i-1; 86 | printf("continueOK\n"); 87 | continue; 88 | printf("continueGG\n"); 89 | } 90 | printf("breakOK\n"); 91 | break; 92 | printf("breakGG\n"); 93 | } 94 | i=1; 95 | i=Func2(i); 96 | Func3(C); 97 | Func4(D); 98 | Func5(C[0]); 99 | return ; 100 | } 101 | int main() 102 | { 103 | printf("19182619\n"); 104 | Func0(); 105 | printf("end"); 106 | return 0; 107 | } -------------------------------------------------------------------------------- /testcases/A/testfile9.txt: -------------------------------------------------------------------------------- 1 | // #include "test.h" 2 | int next[4][2]={{1,0},{0,-1},{-1,0},{0,1}}; 3 | const int len=3,next1[4][2]={{1,0},{0,-1},{-1,0},{0,1}}; 4 | const int xxx[2]={1,2}; 5 | int ans=0,arr[2]={3,1}; 6 | int getDif3N(int min,int max){ 7 | int i=1,j=1,k=1; 8 | int cnt=0; 9 | int arr1[2]={1,2}; 10 | while(i<=3){ 11 | j=1; 12 | while(j<=3){ 13 | k=1; 14 | while(k<=3){ 15 | if(i!=j&&i!=k&&j!=k){ 16 | cnt=cnt+1; 17 | } 18 | k=k+1; 19 | } 20 | j=j+1; 21 | } 22 | i=i+1; 23 | } 24 | return cnt; 25 | } 26 | int judgeB(int a,int b){ 27 | if(a<=b){ 28 | if(a=b){ 34 | if(a>b){ 35 | return a-b; 36 | } else if(a==b){ 37 | return 0; 38 | } 39 | } 40 | return 0; 41 | } 42 | void printArr(int a[]){ 43 | int i=0; 44 | while(i<2){ 45 | printf("%d",a[i]); 46 | i=i+1; 47 | } 48 | printf("\n"); 49 | } 50 | void printArr2(int a[][2]){ 51 | int i=0; 52 | while(i<4){ 53 | printArr(a[i]); 54 | i=i+1; 55 | } 56 | return; 57 | } 58 | void printHello(){ 59 | int name; 60 | name=getint(); 61 | printf("Hello %d\n",name); 62 | } 63 | int add(int n){ 64 | int ans; 65 | ans=n+3; 66 | return ans; 67 | } 68 | void opp(){ 69 | 70 | } 71 | int main(){ 72 | printf("19373573\n"); 73 | int ans; 74 | ; 75 | {} 76 | { 77 | ans=3; 78 | } 79 | int i=0; 80 | int y=1; 81 | if(!y){ 82 | y=0; 83 | } 84 | y=+1; 85 | y=-1; 86 | // y=-1; 87 | // y=+1; 88 | int xx; 89 | xx=(16+2)/(i+1)-14+next[0][0]; 90 | while(i<=5){ 91 | if(i==3){ 92 | i=i+1; 93 | continue; 94 | } 95 | if(i==5){ 96 | break; 97 | } else { 98 | int j=i; 99 | } 100 | i=i+1; 101 | } 102 | ans=getint(); 103 | printf("%d\n",add(ans)); 104 | ans=getDif3N(1,999); 105 | printf("%d\n",ans); 106 | ans=judgeB(2,3); 107 | printf("judgeB 2,3 = %d\n",ans); 108 | printHello(); 109 | printArr2(next); 110 | printArr(next[0]); 111 | printArr(arr); 112 | return 0; 113 | } -------------------------------------------------------------------------------- /testcases/B/input1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coekjan/MIPSysY-Compiler/772e50d5f4ac1114c8a9f880264a659d99575cb2/testcases/B/input1.txt -------------------------------------------------------------------------------- /testcases/B/input10.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 4 4 | 5 -------------------------------------------------------------------------------- /testcases/B/input11.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 2 3 | 3 4 | 1 5 | 0 -------------------------------------------------------------------------------- /testcases/B/input12.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coekjan/MIPSysY-Compiler/772e50d5f4ac1114c8a9f880264a659d99575cb2/testcases/B/input12.txt -------------------------------------------------------------------------------- /testcases/B/input13.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 4 3 | -------------------------------------------------------------------------------- /testcases/B/input14.txt: -------------------------------------------------------------------------------- 1 | 1150 -------------------------------------------------------------------------------- /testcases/B/input15.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 4 4 | 5 -------------------------------------------------------------------------------- /testcases/B/input16.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coekjan/MIPSysY-Compiler/772e50d5f4ac1114c8a9f880264a659d99575cb2/testcases/B/input16.txt -------------------------------------------------------------------------------- /testcases/B/input17.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 19123412 3 | 53 4 | 12142344 5 | 89 6 | 12354123 7 | 35 8 | 32151245 9 | 65 10 | 21532521 11 | 93 12 | 21654212 13 | 13 14 | 12312654 15 | 89 16 | 56335232 17 | 87 18 | 15687643 19 | 78 20 | 56323432 21 | 78 22 | -------------------------------------------------------------------------------- /testcases/B/input18.txt: -------------------------------------------------------------------------------- 1 | 123 2 | 0 3 | -234 -------------------------------------------------------------------------------- /testcases/B/input19.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /testcases/B/input2.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 2 3 | -------------------------------------------------------------------------------- /testcases/B/input20.txt: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testcases/B/input21.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coekjan/MIPSysY-Compiler/772e50d5f4ac1114c8a9f880264a659d99575cb2/testcases/B/input21.txt -------------------------------------------------------------------------------- /testcases/B/input22.txt: -------------------------------------------------------------------------------- 1 | 11 -------------------------------------------------------------------------------- /testcases/B/input23.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 9 -------------------------------------------------------------------------------- /testcases/B/input24.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coekjan/MIPSysY-Compiler/772e50d5f4ac1114c8a9f880264a659d99575cb2/testcases/B/input24.txt -------------------------------------------------------------------------------- /testcases/B/input25.txt: -------------------------------------------------------------------------------- 1 | 23 2 | 26 3 | 353 4 | -------------------------------------------------------------------------------- /testcases/B/input26.txt: -------------------------------------------------------------------------------- 1 | 13 2 | 29 3 | 37 4 | -------------------------------------------------------------------------------- /testcases/B/input27.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /testcases/B/input3.txt: -------------------------------------------------------------------------------- 1 | 9 2 | 8 3 | 7 4 | 6 5 | -------------------------------------------------------------------------------- /testcases/B/input4.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coekjan/MIPSysY-Compiler/772e50d5f4ac1114c8a9f880264a659d99575cb2/testcases/B/input4.txt -------------------------------------------------------------------------------- /testcases/B/input5.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 20 3 | 30 -------------------------------------------------------------------------------- /testcases/B/input6.txt: -------------------------------------------------------------------------------- 1 | 12308760 2 | -------------------------------------------------------------------------------- /testcases/B/input7.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /testcases/B/input8.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 8 3 | 7 4 | 6 5 | 5 6 | 4 7 | 3 8 | 2 9 | 1 10 | -------------------------------------------------------------------------------- /testcases/B/input9.txt: -------------------------------------------------------------------------------- 1 | 10 -------------------------------------------------------------------------------- /testcases/B/output1.txt: -------------------------------------------------------------------------------- 1 | 19373749 2 | 4 3 | 2 4 | no 5 | 0 6 | 0 7 | 0 8 | 1 9 | 1 10 | -1 -------------------------------------------------------------------------------- /testcases/B/output10.txt: -------------------------------------------------------------------------------- 1 | 19373330 2 | n 4 3 | p 25 4 | i 1 5 | sum of two D 3 6 | const D + 10 is 10 -_- 7 | after sort 1 1 3 4 5 8 | Squ const2 + 101 115 9 | slee882641 10 | sadhiukashjfasodifd51023sad65saf1erwg0fdss5a6d1asd56sa0ds55saad511sa2d31asd556gdsfsadsa 11 | -------------------------------------------------------------------------------- /testcases/B/output11.txt: -------------------------------------------------------------------------------- 1 | 19182616 2 | 5 is a prime number 3 | c and d are both positive 4 | 2 5 | 3 6 | 4 7 | 1 8 | 2 9 | 5 10 | 6 -------------------------------------------------------------------------------- /testcases/B/output12.txt: -------------------------------------------------------------------------------- 1 | 19182622 2 | 19182622 3 | 19182622 4 | 19182622 5 | 19182622 6 | 19182622 7 | 19182622 8 | 19182622 9 | 19182622 10 | 19182622 -------------------------------------------------------------------------------- /testcases/B/output14.txt: -------------------------------------------------------------------------------- 1 | 19373459 2 | f1: 8221 3 | f0: 0 4 | ori00:5577 5 | -------------------------------------------------------------------------------- /testcases/B/output15.txt: -------------------------------------------------------------------------------- 1 | 19373479 2 | print int : 2 3 | print int : 2 4 | print int : 0 5 | print int : 41 6 | print int : 61 7 | print int : 4884 8 | print int : -45015 9 | print int : 10432 -------------------------------------------------------------------------------- /testcases/B/output16.txt: -------------------------------------------------------------------------------- 1 | 19373466 2 | const declaration: const int a[4][2]={{1, 2}, {3, 4}, {5, 6}, {7, 8}}, b[2][1] = {{9}, {10}} 3 | global var declaration: int c[1][2]={{11, 12}} 4 | global var declaration(not initialized): des[4][1], des2[4][2] 5 | use ConstDef in FuncFParam (exactly, the len of array) 6 | calculate a * b, your result is des[4][1] = {{29}, {67}, {105}, {143}} 7 | calculate des * c 8 | then calculate the sum of each row(store in rowSum[4]) 9 | your result is (4 row): 667, 1541, 2415, 3289 10 | finish 11 | -------------------------------------------------------------------------------- /testcases/B/output17.txt: -------------------------------------------------------------------------------- 1 | 19373372 2 | input > 19123412 53 3 | input > 12142344 89 4 | input > 12354123 35 5 | input > 32151245 65 6 | input > 21532521 93 7 | input > 21654212 13 8 | input > 12312654 89 9 | input > 56335232 87 10 | input > 15687643 78 11 | input > 56323432 78 12 | 19123412 -> 53 13 | 12142344 -> 89 14 | 12354123 -> 35 15 | 32151245 -> 65 16 | 21532521 -> 93 17 | 21654212 -> 13 18 | 12312654 -> 89 19 | 56335232 -> 87 20 | 15687643 -> 78 21 | 56323432 -> 78 22 | swap <19123412 53> <-> <12142344 89> 23 | swap <12142344 89> <-> <21532521 93> 24 | swap <19123412 53> <-> <32151245 65> 25 | swap <32151245 65> <-> <12142344 89> 26 | swap <12354123 35> <-> <19123412 53> 27 | swap <19123412 53> <-> <32151245 65> 28 | swap <32151245 65> <-> <12312654 89> 29 | swap <12354123 35> <-> <19123412 53> 30 | swap <19123412 53> <-> <32151245 65> 31 | swap <32151245 65> <-> <56335232 87> 32 | swap <12354123 35> <-> <19123412 53> 33 | swap <19123412 53> <-> <32151245 65> 34 | swap <32151245 65> <-> <15687643 78> 35 | swap <21654212 13> <-> <12354123 35> 36 | swap <12354123 35> <-> <19123412 53> 37 | swap <19123412 53> <-> <32151245 65> 38 | swap <32151245 65> <-> <56323432 78> 39 | swap <21654212 13> <-> <12354123 35> 40 | swap <12354123 35> <-> <19123412 53> 41 | swap <19123412 53> <-> <32151245 65> 42 | swap <21654212 13> <-> <12354123 35> 43 | swap <12354123 35> <-> <19123412 53> 44 | swap <21654212 13> <-> <12354123 35> 45 | 9 46 | 21532521 -> 93 47 | 12142344 -> 89 48 | 12312654 -> 89 49 | 56335232 -> 87 50 | 15687643 -> 78 51 | 56323432 -> 78 52 | 32151245 -> 65 53 | 19123412 -> 53 54 | 12354123 -> 35 55 | 21654212 -> 13 56 | -------------------------------------------------------------------------------- /testcases/B/output18.txt: -------------------------------------------------------------------------------- 1 | 19373755 2 | n1 = 100 3 | n2-5 = -30 4 | n2 + n3 = -15 5 | n2 * n3 = -250 6 | ! ()*+,-./0123456789:; 7 | <=>?@ 8 | ABCDEFGHIJKLMNOPQRSTUVWXYZ 9 | []^_` 10 | abcdefghijklmnopqrstuvwxyz{|}~ -------------------------------------------------------------------------------- /testcases/B/output19.txt: -------------------------------------------------------------------------------- 1 | 19373135 2 | test func, should be 2: 2 3 | test func, should be 2: 2 4 | test Exp, should be 5: 5 5 | test Block, should be 2: 2 6 | test if, should be 2, 2: 2, 2 7 | test while, should be 6: 6 8 | test break continue, should be 0, 1: 0, 1 9 | test printf, should be 2: 2 10 | test getint, should be 1: 1 11 | -------------------------------------------------------------------------------- /testcases/B/output2.txt: -------------------------------------------------------------------------------- 1 | 19231007 2 | input recurrent cycle: 3 | cycle is: 2 4 | input initial value: 5 | initial value is: 2 6 | your input is good 7 | A = 7 8 | B = 3 9 | C = 1 10 | final value is: 1010 11 | -------------------------------------------------------------------------------- /testcases/B/output20.txt: -------------------------------------------------------------------------------- 1 | 19373408 all weak points 2 | L and Eq is ok (no params) 3 | Rel is ok (with params) 4 | Add is ok1 5 | Add is ok2 6 | -1 7 | -1 8 | 1 9 | 1 10 | -------------------------------------------------------------------------------- /testcases/B/output21.txt: -------------------------------------------------------------------------------- 1 | 19373384 2 | [1, 3, 5, 7, 9, 11, 2, 9, 7, 8] 3 | [2, 5, 4, 8, 9, 6, 3, 7, 1, 1] 4 | Inner product: expect 324, output: 324 5 | SBC step 1: expect:[12, 25, 26, 42, 49, 44, 17, 43, 21, 23] 6 | output:[12, 25, 26, 42, 49, 44, 17, 43, 21, 23] 7 | SBC step 2 and EWM: expect:[70, 350, 276, 904, 1170, 666, 144, 784, 50, 54] 8 | output:[70, 350, 276, 904, 1170, 666, 144, 784, 50, 54] 9 | 10 | 11 | ================================================================================ 12 | PASSED 13 | ================================================================================ 14 | -------------------------------------------------------------------------------- /testcases/B/output22.txt: -------------------------------------------------------------------------------- 1 | 19373339 2 | 2 3 | 3 4 | 4 5 | 13 6 | 2 7 | 123456 8 | 123456 9 | 123456 -------------------------------------------------------------------------------- /testcases/B/output23.txt: -------------------------------------------------------------------------------- 1 | 19373611 2 | 19373611 3 | 19373611 4 | Please input base number a: 5 | Please input base number b: 6 | The No.0 number is -4. 7 | The No.1 number is 0. 8 | The No.2 number is 5. 9 | The No.3 number is 14. 10 | The No.4 number is 45. -------------------------------------------------------------------------------- /testcases/B/output24.txt: -------------------------------------------------------------------------------- 1 | 19373063 2 | 1.localVirable1 = 11,localVirable2 = 10 3 | 2. 4 | [2][0]:10|10 , [2]:-7|30 5 | [1][0]:8|8 , [1]:-8|20 6 | [0][0]:6|6 , [0]:-9|10 7 | 9? 8 | 3.function of kinds of parameters testified 9 | 4.non exp testified -------------------------------------------------------------------------------- /testcases/B/output25.txt: -------------------------------------------------------------------------------- 1 | 19373341 2 | m = 6, n = 23, mm = 26, nn = 353 3 | max of mm and nn: 353; min of mm and nn: 26 4 | mainConst1 = 10 5 | Sum of normalConst: 35 6 | 23 is odd! 7 | Sum of array: 6 8 | sum of array: 24 9 | array contains 4 even number! 10 | All even! 11 | -------------------------------------------------------------------------------- /testcases/B/output26.txt: -------------------------------------------------------------------------------- 1 | 19373341 2 | m = 3, n = 13, mm = 29, nn = 37 3 | max of mm and nn: 37; min of mm and nn: 29 4 | mainConst1 = 10 5 | Sum of normalConst: 66 6 | 13 is odd! 7 | Sum of array: 3 8 | sum of array: 24 9 | array contains 3 even number! 10 | All even! 11 | -------------------------------------------------------------------------------- /testcases/B/output27.txt: -------------------------------------------------------------------------------- 1 | 1837518218183751821837518218375182 -------------------------------------------------------------------------------- /testcases/B/output3.txt: -------------------------------------------------------------------------------- 1 | 19231111 2 | 0 2 3 0 3 | 0 2 3 0 4 | 6 2 12 6 5 | 23 20 55 48 6 | 5 7 | true 8 | true 9 | 2 10 | 123 11 | 123 12 | -------------------------------------------------------------------------------- /testcases/B/output4.txt: -------------------------------------------------------------------------------- 1 | 19231047 2 | climb 0 : 1 3 | climb 3 : 3 4 | climb 6 : 13 5 | test return1 : 14 6 | test climb sum 7 : 21 7 | test product - sum : 2854 8 | test nest 1 : 13 9 | test nest 2 : 89 10 | test file -------------------------------------------------------------------------------- /testcases/B/output5.txt: -------------------------------------------------------------------------------- 1 | 19231177 2 | b=5 3 | 20 4 | 30 5 | testBlock : b=1524 6 | result = 79626240 7 | 1 2 3 4 sum is : 10 8 | line1 is:11111;line2 is : 22222; line3 is : 33333; 9 | 1+2=3 10 | 1+2=3 11 | 19231177 -------------------------------------------------------------------------------- /testcases/B/output6.txt: -------------------------------------------------------------------------------- 1 | 19231150 2 | what you enter in is:12308760 3 | _a=5 4 | array_c[0] is:1 5 | array_d[0][0] is:1 6 | array_d[1][0] is:2 7 | _a=10 8 | _a=103 9 | 2 2 2 3 3 3 3 5 29 131 10 | Over -------------------------------------------------------------------------------- /testcases/B/output7.txt: -------------------------------------------------------------------------------- 1 | 19231188111111111 -------------------------------------------------------------------------------- /testcases/B/output8.txt: -------------------------------------------------------------------------------- 1 | 19231076 2 | >/!~varg1 is:1;~ 3 | >/!~varg2 is:6;~ 4 | >/!~varg3 is:7;~ 5 | >/!~varg4 is:6;~ 6 | >/!~varg5 is:5;~ 7 | >/!~varg6 is:4;~ 8 | >/!~varg7 is:3;~ 9 | >/!~varg8 is:2;~ 10 | >/!~varg9 is:-1;~ 11 | -------------------------------------------------------------------------------- /testcases/B/output9.txt: -------------------------------------------------------------------------------- 1 | 193733852345678910 -------------------------------------------------------------------------------- /testcases/B/testfile1.txt: -------------------------------------------------------------------------------- 1 | const int cnum1 = 1; 2 | const int cnum2 = 2, cnum3 = 3; 3 | const int carray1[2] = {1,2}; 4 | const int carray2[2] = {3,4}, carray3[2] = {5,6}; 5 | const int carrays1[2][2] = {{1,2},{3,4}}; 6 | const int carrays2[2][2] = {{1,2},{5,6}}, carrays3[2][2] = {{1,2},{7,8}}; 7 | void vfun1() { 8 | } 9 | void vfun2(int a) { 10 | } 11 | void vfun3(int a, int b) { 12 | } 13 | void vfun4(int a[]) { 14 | } 15 | void vfun5(int a[], int b[]) { 16 | } 17 | void vfun6(int a[][2]) { 18 | } 19 | void vfun7(int a[][2],int b[][2]) { 20 | } 21 | int ifun1() { 22 | return 0; 23 | } 24 | int ifun2(int a) { 25 | return a+a; 26 | } 27 | int ifun3(int a, int b) { 28 | return a+b; 29 | } 30 | int ifun4(int a[]) { 31 | return a[0]; 32 | } 33 | int ifun5(int a[], int b[]) { 34 | return a[0]+b[0]; 35 | } 36 | int ifun6(int a[][2]) { 37 | return a[0][0]; 38 | } 39 | int ifun7(int a[][2],int b[][2]) { 40 | return a[0][0] + b[0][0]; 41 | } 42 | int main() { 43 | printf("19373749\n"); 44 | int a = 0; 45 | int b = 0, c = 0; 46 | int array1[2] = {1,2}; 47 | int array2[2] = {3,4}, array3[2] = {5,6}; 48 | int arrays1[2][2] = {{1,2},{3,4}}; 49 | int arrays2[2][2] = {{1,2},{5,6}}, arrays3[2][2] = {{1,2},{7,8}}; 50 | a = 1; 51 | array1[a*a] = 3; 52 | printf("%d\n",array1[1] + array1[0]); 53 | { 54 | } 55 | a + b; 56 | ; 57 | if (1) { 58 | a = a; 59 | } 60 | if (1 < 0) { 61 | a = 1; 62 | } 63 | if (0 > 1) { 64 | a = 1; 65 | } 66 | if (1 <= 0) { 67 | a = 1; 68 | } 69 | if(a >= b){ 70 | a = a+a; 71 | } else { 72 | a = a+b; 73 | } 74 | printf("%d\n",a); 75 | if (a == b) { 76 | printf("yes\n"); 77 | } 78 | if (a != b) { 79 | printf("no\n"); 80 | } 81 | int i = 2; 82 | while (1) { 83 | if (i != 0) { 84 | i = i - 1; 85 | continue; 86 | } 87 | break; 88 | } 89 | a = b; 90 | a = 2; 91 | a = (a + b); 92 | a = +-a; 93 | a = ifun1(); 94 | array1[1] = ifun2(b); 95 | printf("%d\n",array1[1]); 96 | arrays1[0][0] = ifun3(a,b); 97 | printf("%d\n",arrays1[0][0]); 98 | a = a*arrays1[1][1]; 99 | a = a/arrays2[1][0]; 100 | a = a%arrays3[0][1]; 101 | printf("%d\n",a); 102 | a = ifun4(arrays3[0]); 103 | printf("%d\n",a); 104 | a = ifun7(arrays1,arrays2); 105 | printf("%d\n",a); 106 | a = a + array1[0] - array2[0]; 107 | printf("%d\n",a); 108 | return 0; 109 | } -------------------------------------------------------------------------------- /testcases/B/testfile11.txt: -------------------------------------------------------------------------------- 1 | const int MAX = 6; 2 | 3 | int main() 4 | { 5 | printf("19182616\n"); 6 | int a = 0; 7 | int num = 0; 8 | int i = 2; 9 | int c,d; 10 | int j = 1, sum; 11 | int k; 12 | num = getint(); 13 | c = getint(); 14 | d = getint(); 15 | sum = getint(); 16 | k = getint(); 17 | if(num >= 2) 18 | { 19 | while(i0 && d>0) 36 | { 37 | printf("c and d are both positive\n"); 38 | } 39 | else 40 | { 41 | printf("Neither c nor d are positive\n"); 42 | } 43 | 44 | while(1) 45 | { 46 | sum = sum + 1; 47 | printf("%d\n", sum); 48 | j = j + 1; 49 | if(j > 3)break; 50 | } 51 | while(k= 3){ 5 | printf("%d\n",id); 6 | i = i - 1; 7 | } 8 | while(i > 0){ 9 | printf("%d\n",id); 10 | i = i - 1; 11 | } 12 | int j = 0; 13 | while(j <= 3){ 14 | printf("%d\n",id); 15 | j = j + 1; 16 | } 17 | while(j < 5){ 18 | printf("%d\n",id); 19 | j = j + 1; 20 | } 21 | return; 22 | } 23 | 24 | int playID(int id) 25 | { 26 | int i = 0; 27 | while(i < id){ 28 | i = i + 1; 29 | if(i == 711){ 30 | continue; 31 | } 32 | if(i == 19182622){ 33 | break; 34 | } 35 | } 36 | return i; 37 | } 38 | int block(){return 1;} 39 | 40 | int main() 41 | { 42 | const int id = 19182622; 43 | printMyID(id); 44 | while(0); 45 | return 0; 46 | } -------------------------------------------------------------------------------- /testcases/B/testfile14.txt: -------------------------------------------------------------------------------- 1 | const int Mod = 10007; 2 | 3 | const int Map[2][2] = { 4 | {1, 1}, 5 | {1, 0} 6 | }, Bound[2] = {2, 2}; 7 | 8 | int T, f[2] = {1, 0}; 9 | int ori[2][2] = { 10 | {1, 0}, 11 | {0, 0} 12 | }; 13 | 14 | void calc(int a[][2], int b[][2]) { 15 | int i = 0, j = 0, k = 0; 16 | int Map[2][2]; 17 | while (i < Bound[0]) { 18 | j = 0; 19 | while (j < Bound[1]) { 20 | k = 0; 21 | int sum = 0; 22 | while (k < Bound[0]) { 23 | sum = (sum + a[i][k] * b[k][j] % Mod) % Mod; 24 | k = k + 1; 25 | } 26 | Map[i][j] = sum; 27 | j = j + 1; 28 | } 29 | i = i + 1; 30 | } 31 | i = 0; 32 | j = 0; 33 | while (i < Bound[0]) { 34 | while (j < Bound[1]) { 35 | a[i][j] = Map[i][j]; 36 | j = j + 1; 37 | } 38 | i = i + 1; 39 | } 40 | } 41 | 42 | int getans(int a[]) { 43 | int i = 0, sum = 0; 44 | while (i < Bound[0]) { 45 | sum = sum + a[i]; 46 | i = i + 1; 47 | } 48 | return sum; 49 | } 50 | 51 | void Copy(int a[][2]) { 52 | a[0][0] = Map[0][0]; a[0][1] = Map[0][1]; 53 | a[1][0] = Map[1][0]; a[1][1] = Map[1][1]; 54 | } 55 | 56 | int main() { 57 | printf("19373459\n"); 58 | T = getint(); 59 | int temp[2][2]; 60 | Copy(temp); 61 | while (T) { 62 | if (T / 2 * 2 != T) { 63 | calc(ori, temp); 64 | } else {} 65 | T = T / 2; 66 | calc(temp, temp); 67 | } 68 | int i = 0; 69 | while (i < Bound[0]) { 70 | printf("f%d: %d\n", f[i], getans(ori[i])); 71 | i = i + 1; 72 | } 73 | printf("ori00:%d\n", ori[0][0]); 74 | return 0; 75 | } -------------------------------------------------------------------------------- /testcases/B/testfile17.txt: -------------------------------------------------------------------------------- 1 | int array[100][2]; 2 | int len = 0; 3 | 4 | void swap(int i, int j) { 5 | printf("swap <%d %d> <-> <%d %d>\n", array[i][0], array[i][1], array[j][0], array[j][1]); 6 | int tmp[2] = {array[i][0], array[i][1]}; 7 | array[i][0] = array[j][0]; 8 | array[i][1] = array[j][1]; 9 | array[j][0] = tmp[0]; 10 | array[j][1] = tmp[1]; 11 | return; 12 | } 13 | 14 | void sort() { 15 | int i, j; 16 | i = 0; 17 | while (i < len - 1) { 18 | int f = 0; 19 | j = i + 1; 20 | while (j < len) { 21 | if (array[i][1] < array[j][1]) { 22 | swap(i, j); 23 | f = 1; 24 | } else if (array[i][1] == array[j][1]) { 25 | if (array[i][0] > array[j][0]) { 26 | swap(i, j); 27 | f = 1; 28 | } 29 | } 30 | j = j + 1; 31 | } 32 | if (!f) { 33 | printf("%d\n", i); 34 | return; 35 | } 36 | i = i + 1; 37 | } 38 | printf("%d\n", i); 39 | return; 40 | } 41 | 42 | int main() { 43 | len = getint(); 44 | int i; 45 | printf("19373372\n"); 46 | i = 0; 47 | { 48 | int i = 100; 49 | } 50 | while (i < len) { 51 | int x; 52 | x = getint(); 53 | int y; 54 | y = getint(); 55 | printf("input > %d %d\n", x, y); 56 | array[i][0] = x; 57 | array[i][1] = y; 58 | i = i + 1; 59 | } 60 | i = 0; 61 | while (i < len) { 62 | printf("%d -> %d\n", array[i][0], array[i][1]); 63 | i = i + 1; 64 | } 65 | sort(); 66 | i = 0; 67 | while (i < len) { 68 | printf("%d -> %d\n", array[i][0], array[i][1]); 69 | i = i + 1; 70 | } 71 | printf("");printf("");printf("");printf("");printf(""); 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /testcases/B/testfile2.txt: -------------------------------------------------------------------------------- 1 | const int a0 = 1; 2 | const int b0 = 2, c0 = 3; 3 | int a1 = 0, b1 = 0; 4 | int c1 = 0; 5 | 6 | const int s1[3] = {1,2,3}; 7 | const int s2[2][2] = {{1,2}, {3,4}}; 8 | int s3[3] = {1,2,3}; 9 | int s4[2][2] = {{1,2}, {3,4}}; 10 | 11 | int dealSet0(int s1[], int s2[][2]) { 12 | int i = 0, sum = 0; 13 | while (i<2) { 14 | sum = sum + s1[i] + s2[i][0] + s2[i][1]; 15 | i = i + 1; 16 | } 17 | return sum; 18 | } 19 | 20 | int getnumber() { 21 | int instantA,instantB,instantC; 22 | instantA = 1 + a0 + (b0 + c0); 23 | instantB = instantA * instantA / instantA % b0; 24 | instantB = instantA - (instantB + c0); 25 | if (b1b1!=a1>a1==b1<=b1==b1>=b1) { 26 | instantC = 1; 27 | } 28 | printf("A = %d\n", instantA); 29 | printf("B = %d\n", instantB); 30 | printf("C = %d\n", instantC); 31 | return 1; 32 | } 33 | 34 | int addself(int a) { 35 | return a+a; 36 | } 37 | 38 | int multself(int a) { 39 | return a*a; 40 | } 41 | 42 | void none(){ 43 | return; 44 | } 45 | 46 | void minus(int a, int b) { 47 | } 48 | 49 | int main() { 50 | int value; 51 | int i = 0, cycle; 52 | ; 53 | {} 54 | printf("19231007\n"); 55 | printf("input recurrent cycle:\n"); 56 | cycle = getint(); 57 | printf("cycle is: %d\n", cycle); 58 | 59 | printf("input initial value:\n"); 60 | value = getint(); 61 | printf("initial value is: %d\n", value); 62 | 63 | if (!0) { 64 | printf("your input is good\n"); 65 | while (i= 1) { 26 | val_Rel = val_Rel + 1; 27 | } 28 | if (a <= 2) { 29 | val_Rel = val_Rel + 1; 30 | } 31 | if (1 < b) { 32 | val_Rel = val_Rel + 1; 33 | } 34 | if (b > 2) { 35 | val_Rel = val_Rel + 1; 36 | } 37 | if (c == 2) { 38 | val_Rel = val_Rel + 1; 39 | } 40 | if (c != 3) { 41 | val_Rel = val_Rel + 1; 42 | } 43 | return val_Rel; 44 | } 45 | 46 | void check_Add(int x) { 47 | if (const_a == x) { 48 | printf("Add is ok1\n"); 49 | } 50 | if (const_b == 4) { 51 | printf("Add is ok2\n"); 52 | } 53 | } 54 | 55 | void check_block(int a2, int b2[], int c2[][2]) { 56 | int tmp0 = -1; 57 | int tmp1 = 1; 58 | if( a2 > 0 ) { 59 | while(tmp1 > 0) { 60 | tmp1 = tmp1 - 2; 61 | if (b2[1] == 0) { 62 | break; 63 | } 64 | tmp1 = tmp1 - 2; 65 | } 66 | } else { 67 | while(tmp0 < 0) { 68 | tmp0 = tmp0 + 2; 69 | if (c2[1][1] == 1) { 70 | continue; 71 | } 72 | tmp0 = tmp0 + 2; 73 | } 74 | } 75 | ; 76 | printf("%d\n",tmp0); 77 | printf("%d\n",tmp1); 78 | return; 79 | } 80 | 81 | 82 | int main() { 83 | int a, val_Rel; 84 | printf("19373408 all weak points\n"); 85 | check_LandEq(); 86 | val_Rel = check_Rel(1, 6, 2); 87 | if (val_Rel == 6) { 88 | printf("Rel is ok (with params)\n"); 89 | } else { 90 | printf("sth wrong with Rel (no params)\n"); 91 | } 92 | check_Add(-14); 93 | a = getint();//1 94 | check_block(a, var_array1_a, var_array2_a); 95 | check_block(-1, var_array1_a, var_array2_a); 96 | return 0; 97 | } -------------------------------------------------------------------------------- /testcases/B/testfile21.txt: -------------------------------------------------------------------------------- 1 | int global_counter = 0; 2 | int innerProduct(int a[], int b[], int length){ 3 | int i = 0; 4 | int res = 0; 5 | while(i < length){ 6 | res = res + a[i] * b[i]; 7 | i = i + 1; 8 | } 9 | return res; 10 | } 11 | void scaleBiasCombination(int res[], int a[], int s1, int b[], int s2, int bias, int length){ 12 | int i = 0; 13 | while(i < length){ 14 | res[i] = a[i] * s1 + b[i] * s2 + bias + global_counter; 15 | i = i + 1; 16 | } 17 | global_counter = global_counter + 1; 18 | } 19 | void elementWiseMultiply(int res[], int a[], int b[], int length){ 20 | int i = 0; 21 | while(i < length){ 22 | res[i] = a[i] * b[i]; 23 | i = i + 1; 24 | } 25 | } 26 | void printVector(int vec[], int length){ 27 | printf("[%d", vec[0]); 28 | int i = 1; 29 | while(i < length){ 30 | printf(", %d", vec[i]); 31 | i = i + 1; 32 | } 33 | printf("]\n"); 34 | } 35 | int main(){ 36 | printf("19373384\n"); 37 | int a[10] = {1, 3, 5, 7, 9, 11, 2, 9, 7, 8}; 38 | int b[10] = {2, 5, 4, 8, 9, 6, 3, 7, 1, 1}; 39 | int res1[10], res2[10]; 40 | int result; 41 | printVector(a, 10); 42 | printVector(b, 10); 43 | result = innerProduct(a, b, 10); 44 | int INNER_PRODUCT_ANSWER = 324; 45 | printf("Inner product: expect %d, output: %d\n", INNER_PRODUCT_ANSWER, result); 46 | if(INNER_PRODUCT_ANSWER != result) return 1; 47 | 48 | scaleBiasCombination(res1, a, 2, b, 3, 4, 10); 49 | int SBC1_RESULT[10] = {12, 25, 26, 42, 49, 44, 17, 43, 21, 23}; 50 | printf("SBC step 1: expect:"); 51 | printVector(SBC1_RESULT, 10); 52 | printf("output:"); 53 | printVector(res1, 10); 54 | int i = 0; 55 | while(i < 10){ 56 | if(res1[i] != SBC1_RESULT[i]) return 2; 57 | i = i + 1; 58 | } 59 | 60 | scaleBiasCombination(res2, res1, 2, b, 3, 4, 10); 61 | elementWiseMultiply(res1, res2, b, 10); 62 | int FINAL_RESULT[10] = {70, 350, 276, 904, 1170, 666, 144, 784, 50, 54}; 63 | printf("SBC step 2 and EWM: expect:"); 64 | printVector(FINAL_RESULT, 10); 65 | printf("output:"); 66 | printVector(res1, 10); 67 | i = 0; 68 | while(i < 10){ 69 | if(res1[i] != FINAL_RESULT[i]) return 3; 70 | i = i + 1; 71 | } 72 | 73 | printf("\n\n================================================================================\n PASSED \n================================================================================\n"); 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /testcases/B/testfile22.txt: -------------------------------------------------------------------------------- 1 | const int zhenghw = 100; 2 | const int ID = 19373339; 3 | const int abc123 = 1, abc124 = 2, abc125 = +3; 4 | int a; 5 | int b,c,d,f,g; 6 | int AA; 7 | int e = 66; 8 | const int a3[2][2] = {{1,2},{3,4}}; 9 | const int h3 = 6; 10 | int b3,c3,d3; 11 | int e3[4],f3[3],ii3[2][2] = {{9,8},{7,6}}; 12 | int g3[2] = {1,2}; 13 | int funcAA(int x[], int y[]) { 14 | int tempp; 15 | tempp = x[0] + y[0]; 16 | return tempp; 17 | } 18 | int func1 (int paramA) { 19 | int declInBlock; 20 | int temp = 2; 21 | declInBlock = abc123; 22 | declInBlock = +3; 23 | if (e) temp = 1; 24 | else temp = 2; 25 | if (e == 66) temp = 3; 26 | else temp = 4; 27 | if (e != abc123) temp = 5; 28 | else temp=6; 29 | if (e > 1) temp = 7; 30 | if (e + 4 < 80) temp = 8; 31 | if (e <= 90) temp = 9; 32 | if (e >= 100) temp = 10; 33 | if (e * 2 == 140) temp = 11; 34 | if (e / 2 == 33) temp = 12; 35 | if (e % abc124 == 1) temp = 13; 36 | if (!(0 + 1)) temp = 14; 37 | while (e - 1 >= 0) { 38 | int bbb = e - 1; 39 | e = bbb; 40 | break; 41 | } 42 | while (1 == 0) continue; 43 | return (-temp); 44 | } 45 | 46 | void func2 () { 47 | ; 48 | return; 49 | } 50 | 51 | int func3 (int xxx, int yyy) { 52 | { 53 | } 54 | return (4); 55 | } 56 | 57 | int func4 () { 58 | return 1; 59 | } 60 | 61 | int main() { 62 | a = +-zhenghw; 63 | b = abc123 + abc124 + abc124; 64 | c = abc123 + abc124*abc125; 65 | d = func3(abc123, 1); 66 | f = func1(abc124); 67 | g= func4(); 68 | b3 = a3[0][1]; 69 | c3 = a3[1][0]; 70 | d3 = a3[1][1]; 71 | int temp3,inn; 72 | int j3[2][3] = {{ii3[0][0],2,ii3[0][1]},{4,ii3[1][0],ii3[1][1]}}; 73 | temp3 = funcAA(ii3[0], j3[1]); 74 | func2(); 75 | inn = getint(); 76 | printf("19373339"); 77 | printf("\n"); 78 | printf("%d\n",b3); 79 | printf("%d\n",c3); 80 | printf("%d\n",d3); 81 | printf("%d\n",temp3); 82 | printf("%d\n",g3[3/3]); 83 | printf("123456\n"); 84 | printf("123456\n"); 85 | printf("123456\n"); 86 | return 0; 87 | } -------------------------------------------------------------------------------- /testcases/B/testfile23.txt: -------------------------------------------------------------------------------- 1 | void quickSort(int arr[], int left, int right) { 2 | if (left >= right) { 3 | return; 4 | } 5 | int i = left, j = right, base, temp; 6 | base = arr[left]; 7 | while (i < j) { 8 | while (arr[j] >= base && i < j) { 9 | j = j - 1; 10 | } 11 | while (arr[i] <= base && i < j) { 12 | i = i + 1; 13 | } 14 | if (i < j) { 15 | temp = arr[i]; 16 | arr[i] = arr[j]; 17 | arr[j] = temp; 18 | } 19 | } 20 | arr[left] = arr[i]; 21 | arr[i] = base; 22 | quickSort(arr, left, i - 1); 23 | quickSort(arr, i + 1, right); 24 | } 25 | 26 | int main() { 27 | printf("19373611\n"); 28 | printf("19373611\n"); 29 | printf("19373611\n"); 30 | const int length = 5; 31 | const int array_const[5] = {1, 2, 3, 4, 5}; 32 | int array[5]; 33 | printf("Please input base number a:\n"); 34 | int a, b; 35 | a = getint(); 36 | printf("Please input base number b:\n"); 37 | b = getint(); 38 | array[0] = a + b; 39 | array[1] = a - b; 40 | array[2] = a * b; 41 | if (!b) { 42 | array[3] = array_const[3]; 43 | array[4] = array_const[4]; 44 | printf("error.\n"); 45 | } else { 46 | array[3] = a / b; 47 | array[4] = a % b; 48 | } 49 | quickSort(array, 0, 4); 50 | int i = 0; 51 | while (i < 5) { 52 | printf("The No.%d number is %d.\n", i, array[i]); 53 | i = i + 1; 54 | } 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /testcases/B/testfile24.txt: -------------------------------------------------------------------------------- 1 | const int globalConst1 = 11, globalConst2 = 22; 2 | const int globalConstArray2[3][2] = {{6,7},{8,9},{10,11}}; 3 | const int globalConstArray1[3] = {10,20,30}; 4 | int globalVirable1 = 111, globalVirable2; 5 | void assignmentArray(int n,int array1[], int array2[][2]){ 6 | int i = 0; 7 | int j = i; 8 | int m = n - 1; 9 | while(i<3 && i<=m){ 10 | array1[i] = globalConstArray1[i] / 10 - 10; 11 | i = i + 1; 12 | } 13 | i = i - 1; 14 | while(i>=0){ 15 | array1[i] = globalConstArray1[i] / 10 - 10; 16 | while(1){ 17 | if(j < 2){ 18 | array2[i][j] = globalConstArray2[i][j] % 6 + 6; 19 | j = j + 1; 20 | continue; 21 | } 22 | else{ 23 | j = 0; 24 | printf("[%d][%d]:%d|%d , [%d]:%d|%d\n",i,j,array2[i][j],globalConstArray2[i][j],i,array1[i],globalConstArray1[i]); 25 | break; 26 | } 27 | } 28 | i = i - 1; 29 | } 30 | return; 31 | } 32 | int main(){ 33 | printf("19373063\n"); 34 | int localVirable1 = globalConst1; 35 | int localVirableArray1[3],localVirableArray2[3][2]; 36 | int localVirable2 = globalConstArray2[2][0]; 37 | int n = 3; 38 | printf("1.localVirable1 = %d,localVirable2 = %d \n2.\n",localVirable1, localVirable2); 39 | 40 | assignmentArray(n,localVirableArray1, localVirableArray2); 41 | printf("%d?\n",localVirableArray2[1][1]); 42 | printf("3.function of kinds of parameters testified\n"); 43 | ; 44 | if(1>0) 45 | { 46 | 47 | } 48 | printf("4.non exp testified\n"); 49 | return 0; 50 | } -------------------------------------------------------------------------------- /testcases/B/testfile3.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * this is test file 2 3 | */ 4 | 5 | const int constArray[5] = {1, 2, 3, 4 ,5}; 6 | const int a[2][2] = {{1, 0}, {0, 1}}, b[2][2] = {{0, 1}, {1, 0}}; 7 | 8 | void multi(int n1[][2], int n2[][2], int ans[][2]) { 9 | ans[0][0] = n1[0][0] * n2[0][0] + n1[0][1] * n2[1][0]; 10 | ans[0][1] = n1[0][0] * n2[0][1] + n1[0][1] * n2[1][1]; 11 | ans[1][0] = n1[1][0] * n2[0][0] + n1[1][1] * n2[1][0]; 12 | ans[1][1] = n1[1][0] * n2[0][1] + n1[1][1] * n2[1][1]; 13 | } 14 | 15 | void add(int n1[][2], int n2[][2], int ans[][2]) { 16 | ans[0][0] = n1[0][0] * n2[0][0]; 17 | ans[0][1] = n1[0][1] * n2[0][1]; 18 | ans[1][0] = n1[1][0] * n2[1][0]; 19 | ans[1][1] = n1[1][1] * n2[1][1]; 20 | } 21 | 22 | void copyConst(int dst[][2], int type) { 23 | if (type == 0) { 24 | dst[0][0] = a[0][0]; 25 | dst[0][1] = a[0][1]; 26 | dst[1][0] = a[1][0]; 27 | dst[1][1] = a[1][1]; 28 | } else { 29 | dst[0][0] = b[0][0]; 30 | dst[0][1] = b[0][1]; 31 | dst[1][0] = b[1][0]; 32 | dst[1][1] = b[1][1]; 33 | } 34 | } 35 | 36 | void copy(int dst[][2], int src[][2]) { 37 | dst[0][0] = src[0][0]; 38 | dst[0][1] = src[0][1]; 39 | dst[1][0] = src[1][0]; 40 | dst[1][1] = src[1][1]; 41 | } 42 | 43 | void getMat(int buffer[][2]) { 44 | buffer[0][0] = getint(); 45 | buffer[0][1] = getint(); 46 | buffer[1][0] = getint(); 47 | buffer[1][1] = getint(); 48 | } 49 | 50 | int main() { 51 | printf("19231111\n"); 52 | int c[2][2] = {{1, 2}, {3, 4}}, d[constArray[1]][a[0][0] + 1], ans[2][2]; 53 | copyConst(d, 1); 54 | add(c, d, ans); 55 | printf("%d %d %d %d\n", ans[0][0], ans[0][1], ans[1][0], ans[1][1]); 56 | copy(d, ans); 57 | printf("%d %d %d %d\n", d[0][0], d[0][1], d[1][0], d[1][1]); 58 | multi(c, d, ans); 59 | printf("%d %d %d %d\n", ans[0][0], ans[0][1], ans[1][0], ans[1][1]); 60 | getMat(d); 61 | multi(c, d, ans); 62 | printf("%d %d %d %d\n", ans[0][0], ans[0][1], ans[1][0], ans[1][1]); 63 | 64 | int arr1[1 + 5 * 0 - 9 / 9 + 56 / 8]; 65 | arr1[6] = 5; 66 | printf("%d\n", arr1[6]); 67 | int arr2[2222 / 1111] = {1, 2}; 68 | int i = 0; 69 | while (i < 2) { 70 | if (arr2[i] == constArray[i]) 71 | printf("true\n"); 72 | i = i + 1; 73 | } 74 | printf("%d\n", arr2[constArray[0]]); 75 | c[0][1] = 123; 76 | printf("%d\n", c[0][1]); 77 | c[0][0] = c[0][1]; 78 | printf("%d\n", c[0][0]); 79 | return 0; // test 80 | } 81 | -------------------------------------------------------------------------------- /testcases/B/testfile4.txt: -------------------------------------------------------------------------------- 1 | int count = 0; 2 | int climbStairs(int n){ 3 | if (n<0) return 0; 4 | if (n==0) return 1; 5 | if (n==1) return 1; 6 | return climbStairs(n-1) + climbStairs(n-2); 7 | } 8 | int sum(int a, int b) { 9 | return a + b; 10 | } 11 | int return1() { 12 | return sum(2,3) + sum(4,5); 13 | } 14 | void return2() { 15 | count = count + 3; 16 | return; 17 | } 18 | int SPAS(int n){ 19 | int product = 1; 20 | int sum = 0; 21 | int digit; 22 | while (n != 0) { 23 | digit = n % 10; 24 | n = n / 10; 25 | product = product * digit; 26 | sum = sum + digit; 27 | } 28 | return product - sum; 29 | } 30 | int NOS(int num){ 31 | int step = 0; 32 | while (num != 0) { 33 | step = step + 1; 34 | if (num % 2 == 1) { 35 | num = num - 1; 36 | continue; 37 | } 38 | if (num % 2 != 1) { 39 | num = num / 2; 40 | } 41 | } 42 | return step; 43 | } 44 | int main() { 45 | printf("19231047\n"); 46 | printf("climb 0 : %d\n", climbStairs(count)); 47 | return2(); 48 | printf("climb %d : %d\n", count, climbStairs(count)); 49 | return2(); 50 | printf("climb %d : %d\n", count, climbStairs(count)); 51 | int a = return1(); 52 | printf("test return1 : %d\n", a); 53 | printf("test climb sum %d : %d\n", sum(3,4), climbStairs(sum(3,4))); 54 | printf("test product - sum : %d\n", SPAS(1345121324)); 55 | printf("test nest 1 : %d\n", climbStairs(sum(SPAS(34), SPAS(32)))); 56 | printf("test nest 2 : %d\n", climbStairs(sum(NOS(14), NOS(6)))); 57 | printf("test file"); 58 | return 0; 59 | } -------------------------------------------------------------------------------- /testcases/B/testfile6.txt: -------------------------------------------------------------------------------- 1 | //#include 2 | const int _a = 3+2+-+2%2/1,_12 = 85; 3 | const int a=3+(1*2)/2*_a; 4 | const int arrayA[2] = {1,2}; 5 | const int array_b[2][1] = {{1},{arrayA[0]}}; 6 | int array_c[2] = {1,2}; 7 | int array_d[2][1] = {{1},{2}}; 8 | int b=12,c_1; 9 | int d = _a*_a+_a; 10 | int func1(int c){ 11 | return 1; 12 | } 13 | void func2(){ 14 | return; 15 | } 16 | void _func1 (){ 17 | const int _a = 10,_12 = 12; 18 | int array_d[2][1] = {{1},{array_c[1]}}; 19 | int a=3+(1*20)/2*_a; 20 | int b=121,c_1; 21 | int d = _a*_a+_a+arrayA[0]; 22 | printf("_a=%d\n",_a); 23 | printf("_a=%d\n",a); 24 | if(a==0) 25 | a = a+-+1; 26 | else 27 | //scanf("%d",&c_1); 28 | //c_1 = getint(); 29 | //scanf("%d",&c_1); 30 | a = 1; 31 | while(a<10 && a>0 ){ 32 | a=a+1; 33 | if(a==5 || a==6 && a!=5*1%5 && a<10 && a>5 && a>=5 && a<=6 &&!(1-1)&&a )break; 34 | else; 35 | a=a+1; 36 | } 37 | while(a<10){ 38 | a=a+1; 39 | if(a==5) continue; 40 | } 41 | _a+1; 42 | b=_a%2; 43 | return; 44 | } 45 | int main(){ 46 | int x; 47 | printf("19231150\n"); 48 | //scanf("%d",&x); 49 | x=getint(); 50 | printf("what you enter in is:%d\n",x); 51 | printf("_a=%d\n",_a); 52 | printf("array_c[0] is:%d\n",array_c[0]); 53 | printf("array_d[0][0] is:%d\n",array_d[0][0]); 54 | printf("array_d[1][0] is:%d\n",array_d[1][0]); 55 | _func1(); 56 | int i=2; 57 | int ext; 58 | while(i1){} 64 | if (1<1 == 1<=1) {} 65 | if (1<=1 != 1>= 1) {} 66 | if (!1) {} 67 | if (1 && 1) {}; 68 | if (1 ||1 ) {}; 69 | 70 | while (0) break ; 71 | while (0) continue; 72 | 73 | 74 | 75 | var01 = getint(); 76 | var1DArr01[0] = 0; 77 | var2DArr01[0][0] = 0; 78 | 79 | printf("1"); 80 | printf("%d", var01); 81 | 82 | printf("1"); 83 | printf("1"); 84 | printf("1"); 85 | printf("1"); 86 | printf("1"); 87 | printf("1"); 88 | printf("1"); 89 | 90 | 0; 91 | return 0; 92 | 93 | } 94 | -------------------------------------------------------------------------------- /testcases/B/testfile8.txt: -------------------------------------------------------------------------------- 1 | const int a = 1; 2 | const int b = 2 * 6 + 1, _a_b[2%2+1] = {5}, _a_3_b[2/2+1][2*1-1] = {{0},{3452%2+4*3}}; 3 | int c, d[2%2+1], _a_4_b[2/2+1][2*1-1] = {{0},{3452%2+4*3}}, z; 4 | int _d_e = 1; 5 | int glo_1, glo_2, glo_3, glo_4, glo_5, glo_6, glo_7, glo_8, glo_9; 6 | 7 | int test_1(int var_1, int var_2[], int var_3[][1]){ 8 | c = var_1 + var_2[0] + var_3[0][0] + 3452340 + 0; 9 | return c; 10 | } 11 | 12 | int test_2(int var_6){ 13 | z = var_6; 14 | return (z + 6%4/2) * 2; 15 | } 16 | 17 | void test_3() { 18 | } 19 | 20 | void test_4() { 21 | return; 22 | } 23 | 24 | int test_5() { 25 | return 2; 26 | } 27 | 28 | int main() { 29 | const int f = 1; 30 | const int g = 2 * 6 + 1, _a_b_[2%2+1] = {a}, _a_3_b_d[2/2+1][2*1-1] = {{0},{3452%2+4*3}}; 31 | int c, d[2%2+1], _a_4_b_d[2/2+1][2*1-1] = {{0},{3452%2+4*3}}; 32 | int _d_e_g = (_a_3_b_d[0][0] + _a_4_b_d[0][0]) * b + 1; 33 | d[0] = 1; 34 | _a_4_b_d[0][0] = 1; 35 | c = _d_e_g + _a_4_b_d[0][0]; 36 | c = +-+d[0]; 37 | 5 * 5 + 1; 38 | glo_1 = getint(); 39 | glo_2 = getint(); 40 | glo_3 = getint(); 41 | glo_4 = getint(); 42 | glo_5 = getint(); 43 | glo_6 = getint(); 44 | glo_7 = getint(); 45 | glo_8 = getint(); 46 | glo_9 = getint(); 47 | c = -+-test_5() + test_1(c, d, _a_4_b_d) + test_1(_a_4_b_d[0][0], _a_4_b_d[0], _a_4_b_d) - test_1(_a_4_b_d[0][0], _a_4_b_d[0], _a_4_b_d); 48 | z = test_2(c); 49 | while(glo_9 >= 0 || 0 && 1 || !0 && glo_1 < 0 && 0 <= glo_8 && glo_7 > 0 && glo_6 != glo_5 && (glo_4 % 2 / 2 + test_1(c, d, _a_4_b_d) + test_1(_a_4_b_d[0][0], _a_4_b_d[0], _a_4_b_d) - test_1(_a_4_b_d[0][0], _a_4_b_d[0], _a_4_b_d) * 20) && glo_6 == glo_6 ) { 50 | if(glo_2>1) { 51 | glo_2 = glo_2 - 1; 52 | glo_9 = glo_9 - 1; 53 | continue; 54 | } else { 55 | glo_2 = glo_2 - 1; 56 | glo_1 = glo_1 - 1; 57 | if (glo_1 < 0) { 58 | glo_8 = glo_8 - 1; 59 | break; 60 | } 61 | else { 62 | ; 63 | } 64 | } 65 | } 66 | printf("19231076\n"); 67 | printf(">/!~varg1 is:%d;~\n", glo_1); 68 | printf(">/!~varg2 is:%d;~\n", glo_2); 69 | printf(">/!~varg3 is:%d;~\n", glo_3); 70 | printf(">/!~varg4 is:%d;~\n", glo_4); 71 | printf(">/!~varg5 is:%d;~\n", glo_5); 72 | printf(">/!~varg6 is:%d;~\n", glo_6); 73 | printf(">/!~varg7 is:%d;~\n", glo_7); 74 | printf(">/!~varg8 is:%d;~\n", glo_8); 75 | printf(">/!~varg9 is:%d;~\n", glo_9); 76 | return 0; 77 | } -------------------------------------------------------------------------------- /testcases/B/testfile9.txt: -------------------------------------------------------------------------------- 1 | void fun_1(){ 2 | return; 3 | } 4 | 5 | void fun_2(int a){ 6 | return; 7 | } 8 | 9 | void fun_3(int a, int b){ 10 | fun_2(a); 11 | } 12 | 13 | void fun_4(int a, int b, int c){ 14 | if(a <= b || a < b || a > b || a >= b){ 15 | if(b <= c && b == a && a != c){ 16 | 17 | } 18 | } 19 | 20 | } 21 | 22 | void fun_5(int a[], int b[][2]){ 23 | int t1 = 2, t2 = 1, t3; 24 | fun_4(t1, t2, t3 - t2); 25 | if(t1 + t2 == 0){ 26 | fun_4(t1, t2, t3); 27 | }else if(t2 + t2 != 0){ 28 | fun_4(t2, t1, t3); 29 | if(t3 == 1){ 30 | t3 = 0; 31 | } 32 | }else{ 33 | return; 34 | } 35 | } 36 | 37 | 38 | void fun_6(){ 39 | int var_1; 40 | var_1 = 1 + 1; 41 | var_1 = 1 + 1 * 3; 42 | var_1 = 3 * (var_1 / (-2) + 1 % (23 * +2)); 43 | int a[2][2] = {{1,2}, {1,2}}; 44 | // func_5(a[1], a); 45 | var_1 = var_1 + var_1 / var_1; 46 | { 47 | int var_1; 48 | int var_2[23]; 49 | 50 | var_1 = 0; 51 | var_1 = 3 % 5; 52 | var_1 = var_1 * 5; 53 | } 54 | return; 55 | } 56 | 57 | void fun_7(int a[]){ 58 | 59 | } 60 | 61 | int funInt(int a, int b[][2]){ 62 | int var_1[2][2], var_2[1]; 63 | var_1[1][1] = 2; 64 | var_2[0] = 3; 65 | int c = 0, d = 0; 66 | int i = 0; 67 | if(c == 0){ 68 | c = 1; 69 | } 70 | while(i < a){ 71 | if(i == c + d){ 72 | break; 73 | } else { 74 | continue; 75 | } 76 | i = i + 1; 77 | } 78 | 79 | while(i < !a || i >= 0){ 80 | if(i != 0){ 81 | i = i - 2; 82 | } 83 | i = i - 1; 84 | } 85 | return 1; 86 | } 87 | 88 | // MainFuncDef 89 | int main(){ 90 | int n; 91 | ; 92 | n = getint(); 93 | fun_6(); 94 | int a[2][2]; 95 | int b[2]; 96 | fun_7(a[1]); 97 | fun_7(b); 98 | printf("19373385"); 99 | printf("2"); 100 | printf("3"); 101 | printf("4"); 102 | printf("5"); 103 | printf("6"); 104 | printf("7"); 105 | printf("8"); 106 | printf("9"); 107 | printf("%d", n); 108 | return 0; 109 | } -------------------------------------------------------------------------------- /testcases/C/input1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coekjan/MIPSysY-Compiler/772e50d5f4ac1114c8a9f880264a659d99575cb2/testcases/C/input1.txt -------------------------------------------------------------------------------- /testcases/C/input10.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coekjan/MIPSysY-Compiler/772e50d5f4ac1114c8a9f880264a659d99575cb2/testcases/C/input10.txt -------------------------------------------------------------------------------- /testcases/C/input11.txt: -------------------------------------------------------------------------------- 1 | 5 -------------------------------------------------------------------------------- /testcases/C/input12.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coekjan/MIPSysY-Compiler/772e50d5f4ac1114c8a9f880264a659d99575cb2/testcases/C/input12.txt -------------------------------------------------------------------------------- /testcases/C/input13.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | -------------------------------------------------------------------------------- /testcases/C/input14.txt: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /testcases/C/input15.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 4 4 | 5 -------------------------------------------------------------------------------- /testcases/C/input16.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 15 3 | 6 4 | 6 -------------------------------------------------------------------------------- /testcases/C/input17.txt: -------------------------------------------------------------------------------- 1 | 12345 2 | -------------------------------------------------------------------------------- /testcases/C/input18.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 0 4 | -1 5 | 1 6 | 2 7 | 2 8 | -1 9 | 2 10 | 2 11 | -------------------------------------------------------------------------------- /testcases/C/input19.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coekjan/MIPSysY-Compiler/772e50d5f4ac1114c8a9f880264a659d99575cb2/testcases/C/input19.txt -------------------------------------------------------------------------------- /testcases/C/input2.txt: -------------------------------------------------------------------------------- 1 | 54633487 2 | 632917 3 | 30 -------------------------------------------------------------------------------- /testcases/C/input20.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /testcases/C/input21.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 2 4 | 3 5 | 3 6 | 4 7 | 2 8 | 4 9 | 0 10 | 1 11 | 1 12 | 0 13 | 123456789 14 | 987654321 15 | -1 -------------------------------------------------------------------------------- /testcases/C/input22.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /testcases/C/input23.txt: -------------------------------------------------------------------------------- 1 | 0 -------------------------------------------------------------------------------- /testcases/C/input24.txt: -------------------------------------------------------------------------------- 1 | 19260817 2 | 114514 3 | 1919810 4 | 4 5 | 16 6 | 13 -------------------------------------------------------------------------------- /testcases/C/input25.txt: -------------------------------------------------------------------------------- 1 | 11 2 | 13 3 | 12341 4 | -------------------------------------------------------------------------------- /testcases/C/input26.txt: -------------------------------------------------------------------------------- 1 | 33 -------------------------------------------------------------------------------- /testcases/C/input27.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | -------------------------------------------------------------------------------- /testcases/C/input28.txt: -------------------------------------------------------------------------------- 1 | 6 -------------------------------------------------------------------------------- /testcases/C/input29.txt: -------------------------------------------------------------------------------- 1 | 233 2 | 1 3 | 42 4 | -15 5 | 0 6 | -------------------------------------------------------------------------------- /testcases/C/input3.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 23 3 | 3 4 | 4 5 | 52 6 | 6 7 | 7 8 | 8 9 | 99 10 | -------------------------------------------------------------------------------- /testcases/C/input4.txt: -------------------------------------------------------------------------------- 1 | 56 -------------------------------------------------------------------------------- /testcases/C/input5.txt: -------------------------------------------------------------------------------- 1 | -4 2 | 0 3 | 1 4 | 2 5 | 3 6 | 4 7 | 5 8 | 6 9 | 7 10 | 8 11 | -------------------------------------------------------------------------------- /testcases/C/input6.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coekjan/MIPSysY-Compiler/772e50d5f4ac1114c8a9f880264a659d99575cb2/testcases/C/input6.txt -------------------------------------------------------------------------------- /testcases/C/input7.txt: -------------------------------------------------------------------------------- 1 | 123 -------------------------------------------------------------------------------- /testcases/C/input8.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coekjan/MIPSysY-Compiler/772e50d5f4ac1114c8a9f880264a659d99575cb2/testcases/C/input8.txt -------------------------------------------------------------------------------- /testcases/C/input9.txt: -------------------------------------------------------------------------------- 1 | 9 2 | 8 3 | 7 4 | 6 5 | 5 6 | 4 7 | 3 8 | 2 9 | 1 10 | -------------------------------------------------------------------------------- /testcases/C/output1.txt: -------------------------------------------------------------------------------- 1 | 19231204 2 | + is error! 3 | + is error! 4 | + is error! 5 | + is error! 6 | Break is error! 7 | a1+b1 is 3 8 | a2+b2 is -2 9 | -------------------------------------------------------------------------------- /testcases/C/output10.txt: -------------------------------------------------------------------------------- 1 | 19373025 2 | 1 3 | funi 4 | try 5 | try 6 | try 7 | try 8 | try 9 | try 10 | try -------------------------------------------------------------------------------- /testcases/C/output11.txt: -------------------------------------------------------------------------------- 1 | 19182650 2 | this is d 3 | 4 4 | 5 5 | 4 6 | 5 7 | 2 -------------------------------------------------------------------------------- /testcases/C/output12.txt: -------------------------------------------------------------------------------- 1 | 19182623 2 | -------------------------------------------------------------------------------- /testcases/C/output13.txt: -------------------------------------------------------------------------------- 1 | 10, 30972, -5 -------------------------------------------------------------------------------- /testcases/C/output14.txt: -------------------------------------------------------------------------------- 1 | 19373372 2 | fact[10] = 3628800 3 | fact[1] = 1 4 | fact[2] = 2 5 | fact[3] = 6 6 | fact[4] = 24 7 | fact[5] = 120 8 | fact[6] = 720 9 | fact[7] = 5040 10 | fact[8] = 40320 11 | -------------------------------------------------------------------------------- /testcases/C/output15.txt: -------------------------------------------------------------------------------- 1 | 19373479 2 | print int : 0 3 | print int : 2 4 | print int : 2 5 | print int : 0 6 | print int : 41 7 | print int : 61 8 | print int : 4884 9 | print int : -45015 -------------------------------------------------------------------------------- /testcases/C/output16.txt: -------------------------------------------------------------------------------- 1 | 19373373 2 | j : 4, k : 10, l : 4 3 | a! = 720, num = 5 4 | 6 5 | scanf a, b to get gcd and lcm 6 | gcd is 5 7 | lcm is 30 8 | -6 9 | scanf a to get Fibonacci 10 | fib is 8 -------------------------------------------------------------------------------- /testcases/C/output17.txt: -------------------------------------------------------------------------------- 1 | 19373682 2 | hello? 12345 12345 12345 3 | func1 done! 4 | func2 done! 5 | func3 input = 0 6 | func3 done! 7 | 204 204 100 100 20400 100 0 100 100 8 | func4 done! 9 | -------------------------------------------------------------------------------- /testcases/C/output18.txt: -------------------------------------------------------------------------------- 1 | 19373719 2 | 0 -2 3 | 0 2 4 | 4 5 | 0 6 | -------------------------------------------------------------------------------- /testcases/C/output19.txt: -------------------------------------------------------------------------------- 1 | 19373135 2 | l_const_0, should be 0: 0 3 | l_const_1, should be 1: 1 4 | l_const_3, should be 2: 2 5 | l_const_5[2], l_const_6[0][1], should be 3, 1: 3, 1 6 | l_var_0, should be 0: 0 7 | l_var_1, should be 2: 2 8 | l_var_3, should be 4: 4 9 | l_var_5, should be 5: 5 10 | l_var_6[2], l_var_7[0][1], should be 3, 1: 3, 1 -------------------------------------------------------------------------------- /testcases/C/output2.txt: -------------------------------------------------------------------------------- 1 | 18375200 2 | -163900461 3 | -628 4 | -925500 5 | ppgod7mi 6 | 4396yoga7 7 | 2333 8 | 9 | 10 | 11 | 632917 is not a prime, with factor 41. 12 | The 30th Fibonacci num is 832040. -------------------------------------------------------------------------------- /testcases/C/output20.txt: -------------------------------------------------------------------------------- 1 | 19373061 2 | 0 3 | 1 4 | 0 5 | 0 6 | 1 7 | 0 8 | 1 9 | 0 10 | t:1 -------------------------------------------------------------------------------- /testcases/C/output21.txt: -------------------------------------------------------------------------------- 1 | gcd is 1 2 | gcd is 1 3 | gcd is 1 4 | gcd is 2 5 | invaild input! 6 | invaild input! 7 | gcd is 9 8 | -------------------------------------------------------------------------------- /testcases/C/output22.txt: -------------------------------------------------------------------------------- 1 | 19373034 2 | 1 3 | 1 4 | 0 5 | 1 6 | 0 7 | 10 8 | 8 9 | 9 10 | 10 -------------------------------------------------------------------------------- /testcases/C/output23.txt: -------------------------------------------------------------------------------- 1 | 19373044 2 | s+1=2 3 | m=0 4 | m=1 5 | m=0 6 | m=0 7 | m=1 8 | m=2 9 | m=3 10 | before break -------------------------------------------------------------------------------- /testcases/C/output24.txt: -------------------------------------------------------------------------------- 1 | 19373022 2 | b:-19260604 3 | Bool1 is false! 4 | 1919820 5 | 1932053504 6 | -------------------------------------------------------------------------------- /testcases/C/output25.txt: -------------------------------------------------------------------------------- 1 | 19373341 2 | the num is 851 3 | the num is 11 4 | the num is 13 5 | the num is 12341 6 | 11 is odd! 7 | 13 is odd! 8 | max of 11 and 13 is 13 9 | min of 11 and 13 is 11 10 | No, 12341 is not a prime! It has a factor 7 11 | -------------------------------------------------------------------------------- /testcases/C/output26.txt: -------------------------------------------------------------------------------- 1 | 19373276 2 | !()*+,-./0123456789:;<>=?@[]^_`~{}| 3 | qwertyuiopasd 4 | fghjklzxcvbnmQWERTYUIOPASD 5 | FGHJKLZXCVBNM0 6 | 72 23 7 | addSum: 105, 45 8 | -2169 9 | 1008-6 10 | end -------------------------------------------------------------------------------- /testcases/C/output27.txt: -------------------------------------------------------------------------------- 1 | 19373315 2 | this is a yu ju ky 3 | unbelievable! 4 | var_a from getint() is 1 5 | getint is 1 6 | tmp 7 | tmp 8 | tmp 9 | tmp 10 | tmp 11 | -------------------------------------------------------------------------------- /testcases/C/output28.txt: -------------------------------------------------------------------------------- 1 | 19373332 2 | Stmt-3(Block): c = 2, d = 46 3 | Stmt-3(Block): e = 4, f = 829 4 | Stmt-4(if) check finish! 5 | Stmt-5,6 check finish! 6 | Stmt-7 check finish! 7 | Stmt-8 check finish! 8 | 9 | FormatChar. 10 | 13 -------------------------------------------------------------------------------- /testcases/C/output29.txt: -------------------------------------------------------------------------------- 1 | 19373348 2 | Got a number: 233! 3 | 247 4 | Got a number: 1! 5 | -3 6 | Got a number: 42! 7 | 738 8 | Got a number: -15! 9 | 1711 10 | Got a number: 0! 11 | 3667 12 | -------------------------------------------------------------------------------- /testcases/C/output3.txt: -------------------------------------------------------------------------------- 1 | 19231177 2 | 1 3 | 23 4 | 3 5 | 4 6 | 52 7 | 6 8 | 7 9 | 8 10 | 99 11 | 10 12 | appear 13 | 20 14 | not 15 | 30 16 | not 17 | 40 18 | not 19 | 50 20 | not 21 | 60 22 | not 23 | 99 24 | not 25 | 99 26 | not 27 | 99 28 | not 29 | print123 30 | 123 31 | /****/123 32 | /**/123 33 | print return value : 34 | in : 5 ,out = 50 35 | in : 5 ,out = 50 -------------------------------------------------------------------------------- /testcases/C/output4.txt: -------------------------------------------------------------------------------- 1 | 19231204 2 | The score is 56. 3 | Yes! 4 | Yes! 5 | Yes! 6 | No! -------------------------------------------------------------------------------- /testcases/C/output5.txt: -------------------------------------------------------------------------------- 1 | 16061069 2 | input an integer,judge if it is prime number,10 groups in total 3 | input > 0 is needed 4 | input > 0 is needed 5 | 1 is not concerned 6 | 2 is a prime number 7 | 3 is a prime number 8 | 4 is not a prime number 9 | 5 is a prime number 10 | 6 is not a prime number 11 | 7 is a prime number 12 | 8 is not a prime number 13 | while times is 22 in total 14 | -------------------------------------------------------------------------------- /testcases/C/output6.txt: -------------------------------------------------------------------------------- 1 | 19231177 2 | _ = 1; a = 20; b = 30; c = 460; 3 | 20+30=50; 460-1=459; 50*459=22950; 459/50=9; 22950mod30=0 4 | 50+459+22950=23459; 459-22950-9=-22500; 22950*9*0=0; 0/50/459=0; 9mod0mod50=9 5 | 10+17-23*37/43mod71-17*23+43=-340=-340 6 | 10+(17-23)*37/43mod(71-37)*-340=1710 7 | all chars : !()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~ 8 | 5!+7+3=130 9 | max: 2147483647 ; min : -2147483647 ; sum : 0 10 | 19231177 -------------------------------------------------------------------------------- /testcases/C/output7.txt: -------------------------------------------------------------------------------- 1 | 19373755 2 | n = -864 3 | n = -7938 4 | n = 10 5 | n = -15 6 | n = 861 7 | n = 0 8 | test_if done! 9 | test_while done! 10 | test_break_continue done! -------------------------------------------------------------------------------- /testcases/C/output8.txt: -------------------------------------------------------------------------------- 1 | 19182650 2 | 1 3 | 2 4 | 3 5 | 4 6 | 5 7 | 6 8 | 21 9 | 1 10 | 6 -------------------------------------------------------------------------------- /testcases/C/output9.txt: -------------------------------------------------------------------------------- 1 | 19231076 2 | >/!~varg1 is:-1;~ 3 | >/!~varg2 is:-8;~ 4 | >/!~varg3 is:7;~ 5 | >/!~varg4 is:6;~ 6 | >/!~varg5 is:5;~ 7 | >/!~varg6 is:4;~ 8 | >/!~varg7 is:3;~ 9 | >/!~varg8 is:2;~ 10 | >/!~varg9 is:1;~ 11 | -------------------------------------------------------------------------------- /testcases/C/testfile1.txt: -------------------------------------------------------------------------------- 1 | const int a1 = 1, a2 = +3, a3 = 8; 2 | int b1 = 0 + 2, b2 = -5, b3 = +6; 3 | 4 | int main() { 5 | printf("19231204"); 6 | printf("\n"); 7 | int n = 10; 8 | while (n) { 9 | n = n - 1; 10 | if (n < b3) { 11 | continue; 12 | printf("Continue is error!\n"); 13 | } 14 | if (n < a1) { 15 | break; 16 | printf("Break is error!And < is error!\n"); 17 | } 18 | if (n == a2) { 19 | printf("+ is correct!\n"); 20 | } else { 21 | printf("+ is error!\n"); 22 | } 23 | if (n == b1) { 24 | break; 25 | } 26 | } 27 | if (n != b1) { 28 | if (n == 0) { 29 | printf("Break is error!\n"); 30 | } else { 31 | printf("Continue is error!\n"); 32 | } 33 | } 34 | printf("a1+b1 is %d\n", a1 + b1); 35 | printf("a2+b2 is %d\n", a2 + b2); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /testcases/C/testfile10.txt: -------------------------------------------------------------------------------- 1 | const int ci=1; 2 | const int ciexp=1+1*1/1%1-1; 3 | const int ca=1,cb=2; 4 | int i=-+1; 5 | int iexp=1+1*1/1%1-1; 6 | int a=1,b=2; 7 | void funv(int a,int b) {{ 8 | printf("funv\n"); 9 | }} 10 | int funi(int a){ 11 | printf("funi\n"); 12 | return 0; 13 | } 14 | int funvnop(){ 15 | return 0; 16 | } 17 | int main() { 18 | int ma1,ma2,ma3,ma4; 19 | printf("19373025\n"); 20 | ma1=1; 21 | ma2=1+1; 22 | ma3=1; 23 | ma4=1; 24 | if(ma1!=ma2) { 25 | int mif1=1; 26 | printf("%d\n",mif1); 27 | } else { 28 | return 0; 29 | } 30 | if(ma1==ma3){ 31 | funi(ma1); 32 | } 33 | if(ma1!=ma3){ 34 | funvnop(); 35 | } 36 | if(ma1>=ma3){ 37 | 38 | } 39 | if(ma2<=ma3){ 40 | funvnop(); 41 | } 42 | if(ma1>ma3){ 43 | funvnop(); 44 | } 45 | if(ma2 2 | int getint(){ 3 | int n; 4 | scanf("%d",&n); 5 | return n; 6 | } 7 | */ 8 | const int singleConstDecl = 23; 9 | //const int singleConstDecl_0 = singleConstDecl + 123 ,singleConstDecl_1 = singleConstDecl + 3 ; 10 | const int singleConstDecl_0 = 13 ,singleConstDecl_1 = 3 ; 11 | 12 | int singleVarDecl = 3 - 13; 13 | int singleVarDecl_0 = 23 ,singleVarDecl_1 = +-+(3-13),singleVarDecl_2; 14 | 15 | void funcDef_void(){ 16 | 17 | } 18 | 19 | int funcDef_0(int var){ 20 | int ans = var * 10; 21 | return ans; 22 | } 23 | 24 | int funcDef_1(int var1, int var2){ 25 | int a = var1 * var2; 26 | int b; 27 | int c; 28 | if (var2 != 0){ 29 | b = a + var1%var2; 30 | c = var1/var2; 31 | } 32 | else { 33 | b = a+var1; 34 | c = var1/2; 35 | } 36 | 37 | b = b - a; 38 | { 39 | ; 40 | a+b; 41 | } 42 | if (a < 0) a = -a; 43 | return (1+a)*(b+c); 44 | } 45 | void printInt(int var){ 46 | printf("print int : %d\n",var); 47 | return ; 48 | } 49 | int main(){ 50 | printf("19373479\n"); 51 | int a = 10,b,c,d,e; 52 | b = getint(); 53 | c = getint(); 54 | d = getint(); 55 | e = getint(); 56 | if(b>5){ 57 | b = 5; 58 | 59 | } 60 | while (a) { 61 | a = a - 1; 62 | if (c>=a){ 63 | c = c / (a+1) + a; 64 | } 65 | if (d <= a){ 66 | d = d*a; 67 | } 68 | else{ 69 | d = d % (a+3); 70 | } 71 | while(e < d){ 72 | e = e + a; 73 | if (e == b) break; 74 | if (e != c) { 75 | e = c + e; 76 | continue; 77 | } 78 | } 79 | } 80 | 81 | if(!a){ 82 | printInt(a); 83 | } 84 | printInt(b); 85 | printInt(c); 86 | printInt(d); 87 | printInt(e); 88 | int f = funcDef_1(e,d); 89 | int g = funcDef_1(f, funcDef_0(c)); 90 | funcDef_void(); 91 | printInt(f); 92 | printInt(g); 93 | singleVarDecl_2 = funcDef_1(funcDef_1(singleVarDecl,singleVarDecl_2), funcDef_1(singleConstDecl_0,singleConstDecl_1)); 94 | printInt(singleVarDecl_2); 95 | 96 | return 0; 97 | } -------------------------------------------------------------------------------- /testcases/C/testfile16.txt: -------------------------------------------------------------------------------- 1 | void fun1() 2 | { 3 | int j; 4 | int k = 4, l = 6; 5 | l = k; 6 | j = 3; 7 | j = (j % 20) - 1 + 9; 8 | int i=0; 9 | while (i <= 7) 10 | { 11 | i = i + 1; 12 | if (j == i) 13 | { 14 | k = k + j; 15 | continue; 16 | } 17 | j = j - 1; 18 | } 19 | printf("j : %d, k : %d, l : %d\n", j, k, l); 20 | } 21 | 22 | int fun2(int a) 23 | { 24 | int b = 1; 25 | int num = 1; 26 | while (a >= 1) 27 | { 28 | b = b * a; 29 | a = a - 1; 30 | if (a == 1) 31 | { 32 | break; 33 | } 34 | else if (a != 1) 35 | { 36 | num = num + 1; 37 | } 38 | } 39 | printf("a! = %d, num = %d\n", b, num); 40 | return 1; 41 | } 42 | 43 | int fun3(int a, int b) 44 | { 45 | if (a > b) 46 | { 47 | return a; 48 | } 49 | else if (a < b) 50 | { 51 | return b; 52 | } 53 | return a; 54 | } 55 | 56 | int gcd(int a, int b) 57 | { 58 | if (a % b == 0) 59 | { 60 | return b; 61 | } 62 | return gcd(b, a % b); 63 | } 64 | 65 | int lcm(int a, int b) 66 | { 67 | int gcds = gcd(a, b); 68 | return a * b / gcds; 69 | } 70 | 71 | void fun4(int a, int b, int c) 72 | { 73 | int d = (a + b - c) * a; 74 | printf("%d\n", d); 75 | } 76 | 77 | int fun5(int a) 78 | { 79 | if (a == 1) 80 | { 81 | return 1; 82 | } 83 | else if (a == 2) 84 | { 85 | return 1; 86 | } 87 | return fun5(a - 1) + fun5(a - 2); 88 | } 89 | 90 | int main() 91 | { 92 | printf("19373373\n"); 93 | fun1(); 94 | fun2(6); 95 | printf("%d\n", fun3(2, fun3(3, 6))); 96 | int a, b; 97 | printf("scanf a, b to get gcd and lcm\n"); 98 | a = getint(); 99 | b = getint(); 100 | printf("gcd is %d\n", gcd(a, b)); 101 | printf("lcm is %d\n", lcm(a, b)); 102 | int temp; 103 | temp = getint(); 104 | fun4(temp, 3, 10); 105 | printf("scanf a to get Fibonacci\n"); 106 | int fib; 107 | fib = getint(); 108 | printf("fib is %d\n", fun5(fib)); 109 | return 0; 110 | } -------------------------------------------------------------------------------- /testcases/C/testfile17.txt: -------------------------------------------------------------------------------- 1 | // All Decl's forms exist in global variable decl 2 | const int AZ = 100; 3 | const int AZA1 = 200, AZA2 = 300; 4 | 5 | int az; 6 | int aza = 100; 7 | int azaz1, azaz2 = 200; 8 | 9 | // All Block's forms exist in while() in func1, except for (return exp) 10 | void func1() { 11 | while (1) { 12 | int i = 0; 13 | i = 0; 14 | i * 8; 15 | { ; } 16 | if (i != 0) continue; 17 | if (i != 0); else; 18 | i = getint(); 19 | printf("hello? "); 20 | printf("%d ", i); 21 | printf("%d %d\n", i, i); 22 | break; 23 | } 24 | if (1) { 25 | } 26 | return; 27 | } 28 | 29 | // All Ident's form and Other forms exist in func2 30 | int func2() { 31 | int abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 = 43; 32 | int temp; 33 | temp = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890; 34 | int a; 35 | int a1b3; 36 | /* 37 | This is annotation1 38 | */ 39 | // This is annotation2 40 | int d = 0; 41 | 0; 42 | 1234567890; 43 | return 100; 44 | } 45 | 46 | // All Cond's forms exist in func3 47 | void func3(int in) { 48 | printf("func3 input = %d\n", in); 49 | int a = 7; 50 | int b = 8; 51 | if (!(a + b)); 52 | if ((a + b) < (a + b)); 53 | if ((a + b) > (a + b)); 54 | if ((a + b) <= (a + b)); 55 | if ((a + b) >= (a + b)); 56 | if ((a + b) == (a + b)); 57 | if ((a + b) != (a + b)); 58 | return; 59 | } 60 | 61 | // All Exp's forms exist in func4 62 | int func4(int param1, int param2, int param3) { 63 | int temp1 = (param1 * param2) / (param2) % (param1) + param3 - param3 * (param1 / param3 / param3); 64 | const int temp2 = (AZ + AZA1 - AZA2) * AZ * (18 / 6) - 16 * (0); 65 | int temp3; 66 | temp3 = AZ * AZA1 % AZA2; 67 | int a = temp3 + 4; 68 | int b = (a); 69 | int c = func2(); 70 | int d = - + - +func2(); 71 | int e = c * b; 72 | int f = e / b; 73 | int g = f % c; 74 | int h = f + g; 75 | int i = f - g; 76 | printf("%d %d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h, i); 77 | return 1; 78 | } 79 | 80 | int main() { 81 | printf("19373682\n"); 82 | func1(); 83 | printf("func1 done!\n"); 84 | func2(); 85 | printf("func2 done!\n"); 86 | func3(az); 87 | printf("func3 done!\n"); 88 | func4(1, 2, 3); 89 | printf("func4 done!\n"); 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /testcases/C/testfile18.txt: -------------------------------------------------------------------------------- 1 | const int a = 1, b = 2; 2 | const int c = 3; 3 | int d, e = 1 + 2; 4 | int f; 5 | 6 | 7 | int double2(int x1) { 8 | if (!x1) { 9 | return 2*x1; 10 | } 11 | else { 12 | return (2*-x1); 13 | } 14 | return 0; 15 | } 16 | 17 | int add(int x1, int x2) { 18 | int sum = 0; 19 | sum = x1 + x2; 20 | return sum; 21 | } 22 | 23 | int sub(int x1, int x2) { 24 | int sum = 0; 25 | sum = x1 - x2; 26 | if (sum >= 0) { 27 | return sum; 28 | } 29 | if (sum <= 0) { 30 | return 0; 31 | } 32 | return 0; 33 | } 34 | 35 | void print_none() { 36 | return; 37 | } 38 | 39 | int main() { 40 | { 41 | printf("19373719\n"); 42 | int x = 0; 43 | int flag; 44 | int temp; 45 | int x1, x2; 46 | while(x < 4) { 47 | if (x != 4) { 48 | x = x + 1; 49 | } else { 50 | break; 51 | } 52 | flag = getint(); 53 | if (flag == 0) { 54 | x1 = getint(); 55 | temp = double2(x1) % 1; 56 | printf("%d ", temp); 57 | temp = double2(x1) / +1; 58 | printf("%d\n", temp); 59 | continue; 60 | } 61 | if (flag > 0) { 62 | x1 = getint(); 63 | x2 = getint(); 64 | printf("%d\n", add(x1, x2)); 65 | continue; 66 | } 67 | if (flag < 0) { 68 | x1 = getint(); 69 | x2 = getint(); 70 | printf("%d\n", sub(x1, x2)); 71 | continue; 72 | } 73 | 74 | } 75 | } 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /testcases/C/testfile19.txt: -------------------------------------------------------------------------------- 1 | /*cover basis, focus on Decl*/ 2 | int main(){ 3 | printf("19373135\n"); 4 | const int l_const_0 = 0; 5 | printf("l_const_0, should be 0: %d\n", l_const_0); 6 | const int l_const_1 = l_const_0 + 1; 7 | printf("l_const_1, should be 1: %d\n", l_const_1); 8 | const int l_const_2 = 2, l_const_3 = 2 * l_const_1, l_const_4 = 4; 9 | printf("l_const_3, should be 2: %d\n", l_const_3); 10 | const int l_const_5[3] = {1, 2, 3}, l_const_6[2][2] = {{1, l_const_1}, {0,0}}; 11 | printf("l_const_5[2], l_const_6[0][1], should be 3, 1: %d, %d\n", l_const_5[2], l_const_6[0][1]); 12 | int l_var_0 = 0; 13 | printf("l_var_0, should be 0: %d\n", l_var_0); 14 | int l_var_1 = 2 * (l_var_0 + 1); 15 | printf("l_var_1, should be 2: %d\n", l_var_1); 16 | int l_var_2, l_var_3 = 2 * l_var_1, l_var_4; 17 | printf("l_var_3, should be 4: %d\n", l_var_3); 18 | int l_var_5; 19 | l_var_5 = 5; 20 | printf("l_var_5, should be 5: %d\n", l_var_5); 21 | int l_var_6[3] = {1, 2, 3}, l_var_7[2][2] = {{1, l_const_1}, {1, 1}}; 22 | printf("l_var_6[2], l_var_7[0][1], should be 3, 1: %d, %d", l_var_6[2], l_var_7[0][1]); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /testcases/C/testfile2.txt: -------------------------------------------------------------------------------- 1 | int main() { 2 | printf("18375200\n"); 3 | int _origin, _1, _2, _3, _4, _5, _6, _7, _8, _9; 4 | _origin = getint(); 5 | _1 = _origin * + - +3; 6 | printf("%d\n", _1); 7 | _2 = (_1 % 10086) % 2333; 8 | printf("%d\n", _2); 9 | _3 = _2 * (_1 * _1) / 326; 10 | printf("%d\n", _3); 11 | printf("ppgod7mi"); 12 | printf("\n%dyoga%d\n", 4396, 7); 13 | printf("2333\n\n\n\n"); 14 | _4 = getint(); 15 | _5 = 2; 16 | if (_4 >= 2) _6 = 1; 17 | else _6 = 0; 18 | while (_5 <= _4 / 2) { 19 | if (_4 % _5 == 0) { 20 | _6 = 0; 21 | break; 22 | } 23 | _5 = _5 + 1; 24 | } 25 | if (_6 == 0)printf("%d is not a prime, with factor %d.\n", _4, _5); 26 | else printf("%d is a prime.\n", _4); 27 | _7 = getint(); 28 | _8 = 1; 29 | _9 = 1; 30 | _2 = 2; 31 | while (_2 < _7) { 32 | _3 = (_8 + _9) % 1000007; 33 | _8 = _9; 34 | _9 = _3; 35 | _2 = _2 + 1; 36 | } 37 | printf("The %dth Fibonacci num is %d.", _7, _9); 38 | return 0; 39 | } -------------------------------------------------------------------------------- /testcases/C/testfile20.txt: -------------------------------------------------------------------------------- 1 | 2 | int isPrime(int m) { 3 | int i; 4 | i = 2; 5 | while (i < m) { 6 | if (m % i == 0) 7 | return 0; 8 | i = i + 1; 9 | } 10 | return 1; 11 | } 12 | 13 | 14 | void check_group(int t[]) { 15 | int i; 16 | i = 0; 17 | while (i < 2) { 18 | int tmp; 19 | tmp = t[i]; 20 | tmp = isPrime(tmp); 21 | printf("%d\n", tmp); 22 | i = i + 1; 23 | } 24 | 25 | 26 | } 27 | 28 | int test(int t[][2]) { 29 | if (!t[0][1]) { 30 | ; 31 | } 32 | return 0; 33 | } 34 | 35 | int main() { 36 | 37 | printf("19373061\n"); 38 | int num; 39 | num = 30; 40 | printf("%d\n", isPrime(num)); 41 | num = 31; 42 | printf("%d\n", isPrime(num)); 43 | int tmp[3][2] = {{111, 2222},{3, 4},{5, 6}}; 44 | check_group(tmp[0]); 45 | check_group(tmp[1]); 46 | check_group(tmp[2]); 47 | 48 | int t; 49 | t = 1; 50 | while (t > 0) { 51 | if (t < 10) 52 | break; 53 | t = t + 1; 54 | } 55 | printf("t:%d\n", t); 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /testcases/C/testfile21.txt: -------------------------------------------------------------------------------- 1 | int ans; 2 | const int zero = 0, end = -1; 3 | void gcd(int a, int b) { 4 | if (a == zero) { 5 | ans = b; 6 | return; 7 | } 8 | if (b == zero) { 9 | ans = a; 10 | return; 11 | } 12 | 13 | if (a >= b) gcd(a % b, b); 14 | else gcd(a, b % a); 15 | return; 16 | } 17 | 18 | void output(int ans) { 19 | printf("gcd is %d\n", ans); 20 | return; 21 | } 22 | 23 | void error() { 24 | printf("invaild input!\n"); 25 | return; 26 | } 27 | 28 | int main() { 29 | int a, b; 30 | 31 | a = getint(); 32 | while(a != end) { 33 | b = getint(); 34 | 35 | if (a == 0) { 36 | error(); 37 | a = getint(); 38 | continue; 39 | } 40 | if (!b) { 41 | error(); 42 | a = getint(); 43 | continue; 44 | } 45 | 46 | gcd(a, b); 47 | output(ans); 48 | a = getint(); 49 | } 50 | 51 | {} 52 | ; 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /testcases/C/testfile22.txt: -------------------------------------------------------------------------------- 1 | //#include 2 | //test Decl 3 | // test ConstDecl 4 | const int top = 1;//test ConstDecl.1 5 | const int sum = 0, all = 0, sum_1 = 23;//test ConstDecl.2 6 | const int top_2 = top, top_3 = top + 2;//ConstExp 7 | // test VarDecl 8 | int head = 0; 9 | int stack_top, stack_bottom, bottom; 10 | int a1; 11 | int a2 = 2, a3 = 3, a5 = (3 + 2); 12 | //test FuncDef 13 | 14 | void addGloHead() { 15 | head = head + 1; 16 | return; 17 | } 18 | 19 | int judgeZero(int a) { 20 | if (a == 0) { 21 | return 1; 22 | } 23 | return 0; 24 | } 25 | 26 | int findMax(int a, int b) { 27 | if (a > b) { 28 | return a; 29 | } 30 | return b; 31 | } 32 | 33 | void blank() { 34 | } 35 | 36 | void testWhile() { 37 | int i = 10; 38 | while (i != 10);//add 39 | while (i >= 5) { 40 | if (i != 8) { 41 | i = i - 1; 42 | continue; 43 | } 44 | if (i == 8) { 45 | break; 46 | } 47 | } 48 | } 49 | 50 | void testUnaryExp() { 51 | int tmp, blk; 52 | //primaryExp 53 | tmp = sum; 54 | tmp = 1; 55 | tmp = (a2 * 3); 56 | 57 | blk = tmp + findMax(a2, a3); 58 | blk = blk - (2 * 1); 59 | 60 | int zero; 61 | zero = +5; 62 | zero = -7; 63 | zero = +-+10; 64 | } 65 | 66 | void testRelExp() { 67 | int score = 40; 68 | int grade; 69 | if (score < 60) { 70 | grade = 1; 71 | } 72 | if (score <= 40) { 73 | grade = 0; 74 | } 75 | if (score > 60) { 76 | grade = 3; 77 | } 78 | if (score >= 85) 79 | grade = 5; 80 | else { 81 | grade = 4; 82 | } 83 | } 84 | 85 | void testAddExp() { 86 | int b1, b2; 87 | b1 = 3 + 4; 88 | b2 = 5 - 7; 89 | } 90 | 91 | void testLogic() { 92 | int a1; 93 | if (!judgeZero(a5)) { 94 | a1 = 10; 95 | } 96 | } 97 | 98 | int main() { 99 | int tmp; 100 | //test MulExp 101 | int b1 = 8 / 2; 102 | int b2 = a2 * 5; 103 | int b3 = b2 % 3; 104 | //end 105 | tmp = getint();// 106 | printf("19373034\n");//1 107 | printf("%d\n", tmp);//7 108 | 109 | printf("%d\n", top);//2 110 | 111 | printf("%d\n", head);//3 112 | addGloHead(); 113 | printf("%d\n", head);//4 114 | 115 | tmp = judgeZero(b1); 116 | printf("%d\n", tmp);//5 117 | 118 | tmp = findMax(b2, b3); 119 | printf("%d\n", tmp);//6 120 | 121 | blank(); 122 | testWhile(); 123 | testUnaryExp(); 124 | testRelExp(); 125 | testAddExp(); 126 | testLogic(); 127 | 128 | printf("8\n"); 129 | printf("9\n"); 130 | printf("10"); 131 | return 0; 132 | } -------------------------------------------------------------------------------- /testcases/C/testfile23.txt: -------------------------------------------------------------------------------- 1 | 2 | int a,b=2+0; 3 | int c=3+0; 4 | int d=4; 5 | 6 | void shayemeiyou(){ 7 | int m; 8 | } 9 | int yi(){ 10 | return 1; 11 | } 12 | int pidoubushi(int n){ 13 | return 0; 14 | } 15 | int mult(int g,int k){ 16 | return g*k; 17 | } 18 | int main(){ 19 | int i=0; 20 | int m; 21 | int s=1; 22 | printf("19373044\n"); 23 | printf("s+1=%d\n",s+1); 24 | m=getint(); 25 | printf("m=%d\n",m); 26 | { 27 | } 28 | if(!m){ 29 | m=m+yi(); 30 | } 31 | printf("m=%d\n",m); 32 | if(m==1){ 33 | m=m-1; 34 | } 35 | else; 36 | printf("m=%d\n",m); 37 | while(m!=3){ 38 | printf("m=%d\n",m); 39 | m=-+-((mult(m,1)/1+1)%4); 40 | } 41 | i=mult(m,1); 42 | printf("m=%d\n",m); 43 | while(m>0){ 44 | if(m<=0){ 45 | continue; 46 | } 47 | printf("before break\n"); 48 | break; 49 | } 50 | if(m>=0){ 51 | } 52 | return 0; 53 | 54 | } 55 | 56 | -------------------------------------------------------------------------------- /testcases/C/testfile24.txt: -------------------------------------------------------------------------------- 1 | const int p = 88; 2 | int q = 66, r = 155; 3 | int s = 15; 4 | int max(int a, int b) { 5 | if (a > b) { 6 | return a; 7 | } 8 | else { 9 | return b; 10 | } 11 | return a; 12 | } 13 | int min(int a, int b) { 14 | if (a < b) { 15 | return a; 16 | } 17 | else { 18 | return b; 19 | } 20 | return a; 21 | } 22 | int scan() { 23 | int tmp = 0; 24 | tmp = getint(); 25 | return tmp + 0; 26 | } 27 | void print(int num) { 28 | printf("%d\n", num); 29 | return; 30 | } 31 | void noUse(int a) { 32 | int b = a; 33 | } 34 | int mid(int a, int b, int c) { 35 | int m = 0; 36 | if (max(a, b) == min(b, c)) { 37 | return b; 38 | } 39 | else { 40 | if (max(a, b) != min(a, c)) 41 | return c; 42 | else 43 | return a; 44 | } 45 | return b; 46 | } 47 | int factorial(int n) { 48 | int i = n; 49 | int ret = 1; 50 | if (n > 20) { 51 | printf("Your Num is too Big!!!\n"); 52 | return -1; 53 | } 54 | while (i) { 55 | ret = ret * i; 56 | i = i - 1; 57 | } 58 | return ret; 59 | } 60 | int main() { 61 | int a = max(min(p, q), max(s, scan())); 62 | int b = min(r, scan()), c = 58; 63 | const int d = 65535; 64 | int bool1 = 0, bool2 = 1, bool3 = -1; 65 | int tmp = -10; 66 | printf("19373022\n"); 67 | b = b + c - a; 68 | printf("b:%d\n", b); 69 | ; 70 | (bool2 + bool3); 71 | bool1; 72 | if (!bool1) { 73 | printf("Bool1 is false!\n"); 74 | } 75 | 2147483647; 76 | { 77 | int tmp = 0; 78 | tmp = scan(); 79 | print(tmp + 10); 80 | c = tmp; 81 | } 82 | a = scan(); 83 | b = scan(); 84 | c = scan(); 85 | if (mid(a, b, c) <= a) { 86 | printf("Good!,Num is %d\n", a + mid(a, b, c) / 6 * c % 2 - (bool1 * bool3)); 87 | } 88 | else { 89 | if (mid(a, b, c) < c) { 90 | printf("Oh!?\n"); 91 | } 92 | else { 93 | printf("%d\n", factorial(mid(a, b, c) % d)); 94 | } 95 | } 96 | noUse(a); 97 | return 0; 98 | } -------------------------------------------------------------------------------- /testcases/C/testfile26.txt: -------------------------------------------------------------------------------- 1 | const int cn0 = 12; 2 | const int cn1 = cn0 + 1, cn2 = cn1 + cn0, cn3 = 76 * 12; 3 | int vr0 = cn1; 4 | int vr1; 5 | int vr2, vr3 = 99, vr4; 6 | 7 | int rand() { 8 | return 180; 9 | } 10 | 11 | int addSum(int x) { 12 | int t = x, sum = 0; 13 | while (t>t == t y) return gcd(x, x % y); 24 | return gcd(y, y%x); 25 | } 26 | 27 | void fv0() { 28 | return; 29 | } 30 | 31 | void fv1(int x, int y, int z) { 32 | 33 | } 34 | 35 | int main() { 36 | const int cn4 = 23; 37 | int vr5 = 0; 38 | printf("%d%d%d%d%d%d%d%d\n",1,9,3,7,3,2,7,6); 39 | printf(" !()*+,-./0123456789:;<>=?@[]^_`~{}|\n"); 40 | printf("qwertyuiopasd\nfghjklzxcvbnm"); 41 | printf("QWERTYUIOPASD\nFGHJKLZXCVBNM"); 42 | vr5 = getint(); 43 | vr5 = cn4 * vr5; 44 | ; 45 | 1+1; 46 | { 47 | if (cn4 >= cn4 != cn4 <= cn4) ; 48 | fv0(); 49 | } 50 | while (vr5 > 0) { 51 | vr5 = vr5 - 1; 52 | if (vr5 % 2 == 1) continue; 53 | vr1 = vr1 + 1; 54 | vr5 = vr5 / 2; 55 | } 56 | while((1)){break;} 57 | if (1) vr3 = 9; 58 | printf("%d\n", vr5); 59 | printf("%d %d\n", gcd(72, 18), gcd(vr1, cn4)); 60 | printf("addSum: %d, %d\n", addSum(14), addSum(vr1)); 61 | printf("%d\n", +-+1*-+-rand() *(12) -vr1 /2 /2 + -+-100%97%2 - (1+1)*(1+1) *(1+1)); 62 | printf("1008%d\n", -6); 63 | printf("end"); 64 | return 0; 65 | } -------------------------------------------------------------------------------- /testcases/C/testfile27.txt: -------------------------------------------------------------------------------- 1 | // 编译单元 2 | /* add exp 3 | 4 | 5 | 6 | */ 7 | //声明 8 | const int const_a = 1; 9 | const int const_a0 = 1 + 3, _const_a1 = 1 + 3 * 4 / 5 % 2; 10 | int var_a; 11 | int var_a0, var_a1; 12 | int var_init = -1; 13 | int var_init0 = -2 +-+5, var_init1 = 4 / 2; 14 | 15 | //函数定义 16 | void func_void0() { 17 | return; 18 | } 19 | 20 | void func_void1(int a1) { 21 | return; 22 | } 23 | 24 | void func_void2(int a1, int a2, int a3) { 25 | return; 26 | } 27 | 28 | int func_int0() { 29 | return 0; 30 | } 31 | 32 | int func_int1(int a1) { 33 | return 1; 34 | } 35 | 36 | int func_int2(int a1, int a2) { 37 | return 2; 38 | } 39 | 40 | 41 | // 主函数 42 | int main() { 43 | printf("19373315\n"); 44 | var_a = -const_a; 45 | var_a0 = (const_a + 1) * -5 * -1 % 7 + 1 -+-5; 46 | var_a1 = 1; 47 | int tmp_a = 0; 48 | int tmp_1 = 1; 49 | ; 50 | func_void0(); 51 | 1 + 1; 52 | { 53 | 54 | } 55 | { 56 | printf("this is a yu ju ky\n"); 57 | } 58 | var_a = 1; 59 | while (var_a <= 10) { 60 | var_a = var_a + 1; 61 | if (var_a >= 8) { 62 | break; 63 | } else { 64 | continue; 65 | } 66 | } 67 | if (1) { 68 | if (1 == 1) { 69 | if (func_int0() == 0) { 70 | if (func_int1(1) == 1) { 71 | if (func_int2(1, 2) - 5 +-1 != 1) { 72 | if (1 < 2) { 73 | if (2 > 1) { 74 | printf("unbelievable!\n"); 75 | } 76 | } 77 | } 78 | } 79 | } 80 | } 81 | } 82 | if (!0) ; 83 | if (!func_int0()) ; 84 | if (2 - !func_int1(1) == 2) ; 85 | 86 | var_a = getint(); 87 | printf("var_a from getint() is %d\n", var_a); 88 | printf("getint is %d\n", 1); 89 | printf("tmp\n"); 90 | printf("tmp\n"); 91 | printf("tmp\n"); 92 | printf("tmp\n"); 93 | printf("tmp\n"); 94 | return 0; 95 | } -------------------------------------------------------------------------------- /testcases/C/testfile28.txt: -------------------------------------------------------------------------------- 1 | /*test5:Stmt的[2]~[9] */ 2 | void test() { 3 | return; 4 | } 5 | 6 | int main() 7 | { 8 | //Decl 9 | int a = 2; 10 | int b = 5; 11 | 12 | //First Stmt 13 | printf("19373332\n"); //[1] 14 | 15 | //Stmt 16 | /*[2]: [Exp] ';' //有无Exp两种情况*/ 17 | a + b; 18 | ; 19 | 20 | /*[3]: Block */ 21 | { 22 | /*重复0次*/ 23 | } 24 | { 25 | /*重复多次*/ 26 | int c = 1; 27 | int d = 0; 28 | c = a; 29 | d = b * 9 + 1; 30 | printf("Stmt-3(Block): c = %d, d = %d\n", c, d); //[2] 31 | int e = 1; 32 | int f = 0; 33 | e = 2 * c; 34 | f = e * d / c * 9 + 1; 35 | printf("Stmt-3(Block): e = %d, f = %d\n", e, f); //[3] 36 | } 37 | 38 | /*[4]: 'if' '( Cond ')' Stmt [ 'else' Stmt ] // 1.有else 2.无else*/ 39 | if(b != 0) a = a + 1; 40 | if(b != 0) { 41 | a = 0; 42 | } else { 43 | a = 1; 44 | } 45 | printf("Stmt-4(if) check finish!\n"); //[4] 46 | 47 | /*[5]: 'while' '(' Cond ')' Stmt*/ 48 | /*[6]: 'break' ';' | 'continue' ';'*/ 49 | int i = 0; 50 | while(a < 10) { 51 | i = i * 2; 52 | a = a + 1; 53 | if(a >= 6) { 54 | continue; 55 | } 56 | if(a == 5) { 57 | break; 58 | } 59 | } 60 | printf("Stmt-5,6 check finish!\n"); //[5] 61 | 62 | /*[7]: 'return' [Exp] ';' // 1.有Exp 2.无Exp*/ 63 | /*最后的return 0就是了*/ 64 | printf("Stmt-7 check finish!\n"); //[6] 65 | 66 | /*[8]: LVal = 'getint''('')'';'*/ 67 | a = getint(); 68 | //scanf("%d", &a); 69 | printf("Stmt-8 check finish!\n"); //[7] 70 | 71 | /*[9]: 'printf' '('FormatString {',' Exp} ')'';' // 1.有Exp 2.无Exp */ 72 | printf("\n"); //[8] 73 | printf("FormatChar.\n"); //[9] 74 | printf("%d\n", a * 2 + 1); //[10] 75 | 76 | test(); 77 | 78 | return 0; 79 | } -------------------------------------------------------------------------------- /testcases/C/testfile29.txt: -------------------------------------------------------------------------------- 1 | const int A = 1; 2 | const int B = 2, C = 3, D = 4; 3 | 4 | int n = 10; 5 | int m = 20, p = 99, q = 66; 6 | 7 | void f0() { 8 | return; 9 | } 10 | 11 | int f1(int x) { 12 | if (x >= 0) { 13 | x = x + 1;;;; 14 | } 15 | 16 | if (x <= 0) { 17 | x = x + 1; 18 | } else { 19 | } 20 | 21 | { 22 | x = x + 1; 23 | } 24 | 25 | while (x < 0) { 26 | x = -x; 27 | } 28 | 29 | while (x > 0) { 30 | x = -x; 31 | continue; 32 | } 33 | 34 | while (x == 0) 35 | x = x + 1; 36 | 37 | while (x != 0) { 38 | break; 39 | } 40 | 41 | while (1) { 42 | while (!1) { 43 | } 44 | break; 45 | } 46 | 47 | return x; 48 | } 49 | 50 | int f2(int x, int y, int z) { 51 | int a; 52 | a = x + n * B - m / C + z % (A + B) + 233 + -y + f1(y); 53 | a = a * +A; 54 | return x + y + a; 55 | } 56 | 57 | int gi() { 58 | int r; 59 | r = getint(); 60 | printf("Got a number: "); 61 | printf("%d!\n", r); 62 | return r; 63 | } 64 | 65 | int main() { 66 | printf("19373348\n"); 67 | 68 | int a = f2(1, 2, gi()); 69 | f0(); 70 | printf("%d\n", a); 71 | printf("%d\n", f1(gi())); 72 | int b = f2(a, A, gi()), c, d; 73 | printf("%d\n", b); 74 | c = f2(b, n, gi()); 75 | printf("%d\n", c); 76 | printf("%d\n", f2(c, gi(), q)); 77 | d = 0; 78 | return d; 79 | } 80 | -------------------------------------------------------------------------------- /testcases/C/testfile3.txt: -------------------------------------------------------------------------------- 1 | //#include 2 | const int a = 9; 3 | const int b = a; 4 | int d = a; 5 | 6 | //int getint(){ 7 | // int n; 8 | // scanf("%d",&n); 9 | // return n; 10 | // 11 | //} 12 | int mycheck(int a){ 13 | if (a == 1) return 10; 14 | if (a==2) return 20; 15 | if (a==4) return 40 ; 16 | else if (a==5) return 50; 17 | else if (a == 6) return 60; 18 | if (a==3) return 30 ;else return 99 ; 19 | return 0; 20 | return 1; 21 | } 22 | 23 | void testGetInt(){ 24 | int i = 0; 25 | 26 | while(i<9){ 27 | int temp; 28 | temp = getint(); 29 | printf("%d\n",temp); 30 | i = i + 1; 31 | } 32 | } 33 | 34 | 35 | int main(){ 36 | const int in1 = 89; 37 | const int in2 = in1; 38 | int vin1 = in1; 39 | int vin2 = vin1; 40 | int vin3 = in2; 41 | int vin4 = a + b; 42 | int vin5 = d; 43 | 44 | 45 | printf("%d\n",19231177); 46 | testGetInt(); 47 | int a = 1; 48 | while(a<10){ 49 | printf("%d\n",mycheck(a)); 50 | if (mycheck(a) < mycheck(mycheck(a)/20) ){ 51 | printf("appear\n"); 52 | }else{ 53 | printf("not\n"); 54 | } 55 | a = a + 1; 56 | } 57 | int a1 = 1,a2 = 2,a3 = 3; 58 | printf("print123\n"); 59 | printf("%d%d%d\n",1,2,3); 60 | printf("/****/%d%d%d\n",1,a2,a3); 61 | printf("/**/%d%d%d\n",a1,a2,a3); 62 | printf("print return value :\n"); 63 | int temp = 5; 64 | printf("in : 5 ,out = %d\n",mycheck(5)); 65 | printf("in : 5 ,out = %d\n",mycheck(temp)); 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /testcases/C/testfile4.txt: -------------------------------------------------------------------------------- 1 | const int max_number = 100; 2 | const int min_number = 0; 3 | int a = 0; 4 | int main(){ 5 | printf("19231204"); 6 | printf("\n"); 7 | int score; 8 | int b = 30; 9 | score = getint(); 10 | if (score >= min_number){ 11 | printf("The score is %d.\n",score); 12 | } 13 | a = 4 / 2; 14 | if (a == 2){ 15 | printf("Yes!\n"); 16 | } 17 | a = 3 + 5; 18 | if (a != 8){ 19 | printf("No!\n"); 20 | }else{ 21 | printf("Yes!\n"); 22 | } 23 | a = 10 * 10; 24 | if (a <= max_number){ 25 | printf("Yes!\n"); 26 | } 27 | if (a < max_number){ 28 | printf("Yes!\n"); 29 | } 30 | if (a > b) { 31 | printf("No!"); 32 | }else { 33 | printf("Yes!"); 34 | } 35 | return 0; 36 | } -------------------------------------------------------------------------------- /testcases/C/testfile5.txt: -------------------------------------------------------------------------------- 1 | const int zero = 0,one = +1, minus_one = -1; 2 | const int two = 2; 3 | const int times = zero; 4 | int while_times = zero; 5 | int groups = 10; 6 | 7 | int get_max(int a,int b,int c){ 8 | a/b; 9 | int max = a; 10 | if(b > max){ 11 | max = b; 12 | if(c > max){ 13 | max = c; 14 | } 15 | } 16 | return max; 17 | } 18 | 19 | void while_times_cal(){ 20 | while_times = while_times + 1; 21 | return; 22 | } 23 | 24 | int is_prime(int in){ 25 | int result = zero; 26 | int item = two; 27 | { 28 | 29 | } 30 | if(in == 2){ 31 | result = one; 32 | ; 33 | }else{ 34 | while(item < in){ 35 | while_times_cal(); 36 | if(in%item == 0){ 37 | result = zero; 38 | break; 39 | } 40 | result = one; 41 | item = item + 1; 42 | } 43 | } 44 | return result; 45 | } 46 | 47 | 48 | 49 | int main(){ 50 | int input; 51 | printf("16061069\n"); 52 | printf("input an integer,judge if it is prime number,10 groups in total\n"); 53 | while(groups != 0){ 54 | while_times_cal(); 55 | input = getint(); 56 | if(input <= 0){ 57 | printf("input > 0 is needed\n"); 58 | groups = groups - 1; 59 | continue; 60 | } 61 | if(input == 1){ 62 | printf("1 is not concerned\n"); 63 | groups = groups - 1; 64 | continue; 65 | }else{ 66 | if(is_prime(input) >= 1){ 67 | printf("%d is a prime number\n",input); 68 | }else{ 69 | printf("%d is not a prime number\n",input); 70 | } 71 | } 72 | groups = groups - 1; 73 | } 74 | printf("while times is %d in total\n",while_times); 75 | return 0; 76 | } -------------------------------------------------------------------------------- /testcases/C/testfile6.txt: -------------------------------------------------------------------------------- 1 | //#include 2 | int main(){ 3 | printf("19231177\n"); 4 | int _ = 1;/**/ 5 | int a; 6 | a = /**/20; 7 | int b,c=460; 8 | b/**/=30; 9 | printf/**/("_ = %d; a = %d; b = %d; c = %d;\n",_,a,/**/b,c); 10 | 11 | int n1 ,n2,n3,n4,n5; 12 | n1 = a + b; 13 | n2 = c - _; 14 | n3 = n1 * n2; 15 | n4 = n2 / n1; 16 | n5 = n3 % b; 17 | printf( "%d+%d=%d; %d-%d=%d; %d*%d=%d; %d/%d=%d; %dmod%d=%d\n",a,b,n1,c,_,n2,n1,n2,n3,n2,n1,n4,n3,b,n5); 18 | 19 | int a1 = n1+n2+n3,a2=n2-n3-n4,a3=n3*n4*n5,a4=n5/n1/n4,a5=n4%n1%n1; 20 | printf("%d+%d+%d=%d; %d-%d-%d=%d; %d*%d*%d=%d; %d/%d/%d=%d; %dmod%dmod%d=%d\n",n1, n2,n3,a1,n2, n3 , n4,a2,n3, n4,n5 ,a3,n5,n1,n2,a4,n4,n5,n1,a5) ; 21 | ;;; 22 | 23 | 24 | int m_1 = 10,m_2=17,m_3=23,m_4=37,m_5=43,m_6=71;int r1=m_1+m_2-m_3*m_4/m_5%m_6-m_2*m_3+m_5; 25 | int r2 =m_1+(m_2-m_3)*m_4/m_5%(m_6-m_4)*r1; 26 | 27 | // right 28 | printf("%d+%d-%d*%d/%dmod%d-%d*%d+%d=%d=%d\n", m_1,m_2, m_3,m_4,m_5,m_6,m_2,m_3,m_5,r1,m_1+m_2-m_3*m_4/m_5%m_6-m_2*m_3+m_5); 29 | // printf("%d\n",m_1); 30 | printf("%d+(%d-%d)*%d/%dmod(%d-%d)*%d=%d\n",m_1,m_2,m_3,m_4,m_5,m_6,m_4,r1,r2); 31 | // wrong 32 | printf("all chars : !()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~\n"); 33 | 34 | int test_1 = 1; 35 | int i=5 ; 36 | int old = i; 37 | while(i > 0 ){// /* 38 | test_1 = test_1 * i;i = i - 1;} 39 | if(test_1==120){ 40 | test_1 = test_1 + 7; // */ 41 | } 42 | if(test_1>119==1){ 43 | test_1 = test_1 + 3; 44 | } 45 | if (0>=1){ 46 | printf ("a"); 47 | } 48 | if (1<=0){ 49 | printf("a");/*** / */ 50 | } 51 | if (!1){ 52 | printf("b"); 53 | } 54 | printf("%d!+7+3=%d\n",old,test_1); 55 | 56 | int nn_1 = +1, nn2 = -1,nn3 = +-1,nn4 = -+1,nn5 = -+-1,nn6 = +-+1,nn7=-+-+1,nn8=+-+-1; 57 | if (nn_1 + nn2 + nn3 + nn4 + nn5 + nn6 + nn7 + nn8 != 0) ; 58 | if (nn_1 + nn2 + nn3 + nn4 + nn5 + nn6 + nn7 + nn8 != 0) printf("! : error\n"); 59 | 60 | int max_int = 2147483647; 61 | int min_int = -2147483647; 62 | printf("max: %d ; min : %d ; sum : %d\n",max_int,min_int,max_int + min_int); 63 | 64 | 65 | /** /*** **/ 66 | int remain = 1; 67 | int /** /*** **/remain_index = 0; 68 | while (remain_index/** /*** **/ < remain) { 69 | printf("19231177\n"); 70 | remain_index = remain_index + 1; 71 | } 72 | 73 | 74 | return 0; 75 | 76 | } 77 | -------------------------------------------------------------------------------- /testcases/C/testfile8.txt: -------------------------------------------------------------------------------- 1 | int aa(int b[][3]) 2 | { 3 | int w; 4 | w=b[0][0]+b[0][1]+b[0][2]+b[1][0]+b[1][1]+b[1][2]; 5 | return w; 6 | } 7 | int main() 8 | { 9 | printf("19182650\n"); 10 | const int a[2][3]={{1,2,3},{4,5,6}}; 11 | int b[2][3]={{1,2,3},{4,5,6}}; 12 | int c[2][3]; 13 | int d; 14 | d=aa(b); 15 | c[0][0]=b[0][0]; 16 | c[0][1]=b[0][1]; 17 | c[0][2]=b[0][2]; 18 | c[1][0]=b[1][0]; 19 | c[1][1]=b[1][1]; 20 | c[1][2]=b[1][2]; 21 | printf("%d\n",a[0][0]); 22 | printf("%d\n",a[0][1]); 23 | printf("%d\n",a[0][2]); 24 | printf("%d\n",a[1][0]); 25 | printf("%d\n",a[1][1]); 26 | printf("%d\n",a[1][2]); 27 | printf("%d\n",d); 28 | printf("%d\n",c[0][0]); 29 | printf("%d\n",c[1][2]); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /testcases/C/testfile9.txt: -------------------------------------------------------------------------------- 1 | const int a = 1; 2 | const int b = 2 * 6 + 1, _a_b[2%2+1] = {5}, _a_3_b[2/2+1][2*1-1] = {{0},{3452%2+4*3}}; 3 | int c, d[2%2+1], _a_4_b[2/2+1][2*1-1] = {{0},{3452%2+4*3}}, z; 4 | int _d_e = 1; 5 | int glo_1, glo_2, glo_3, glo_4, glo_5, glo_6, glo_7, glo_8, glo_9; 6 | 7 | void test_1(int var_1, int var_2[], int var_3[][1]){ 8 | c = var_1 + var_2[0] + var_3[0][0]; 9 | 10 | } 11 | 12 | int main() { 13 | const int f = 1; 14 | const int g = 2 * 6 + 1, _a_b_[2%2+1] = {a}, _a_3_b_d[2/2+1][2*1-1] = {{0},{3452%2+4*3}}; 15 | int c, d[2%2+1], _a_4_b_d[2/2+1][2*1-1] = {{0},{3452%2+4*3}}; 16 | int _d_e_g = (_a_3_b_d[0][0] + _a_4_b_d[0][0]) * b + 1; 17 | d[0] = 1; 18 | _a_4_b_d[0][0] = 1; 19 | c = _d_e_g + _a_4_b_d[0][0]; 20 | glo_1 = getint(); 21 | glo_2 = getint(); 22 | glo_3 = getint(); 23 | glo_4 = getint(); 24 | glo_5 = getint(); 25 | glo_6 = getint(); 26 | glo_7 = getint(); 27 | glo_8 = getint(); 28 | glo_9 = getint(); 29 | test_1(c, d, _a_4_b_d); 30 | while(glo_9 > 0 || glo_8 > 0 && glo_7 > 0) { 31 | if(glo_2>2) { 32 | glo_2 = glo_2 - 1; 33 | continue; 34 | } else { 35 | glo_2 = glo_2 - 1; 36 | glo_1 = glo_1 - 1; 37 | if (glo_1 < 0) 38 | break; 39 | } 40 | } 41 | printf("19231076\n"); 42 | printf(">/!~varg1 is:%d;~\n", glo_1); 43 | printf(">/!~varg2 is:%d;~\n", glo_2); 44 | printf(">/!~varg3 is:%d;~\n", glo_3); 45 | printf(">/!~varg4 is:%d;~\n", glo_4); 46 | printf(">/!~varg5 is:%d;~\n", glo_5); 47 | printf(">/!~varg6 is:%d;~\n", glo_6); 48 | printf(">/!~varg7 is:%d;~\n", glo_7); 49 | printf(">/!~varg8 is:%d;~\n", glo_8); 50 | printf(">/!~varg9 is:%d;~\n", glo_9); 51 | return 0; 52 | } --------------------------------------------------------------------------------