├── .gitignore ├── Document.md ├── README.md ├── compiler └── compiler.iml ├── document ├── 2021编译器课程设计竞速排名及MARS仿真器使用说明.pdf ├── Document.pdf ├── SysY文法.pdf ├── 编译器课程设计中间代码格式2021.pdf └── 编译课感想.pdf ├── out ├── artifacts │ └── Compiler_jar │ │ └── Compiler.jar └── production │ └── BUAA-Compile-2021 │ ├── Compiler.class │ ├── META-INF │ └── MANIFEST.MF │ ├── backend │ ├── Backend.class │ ├── IR2Mips.class │ ├── MIPSOptimizer.class │ └── mips │ │ ├── Assign.class │ │ ├── BrJump.class │ │ ├── Calculate.class │ │ ├── IRTranslator.class │ │ ├── LabelMipsCode.class │ │ ├── LoadStore.class │ │ ├── MTF.class │ │ ├── MipsCode.class │ │ ├── Namespace.class │ │ ├── StackManage.class │ │ └── Syscall.class │ └── frontend │ ├── Frontend.class │ ├── IOtool.class │ ├── SymbolTable.class │ ├── irgen │ ├── IRGenerater.class │ ├── Optimizer.class │ ├── optimize │ │ ├── BasicBlock.class │ │ ├── BasicBlockDivide.class │ │ ├── CompileUnit.class │ │ ├── Dag$Block.class │ │ ├── Dag$Graph.class │ │ ├── Dag$Node.class │ │ ├── Dag.class │ │ ├── Divoptimizer.class │ │ ├── Flatter.class │ │ ├── FuncBlock.class │ │ └── HoleOptimizer.class │ └── symtable │ │ ├── Block.class │ │ ├── Func.class │ │ ├── SymTable.class │ │ └── Var.class │ ├── preprocess │ ├── ASTNode.class │ ├── ExcNode.class │ ├── Lexer.class │ ├── Parser.class │ ├── Visitor.class │ └── Word.class │ └── stdir │ ├── ArrayDecl.class │ ├── ArrayLoadStore.class │ ├── CondBranch.class │ ├── Decl.class │ ├── Exp.class │ ├── FuncCall.class │ ├── FuncDecl.class │ ├── FuncParam.class │ ├── FuncRet.class │ ├── IRCode.class │ ├── Jump.class │ ├── Label.class │ ├── Printf.class │ └── Sym.class ├── pic ├── Compiler.png ├── Compiler1.png ├── ExcNode_Visitor_SymbolTable.png ├── Lexer_Word.png └── Parser_ASTNode.png ├── score ├── 2021-11-22-16-12.txt ├── 2021-11-22-16-17.txt ├── 2021-11-22-16-25.txt ├── 2021-12-09-16-24.txt └── 2021-12-09-16-26.txt ├── src ├── Compiler.java ├── META-INF │ └── MANIFEST.MF ├── backend │ ├── Backend.java │ ├── IR2Mips.java │ ├── MIPSOptimizer.java │ └── mips │ │ ├── Assign.java │ │ ├── BrJump.java │ │ ├── Calculate.java │ │ ├── IRTranslator.java │ │ ├── LabelMipsCode.java │ │ ├── LoadStore.java │ │ ├── MTF.java │ │ ├── MipsCode.java │ │ ├── Namespace.java │ │ ├── StackManage.java │ │ └── Syscall.java └── frontend │ ├── Frontend.java │ ├── IOtool.java │ ├── irgen │ ├── IRGenerater.java │ ├── Optimizer.java │ ├── optimize │ │ ├── BasicBlock.java │ │ ├── BasicBlockDivide.java │ │ ├── CompileUnit.java │ │ ├── Dag.java │ │ ├── Divoptimizer.java │ │ ├── Flatter.java │ │ ├── FuncBlock.java │ │ └── HoleOptimizer.java │ └── symtable │ │ ├── Block.java │ │ ├── Func.java │ │ ├── SymTable.java │ │ └── Var.java │ ├── preprocess │ ├── ASTNode.java │ ├── ExcNode.java │ ├── Lexer.java │ ├── Parser.java │ ├── SymbolTable.java │ ├── Visitor.java │ └── Word.java │ └── stdir │ ├── ArrayDecl.java │ ├── ArrayLoadStore.java │ ├── CondBranch.java │ ├── Decl.java │ ├── Exp.java │ ├── FuncCall.java │ ├── FuncDecl.java │ ├── FuncParam.java │ ├── FuncRet.java │ ├── IRCode.java │ ├── Jump.java │ ├── Label.java │ ├── Printf.java │ └── Sym.java ├── test.py └── test ├── 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 ├── D ├── input1.txt ├── input2.txt ├── output1.txt ├── output2.txt ├── testfile1.txt └── testfile2.txt └── DIV ├── input1.txt ├── input2.txt ├── output1.txt ├── output2.txt ├── testfile1.txt └── testfile2.txt /.gitignore: -------------------------------------------------------------------------------- 1 | /Compiler.iml 2 | /*.zip 3 | /*.txt 4 | /*.asm 5 | /src/test/* 6 | /*.jar 7 | /myoutput 8 | /BUAA-Compile-2021.iml 9 | .idea/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BUAA-Compile-2021 2 | 3 | 2021年北航编译课程设计,基于类C的SysY文法的MIPS编译器 4 | 5 | 文法和错误类型参见`document/SysY文法.pdf` 6 | 7 | 设计文档参见`document/Document.pdf` 8 | 9 | 推荐使用IDEA进行运行和测试 10 | 11 | -------------------------------------------------------------------------------- /compiler/compiler.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /document/2021编译器课程设计竞速排名及MARS仿真器使用说明.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/document/2021编译器课程设计竞速排名及MARS仿真器使用说明.pdf -------------------------------------------------------------------------------- /document/Document.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/document/Document.pdf -------------------------------------------------------------------------------- /document/SysY文法.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/document/SysY文法.pdf -------------------------------------------------------------------------------- /document/编译器课程设计中间代码格式2021.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/document/编译器课程设计中间代码格式2021.pdf -------------------------------------------------------------------------------- /document/编译课感想.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/document/编译课感想.pdf -------------------------------------------------------------------------------- /out/artifacts/Compiler_jar/Compiler.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/artifacts/Compiler_jar/Compiler.jar -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/Compiler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/Compiler.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: Compiler 3 | 4 | -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/backend/Backend.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/backend/Backend.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/backend/IR2Mips.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/backend/IR2Mips.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/backend/MIPSOptimizer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/backend/MIPSOptimizer.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/backend/mips/Assign.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/backend/mips/Assign.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/backend/mips/BrJump.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/backend/mips/BrJump.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/backend/mips/Calculate.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/backend/mips/Calculate.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/backend/mips/IRTranslator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/backend/mips/IRTranslator.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/backend/mips/LabelMipsCode.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/backend/mips/LabelMipsCode.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/backend/mips/LoadStore.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/backend/mips/LoadStore.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/backend/mips/MTF.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/backend/mips/MTF.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/backend/mips/MipsCode.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/backend/mips/MipsCode.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/backend/mips/Namespace.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/backend/mips/Namespace.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/backend/mips/StackManage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/backend/mips/StackManage.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/backend/mips/Syscall.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/backend/mips/Syscall.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/Frontend.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/Frontend.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/IOtool.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/IOtool.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/SymbolTable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/SymbolTable.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/irgen/IRGenerater.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/irgen/IRGenerater.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/irgen/Optimizer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/irgen/Optimizer.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/irgen/optimize/BasicBlock.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/irgen/optimize/BasicBlock.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/irgen/optimize/BasicBlockDivide.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/irgen/optimize/BasicBlockDivide.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/irgen/optimize/CompileUnit.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/irgen/optimize/CompileUnit.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/irgen/optimize/Dag$Block.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/irgen/optimize/Dag$Block.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/irgen/optimize/Dag$Graph.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/irgen/optimize/Dag$Graph.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/irgen/optimize/Dag$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/irgen/optimize/Dag$Node.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/irgen/optimize/Dag.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/irgen/optimize/Dag.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/irgen/optimize/Divoptimizer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/irgen/optimize/Divoptimizer.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/irgen/optimize/Flatter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/irgen/optimize/Flatter.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/irgen/optimize/FuncBlock.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/irgen/optimize/FuncBlock.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/irgen/optimize/HoleOptimizer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/irgen/optimize/HoleOptimizer.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/irgen/symtable/Block.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/irgen/symtable/Block.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/irgen/symtable/Func.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/irgen/symtable/Func.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/irgen/symtable/SymTable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/irgen/symtable/SymTable.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/irgen/symtable/Var.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/irgen/symtable/Var.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/preprocess/ASTNode.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/preprocess/ASTNode.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/preprocess/ExcNode.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/preprocess/ExcNode.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/preprocess/Lexer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/preprocess/Lexer.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/preprocess/Parser.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/preprocess/Parser.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/preprocess/Visitor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/preprocess/Visitor.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/preprocess/Word.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/preprocess/Word.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/stdir/ArrayDecl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/stdir/ArrayDecl.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/stdir/ArrayLoadStore.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/stdir/ArrayLoadStore.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/stdir/CondBranch.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/stdir/CondBranch.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/stdir/Decl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/stdir/Decl.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/stdir/Exp.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/stdir/Exp.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/stdir/FuncCall.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/stdir/FuncCall.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/stdir/FuncDecl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/stdir/FuncDecl.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/stdir/FuncParam.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/stdir/FuncParam.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/stdir/FuncRet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/stdir/FuncRet.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/stdir/IRCode.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/stdir/IRCode.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/stdir/Jump.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/stdir/Jump.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/stdir/Label.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/stdir/Label.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/stdir/Printf.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/stdir/Printf.class -------------------------------------------------------------------------------- /out/production/BUAA-Compile-2021/frontend/stdir/Sym.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/out/production/BUAA-Compile-2021/frontend/stdir/Sym.class -------------------------------------------------------------------------------- /pic/Compiler.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/pic/Compiler.png -------------------------------------------------------------------------------- /pic/Compiler1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/pic/Compiler1.png -------------------------------------------------------------------------------- /pic/ExcNode_Visitor_SymbolTable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/pic/ExcNode_Visitor_SymbolTable.png -------------------------------------------------------------------------------- /pic/Lexer_Word.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/pic/Lexer_Word.png -------------------------------------------------------------------------------- /pic/Parser_ASTNode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/pic/Parser_ASTNode.png -------------------------------------------------------------------------------- /score/2021-12-09-16-24.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/score/2021-12-09-16-24.txt -------------------------------------------------------------------------------- /score/2021-12-09-16-26.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/score/2021-12-09-16-26.txt -------------------------------------------------------------------------------- /src/Compiler.java: -------------------------------------------------------------------------------- 1 | import backend.Backend; 2 | import frontend.Frontend; 3 | import frontend.IOtool; 4 | 5 | import java.io.IOException; 6 | 7 | public class Compiler { 8 | 9 | public static void main(String[] argv) throws IOException { 10 | /** 11 | * frontlevel: 12 | * 1-->lexer 13 | * 2-->lexer parser 14 | * 3-->lexer parser error-process 15 | * 4-->all frontend basic 16 | * 5-->all frontend basic and frontend optimizer 17 | */ 18 | int frontlevel = 4; 19 | Frontend frontend = new Frontend(frontlevel); 20 | /** 21 | * backlevel: 22 | * 0-->backend close 23 | * 1-->backend open 24 | * 2-->optimizer version backend 25 | */ 26 | int backlevel = 1; 27 | Backend backend = new Backend(frontend.getIrCodes(), backlevel, frontend.getCompileUnit()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: Compiler 3 | 4 | -------------------------------------------------------------------------------- /src/backend/Backend.java: -------------------------------------------------------------------------------- 1 | package backend; 2 | 3 | import backend.mips.IRTranslator; 4 | import frontend.IOtool; 5 | import frontend.irgen.IRGenerater; 6 | import frontend.irgen.optimize.CompileUnit; 7 | import frontend.stdir.IRCode; 8 | import frontend.stdir.Sym; 9 | 10 | import java.io.IOException; 11 | import java.util.ArrayList; 12 | import java.util.Arrays; 13 | 14 | public class Backend { 15 | 16 | private ArrayList irCodes; 17 | private CompileUnit compileUnit; 18 | 19 | public Backend(ArrayList irCodes, int level, CompileUnit compileUnit) throws IOException { 20 | if (level <= 0 || irCodes == null) return; 21 | if (level == 1) { 22 | this.irCodes = irCodes; 23 | IOtool iotool = new IOtool(); 24 | IRTranslator irTranslator = new IRTranslator(irCodes); 25 | iotool.output("mips.txt", irTranslator.getMipsout()); 26 | } else { 27 | this.irCodes = irCodes; 28 | IOtool iotool = new IOtool(); 29 | IR2Mips ir2Mips = new IR2Mips(compileUnit); 30 | iotool.output("mips.txt", ir2Mips.getMipsout()); 31 | } 32 | } 33 | 34 | private ArrayList splitByLine(String str) { 35 | return new ArrayList(Arrays.asList(str.split("\\n"))); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/backend/mips/Assign.java: -------------------------------------------------------------------------------- 1 | package backend.mips; 2 | 3 | public class Assign extends MipsCode { 4 | int type; //0 li 1 move 5 | Namespace sym1; 6 | Namespace sym2; 7 | int value; 8 | 9 | public Assign(Namespace sym1, int value) { 10 | this.sym1 = sym1; 11 | this.value = value; 12 | this.type = 0; 13 | } 14 | 15 | public Assign(Namespace sym1, Namespace sym2) { 16 | this.sym1 = sym1; 17 | this.sym2 = sym2; 18 | this.type = 1; 19 | if (sym2 != null && sym2.getType() == 1) { 20 | this.type = 0; 21 | this.value = sym2.getValue(); 22 | } 23 | } 24 | 25 | public Namespace getSym1() { 26 | return sym1; 27 | } 28 | 29 | public Namespace getSym2() { 30 | return sym2; 31 | } 32 | 33 | public int getValue() { 34 | return value; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | if (type == 0) { 40 | return String.format("li %s 0x%x\n", sym1, value); 41 | } else if (type == 1) { 42 | return String.format("move %s %s\n", sym1, sym2); 43 | } 44 | return ""; 45 | } 46 | 47 | public int getType() { 48 | return type; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/backend/mips/BrJump.java: -------------------------------------------------------------------------------- 1 | package backend.mips; 2 | 3 | public class BrJump extends MipsCode { 4 | Namespace reg1; 5 | Namespace reg2; 6 | Namespace label; 7 | String jbcode; 8 | int type; //0 j 1 b 9 | 10 | public BrJump(Namespace reg1, Namespace reg2, Namespace label, String jbcode) { 11 | this.reg1 = reg1; 12 | this.reg2 = reg2; 13 | this.label = label; 14 | this.jbcode = jbcode; 15 | this.type = 1; 16 | } 17 | 18 | public BrJump(Namespace label, String jbcode) { 19 | this.label = label; 20 | this.jbcode = jbcode; 21 | this.type = 0; 22 | } 23 | 24 | 25 | @Override 26 | public String toString() { 27 | if (type == 0) { 28 | return String.format("%s %s\n", jbcode, label); 29 | } else { 30 | return String.format("%s %s %s %s\n", jbcode, reg1, reg2, label); 31 | } 32 | } 33 | 34 | public Namespace getReg1() { 35 | return reg1; 36 | } 37 | 38 | public Namespace getReg2() { 39 | return reg2; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/backend/mips/LabelMipsCode.java: -------------------------------------------------------------------------------- 1 | package backend.mips; 2 | 3 | public class LabelMipsCode extends MipsCode { 4 | String label; 5 | 6 | public LabelMipsCode(String label) { 7 | this.label = label; 8 | } 9 | 10 | @Override 11 | public String toString() { 12 | return label; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/backend/mips/MTF.java: -------------------------------------------------------------------------------- 1 | package backend.mips; 2 | 3 | public class MTF extends MipsCode { 4 | Namespace reg; 5 | String type; //0 mthi 1 mtlo 2 mfhi 3 mflo 6 | 7 | public MTF(Namespace reg, String type) { 8 | this.reg = reg; 9 | this.type = type; 10 | } 11 | 12 | @Override 13 | public String toString() { 14 | return String.format("%s %s\n", type, reg); 15 | } 16 | 17 | public Namespace getReg() { 18 | return reg; 19 | } 20 | 21 | public String getType() { 22 | return type; 23 | } 24 | 25 | public int getTransType() { 26 | if (type.equals("mthi") || type.equals("mtlo")) return 0; 27 | else return 1; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/backend/mips/MipsCode.java: -------------------------------------------------------------------------------- 1 | package backend.mips; 2 | 3 | public abstract class MipsCode { 4 | @Override 5 | public boolean equals(Object obj) { 6 | return super.equals(obj); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/backend/mips/Namespace.java: -------------------------------------------------------------------------------- 1 | package backend.mips; 2 | 3 | import java.util.Objects; 4 | 5 | public class Namespace { 6 | int type; //0 reg 1 num 2 label 7 | int reg; 8 | int value; 9 | String label; 10 | 11 | /** 12 | * @param num 13 | * @param type 1-->number 0-->regNum 14 | */ 15 | public Namespace(int num, int type) { 16 | if (type == 0) { 17 | this.reg = num; 18 | } else { 19 | this.value = num; 20 | } 21 | this.type = type; 22 | } 23 | 24 | public Namespace(String label) { 25 | this.label = label; 26 | this.type = 2; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | if (type == 0) { 32 | return "$" + reg; 33 | } else if (type == 1) { 34 | return String.format("0x%x", value); 35 | } else if (type == 2) { 36 | return label; 37 | } 38 | return ""; 39 | } 40 | 41 | /** 42 | * @return 0:reg 1:value 43 | */ 44 | public int getType() { 45 | return type; 46 | } 47 | 48 | public int getReg() { 49 | return reg; 50 | } 51 | 52 | public int getValue() { 53 | return value; 54 | } 55 | 56 | public String getLabel() { 57 | return label; 58 | } 59 | 60 | @Override 61 | public boolean equals(Object o) { 62 | if (this == o) return true; 63 | if (o == null || getClass() != o.getClass()) return false; 64 | Namespace namespace = (Namespace) o; 65 | return type == namespace.type && reg == namespace.reg && value == namespace.value && Objects.equals(label, namespace.label); 66 | } 67 | 68 | @Override 69 | public int hashCode() { 70 | return Objects.hash(type, reg, value, label); 71 | } 72 | 73 | public boolean isGlobal() { 74 | return reg >= 16 && reg <= 23; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/backend/mips/StackManage.java: -------------------------------------------------------------------------------- 1 | package backend.mips; 2 | 3 | public class StackManage extends MipsCode { 4 | Namespace reg; 5 | int type; 6 | int offset; 7 | 8 | /** 9 | * @param reg 10 | * @param type 0:store to stack 1:load to reg 2:stack-=4 3:stack+=4 11 | */ 12 | public StackManage(Namespace reg, int type) { 13 | this.reg = reg; 14 | this.type = type; 15 | } 16 | 17 | public StackManage(int type) { 18 | this.type = type; 19 | } 20 | 21 | public StackManage(int type, int offset) { 22 | this.type = type; 23 | this.offset = offset; 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | if (type == 0) { 29 | return String.format("sw %s 0($sp)\n", reg); 30 | } else if (type == 1) { 31 | return String.format("lw %s 0($sp)\n", reg); 32 | } else if (type == 2) { 33 | return "subi $sp $sp 4\n"; 34 | } else if (type == 3) { 35 | return "addi $sp $sp 4\n"; 36 | } else if (type == 4) { 37 | return "subi $sp $sp " + offset + "\n"; 38 | } else if (type == 5) { 39 | return "addi $sp $sp " + offset + "\n"; 40 | } 41 | return null; 42 | } 43 | 44 | public Namespace getReg() { 45 | return reg; 46 | } 47 | 48 | public int getType() { 49 | return type; 50 | } 51 | 52 | public int getOffset() { 53 | return offset; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/backend/mips/Syscall.java: -------------------------------------------------------------------------------- 1 | package backend.mips; 2 | 3 | public class Syscall extends MipsCode { 4 | int type; //0 input 1 print int 2 print string 5 | Assign assign; 6 | 7 | public Syscall(int type) { 8 | this.type = type; 9 | } 10 | 11 | @Override 12 | public String toString() { 13 | StringBuilder res = new StringBuilder(""); 14 | if (type == 0) { 15 | assign = new Assign(new Namespace(2, 0), 5); 16 | res.append(assign); 17 | } else if (type == 1) { 18 | assign = new Assign(new Namespace(2, 0), 1); 19 | res.append(assign); 20 | } else if (type == 2) { 21 | assign = new Assign(new Namespace(2, 0), 4); 22 | res.append(assign); 23 | } else if (type == 3) { 24 | assign = new Assign(new Namespace(2, 0), 10); 25 | res.append(assign); 26 | } 27 | res.append("syscall\n"); 28 | return res.toString(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/frontend/Frontend.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | import frontend.irgen.IRGenerater; 4 | import frontend.irgen.Optimizer; 5 | import frontend.irgen.optimize.CompileUnit; 6 | import frontend.preprocess.Lexer; 7 | import frontend.preprocess.Parser; 8 | import frontend.preprocess.Visitor; 9 | import frontend.stdir.IRCode; 10 | 11 | import java.io.IOException; 12 | import java.util.ArrayList; 13 | 14 | public class Frontend { 15 | private ArrayList irCodes; 16 | private CompileUnit compileUnit; 17 | 18 | public Frontend(int level) throws IOException { 19 | /** 20 | * lexer analysis 21 | */ 22 | IOtool iOtool = new IOtool(); 23 | Lexer lexer = new Lexer(iOtool.getInput()); 24 | iOtool.outputAns(lexer.getLexerAns()); 25 | if (level <= 1) return; 26 | /** 27 | * Parser analysis 28 | */ 29 | Parser parser = new Parser(lexer.getWords()); 30 | iOtool.outputAns(parser.getParserAns()); 31 | if (level <= 2) return; 32 | /** 33 | * Error process 34 | */ 35 | Visitor visitor = new Visitor(parser.getAst(), parser.getExcNodes()); 36 | iOtool.outputError(visitor.getExcOutAns()); 37 | if (level <= 3) return; 38 | if (!visitor.getExcOutAns().equals("")) { 39 | System.out.println("Source code has wrong."); 40 | return; 41 | } 42 | /** 43 | *Intermediate code generate 44 | */ 45 | //Translater translater = new Translater(parser.getAst()); 46 | //iOtool.output("ircode", translater.getIROutput()); 47 | IRGenerater irGenerater = new IRGenerater(parser.getAst()); 48 | this.irCodes = irGenerater.getIrcodes(); 49 | outputIrcodes("ircode0.txt"); 50 | // iOtool.output("ircode.txt", irGenerater.getIroutput()); 51 | if (level <= 4) return; 52 | Optimizer optimizer = new Optimizer(this.irCodes, irGenerater.getRegNum()); 53 | irCodes = optimizer.getIrCodes(); 54 | outputIrcodes("ircode.txt"); 55 | compileUnit = optimizer.getCompileUnit(); 56 | } 57 | 58 | public ArrayList getIrCodes() { 59 | return irCodes; 60 | } 61 | 62 | void outputIrcodes(String name) { 63 | StringBuilder sb = new StringBuilder(""); 64 | for (IRCode irCode : irCodes) { 65 | sb.append(irCode.toString()); 66 | } 67 | IOtool.output(name, sb.toString()); 68 | } 69 | 70 | public CompileUnit getCompileUnit() { 71 | return compileUnit; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/frontend/IOtool.java: -------------------------------------------------------------------------------- 1 | package frontend; 2 | 3 | import java.io.*; 4 | import java.nio.charset.StandardCharsets; 5 | 6 | public class IOtool { 7 | public IOtool() { 8 | } 9 | 10 | public static String getInput() throws IOException { 11 | InputStream in = new FileInputStream("testfile.txt"); 12 | InputStreamReader reader = new InputStreamReader(in, StandardCharsets.UTF_8); 13 | StringBuilder sb = new StringBuilder(); 14 | while (reader.ready()) { 15 | sb.append((char) reader.read()); 16 | } 17 | reader.close(); 18 | in.close(); 19 | return sb.toString(); 20 | } 21 | 22 | public static String getInput(String file) throws IOException { 23 | InputStream in = new FileInputStream(file); 24 | InputStreamReader reader = new InputStreamReader(in, StandardCharsets.UTF_8); 25 | StringBuilder sb = new StringBuilder(); 26 | while (reader.ready()) { 27 | sb.append((char) reader.read()); 28 | } 29 | reader.close(); 30 | in.close(); 31 | return sb.toString(); 32 | } 33 | 34 | public static void outputAns(String outAns) throws IOException { 35 | OutputStream out = new FileOutputStream("output.txt"); 36 | OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8); 37 | outAns = outAns.trim(); 38 | writer.append(outAns); 39 | writer.close(); 40 | } 41 | 42 | public static void output(String name, String outAns) { 43 | String filename = name; 44 | OutputStream out = null; 45 | try { 46 | out = new FileOutputStream(filename); 47 | OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8); 48 | outAns = outAns.trim(); 49 | writer.append(outAns); 50 | writer.close(); 51 | } catch (FileNotFoundException e) { 52 | e.printStackTrace(); 53 | } catch (IOException e) { 54 | e.printStackTrace(); 55 | } 56 | } 57 | 58 | public void outputError(String outError) throws IOException { 59 | OutputStream out = new FileOutputStream("error.txt"); 60 | OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8); 61 | outError = outError.trim(); 62 | writer.append(outError); 63 | writer.close(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/frontend/irgen/Optimizer.java: -------------------------------------------------------------------------------- 1 | package frontend.irgen; 2 | 3 | import frontend.IOtool; 4 | import frontend.irgen.optimize.*; 5 | import frontend.stdir.IRCode; 6 | 7 | import java.util.ArrayList; 8 | 9 | public class Optimizer { 10 | ArrayList irCodes; 11 | int tmpnum; 12 | CompileUnit compileUnit; 13 | 14 | public Optimizer(ArrayList inirCodes, int tmpnum) { 15 | irCodes = inirCodes; 16 | Flatter flatter = new Flatter(irCodes); 17 | irCodes = flatter.getIrCodes(); 18 | Divoptimizer divoptimizer = new Divoptimizer(irCodes, tmpnum); 19 | irCodes = divoptimizer.getIrCodes(); 20 | outputIrcodes(); 21 | compileUnit = new CompileUnit(irCodes); 22 | IOtool.output("compileunit.txt", compileUnit.toString()); 23 | irCodes = compileUnit.getIrCodes(); 24 | //outputIrcodes(); 25 | this.tmpnum = tmpnum; 26 | } 27 | 28 | public ArrayList getIrCodes() { 29 | return irCodes; 30 | } 31 | 32 | void outputIrcodes() { 33 | StringBuilder sb = new StringBuilder(""); 34 | for (IRCode irCode : irCodes) { 35 | sb.append(irCode.toString()); 36 | } 37 | IOtool.output("ircode_optimizer.txt", sb.toString()); 38 | } 39 | 40 | public CompileUnit getCompileUnit() { 41 | return compileUnit; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/frontend/irgen/optimize/HoleOptimizer.java: -------------------------------------------------------------------------------- 1 | package frontend.irgen.optimize; 2 | 3 | import frontend.stdir.IRCode; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class HoleOptimizer { 8 | ArrayList irCodes; 9 | 10 | public HoleOptimizer(ArrayList irCodes) { 11 | this.irCodes = irCodes; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/frontend/irgen/symtable/Block.java: -------------------------------------------------------------------------------- 1 | package frontend.irgen.symtable; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Block extends SymTable { 6 | private ArrayList symTables; 7 | private String name; 8 | 9 | public Block(String name) { 10 | this.name = name; 11 | this.symTables = new ArrayList<>(); 12 | } 13 | 14 | public void addSym(SymTable symTable) { 15 | symTables.add(symTable); 16 | } 17 | 18 | public SymTable findFunc(String name) { 19 | for (SymTable symTable : symTables) { 20 | if (symTable instanceof Func && symTable.getName().equals(name)) { 21 | return symTable; 22 | } 23 | } 24 | return null; 25 | } 26 | 27 | public SymTable findVar(String name) { 28 | for (SymTable symTable : symTables) { 29 | if (symTable instanceof Var && symTable.getName().equals(name)) { 30 | return symTable; 31 | } 32 | } 33 | return null; 34 | } 35 | 36 | public SymTable findVar1(String name) { 37 | if (true) 38 | return findVar(name); 39 | for (SymTable symTable : symTables) { 40 | if (symTable instanceof Var && ((symTable.getName() + ((Var) symTable).getLevel()).equals(name) || (symTable.getName().equals(name)))) { 41 | return symTable; 42 | } 43 | } 44 | return null; 45 | } 46 | 47 | @Override 48 | public String getName() { 49 | return name; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/frontend/irgen/symtable/Func.java: -------------------------------------------------------------------------------- 1 | package frontend.irgen.symtable; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Func extends SymTable { 6 | private String name; 7 | private ArrayList params; 8 | private String type; //void int 9 | private int addr; 10 | 11 | public Func(String name, ArrayList params, String type) { 12 | this.name = name; 13 | this.params = params; 14 | this.type = type; 15 | } 16 | 17 | @Override 18 | public String getName() { 19 | return name; 20 | } 21 | 22 | public String getType() { 23 | return type; 24 | } 25 | 26 | public void setAddr(int addr) { 27 | this.addr = addr; 28 | } 29 | 30 | public int getAddr() { 31 | return addr; 32 | } 33 | 34 | public ArrayList getParams() { 35 | return params; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/frontend/irgen/symtable/SymTable.java: -------------------------------------------------------------------------------- 1 | package frontend.irgen.symtable; 2 | 3 | public abstract class SymTable { 4 | public abstract String getName(); 5 | } 6 | -------------------------------------------------------------------------------- /src/frontend/preprocess/ExcNode.java: -------------------------------------------------------------------------------- 1 | package frontend.preprocess; 2 | 3 | public class ExcNode { 4 | private int line; 5 | 6 | public int getLine() { 7 | return line; 8 | } 9 | 10 | public String getExccode() { 11 | return exccode; 12 | } 13 | 14 | public String getInfo() { 15 | return info; 16 | } 17 | 18 | private String exccode; 19 | private String info; 20 | 21 | public ExcNode(int line, String exccode, String info) { 22 | this.line = line; 23 | this.exccode = exccode; 24 | this.info = info; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/frontend/preprocess/Word.java: -------------------------------------------------------------------------------- 1 | package frontend.preprocess; 2 | 3 | public class Word { 4 | private String typeCode; 5 | private String content; 6 | private int line; 7 | 8 | public Word(String typeCode, String content, int line) { 9 | this.typeCode = typeCode; 10 | this.content = content; 11 | this.line = line; 12 | } 13 | 14 | public String getTypeCode() { 15 | return typeCode; 16 | } 17 | 18 | public String getContent() { 19 | return content; 20 | } 21 | 22 | public int getLine() { 23 | return line; 24 | } 25 | 26 | public String getOutPut() { 27 | return typeCode + " " + content + "\n"; 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return "Word{" + 33 | "typeCode='" + typeCode + '\'' + 34 | ", content='" + content + '\'' + 35 | ", line=" + line + 36 | '}'; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/frontend/stdir/ArrayDecl.java: -------------------------------------------------------------------------------- 1 | package frontend.stdir; 2 | 3 | import frontend.irgen.symtable.Var; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class ArrayDecl extends IRCode { 8 | Sym sym; 9 | ArrayList lenval; 10 | ArrayList arrayval; 11 | Boolean hasInitVal; 12 | 13 | public ArrayDecl(Sym sym, ArrayList arrayval, ArrayList lenval, Boolean hasInitVal) { 14 | this.sym = sym; 15 | this.arrayval = arrayval; 16 | this.lenval = lenval; 17 | this.hasInitVal = hasInitVal; 18 | } 19 | 20 | private String arraydecl() { 21 | StringBuilder res = new StringBuilder(""); 22 | res.append(sym); 23 | for (int i = 0; i < lenval.size(); i++) { 24 | res.append("[" + lenval.get(i) + "]"); 25 | } 26 | return res.toString(); 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | StringBuilder res = new StringBuilder(""); 32 | if (((Var) sym.getSymbol()).isIsconst()) res.append("const "); 33 | if (hasInitVal) { 34 | if (arrayval.size() == 0) { 35 | res.append(String.format("arr int %s\n", arraydecl())); 36 | } else { 37 | res.append(String.format("arr int %s\n", ((Var) sym.getSymbol()).toString1())); 38 | for (int i = 0; i < arrayval.size(); i++) { 39 | res.append(String.format("%s[%d] = %s\n", sym, i, arrayval.get(i))); 40 | } 41 | } 42 | } else { 43 | if (arrayval.size() == 0) { 44 | res.append(String.format("arr int %s\n", arraydecl())); 45 | } else { 46 | res.append(String.format("arr int %s\n", ((Var) sym.getSymbol()).toString1())); 47 | } 48 | } 49 | return res.toString(); 50 | } 51 | 52 | public Sym getSym() { 53 | return sym; 54 | } 55 | 56 | public Sym getSym1() { 57 | return new Sym(sym.toString(), true); 58 | } 59 | 60 | public ArrayList getArrayval() { 61 | return arrayval; 62 | } 63 | 64 | public ArrayList getLenval() { 65 | return lenval; 66 | } 67 | 68 | public int getSpace() { 69 | if (lenval.size() == 1) { 70 | return lenval.get(0).getValue() * 4; 71 | } else { 72 | return lenval.get(1).getValue() * lenval.get(0).getValue() * 4; 73 | } 74 | } 75 | 76 | public Boolean getHasInitVal() { 77 | return hasInitVal; 78 | } 79 | 80 | public void setArrayval(ArrayList arrayval) { 81 | this.arrayval = arrayval; 82 | } 83 | 84 | public void setHasInitVal(Boolean hasInitVal) { 85 | this.hasInitVal = hasInitVal; 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/frontend/stdir/CondBranch.java: -------------------------------------------------------------------------------- 1 | package frontend.stdir; 2 | 3 | public class CondBranch extends IRCode { 4 | Sym cmpa; 5 | Sym cmpb; 6 | String type; 7 | Label label; 8 | 9 | public CondBranch(Sym cmpa, Sym cmpb, String type, Label label) { 10 | this.cmpa = cmpa; 11 | this.cmpb = cmpb; 12 | this.type = type; 13 | this.label = label; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | return String.format("cmp %s, %s\n%s %s\n", cmpa, cmpb, type, label.getName()); 19 | } 20 | 21 | public String getType() { 22 | return type; 23 | } 24 | 25 | public Sym getCmpa() { 26 | return cmpa; 27 | } 28 | 29 | public Sym getCmpb() { 30 | return cmpb; 31 | } 32 | 33 | public Label getLabel() { 34 | return label; 35 | } 36 | 37 | public void setLabel(Label label) { 38 | this.label = label; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/frontend/stdir/Decl.java: -------------------------------------------------------------------------------- 1 | package frontend.stdir; 2 | 3 | public class Decl extends IRCode { 4 | private Sym sym; 5 | private Sym rsym; 6 | 7 | public Decl(Sym sym, Sym rsym) { 8 | this.sym = sym; 9 | this.rsym = rsym; 10 | } 11 | 12 | public Sym getRsym() { 13 | return rsym; 14 | } 15 | 16 | public Sym getSym() { 17 | return sym; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | if (sym.isconst()) { 23 | return String.format("const int %s = %s\n", sym, rsym); 24 | } 25 | return String.format("var int %s = %s\n", sym, rsym); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/frontend/stdir/Exp.java: -------------------------------------------------------------------------------- 1 | package frontend.stdir; 2 | 3 | public class Exp extends IRCode { 4 | String op; 5 | Sym lsym; 6 | Sym rsym1; 7 | Sym rsym2; 8 | 9 | public Exp(String op, Sym lsym, Sym rsym1, Sym rsym2) { 10 | this.op = op; 11 | this.lsym = lsym; 12 | this.rsym1 = rsym1; 13 | this.rsym2 = rsym2; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | if (op.equals("=")) { 19 | return String.format("%s = %s\n", lsym, rsym1); 20 | } 21 | return String.format("%s = %s %s %s\n", lsym, rsym1, op, rsym2); 22 | } 23 | 24 | public Sym getLsym() { 25 | return lsym; 26 | } 27 | 28 | public Sym getRsym1() { 29 | return rsym1; 30 | } 31 | 32 | public Sym getRsym2() { 33 | return rsym2; 34 | } 35 | 36 | public String getOp() { 37 | return op; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/frontend/stdir/FuncCall.java: -------------------------------------------------------------------------------- 1 | package frontend.stdir; 2 | 3 | import frontend.irgen.symtable.Func; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class FuncCall extends IRCode { 8 | private Sym lsym; 9 | private Func func; 10 | private ArrayList params; 11 | 12 | public FuncCall(Sym lsym, Func func, ArrayList params) { 13 | this.lsym = lsym; 14 | this.func = func; 15 | this.params = params; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | StringBuilder res = new StringBuilder(""); 21 | for (Sym sym : params) { 22 | res.append("push " + sym + "\n"); 23 | } 24 | res.append("call " + func.getName() + "\n"); 25 | if (func.getType().equals("int")) res.append(lsym + " = RET\n"); 26 | return res.toString(); 27 | } 28 | 29 | public Sym getLsym() { 30 | return lsym; 31 | } 32 | 33 | public Func getFunc() { 34 | return func; 35 | } 36 | 37 | public ArrayList getParams() { 38 | return params; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/frontend/stdir/FuncDecl.java: -------------------------------------------------------------------------------- 1 | package frontend.stdir; 2 | 3 | import frontend.irgen.symtable.Func; 4 | import frontend.irgen.symtable.SymTable; 5 | 6 | import java.util.ArrayList; 7 | 8 | public class FuncDecl extends IRCode { 9 | private Func func; //function sym 10 | private int type; //0 void 1 int 11 | 12 | public FuncDecl(Func func, int type) { 13 | this.func = func; 14 | this.type = type; 15 | } 16 | 17 | @Override 18 | public String toString() { 19 | StringBuilder res = new StringBuilder(""); 20 | res.append(type == 0 ? "void " : "int "); 21 | res.append(func.getName() + "()\n"); 22 | return res.toString(); 23 | } 24 | 25 | public Func getFunc() { 26 | return func; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/frontend/stdir/FuncParam.java: -------------------------------------------------------------------------------- 1 | package frontend.stdir; 2 | 3 | public class FuncParam extends IRCode { 4 | private Sym sym; 5 | 6 | public FuncParam(Sym sym) { 7 | this.sym = sym; 8 | } 9 | 10 | public String getType() { 11 | return sym.getTypeOut(); 12 | } 13 | 14 | public Sym getSym() { 15 | return new Sym(sym.toString(), true); 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return String.format("para %s %s\n", sym.getTypeOut(), sym); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/frontend/stdir/FuncRet.java: -------------------------------------------------------------------------------- 1 | package frontend.stdir; 2 | 3 | public class FuncRet extends IRCode { 4 | Sym sym; 5 | 6 | public FuncRet(Sym sym) { 7 | this.sym = sym; 8 | } 9 | 10 | @Override 11 | public String toString() { 12 | if (sym == null) return "ret\n"; 13 | return "ret " + sym + "\n"; 14 | } 15 | 16 | public Sym getSym() { 17 | return sym; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/frontend/stdir/IRCode.java: -------------------------------------------------------------------------------- 1 | package frontend.stdir; 2 | 3 | public abstract class IRCode { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/frontend/stdir/Jump.java: -------------------------------------------------------------------------------- 1 | package frontend.stdir; 2 | 3 | public class Jump extends IRCode { 4 | Label label; 5 | 6 | public Jump(Label label) { 7 | this.label = label; 8 | } 9 | 10 | @Override 11 | public String toString() { 12 | return String.format("goto %s\n", label.getName()); 13 | } 14 | 15 | public Label getLabel() { 16 | return label; 17 | } 18 | 19 | public void setLabel(Label label) { 20 | this.label = label; 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /src/frontend/stdir/Label.java: -------------------------------------------------------------------------------- 1 | package frontend.stdir; 2 | 3 | import java.util.Objects; 4 | 5 | public class Label extends IRCode { 6 | private String name; 7 | 8 | public Label(String name) { 9 | this.name = name; 10 | } 11 | 12 | @Override 13 | public String toString() { 14 | return name + ":\n"; 15 | } 16 | 17 | public String getName() { 18 | return name; 19 | } 20 | 21 | @Override 22 | public boolean equals(Object o) { 23 | if (this == o) return true; 24 | if (o == null || getClass() != o.getClass()) return false; 25 | Label label = (Label) o; 26 | return Objects.equals(name, label.name); 27 | } 28 | 29 | @Override 30 | public int hashCode() { 31 | return Objects.hash(name); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/frontend/stdir/Printf.java: -------------------------------------------------------------------------------- 1 | package frontend.stdir; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Printf extends IRCode { 6 | ArrayList syms; 7 | Sym sym; 8 | 9 | public Printf(ArrayList syms, Sym sym) { 10 | this.syms = syms; 11 | this.sym = sym; 12 | } 13 | 14 | private String syms2str() { 15 | StringBuilder res = new StringBuilder(""); 16 | for (int i = 0; i < syms.size(); i++) { 17 | res.append(syms.get(i)); 18 | if (i != syms.size() - 1) res.append("-"); 19 | } 20 | return res.toString(); 21 | } 22 | 23 | @Override 24 | public String toString() { 25 | if (syms.size() > 0) { 26 | return String.format("printf %s %s\n", sym, syms2str()); 27 | } 28 | return String.format("printf %s\n", sym); 29 | } 30 | 31 | public Sym getSym() { 32 | return sym; 33 | } 34 | 35 | public ArrayList getSyms() { 36 | return syms; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/A/input10.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 -------------------------------------------------------------------------------- /test/A/input11.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 2 3 | 1 -------------------------------------------------------------------------------- /test/A/input12.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/test/A/input12.txt -------------------------------------------------------------------------------- /test/A/input13.txt: -------------------------------------------------------------------------------- 1 | 123 2 | 456 3 | 12 4 | 324 -------------------------------------------------------------------------------- /test/A/input14.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 0 3 | 1 4 | 6 5 | 8 6 | 20 7 | 30 8 | -------------------------------------------------------------------------------- /test/A/input15.txt: -------------------------------------------------------------------------------- 1 | 200 2 | -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/A/input17.txt: -------------------------------------------------------------------------------- 1 | 33 2 | 28 3 | 501 4 | 233 5 | 114 6 | 711 7 | 266 8 | 500 9 | 77 -------------------------------------------------------------------------------- /test/A/input18.txt: -------------------------------------------------------------------------------- 1 | 9 2 | 8 3 | 7 4 | 6 5 | 5 6 | 4 7 | 3 8 | 2 9 | 1 10 | -------------------------------------------------------------------------------- /test/A/input19.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/A/input20.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 1 -------------------------------------------------------------------------------- /test/A/input21.txt: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /test/A/input22.txt: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /test/A/input23.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 -------------------------------------------------------------------------------- /test/A/input24.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 3 4 | -------------------------------------------------------------------------------- /test/A/input25.txt: -------------------------------------------------------------------------------- 1 | 24 2 | 27 3 | 342526 4 | -------------------------------------------------------------------------------- /test/A/input26.txt: -------------------------------------------------------------------------------- 1 | 3 -------------------------------------------------------------------------------- /test/A/input3.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /test/A/input4.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/test/A/input4.txt -------------------------------------------------------------------------------- /test/A/input5.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/test/A/input5.txt -------------------------------------------------------------------------------- /test/A/input6.txt: -------------------------------------------------------------------------------- 1 | 4 -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/A/input8.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 -------------------------------------------------------------------------------- /test/A/input9.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 12 -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/A/output11.txt: -------------------------------------------------------------------------------- 1 | 19182620 2 | 0 3 | 1 4 | 2 5 | 2 6 | 1 7 | 2 8 | 19182620 9 | 19182620 10 | 19182620 11 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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!!! -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/A/output26.txt: -------------------------------------------------------------------------------- 1 | 19373630 2 | 1 3 | 120 4 | 720 5 | 5040 6 | 1 7 | 2 8 | 4 9 | 3 10 | 30250 11 | -------------------------------------------------------------------------------- /test/A/output3.txt: -------------------------------------------------------------------------------- 1 | 19373734 2 | 19373734 3 | 19373734 4 | 19373734 5 | 19373734 6 | 19373734 7 | 19373734 8 | 19373734 9 | 19373734 10 | 19373734 -------------------------------------------------------------------------------- /test/A/output4.txt: -------------------------------------------------------------------------------- 1 | 19231258 OK1 2 | OK2 3 | OK3 4 | OK4 5 | OK5 6 | OK6 7 | OK7 8 | OK8 9 | OK9 -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/A/output7.txt: -------------------------------------------------------------------------------- 1 | 19182604 2 | 0 3 | 1 4 | 2 5 | 3 6 | 4 7 | 5 8 | 6 9 | 7 10 | 8 11 | -------------------------------------------------------------------------------- /test/A/output8.txt: -------------------------------------------------------------------------------- 1 | 19182619 2 | CscanfOK 3 | DscanfOK 4 | sb:2 5 | continueOK 6 | breakOK 7 | 0Func2OK 8 | Func3OK 9 | Func4OK 10 | end -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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] down) { 63 | int p; 64 | p = getint(); 65 | int ret = power(p, res); 66 | printf("/* input = %d */\n", p); 67 | if (ret && error()) { 68 | n = n - 1; 69 | continue; 70 | } 71 | if (ret || out(res)) { 72 | int i = 0; 73 | while (i < 6 || 1) { 74 | __vec_mul(tmp, res, vec_list[i]); 75 | printf("when a[0] = %d, a[1] = %d ==> a[%d] = %d\n", vec_list[i][1], vec_list[i][0], p, tmp[1]); 76 | i = i + 1; 77 | if (i >= 6) break; 78 | else continue; 79 | } 80 | } 81 | printf("//////////////////////////////////////\n"); 82 | n = -+-+-(1 - n); 83 | } 84 | printf("/****************** END ******************/\n"); 85 | printf("");printf(""); 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /test/A/testfile16.txt: -------------------------------------------------------------------------------- 1 | const int Mod = 10007; 2 | 3 | const int dx[2] = {1, 0}; 4 | const int dy[2] = {0, 1}; 5 | 6 | const int Map[5][5] = { 7 | {0, 1, 0, 1, 0}, 8 | {0, 1, 1, 1, 1}, 9 | {1, 1, 1, 1, 1}, 10 | {1, 0, 1, 0, 1}, 11 | {1, 1, 1, 0, 1} 12 | }; 13 | 14 | 15 | int strP[2]; 16 | int ans, base; 17 | int val[5][5]; 18 | 19 | int CalcMod(int x) { 20 | return x - x / Mod * Mod; 21 | } 22 | 23 | int Check(int y) { 24 | if (y >= 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 | } -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/A/testfile22.txt: -------------------------------------------------------------------------------- 1 | int val_L = 0; 2 | const int const_a = +1 - 2 + (-3)*4 + 5/(2+3) - 6 % 4, const_b =((5-10)*(-4) + 4)/6 * (3%6/3); 3 | const int const_array1_a[2] = {1, 1}; 4 | const int const_array2_a[2][2] = { {1, 1}, {1, 1} }, const_array2_b[2][2] = { {1, 1}, {1, 1} }; 5 | int var_array1_a[2] = {0, 0}; 6 | int var_array2_a[2][2] = { {1, 1}, {1, 1} }; 7 | 8 | void check_LandEq() { 9 | val_L = 0; 10 | if (!0) { 11 | val_L = val_L + 1; 12 | } 13 | if ((!0) || 0) { 14 | val_L = val_L + 1; 15 | } 16 | if ((!0) && 1) { 17 | val_L = val_L + 1; 18 | } 19 | if (1 != 0) { 20 | val_L = val_L + 1; 21 | } 22 | if (val_L == 4) { 23 | printf("L and Eq is ok (no params)\n"); 24 | } else { 25 | printf("sth wrong with L and Eq (no params)\n"); 26 | } 27 | } 28 | 29 | int check_Rel(int a, int b, int c) { 30 | int val_Rel = 0; 31 | if (a >= 1 && a <= 2) { 32 | val_Rel = val_Rel + 1; 33 | } 34 | if (1 < b && b > 2) { 35 | val_Rel = val_Rel + 1; 36 | } 37 | if (c == 2 && c != 3) { 38 | val_Rel = val_Rel + 1; 39 | } 40 | return val_Rel; 41 | } 42 | 43 | void check_Add(int x) { 44 | if (const_a == x && const_b == 4) { //x == -14 45 | printf("Add is ok\n"); 46 | } else { 47 | printf("sth wrong with Add (no params)\n"); 48 | } 49 | } 50 | 51 | void check_block(int a2, int b2[], int c2[][2], int c3[]) { 52 | int tmp0 = -1; 53 | int tmp1 = 1; 54 | if( a2 > 0 ) { 55 | while(tmp1 > 0) { 56 | tmp1 = tmp1 - 2; 57 | if (b2[1] == 0) { 58 | break; 59 | } 60 | tmp1 = tmp1 - 2; 61 | } 62 | } else { 63 | while(tmp0 < 0) { 64 | tmp0 = tmp0 + 2; 65 | if (c2[1][1] == 1) { 66 | continue; 67 | } 68 | tmp0 = tmp0 + 2; 69 | } 70 | } 71 | { 72 | 73 | } 74 | ; 75 | printf("%d\n",tmp0); 76 | printf("%d\n",tmp1); 77 | return; 78 | } 79 | 80 | 81 | int main() { 82 | int a, val_Rel; 83 | printf("19373408 all weak points\n"); 84 | check_LandEq(); 85 | val_Rel = check_Rel(1, 6, 2); 86 | if (val_Rel == 3) { 87 | printf("Rel is ok (with params)\n"); 88 | } else { 89 | printf("sth wrong with Rel (no params)\n"); 90 | } 91 | check_Add(-14); 92 | a = getint();//1 93 | if (a == 1) { 94 | printf("getint is ok\n"); 95 | } 96 | check_block(a, var_array1_a, var_array2_a, var_array2_a[0]); 97 | check_block(-1, var_array1_a, var_array2_a, var_array2_a[0]); 98 | return 0; 99 | } -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/A/testfile5.txt: -------------------------------------------------------------------------------- 1 | // #include 2 | 3 | /* 4 | * check for LevelA: logic expression 5 | */ 6 | 7 | int global_array[10]; 8 | 9 | int addIndex(int i, int array[]) { 10 | array[i] = array[i] + 1; 11 | return 1; 12 | } 13 | 14 | int main() { 15 | int a0 = 0; 16 | int a1 = 1; 17 | 18 | // && 19 | if (!a0 && a1) 20 | global_array[1] = 1; 21 | if (a0 && a1) 22 | global_array[2] = -1; 23 | else 24 | global_array[2] = 2; 25 | if (!a1 && a0) 26 | global_array[3] = -1; 27 | else 28 | global_array[3] = 3; 29 | int i = 1; 30 | while (i < 5 && i > 0) { 31 | i = i * 2; 32 | } 33 | if (i >= 5) { 34 | global_array[4] = 4; 35 | } else { 36 | global_array[4] = -1; 37 | } 38 | 39 | // || 40 | if (a0 || a1) { 41 | global_array[5] = 5; 42 | } else { 43 | global_array[5] = -1; 44 | } 45 | if (a0 || !a1) { 46 | global_array[6] = -1; 47 | } else 48 | global_array[6] = 6; 49 | while (6 < 3 || 4 <= 7){ 50 | global_array[7] = 7; 51 | break; 52 | } 53 | if (global_array[7] != 7) { 54 | global_array[7] = -1; 55 | } 56 | 57 | // short-circuit 58 | int tool[2] = {0, 0}; 59 | if (0 && addIndex(0, tool)) 60 | ; 61 | if (tool[0]) { 62 | global_array[8] = -1; 63 | } else 64 | global_array[8] = 8; 65 | if (1 || addIndex(1, tool)) 66 | ; 67 | if (tool[1]) 68 | global_array[9] = -1; 69 | else 70 | global_array[9] = 9; 71 | 72 | // check 73 | printf("19231011\n"); 74 | printf("start checking for logic expressions\n"); 75 | i = 0; 76 | while (i < 5 && global_array[i] == i) { 77 | i = i + 1; 78 | } 79 | if (i == 5) { 80 | printf("check for AND calculation: successfully!\n"); 81 | } else { 82 | printf("check for AND calculation: something wrong!\n"); 83 | } 84 | 85 | i = 5; 86 | while (i < 8 && global_array[i] == i) { 87 | i = i + 1; 88 | } 89 | if (i == 8) { 90 | printf("check for OR calculation: successfully!\n"); 91 | } else { 92 | printf("check for OR calculation: something wrong!\n"); 93 | } 94 | 95 | i = 8; 96 | while (i < 10 && global_array[i] == i) { 97 | i = i + 1; 98 | } 99 | if (i == 10) { 100 | printf("check for short-circuit calculation: successfully!\n"); 101 | } else { 102 | printf("check for short-circuit calculation: something wrong!\n"); 103 | } 104 | 105 | printf("end checking\n"); 106 | 107 | return 0; 108 | } -------------------------------------------------------------------------------- /test/A/testfile6.txt: -------------------------------------------------------------------------------- 1 | const int sb = 250; 2 | const int mmm = 2, nnn = 3, jjj = 4, kkk = 2 * 3; 3 | const int arr1[1] = {5}, arr2[2][2] = {{1, 2}, 4 | {4, 5}}; 5 | 6 | int funcExp(int a, int b) { 7 | int c, d; 8 | if (a == b) { 9 | c = a; 10 | } 11 | if (a != b) { 12 | a = c; 13 | } 14 | if (a == b || c == b) { 15 | c = a; 16 | } 17 | if (a == b && c == b) { 18 | a = c; 19 | } 20 | if (a == c && a == b || a == 0) { 21 | c = 2; 22 | } 23 | if (a < b) { 24 | a = 1; 25 | } 26 | if (a > b) { 27 | b = 1; 28 | } 29 | if (a <= c) { 30 | a = 2; 31 | } 32 | if (a >= c) { 33 | c = 2; 34 | } 35 | c = a + b; 36 | c = a / b; 37 | c = a - b; 38 | c = a % b; 39 | c = a * b; 40 | c = a; 41 | c = +a; 42 | c = -a; 43 | return c; 44 | } 45 | 46 | int func0() { 47 | return 1; 48 | } 49 | 50 | int func1(int a) { 51 | return a + 1; 52 | } 53 | 54 | int func2(int a, int b) { 55 | return a + b; 56 | } 57 | 58 | void func3() { 59 | 60 | } 61 | 62 | void fun4() { 63 | return; 64 | } 65 | 66 | int func5(int a[], int b[][2]) { 67 | return a[0] * b[1][1]; 68 | } 69 | 70 | int main() { 71 | int a; 72 | int a1[3] = {0, 1, 2}; 73 | int a2[2][2] = {{2, 2}, 74 | {2, 2}}; 75 | int a3[1] = {0}; 76 | int a4[1][1] = {{0}}; 77 | if (func0()) { ; 78 | 3 * 3; 79 | } 80 | a3[0] = 1; 81 | a4[0][0] = 1; 82 | a = func5(a1, a2); 83 | a = func1(a3[0]); 84 | a = getint(); 85 | int arr3[3]; 86 | int arr[3] = {0, 2, 4}; 87 | printf("19231248"); 88 | if (a == 4) { 89 | a = 5; 90 | } else { 91 | a = 6; 92 | } 93 | while (a < 8) { 94 | a = a + 1; 95 | if (a > 6) { 96 | break; 97 | } else { 98 | continue; 99 | } 100 | } 101 | if (!1) { 102 | a = sb; 103 | } 104 | a = func1(a); 105 | a = func2(a, a); 106 | int b = sb + mmm; 107 | a = b * sb; 108 | a = b / sb; 109 | a = sb % b; 110 | a = +sb; 111 | a = -sb; 112 | a = (+sb); 113 | a = (-sb); 114 | printf("%d\n",a); 115 | printf("19231248\n"); 116 | printf("19231248\n"); 117 | printf("19231248\n"); 118 | printf("19231248\n"); 119 | printf("19231248\n"); 120 | printf("19231248\n"); 121 | printf("19231248\n"); 122 | printf("19231248\n"); 123 | printf("19231248\n"); 124 | return 0; 125 | } -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/B/input1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/test/B/input1.txt -------------------------------------------------------------------------------- /test/B/input10.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 4 4 | 5 -------------------------------------------------------------------------------- /test/B/input11.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 2 3 | 3 4 | 1 5 | 0 -------------------------------------------------------------------------------- /test/B/input12.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/test/B/input12.txt -------------------------------------------------------------------------------- /test/B/input13.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 4 3 | -------------------------------------------------------------------------------- /test/B/input14.txt: -------------------------------------------------------------------------------- 1 | 1150 -------------------------------------------------------------------------------- /test/B/input15.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 4 4 | 5 -------------------------------------------------------------------------------- /test/B/input16.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/test/B/input16.txt -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/B/input18.txt: -------------------------------------------------------------------------------- 1 | 123 2 | 0 3 | -234 -------------------------------------------------------------------------------- /test/B/input19.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /test/B/input2.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 2 3 | -------------------------------------------------------------------------------- /test/B/input20.txt: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /test/B/input21.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/test/B/input21.txt -------------------------------------------------------------------------------- /test/B/input22.txt: -------------------------------------------------------------------------------- 1 | 11 -------------------------------------------------------------------------------- /test/B/input23.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 9 -------------------------------------------------------------------------------- /test/B/input24.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/test/B/input24.txt -------------------------------------------------------------------------------- /test/B/input25.txt: -------------------------------------------------------------------------------- 1 | 23 2 | 26 3 | 353 4 | -------------------------------------------------------------------------------- /test/B/input26.txt: -------------------------------------------------------------------------------- 1 | 13 2 | 29 3 | 37 4 | -------------------------------------------------------------------------------- /test/B/input27.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /test/B/input3.txt: -------------------------------------------------------------------------------- 1 | 9 2 | 8 3 | 7 4 | 6 5 | -------------------------------------------------------------------------------- /test/B/input4.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/test/B/input4.txt -------------------------------------------------------------------------------- /test/B/input5.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 20 3 | 30 -------------------------------------------------------------------------------- /test/B/input6.txt: -------------------------------------------------------------------------------- 1 | 12308760 2 | -------------------------------------------------------------------------------- /test/B/input7.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /test/B/input8.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 8 3 | 7 4 | 6 5 | 5 6 | 4 7 | 3 8 | 2 9 | 1 10 | -------------------------------------------------------------------------------- /test/B/input9.txt: -------------------------------------------------------------------------------- 1 | 10 -------------------------------------------------------------------------------- /test/B/output1.txt: -------------------------------------------------------------------------------- 1 | 19373749 2 | 4 3 | 2 4 | no 5 | 0 6 | 0 7 | 0 8 | 1 9 | 1 10 | -1 -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/B/output12.txt: -------------------------------------------------------------------------------- 1 | 19182622 2 | 19182622 3 | 19182622 4 | 19182622 5 | 19182622 6 | 19182622 7 | 19182622 8 | 19182622 9 | 19182622 10 | 19182622 -------------------------------------------------------------------------------- /test/B/output14.txt: -------------------------------------------------------------------------------- 1 | 19373459 2 | f1: 8221 3 | f0: 0 4 | ori00:5577 5 | -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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{|}~ -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/B/output22.txt: -------------------------------------------------------------------------------- 1 | 19373339 2 | 2 3 | 3 4 | 4 5 | 13 6 | 2 7 | 123456 8 | 123456 9 | 123456 -------------------------------------------------------------------------------- /test/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. -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/B/output27.txt: -------------------------------------------------------------------------------- 1 | 1837518218183751821837518218375182 -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/B/output7.txt: -------------------------------------------------------------------------------- 1 | 19231188111111111 -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/B/output9.txt: -------------------------------------------------------------------------------- 1 | 193733852345678910 -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/B/testfile16.txt: -------------------------------------------------------------------------------- 1 | const int notuse[3] = {0, 0, 0}; 2 | const int notuse2[2][1] = {{1}, {1}}; 3 | const int n = 2, k = 1; 4 | 5 | int a[4][2]={{1, 2}, {3, 4}, {5, 6}, {7, 8}}; 6 | int b[2][1] = {{9}, {10}}; 7 | int c[1][2]={{11, 12}}, des[4][1], des2[4][2], m; 8 | 9 | void matrixMul(int a1[][2], int a2[][1], int op){ 10 | int i = 0, j = 0, l = 0, tmp; 11 | while(m > i) { 12 | l = 0; 13 | while(k > l) { 14 | tmp = 0; 15 | j = 0; 16 | while(n > j) { 17 | tmp = tmp + a1[i][j] * a2[j][l]; 18 | j = j + 1; 19 | } 20 | 21 | if (op == 1) { 22 | des[i][l] = tmp; 23 | } else { 24 | des2[i][l] = tmp; 25 | } 26 | l = l + 1; 27 | } 28 | i = i + 1; 29 | } 30 | return; 31 | } 32 | 33 | void matrixMul2(int a1[][1], int a2[][2], int op){ 34 | int i = 0, j = 0, l = 0, tmp; 35 | while(m > i) { 36 | l = 0; 37 | while(n > l) { 38 | tmp = 0; 39 | j = 0; 40 | while(k > j) { 41 | tmp = tmp + a1[i][j] * a2[j][l]; 42 | j = j + 1; 43 | } 44 | if (op == 1) { 45 | des[i][l] = tmp; 46 | } else { 47 | des2[i][l] = tmp; 48 | } 49 | l = l + 1; 50 | } 51 | i = i + 1; 52 | } 53 | return; 54 | } 55 | 56 | int arraySum(int a3[], int h) { 57 | int i = 0, ans = 0; 58 | while(i < h) { 59 | ans = ans + a3[i]; 60 | i = i+1; 61 | } 62 | return ans; 63 | } 64 | 65 | int main() { 66 | int rowSum[4] = {0, 0, 0, 0}; 67 | printf("19373466\n"); 68 | printf("const declaration: const int a[4][2]={{1, 2}, {3, 4}, {5, 6}, {7, 8}}, b[2][1] = {{9}, {10}}\n"); 69 | printf("global var declaration: int c[1][2]={{11, 12}}\n"); 70 | printf("global var declaration(not initialized): des[4][1], des2[4][2]\n"); 71 | printf("use ConstDef in FuncFParam (exactly, the len of array)\n"); 72 | m = 4; 73 | matrixMul(a, b, 1); 74 | printf("calculate a * b, your result is des[4][1] = {{%d}, {%d}, {%d}, {%d}}\n", des[0][0], des[1][0], des[2][0], des[3][0]); 75 | m = 4; 76 | matrixMul2(des, c, 2); 77 | rowSum[0] = arraySum(des2[0], 2); 78 | rowSum[1] = arraySum(des2[1], 2); 79 | rowSum[2] = arraySum(des2[2], 2); 80 | rowSum[3] = arraySum(des2[3], 2); 81 | printf("calculate des * c\n"); 82 | printf("then calculate the sum of each row(store in rowSum[4])\n"); 83 | printf("your result is (4 row): %d, %d, %d, %d\n", rowSum[0], rowSum[1], rowSum[2], rowSum[3]); 84 | printf("finish\n"); 85 | 86 | return 0; 87 | } 88 | 89 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/B/testfile5.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/test/B/testfile5.txt -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/C/input1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/test/C/input1.txt -------------------------------------------------------------------------------- /test/C/input10.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/test/C/input10.txt -------------------------------------------------------------------------------- /test/C/input11.txt: -------------------------------------------------------------------------------- 1 | 5 -------------------------------------------------------------------------------- /test/C/input12.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/test/C/input12.txt -------------------------------------------------------------------------------- /test/C/input13.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | -------------------------------------------------------------------------------- /test/C/input14.txt: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /test/C/input15.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 4 4 | 5 -------------------------------------------------------------------------------- /test/C/input16.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 15 3 | 6 4 | 6 -------------------------------------------------------------------------------- /test/C/input17.txt: -------------------------------------------------------------------------------- 1 | 12345 2 | -------------------------------------------------------------------------------- /test/C/input18.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 0 4 | -1 5 | 1 6 | 2 7 | 2 8 | -1 9 | 2 10 | 2 11 | -------------------------------------------------------------------------------- /test/C/input19.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/test/C/input19.txt -------------------------------------------------------------------------------- /test/C/input2.txt: -------------------------------------------------------------------------------- 1 | 54633487 2 | 632917 3 | 30 -------------------------------------------------------------------------------- /test/C/input20.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/C/input22.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /test/C/input23.txt: -------------------------------------------------------------------------------- 1 | 0 -------------------------------------------------------------------------------- /test/C/input24.txt: -------------------------------------------------------------------------------- 1 | 19260817 2 | 114514 3 | 1919810 4 | 4 5 | 16 6 | 13 -------------------------------------------------------------------------------- /test/C/input25.txt: -------------------------------------------------------------------------------- 1 | 11 2 | 13 3 | 12341 4 | -------------------------------------------------------------------------------- /test/C/input26.txt: -------------------------------------------------------------------------------- 1 | 33 -------------------------------------------------------------------------------- /test/C/input27.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | -------------------------------------------------------------------------------- /test/C/input28.txt: -------------------------------------------------------------------------------- 1 | 6 -------------------------------------------------------------------------------- /test/C/input29.txt: -------------------------------------------------------------------------------- 1 | 233 2 | 1 3 | 42 4 | -15 5 | 0 6 | -------------------------------------------------------------------------------- /test/C/input3.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 23 3 | 3 4 | 4 5 | 52 6 | 6 7 | 7 8 | 8 9 | 99 10 | -------------------------------------------------------------------------------- /test/C/input4.txt: -------------------------------------------------------------------------------- 1 | 56 -------------------------------------------------------------------------------- /test/C/input5.txt: -------------------------------------------------------------------------------- 1 | -4 2 | 0 3 | 1 4 | 2 5 | 3 6 | 4 7 | 5 8 | 6 9 | 7 10 | 8 11 | -------------------------------------------------------------------------------- /test/C/input6.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/test/C/input6.txt -------------------------------------------------------------------------------- /test/C/input7.txt: -------------------------------------------------------------------------------- 1 | 123 -------------------------------------------------------------------------------- /test/C/input8.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/test/C/input8.txt -------------------------------------------------------------------------------- /test/C/input9.txt: -------------------------------------------------------------------------------- 1 | 9 2 | 8 3 | 7 4 | 6 5 | 5 6 | 4 7 | 3 8 | 2 9 | 1 10 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/C/output10.txt: -------------------------------------------------------------------------------- 1 | 19373025 2 | 1 3 | funi 4 | try 5 | try 6 | try 7 | try 8 | try 9 | try 10 | try -------------------------------------------------------------------------------- /test/C/output11.txt: -------------------------------------------------------------------------------- 1 | 19182650 2 | this is d 3 | 4 4 | 5 5 | 4 6 | 5 7 | 2 -------------------------------------------------------------------------------- /test/C/output12.txt: -------------------------------------------------------------------------------- 1 | 19182623 2 | -------------------------------------------------------------------------------- /test/C/output13.txt: -------------------------------------------------------------------------------- 1 | 10, 30972, -5 -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/C/output18.txt: -------------------------------------------------------------------------------- 1 | 19373719 2 | 0 -2 3 | 0 2 4 | 4 5 | 0 6 | -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/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. -------------------------------------------------------------------------------- /test/C/output20.txt: -------------------------------------------------------------------------------- 1 | 19373061 2 | 0 3 | 1 4 | 0 5 | 0 6 | 1 7 | 0 8 | 1 9 | 0 10 | t:1 -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/C/output22.txt: -------------------------------------------------------------------------------- 1 | 19373034 2 | 1 3 | 1 4 | 0 5 | 1 6 | 0 7 | 10 8 | 8 9 | 9 10 | 10 -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/C/output24.txt: -------------------------------------------------------------------------------- 1 | 19373022 2 | b:-19260604 3 | Bool1 is false! 4 | 1919820 5 | 1932053504 6 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/C/output4.txt: -------------------------------------------------------------------------------- 1 | 19231204 2 | The score is 56. 3 | Yes! 4 | Yes! 5 | Yes! 6 | No! -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 -------------------------------------------------------------------------------- /test/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! -------------------------------------------------------------------------------- /test/C/output8.txt: -------------------------------------------------------------------------------- 1 | 19182650 2 | 1 3 | 2 4 | 3 5 | 4 6 | 5 7 | 6 8 | 21 9 | 1 10 | 6 -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/C/testfile21.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/test/C/testfile21.txt -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/C/testfile6.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/test/C/testfile6.txt -------------------------------------------------------------------------------- /test/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 | -------------------------------------------------------------------------------- /test/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 | } -------------------------------------------------------------------------------- /test/D/input1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUAADreamer/BUAA-Compile-2021/344c36af08e7faaf423eec31a7f927e6a46e1c3d/test/D/input1.txt -------------------------------------------------------------------------------- /test/D/input2.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 2 3 | -------------------------------------------------------------------------------- /test/D/output1.txt: -------------------------------------------------------------------------------- 1 | 13 -------------------------------------------------------------------------------- /test/D/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 | -------------------------------------------------------------------------------- /test/D/testfile1.txt: -------------------------------------------------------------------------------- 1 | int e3[4],f3[3],ii3[2][2] = {{9,8},{7,6}}; 2 | int funcAA(int x[], int y[]) { 3 | int tempp; 4 | tempp = x[0] + y[0]; 5 | return tempp; 6 | } 7 | int main () { 8 | int j3[2][3] = {{ii3[0][0],2,ii3[0][1]},{4,ii3[1][0],ii3[1][1]}}; 9 | int temp3; 10 | temp3 = funcAA(ii3[0], j3[1]); 11 | printf("%d\n",temp3); 12 | return 0; 13 | } -------------------------------------------------------------------------------- /test/D/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