├── .gitignore ├── META-INF └── MANIFEST.MF ├── README.md ├── build.sh ├── doc ├── 总结感想.md ├── 申优文档.md └── 设计文档.md ├── scripts ├── .gitignore ├── cg_submit.py ├── submit.sh └── zip.sh ├── src ├── Compiler.java ├── autotest │ ├── TestCase.java │ ├── TestRunner.java │ └── TestSet.java ├── backend │ ├── Mips.java │ ├── RegisterMap.java │ ├── Translator.java │ ├── exception │ │ ├── AddressNotAlignedException.java │ │ └── JumpTargetUndefinedException.java │ ├── hardware │ │ ├── Memory.java │ │ └── RegisterFile.java │ ├── instruction │ │ ├── AbsoluteValue.java │ │ ├── Addiu.java │ │ ├── Addu.java │ │ ├── And.java │ │ ├── Andi.java │ │ ├── BranchEqual.java │ │ ├── BranchGreaterEqualZero.java │ │ ├── BranchGreaterThanZero.java │ │ ├── BranchLessEqualZero.java │ │ ├── BranchLessThanZero.java │ │ ├── BranchNotEqual.java │ │ ├── CountLeadingOnes.java │ │ ├── CountLeadingZeros.java │ │ ├── Divide.java │ │ ├── JumpAndLink.java │ │ ├── JumpLabel.java │ │ ├── JumpRegister.java │ │ ├── LoadByte.java │ │ ├── LoadHalf.java │ │ ├── LoadImmediate.java │ │ ├── LoadWord.java │ │ ├── MipsInstruction.java │ │ ├── Move.java │ │ ├── MoveFromHi.java │ │ ├── MoveFromLo.java │ │ ├── MoveIfZero.java │ │ ├── MoveNotZero.java │ │ ├── Multiply.java │ │ ├── NotOr.java │ │ ├── Or.java │ │ ├── Ori.java │ │ ├── SetEqual.java │ │ ├── SetEqualImmediate.java │ │ ├── SetGreaterEqual.java │ │ ├── SetGreaterEqualImmediate.java │ │ ├── SetGreaterThan.java │ │ ├── SetGreaterThanImmediate.java │ │ ├── SetLessEqual.java │ │ ├── SetLessEqualImmediate.java │ │ ├── SetLessThan.java │ │ ├── SetLessThanImmediate.java │ │ ├── SetNotEqual.java │ │ ├── SetNotEqualImmediate.java │ │ ├── ShiftLeft.java │ │ ├── ShiftLeftVariable.java │ │ ├── ShiftRightArithmetic.java │ │ ├── ShiftRightArithmeticVariable.java │ │ ├── StoreByte.java │ │ ├── StoreHalf.java │ │ ├── StoreWord.java │ │ ├── Subu.java │ │ ├── Syscall.java │ │ ├── Xor.java │ │ └── Xori.java │ └── optimize │ │ ├── JumpFollow.java │ │ └── MipsOptimize.java ├── compiler │ ├── Config.java │ ├── MainCompiler.java │ └── SpecialOptimize.java ├── exception │ ├── ConstExpException.java │ ├── EofException.java │ ├── FrontendException.java │ ├── NoMainFuncException.java │ ├── UndefinedTokenException.java │ └── WrongTokenException.java ├── frontend │ ├── SysY.java │ ├── error │ │ ├── Error.java │ │ └── ErrorTable.java │ ├── input │ │ └── Source.java │ ├── lexical │ │ ├── README.md │ │ ├── TokenList.java │ │ ├── Tokenizer.java │ │ └── token │ │ │ ├── FormatString.java │ │ │ ├── Ident.java │ │ │ ├── IntConst.java │ │ │ ├── ReservedToken.java │ │ │ └── Token.java │ ├── syntax │ │ ├── CompUnit.java │ │ ├── CompUnitParser.java │ │ ├── Component.java │ │ ├── ParserUtil.java │ │ ├── README.md │ │ ├── decl │ │ │ ├── ArrInitVal.java │ │ │ ├── Constable.java │ │ │ ├── Decl.java │ │ │ ├── DeclParser.java │ │ │ ├── Def.java │ │ │ ├── ExpInitVal.java │ │ │ └── InitVal.java │ │ ├── expr │ │ │ ├── ExprParser.java │ │ │ ├── multi │ │ │ │ ├── AddExp.java │ │ │ │ ├── Cond.java │ │ │ │ ├── ConstExp.java │ │ │ │ ├── EqExp.java │ │ │ │ ├── Exp.java │ │ │ │ ├── LAndExp.java │ │ │ │ ├── LOrExp.java │ │ │ │ ├── MulExp.java │ │ │ │ ├── MultiExp.java │ │ │ │ └── RelExp.java │ │ │ └── unary │ │ │ │ ├── BasePrimaryExp.java │ │ │ │ ├── BaseUnaryExp.java │ │ │ │ ├── FuncRParams.java │ │ │ │ ├── FunctionCall.java │ │ │ │ ├── LVal.java │ │ │ │ ├── Number.java │ │ │ │ ├── PrimaryExp.java │ │ │ │ ├── SubExp.java │ │ │ │ └── UnaryExp.java │ │ ├── func │ │ │ ├── FuncDef.java │ │ │ ├── FuncFParam.java │ │ │ ├── FuncFParams.java │ │ │ ├── FuncParser.java │ │ │ └── MainFuncDef.java │ │ └── stmt │ │ │ ├── Stmt.java │ │ │ ├── StmtParser.java │ │ │ ├── complex │ │ │ ├── Block.java │ │ │ ├── BlockItem.java │ │ │ ├── CplStmt.java │ │ │ ├── IfStmt.java │ │ │ └── WhileStmt.java │ │ │ └── simple │ │ │ ├── AssignStmt.java │ │ │ ├── BreakStmt.java │ │ │ ├── ContinueStmt.java │ │ │ ├── ExpStmt.java │ │ │ ├── InputStmt.java │ │ │ ├── OutputStmt.java │ │ │ ├── ReturnStmt.java │ │ │ └── SplStmt.java │ └── visitor │ │ ├── CalcUtil.java │ │ └── Visitor.java ├── middle │ ├── MidRunner.java │ ├── MiddleCode.java │ ├── code │ │ ├── AddressOffset.java │ │ ├── BasicBlock.java │ │ ├── BinaryOp.java │ │ ├── BranchIfElse.java │ │ ├── Call.java │ │ ├── ILinkNode.java │ │ ├── Input.java │ │ ├── Jump.java │ │ ├── PointerOp.java │ │ ├── PrintInt.java │ │ ├── PrintStr.java │ │ ├── Return.java │ │ └── UnaryOp.java │ ├── operand │ │ ├── Immediate.java │ │ └── Operand.java │ ├── optimize │ │ ├── MergeBlock.java │ │ ├── MidOptimizer.java │ │ ├── MulDivOpt.java │ │ └── RemoveAfterJump.java │ └── symbol │ │ ├── FuncMeta.java │ │ ├── SymTable.java │ │ └── Symbol.java └── utility │ ├── MathUtil.java │ ├── ReaderUtil.java │ └── ZipUtil.java └── testfile ├── 2021 ├── 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 └── myself │ ├── input1.txt │ ├── input2.txt │ ├── input3.txt │ ├── input4.txt │ ├── input5.txt │ ├── output1.txt │ ├── output2.txt │ ├── output3.txt │ ├── output4.txt │ ├── output5.txt │ ├── testfile1.txt │ ├── testfile2.txt │ ├── testfile3.txt │ ├── testfile4.txt │ └── testfile5.txt ├── 2022 ├── 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 │ ├── input27.txt │ ├── input28.txt │ ├── input29.txt │ ├── input3.txt │ ├── input30.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 │ ├── output30.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 │ ├── testfile30.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 │ ├── input28.txt │ ├── input29.txt │ ├── input3.txt │ ├── input30.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 │ ├── output30.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 │ ├── testfile30.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 │ ├── input30.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 │ ├── output30.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 │ ├── testfile30.txt │ ├── testfile4.txt │ ├── testfile5.txt │ ├── testfile6.txt │ ├── testfile7.txt │ ├── testfile8.txt │ └── testfile9.txt └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Idea Project 2 | .idea/ 3 | *.iml 4 | 5 | # Compiled Output 6 | /target/ 7 | /out/ 8 | 9 | # Test files 10 | *.txt 11 | *.sy 12 | *.in 13 | *.out 14 | *.asm 15 | *.s 16 | *.S 17 | 18 | # Archives 19 | *.zip 20 | *.jar 21 | *.rar -------------------------------------------------------------------------------- /META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: Compiler 3 | 4 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mkdir -p build 4 | javac -d build -encoding 'utf-8' $(find src -name '*.java') 5 | cd build 6 | mkdir -p META-INF; echo -e 'Manifest-Version: 1.0\r\nMain-Class: Compiler\r\n\r\n' > META-INF/MANIFEST.MF 7 | jar cfm ../compiler.jar META-INF/MANIFEST.MF * 8 | cd - 9 | rm -r build 10 | -------------------------------------------------------------------------------- /scripts/.gitignore: -------------------------------------------------------------------------------- 1 | # Your Configuration (May have private content) 2 | *.json 3 | !cg_config_sample.json 4 | 5 | # Files you may submit 6 | *.zip 7 | *.rar 8 | *.jar 9 | *.c 10 | *.cpp 11 | *.java 12 | *.py 13 | *.txt 14 | *.doc 15 | *.docx 16 | *.ppt 17 | *.pptx 18 | *.xls 19 | *.xlsx 20 | *.pdf 21 | 22 | # Judge Result 23 | *.html 24 | -------------------------------------------------------------------------------- /scripts/submit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # run this script at root dir of project: `scripts/submit.py` 4 | # cg_submit.py needs a configuration file of JSON format, sample: https://github.com/dhy2000/CG-Submit/blob/master/cg_config_sample.json 5 | 6 | scripts/zip.sh src/ && cd scripts/ && python -u cg_submit.py ../Compiler2021.zip ; cd .. 7 | 8 | 9 | -------------------------------------------------------------------------------- /scripts/zip.sh: -------------------------------------------------------------------------------- 1 | echo "Zipping all java sources inside src/ ......" 2 | 3 | # Working directory is root of project! 4 | srcs=`find . -name "*.java"` 5 | 6 | echo $srcs | xargs zip -q Compiler2021.zip -------------------------------------------------------------------------------- /src/autotest/TestCase.java: -------------------------------------------------------------------------------- 1 | package autotest; 2 | 3 | /** 4 | * 测试点 5 | */ 6 | public class TestCase { 7 | /* 8 | name: String 9 | testfile(path): String 10 | input(path): String 11 | output(path): String 12 | 13 | path: relative path 14 | */ 15 | private final String name; 16 | private final String testfile; 17 | private final String input; 18 | private final String output; 19 | 20 | public TestCase(String name, String testfile, String input, String output) { 21 | this.name = name; 22 | this.testfile = testfile; 23 | this.input = input; 24 | this.output = output; 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | public String getTestfile() { 32 | return testfile; 33 | } 34 | 35 | public String getInput() { 36 | return input; 37 | } 38 | 39 | public String getOutput() { 40 | return output; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return name + ": [" + testfile + ", " + input + ", " + output + "]"; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/backend/exception/AddressNotAlignedException.java: -------------------------------------------------------------------------------- 1 | package backend.exception; 2 | 3 | /** 4 | * 读写内存的字或半字,地址未对齐 5 | */ 6 | public class AddressNotAlignedException extends Exception{ 7 | private final int badAddress; 8 | private final String instruction; 9 | 10 | public AddressNotAlignedException(int badAddress, String instruction) { 11 | super("Address not aligned at " + String.format("%08x", badAddress) + " when executing " + instruction); 12 | this.badAddress = badAddress; 13 | this.instruction = instruction; 14 | } 15 | 16 | public int getBadAddress() { 17 | return badAddress; 18 | } 19 | 20 | public String getInstruction() { 21 | return instruction; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/backend/exception/JumpTargetUndefinedException.java: -------------------------------------------------------------------------------- 1 | package backend.exception; 2 | 3 | /** 4 | * 跳转到未加载指令的区域 5 | */ 6 | public class JumpTargetUndefinedException extends Exception { 7 | private final String badInstruction; 8 | 9 | public JumpTargetUndefinedException(String badInstruction) { 10 | super("Branch/Jump to undefined label: " + badInstruction); 11 | this.badInstruction = badInstruction; 12 | } 13 | 14 | public String getBadInstruction() { 15 | return badInstruction; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/backend/instruction/AbsoluteValue.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class AbsoluteValue extends MipsInstruction { 6 | private final int regDst; 7 | private final int regSrc; 8 | 9 | public AbsoluteValue(int regDst, int regSrc) { 10 | this.regDst = regDst; 11 | this.regSrc = regSrc; 12 | } 13 | 14 | public int getRegDst() { 15 | return regDst; 16 | } 17 | 18 | public int getRegSrc() { 19 | return regSrc; 20 | } 21 | 22 | @Override 23 | public String instrToString() { 24 | return String.format("abs $%s, $%s", RegisterFile.getRegisterName(regDst), RegisterFile.getRegisterName(regSrc)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/backend/instruction/Addiu.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class Addiu extends MipsInstruction { 6 | 7 | private final int regSrc; 8 | private final int immediate; 9 | private final int regDst; 10 | 11 | public Addiu(int regSrc, int immediate, int regDst) { 12 | this.regDst = regDst; 13 | this.regSrc = regSrc; 14 | this.immediate = immediate; 15 | } 16 | 17 | public int getRegSrc() { 18 | return regSrc; 19 | } 20 | 21 | public int getImmediate() { 22 | return immediate; 23 | } 24 | 25 | public int getRegDst() { 26 | return regDst; 27 | } 28 | 29 | @Override 30 | public String instrToString() { 31 | return String.format("addiu $%s, $%s, %d", RegisterFile.getRegisterName(regDst), RegisterFile.getRegisterName(regSrc), immediate); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/backend/instruction/Addu.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class Addu extends MipsInstruction { 6 | 7 | private final int regSrc1; 8 | private final int regSrc2; 9 | private final int regDst; 10 | 11 | public Addu(int regSrc1, int regSrc2, int regDst) { 12 | this.regSrc1 = regSrc1; 13 | this.regSrc2 = regSrc2; 14 | this.regDst = regDst; 15 | } 16 | 17 | public int getRegSrc1() { 18 | return regSrc1; 19 | } 20 | 21 | public int getRegSrc2() { 22 | return regSrc2; 23 | } 24 | 25 | public int getRegDst() { 26 | return regDst; 27 | } 28 | 29 | @Override 30 | public String instrToString() { 31 | return String.format("addu $%s, $%s, $%s", 32 | RegisterFile.getRegisterName(regDst), 33 | RegisterFile.getRegisterName(regSrc1), 34 | RegisterFile.getRegisterName(regSrc2)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/backend/instruction/And.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class And extends MipsInstruction { 6 | 7 | private final int regSrc1; 8 | private final int regSrc2; 9 | private final int regDst; 10 | 11 | public And(int regSrc1, int regSrc2, int regDst) { 12 | this.regSrc1 = regSrc1; 13 | this.regSrc2 = regSrc2; 14 | this.regDst = regDst; 15 | } 16 | 17 | public int getRegSrc1() { 18 | return regSrc1; 19 | } 20 | 21 | public int getRegSrc2() { 22 | return regSrc2; 23 | } 24 | 25 | public int getRegDst() { 26 | return regDst; 27 | } 28 | 29 | @Override 30 | public String instrToString() { 31 | return String.format("and $%s, $%s, $%s", 32 | RegisterFile.getRegisterName(regDst), 33 | RegisterFile.getRegisterName(regSrc1), 34 | RegisterFile.getRegisterName(regSrc2)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/backend/instruction/Andi.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class Andi extends MipsInstruction { 6 | 7 | private final int regSrc; 8 | private final int immediate; 9 | private final int regDst; 10 | 11 | public Andi(int regSrc, int immediate, int regDst) { 12 | this.regDst = regDst; 13 | this.regSrc = regSrc; 14 | this.immediate = immediate; 15 | } 16 | 17 | public int getRegSrc() { 18 | return regSrc; 19 | } 20 | 21 | public int getImmediate() { 22 | return immediate; 23 | } 24 | 25 | public int getRegDst() { 26 | return regDst; 27 | } 28 | 29 | @Override 30 | public String instrToString() { 31 | return String.format("andi $%s, $%s, %d", RegisterFile.getRegisterName(regDst), RegisterFile.getRegisterName(regSrc), immediate); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/backend/instruction/BranchEqual.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class BranchEqual extends MipsInstruction { 6 | 7 | private final int regSrc1; 8 | private final int regSrc2; 9 | private final String target; 10 | 11 | public BranchEqual(int regSrc1, int regSrc2, String target) { 12 | this.regSrc1 = regSrc1; 13 | this.regSrc2 = regSrc2; 14 | assert !target.isEmpty(); 15 | this.target = target; 16 | } 17 | 18 | public int getRegSrc1() { 19 | return regSrc1; 20 | } 21 | 22 | public int getRegSrc2() { 23 | return regSrc2; 24 | } 25 | 26 | @Override 27 | public String instrToString() { 28 | return String.format("beq $%s, $%s, %s", RegisterFile.getRegisterName(regSrc1), RegisterFile.getRegisterName(regSrc2), target); 29 | } 30 | 31 | @Override 32 | public String getJumpTarget() { 33 | return target; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/backend/instruction/BranchGreaterEqualZero.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class BranchGreaterEqualZero extends MipsInstruction { 6 | 7 | private final int regSrc; 8 | private final String target; 9 | 10 | public BranchGreaterEqualZero(int regSrc, String target) { 11 | this.regSrc = regSrc; 12 | assert !target.isEmpty(); 13 | this.target = target; 14 | } 15 | 16 | public int getRegSrc() { 17 | return regSrc; 18 | } 19 | 20 | @Override 21 | public String instrToString() { 22 | return String.format("bgez $%s, %s", RegisterFile.getRegisterName(regSrc), target); 23 | } 24 | 25 | @Override 26 | public String getJumpTarget() { 27 | return target; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/backend/instruction/BranchGreaterThanZero.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class BranchGreaterThanZero extends MipsInstruction { 6 | 7 | private final int regSrc; 8 | private final String target; 9 | 10 | public BranchGreaterThanZero(int regSrc, String target) { 11 | this.regSrc = regSrc; 12 | assert !target.isEmpty(); 13 | this.target = target; 14 | } 15 | 16 | public int getRegSrc() { 17 | return regSrc; 18 | } 19 | 20 | @Override 21 | public String instrToString() { 22 | return String.format("bgtz $%s, %s", RegisterFile.getRegisterName(regSrc), target); 23 | } 24 | 25 | @Override 26 | public String getJumpTarget() { 27 | return target; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/backend/instruction/BranchLessEqualZero.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class BranchLessEqualZero extends MipsInstruction { 6 | 7 | private final int regSrc; 8 | private final String target; 9 | 10 | public BranchLessEqualZero(int regSrc, String target) { 11 | this.regSrc = regSrc; 12 | assert !target.isEmpty(); 13 | this.target = target; 14 | } 15 | 16 | public int getRegSrc() { 17 | return regSrc; 18 | } 19 | 20 | @Override 21 | public String instrToString() { 22 | return String.format("blez $%s, %s", RegisterFile.getRegisterName(regSrc), target); 23 | } 24 | 25 | @Override 26 | public String getJumpTarget() { 27 | return target; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/backend/instruction/BranchLessThanZero.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class BranchLessThanZero extends MipsInstruction { 6 | 7 | private final int regSrc; 8 | private final String target; 9 | 10 | public BranchLessThanZero(int regSrc, String target) { 11 | this.regSrc = regSrc; 12 | assert !target.isEmpty(); 13 | this.target = target; 14 | } 15 | 16 | public int getRegSrc() { 17 | return regSrc; 18 | } 19 | 20 | @Override 21 | public String instrToString() { 22 | return String.format("bltz $%s, %s", RegisterFile.getRegisterName(regSrc), target); 23 | } 24 | 25 | @Override 26 | public String getJumpTarget() { 27 | return target; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/backend/instruction/BranchNotEqual.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class BranchNotEqual extends MipsInstruction { 6 | 7 | private final int regSrc1; 8 | private final int regSrc2; 9 | private final String target; 10 | 11 | public BranchNotEqual(int regSrc1, int regSrc2, String target) { 12 | this.regSrc1 = regSrc1; 13 | this.regSrc2 = regSrc2; 14 | assert !target.isEmpty(); 15 | this.target = target; 16 | } 17 | 18 | public int getRegSrc1() { 19 | return regSrc1; 20 | } 21 | 22 | public int getRegSrc2() { 23 | return regSrc2; 24 | } 25 | 26 | @Override 27 | public String instrToString() { 28 | return String.format("bne $%s, $%s, %s", RegisterFile.getRegisterName(regSrc1), RegisterFile.getRegisterName(regSrc2), target); 29 | } 30 | 31 | @Override 32 | public String getJumpTarget() { 33 | return target; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/backend/instruction/CountLeadingOnes.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class CountLeadingOnes extends MipsInstruction { 6 | private final int regDst; 7 | private final int regSrc; 8 | 9 | public CountLeadingOnes(int regDst, int regSrc) { 10 | this.regDst = regDst; 11 | this.regSrc = regSrc; 12 | } 13 | 14 | public int getRegDst() { 15 | return regDst; 16 | } 17 | 18 | public int getRegSrc() { 19 | return regSrc; 20 | } 21 | 22 | @Override 23 | public String instrToString() { 24 | return String.format("clo $%s, $%s", RegisterFile.getRegisterName(regDst), RegisterFile.getRegisterName(regSrc)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/backend/instruction/CountLeadingZeros.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class CountLeadingZeros extends MipsInstruction { 6 | private final int regDst; 7 | private final int regSrc; 8 | 9 | public CountLeadingZeros(int regDst, int regSrc) { 10 | this.regDst = regDst; 11 | this.regSrc = regSrc; 12 | } 13 | 14 | public int getRegDst() { 15 | return regDst; 16 | } 17 | 18 | public int getRegSrc() { 19 | return regSrc; 20 | } 21 | 22 | @Override 23 | public String instrToString() { 24 | return String.format("clz $%s, $%s", RegisterFile.getRegisterName(regDst), RegisterFile.getRegisterName(regSrc)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/backend/instruction/Divide.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class Divide extends MipsInstruction { 6 | 7 | private final int regSrc1; 8 | private final int regSrc2; 9 | 10 | public Divide(int regSrc1, int regSrc2) { 11 | this.regSrc1 = regSrc1; 12 | this.regSrc2 = regSrc2; 13 | } 14 | 15 | public int getRegSrc1() { 16 | return regSrc1; 17 | } 18 | 19 | public int getRegSrc2() { 20 | return regSrc2; 21 | } 22 | 23 | @Override 24 | public String instrToString() { 25 | return String.format("div $%s, $%s", RegisterFile.getRegisterName(regSrc1), RegisterFile.getRegisterName(regSrc2)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/backend/instruction/JumpAndLink.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | public class JumpAndLink extends MipsInstruction { 4 | 5 | private final String target; 6 | 7 | public JumpAndLink(String target) { 8 | assert !target.isEmpty(); 9 | this.target = target; 10 | } 11 | 12 | @Override 13 | public String instrToString() { 14 | return "jal " + target; 15 | } 16 | 17 | @Override 18 | public String getJumpTarget() { 19 | return target; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/backend/instruction/JumpLabel.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | public class JumpLabel extends MipsInstruction { 4 | 5 | private final String target; 6 | 7 | public JumpLabel(String target) { 8 | assert !target.isEmpty(); 9 | this.target = target; 10 | } 11 | 12 | @Override 13 | public String instrToString() { 14 | return "j " + getJumpTarget(); 15 | } 16 | 17 | @Override 18 | public String getJumpTarget() { 19 | return target; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/backend/instruction/JumpRegister.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | /** 6 | * jr 指令,跳转到寄存器, 在写模拟器时需要特殊处理 7 | */ 8 | public class JumpRegister extends MipsInstruction { 9 | 10 | private final int regSrc; 11 | 12 | public JumpRegister(int regSrc) { 13 | this.regSrc = regSrc; 14 | } 15 | 16 | public int getRegSrc() { 17 | return regSrc; 18 | } 19 | 20 | @Override 21 | public String instrToString() { 22 | return "jr $" + RegisterFile.getRegisterName(regSrc); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/backend/instruction/LoadByte.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class LoadByte extends MipsInstruction { 6 | private final int regBase; 7 | private final int offset; 8 | private final int regDst; 9 | 10 | public LoadByte(int regBase, int offset, int regDst) { 11 | this.regBase = regBase; 12 | this.offset = offset; 13 | this.regDst = regDst; 14 | } 15 | 16 | public int getRegBase() { 17 | return regBase; 18 | } 19 | 20 | public int getOffset() { 21 | return offset; 22 | } 23 | 24 | public int getRegDst() { 25 | return regDst; 26 | } 27 | 28 | @Override 29 | public String instrToString() { 30 | return String.format("lb $%s, %d($%s)", RegisterFile.getRegisterName(regDst), offset, RegisterFile.getRegisterName(regBase)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/backend/instruction/LoadHalf.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class LoadHalf extends MipsInstruction { 6 | private final int regBase; 7 | private final int offset; 8 | private final int regDst; 9 | 10 | public LoadHalf(int regBase, int offset, int regDst) { 11 | this.regBase = regBase; 12 | this.offset = offset; 13 | this.regDst = regDst; 14 | } 15 | 16 | public int getRegBase() { 17 | return regBase; 18 | } 19 | 20 | public int getOffset() { 21 | return offset; 22 | } 23 | 24 | public int getRegDst() { 25 | return regDst; 26 | } 27 | 28 | @Override 29 | public String instrToString() { 30 | return String.format("lh $%s, %d($%s)", RegisterFile.getRegisterName(regDst), offset, RegisterFile.getRegisterName(regBase)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/backend/instruction/LoadImmediate.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class LoadImmediate extends MipsInstruction { 6 | 7 | private final int regDst; 8 | private final int immediate; 9 | 10 | public LoadImmediate(int regDst, int immediate) { 11 | this.regDst = regDst; 12 | this.immediate = immediate; 13 | } 14 | 15 | public int getRegDst() { 16 | return regDst; 17 | } 18 | 19 | public int getImmediate() { 20 | return immediate; 21 | } 22 | 23 | @Override 24 | public String instrToString() { 25 | return String.format("li $%s, %d", RegisterFile.getRegisterName(regDst), immediate); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/backend/instruction/LoadWord.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class LoadWord extends MipsInstruction { 6 | 7 | private final int regBase; 8 | private final int offset; 9 | private final int regDst; 10 | 11 | public LoadWord(int regBase, int offset, int regDst) { 12 | this.regBase = regBase; 13 | this.offset = offset; 14 | this.regDst = regDst; 15 | } 16 | 17 | public int getRegBase() { 18 | return regBase; 19 | } 20 | 21 | public int getOffset() { 22 | return offset; 23 | } 24 | 25 | public int getRegDst() { 26 | return regDst; 27 | } 28 | 29 | @Override 30 | public String instrToString() { 31 | return String.format("lw $%s, %d($%s)", RegisterFile.getRegisterName(regDst), offset, RegisterFile.getRegisterName(regBase)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/backend/instruction/Move.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class Move extends MipsInstruction { 6 | 7 | private final int regDst; 8 | private final int regSrc; 9 | 10 | public Move(int regDst, int regSrc) { 11 | this.regDst = regDst; 12 | this.regSrc = regSrc; 13 | } 14 | 15 | public int getRegDst() { 16 | return regDst; 17 | } 18 | 19 | public int getRegSrc() { 20 | return regSrc; 21 | } 22 | 23 | @Override 24 | public String instrToString() { 25 | return String.format("move $%s, $%s", RegisterFile.getRegisterName(regDst), RegisterFile.getRegisterName(regSrc)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/backend/instruction/MoveFromHi.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class MoveFromHi extends MipsInstruction { 6 | 7 | private final int regDst; 8 | 9 | public MoveFromHi(int regDst) { 10 | this.regDst = regDst; 11 | } 12 | 13 | public int getRegDst() { 14 | return regDst; 15 | } 16 | 17 | @Override 18 | public String instrToString() { 19 | return "mfhi $" + RegisterFile.getRegisterName(regDst); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/backend/instruction/MoveFromLo.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class MoveFromLo extends MipsInstruction { 6 | 7 | private final int regDst; 8 | 9 | public MoveFromLo(int regDst) { 10 | this.regDst = regDst; 11 | } 12 | 13 | public int getRegDst() { 14 | return regDst; 15 | } 16 | 17 | @Override 18 | public String instrToString() { 19 | return "mflo $" + RegisterFile.getRegisterName(regDst); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/backend/instruction/MoveIfZero.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class MoveIfZero extends MipsInstruction { 6 | private final int regSrc1; 7 | private final int regSrc2; 8 | private final int regDst; 9 | 10 | public MoveIfZero(int regSrc1, int regSrc2, int regDst) { 11 | this.regSrc1 = regSrc1; 12 | this.regSrc2 = regSrc2; 13 | this.regDst = regDst; 14 | } 15 | 16 | public int getRegSrc1() { 17 | return regSrc1; 18 | } 19 | 20 | public int getRegSrc2() { 21 | return regSrc2; 22 | } 23 | 24 | public int getRegDst() { 25 | return regDst; 26 | } 27 | 28 | @Override 29 | public String instrToString() { 30 | return String.format("movz $%s, $%s, $%s", RegisterFile.getRegisterName(regDst), RegisterFile.getRegisterName(regSrc1), RegisterFile.getRegisterName(regSrc2)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/backend/instruction/MoveNotZero.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class MoveNotZero extends MipsInstruction { 6 | private final int regSrc1; 7 | private final int regSrc2; 8 | private final int regDst; 9 | 10 | public MoveNotZero(int regSrc1, int regSrc2, int regDst) { 11 | this.regSrc1 = regSrc1; 12 | this.regSrc2 = regSrc2; 13 | this.regDst = regDst; 14 | } 15 | 16 | public int getRegSrc1() { 17 | return regSrc1; 18 | } 19 | 20 | public int getRegSrc2() { 21 | return regSrc2; 22 | } 23 | 24 | public int getRegDst() { 25 | return regDst; 26 | } 27 | 28 | @Override 29 | public String instrToString() { 30 | return String.format("movn $%s, $%s, $%s", RegisterFile.getRegisterName(regDst), RegisterFile.getRegisterName(regSrc1), RegisterFile.getRegisterName(regSrc2)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/backend/instruction/Multiply.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class Multiply extends MipsInstruction { 6 | 7 | private final int regSrc1; 8 | private final int regSrc2; 9 | 10 | public Multiply(int regSrc1, int regSrc2) { 11 | this.regSrc1 = regSrc1; 12 | this.regSrc2 = regSrc2; 13 | } 14 | 15 | public int getRegSrc1() { 16 | return regSrc1; 17 | } 18 | 19 | public int getRegSrc2() { 20 | return regSrc2; 21 | } 22 | 23 | @Override 24 | public String instrToString() { 25 | return String.format("mult $%s, $%s", RegisterFile.getRegisterName(regSrc1), RegisterFile.getRegisterName(regSrc2)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/backend/instruction/NotOr.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class NotOr extends MipsInstruction { 6 | private final int regSrc1; 7 | private final int regSrc2; 8 | private final int regDst; 9 | 10 | public NotOr(int regSrc1, int regSrc2, int regDst) { 11 | this.regSrc1 = regSrc1; 12 | this.regSrc2 = regSrc2; 13 | this.regDst = regDst; 14 | } 15 | 16 | public int getRegSrc1() { 17 | return regSrc1; 18 | } 19 | 20 | public int getRegSrc2() { 21 | return regSrc2; 22 | } 23 | 24 | public int getRegDst() { 25 | return regDst; 26 | } 27 | 28 | @Override 29 | public String instrToString() { 30 | return String.format("nor $%s, $%s, $%s", 31 | RegisterFile.getRegisterName(regDst), 32 | RegisterFile.getRegisterName(regSrc1), 33 | RegisterFile.getRegisterName(regSrc2)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/backend/instruction/Or.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class Or extends MipsInstruction { 6 | 7 | private final int regSrc1; 8 | private final int regSrc2; 9 | private final int regDst; 10 | 11 | public Or(int regSrc1, int regSrc2, int regDst) { 12 | this.regSrc1 = regSrc1; 13 | this.regSrc2 = regSrc2; 14 | this.regDst = regDst; 15 | } 16 | 17 | public int getRegSrc1() { 18 | return regSrc1; 19 | } 20 | 21 | public int getRegSrc2() { 22 | return regSrc2; 23 | } 24 | 25 | public int getRegDst() { 26 | return regDst; 27 | } 28 | 29 | @Override 30 | public String instrToString() { 31 | return String.format("or $%s, $%s, $%s", 32 | RegisterFile.getRegisterName(regDst), 33 | RegisterFile.getRegisterName(regSrc1), 34 | RegisterFile.getRegisterName(regSrc2)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/backend/instruction/Ori.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class Ori extends MipsInstruction { 6 | private final int regSrc; 7 | private final int immediate; 8 | private final int regDst; 9 | 10 | public Ori(int regSrc, int immediate, int regDst) { 11 | this.regDst = regDst; 12 | this.regSrc = regSrc; 13 | this.immediate = immediate; 14 | } 15 | 16 | public int getRegSrc() { 17 | return regSrc; 18 | } 19 | 20 | public int getImmediate() { 21 | return immediate; 22 | } 23 | 24 | public int getRegDst() { 25 | return regDst; 26 | } 27 | 28 | @Override 29 | public String instrToString() { 30 | return String.format("ori $%s, $%s, %d", RegisterFile.getRegisterName(regDst), RegisterFile.getRegisterName(regSrc), immediate); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/backend/instruction/SetEqual.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class SetEqual extends MipsInstruction { 6 | private final int regSrc1; 7 | private final int regSrc2; 8 | private final int regDst; 9 | 10 | public SetEqual(int regSrc1, int regSrc2, int regDst) { 11 | this.regSrc1 = regSrc1; 12 | this.regSrc2 = regSrc2; 13 | this.regDst = regDst; 14 | } 15 | 16 | public int getRegSrc1() { 17 | return regSrc1; 18 | } 19 | 20 | public int getRegSrc2() { 21 | return regSrc2; 22 | } 23 | 24 | public int getRegDst() { 25 | return regDst; 26 | } 27 | 28 | @Override 29 | public String instrToString() { 30 | return String.format("seq $%s, $%s, $%s", RegisterFile.getRegisterName(regDst), RegisterFile.getRegisterName(regSrc1), RegisterFile.getRegisterName(regSrc2)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/backend/instruction/SetEqualImmediate.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | public class SetEqualImmediate extends MipsInstruction { 4 | 5 | private final int regSrc; 6 | private final int immediate; 7 | private final int regDst; 8 | 9 | public SetEqualImmediate(int regSrc, int immediate, int regDst) { 10 | this.regDst = regDst; 11 | this.regSrc = regSrc; 12 | this.immediate = immediate; 13 | } 14 | 15 | public int getRegSrc() { 16 | return regSrc; 17 | } 18 | 19 | public int getImmediate() { 20 | return immediate; 21 | } 22 | 23 | public int getRegDst() { 24 | return regDst; 25 | } 26 | 27 | @Override 28 | public String instrToString() { 29 | return String.format("seq $%s, $%s, %d", regDst, regSrc, immediate); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/backend/instruction/SetGreaterEqual.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class SetGreaterEqual extends MipsInstruction { 6 | private final int regSrc1; 7 | private final int regSrc2; 8 | private final int regDst; 9 | 10 | public SetGreaterEqual(int regSrc1, int regSrc2, int regDst) { 11 | this.regSrc1 = regSrc1; 12 | this.regSrc2 = regSrc2; 13 | this.regDst = regDst; 14 | } 15 | 16 | public int getRegSrc1() { 17 | return regSrc1; 18 | } 19 | 20 | public int getRegSrc2() { 21 | return regSrc2; 22 | } 23 | 24 | public int getRegDst() { 25 | return regDst; 26 | } 27 | 28 | @Override 29 | public String instrToString() { 30 | return String.format("sge $%s, $%s, $%s", RegisterFile.getRegisterName(regDst), RegisterFile.getRegisterName(regSrc1), RegisterFile.getRegisterName(regSrc2)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/backend/instruction/SetGreaterEqualImmediate.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | public class SetGreaterEqualImmediate extends MipsInstruction { 4 | private final int regSrc; 5 | private final int immediate; 6 | private final int regDst; 7 | 8 | public SetGreaterEqualImmediate(int regSrc, int immediate, int regDst) { 9 | this.regDst = regDst; 10 | this.regSrc = regSrc; 11 | this.immediate = immediate; 12 | } 13 | 14 | public int getRegSrc() { 15 | return regSrc; 16 | } 17 | 18 | public int getImmediate() { 19 | return immediate; 20 | } 21 | 22 | public int getRegDst() { 23 | return regDst; 24 | } 25 | 26 | @Override 27 | public String instrToString() { 28 | return String.format("sge $%s, $%s, %d", regDst, regSrc, immediate); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/backend/instruction/SetGreaterThan.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class SetGreaterThan extends MipsInstruction { 6 | private final int regSrc1; 7 | private final int regSrc2; 8 | private final int regDst; 9 | 10 | public SetGreaterThan(int regSrc1, int regSrc2, int regDst) { 11 | this.regSrc1 = regSrc1; 12 | this.regSrc2 = regSrc2; 13 | this.regDst = regDst; 14 | } 15 | 16 | public int getRegSrc1() { 17 | return regSrc1; 18 | } 19 | 20 | public int getRegSrc2() { 21 | return regSrc2; 22 | } 23 | 24 | public int getRegDst() { 25 | return regDst; 26 | } 27 | 28 | @Override 29 | public String instrToString() { 30 | return String.format("sgt $%s, $%s, $%s", RegisterFile.getRegisterName(regDst), RegisterFile.getRegisterName(regSrc1), RegisterFile.getRegisterName(regSrc2)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/backend/instruction/SetGreaterThanImmediate.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | public class SetGreaterThanImmediate extends MipsInstruction { 4 | private final int regSrc; 5 | private final int immediate; 6 | private final int regDst; 7 | 8 | public SetGreaterThanImmediate(int regSrc, int immediate, int regDst) { 9 | this.regDst = regDst; 10 | this.regSrc = regSrc; 11 | this.immediate = immediate; 12 | } 13 | 14 | public int getRegSrc() { 15 | return regSrc; 16 | } 17 | 18 | public int getImmediate() { 19 | return immediate; 20 | } 21 | 22 | public int getRegDst() { 23 | return regDst; 24 | } 25 | 26 | @Override 27 | public String instrToString() { 28 | return String.format("sgt $%s, $%s, %d", regDst, regSrc, immediate); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/backend/instruction/SetLessEqual.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class SetLessEqual extends MipsInstruction { 6 | 7 | private final int regSrc1; 8 | private final int regSrc2; 9 | private final int regDst; 10 | 11 | public SetLessEqual(int regSrc1, int regSrc2, int regDst) { 12 | this.regSrc1 = regSrc1; 13 | this.regSrc2 = regSrc2; 14 | this.regDst = regDst; 15 | } 16 | 17 | public int getRegSrc1() { 18 | return regSrc1; 19 | } 20 | 21 | public int getRegSrc2() { 22 | return regSrc2; 23 | } 24 | 25 | public int getRegDst() { 26 | return regDst; 27 | } 28 | 29 | @Override 30 | public String instrToString() { 31 | return String.format("sle $%s, $%s, $%s", RegisterFile.getRegisterName(regDst), RegisterFile.getRegisterName(regSrc1), RegisterFile.getRegisterName(regSrc2)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/backend/instruction/SetLessEqualImmediate.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | public class SetLessEqualImmediate extends MipsInstruction { 4 | private final int regSrc; 5 | private final int immediate; 6 | private final int regDst; 7 | 8 | public SetLessEqualImmediate(int regSrc, int immediate, int regDst) { 9 | this.regDst = regDst; 10 | this.regSrc = regSrc; 11 | this.immediate = immediate; 12 | } 13 | 14 | public int getRegSrc() { 15 | return regSrc; 16 | } 17 | 18 | public int getImmediate() { 19 | return immediate; 20 | } 21 | 22 | public int getRegDst() { 23 | return regDst; 24 | } 25 | 26 | @Override 27 | public String instrToString() { 28 | return String.format("sle $%s, $%s, %d", regDst, regSrc, immediate); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/backend/instruction/SetLessThan.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class SetLessThan extends MipsInstruction { 6 | 7 | private final int regSrc1; 8 | private final int regSrc2; 9 | private final int regDst; 10 | 11 | public SetLessThan(int regSrc1, int regSrc2, int regDst) { 12 | this.regSrc1 = regSrc1; 13 | this.regSrc2 = regSrc2; 14 | this.regDst = regDst; 15 | } 16 | 17 | public int getRegSrc1() { 18 | return regSrc1; 19 | } 20 | 21 | public int getRegSrc2() { 22 | return regSrc2; 23 | } 24 | 25 | public int getRegDst() { 26 | return regDst; 27 | } 28 | 29 | @Override 30 | public String instrToString() { 31 | return String.format("slt $%s, $%s, $%s", RegisterFile.getRegisterName(regDst), RegisterFile.getRegisterName(regSrc1), RegisterFile.getRegisterName(regSrc2)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/backend/instruction/SetLessThanImmediate.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | public class SetLessThanImmediate extends MipsInstruction { 4 | private final int regSrc; 5 | private final int immediate; 6 | private final int regDst; 7 | 8 | public SetLessThanImmediate(int regSrc, int immediate, int regDst) { 9 | this.regDst = regDst; 10 | this.regSrc = regSrc; 11 | this.immediate = immediate; 12 | } 13 | 14 | public int getRegSrc() { 15 | return regSrc; 16 | } 17 | 18 | public int getImmediate() { 19 | return immediate; 20 | } 21 | 22 | public int getRegDst() { 23 | return regDst; 24 | } 25 | 26 | @Override 27 | public String instrToString() { 28 | return String.format("slti $%s, $%s, %d", regDst, regSrc, immediate); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/backend/instruction/SetNotEqual.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class SetNotEqual extends MipsInstruction { 6 | private final int regSrc1; 7 | private final int regSrc2; 8 | private final int regDst; 9 | 10 | public SetNotEqual(int regSrc1, int regSrc2, int regDst) { 11 | this.regSrc1 = regSrc1; 12 | this.regSrc2 = regSrc2; 13 | this.regDst = regDst; 14 | } 15 | 16 | public int getRegSrc1() { 17 | return regSrc1; 18 | } 19 | 20 | public int getRegSrc2() { 21 | return regSrc2; 22 | } 23 | 24 | public int getRegDst() { 25 | return regDst; 26 | } 27 | 28 | @Override 29 | public String instrToString() { 30 | return String.format("sne $%s, $%s, $%s", RegisterFile.getRegisterName(regDst), RegisterFile.getRegisterName(regSrc1), RegisterFile.getRegisterName(regSrc2)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/backend/instruction/SetNotEqualImmediate.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | public class SetNotEqualImmediate extends MipsInstruction { 4 | private final int regSrc; 5 | private final int immediate; 6 | private final int regDst; 7 | 8 | public SetNotEqualImmediate(int regSrc, int immediate, int regDst) { 9 | this.regDst = regDst; 10 | this.regSrc = regSrc; 11 | this.immediate = immediate; 12 | } 13 | 14 | public int getRegSrc() { 15 | return regSrc; 16 | } 17 | 18 | public int getImmediate() { 19 | return immediate; 20 | } 21 | 22 | public int getRegDst() { 23 | return regDst; 24 | } 25 | 26 | @Override 27 | public String instrToString() { 28 | return String.format("sne $%s, $%s, %d", regDst, regSrc, immediate); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/backend/instruction/ShiftLeft.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class ShiftLeft extends MipsInstruction { 6 | 7 | private final int regDst; 8 | private final int regSrc; 9 | private final int bits; 10 | 11 | public ShiftLeft(int regSrc, int bits, int regDst) { 12 | this.regDst = regDst; 13 | this.regSrc = regSrc; 14 | this.bits = bits; 15 | } 16 | 17 | public int getRegSrc() { 18 | return regSrc; 19 | } 20 | 21 | public int getRegDst() { 22 | return regDst; 23 | } 24 | 25 | public int getBits() { 26 | return bits; 27 | } 28 | 29 | @Override 30 | public String instrToString() { 31 | return String.format("sll $%s, $%s, %d", RegisterFile.getRegisterName(regDst), RegisterFile.getRegisterName(regSrc), bits); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/backend/instruction/ShiftLeftVariable.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class ShiftLeftVariable extends MipsInstruction { 6 | private final int regDst; 7 | private final int regSrc; 8 | private final int regBits; 9 | 10 | public ShiftLeftVariable(int regSrc, int regBits, int regDst) { 11 | this.regDst = regDst; 12 | this.regSrc = regSrc; 13 | this.regBits = regBits; 14 | } 15 | 16 | public int getRegDst() { 17 | return regDst; 18 | } 19 | 20 | public int getRegSrc() { 21 | return regSrc; 22 | } 23 | 24 | public int getRegBits() { 25 | return regBits; 26 | } 27 | 28 | @Override 29 | public String instrToString() { 30 | return String.format("sllv $%s, $%s, $%s", RegisterFile.getRegisterName(regDst), RegisterFile.getRegisterName(regSrc), RegisterFile.getRegisterName(regBits)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/backend/instruction/ShiftRightArithmetic.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class ShiftRightArithmetic extends MipsInstruction { 6 | 7 | private final int regDst; 8 | private final int regSrc; 9 | private final int bits; 10 | 11 | public ShiftRightArithmetic(int regSrc, int bits, int regDst) { 12 | this.regDst = regDst; 13 | this.regSrc = regSrc; 14 | this.bits = bits; 15 | } 16 | 17 | public int getRegDst() { 18 | return regDst; 19 | } 20 | 21 | public int getRegSrc() { 22 | return regSrc; 23 | } 24 | 25 | public int getBits() { 26 | return bits; 27 | } 28 | 29 | @Override 30 | public String instrToString() { 31 | return String.format("sra $%s, $%s, %d", RegisterFile.getRegisterName(regDst), RegisterFile.getRegisterName(regSrc), bits); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/backend/instruction/ShiftRightArithmeticVariable.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class ShiftRightArithmeticVariable extends MipsInstruction { 6 | private final int regDst; 7 | private final int regSrc; 8 | private final int regBits; 9 | 10 | public ShiftRightArithmeticVariable(int regSrc, int regBits, int regDst) { 11 | this.regDst = regDst; 12 | this.regSrc = regSrc; 13 | this.regBits = regBits; 14 | } 15 | 16 | public int getRegDst() { 17 | return regDst; 18 | } 19 | 20 | public int getRegSrc() { 21 | return regSrc; 22 | } 23 | 24 | public int getRegBits() { 25 | return regBits; 26 | } 27 | 28 | @Override 29 | public String instrToString() { 30 | return String.format("srav $%s, $%s, $%s", RegisterFile.getRegisterName(regDst), RegisterFile.getRegisterName(regSrc), RegisterFile.getRegisterName(regBits)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/backend/instruction/StoreByte.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class StoreByte extends MipsInstruction { 6 | private final int regBase; 7 | private final int offset; 8 | private final int regSrc; 9 | 10 | public StoreByte(int regBase, int offset, int regSrc) { 11 | this.regBase = regBase; 12 | this.offset = offset; 13 | this.regSrc = regSrc; 14 | } 15 | 16 | public int getRegBase() { 17 | return regBase; 18 | } 19 | 20 | public int getOffset() { 21 | return offset; 22 | } 23 | 24 | public int getRegSrc() { 25 | return regSrc; 26 | } 27 | 28 | @Override 29 | public String instrToString() { 30 | return String.format("sb $%s, %d($%s)", RegisterFile.getRegisterName(regSrc), offset, RegisterFile.getRegisterName(regBase)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/backend/instruction/StoreHalf.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class StoreHalf extends MipsInstruction { 6 | private final int regBase; 7 | private final int offset; 8 | private final int regSrc; 9 | 10 | public StoreHalf(int regBase, int offset, int regSrc) { 11 | this.regBase = regBase; 12 | this.offset = offset; 13 | this.regSrc = regSrc; 14 | } 15 | 16 | public int getRegBase() { 17 | return regBase; 18 | } 19 | 20 | public int getOffset() { 21 | return offset; 22 | } 23 | 24 | public int getRegSrc() { 25 | return regSrc; 26 | } 27 | 28 | @Override 29 | public String instrToString() { 30 | return String.format("sh $%s, %d($%s)", RegisterFile.getRegisterName(regSrc), offset, RegisterFile.getRegisterName(regBase)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/backend/instruction/StoreWord.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class StoreWord extends MipsInstruction { 6 | 7 | private final int regBase; 8 | private final int offset; 9 | private final int regSrc; 10 | 11 | public StoreWord(int regBase, int offset, int regSrc) { 12 | this.regBase = regBase; 13 | this.offset = offset; 14 | this.regSrc = regSrc; 15 | } 16 | 17 | public int getRegBase() { 18 | return regBase; 19 | } 20 | 21 | public int getOffset() { 22 | return offset; 23 | } 24 | 25 | public int getRegSrc() { 26 | return regSrc; 27 | } 28 | 29 | @Override 30 | public String instrToString() { 31 | return String.format("sw $%s, %d($%s)", RegisterFile.getRegisterName(regSrc), offset, RegisterFile.getRegisterName(regBase)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/backend/instruction/Subu.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class Subu extends MipsInstruction { 6 | 7 | private final int regSrc1; 8 | private final int regSrc2; 9 | private final int regDst; 10 | 11 | public Subu(int regSrc1, int regSrc2, int regDst) { 12 | this.regSrc1 = regSrc1; 13 | this.regSrc2 = regSrc2; 14 | this.regDst = regDst; 15 | } 16 | 17 | public int getRegSrc1() { 18 | return regSrc1; 19 | } 20 | 21 | public int getRegSrc2() { 22 | return regSrc2; 23 | } 24 | 25 | public int getRegDst() { 26 | return regDst; 27 | } 28 | 29 | @Override 30 | public String instrToString() { 31 | return String.format("subu $%s, $%s, $%s", 32 | RegisterFile.getRegisterName(regDst), 33 | RegisterFile.getRegisterName(regSrc1), 34 | RegisterFile.getRegisterName(regSrc2)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/backend/instruction/Syscall.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | public class Syscall extends MipsInstruction { 4 | 5 | public static final int PRINT_INTEGER = 1; 6 | public static final int PRINT_STRING = 4; 7 | public static final int READ_INTEGER = 5; 8 | public static final int TERMINATE = 10; 9 | 10 | @Override 11 | public String instrToString() { 12 | return "syscall"; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/backend/instruction/Xor.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class Xor extends MipsInstruction { 6 | 7 | private final int regSrc1; 8 | private final int regSrc2; 9 | private final int regDst; 10 | 11 | public Xor(int regSrc1, int regSrc2, int regDst) { 12 | this.regSrc1 = regSrc1; 13 | this.regSrc2 = regSrc2; 14 | this.regDst = regDst; 15 | } 16 | 17 | public int getRegSrc1() { 18 | return regSrc1; 19 | } 20 | 21 | public int getRegSrc2() { 22 | return regSrc2; 23 | } 24 | 25 | public int getRegDst() { 26 | return regDst; 27 | } 28 | 29 | @Override 30 | public String instrToString() { 31 | return String.format("xor $%s, $%s, $%s", 32 | RegisterFile.getRegisterName(regDst), 33 | RegisterFile.getRegisterName(regSrc1), 34 | RegisterFile.getRegisterName(regSrc2)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/backend/instruction/Xori.java: -------------------------------------------------------------------------------- 1 | package backend.instruction; 2 | 3 | import backend.hardware.RegisterFile; 4 | 5 | public class Xori extends MipsInstruction { 6 | 7 | private final int regSrc; 8 | private final int immediate; 9 | private final int regDst; 10 | 11 | public Xori(int regSrc, int immediate, int regDst) { 12 | this.regDst = regDst; 13 | this.regSrc = regSrc; 14 | this.immediate = immediate; 15 | } 16 | 17 | public int getRegSrc() { 18 | return regSrc; 19 | } 20 | 21 | public int getImmediate() { 22 | return immediate; 23 | } 24 | 25 | public int getRegDst() { 26 | return regDst; 27 | } 28 | 29 | @Override 30 | public String instrToString() { 31 | return String.format("xori $%s, $%s, %d", RegisterFile.getRegisterName(regDst), RegisterFile.getRegisterName(regSrc), immediate); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/backend/optimize/JumpFollow.java: -------------------------------------------------------------------------------- 1 | package backend.optimize; 2 | 3 | import backend.Mips; 4 | import backend.instruction.JumpLabel; 5 | import backend.instruction.MipsInstruction; 6 | 7 | import java.util.Objects; 8 | 9 | public class JumpFollow implements MipsOptimize { 10 | 11 | public JumpFollow() {} 12 | 13 | @Override 14 | public void optimize(Mips mips) { 15 | MipsInstruction instr = mips.getFirstInstruction(); 16 | while (Objects.nonNull(instr) && instr.hasNext()) { 17 | if (instr instanceof JumpLabel && !instr.hasLabel() 18 | && instr.getJumpTarget().equals(((MipsInstruction) instr.getNext()).getLabel())) { 19 | instr.remove(); 20 | } 21 | instr = (MipsInstruction) instr.getNext(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/backend/optimize/MipsOptimize.java: -------------------------------------------------------------------------------- 1 | package backend.optimize; 2 | 3 | import backend.Mips; 4 | 5 | public interface MipsOptimize { 6 | void optimize(Mips mips); 7 | } 8 | -------------------------------------------------------------------------------- /src/exception/ConstExpException.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class ConstExpException extends FrontendException { 4 | public ConstExpException(int line, String source) { 5 | super("ConstExp not const", line, source); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/exception/EofException.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class EofException extends FrontendException { 4 | public EofException(int line, String syntax) { 5 | super("Unexpected EOF", line, "EOF in " + syntax); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/exception/FrontendException.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | /** 4 | * 词法或语法错误 5 | */ 6 | public abstract class FrontendException extends Exception { 7 | 8 | private final int line; // 出错位置的行号 9 | private final String source; // 出错位置相关的源代码 10 | 11 | public FrontendException(String tag, int line,String source) { 12 | super(String.format("%s at line %d: %s", tag, line, source)); 13 | this.line = line; 14 | this.source = source; 15 | } 16 | 17 | public int getLineNumber() { 18 | return line; 19 | } 20 | 21 | public String getSource() { 22 | return source; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/exception/NoMainFuncException.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class NoMainFuncException extends FrontendException { 4 | public NoMainFuncException(int line, String source) { 5 | super("No main function", line, source); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/exception/UndefinedTokenException.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | /** 4 | * 未识别符号异常 5 | */ 6 | public class UndefinedTokenException extends FrontendException { 7 | public UndefinedTokenException(int line, String source) { 8 | super("Unrecognized token", line, source); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/frontend/error/ErrorTable.java: -------------------------------------------------------------------------------- 1 | package frontend.error; 2 | 3 | import java.util.Iterator; 4 | import java.util.TreeSet; 5 | 6 | public class ErrorTable implements Iterable { 7 | 8 | @Override 9 | public Iterator iterator() { 10 | return errors.iterator(); 11 | } 12 | 13 | public ErrorTable() {} 14 | 15 | private final TreeSet errors = new TreeSet<>(); 16 | 17 | public void add(Error e) { 18 | errors.add(e); 19 | } 20 | 21 | public boolean isEmpty() { 22 | return errors.isEmpty(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/frontend/lexical/TokenList.java: -------------------------------------------------------------------------------- 1 | package frontend.lexical; 2 | 3 | import frontend.lexical.token.Token; 4 | 5 | import java.io.PrintStream; 6 | import java.util.*; 7 | 8 | public class TokenList { 9 | private final List tokens = new LinkedList<>(); 10 | private int maxLineNumber = 0; 11 | 12 | public TokenList() {} 13 | 14 | public void append(Token token) { 15 | tokens.add(token); 16 | maxLineNumber = Math.max(maxLineNumber, token.lineNumber()); 17 | } 18 | 19 | public int getMaxLineNumber() { 20 | return maxLineNumber; 21 | } 22 | 23 | public void output(PrintStream out) { 24 | tokens.forEach(token -> token.output(out)); 25 | } 26 | 27 | public ListIterator listIterator() { 28 | return tokens.listIterator(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/frontend/lexical/token/FormatString.java: -------------------------------------------------------------------------------- 1 | package frontend.lexical.token; 2 | 3 | public class FormatString extends Token { 4 | 5 | /** 6 | * 不包括双引号 7 | */ 8 | private final String inner; 9 | 10 | public FormatString(String str, int line) { 11 | super(Type.STRCON, line, str); 12 | assert str.length() >= 2 && str.charAt(0) == '\"' && str.charAt(str.length() - 1) == '\"'; 13 | this.inner = str.substring(1, str.length() - 1); 14 | // TODO: check invalid character 15 | } 16 | 17 | public String getInner() { 18 | return inner; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/frontend/lexical/token/Ident.java: -------------------------------------------------------------------------------- 1 | package frontend.lexical.token; 2 | 3 | public class Ident extends Token { 4 | 5 | private final String name; 6 | 7 | public Ident(String name, int line) { 8 | super(Type.IDENFR, line, name); 9 | this.name = name; 10 | } 11 | 12 | public String getName() { 13 | return name; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/frontend/lexical/token/IntConst.java: -------------------------------------------------------------------------------- 1 | package frontend.lexical.token; 2 | 3 | public class IntConst extends Token { 4 | 5 | /** 6 | * 32 位有符号整数 7 | */ 8 | private final int value; 9 | 10 | public IntConst(String literal, int line) { 11 | super(Type.INTCON, line, literal); 12 | this.value = Integer.parseInt(literal); 13 | } 14 | 15 | public int getValue() { 16 | return value; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/frontend/lexical/token/ReservedToken.java: -------------------------------------------------------------------------------- 1 | package frontend.lexical.token; 2 | 3 | public class ReservedToken extends Token { 4 | public ReservedToken(Type type, int line, String content) { 5 | super(type, line, content); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/frontend/syntax/Component.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax; 2 | 3 | import java.io.PrintStream; 4 | 5 | /** 6 | * 用于管理语法树成分的输出(按照 "语法分析" 作业的要求) 7 | */ 8 | public interface Component { 9 | void output(PrintStream ps); 10 | } 11 | -------------------------------------------------------------------------------- /src/frontend/syntax/decl/Constable.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.decl; 2 | 3 | /** 4 | * 可能是常量也可能是变量的语法成分实现该接口 5 | */ 6 | public interface Constable { 7 | boolean isConst(); 8 | } 9 | -------------------------------------------------------------------------------- /src/frontend/syntax/decl/ExpInitVal.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.decl; 2 | 3 | import frontend.syntax.expr.multi.Exp; 4 | 5 | import java.io.PrintStream; 6 | 7 | public class ExpInitVal implements InitVal { 8 | 9 | private final boolean constant; 10 | 11 | private final Exp exp; 12 | 13 | public ExpInitVal(boolean constant, Exp exp) { 14 | this.constant = constant; 15 | this.exp = exp; 16 | } 17 | 18 | public Exp getExp() { 19 | return exp; 20 | } 21 | 22 | @Override 23 | public void output(PrintStream ps) { 24 | exp.output(ps); 25 | if (isConst()) { 26 | ps.println(""); 27 | } else { 28 | ps.println(""); 29 | } 30 | } 31 | 32 | @Override 33 | public boolean isConst() { 34 | return constant; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/frontend/syntax/decl/InitVal.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.decl; 2 | 3 | import frontend.syntax.Component; 4 | 5 | public interface InitVal extends Component, Constable { 6 | } 7 | -------------------------------------------------------------------------------- /src/frontend/syntax/expr/multi/AddExp.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.expr.multi; 2 | 3 | import frontend.lexical.token.Token; 4 | 5 | import java.util.List; 6 | 7 | public class AddExp extends MultiExp { 8 | public AddExp(MulExp first, List operators, List operands) { 9 | super(first, operators, operands, ""); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/frontend/syntax/expr/multi/Cond.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.expr.multi; 2 | 3 | import frontend.syntax.Component; 4 | 5 | import java.io.PrintStream; 6 | 7 | public class Cond implements Component { 8 | 9 | private final LOrExp lOrExp; 10 | 11 | public Cond(LOrExp lOrExp) { 12 | this.lOrExp = lOrExp; 13 | } 14 | 15 | public LOrExp getLOrExp() { 16 | return lOrExp; 17 | } 18 | 19 | @Override 20 | public void output(PrintStream ps) { 21 | lOrExp.output(ps); 22 | ps.println(""); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/frontend/syntax/expr/multi/ConstExp.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.expr.multi; 2 | 3 | import java.io.PrintStream; 4 | 5 | /** 6 | * 常量表达式, 要求用到的变量必须是常量 7 | */ 8 | public class ConstExp extends Exp { 9 | public ConstExp(AddExp addExp) { 10 | super(addExp); 11 | } 12 | 13 | @Override 14 | public void output(PrintStream ps) { 15 | getAddExp().output(ps); 16 | ps.println(""); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/frontend/syntax/expr/multi/EqExp.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.expr.multi; 2 | 3 | import frontend.lexical.token.Token; 4 | 5 | import java.util.List; 6 | 7 | public class EqExp extends MultiExp { 8 | public EqExp(RelExp first, List operators, List operands) { 9 | super(first, operators, operands, ""); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/frontend/syntax/expr/multi/Exp.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.expr.multi; 2 | 3 | import frontend.syntax.Component; 4 | 5 | import java.io.PrintStream; 6 | 7 | public class Exp implements Component { 8 | private final AddExp addExp; 9 | 10 | public Exp(AddExp addExp) { 11 | this.addExp = addExp; 12 | } 13 | 14 | public AddExp getAddExp() { 15 | return addExp; 16 | } 17 | 18 | @Override 19 | public void output(PrintStream ps) { 20 | addExp.output(ps); 21 | ps.println(""); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/frontend/syntax/expr/multi/LAndExp.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.expr.multi; 2 | 3 | import frontend.lexical.token.Token; 4 | 5 | import java.util.List; 6 | 7 | public class LAndExp extends MultiExp { 8 | public LAndExp(EqExp first, List operators, List operands) { 9 | super(first, operators, operands, ""); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/frontend/syntax/expr/multi/LOrExp.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.expr.multi; 2 | 3 | import frontend.lexical.token.Token; 4 | 5 | import java.util.List; 6 | 7 | public class LOrExp extends MultiExp { 8 | public LOrExp(LAndExp first, List operators, List operands) { 9 | super(first, operators, operands, ""); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/frontend/syntax/expr/multi/MulExp.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.expr.multi; 2 | 3 | import frontend.lexical.token.Token; 4 | import frontend.syntax.expr.unary.UnaryExp; 5 | 6 | import java.util.List; 7 | 8 | public class MulExp extends MultiExp { 9 | public MulExp(UnaryExp first, List operators, List operands) { 10 | super(first, operators, operands, ""); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/frontend/syntax/expr/multi/RelExp.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.expr.multi; 2 | 3 | import frontend.lexical.token.Token; 4 | 5 | import java.util.List; 6 | 7 | public class RelExp extends MultiExp { 8 | public RelExp(AddExp first, List operators, List operands) { 9 | super(first, operators, operands, ""); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/frontend/syntax/expr/unary/BasePrimaryExp.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.expr.unary; 2 | 3 | public interface BasePrimaryExp extends BaseUnaryExp { 4 | } 5 | -------------------------------------------------------------------------------- /src/frontend/syntax/expr/unary/BaseUnaryExp.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.expr.unary; 2 | 3 | import frontend.syntax.Component; 4 | 5 | public interface BaseUnaryExp extends Component { 6 | } 7 | -------------------------------------------------------------------------------- /src/frontend/syntax/expr/unary/Number.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.expr.unary; 2 | 3 | import frontend.lexical.token.IntConst; 4 | 5 | import java.io.PrintStream; 6 | 7 | public class Number implements BasePrimaryExp { 8 | 9 | private final IntConst value; 10 | 11 | public Number(IntConst value) { 12 | this.value = value; 13 | } 14 | 15 | public IntConst getValue() { 16 | return value; 17 | } 18 | 19 | @Override 20 | public void output(PrintStream ps) { 21 | value.output(ps); 22 | ps.println(""); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/frontend/syntax/expr/unary/PrimaryExp.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.expr.unary; 2 | 3 | import java.io.PrintStream; 4 | 5 | public class PrimaryExp implements BaseUnaryExp { 6 | 7 | private final BasePrimaryExp base; 8 | 9 | public PrimaryExp(BasePrimaryExp base) { 10 | this.base = base; 11 | } 12 | 13 | public BasePrimaryExp getBase() { 14 | return base; 15 | } 16 | 17 | @Override 18 | public void output(PrintStream ps) { 19 | base.output(ps); 20 | ps.println(""); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/frontend/syntax/stmt/complex/BlockItem.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.stmt.complex; 2 | 3 | import frontend.syntax.Component; 4 | 5 | public interface BlockItem extends Component { 6 | } 7 | -------------------------------------------------------------------------------- /src/frontend/syntax/stmt/complex/CplStmt.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.stmt.complex; 2 | 3 | import frontend.syntax.Component; 4 | 5 | /** 6 | * 复杂语句, 通常一行以内结束不了,且不一定以分号结尾,包括 if, while, block 7 | */ 8 | public interface CplStmt extends Component { 9 | } 10 | -------------------------------------------------------------------------------- /src/frontend/syntax/stmt/simple/AssignStmt.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.stmt.simple; 2 | 3 | import frontend.lexical.token.Token; 4 | import frontend.syntax.expr.multi.Exp; 5 | import frontend.syntax.expr.unary.LVal; 6 | 7 | import java.io.PrintStream; 8 | 9 | public class AssignStmt implements SplStmt { 10 | 11 | private final LVal leftVal; 12 | private final Token assignTk; 13 | private final Exp exp; 14 | 15 | public AssignStmt(LVal leftVal, Token assignTk, Exp exp) { 16 | this.leftVal = leftVal; 17 | this.assignTk = assignTk; 18 | this.exp = exp; 19 | } 20 | 21 | public LVal getLeftVal() { 22 | return leftVal; 23 | } 24 | 25 | public Token getAssignTk() { 26 | return assignTk; 27 | } 28 | 29 | public Exp getExp() { 30 | return exp; 31 | } 32 | 33 | @Override 34 | public void output(PrintStream ps) { 35 | leftVal.output(ps); 36 | assignTk.output(ps); 37 | exp.output(ps); 38 | } 39 | 40 | @Override 41 | public int lineNumber() { 42 | return leftVal.getName().lineNumber(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/frontend/syntax/stmt/simple/BreakStmt.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.stmt.simple; 2 | 3 | import frontend.lexical.token.Token; 4 | 5 | import java.io.PrintStream; 6 | 7 | public class BreakStmt implements SplStmt { 8 | 9 | private final Token breakTk; 10 | 11 | public BreakStmt(Token breakTk) { 12 | assert Token.Type.BREAKTK.equals(breakTk.getType()); 13 | this.breakTk = breakTk; 14 | } 15 | 16 | public Token getBreakTk() { 17 | return breakTk; 18 | } 19 | 20 | @Override 21 | public void output(PrintStream ps) { 22 | breakTk.output(ps); 23 | } 24 | 25 | @Override 26 | public int lineNumber() { 27 | return breakTk.lineNumber(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/frontend/syntax/stmt/simple/ContinueStmt.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.stmt.simple; 2 | 3 | import frontend.lexical.token.Token; 4 | 5 | import java.io.PrintStream; 6 | 7 | public class ContinueStmt implements SplStmt { 8 | 9 | private final Token continueTk; 10 | 11 | public ContinueStmt(Token continueTk) { 12 | assert Token.Type.CONTINUETK.equals(continueTk.getType()); 13 | this.continueTk = continueTk; 14 | } 15 | 16 | public Token getContinueTk() { 17 | return continueTk; 18 | } 19 | 20 | @Override 21 | public void output(PrintStream ps) { 22 | continueTk.output(ps); 23 | } 24 | 25 | @Override 26 | public int lineNumber() { 27 | return continueTk.lineNumber(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/frontend/syntax/stmt/simple/SplStmt.java: -------------------------------------------------------------------------------- 1 | package frontend.syntax.stmt.simple; 2 | 3 | import frontend.syntax.Component; 4 | 5 | /** 6 | * 以分号结尾的 (通常在一行以内的) 简单语句 (不包括分号), 包括赋值语句, 表达式语句, break/continue 语句,return 语句,输入输出语句 7 | * 输出自己时不输出名字,因为完整的 Stmt 需要分号 8 | */ 9 | public interface SplStmt extends Component { 10 | public int lineNumber(); 11 | } 12 | -------------------------------------------------------------------------------- /src/middle/code/AddressOffset.java: -------------------------------------------------------------------------------- 1 | package middle.code; 2 | 3 | import middle.operand.Operand; 4 | import middle.symbol.Symbol; 5 | 6 | /** 7 | * 寻址操作 8 | */ 9 | public class AddressOffset extends ILinkNode { 10 | private final Symbol base; // pointer or array 11 | private final Operand offset; 12 | private final Symbol target; // pointer 13 | 14 | public AddressOffset(Symbol base, Operand offset, Symbol target) { 15 | assert base.getRefType().equals(Symbol.RefType.POINTER) || base.getRefType().equals(Symbol.RefType.ARRAY); 16 | assert target.getRefType().equals(Symbol.RefType.POINTER); 17 | this.base = base; 18 | this.offset = offset; 19 | this.target = target; 20 | } 21 | 22 | public Symbol getBase() { 23 | return base; 24 | } 25 | 26 | public Operand getOffset() { 27 | return offset; 28 | } 29 | 30 | public Symbol getTarget() { 31 | return target; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "OFFSET " + base + ", " + offset + ", " + target; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/middle/code/BranchIfElse.java: -------------------------------------------------------------------------------- 1 | package middle.code; 2 | 3 | import middle.operand.Operand; 4 | 5 | /** 6 | * 双分支 7 | */ 8 | public class BranchIfElse extends ILinkNode { 9 | private final Operand condition; 10 | private final BasicBlock thenTarget; 11 | private final BasicBlock elseTarget; 12 | 13 | public BranchIfElse(Operand condition, BasicBlock thenTarget, BasicBlock elseTarget) { 14 | this.condition = condition; 15 | this.thenTarget = thenTarget; 16 | this.elseTarget = elseTarget; 17 | } 18 | 19 | public Operand getCondition() { 20 | return condition; 21 | } 22 | 23 | public BasicBlock getThenTarget() { 24 | return thenTarget; 25 | } 26 | 27 | public BasicBlock getElseTarget() { 28 | return elseTarget; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return "BR " + condition + " ? " + thenTarget + " : " + elseTarget; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/middle/code/Input.java: -------------------------------------------------------------------------------- 1 | package middle.code; 2 | 3 | 4 | import middle.symbol.Symbol; 5 | 6 | public class Input extends ILinkNode { 7 | private final Symbol dst; 8 | 9 | public Input(Symbol dst) { 10 | this.dst = dst; 11 | } 12 | 13 | public Symbol getDst() { 14 | return dst; 15 | } 16 | 17 | @Override 18 | public String toString() { 19 | return "INPUT " + dst; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/middle/code/Jump.java: -------------------------------------------------------------------------------- 1 | package middle.code; 2 | 3 | /** 4 | * 无条件跳转 5 | */ 6 | public class Jump extends ILinkNode { 7 | 8 | private final BasicBlock target; 9 | 10 | public Jump(BasicBlock target) { 11 | this.target = target; 12 | } 13 | 14 | public BasicBlock getTarget() { 15 | return target; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return "J " + target.getLabel(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/middle/code/PrintInt.java: -------------------------------------------------------------------------------- 1 | package middle.code; 2 | 3 | import middle.operand.Operand; 4 | 5 | /** 6 | * 输出整数,对应 Mars 的 1 号 syscall 7 | */ 8 | public class PrintInt extends ILinkNode { 9 | private final Operand value; 10 | 11 | public PrintInt(Operand value) { 12 | this.value = value; 13 | } 14 | 15 | public Operand getValue() { 16 | return value; 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | return "PRINT_INT " + value; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/middle/code/PrintStr.java: -------------------------------------------------------------------------------- 1 | package middle.code; 2 | 3 | /** 4 | * 输出字符串,对应 Mars 的 4 号 syscall 5 | * 参数是代表这个字符串首地址的标签 6 | */ 7 | public class PrintStr extends ILinkNode { 8 | private final String label; 9 | 10 | public PrintStr(String label) { 11 | this.label = label; 12 | } 13 | 14 | public String getLabel() { 15 | return label; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return "PRINT_STR " + label; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/middle/code/Return.java: -------------------------------------------------------------------------------- 1 | package middle.code; 2 | 3 | import middle.operand.Operand; 4 | 5 | import java.util.Objects; 6 | 7 | /** 8 | * 从函数中返回 9 | */ 10 | public class Return extends ILinkNode { 11 | private final Operand value; // Nullable 12 | 13 | public Return() { 14 | this.value = null; 15 | } 16 | 17 | public Return(Operand value) { 18 | this.value = value; 19 | } 20 | 21 | public Operand getValue() { 22 | return value; 23 | } 24 | 25 | public boolean hasValue() { 26 | return Objects.nonNull(value); 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "RETURN" + (hasValue() ? " " + value : ""); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/middle/code/UnaryOp.java: -------------------------------------------------------------------------------- 1 | package middle.code; 2 | 3 | import middle.operand.Operand; 4 | import middle.symbol.Symbol; 5 | 6 | /** 7 | * 一元运算 8 | */ 9 | public class UnaryOp extends ILinkNode { 10 | public enum Op { 11 | MOV, // INT to INT 12 | NEG, // INT to INT 13 | NOT, // INT to INT 14 | CLO, // INT to INT 15 | CLZ, // INT to INT 16 | ABS, // INT to INT 17 | } 18 | 19 | private final Op op; 20 | private final Operand src; 21 | private final Symbol dst; 22 | 23 | public UnaryOp(Op op, Operand src, Symbol dst) { 24 | this.op = op; 25 | this.src = src; 26 | this.dst = dst; 27 | } 28 | 29 | public Op getOp() { 30 | return op; 31 | } 32 | 33 | public Operand getSrc() { 34 | return src; 35 | } 36 | 37 | public Symbol getDst() { 38 | return dst; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return op.name() + " " + src + ", " + dst; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/middle/operand/Immediate.java: -------------------------------------------------------------------------------- 1 | package middle.operand; 2 | 3 | /** 4 | * 中间代码中的立即数 5 | */ 6 | public class Immediate implements Operand { 7 | private final int value; 8 | 9 | public Immediate(int value) { 10 | this.value = value; 11 | } 12 | 13 | public int getValue() { 14 | return value; 15 | } 16 | 17 | @Override 18 | public String toString() { 19 | return Integer.toString(value); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/middle/operand/Operand.java: -------------------------------------------------------------------------------- 1 | package middle.operand; 2 | 3 | /** 4 | * 中间代码的操作数 5 | */ 6 | public interface Operand { 7 | } 8 | -------------------------------------------------------------------------------- /src/middle/optimize/MidOptimizer.java: -------------------------------------------------------------------------------- 1 | package middle.optimize; 2 | 3 | import middle.MiddleCode; 4 | import middle.code.BasicBlock; 5 | import middle.code.BranchIfElse; 6 | import middle.code.ILinkNode; 7 | import middle.code.Jump; 8 | 9 | import java.util.Queue; 10 | 11 | /** 12 | * 中间代码优化的基本接口 13 | */ 14 | public interface MidOptimizer { 15 | void optimize(MiddleCode ir); 16 | 17 | default void detectBranch(ILinkNode node, Queue queue) { 18 | if (node instanceof Jump) { 19 | queue.offer(((Jump) node).getTarget()); 20 | } else if (node instanceof BranchIfElse) { 21 | queue.offer(((BranchIfElse) node).getThenTarget()); 22 | queue.offer(((BranchIfElse) node).getElseTarget()); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/utility/ReaderUtil.java: -------------------------------------------------------------------------------- 1 | package utility; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | 6 | public class ReaderUtil { 7 | 8 | private ReaderUtil() {} 9 | 10 | public static int readInt(BufferedReader input) { 11 | try { 12 | int c = input.read(); 13 | int value = 0; 14 | boolean negative = false; 15 | while (c != -1 && !(c >= 48 && c <= 57)) { 16 | if (c == 45) { // '-' 17 | negative = true; 18 | } 19 | c = input.read(); 20 | } 21 | if (c == -1) { 22 | return -1; 23 | } 24 | while ((c >= 48 && c <= 57)) { 25 | value = value * 10 + (c - 48); 26 | c = input.read(); 27 | } 28 | return negative ? -value : value; 29 | } catch (IOException e) { 30 | throw new AssertionError(e); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /testfile/2021/A/input10.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 -------------------------------------------------------------------------------- /testfile/2021/A/input11.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 2 3 | 1 -------------------------------------------------------------------------------- /testfile/2021/A/input12.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2021/A/input12.txt -------------------------------------------------------------------------------- /testfile/2021/A/input13.txt: -------------------------------------------------------------------------------- 1 | 123 2 | 456 3 | 12 4 | 324 -------------------------------------------------------------------------------- /testfile/2021/A/input14.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 0 3 | 1 4 | 6 5 | 8 6 | 20 7 | 30 8 | -------------------------------------------------------------------------------- /testfile/2021/A/input15.txt: -------------------------------------------------------------------------------- 1 | 200 2 | -------------------------------------------------------------------------------- /testfile/2021/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 -------------------------------------------------------------------------------- /testfile/2021/A/input17.txt: -------------------------------------------------------------------------------- 1 | 33 2 | 28 3 | 501 4 | 233 5 | 114 6 | 711 7 | 266 8 | 500 9 | 77 -------------------------------------------------------------------------------- /testfile/2021/A/input18.txt: -------------------------------------------------------------------------------- 1 | 9 2 | 8 3 | 7 4 | 6 5 | 5 6 | 4 7 | 3 8 | 2 9 | 1 10 | -------------------------------------------------------------------------------- /testfile/2021/A/input19.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/A/input20.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 1 -------------------------------------------------------------------------------- /testfile/2021/A/input21.txt: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /testfile/2021/A/input22.txt: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testfile/2021/A/input23.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 -------------------------------------------------------------------------------- /testfile/2021/A/input24.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 3 4 | -------------------------------------------------------------------------------- /testfile/2021/A/input25.txt: -------------------------------------------------------------------------------- 1 | 24 2 | 27 3 | 342526 4 | -------------------------------------------------------------------------------- /testfile/2021/A/input26.txt: -------------------------------------------------------------------------------- 1 | 3 -------------------------------------------------------------------------------- /testfile/2021/A/input3.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /testfile/2021/A/input4.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2021/A/input4.txt -------------------------------------------------------------------------------- /testfile/2021/A/input5.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2021/A/input5.txt -------------------------------------------------------------------------------- /testfile/2021/A/input6.txt: -------------------------------------------------------------------------------- 1 | 4 -------------------------------------------------------------------------------- /testfile/2021/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 -------------------------------------------------------------------------------- /testfile/2021/A/input8.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 -------------------------------------------------------------------------------- /testfile/2021/A/input9.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 12 -------------------------------------------------------------------------------- /testfile/2021/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 -------------------------------------------------------------------------------- /testfile/2021/A/output11.txt: -------------------------------------------------------------------------------- 1 | 19182620 2 | 0 3 | 1 4 | 2 5 | 2 6 | 1 7 | 2 8 | 19182620 9 | 19182620 10 | 19182620 11 | -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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!!! -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/A/output26.txt: -------------------------------------------------------------------------------- 1 | 19373630 2 | 1 3 | 120 4 | 720 5 | 5040 6 | 1 7 | 2 8 | 4 9 | 3 10 | 30250 11 | -------------------------------------------------------------------------------- /testfile/2021/A/output3.txt: -------------------------------------------------------------------------------- 1 | 19373734 2 | 19373734 3 | 19373734 4 | 19373734 5 | 19373734 6 | 19373734 7 | 19373734 8 | 19373734 9 | 19373734 10 | 19373734 -------------------------------------------------------------------------------- /testfile/2021/A/output4.txt: -------------------------------------------------------------------------------- 1 | 19231258 OK1 2 | OK2 3 | OK3 4 | OK4 5 | OK5 6 | OK6 7 | OK7 8 | OK8 9 | OK9 -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/A/output7.txt: -------------------------------------------------------------------------------- 1 | 19182604 2 | 0 3 | 1 4 | 2 5 | 3 6 | 4 7 | 5 8 | 6 9 | 7 10 | 8 11 | 12 | -------------------------------------------------------------------------------- /testfile/2021/A/output8.txt: -------------------------------------------------------------------------------- 1 | 19182619 2 | CscanfOK 3 | DscanfOK 4 | sb:2 5 | continueOK 6 | breakOK 7 | 0Func2OK 8 | Func3OK 9 | Func4OK 10 | end -------------------------------------------------------------------------------- /testfile/2021/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 -------------------------------------------------------------------------------- /testfile/2021/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 | } -------------------------------------------------------------------------------- /testfile/2021/B/input1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2021/B/input1.txt -------------------------------------------------------------------------------- /testfile/2021/B/input10.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 4 4 | 5 -------------------------------------------------------------------------------- /testfile/2021/B/input11.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 2 3 | 3 4 | 1 5 | 0 -------------------------------------------------------------------------------- /testfile/2021/B/input12.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2021/B/input12.txt -------------------------------------------------------------------------------- /testfile/2021/B/input13.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 4 3 | -------------------------------------------------------------------------------- /testfile/2021/B/input14.txt: -------------------------------------------------------------------------------- 1 | 1150 -------------------------------------------------------------------------------- /testfile/2021/B/input15.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 4 4 | 5 -------------------------------------------------------------------------------- /testfile/2021/B/input16.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2021/B/input16.txt -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/B/input18.txt: -------------------------------------------------------------------------------- 1 | 123 2 | 0 3 | -234 -------------------------------------------------------------------------------- /testfile/2021/B/input19.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /testfile/2021/B/input2.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 2 3 | -------------------------------------------------------------------------------- /testfile/2021/B/input20.txt: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testfile/2021/B/input21.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2021/B/input21.txt -------------------------------------------------------------------------------- /testfile/2021/B/input22.txt: -------------------------------------------------------------------------------- 1 | 11 -------------------------------------------------------------------------------- /testfile/2021/B/input23.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 9 -------------------------------------------------------------------------------- /testfile/2021/B/input24.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2021/B/input24.txt -------------------------------------------------------------------------------- /testfile/2021/B/input25.txt: -------------------------------------------------------------------------------- 1 | 23 2 | 26 3 | 353 4 | -------------------------------------------------------------------------------- /testfile/2021/B/input26.txt: -------------------------------------------------------------------------------- 1 | 13 2 | 29 3 | 37 4 | -------------------------------------------------------------------------------- /testfile/2021/B/input27.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /testfile/2021/B/input3.txt: -------------------------------------------------------------------------------- 1 | 9 2 | 8 3 | 7 4 | 6 5 | -------------------------------------------------------------------------------- /testfile/2021/B/input4.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2021/B/input4.txt -------------------------------------------------------------------------------- /testfile/2021/B/input5.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 20 3 | 30 -------------------------------------------------------------------------------- /testfile/2021/B/input6.txt: -------------------------------------------------------------------------------- 1 | 12308760 2 | -------------------------------------------------------------------------------- /testfile/2021/B/input7.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /testfile/2021/B/input8.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 8 3 | 7 4 | 6 5 | 5 6 | 4 7 | 3 8 | 2 9 | 1 10 | -------------------------------------------------------------------------------- /testfile/2021/B/input9.txt: -------------------------------------------------------------------------------- 1 | 10 -------------------------------------------------------------------------------- /testfile/2021/B/output1.txt: -------------------------------------------------------------------------------- 1 | 19373749 2 | 4 3 | 2 4 | no 5 | 0 6 | 0 7 | 0 8 | 1 9 | 1 10 | -1 -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 -------------------------------------------------------------------------------- /testfile/2021/B/output12.txt: -------------------------------------------------------------------------------- 1 | 19182622 2 | 19182622 3 | 19182622 4 | 19182622 5 | 19182622 6 | 19182622 7 | 19182622 8 | 19182622 9 | 19182622 10 | 19182622 -------------------------------------------------------------------------------- /testfile/2021/B/output14.txt: -------------------------------------------------------------------------------- 1 | 19373459 2 | f1: 8221 3 | f0: 0 4 | ori00:5577 5 | -------------------------------------------------------------------------------- /testfile/2021/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 -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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{|}~ -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/B/output22.txt: -------------------------------------------------------------------------------- 1 | 19373339 2 | 2 3 | 3 4 | 4 5 | 13 6 | 2 7 | 123456 8 | 123456 9 | 123456 -------------------------------------------------------------------------------- /testfile/2021/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. -------------------------------------------------------------------------------- /testfile/2021/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 -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/B/output27.txt: -------------------------------------------------------------------------------- 1 | 1837518218183751821837518218375182 -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 -------------------------------------------------------------------------------- /testfile/2021/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 -------------------------------------------------------------------------------- /testfile/2021/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 -------------------------------------------------------------------------------- /testfile/2021/B/output7.txt: -------------------------------------------------------------------------------- 1 | 19231188111111111 -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/B/output9.txt: -------------------------------------------------------------------------------- 1 | 193733852345678910 -------------------------------------------------------------------------------- /testfile/2021/B/testfile12.txt: -------------------------------------------------------------------------------- 1 | void printMyID(int id) 2 | { 3 | int i = 5; 4 | while(i >= 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 | } -------------------------------------------------------------------------------- /testfile/2021/B/testfile5.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2021/B/testfile5.txt -------------------------------------------------------------------------------- /testfile/2021/C/input1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2021/C/input1.txt -------------------------------------------------------------------------------- /testfile/2021/C/input10.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2021/C/input10.txt -------------------------------------------------------------------------------- /testfile/2021/C/input11.txt: -------------------------------------------------------------------------------- 1 | 5 -------------------------------------------------------------------------------- /testfile/2021/C/input12.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2021/C/input12.txt -------------------------------------------------------------------------------- /testfile/2021/C/input13.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | -------------------------------------------------------------------------------- /testfile/2021/C/input14.txt: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /testfile/2021/C/input15.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 4 4 | 5 -------------------------------------------------------------------------------- /testfile/2021/C/input16.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 15 3 | 6 4 | 6 -------------------------------------------------------------------------------- /testfile/2021/C/input17.txt: -------------------------------------------------------------------------------- 1 | 12345 2 | -------------------------------------------------------------------------------- /testfile/2021/C/input18.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 0 4 | -1 5 | 1 6 | 2 7 | 2 8 | -1 9 | 2 10 | 2 11 | -------------------------------------------------------------------------------- /testfile/2021/C/input19.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2021/C/input19.txt -------------------------------------------------------------------------------- /testfile/2021/C/input2.txt: -------------------------------------------------------------------------------- 1 | 54633487 2 | 632917 3 | 30 -------------------------------------------------------------------------------- /testfile/2021/C/input20.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /testfile/2021/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 -------------------------------------------------------------------------------- /testfile/2021/C/input22.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /testfile/2021/C/input23.txt: -------------------------------------------------------------------------------- 1 | 0 -------------------------------------------------------------------------------- /testfile/2021/C/input24.txt: -------------------------------------------------------------------------------- 1 | 19260817 2 | 114514 3 | 1919810 4 | 4 5 | 16 6 | 13 -------------------------------------------------------------------------------- /testfile/2021/C/input25.txt: -------------------------------------------------------------------------------- 1 | 11 2 | 13 3 | 12341 4 | -------------------------------------------------------------------------------- /testfile/2021/C/input26.txt: -------------------------------------------------------------------------------- 1 | 33 -------------------------------------------------------------------------------- /testfile/2021/C/input27.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | -------------------------------------------------------------------------------- /testfile/2021/C/input28.txt: -------------------------------------------------------------------------------- 1 | 6 -------------------------------------------------------------------------------- /testfile/2021/C/input29.txt: -------------------------------------------------------------------------------- 1 | 233 2 | 1 3 | 42 4 | -15 5 | 0 6 | -------------------------------------------------------------------------------- /testfile/2021/C/input3.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 23 3 | 3 4 | 4 5 | 52 6 | 6 7 | 7 8 | 8 9 | 99 10 | -------------------------------------------------------------------------------- /testfile/2021/C/input4.txt: -------------------------------------------------------------------------------- 1 | 56 -------------------------------------------------------------------------------- /testfile/2021/C/input5.txt: -------------------------------------------------------------------------------- 1 | -4 2 | 0 3 | 1 4 | 2 5 | 3 6 | 4 7 | 5 8 | 6 9 | 7 10 | 8 11 | -------------------------------------------------------------------------------- /testfile/2021/C/input6.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2021/C/input6.txt -------------------------------------------------------------------------------- /testfile/2021/C/input7.txt: -------------------------------------------------------------------------------- 1 | 123 -------------------------------------------------------------------------------- /testfile/2021/C/input8.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2021/C/input8.txt -------------------------------------------------------------------------------- /testfile/2021/C/input9.txt: -------------------------------------------------------------------------------- 1 | 9 2 | 8 3 | 7 4 | 6 5 | 5 6 | 4 7 | 3 8 | 2 9 | 1 10 | -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/C/output10.txt: -------------------------------------------------------------------------------- 1 | 19373025 2 | 1 3 | funi 4 | try 5 | try 6 | try 7 | try 8 | try 9 | try 10 | try -------------------------------------------------------------------------------- /testfile/2021/C/output11.txt: -------------------------------------------------------------------------------- 1 | 19182650 2 | this is d 3 | 4 4 | 5 5 | 4 6 | 5 7 | 2 -------------------------------------------------------------------------------- /testfile/2021/C/output12.txt: -------------------------------------------------------------------------------- 1 | 19182623 2 | -------------------------------------------------------------------------------- /testfile/2021/C/output13.txt: -------------------------------------------------------------------------------- 1 | 10, 30972, -5 -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 -------------------------------------------------------------------------------- /testfile/2021/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 -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/C/output18.txt: -------------------------------------------------------------------------------- 1 | 19373719 2 | 0 -2 3 | 0 2 4 | 4 5 | 0 6 | -------------------------------------------------------------------------------- /testfile/2021/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 -------------------------------------------------------------------------------- /testfile/2021/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. -------------------------------------------------------------------------------- /testfile/2021/C/output20.txt: -------------------------------------------------------------------------------- 1 | 19373061 2 | 0 3 | 1 4 | 0 5 | 0 6 | 1 7 | 0 8 | 1 9 | 0 10 | t:1 -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/C/output22.txt: -------------------------------------------------------------------------------- 1 | 19373034 2 | 1 3 | 1 4 | 0 5 | 1 6 | 0 7 | 10 8 | 8 9 | 9 10 | 10 -------------------------------------------------------------------------------- /testfile/2021/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 -------------------------------------------------------------------------------- /testfile/2021/C/output24.txt: -------------------------------------------------------------------------------- 1 | 19373022 2 | b:-19260604 3 | Bool1 is false! 4 | 1919820 5 | 1932053504 6 | -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 36 | -------------------------------------------------------------------------------- /testfile/2021/C/output4.txt: -------------------------------------------------------------------------------- 1 | 19231204 2 | The score is 56. 3 | Yes! 4 | Yes! 5 | Yes! 6 | No! -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 -------------------------------------------------------------------------------- /testfile/2021/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! -------------------------------------------------------------------------------- /testfile/2021/C/output8.txt: -------------------------------------------------------------------------------- 1 | 19182650 2 | 1 3 | 2 4 | 3 5 | 4 6 | 5 7 | 6 8 | 21 9 | 1 10 | 6 -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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) _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 | } -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/C/testfile21.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2021/C/testfile21.txt -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/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 | } -------------------------------------------------------------------------------- /testfile/2021/C/testfile6.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2021/C/testfile6.txt -------------------------------------------------------------------------------- /testfile/2021/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 | -------------------------------------------------------------------------------- /testfile/2021/myself/input2.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | -1 4 | -1906 5 | 5 6 | 3 7 | -2 8 | -1906 9 | 3 10 | 8 11 | -3 12 | -1906 13 | 12 14 | 4 15 | -4 16 | -1906 17 | 15 18 | 6 19 | -5 20 | -1906 21 | 3 22 | 8 23 | -1 24 | 5 25 | 3 26 | -1 27 | -3 28 | -1906 29 | 1 30 | 2 31 | -1 32 | 3 33 | -1 34 | 4 35 | -1 36 | 5 37 | -1 38 | 6 39 | -1 40 | 7 41 | -1 42 | 8 43 | -1 44 | 9 45 | -1 46 | 10 47 | -1 48 | -1906 49 | 1 50 | 2 51 | -3 52 | 3 53 | -3 54 | 4 55 | -3 56 | 5 57 | -3 58 | 6 59 | -3 60 | 7 61 | -3 62 | 8 63 | -3 64 | 9 65 | -3 66 | 10 67 | -3 68 | -1906 69 | 0 70 | 10 71 | -3 72 | 1 73 | -1 74 | 10 75 | -3 76 | 9 77 | -1 78 | 10 79 | -3 80 | 0 81 | -1 82 | 10 83 | -3 84 | 6 85 | -1 86 | -1906 87 | 1906 88 | 1952 89 | -3 90 | 2 91 | -3 92 | 1026 93 | 921 94 | -3 95 | 4000 96 | 97 97 | -5 98 | -3 99 | -1 100 | 23 101 | 24 102 | -3 103 | 27 104 | -3 105 | 9 106 | -4 107 | 21 108 | -3 109 | -1 110 | 1999 111 | 2333 112 | 2 113 | -3 114 | -3 115 | -2 116 | 113 117 | 117 118 | -3 119 | 113 120 | -3 121 | -2 122 | 17 123 | 17 124 | -3 125 | 2 126 | -3 127 | 5 128 | 5 129 | -3 130 | -3 131 | -2 132 | 410 133 | -2 134 | -1906 -------------------------------------------------------------------------------- /testfile/2021/myself/input3.txt: -------------------------------------------------------------------------------- 1 | 10 -------------------------------------------------------------------------------- /testfile/2021/myself/input4.txt: -------------------------------------------------------------------------------- 1 | 100 2 | 1 3 | 2 4 | 3 5 | 4 6 | 5 7 | 6 8 | 7 9 | 8 10 | 9 11 | 10 12 | 11 13 | 12 14 | 13 15 | 14 16 | 15 17 | 16 18 | 17 19 | 18 20 | 19 21 | 20 22 | 21 23 | 22 24 | 23 25 | 24 26 | 25 27 | 26 28 | 27 29 | 28 30 | 29 31 | 30 32 | 31 33 | 32 34 | 33 35 | 34 36 | 35 37 | 36 38 | 37 39 | 38 40 | 39 41 | 40 42 | 41 43 | 42 44 | 43 45 | 44 46 | 45 47 | 46 48 | 47 49 | 48 50 | 49 51 | 50 52 | 51 53 | 52 54 | 53 55 | 54 56 | 55 57 | 56 58 | 57 59 | 58 60 | 59 61 | 60 62 | 61 63 | 62 64 | 63 65 | 64 66 | 65 67 | 66 68 | 67 69 | 68 70 | 69 71 | 70 72 | 71 73 | 72 74 | 73 75 | 74 76 | 75 77 | 76 78 | 77 79 | 78 80 | 79 81 | 80 82 | 81 83 | 82 84 | 83 85 | 84 86 | 85 87 | 86 88 | 87 89 | 88 90 | 89 91 | 90 92 | 91 93 | 92 94 | 93 95 | 94 96 | 95 97 | 96 98 | 97 99 | 98 100 | 99 101 | 100 102 | -------------------------------------------------------------------------------- /testfile/2021/myself/testfile4.txt: -------------------------------------------------------------------------------- 1 | /* Testfile 5 */ 2 | 3 | // Author: 18375354 4 | 5 | int main() { 6 | printf("18375354\n"); 7 | int n, T, cnt, _T = 1; 8 | int _Step_Sum0 = 0; 9 | printf("Collatz conjecture\n"); 10 | printf("Rule: if n is odd, turn it to %d * n + %d; else divide n by %d\n", 3, 1, 2); 11 | T = getint(); 12 | printf("Total %d testcases.\n", T); 13 | while (1 <= T) { 14 | n = getint(); 15 | printf("- case %d: ", _T); 16 | _T = _T + 1; 17 | printf("Get %d ......\n", n); 18 | cnt = 0; 19 | while (n > 1) { 20 | cnt = cnt * 1 + cnt * 2 + 5 - +-+-3 - cnt * (9 / 3 - 1); 21 | if (n % 2 == 0) { 22 | printf("%d is even, /2 = %d; ", n, n / 2); 23 | n = n / 2; 24 | continue; 25 | } else ; 26 | printf("%d is odd, *3+1 = %d; ", n, n * 3 + 1); 27 | n = 1 + 3 * n; 28 | } 29 | printf("\nDone, total %d steps.\n", cnt); 30 | _Step_Sum0 = cnt + _Step_Sum0; 31 | T = T - 1; 32 | } 33 | printf("All cost steps: %d\n", _Step_Sum0); 34 | 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /testfile/2022/A/input1.txt: -------------------------------------------------------------------------------- 1 | 3 2 | 4 3 | -------------------------------------------------------------------------------- /testfile/2022/A/input10.txt: -------------------------------------------------------------------------------- 1 | 555 2 | -------------------------------------------------------------------------------- /testfile/2022/A/input11.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/A/input11.txt -------------------------------------------------------------------------------- /testfile/2022/A/input12.txt: -------------------------------------------------------------------------------- 1 | 4 -------------------------------------------------------------------------------- /testfile/2022/A/input13.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 7 3 | 1 4 | 2 5 | 3 6 | 2 7 | 3 8 | 4 9 | 3 10 | 4 11 | 5 12 | 4 13 | 5 14 | 6 15 | -------------------------------------------------------------------------------- /testfile/2022/A/input14.txt: -------------------------------------------------------------------------------- 1 | 10 -------------------------------------------------------------------------------- /testfile/2022/A/input15.txt: -------------------------------------------------------------------------------- 1 | 2021 -------------------------------------------------------------------------------- /testfile/2022/A/input16.txt: -------------------------------------------------------------------------------- 1 | 123 2 | 456 3 | 789 -------------------------------------------------------------------------------- /testfile/2022/A/input17.txt: -------------------------------------------------------------------------------- 1 | 20373381 2 | 321 3 | 111 4 | 2233 5 | 10086 6 | 38297 7 | 234 8 | -12389 9 | 324 10 | 55 11 | 1232 -------------------------------------------------------------------------------- /testfile/2022/A/input18.txt: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testfile/2022/A/input19.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 5 -------------------------------------------------------------------------------- /testfile/2022/A/input2.txt: -------------------------------------------------------------------------------- 1 | 123 -------------------------------------------------------------------------------- /testfile/2022/A/input20.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /testfile/2022/A/input21.txt: -------------------------------------------------------------------------------- 1 | 5 -------------------------------------------------------------------------------- /testfile/2022/A/input22.txt: -------------------------------------------------------------------------------- 1 | 4 2 | -10 3 | -1 4 | 0 5 | 1 6 | 1 7 | 1 8 | 2 9 | 0 10 | 3 11 | -1 12 | 4 13 | -------------------------------------------------------------------------------- /testfile/2022/A/input23.txt: -------------------------------------------------------------------------------- 1 | 8 2 | 20 3 | 4 4 | -------------------------------------------------------------------------------- /testfile/2022/A/input24.txt: -------------------------------------------------------------------------------- 1 | 18 2 | 2022 3 | 2000 4 | 2020 5 | 3 6 | 9999 7 | 100 -------------------------------------------------------------------------------- /testfile/2022/A/input25.txt: -------------------------------------------------------------------------------- 1 | 100 2 | 200 3 | 300 4 | -------------------------------------------------------------------------------- /testfile/2022/A/input26.txt: -------------------------------------------------------------------------------- 1 | 6 -------------------------------------------------------------------------------- /testfile/2022/A/input27.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 2 4 | 3 -------------------------------------------------------------------------------- /testfile/2022/A/input28.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | -------------------------------------------------------------------------------- /testfile/2022/A/input29.txt: -------------------------------------------------------------------------------- 1 | 123 -------------------------------------------------------------------------------- /testfile/2022/A/input3.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/A/input3.txt -------------------------------------------------------------------------------- /testfile/2022/A/input30.txt: -------------------------------------------------------------------------------- 1 | 2 -------------------------------------------------------------------------------- /testfile/2022/A/input4.txt: -------------------------------------------------------------------------------- 1 | 10 -------------------------------------------------------------------------------- /testfile/2022/A/input5.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 3 3 | 1 4 | 2 5 | 6 6 | 4 -------------------------------------------------------------------------------- /testfile/2022/A/input6.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /testfile/2022/A/input7.txt: -------------------------------------------------------------------------------- 1 | 123 -------------------------------------------------------------------------------- /testfile/2022/A/input8.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/A/input8.txt -------------------------------------------------------------------------------- /testfile/2022/A/input9.txt: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testfile/2022/A/output1.txt: -------------------------------------------------------------------------------- 1 | 19241091 2 | A_GLOBAL = 1 3 | I am a function with only one param: {{ 3 }} and I return noting. 4 | I am a function with 2 param: {{ 1, 2 }} and I return noting. 5 | I am a function without params and I return 0. 6 | arr2_1_global[1][1] is 4 7 | Now a_global is 12, it is < 50. 8 | I am a function with 3 param: {{ 2, 2, 4 }} and I return 22. 9 | Now main_var_c is 22 10 | Now main_var_a is 3, it is <= 10 11 | ==================testfile1 end================== 12 | -------------------------------------------------------------------------------- /testfile/2022/A/output10.txt: -------------------------------------------------------------------------------- 1 | 20373188 2 | the in is : 555 3 | print1 4 | 20373188 5 | testParams : 1 6 | testParams : 2 7 | 20373188 8 | < 9 | >= 10 | <= 11 | > -------------------------------------------------------------------------------- /testfile/2022/A/output11.txt: -------------------------------------------------------------------------------- 1 | 20373237 2 | Test A begin... 3 | Module1 begin... 4 | Module1 passed! 5 | Module2 begin... 6 | Module2 passed! 7 | Module3 begin... 8 | Module3 passed! 9 | Test A end! 10 | -------------------------------------------------------------------------------- /testfile/2022/A/output12.txt: -------------------------------------------------------------------------------- 1 | 20373275 2 | 3 3 | m:4 4 | 0 5 | 0 6 | -------------------------------------------------------------------------------- /testfile/2022/A/output13.txt: -------------------------------------------------------------------------------- 1 | 20373360 2 | input: 3 | 4 4 | 7 5 | 1 2 3 6 | 2 3 4 7 | 3 4 5 8 | 4 5 6 9 | Your answer is: 10 | 147 11 | 25 12 | 36 13 | expect: 14 | 1 4 7 15 | 2 5 16 | 3 6 17 | 0 18 | 0 19 | -------------------------------------------------------------------------------- /testfile/2022/A/output14.txt: -------------------------------------------------------------------------------- 1 | 20373374 2 | True1 2 13 4 5 10 12 9 26 44 0 303 1000 32 54 123 0 1 2 4 5 9 10 12 13 26 32 44 54 123 303 1000 3 | 1 32 sum is 1638 4 | answer is 5 5 | True 6 | fei 7 | or 8 | True 9 | Tr1 10 | True 11 | dayu 12 | 3 13 | Tr1 14 | True 15 | dayu 16 | Tr1 17 | end1 10 18 | 3 19 | err 20 | 13-10319 -------------------------------------------------------------------------------- /testfile/2022/A/output15.txt: -------------------------------------------------------------------------------- 1 | 20373377 2 | 5: tmp is 687 3 | 6: a2*tmp = 41220 4 | 7: i = 1, tmp is 2021 5 | right judge 6 | 1 7 | 4 8 | 3 9 | func1 = 2037 10 | in func2 -------------------------------------------------------------------------------- /testfile/2022/A/output16.txt: -------------------------------------------------------------------------------- 1 | 20373379 2 | 1 3 | 1 4 | 1 5 | 1 6 | 1 7 | 1 8 | 1 9 | 1 10 | 1 11 | -------------------------------------------------------------------------------- /testfile/2022/A/output17.txt: -------------------------------------------------------------------------------- 1 | 20373381 2 | 76 3 | 10086 4 | -10 5 | !!! ()*+,-./:;<>=@?^_`{}|~[] called func: ___ 6 | called func: Main, array[0][0] = 287, array[0][1] = -98662 7 | 8 | called func: __, array[0] = 2323 9 | 10 | 11 | temp: 1 12 | -95911046 19715301 1 64 24 1040 10086 16 212132 76 13 | 308 26 57048 3194880 8792 -687331 908 1040 136 10104 14 | 4491858 -597 0 1983 38297 0 234 0 -12389 -2899026 15 | 324 55 19052 111767217 -428321733 245512106 1332 10 10086 3 16 | //called func: ____, _arg = 14 17 | -------------------------------------------------------------------------------- /testfile/2022/A/output18.txt: -------------------------------------------------------------------------------- 1 | 20373394 2 | a = 2 3 | b = 3 4 | 20373394 5 | a = 1 6 | b = 2 7 | 20373394 8 | a = -1 9 | b = 2 10 | 20373394 11 | a = 1 12 | b = 1 13 | 20373394 14 | a = 1 15 | b = 3 16 | 1 is not 2 17 | xxxx 18 | 2 19 | xxxx 20 | 3 is not 2 21 | xxxx 22 | first : 1first: 1 -------------------------------------------------------------------------------- /testfile/2022/A/output19.txt: -------------------------------------------------------------------------------- 1 | 20373447 2 | 2YeG1 3 | YeG2 4 | YeG3 5 | YeG4 6 | YeG5 7 | 2 -- 5 8 | 4 9 | 10000 10 | 15 11 | 6 12 | 7 13 | -3 14 | 10 15 | 2 16 | -------------------------------------------------------------------------------- /testfile/2022/A/output2.txt: -------------------------------------------------------------------------------- 1 | 19373035 2 | 1, 1 3 | 1, 1 4 | a:125 5 | -------------------------------------------------------------------------------- /testfile/2022/A/output20.txt: -------------------------------------------------------------------------------- 1 | 20373460 2 | 13 3 | usii = 11 4 | usee = 0 5 | buf = 1 6 | getsum3 = 12 7 | 1 8 | 1 9 | jjj = 16 10 | tt1 = 3 -------------------------------------------------------------------------------- /testfile/2022/A/output21.txt: -------------------------------------------------------------------------------- 1 | 20373473 2 | 0 1 3 | 3 4 | 3 5 | 3 6 | 5 7 | 0 8 | 8 9 | 1 10 | 3 11 | 2 12 | 13 | 2 14 | -------------------------------------------------------------------------------- /testfile/2022/A/output22.txt: -------------------------------------------------------------------------------- 1 | 20373585 2 | const1_arr2[1][1]:9 <==> correct:9 3 | test_return:3 <==> correct:3 4 | test_not:1 <==> correct:1 5 | test_sum:15 <==> correct:15 6 | test_ifcomb:-11 <==> correct:-11 7 | short-circuit logic or ok! 8 | short-circuit logic and ok! 9 | c=9 <==> correct:9 10 | -------------------------------------------------------------------------------- /testfile/2022/A/output23.txt: -------------------------------------------------------------------------------- 1 | 20373649 2 | This Function has no return! 3 | multiply_and_add: a=1 b=3 c=9 4 | Weekday == 2 5 | redefined ConstA = 2 6 | multiply_and_add: a=3 b=4 c=8 7 | The binary of decimal 23 is 10111. 8 | binary != 0 9 | The correct sort of the input array is: 4 8 20. 10 | short circuit evaluation: Or 11 | globalVal: 1. short circuit evaluation:And 12 | -------------------------------------------------------------------------------- /testfile/2022/A/output24.txt: -------------------------------------------------------------------------------- 1 | 20373614 2 | add:6 3 | input:8 4 | 2022!!! 5 | run:2000 6 | run:2020 7 | not run:3 8 | not run:9999 9 | not run:100 10 | year1:2022,year2:2000,year3:2020,year4:3,year5:9999,year6:100 11 | printsth -------------------------------------------------------------------------------- /testfile/2022/A/output25.txt: -------------------------------------------------------------------------------- 1 | 20373623 2 | 3 | 1 1 1 1 1 1 1 1 1 1 4 | 2 2 2 2 2 2 2 2 2 2 5 | 3 3 3 3 3 3 3 3 3 3 6 | 4 4 4 4 4 4 4 4 4 4 7 | 5 5 5 5 5 5 5 5 5 5 8 | 6 6 6 6 6 6 6 6 6 6 9 | 7 7 7 7 7 7 7 7 7 7 10 | 8 8 8 8 8 8 8 8 8 8 11 | 9 9 9 9 9 9 9 9 9 9 12 | 10 10 10 10 10 10 10 10 10 10 13 | 14 | 1 2 3 4 5 6 7 8 9 10 15 | 1 2 3 4 5 6 7 8 9 10 16 | 1 2 3 4 5 6 7 8 9 10 17 | 1 2 3 4 5 6 7 8 9 10 18 | 1 2 3 4 5 6 7 8 9 10 19 | 1 2 3 4 5 6 7 8 9 10 20 | 1 2 3 4 5 6 7 8 9 10 21 | 1 2 3 4 5 6 7 8 9 10 22 | 1 2 3 4 5 6 7 8 9 10 23 | 1 2 3 4 5 6 7 8 9 10 24 | 30250 25 | 100 26 | 200 27 | 300 28 | Let us solve math problem 29 | x not equal to y 30 | Let us solve math problem 31 | x is not equal to y and x is 100 more than y 32 | Let us solve math problem 33 | x is not equal to y and y is 200 more than x 34 | -------------------------------------------------------------------------------- /testfile/2022/A/output26.txt: -------------------------------------------------------------------------------- 1 | 20373743 2 | input: 6 3 | a is [[1, 1], [1, 0]] 4 | a is [[2, 1], [1, 1]] 5 | a is [[3, 2], [2, 1]] 6 | a is [[5, 3], [3, 2]] 7 | a is [[8, 5], [5, 3]] 8 | a is [[13, 8], [8, 5]] 9 | a is [[21, 13], [13, 8]] 10 | a is [[34, 21], [21, 13]] 11 | a is [[55, 34], [34, 21]] 12 | get matrix after 9 multplFIB_M turns! 13 | given original vector: [13, 8] 14 | get next vector: [21, 13]! 15 | a and b is true 16 | c is true 17 | a || c is true 18 | sum of a, b, c is 12 19 | sum of lis front id 6 20 | -------------------------------------------------------------------------------- /testfile/2022/A/output27.txt: -------------------------------------------------------------------------------- 1 | 20373775 2 | Hello world! 3 | 1 2 4 | 3 4 5 | 5 6 6 | 1 7 | 0 8 | 2 9 | 9 10 | 25 11 | -------------------------------------------------------------------------------- /testfile/2022/A/output28.txt: -------------------------------------------------------------------------------- 1 | 20373974 2 | 1 3 | 2 4 | 3 5 | 2 6 | 3 7 | 2 8 | 10 9 | 3 10 | 6 11 | -------------------------------------------------------------------------------- /testfile/2022/A/output29.txt: -------------------------------------------------------------------------------- 1 | 20377020 2 | vm_01 = 124 3 | vm_02 = 9, vm_03 = 0 4 | vm_04 = 11 5 | vm_AE = 0 6 | vm_ME = 3435420 7 | vm_UE = 343554 8 | vm_PE = 114357 9 | vm_i_1 = 0, vm_i_2 = 5 10 | vs_test = 1218 -------------------------------------------------------------------------------- /testfile/2022/A/output3.txt: -------------------------------------------------------------------------------- 1 | Author: 19376160 2 | There 3 | is 4 | nothing 5 | special 6 | 1 7 | 11 8 | 44 9 | 44 10 | The end -------------------------------------------------------------------------------- /testfile/2022/A/output30.txt: -------------------------------------------------------------------------------- 1 | 21371064 2 | heihei0 3 | 8 4 | AC 5 | WA 6 | TLE 7 | RE 8 | PE 9 | AK!! 10 | -------------------------------------------------------------------------------- /testfile/2022/A/output4.txt: -------------------------------------------------------------------------------- 1 | 20231077 2 | 20231077 3 | 10 4 | 20231077 5 | 20231077 6 | 20231077 7 | 20231077 8 | 20231077 9 | 20231077 10 | 20231077 -------------------------------------------------------------------------------- /testfile/2022/A/output6.txt: -------------------------------------------------------------------------------- 1 | 20231229 2 | 1 3 | 2 4 | 3 5 | 4 6 | 1 7 | 2 8 | 1 9 | 4 10 | 2 -------------------------------------------------------------------------------- /testfile/2022/A/output7.txt: -------------------------------------------------------------------------------- 1 | 20373020 2 | 1 3 | 1 4 | 123 5 | 1 6 | 8 7 | 0 8 | const 520 var 0 glob 666 9 | -666 10 | this is end -------------------------------------------------------------------------------- /testfile/2022/A/output8.txt: -------------------------------------------------------------------------------- 1 | begin 2 | -1 3 | 2 4 | 2 5 | 2 6 | 2 7 | 2 8 | 2 9 | 2 10 | 2 11 | 2 12 | 0 13 | 3 14 | 2 15 | 2 16 | 2 17 | 2 18 | 2 19 | 2 20 | 2 21 | 2 22 | 2 23 | 1 24 | 1 25 | 1 26 | 1 27 | 1 28 | 1 29 | 1 30 | 1 31 | 1 32 | 21 33 | 23 34 | 24 35 | 25 36 | 26 37 | -------------------------------------------------------------------------------- /testfile/2022/A/output9.txt: -------------------------------------------------------------------------------- 1 | 20373110 2 | input test:1 1 3 | calculate test:4 2 1 2, 4 1 0, 4 0 4 | 1 5 | repite 6 | excute repite(a) = 1 7 | repite2 8 | excute repite2(a) = 1 9 | excute +f1(x, z, Z) = 1 10 | excute +f1(x, z, Z) = -1 -------------------------------------------------------------------------------- /testfile/2022/A/testfile8.txt: -------------------------------------------------------------------------------- 1 | const int _a[5]={-1,0,1,2,3},b=0; 2 | int c,d,f; 3 | const int array[2][2]={{1,2},{3,4}}; 4 | const int a1=0,a2=0,a3=0; 5 | int func(int par1){ 6 | if(par1==0){ 7 | return 0; 8 | }else{ 9 | if(par1>10&&par1<=100){ 10 | return 1; 11 | }else{ 12 | if(par1<=-10||par1>=100){ 13 | return -1; 14 | }else{ 15 | if(par1!=1){ 16 | return 2; 17 | } 18 | } 19 | } 20 | } 21 | return 3; 22 | } 23 | int func1(int par1,int par2){ 24 | if(!par1==1); 25 | return par1+par2; 26 | } 27 | int func2(int a[]){ 28 | return a[0]; 29 | } 30 | int func3(int par1,int par2,int par3){ 31 | return par1+par2+par3; 32 | } 33 | int main(){ 34 | int i=-10; 35 | int a1[5]; 36 | printf("begin\n"); 37 | while(i<20){ 38 | printf("%d\n",func(i)); 39 | i=i+1; 40 | } 41 | while(i<25){ 42 | i=i+1; 43 | if(i==22){ 44 | continue; 45 | } 46 | printf("%d\n",i); 47 | } 48 | while(i<30){ 49 | i=i+1; 50 | if(i==27){ 51 | break; 52 | } 53 | printf("%d\n",i); 54 | } 55 | int c=func1(1,2); 56 | int cd=func3(1,2,3); 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /testfile/2022/B/input1.txt: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testfile/2022/B/input10.txt: -------------------------------------------------------------------------------- 1 | 20 2 | -65 3 | -56 4 | 898 5 | 13 6 | 56 7 | 79 8 | 146 9 | 76 10 | 10 11 | 0 12 | 47 13 | 13 14 | 469 15 | 479 16 | 44 17 | 2 18 | 36 19 | 1 20 | 1 21 | 1 -------------------------------------------------------------------------------- /testfile/2022/B/input11.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /testfile/2022/B/input12.txt: -------------------------------------------------------------------------------- 1 | 123 -------------------------------------------------------------------------------- /testfile/2022/B/input13.txt: -------------------------------------------------------------------------------- 1 | 11 2 | 22 3 | 33 4 | 44 5 | 55 6 | 66 7 | 77 8 | 88 9 | 99 -------------------------------------------------------------------------------- /testfile/2022/B/input14.txt: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /testfile/2022/B/input15.txt: -------------------------------------------------------------------------------- 1 | 28 2 | 2147483647 -------------------------------------------------------------------------------- /testfile/2022/B/input16.txt: -------------------------------------------------------------------------------- 1 | 0 -------------------------------------------------------------------------------- /testfile/2022/B/input17.txt: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /testfile/2022/B/input18.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/B/input18.txt -------------------------------------------------------------------------------- /testfile/2022/B/input19.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 741 3 | 12 4 | 543 5 | 24 6 | 86885 7 | 6 8 | 167 9 | 968 10 | 99 -------------------------------------------------------------------------------- /testfile/2022/B/input2.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/B/input2.txt -------------------------------------------------------------------------------- /testfile/2022/B/input20.txt: -------------------------------------------------------------------------------- 1 | 12 2 | 3 3 | 9 -------------------------------------------------------------------------------- /testfile/2022/B/input21.txt: -------------------------------------------------------------------------------- 1 | 0 -------------------------------------------------------------------------------- /testfile/2022/B/input22.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 2 3 | 4 4 | 6 5 | 8 6 | 10 7 | 12 8 | 14 9 | 16 10 | 18 11 | 20 12 | -------------------------------------------------------------------------------- /testfile/2022/B/input23.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/B/input23.txt -------------------------------------------------------------------------------- /testfile/2022/B/input24.txt: -------------------------------------------------------------------------------- 1 | 40 -------------------------------------------------------------------------------- /testfile/2022/B/input25.txt: -------------------------------------------------------------------------------- 1 | 47 2 | 8990 -------------------------------------------------------------------------------- /testfile/2022/B/input26.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/B/input26.txt -------------------------------------------------------------------------------- /testfile/2022/B/input27.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/B/input27.txt -------------------------------------------------------------------------------- /testfile/2022/B/input28.txt: -------------------------------------------------------------------------------- 1 | 9 2 | 9 3 | 8 4 | 7 5 | 6 6 | 5 7 | 4 8 | 3 9 | 2 10 | 1 -------------------------------------------------------------------------------- /testfile/2022/B/input29.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/B/input29.txt -------------------------------------------------------------------------------- /testfile/2022/B/input3.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/B/input3.txt -------------------------------------------------------------------------------- /testfile/2022/B/input30.txt: -------------------------------------------------------------------------------- 1 | 12 2 | 34 3 | 23 4 | 11 5 | 22 6 | 19 7 | 28 8 | 29 9 | 45 10 | 48 11 | 37 12 | 21 13 | 9 14 | 8 15 | 13 16 | 1 17 | 34 18 | 49 19 | 27 20 | 31 21 | 19 22 | 21 23 | 7 24 | 9 25 | 8 26 | 11 27 | 42 28 | 45 29 | 40 30 | 39 31 | 9 32 | 19 33 | 28 34 | 29 35 | 40 36 | 39 37 | 34 38 | 49 39 | 27 40 | 17 41 | 13 42 | 34 43 | 49 44 | 27 45 | 28 46 | 29 47 | 40 48 | 31 49 | 19 50 | 21 51 | 11 52 | 29 53 | 13 54 | 4 55 | 0 56 | 7 57 | 9 58 | 48 -------------------------------------------------------------------------------- /testfile/2022/B/input4.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/B/input4.txt -------------------------------------------------------------------------------- /testfile/2022/B/input5.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/B/input5.txt -------------------------------------------------------------------------------- /testfile/2022/B/input6.txt: -------------------------------------------------------------------------------- 1 | 0 -------------------------------------------------------------------------------- /testfile/2022/B/input7.txt: -------------------------------------------------------------------------------- 1 | 0 -------------------------------------------------------------------------------- /testfile/2022/B/input8.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/B/input8.txt -------------------------------------------------------------------------------- /testfile/2022/B/input9.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | -------------------------------------------------------------------------------- /testfile/2022/B/output1.txt: -------------------------------------------------------------------------------- 1 | 19231240 2 | 1 3 | 0 4 | 0 5 | 0 6 | 0 7 | 0 8 | -------------------------------------------------------------------------------- /testfile/2022/B/output10.txt: -------------------------------------------------------------------------------- 1 | 20231204 2 | awadwad is 545 now 3 | awadwad has changed in block 4 | awadwad is 11 now 5 | double if 6 | cur val in loop is 101 7 | input n and the array which length is n, then will sort this array, n is required less than 20 8 | after sort, the array is: -65 -56 0 1 1 1 2 10 13 13 36 44 47 56 76 79 146 469 479 898 414414 -------------------------------------------------------------------------------- /testfile/2022/B/output11.txt: -------------------------------------------------------------------------------- 1 | 20373236 2 | 100 0 3 | 0 1 2 4 | 5 | 9 8 6 | 7 6 7 | -------------------------------------------------------------------------------- /testfile/2022/B/output12.txt: -------------------------------------------------------------------------------- 1 | 20373286 2 | 3 | 525 4 | 10 5 | 1 6 | -1 7 | ajkshbfjhysaefrbh 8 | +107-* 9 | -114 514 1919810 10 | -------------------------------------------------------------------------------- /testfile/2022/B/output13.txt: -------------------------------------------------------------------------------- 1 | 20373318 2 | a[0] = 1, a[1] = 2, a[2] = 3, a[3] = 4, a[4] = 5, 3 | c[0][0] = 1, c[0][1] = 2, c[0][2] = 3, 4 | c[1][0] = 4, c[1][1] = 8, c[1][2] = 5, 5 | sum1 = 495, sum2 = 0 6 | asd[4] = 89 7 | -------------------------------------------------------------------------------- /testfile/2022/B/output14.txt: -------------------------------------------------------------------------------- 1 | 20373354 2 | 1 2 3 3 | 1 3 2 4 | 2 1 3 5 | 2 3 1 6 | 3 1 2 7 | 3 2 1 -------------------------------------------------------------------------------- /testfile/2022/B/output15.txt: -------------------------------------------------------------------------------- 1 | 20373361 2 | 1 ia-2 aa-21--2-19 ab-1-40-6-5 3 | 2147483647 1 7 97 -616 10 10 -10 -10 4 | in in block i_a = 200 5 | in block i_a = 100 6 | out block i_a = 2147483647 7 | t 8 | t 9 | t 10 | t -------------------------------------------------------------------------------- /testfile/2022/B/output16.txt: -------------------------------------------------------------------------------- 1 | 20373370 2 | 628 3 | 17 4 | 4 5 | 2 6 | 4 7 | 0 8 | 9 9 | 0 10 | -------------------------------------------------------------------------------- /testfile/2022/B/output17.txt: -------------------------------------------------------------------------------- 1 | 20373380 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | -------------------------------------------------------------------------------- /testfile/2022/B/output18.txt: -------------------------------------------------------------------------------- 1 | 20373389 -------------------------------------------------------------------------------- /testfile/2022/B/output2.txt: -------------------------------------------------------------------------------- 1 | 20373898 2 | 1 3 | 1 4 | 1 5 | 1 6 | 2 7 | 1 8 | 2 9 | 4 10 | 4 !()*+,-./0:;=3) 24 | break; 25 | /* 26 | real fans' real comment/* 27 | */; 28 | _getAndPrint(i,tc,i%n); 29 | } 30 | } 31 | return 0; 32 | } -------------------------------------------------------------------------------- /testfile/2022/C/input1.txt: -------------------------------------------------------------------------------- 1 | 16 -------------------------------------------------------------------------------- /testfile/2022/C/input10.txt: -------------------------------------------------------------------------------- 1 | 3 2 | 4 3 | 5 4 | 6 5 | 7 6 | 8 -------------------------------------------------------------------------------- /testfile/2022/C/input11.txt: -------------------------------------------------------------------------------- 1 | 123456789 -------------------------------------------------------------------------------- /testfile/2022/C/input12.txt: -------------------------------------------------------------------------------- 1 | 3 -------------------------------------------------------------------------------- /testfile/2022/C/input13.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /testfile/2022/C/input14.txt: -------------------------------------------------------------------------------- 1 | 3 2 | 3 -------------------------------------------------------------------------------- /testfile/2022/C/input15.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/C/input15.txt -------------------------------------------------------------------------------- /testfile/2022/C/input16.txt: -------------------------------------------------------------------------------- 1 | 23 2 | -------------------------------------------------------------------------------- /testfile/2022/C/input17.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 6 -------------------------------------------------------------------------------- /testfile/2022/C/input18.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 28 3 | 0 -------------------------------------------------------------------------------- /testfile/2022/C/input19.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/C/input19.txt -------------------------------------------------------------------------------- /testfile/2022/C/input2.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /testfile/2022/C/input20.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/C/input20.txt -------------------------------------------------------------------------------- /testfile/2022/C/input21.txt: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /testfile/2022/C/input22.txt: -------------------------------------------------------------------------------- 1 | 7 -------------------------------------------------------------------------------- /testfile/2022/C/input23.txt: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /testfile/2022/C/input24.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/C/input24.txt -------------------------------------------------------------------------------- /testfile/2022/C/input25.txt: -------------------------------------------------------------------------------- 1 | 35 2 | 62 3 | 45 4 | 26 5 | -------------------------------------------------------------------------------- /testfile/2022/C/input26.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 70 -------------------------------------------------------------------------------- /testfile/2022/C/input27.txt: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /testfile/2022/C/input28.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 9 -------------------------------------------------------------------------------- /testfile/2022/C/input29.txt: -------------------------------------------------------------------------------- 1 | 33 -------------------------------------------------------------------------------- /testfile/2022/C/input3.txt: -------------------------------------------------------------------------------- 1 | 6 2 | -------------------------------------------------------------------------------- /testfile/2022/C/input30.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/C/input30.txt -------------------------------------------------------------------------------- /testfile/2022/C/input4.txt: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /testfile/2022/C/input5.txt: -------------------------------------------------------------------------------- 1 | 10 -------------------------------------------------------------------------------- /testfile/2022/C/input6.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/C/input6.txt -------------------------------------------------------------------------------- /testfile/2022/C/input7.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/C/input7.txt -------------------------------------------------------------------------------- /testfile/2022/C/input8.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/C/input8.txt -------------------------------------------------------------------------------- /testfile/2022/C/input9.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/C/input9.txt -------------------------------------------------------------------------------- /testfile/2022/C/output1.txt: -------------------------------------------------------------------------------- 1 | 19241027 2 | -------------------------------------------------------------------------------- /testfile/2022/C/output10.txt: -------------------------------------------------------------------------------- 1 | 20373184 2 | Wow, you will begin test your program! 3 | 3 4 | 30 5 | -3 6 | 29 7 | 44912 8 | 6 9 | 0 10 | -6-13 -------------------------------------------------------------------------------- /testfile/2022/C/output12.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhy2000/Compiler2021/798be43935adae0322b598c4c654201baac10aea/testfile/2022/C/output12.txt -------------------------------------------------------------------------------- /testfile/2022/C/output13.txt: -------------------------------------------------------------------------------- 1 | 20373260 2 | a_c_num_1:1 3 | a_c_num_2:2, a_v_num_2:2 4 | -------------------------------------------------------------------------------- /testfile/2022/C/output14.txt: -------------------------------------------------------------------------------- 1 | 20373276 2 | 3144246 -------------------------------------------------------------------------------- /testfile/2022/C/output15.txt: -------------------------------------------------------------------------------- 1 | 20373291 2 | i = 1 j = 2 k = 3 3 | i = -1 4 | !0 = 1 5 | This is h 6 | 1 < 2 7 | 2 > 1 8 | 1 <= 1 9 | 1 >= 1 10 | -------------------------------------------------------------------------------- /testfile/2022/C/output16.txt: -------------------------------------------------------------------------------- 1 | (20373335) 2 | C level,test a code has decl,no func 3 | con1 is 44 4 | con2 is 678,con3 is 61 5 | the left val is -1288 6 | -------------------------------------------------------------------------------- /testfile/2022/C/output17.txt: -------------------------------------------------------------------------------- 1 | 20373358 2 | Some global constants: 0 1 2 3 3 | Some local constants: 1 2 3 4 4 | Some global variables: 1 2 3 5 | Some local variables: 2 8 5 6 | Set global variable as 5 7 | Set local variable as 6 8 | Calculate -7 9 | Calculate 4 10 | Calculate 3 -------------------------------------------------------------------------------- /testfile/2022/C/output18.txt: -------------------------------------------------------------------------------- 1 | 20373420 2 | Fu1_nC(): 3 3 | func2(): 222 4 | func_3(): 3 5 | a is no less than 0! 6 | b is greater than 0! 7 | c is exactly zero! 8 | i break with a value of 128 9 | func4 result: 2 -------------------------------------------------------------------------------- /testfile/2022/C/output19.txt: -------------------------------------------------------------------------------- 1 | 20373472 2 | a=4, b=7 3 | a<=b 4 | cur i=0 5 | cur i=1 6 | input = -3 7 | -------------------------------------------------------------------------------- /testfile/2022/C/output2.txt: -------------------------------------------------------------------------------- 1 | 19241091 2 | ==================testfile4 end================== -------------------------------------------------------------------------------- /testfile/2022/C/output20.txt: -------------------------------------------------------------------------------- 1 | 20373480 2 | 20373480 3 | 20373480 4 | 20373480 5 | i=-1 6 | 20373480 7 | 20373480 8 | 20373480 9 | 20373480 10 | 20373480 -------------------------------------------------------------------------------- /testfile/2022/C/output21.txt: -------------------------------------------------------------------------------- 1 | 20373493 2 | Move from 1 to 3 3 | Move from 1 to 2 4 | Move from 3 to 2 5 | Move from 1 to 3 6 | Move from 2 to 1 7 | Move from 2 to 3 8 | Move from 1 to 3 9 | -------------------------------------------------------------------------------- /testfile/2022/C/output22.txt: -------------------------------------------------------------------------------- 1 | 20373506 2 | -26 3 | test 4 | 8 5 | <=18 6 | >5 -------------------------------------------------------------------------------- /testfile/2022/C/output23.txt: -------------------------------------------------------------------------------- 1 | 20373569 the mafia~ 2 | funcTest: move disk from 3 to 1 3 | funcTest: move disk from 2 to 1 4 | blockTest: 7 == 7, 8 == 8 5 | blockTest: 5 == 7, 12 == 12 6 | Exptest: 100 7 12 -2147483648 119 10 40 318 7 | Exptest: 10 8 | -------------------------------------------------------------------------------- /testfile/2022/C/output24.txt: -------------------------------------------------------------------------------- 1 | 20373778 2 | 20497234 3 | 3 4 | 7 5 | 10 6 | 11 7 | 12 8 | 12 9 | 2 10 | end 11 | -------------------------------------------------------------------------------- /testfile/2022/C/output25.txt: -------------------------------------------------------------------------------- 1 | 20373780 2 | in addNum a=35,b=62 3 | in addNum c=194,d=-62 4 | in addNum e=132 5 | e=132 become evenout i=0 6 | in addNum out flag=1 7 | in testMul x=25 y=26 8 | in testMul get re=24 9 | c=24 10 | z==0 11 | -------------------------------------------------------------------------------- /testfile/2022/C/output26.txt: -------------------------------------------------------------------------------- 1 | 20373935 2 | Ha 3 | Ha 4 | Ha 5 | Ha 6 | Ha 7 | Ha 8 | Fa 9 | Pa 10 | Pa -------------------------------------------------------------------------------- /testfile/2022/C/output27.txt: -------------------------------------------------------------------------------- 1 | 203739441 2 0 2 | 0 2 3 3 3 | 0 2 1 -1 4 | 0 0 1 5 | 0 -1 6 | -------------------------------------------------------------------------------- /testfile/2022/C/output28.txt: -------------------------------------------------------------------------------- 1 | 20373980 2 | Received!Counting... 3 | The number you want is 89(Using recursion) 4 | The number you want is 89(Using while block) 5 | Multiply:100 6 | Division:1 7 | Delivery:0 8 | 200 17 9 | x is bigger! 10 | Finished! 11 | -------------------------------------------------------------------------------- /testfile/2022/C/output29.txt: -------------------------------------------------------------------------------- 1 | 20376115 2 | helloa1: 1, a2: 2 3 | m: 0 b2: 0 4 | b: -1453 5 | a1: 33 6 | sum: 6 7 | a1: 3 8 | i: 0 9 | i: 0 10 | j: 2 > 1 11 | 123456 12 | i: 0 13 | 123456 14 | i: 0 15 | 123456 16 | -------------------------------------------------------------------------------- /testfile/2022/C/output3.txt: -------------------------------------------------------------------------------- 1 | 19374223 2 | fibo[6] = 8 3 | fibo[6] / 2 = 4 4 | /***************** END *****************/ 5 | -------------------------------------------------------------------------------- /testfile/2022/C/output30.txt: -------------------------------------------------------------------------------- 1 | 20376156 2 | hhh 3 | 3 4 | -------------------------------------------------------------------------------- /testfile/2022/C/output4.txt: -------------------------------------------------------------------------------- 1 | 20231055 2 | a>1 3 | d!=1 4 | 6 5 | 5 6 | 5 7 | 666 8 | 1 9 | 16 10 | 1 11 | -------------------------------------------------------------------------------- /testfile/2022/C/output5.txt: -------------------------------------------------------------------------------- 1 | 20231097 2 | 101 3 | 4 | -------------------------------------------------------------------------------- /testfile/2022/C/output6.txt: -------------------------------------------------------------------------------- 1 | 20231235 2 | local first: 4 3 | the param is 4 4 | the param is 5 5 | the param is 6 6 | the param is 7 7 | the param is 8 8 | the param is 9 9 | the param is 10 10 | the param is 11 -------------------------------------------------------------------------------- /testfile/2022/C/output7.txt: -------------------------------------------------------------------------------- 1 | 20373053 2 | 20373053 3 | 20373053 4 | 20373053 5 | 20373053 6 | 20373053 7 | 20373053 8 | 20373053 9 | 20373053 10 | 20373053 11 | 10009 12 | -------------------------------------------------------------------------------- /testfile/2022/C/output8.txt: -------------------------------------------------------------------------------- 1 | 20373057 2 | 114514 3 | 5 4 | 10 5 | 666 -------------------------------------------------------------------------------- /testfile/2022/C/output9.txt: -------------------------------------------------------------------------------- 1 | 20373117 2 | 20373117 3 | 20373117 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /testfile/2022/C/testfile1.txt: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | int n; 4 | n = getint(); 5 | int i = 19241027; 6 | // only mod 7 | if (n % 4 == 0) 8 | printf("%d\n", i); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /testfile/2022/C/testfile10.txt: -------------------------------------------------------------------------------- 1 | int main() { 2 | const int a1 = 1; 3 | const int _bc = -2, _de = 3; 4 | const int fff = +4, ggg = 5, hhh = 6; 5 | int x1 = 111; 6 | int x2 = 123 + 234; 7 | int x3 = 6 * (5 + 3) - 10; 8 | int x4; 9 | x4 = x1 + x2 * 3; 10 | int x5, x6; 11 | int x7, x8, x9, x10; 12 | 13 | int y1, y2, y3, y4, y5, y6, y7, y8; 14 | 15 | x5 = getint(); 16 | x6 = getint(); 17 | x7 = getint(); 18 | x8 = getint(); 19 | x9 = getint(); 20 | x10 = getint(); 21 | 22 | printf("20373184\n"); 23 | printf("Wow, you will begin test your program!\n"); 24 | printf("%d\n", 1 + 2); 25 | printf("%d\n", ggg * hhh); 26 | 27 | y1 = (a1 + _bc) * _de; 28 | y2 = x2 % x1 + ggg; 29 | y3 = x4 * x3 - fff; 30 | y4 = x5 / 2 * hhh; 31 | y5 = x6 * (1 + x7) % 3; 32 | y6 = -x8; 33 | y7 = 6 + x9; 34 | printf("%d\n", y1); 35 | printf("%d\n", y2); 36 | printf("%d\n", y3); 37 | printf("%d\n", y4); 38 | printf("%d\n", y5); 39 | printf("%d-%d\n", y6, y7); 40 | return 0; 41 | } -------------------------------------------------------------------------------- /testfile/2022/C/testfile12.txt: -------------------------------------------------------------------------------- 1 | int fun(int x){ 2 | int flag = 1; 3 | int tmp = 2*3/1%2+2-2; 4 | if(tmp == -3){ flag = 1;} 5 | else{flag = 0;} 6 | return flag; 7 | } 8 | 9 | int main(){ 10 | int a = 1; 11 | a = getint(); 12 | if(a == 1){ 13 | printf("True"); 14 | } 15 | if(!a){ 16 | printf("False"); 17 | } 18 | ; 19 | int e = fun(1); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /testfile/2022/C/testfile14.txt: -------------------------------------------------------------------------------- 1 | int main(){ 2 | int a = 0,b=0; 3 | a=getint(); 4 | b=getint(); 5 | printf("20373276\n"); 6 | int c=0; 7 | int flag=0; 8 | if ( a==1 ) c=1; 9 | else {c=3;} 10 | printf("%d",c); 11 | if (a==2) c=2; 12 | while ( c<1000 ) { 13 | if ( a==1 ) { 14 | break; 15 | } 16 | if ( a!=1 && flag==0 ) { 17 | a=a-1; 18 | flag=1; 19 | continue; 20 | } 21 | a=a-1; 22 | b=b+1; 23 | c=c+1; 24 | } 25 | printf("%d",a); 26 | printf("%d",b); 27 | printf("%d",c); 28 | if (a>5) printf("1"); 29 | if (a<5) printf("2"); 30 | if (a>=5) printf("3"); 31 | if (a<=5) printf("4"); 32 | if (a==1 && b==4) { 33 | printf("6"); 34 | } 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /testfile/2022/C/testfile15.txt: -------------------------------------------------------------------------------- 1 | //存在Decl 2 | const int a = 1; 3 | const int b = 1,c = 1,d = 1; 4 | int e = 1; 5 | int f = 1,g = 1,h = 1; 6 | int i; 7 | int j,k,l; 8 | const int o = 1,p = 1; 9 | //不存在FuncDel 10 | int main(){ 11 | printf("20373291\n"); 12 | //基本表达式 13 | i = a; 14 | j = 2; 15 | k = b * (a + 2); 16 | printf("i = %d j = %d k = %d\n",i,j,k); 17 | //单目运算符 18 | i = +-+h; 19 | printf("i = %d\n",i); 20 | if(!0){ 21 | printf("!0 = 1\n"); 22 | } 23 | //乘除模表达式 24 | i = 2 * 2; 25 | i = 2 / 2; 26 | i = 2 % 2; 27 | //加减表达式 28 | h = i; 29 | h = a + i; 30 | h = a - i; 31 | //关系表达式 32 | if(h){ 33 | printf("This is h\n"); 34 | } 35 | if(1 < 2){ 36 | printf("1 < 2\n"); 37 | } 38 | if(2 > 1){ 39 | printf("2 > 1\n"); 40 | } 41 | if(1 <= 1){ 42 | printf("1 <= 1\n"); 43 | } 44 | if(1 >= 1){ 45 | printf("1 >= 1\n"); 46 | } 47 | return 0; 48 | } -------------------------------------------------------------------------------- /testfile/2022/C/testfile17.txt: -------------------------------------------------------------------------------- 1 | /* C级:基本类型变量声明定义与算数表达式测试 */ 2 | 3 | const int ZERO = 0; 4 | const int ONE = 1, TWO = 2, THREE = 4 * 7 - 5 * +5; 5 | 6 | int one = 1, two = 2, three = 55 / 9 - 9 % 6; 7 | int gvar; 8 | 9 | int main() { 10 | const int ONE = 1; 11 | const int ABC123 = 2, _ABC = 3, _ABC123 = 4; 12 | int one = 1; 13 | int abc123 = 2, _abc = 8, _abc123 = 5; 14 | int var; 15 | 16 | printf("20373358\n"); 17 | 18 | printf("Some global constants: %d %d %d %d\n", ZERO, ONE, TWO, THREE); 19 | printf("Some local constants: %d %d %d %d\n", ONE, ABC123, _ABC, _ABC123); 20 | printf("Some global variables: %d %d %d\n", one, two, three); 21 | printf("Some local variables: %d %d %d\n", abc123, _abc, _abc123); 22 | 23 | gvar = getint(); 24 | var = getint(); 25 | 26 | printf("Set global variable as %d\n", gvar); 27 | printf("Set local variable as %d\n", var); 28 | 29 | var = (var + 1) * -1; 30 | printf("Calculate %d\n", var); 31 | 32 | var = var + 56 - gvar * 9; 33 | printf("Calculate %d\n", var); 34 | 35 | var = var + -1; 36 | printf("Calculate %d\n", var); 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /testfile/2022/C/testfile19.txt: -------------------------------------------------------------------------------- 1 | void compare(int x, int y){ 2 | printf("a=%d, b=%d\n", x, y); 3 | if(x>y) 4 | printf("a>b\n"); 5 | else 6 | printf("a<=b\n"); 7 | } 8 | 9 | void test(int x){ 10 | if(x<0) 11 | printf("input = %d\n", x); 12 | else 13 | printf("Illegal input\n"); 14 | } 15 | 16 | void printI(int n){ 17 | int i; 18 | i = 0; 19 | while(i10) 34 | test(a-b); 35 | //printf("abc"); 36 | /* 37 | * printf("def"); 38 | */ 39 | return 0; 40 | } -------------------------------------------------------------------------------- /testfile/2022/C/testfile2.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * CompUnit → {Decl} {FuncDef} MainFuncDef 3 | */ 4 | // 不存在 Decl 5 | // 不存在 FuncDef 6 | int main() 7 | { 8 | printf("19241091\n"); 9 | printf("==================testfile4 end=================="); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /testfile/2022/C/testfile20.txt: -------------------------------------------------------------------------------- 1 | const int a = 100; 2 | const int b = 10,c = 1; 3 | const int x = 1,y = 2,z = 3; 4 | int main(){ 5 | printf("20373480\n"); 6 | if(a!=99){ 7 | printf("20373480\n"); 8 | } 9 | if(c<=10 && b>=10){ 10 | printf("20373480\n"); 11 | } 12 | if(a>99 || b<20){ 13 | printf("20373480\n"); 14 | } 15 | int i; 16 | i=-5; 17 | ; 18 | while(i<0){ 19 | if(i==-1){ 20 | break; 21 | }else{ 22 | i=i+1; 23 | continue; 24 | } 25 | break; 26 | } 27 | i=-1; 28 | printf("i=%d\n",i); 29 | printf("20373480\n"); 30 | printf("20373480\n"); 31 | printf("20373480\n"); 32 | printf("20373480\n"); 33 | printf("20373480"); 34 | return 0; 35 | } -------------------------------------------------------------------------------- /testfile/2022/C/testfile21.txt: -------------------------------------------------------------------------------- 1 | void hanoi(int from, int via, int to, int t) { 2 | if (t == 0) return; 3 | hanoi(from, to, via, t - 1); 4 | printf("Move from %d to %d\n", from, to); 5 | hanoi(via, from, to, t - 1); 6 | return; 7 | } 8 | 9 | int main() { 10 | int t; 11 | t = getint(); 12 | printf("20373493\n"); 13 | hanoi(1, 2, 3, t); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /testfile/2022/C/testfile26.txt: -------------------------------------------------------------------------------- 1 | int cnt = 10; 2 | 3 | int main() { 4 | int i = -+-+-+-+-(2 + (4 + 5) * 7); 5 | int begin, end; 6 | begin = getint(); 7 | end = getint(); 8 | i = begin; 9 | printf("20373935"); 10 | printf("\n"); 11 | while(i < end) { 12 | if (i <= begin + (end - begin) / 3) { 13 | if (i % 4 == 0) { 14 | printf("Ha\n"); 15 | cnt = cnt - 1; 16 | } 17 | } else if (i < begin + (end - begin) / 2) { 18 | if (i % 6 == 0) { 19 | printf("Fa\n"); 20 | cnt = cnt - 1; 21 | } 22 | } else if (i >= begin + (end - begin) * 3 / 4) { 23 | if (i % 8 == 0) { 24 | printf("Pa\n"); 25 | cnt = cnt - 1; 26 | } 27 | } else if (i > begin + (end - begin) * 5 / 6) { 28 | if (i % 10 == 0) { 29 | printf("Ja\n"); 30 | } 31 | } 32 | i = i + 1; 33 | } 34 | return 0; 35 | } -------------------------------------------------------------------------------- /testfile/2022/C/testfile3.txt: -------------------------------------------------------------------------------- 1 | const int n = 1; 2 | const int a = 1,b = 2; 3 | const int c = 3,d = 4,e = 5; 4 | 5 | int fib(int n) { 6 | int ret = 1; 7 | if (n == 1) { 8 | ret = 1; 9 | } 10 | else if (n == 2) { 11 | ret = 1; 12 | } 13 | else { 14 | ret = fib(n-1) + fib(n-2); 15 | } 16 | return ret; 17 | } 18 | 19 | int main() { 20 | int n; 21 | n = getint(); 22 | //int vis[5][5] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 23 | printf("19374223\n"); 24 | printf("fibo[%d] = %d\n",n,fib(n)); 25 | printf("fibo[%d] / 2 = %d\n",n,fib(n) / 2); 26 | printf("");printf("");printf(""); 27 | printf("");printf("");printf(""); 28 | printf("/***************** END *****************/\n"); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /testfile/2022/C/testfile30.txt: -------------------------------------------------------------------------------- 1 | // #include 2 | int main() { 3 | printf("20376156\n"); 4 | int x = 2; 5 | if (x == 1) { 6 | ;;; 7 | } else if (x == 2) { 8 | x = 9 - 8; 9 | } else { 10 | printf("%d\n", x); 11 | } 12 | if (x == 1) printf("hhh\n"); 13 | {{{{}}}};; 14 | x = 11; 15 | while (x >= 0) { 16 | x = x - 2; 17 | if (x == 1) continue; 18 | else if (x == 3) break; 19 | x = x - 1; 20 | } 21 | printf("%d\n", x); 22 | return 0; 23 | } -------------------------------------------------------------------------------- /testfile/2022/C/testfile5.txt: -------------------------------------------------------------------------------- 1 | int getnum(int num) { 2 | return num * num + 1; 3 | } 4 | 5 | int main() { 6 | printf("20231097\n"); 7 | int num; 8 | num = getint(); 9 | if(num <= 0) { 10 | int i = 0; 11 | while(i < 11) { 12 | if(i == 10) { 13 | break; 14 | } 15 | if(i == 1) { 16 | continue; 17 | } 18 | printf("a"); 19 | i = i + 1; 20 | } 21 | } 22 | else { 23 | int i = 0; 24 | printf("%d\n",getnum(num)); 25 | } 26 | return 0; 27 | } -------------------------------------------------------------------------------- /testfile/2022/C/testfile6.txt: -------------------------------------------------------------------------------- 1 | void print(int num) 2 | { 3 | printf("the param is %d\n", num); 4 | return ; 5 | } 6 | 7 | int return10() 8 | { 9 | return 10; 10 | } 11 | int main() 12 | { 13 | printf("20231235\n"); 14 | int first; 15 | first = 3; 16 | { 17 | int first = 4; 18 | printf("local first: %d\n", first); 19 | } 20 | int second = return10(); 21 | 22 | while (first < 100) { 23 | if (first > second) { 24 | break; 25 | } 26 | first = first + 1; 27 | print(first); 28 | if (first % 2 == 0) { 29 | continue; 30 | } 31 | } 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /testfile/2022/C/testfile7.txt: -------------------------------------------------------------------------------- 1 | const int PI = 3; 2 | int temp = 100; 3 | 4 | int add(int a, int b) { 5 | return a + b; 6 | } 7 | 8 | int main() { 9 | const int a = 9; 10 | const int b = 11; 11 | int c = 0, now = 10; 12 | 13 | while (now > 0) { 14 | now = now - 1; 15 | printf("20373053\n"); 16 | } 17 | 18 | while (c < 10000) { 19 | if (c < 50) { 20 | c = add(c, a); 21 | } else { 22 | c = add(c, b); 23 | } 24 | } 25 | 26 | printf("%d", c); 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /testfile/2022/C/testfile8.txt: -------------------------------------------------------------------------------- 1 | const int N = 555; 2 | int func() { 3 | const int a = 114500; 4 | int b = 10; // a = 50 5 | return a + b - 4 + 8; 6 | } 7 | int func2(int a,int b,int c) { 8 | return a * b + c; 9 | } 10 | void printTotal(int a,int b,int c) { 11 | printf("%d\n",(a+b+c)*a); 12 | } 13 | int main() { 14 | const int N = 666; 15 | printf("20373057\n"); 16 | printf("%d\n",func()); 17 | printf("%d\n",func2(+1,+2,+3)); 18 | printTotal(+5,-2,-1); 19 | printf("%d",N); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /testfile/2022/C/testfile9.txt: -------------------------------------------------------------------------------- 1 | 2 | const int _ = 20373117 + -+-1 * 1 / 1 - +1 % 2; 3 | const int value1 = 1; 4 | 5 | int value10 = 10; 6 | int value11 = 11, value12 = 12, value13; 7 | 8 | 9 | int main() { 10 | value13 = 13; 11 | int value14 = 14, value15 = 15, value16; 12 | int value17; 13 | 14 | printf("%d\n", _); 15 | 16 | int n = 3; 17 | while(n > 0) { 18 | n = -1 + n; 19 | if (n == 2) { 20 | if (value14 - value11 == 3) { 21 | continue; 22 | printf("continue is wrong\n"); 23 | } else { 24 | printf("if is wrong\n"); 25 | break; 26 | } 27 | } else if (n == 1) { 28 | if (value15 - value12 != 3) { 29 | printf("if is wrong\n"); 30 | break; 31 | } else { 32 | continue; 33 | printf("continue is wrong\n"); 34 | } 35 | } 36 | 37 | if (n == 0) { 38 | printf("%d\n", 20373117 + -+-1 * 1 / 1 - +1 % 2); 39 | printf("%d\n", 20373117); 40 | } 41 | } 42 | 43 | printf("\n\n\n\n\n\n"); 44 | 45 | return 0; 46 | } -------------------------------------------------------------------------------- /testfile/README.md: -------------------------------------------------------------------------------- 1 | # 辅助测试库 2 | 3 | 不一定完全符合要求,可能存在的问题: 4 | 5 | - 整数溢出(选用 `addu`, `subu`, `addiu` 等指令可解决) 6 | - 局部变量未初始化且未赋值就使用 7 | - 数组初始化维度和长度未一一对应 --------------------------------------------------------------------------------