├── .gitignore
├── README.md
├── pa1a
├── .classpath
├── .project
├── ASTPrintFormat.md
├── Decaf PA1-A README.pdf
├── TestCases
│ └── S1
│ │ ├── array-1.decaf
│ │ ├── array-2.decaf
│ │ ├── array-access.decaf
│ │ ├── array-comp.decaf
│ │ ├── array-concat.decaf
│ │ ├── array-const-err.decaf
│ │ ├── array-const.decaf
│ │ ├── array-foreach.decaf
│ │ ├── error1.decaf
│ │ ├── error2.decaf
│ │ ├── error3.decaf
│ │ ├── error4.decaf
│ │ ├── error5.decaf
│ │ ├── fibonacci.decaf
│ │ ├── guarded-1.decaf
│ │ ├── guarded-2.decaf
│ │ ├── guarded-error-1.decaf
│ │ ├── guarded-error-2.decaf
│ │ ├── guarded-error-3.decaf
│ │ ├── nqueues.decaf
│ │ ├── output
│ │ ├── array-1.result
│ │ ├── array-2.result
│ │ ├── array-access.result
│ │ ├── array-comp.result
│ │ ├── array-concat.result
│ │ ├── array-const-err.result
│ │ ├── array-const.result
│ │ ├── array-foreach.result
│ │ ├── error1.result
│ │ ├── error2.result
│ │ ├── error3.result
│ │ ├── error4.result
│ │ ├── error5.result
│ │ ├── fibonacci.result
│ │ ├── guarded-1.result
│ │ ├── guarded-2.result
│ │ ├── guarded-error-1.result
│ │ ├── guarded-error-2.result
│ │ ├── guarded-error-3.result
│ │ ├── nqueues.result
│ │ ├── scopy.result
│ │ ├── sealed.result
│ │ ├── test.result
│ │ ├── test1.result
│ │ ├── test2.result
│ │ ├── test3.result
│ │ ├── test4.result
│ │ ├── test5.result
│ │ ├── test6.result
│ │ ├── var-1.result
│ │ └── var-2.result
│ │ ├── runAll.py
│ │ ├── scopy.decaf
│ │ ├── sealed.decaf
│ │ ├── test1.decaf
│ │ ├── test2.decaf
│ │ ├── test3.decaf
│ │ ├── test4.decaf
│ │ ├── test5.decaf
│ │ ├── test6.decaf
│ │ ├── var-1.decaf
│ │ └── var-2.decaf
├── build.xml
├── report.md
├── report.pdf
├── src
│ └── decaf
│ │ ├── Driver.java
│ │ ├── Location.java
│ │ ├── Option.java
│ │ ├── error
│ │ ├── BadArgCountError.java
│ │ ├── BadArgTypeError.java
│ │ ├── BadArrElementError.java
│ │ ├── BadInheritanceError.java
│ │ ├── BadLengthArgError.java
│ │ ├── BadLengthError.java
│ │ ├── BadNewArrayLength.java
│ │ ├── BadOverrideError.java
│ │ ├── BadPrintArgError.java
│ │ ├── BadReturnTypeError.java
│ │ ├── BadTestExpr.java
│ │ ├── BadVarTypeError.java
│ │ ├── BreakOutOfLoopError.java
│ │ ├── ClassNotFoundError.java
│ │ ├── DecafError.java
│ │ ├── DeclConflictError.java
│ │ ├── FieldNotAccessError.java
│ │ ├── FieldNotFoundError.java
│ │ ├── IncompatBinOpError.java
│ │ ├── IncompatUnOpError.java
│ │ ├── IntTooLargeError.java
│ │ ├── MsgError.java
│ │ ├── NewlineInStrError.java
│ │ ├── NoMainClassError.java
│ │ ├── NotArrayError.java
│ │ ├── NotClassError.java
│ │ ├── NotClassFieldError.java
│ │ ├── NotClassMethodError.java
│ │ ├── OverridingVarError.java
│ │ ├── RefNonStaticError.java
│ │ ├── RuntimeError.java
│ │ ├── SubNotIntError.java
│ │ ├── ThisInStaticFuncError.java
│ │ ├── UndeclVarError.java
│ │ ├── UnrecogCharError.java
│ │ └── UntermStrError.java
│ │ ├── frontend
│ │ ├── BaseLexer.java
│ │ ├── BaseParser.java
│ │ ├── Lexer.java
│ │ ├── Lexer.l
│ │ ├── Parser.java
│ │ ├── Parser.output
│ │ ├── Parser.y
│ │ ├── ParserHelper.java
│ │ └── SemValue.java
│ │ ├── tree
│ │ └── Tree.java
│ │ └── utils
│ │ ├── IndentPrintWriter.java
│ │ └── MiscUtils.java
├── submit.py
└── tools
│ ├── byacc
│ ├── byacc.exe
│ ├── byacc.linux
│ ├── byacc.linux.amd64
│ ├── byacc.mac
│ └── byaccj1.13-extended.tar.gz
│ └── jflex
│ └── JFlex.jar
├── pa1b
├── ASTPrintFormat.md
├── Decaf PA1-B README.pdf
├── TestCases
│ ├── S1+
│ │ ├── .DS_Store
│ │ ├── array-1.decaf
│ │ ├── array-2.decaf
│ │ ├── array-access.decaf
│ │ ├── array-comp.decaf
│ │ ├── array-concat.decaf
│ │ ├── array-const.decaf
│ │ ├── array-foreach.decaf
│ │ ├── fibonacci.decaf
│ │ ├── guarded-1.decaf
│ │ ├── guarded-2.decaf
│ │ ├── nqueues.decaf
│ │ ├── output
│ │ │ ├── .DS_Store
│ │ │ ├── array-1.result
│ │ │ ├── array-2.result
│ │ │ ├── array-access.result
│ │ │ ├── array-comp.result
│ │ │ ├── array-concat.result
│ │ │ ├── array-const.result
│ │ │ ├── array-foreach.result
│ │ │ ├── fibonacci.result
│ │ │ ├── guarded-1.result
│ │ │ ├── guarded-2.result
│ │ │ ├── nqueues.result
│ │ │ ├── sealed.result
│ │ │ ├── test1.result
│ │ │ ├── test2.result
│ │ │ ├── test3.result
│ │ │ ├── test4.result
│ │ │ ├── test5.result
│ │ │ ├── test6.result
│ │ │ ├── var-1.result
│ │ │ └── var-2.result
│ │ ├── run.py
│ │ ├── runAll.py
│ │ ├── sealed.decaf
│ │ ├── test1.decaf
│ │ ├── test2.decaf
│ │ ├── test3.decaf
│ │ ├── test4.decaf
│ │ ├── test5.decaf
│ │ ├── test6.decaf
│ │ ├── var-1.decaf
│ │ └── var-2.decaf
│ ├── S1-
│ │ ├── .DS_Store
│ │ ├── array-errors.decaf
│ │ ├── error1.decaf
│ │ ├── error2.decaf
│ │ ├── error3.decaf
│ │ ├── error4.decaf
│ │ ├── error5.decaf
│ │ ├── guarded-error-1.decaf
│ │ ├── guarded-error-2.decaf
│ │ ├── guarded-error-3.decaf
│ │ ├── guarded-error-4.decaf
│ │ ├── guarded-errors.decaf
│ │ ├── multi-errors-1.decaf
│ │ ├── multi-errors-2.decaf
│ │ ├── multi-errors-3.decaf
│ │ ├── multi-errors-4.decaf
│ │ ├── multi-errors-5.decaf
│ │ ├── multi-errors-6.decaf
│ │ ├── multi-errors-7.decaf
│ │ ├── multi-errors-8.decaf
│ │ ├── multi-errors-9.decaf
│ │ ├── output
│ │ │ ├── .DS_Store
│ │ │ ├── array-errors.result
│ │ │ ├── error1.result
│ │ │ ├── error2.result
│ │ │ ├── error3.result
│ │ │ ├── error4.result
│ │ │ ├── error5.result
│ │ │ ├── guarded-error-1.result
│ │ │ ├── guarded-error-2.result
│ │ │ ├── guarded-error-3.result
│ │ │ ├── guarded-error-4.result
│ │ │ ├── guarded-errors.result
│ │ │ ├── multi-errors-1.result
│ │ │ ├── multi-errors-2.result
│ │ │ ├── multi-errors-3.result
│ │ │ ├── multi-errors-4.result
│ │ │ ├── multi-errors-5.result
│ │ │ ├── multi-errors-6.result
│ │ │ ├── multi-errors-7.result
│ │ │ ├── multi-errors-8.result
│ │ │ └── multi-errors-9.result
│ │ ├── run.py
│ │ └── runAll.py
│ └── S1
│ │ ├── array-1.decaf
│ │ ├── array-2.decaf
│ │ ├── array-access.decaf
│ │ ├── array-comp.decaf
│ │ ├── array-concat.decaf
│ │ ├── array-const-err.decaf
│ │ ├── array-const.decaf
│ │ ├── array-foreach.decaf
│ │ ├── error1.decaf
│ │ ├── error2.decaf
│ │ ├── error3.decaf
│ │ ├── error4.decaf
│ │ ├── error5.decaf
│ │ ├── fibonacci.decaf
│ │ ├── guarded-1.decaf
│ │ ├── guarded-2.decaf
│ │ ├── guarded-error-1.decaf
│ │ ├── guarded-error-2.decaf
│ │ ├── guarded-error-3.decaf
│ │ ├── nqueues.decaf
│ │ ├── output
│ │ ├── array-1.result
│ │ ├── array-2.result
│ │ ├── array-access.result
│ │ ├── array-comp.result
│ │ ├── array-concat.result
│ │ ├── array-const-err.result
│ │ ├── array-const.result
│ │ ├── array-foreach.result
│ │ ├── error1.result
│ │ ├── error2.result
│ │ ├── error3.result
│ │ ├── error4.result
│ │ ├── error5.result
│ │ ├── fibonacci.result
│ │ ├── guarded-1.result
│ │ ├── guarded-2.result
│ │ ├── guarded-error-1.result
│ │ ├── guarded-error-2.result
│ │ ├── guarded-error-3.result
│ │ ├── nqueues.result
│ │ ├── scopy.result
│ │ ├── sealed.result
│ │ ├── test.result
│ │ ├── test1.result
│ │ ├── test2.result
│ │ ├── test3.result
│ │ ├── test4.result
│ │ ├── test5.result
│ │ ├── test6.result
│ │ ├── var-1.result
│ │ └── var-2.result
│ │ ├── runAll.py
│ │ ├── scopy.decaf
│ │ ├── sealed.decaf
│ │ ├── test1.decaf
│ │ ├── test2.decaf
│ │ ├── test3.decaf
│ │ ├── test4.decaf
│ │ ├── test5.decaf
│ │ ├── test6.decaf
│ │ ├── var-1.decaf
│ │ └── var-2.decaf
├── build.xml
├── report.pdf
├── report.tex
├── src
│ └── decaf
│ │ ├── Driver.java
│ │ ├── Location.java
│ │ ├── Option.java
│ │ ├── error
│ │ ├── BadArgCountError.java
│ │ ├── BadArgTypeError.java
│ │ ├── BadArrElementError.java
│ │ ├── BadInheritanceError.java
│ │ ├── BadLengthArgError.java
│ │ ├── BadLengthError.java
│ │ ├── BadNewArrayLength.java
│ │ ├── BadOverrideError.java
│ │ ├── BadPrintArgError.java
│ │ ├── BadReturnTypeError.java
│ │ ├── BadTestExpr.java
│ │ ├── BadVarTypeError.java
│ │ ├── BreakOutOfLoopError.java
│ │ ├── ClassNotFoundError.java
│ │ ├── DecafError.java
│ │ ├── DeclConflictError.java
│ │ ├── FieldNotAccessError.java
│ │ ├── FieldNotFoundError.java
│ │ ├── IncompatBinOpError.java
│ │ ├── IncompatUnOpError.java
│ │ ├── IntTooLargeError.java
│ │ ├── MsgError.java
│ │ ├── NewlineInStrError.java
│ │ ├── NoMainClassError.java
│ │ ├── NotArrayError.java
│ │ ├── NotClassError.java
│ │ ├── NotClassFieldError.java
│ │ ├── NotClassMethodError.java
│ │ ├── OverridingVarError.java
│ │ ├── RefNonStaticError.java
│ │ ├── RuntimeError.java
│ │ ├── SubNotIntError.java
│ │ ├── ThisInStaticFuncError.java
│ │ ├── UndeclVarError.java
│ │ ├── UnrecogCharError.java
│ │ ├── UntermCommentError.java
│ │ └── UntermStrError.java
│ │ ├── frontend
│ │ ├── BaseLexer.java
│ │ ├── Lexer.java
│ │ ├── Parser.java
│ │ ├── Parser.spec
│ │ ├── ParserHelper.java
│ │ ├── SemValue.java
│ │ └── Table.java
│ │ ├── tree
│ │ └── Tree.java
│ │ └── utils
│ │ ├── IndentPrintWriter.java
│ │ └── MiscUtils.java
├── submit.py
└── tools
│ └── pg.jar
├── pa2
├── .classpath
├── .project
├── Decaf PA2 README.pdf
├── TestCases
│ └── S2
│ │ ├── arrayerror.decaf
│ │ ├── callerror.decaf
│ │ ├── d
│ │ ├── declerror.decaf
│ │ ├── exprerror.decaf
│ │ ├── math.decaf
│ │ ├── miscerror.decaf
│ │ ├── nomainerror.decaf
│ │ ├── output
│ │ ├── arrayerror.result
│ │ ├── callerror.result
│ │ ├── declerror.result
│ │ ├── exprerror.result
│ │ ├── math.result
│ │ ├── miscerror.result
│ │ ├── nomainerror.result
│ │ ├── overrideerror.result
│ │ ├── q1-1.result
│ │ ├── q1-2.result
│ │ ├── q1-3.result
│ │ ├── q1-4.result
│ │ ├── q1-scopy-test1.result
│ │ ├── q2-sealed-test1.result
│ │ ├── q3-1.result
│ │ ├── q3-guarded-test1.result
│ │ ├── q4-1.result
│ │ ├── q4-2.result
│ │ ├── q4-3.result
│ │ ├── q4-4.result
│ │ ├── q4-5.result
│ │ ├── q4-6.result
│ │ ├── q4-var-test1.result
│ │ ├── q5-array-test1.result
│ │ ├── q5-array-test2.result
│ │ ├── q5-array-test3.result
│ │ ├── q51-1.result
│ │ ├── q52-1.result
│ │ ├── q52-2.result
│ │ ├── q52-3.result
│ │ ├── q53-1.result
│ │ ├── q53-2.result
│ │ ├── q53-3.result
│ │ ├── queue.result
│ │ ├── referror.result
│ │ ├── stack.result
│ │ ├── t1.result
│ │ ├── t2.result
│ │ ├── t3.result
│ │ ├── t4.result
│ │ ├── t5.result
│ │ ├── t6.result
│ │ ├── t7.result
│ │ ├── t8.result
│ │ ├── t9.result
│ │ ├── z0.result
│ │ ├── z1.result
│ │ ├── z2.result
│ │ ├── z3.result
│ │ ├── z4.result
│ │ ├── z5.result
│ │ ├── z6.result
│ │ ├── z7.result
│ │ ├── z8.result
│ │ └── z9.result
│ │ ├── overrideerror.decaf
│ │ ├── q1-1.decaf
│ │ ├── q1-2.decaf
│ │ ├── q1-3.decaf
│ │ ├── q1-4.decaf
│ │ ├── q1-scopy-test1.decaf
│ │ ├── q2-sealed-test1.decaf
│ │ ├── q3-1.decaf
│ │ ├── q3-guarded-test1.decaf
│ │ ├── q4-1.decaf
│ │ ├── q4-2.decaf
│ │ ├── q4-3.decaf
│ │ ├── q4-4.decaf
│ │ ├── q4-5.decaf
│ │ ├── q4-6.decaf
│ │ ├── q4-var-test1.decaf
│ │ ├── q5-array-test1.decaf
│ │ ├── q5-array-test2.decaf
│ │ ├── q5-array-test3.decaf
│ │ ├── q51-1.decaf
│ │ ├── q52-1.decaf
│ │ ├── q52-2.decaf
│ │ ├── q52-3.decaf
│ │ ├── q53-1.decaf
│ │ ├── q53-2.decaf
│ │ ├── q53-3.decaf
│ │ ├── queue.decaf
│ │ ├── referror.decaf
│ │ ├── runAll.py
│ │ ├── stack.decaf
│ │ ├── t1.decaf
│ │ ├── t2.decaf
│ │ ├── t3.decaf
│ │ ├── t4.decaf
│ │ ├── t5.decaf
│ │ ├── t6.decaf
│ │ ├── t7.decaf
│ │ ├── t8.decaf
│ │ ├── t9.decaf
│ │ ├── z0.decaf
│ │ ├── z1.decaf
│ │ ├── z2.decaf
│ │ ├── z3.decaf
│ │ ├── z4.decaf
│ │ ├── z5.decaf
│ │ ├── z6.decaf
│ │ ├── z7.decaf
│ │ ├── z8.decaf
│ │ └── z9.decaf
├── build.xml
├── report.md
├── report.pdf
├── src
│ └── decaf
│ │ ├── Driver.java
│ │ ├── Location.java
│ │ ├── Option.java
│ │ ├── error
│ │ ├── BadArgCountError.java
│ │ ├── BadArgTypeError.java
│ │ ├── BadArrCompArgTypeError.java
│ │ ├── BadArrElementError.java
│ │ ├── BadArrIndexError.java
│ │ ├── BadArrOperArgError.java
│ │ ├── BadArrTimesError.java
│ │ ├── BadDefError.java
│ │ ├── BadForeachTypeError.java
│ │ ├── BadInheritanceError.java
│ │ ├── BadLengthArgError.java
│ │ ├── BadLengthError.java
│ │ ├── BadNewArrayLength.java
│ │ ├── BadOverrideError.java
│ │ ├── BadPrintArgError.java
│ │ ├── BadReturnTypeError.java
│ │ ├── BadScopyArgError.java
│ │ ├── BadScopySrcError.java
│ │ ├── BadSealedInherError.java
│ │ ├── BadTestExpr.java
│ │ ├── BadVarTypeError.java
│ │ ├── BreakOutOfLoopError.java
│ │ ├── ClassNotFoundError.java
│ │ ├── DecafError.java
│ │ ├── DeclConflictError.java
│ │ ├── FieldNotAccessError.java
│ │ ├── FieldNotFoundError.java
│ │ ├── IncompatBinOpError.java
│ │ ├── IncompatUnOpError.java
│ │ ├── IntTooLargeError.java
│ │ ├── MsgError.java
│ │ ├── NewlineInStrError.java
│ │ ├── NoMainClassError.java
│ │ ├── NotArrayError.java
│ │ ├── NotClassError.java
│ │ ├── NotClassFieldError.java
│ │ ├── NotClassMethodError.java
│ │ ├── OverridingVarError.java
│ │ ├── RefNonStaticError.java
│ │ ├── RuntimeError.java
│ │ ├── SubNotIntError.java
│ │ ├── ThisInStaticFuncError.java
│ │ ├── UndeclVarError.java
│ │ ├── UnrecogCharError.java
│ │ └── UntermStrError.java
│ │ ├── frontend
│ │ ├── BaseLexer.java
│ │ ├── BaseParser.java
│ │ ├── Lexer.java
│ │ ├── Lexer.l
│ │ ├── Parser.java
│ │ ├── Parser.output
│ │ ├── Parser.y
│ │ ├── ParserHelper.java
│ │ └── SemValue.java
│ │ ├── scope
│ │ ├── ClassScope.java
│ │ ├── FormalScope.java
│ │ ├── GlobalScope.java
│ │ ├── LocalScope.java
│ │ ├── Scope.java
│ │ └── ScopeStack.java
│ │ ├── symbol
│ │ ├── Class.java
│ │ ├── Function.java
│ │ ├── Symbol.java
│ │ └── Variable.java
│ │ ├── tree
│ │ └── Tree.java
│ │ ├── type
│ │ ├── ArrayType.java
│ │ ├── BaseType.java
│ │ ├── ClassType.java
│ │ ├── FuncType.java
│ │ └── Type.java
│ │ ├── typecheck
│ │ ├── BuildSym.java
│ │ ├── TypeCheck.java
│ │ ├── bd
│ │ ├── origin
│ │ └── td
│ │ └── utils
│ │ ├── IndentPrintWriter.java
│ │ └── MiscUtils.java
├── submit.py
└── tools
│ ├── byacc
│ ├── byacc.linux
│ ├── byacc.linux.amd64
│ ├── byacc.mac
│ └── byaccj1.13-extended.tar.gz
│ └── jflex
│ └── JFlex.jar
├── pa3
├── .classpath
├── .project
├── Decaf PA3 README.pdf
├── TestCases
│ └── S3
│ │ ├── a
│ │ ├── a.decaf
│ │ ├── blackjack.decaf
│ │ ├── casterror.decaf
│ │ ├── hs_err_pid15474.log
│ │ ├── indexout.decaf
│ │ ├── indexout2.decaf
│ │ ├── math.decaf
│ │ ├── matrix.decaf
│ │ ├── neglength.decaf
│ │ ├── output
│ │ ├── a.result
│ │ ├── a.tac
│ │ ├── blackjack.tac
│ │ ├── casterror.result
│ │ ├── casterror.tac
│ │ ├── indexout.result
│ │ ├── indexout.tac
│ │ ├── indexout2.result
│ │ ├── indexout2.tac
│ │ ├── math.result
│ │ ├── math.tac
│ │ ├── matrix.result
│ │ ├── matrix.tac
│ │ ├── neglength.result
│ │ ├── neglength.tac
│ │ ├── q1-scopy-test1.result
│ │ ├── q1-scopy-test1.tac
│ │ ├── q3-guarded-test1.result
│ │ ├── q3-guarded-test1.tac
│ │ ├── q3-guarded-test2.result
│ │ ├── q3-guarded-test2.tac
│ │ ├── q4-var-test1.result
│ │ ├── q4-var-test1.tac
│ │ ├── q4-var-test2.result
│ │ ├── q4-var-test2.tac
│ │ ├── q5-array-test1-bool.result
│ │ ├── q5-array-test1-bool.tac
│ │ ├── q5-array-test1-class.result
│ │ ├── q5-array-test1-class.tac
│ │ ├── q5-array-test1-error.result
│ │ ├── q5-array-test1-error.tac
│ │ ├── q5-array-test1-int.result
│ │ ├── q5-array-test1-int.tac
│ │ ├── q5-array-test1-string.result
│ │ ├── q5-array-test1-string.tac
│ │ ├── q5-array-test2-default.result
│ │ ├── q5-array-test2-default.tac
│ │ ├── q5-array-test2-normal.result
│ │ ├── q5-array-test2-normal.tac
│ │ ├── q5-array-test3-break.result
│ │ ├── q5-array-test3-break.tac
│ │ ├── q5-array-test3-var.result
│ │ ├── q5-array-test3-var.tac
│ │ ├── q5-array-test3.result
│ │ ├── q5-array-test3.tac
│ │ ├── queue.result
│ │ ├── queue.tac
│ │ ├── stack.result
│ │ ├── stack.tac
│ │ ├── strcmp.result
│ │ ├── strcmp.tac
│ │ ├── test_divisionbyzero1.result
│ │ ├── test_divisionbyzero1.tac
│ │ ├── test_divisionbyzero2.result
│ │ └── test_divisionbyzero2.tac
│ │ ├── q1-scopy-test1.decaf
│ │ ├── q3-guarded-test1.decaf
│ │ ├── q3-guarded-test2.decaf
│ │ ├── q4-var-test1.decaf
│ │ ├── q4-var-test2.decaf
│ │ ├── q5-array-test1-bool.decaf
│ │ ├── q5-array-test1-class.decaf
│ │ ├── q5-array-test1-error.decaf
│ │ ├── q5-array-test1-int.decaf
│ │ ├── q5-array-test1-string.decaf
│ │ ├── q5-array-test2-default.decaf
│ │ ├── q5-array-test2-normal.decaf
│ │ ├── q5-array-test3-break.decaf
│ │ ├── q5-array-test3-var.decaf
│ │ ├── q5-array-test3.decaf
│ │ ├── queue.decaf
│ │ ├── runAll.py
│ │ ├── stack.decaf
│ │ ├── strcmp.decaf
│ │ ├── tac.jar
│ │ ├── test_divisionbyzero1.decaf
│ │ ├── test_divisionbyzero2.decaf
│ │ └── try.cpp
├── build.xml
├── report.md
├── report.pdf
├── src
│ └── decaf
│ │ ├── Driver.java
│ │ ├── Location.java
│ │ ├── Option.java
│ │ ├── backend
│ │ └── OffsetCounter.java
│ │ ├── error
│ │ ├── BadArgCountError.java
│ │ ├── BadArgTypeError.java
│ │ ├── BadArrCompArgTypeError.java
│ │ ├── BadArrElementError.java
│ │ ├── BadArrIndexError.java
│ │ ├── BadArrOperArgError.java
│ │ ├── BadArrTimesError.java
│ │ ├── BadDefError.java
│ │ ├── BadForeachTypeError.java
│ │ ├── BadInheritanceError.java
│ │ ├── BadLengthArgError.java
│ │ ├── BadLengthError.java
│ │ ├── BadNewArrayLength.java
│ │ ├── BadOverrideError.java
│ │ ├── BadPrintArgError.java
│ │ ├── BadReturnTypeError.java
│ │ ├── BadScopyArgError.java
│ │ ├── BadScopySrcError.java
│ │ ├── BadSealedInherError.java
│ │ ├── BadTestExpr.java
│ │ ├── BadVarTypeError.java
│ │ ├── BreakOutOfLoopError.java
│ │ ├── ClassNotFoundError.java
│ │ ├── DecafError.java
│ │ ├── DeclConflictError.java
│ │ ├── FieldNotAccessError.java
│ │ ├── FieldNotFoundError.java
│ │ ├── IncompatBinOpError.java
│ │ ├── IncompatUnOpError.java
│ │ ├── IntTooLargeError.java
│ │ ├── MsgError.java
│ │ ├── NewlineInStrError.java
│ │ ├── NoMainClassError.java
│ │ ├── NotArrayError.java
│ │ ├── NotClassError.java
│ │ ├── NotClassFieldError.java
│ │ ├── NotClassMethodError.java
│ │ ├── OverridingVarError.java
│ │ ├── RefNonStaticError.java
│ │ ├── RuntimeError.java
│ │ ├── SealedClassNotExtendError.java
│ │ ├── SubNotIntError.java
│ │ ├── ThisInStaticFuncError.java
│ │ ├── UndeclVarError.java
│ │ ├── UnrecogCharError.java
│ │ └── UntermStrError.java
│ │ ├── frontend
│ │ ├── BaseLexer.java
│ │ ├── BaseParser.java
│ │ ├── Lexer.java
│ │ ├── Lexer.l
│ │ ├── Parser.java
│ │ ├── Parser.output
│ │ ├── Parser.y
│ │ ├── ParserHelper.java
│ │ └── SemValue.java
│ │ ├── machdesc
│ │ └── Intrinsic.java
│ │ ├── scope
│ │ ├── ClassScope.java
│ │ ├── FormalScope.java
│ │ ├── GlobalScope.java
│ │ ├── LocalScope.java
│ │ ├── Scope.java
│ │ └── ScopeStack.java
│ │ ├── symbol
│ │ ├── Class.java
│ │ ├── Function.java
│ │ ├── Symbol.java
│ │ └── Variable.java
│ │ ├── tac
│ │ ├── Functy.java
│ │ ├── Label.java
│ │ ├── Tac.java
│ │ ├── Temp.java
│ │ └── VTable.java
│ │ ├── translate
│ │ ├── TransPass1.java
│ │ ├── TransPass2.java
│ │ └── Translater.java
│ │ ├── tree
│ │ └── Tree.java
│ │ ├── type
│ │ ├── ArrayType.java
│ │ ├── BaseType.java
│ │ ├── ClassType.java
│ │ ├── FuncType.java
│ │ └── Type.java
│ │ ├── typecheck
│ │ ├── BuildSym.java
│ │ └── TypeCheck.java
│ │ └── utils
│ │ ├── IndentPrintWriter.java
│ │ └── MiscUtils.java
├── submit.py
└── tools
│ ├── byacc
│ ├── byacc.exe
│ ├── byacc.linux
│ ├── byacc.linux.amd64
│ ├── byacc.mac
│ └── byaccj1.13-extended.tar.gz
│ ├── jflex
│ └── JFlex.jar
│ ├── tacvm-dev
│ ├── build.xml
│ └── src
│ │ └── decaf
│ │ └── tacvm
│ │ ├── Location.java
│ │ ├── Opcode.java
│ │ ├── TacVM.java
│ │ ├── exec
│ │ ├── ExecuteException.java
│ │ ├── Executor.java
│ │ ├── Inst.java
│ │ └── Memory.java
│ │ ├── parser
│ │ ├── BaseLexer.java
│ │ ├── BaseParser.java
│ │ ├── Entry.java
│ │ ├── Errs.java
│ │ ├── Lexer.java
│ │ ├── Lexer.l
│ │ ├── Parser.java
│ │ ├── Parser.output
│ │ ├── Parser.y
│ │ ├── ParserHelper.java
│ │ ├── SemValue.java
│ │ ├── Tac.java
│ │ ├── Temp.java
│ │ └── VTable.java
│ │ └── utils
│ │ └── MiscUtils.java
│ ├── test_q4.result
│ ├── test_q5.result
│ └── test_q5_paint.result
├── pa4
├── .classpath
├── .project
├── Decaf PA4 README.pdf
├── TestCases
│ ├── S2
│ │ ├── output
│ │ │ ├── z5.dout
│ │ │ ├── z5.du
│ │ │ ├── z5.result
│ │ │ ├── z5.s
│ │ │ ├── z7.dout
│ │ │ ├── z7.du
│ │ │ ├── z7.result
│ │ │ └── z7.s
│ │ ├── runAll.py
│ │ ├── z5.decaf
│ │ └── z7.decaf
│ └── S4
│ │ ├── blackjack.decaf
│ │ ├── casterror.decaf
│ │ ├── indexout.decaf
│ │ ├── math.decaf
│ │ ├── matrix.decaf
│ │ ├── neglength.decaf
│ │ ├── output
│ │ ├── blackjack.dout
│ │ ├── blackjack.du
│ │ ├── blackjack.s
│ │ ├── casterror.dout
│ │ ├── casterror.du
│ │ ├── casterror.result
│ │ ├── casterror.s
│ │ ├── indexout.dout
│ │ ├── indexout.du
│ │ ├── indexout.result
│ │ ├── indexout.s
│ │ ├── math.dout
│ │ ├── math.du
│ │ ├── math.result
│ │ ├── math.s
│ │ ├── matrix.dout
│ │ ├── matrix.du
│ │ ├── matrix.result
│ │ ├── matrix.s
│ │ ├── neglength.dout
│ │ ├── neglength.du
│ │ ├── neglength.result
│ │ ├── neglength.s
│ │ ├── queue.dout
│ │ ├── queue.du
│ │ ├── queue.result
│ │ ├── queue.s
│ │ ├── stack.dout
│ │ ├── stack.du
│ │ ├── stack.result
│ │ ├── stack.s
│ │ ├── strcmp.dout
│ │ ├── strcmp.du
│ │ ├── strcmp.result
│ │ ├── strcmp.s
│ │ ├── t0.dout
│ │ ├── t0.du
│ │ ├── t0.result
│ │ ├── t0.s
│ │ ├── t1.dout
│ │ ├── t1.du
│ │ ├── t1.result
│ │ ├── t1.s
│ │ ├── t2.dout
│ │ ├── t2.du
│ │ ├── t2.result
│ │ ├── t2.s
│ │ ├── t3.dout
│ │ ├── t3.du
│ │ ├── t3.result
│ │ ├── t3.s
│ │ ├── t4.dout
│ │ ├── t4.du
│ │ ├── t4.result
│ │ ├── t4.s
│ │ ├── t5.dout
│ │ ├── t5.du
│ │ ├── t5.result
│ │ ├── t5.s
│ │ ├── t6.dout
│ │ ├── t6.du
│ │ ├── t6.result
│ │ ├── t6.s
│ │ ├── t7.dout
│ │ ├── t7.du
│ │ ├── t7.result
│ │ ├── t7.s
│ │ ├── t8.dout
│ │ ├── t8.du
│ │ ├── t8.result
│ │ ├── t8.s
│ │ ├── t9.dout
│ │ ├── t9.du
│ │ ├── t9.result
│ │ └── t9.s
│ │ ├── queue.decaf
│ │ ├── runAll.py
│ │ ├── runBlackjack.py
│ │ ├── stack.decaf
│ │ ├── strcmp.decaf
│ │ ├── t0.decaf
│ │ ├── t1.decaf
│ │ ├── t2.decaf
│ │ ├── t3.decaf
│ │ ├── t4.decaf
│ │ ├── t5.decaf
│ │ ├── t6.decaf
│ │ ├── t7.decaf
│ │ ├── t8.decaf
│ │ └── t9.decaf
├── build.xml
├── report.md
├── report.pdf
├── src
│ └── decaf
│ │ ├── Driver.java
│ │ ├── Location.java
│ │ ├── Option.java
│ │ ├── backend
│ │ ├── Mips.java
│ │ ├── MipsAsm.java
│ │ ├── MipsFrameManager.java
│ │ ├── MipsRegister.java
│ │ ├── OffsetCounter.java
│ │ └── RegisterAllocator.java
│ │ ├── dataflow
│ │ ├── BasicBlock.java
│ │ ├── FlowGraph.java
│ │ ├── IDAllocator.java
│ │ └── Pair.java
│ │ ├── error
│ │ ├── BadArgCountError.java
│ │ ├── BadArgTypeError.java
│ │ ├── BadArrElementError.java
│ │ ├── BadInheritanceError.java
│ │ ├── BadLengthArgError.java
│ │ ├── BadLengthError.java
│ │ ├── BadNewArrayLength.java
│ │ ├── BadOverrideError.java
│ │ ├── BadPrintArgError.java
│ │ ├── BadReturnTypeError.java
│ │ ├── BadTestExpr.java
│ │ ├── BadVarTypeError.java
│ │ ├── BreakOutOfLoopError.java
│ │ ├── ClassNotFoundError.java
│ │ ├── DecafError.java
│ │ ├── DeclConflictError.java
│ │ ├── FieldNotAccessError.java
│ │ ├── FieldNotFoundError.java
│ │ ├── IncompatBinOpError.java
│ │ ├── IncompatUnOpError.java
│ │ ├── IntTooLargeError.java
│ │ ├── MsgError.java
│ │ ├── NewlineInStrError.java
│ │ ├── NoMainClassError.java
│ │ ├── NotArrayError.java
│ │ ├── NotClassError.java
│ │ ├── NotClassFieldError.java
│ │ ├── NotClassMethodError.java
│ │ ├── OverridingVarError.java
│ │ ├── RefNonStaticError.java
│ │ ├── RuntimeError.java
│ │ ├── SubNotIntError.java
│ │ ├── ThisInStaticFuncError.java
│ │ ├── UndeclVarError.java
│ │ ├── UnrecogCharError.java
│ │ └── UntermStrError.java
│ │ ├── frontend
│ │ ├── BaseLexer.java
│ │ ├── BaseParser.java
│ │ ├── Lexer.java
│ │ ├── Lexer.l
│ │ ├── Parser.java
│ │ ├── Parser.output
│ │ ├── Parser.y
│ │ ├── ParserHelper.java
│ │ └── SemValue.java
│ │ ├── machdesc
│ │ ├── Asm.java
│ │ ├── Intrinsic.java
│ │ ├── MachineDescription.java
│ │ └── Register.java
│ │ ├── scope
│ │ ├── ClassScope.java
│ │ ├── FormalScope.java
│ │ ├── GlobalScope.java
│ │ ├── LocalScope.java
│ │ ├── Scope.java
│ │ └── ScopeStack.java
│ │ ├── symbol
│ │ ├── Class.java
│ │ ├── Function.java
│ │ ├── Symbol.java
│ │ └── Variable.java
│ │ ├── tac
│ │ ├── Functy.java
│ │ ├── Label.java
│ │ ├── Tac.java
│ │ ├── Temp.java
│ │ └── VTable.java
│ │ ├── translate
│ │ ├── TransPass1.java
│ │ ├── TransPass2.java
│ │ └── Translater.java
│ │ ├── tree
│ │ └── Tree.java
│ │ ├── type
│ │ ├── ArrayType.java
│ │ ├── BaseType.java
│ │ ├── ClassType.java
│ │ ├── FuncType.java
│ │ └── Type.java
│ │ ├── typecheck
│ │ ├── BuildSym.java
│ │ └── TypeCheck.java
│ │ └── utils
│ │ ├── IndentPrintWriter.java
│ │ └── MiscUtils.java
├── submit.py
└── tools
│ ├── byacc
│ ├── byacc.linux
│ ├── byacc.linux.amd64
│ ├── byacc.mac
│ └── byaccj1.13-extended.tar.gz
│ ├── jflex
│ └── JFlex.jar
│ └── spim
│ ├── cygwin1.dll
│ ├── exceptions.s
│ ├── spim-7.3.tar.gz
│ ├── spim.exe
│ ├── spim.linux
│ ├── spim.mac
│ └── trap.handler
└── pa5
├── .classpath
├── .project
├── Decaf PA5 README.pdf
├── TestCases
├── S1
│ ├── error1.decaf
│ ├── error2.decaf
│ ├── error3.decaf
│ ├── error4.decaf
│ ├── error5.decaf
│ ├── fibonacci.decaf
│ ├── nqueues.decaf
│ ├── output
│ │ ├── error1.result
│ │ ├── error2.result
│ │ ├── error3.result
│ │ ├── error4.result
│ │ ├── error5.result
│ │ ├── fibonacci.result
│ │ ├── nqueues.result
│ │ ├── test1.result
│ │ ├── test2.result
│ │ ├── test3.result
│ │ ├── test4.result
│ │ ├── test5.result
│ │ └── test6.result
│ ├── runAll.py
│ ├── test1.decaf
│ ├── test2.decaf
│ ├── test3.decaf
│ ├── test4.decaf
│ ├── test5.decaf
│ └── test6.decaf
├── S2
│ ├── arrayerror.decaf
│ ├── callerror.decaf
│ ├── declerror.decaf
│ ├── exprerror.decaf
│ ├── math.decaf
│ ├── miscerror.decaf
│ ├── nomainerror.decaf
│ ├── output
│ │ ├── arrayerror.result
│ │ ├── callerror.result
│ │ ├── declerror.result
│ │ ├── exprerror.result
│ │ ├── math.result
│ │ ├── miscerror.result
│ │ ├── nomainerror.result
│ │ ├── overrideerror.result
│ │ ├── queue.result
│ │ ├── referror.result
│ │ ├── stack.result
│ │ ├── t1.result
│ │ ├── t2.result
│ │ ├── t3.result
│ │ ├── t4.result
│ │ ├── t5.result
│ │ ├── t6.result
│ │ ├── t7.result
│ │ ├── t8.result
│ │ ├── t9.result
│ │ ├── z0.result
│ │ ├── z1.result
│ │ ├── z2.result
│ │ ├── z3.result
│ │ ├── z4.result
│ │ ├── z5.result
│ │ ├── z6.result
│ │ ├── z7.result
│ │ ├── z8.result
│ │ └── z9.result
│ ├── overrideerror.decaf
│ ├── queue.decaf
│ ├── referror.decaf
│ ├── runAll.py
│ ├── stack.decaf
│ ├── t1.decaf
│ ├── t2.decaf
│ ├── t3.decaf
│ ├── t4.decaf
│ ├── t5.decaf
│ ├── t6.decaf
│ ├── t7.decaf
│ ├── t8.decaf
│ ├── t9.decaf
│ ├── z0.decaf
│ ├── z1.decaf
│ ├── z2.decaf
│ ├── z3.decaf
│ ├── z4.decaf
│ ├── z5.decaf
│ ├── z6.decaf
│ ├── z7.decaf
│ ├── z8.decaf
│ └── z9.decaf
├── S3
│ ├── blackjack.decaf
│ ├── casterror.decaf
│ ├── indexout.decaf
│ ├── math.decaf
│ ├── matrix.decaf
│ ├── neglength.decaf
│ ├── output
│ │ ├── casterror.result
│ │ ├── casterror.tac
│ │ ├── indexout.result
│ │ ├── indexout.tac
│ │ ├── math.result
│ │ ├── math.tac
│ │ ├── matrix.result
│ │ ├── matrix.tac
│ │ ├── neglength.result
│ │ ├── neglength.tac
│ │ ├── queue.result
│ │ ├── queue.tac
│ │ ├── stack.result
│ │ ├── stack.tac
│ │ ├── strcmp.result
│ │ ├── strcmp.tac
│ │ ├── t1.result
│ │ ├── t1.tac
│ │ ├── t2.result
│ │ ├── t2.tac
│ │ ├── t3.result
│ │ ├── t3.tac
│ │ ├── t4.result
│ │ ├── t4.tac
│ │ ├── t5.result
│ │ ├── t5.tac
│ │ ├── t6.result
│ │ ├── t6.tac
│ │ ├── t7.result
│ │ ├── t7.tac
│ │ ├── t8.result
│ │ ├── t8.tac
│ │ ├── t9.result
│ │ └── t9.tac
│ ├── queue.decaf
│ ├── runAll.py
│ ├── stack.decaf
│ ├── strcmp.decaf
│ ├── t1.decaf
│ ├── t2.decaf
│ ├── t3.decaf
│ ├── t4.decaf
│ ├── t5.decaf
│ ├── t6.decaf
│ ├── t7.decaf
│ ├── t8.decaf
│ ├── t9.decaf
│ └── tac.jar
└── S4
│ ├── blackjack.decaf
│ ├── casterror.decaf
│ ├── col.s
│ ├── indexout.decaf
│ ├── math.decaf
│ ├── matrix.decaf
│ ├── neglength.decaf
│ ├── nocol.s
│ ├── output
│ ├── blackjack.dout
│ ├── blackjack.s
│ ├── casterror.dout
│ ├── casterror.result
│ ├── casterror.s
│ ├── indexout.dout
│ ├── indexout.result
│ ├── indexout.s
│ ├── mat
│ │ ├── matrix.dout
│ │ ├── matrix.result
│ │ └── matrix.s
│ ├── math.dout
│ ├── math.result
│ ├── math.s
│ ├── matrix.dout
│ ├── matrix.result
│ ├── matrix.s
│ ├── neglength.dout
│ ├── neglength.result
│ ├── neglength.s
│ ├── queue.dout
│ ├── queue.result
│ ├── queue.s
│ ├── stack.dout
│ ├── stack.result
│ ├── stack.s
│ ├── strcmp.dout
│ ├── strcmp.result
│ ├── strcmp.s
│ ├── t0.dout
│ ├── t0.result
│ ├── t0.s
│ ├── t1.dout
│ ├── t1.result
│ ├── t1.s
│ ├── t10.dout
│ ├── t10.result
│ ├── t10.s
│ ├── t2.dout
│ ├── t2.result
│ ├── t2.s
│ ├── t3.dout
│ ├── t3.result
│ ├── t3.s
│ ├── t4.dout
│ ├── t4.result
│ ├── t4.s
│ ├── t5.dout
│ ├── t5.result
│ ├── t5.s
│ ├── t6.dout
│ ├── t6.result
│ ├── t6.s
│ ├── t7.dout
│ ├── t7.result
│ ├── t7.s
│ ├── t8.dout
│ ├── t8.result
│ ├── t8.s
│ ├── t9.dout
│ ├── t9.result
│ └── t9.s
│ ├── queue.decaf
│ ├── runAll.py
│ ├── runBlackjack.py
│ ├── stack.decaf
│ ├── strcmp.decaf
│ ├── t0.decaf
│ ├── t1.decaf
│ ├── t10.decaf
│ ├── t2.decaf
│ ├── t3.decaf
│ ├── t4.decaf
│ ├── t5.decaf
│ ├── t6.decaf
│ ├── t7.decaf
│ ├── t8.decaf
│ └── t9.decaf
├── build.xml
├── cleantree.sh
├── report.md
├── report.pdf
├── src
├── .classpath
├── .gitignore
├── .project
└── decaf
│ ├── Driver.java
│ ├── Location.java
│ ├── Option.java
│ ├── dataflow
│ ├── BasicBlock.java
│ └── FlowGraph.java
│ ├── error
│ ├── BadArgCountError.java
│ ├── BadArgTypeError.java
│ ├── BadArrElementError.java
│ ├── BadInheritanceError.java
│ ├── BadLengthArgError.java
│ ├── BadLengthError.java
│ ├── BadNewArrayLength.java
│ ├── BadOverrideError.java
│ ├── BadPrintArgError.java
│ ├── BadReturnTypeError.java
│ ├── BadTestExpr.java
│ ├── BadVarTypeError.java
│ ├── BreakOutOfLoopError.java
│ ├── ClassNotFoundError.java
│ ├── DecafError.java
│ ├── DeclConflictError.java
│ ├── FieldNotAccessError.java
│ ├── FieldNotFoundError.java
│ ├── IncompatBinOpError.java
│ ├── IncompatUnOpError.java
│ ├── IntTooLargeError.java
│ ├── MsgError.java
│ ├── NewlineInStrError.java
│ ├── NoMainClassError.java
│ ├── NotArrayError.java
│ ├── NotClassError.java
│ ├── NotClassFieldError.java
│ ├── NotClassMethodError.java
│ ├── OverridingVarError.java
│ ├── RefNonStaticError.java
│ ├── RuntimeError.java
│ ├── SubNotIntError.java
│ ├── ThisInStaticFuncError.java
│ ├── UndeclVarError.java
│ ├── UnrecogCharError.java
│ └── UntermStrError.java
│ ├── frontend
│ ├── BaseLexer.java
│ ├── BaseParser.java
│ ├── Lexer.java
│ ├── Lexer.l
│ ├── Parser.java
│ ├── Parser.output
│ ├── Parser.y
│ ├── ParserHelper.java
│ └── SemValue.java
│ ├── machdesc
│ ├── Asm.java
│ ├── Intrinsic.java
│ ├── MachineDescription.java
│ └── Register.java
│ ├── scope
│ ├── ClassScope.java
│ ├── FormalScope.java
│ ├── GlobalScope.java
│ ├── LocalScope.java
│ ├── Scope.java
│ └── ScopeStack.java
│ ├── symbol
│ ├── Class.java
│ ├── Function.java
│ ├── Symbol.java
│ └── Variable.java
│ ├── tac
│ ├── Functy.java
│ ├── Label.java
│ ├── Tac.java
│ ├── TacTypes.class
│ ├── Temp.java
│ └── VTable.java
│ ├── translate
│ ├── TransPass1.java
│ ├── TransPass2.java
│ └── Translater.java
│ ├── tree
│ └── Tree.java
│ ├── type
│ ├── ArrayType.java
│ ├── BaseType.java
│ ├── ClassType.java
│ ├── FuncType.java
│ └── Type.java
│ ├── typecheck
│ ├── BuildSym.java
│ └── TypeCheck.java
│ └── utils
│ ├── IndentPrintWriter.java
│ └── MiscUtils.java
├── submit.py
└── tools
├── byacc
├── byacc.linux
├── byacc.linux.amd64
└── byacc.mac
├── jflex
└── JFlex.jar
└── spim
├── cygwin1.dll
├── exceptions.s
├── spim.exe
├── spim.linux
├── spim.mac
└── trap.handler
/.gitignore:
--------------------------------------------------------------------------------
1 | bin
2 | result
3 | *.zip
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Decaf
2 |
3 | 6次编译pa作业
4 |
--------------------------------------------------------------------------------
/pa1a/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/pa1a/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | hw1
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/pa1a/Decaf PA1-A README.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa1a/Decaf PA1-A README.pdf
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/array-comp.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int[] xs;
4 | xs = new int[10];
5 |
6 | int[] plus1;
7 | plus1 = [x+1 for x in xs];
8 |
9 | bool[] is_positive;
10 | is_positive = [x > 0 for x in xs];
11 |
12 | int[] positive;
13 | positive = [x for x in xs if x > 0];
14 |
15 | int y;
16 | y = 3;
17 | int[] times_y_ge_5;
18 | times_y = [x*y for x in xs if x >= 5];
19 | }
20 | }
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/array-concat.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static int[] empty() {
3 | int[] nil;
4 | nil = new int[0];
5 | return nil;
6 | }
7 |
8 | static void main() {
9 | int[] ws;
10 | int[] xs;
11 | bool[] ys;
12 | string[] zs;
13 |
14 | int[] arr;
15 | arr = ws ++ xs;
16 | int[] err;
17 | err = ws ++ xs ++ ys;
18 | int[] arr1;
19 | arr1 = ws ++ xs ++ empty();
20 | }
21 | }
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/array-const-err.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int[] xs;
4 | xs = [1,0,-1]; // -1 is an expression, not a constant!
5 | }
6 | }
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/array-const.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int[] xs;
4 | xs = [1,2,3];
5 | bool[] ys;
6 | ys = [true,false,"false"];
7 | string[] zs;
8 | zs = ["one"];
9 | int[] nil;
10 | nil = [];
11 |
12 | int[] manyOnes;
13 | manyOnes = 1 %% 10;
14 | string[][] manyzs;
15 | manyzs = zs %% 5 * 6;
16 | }
17 | }
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/error1.decaf:
--------------------------------------------------------------------------------
1 | // This Program should trigger an "Unrecognized Character Error"
2 |
3 | class Main {
4 | static void main() {
5 | int i;
6 | i = i ^ -1; // error!
7 | }
8 | }
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/error2.decaf:
--------------------------------------------------------------------------------
1 | // This Program should trigger an "Integer Too Large Error"
2 |
3 | class Main {
4 | static void main() {
5 | int i;
6 |
7 | i = 73295739294; // error!
8 | i = 3141592653; // error too!
9 | }
10 | }
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/error3.decaf:
--------------------------------------------------------------------------------
1 | // This Program should trigger a "Syntax Error"
2 |
3 | class Main {
4 | static void main() {
5 | int i = 0; // error! we don't support this grammar
6 |
7 | i = i + 1;
8 | }
9 | }
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/error4.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | string str;
4 | str = "string
5 | ";
6 | }
7 | }
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/error5.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | string s;
4 | s = "str
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/guarded-1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | int foo(int x, int y, int z) {
3 | string s;
4 | if { x + y == z: return 2 * z;
5 | ||| x < 0 || y < 0 && z < 0: s = "negative";
6 | ||| x + y != y + x: s = "impossible";
7 | }
8 | return s;
9 | }
10 |
11 | static int main() {
12 | return foo(1,2,3);
13 | }
14 | }
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/guarded-2.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | void foo() {
3 | if { true: if { false: Print("unreachable"); } }
4 | }
5 |
6 | void bar() {
7 | int x;
8 | x = ReadInteger();
9 | if { true: if (x > 0) if { x == 1: Print("x=1"); ||| x == 2: Print("x=2"); }
10 | else if {} }
11 | }
12 |
13 | static void main() {
14 | if {}
15 | foo();
16 | bar();
17 | }
18 | }
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/guarded-error-1.decaf:
--------------------------------------------------------------------------------
1 | // Unterminated `}` for `if`.
2 |
3 | class Main {
4 | static void main() {
5 | if { true: if { false: if { } }
6 | while (false) {}
7 | }
8 | }
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/guarded-error-2.decaf:
--------------------------------------------------------------------------------
1 | // Missing `|||` for `if`.
2 |
3 | class Main {
4 | void foo(int i) {
5 | return i + 1;
6 | }
7 |
8 | static void main() {
9 | int x;
10 | if { x == 1: foo(1); x == 2: foo(2); }
11 | }
12 | }
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/guarded-error-3.decaf:
--------------------------------------------------------------------------------
1 | // Extra `|||` for `if`.
2 |
3 | class Main {
4 | void foo(int i) {
5 | return i + 1;
6 | }
7 |
8 | static void main() {
9 | int x;
10 | if { x == 1: foo(1); ||| x == 2: foo(2); ||| }
11 | }
12 | }
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/output/array-const-err.result:
--------------------------------------------------------------------------------
1 | *** Error at (4,19): syntax error
2 |
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/output/error1.result:
--------------------------------------------------------------------------------
1 | *** Error at (6,15): unrecognized character '^'
2 |
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/output/error2.result:
--------------------------------------------------------------------------------
1 | *** Error at (7,13): integer literal 73295739294 is too large
2 | *** Error at (8,13): integer literal 3141592653 is too large
3 |
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/output/error3.result:
--------------------------------------------------------------------------------
1 | *** Error at (5,15): syntax error
2 |
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/output/error4.result:
--------------------------------------------------------------------------------
1 | *** Error at (4,15): illegal newline in string constant "string"
2 |
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/output/error5.result:
--------------------------------------------------------------------------------
1 | *** Error at (4,13): unterminated string constant "str"
2 | *** Error at (4,17): syntax error
3 |
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/output/guarded-error-1.result:
--------------------------------------------------------------------------------
1 | *** Error at (6,9): syntax error
2 |
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/output/guarded-error-2.result:
--------------------------------------------------------------------------------
1 | *** Error at (10,30): syntax error
2 |
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/output/guarded-error-3.result:
--------------------------------------------------------------------------------
1 | *** Error at (10,54): syntax error
2 |
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/output/sealed.result:
--------------------------------------------------------------------------------
1 | program
2 | sealed class A
3 | sealed class A1 A
4 | class B
5 | class C B
6 | sealed class D B
7 |
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/output/test5.result:
--------------------------------------------------------------------------------
1 | program
2 | class Main
3 | static func main voidtype
4 | formals
5 | stmtblock
6 | vardef s stringtype
7 | assign
8 | varref s
9 | stringconst "\\\"\n"
10 |
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/output/var-1.result:
--------------------------------------------------------------------------------
1 | program
2 | class Main
3 | static func main voidtype
4 | formals
5 | stmtblock
6 | assign
7 | var x
8 | intconst 1
9 | assign
10 | var y
11 | boolconst true
12 | assign
13 | var z
14 | stringconst "hello"
15 |
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/sealed.decaf:
--------------------------------------------------------------------------------
1 | sealed class A {}
2 |
3 | sealed class A1 extends A {}
4 |
5 | class B {}
6 |
7 | class C extends B {}
8 |
9 | sealed class D extends B {}
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/test1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | bool field;
3 |
4 | class Main another;
5 |
6 | int[] foo(int y) {
7 | int[] q;
8 | int i;
9 |
10 | q = new int[y];
11 | i = 0;
12 | while (i < y) {
13 | q[i] = i;
14 | i = i + 1;
15 | }
16 |
17 | return q;
18 | }
19 |
20 | static int main() {
21 | return this.foo(5).length();
22 | }
23 | }
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/test3.decaf:
--------------------------------------------------------------------------------
1 | class MultipleFormals {
2 |
3 | int foo(int x, int y, int z) {
4 | return (x + y + z)/3;
5 | }
6 |
7 | int method() {
8 | int x;
9 | int y;
10 | int z;
11 |
12 | x = 3;
13 | y = x + x * x;
14 | z = (x - y / x) % y;
15 |
16 | return foo(x, y, z);
17 | }
18 | }
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/test4.decaf:
--------------------------------------------------------------------------------
1 | class Father {
2 | int field;
3 |
4 | void method(int f) {
5 | if (f > 0 && f < 10) {
6 | f = f - 3;
7 | return method(f);
8 | }
9 | }
10 | }
11 |
12 | class Child extends Father {
13 | void start() {
14 | class Father p;
15 |
16 | p = this;
17 | p.field = 5;
18 | p = null;
19 |
20 | Print(this.field);
21 | }
22 | }
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/test5.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | string s;
4 | s = "\\\"\n";
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/var-1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | var x = 1;
4 | var y = true;
5 | var z = "hello";
6 | }
7 | }
--------------------------------------------------------------------------------
/pa1a/TestCases/S1/var-2.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static int foo() {
3 | var cnt = 1;
4 | for (var i = 0; i < 100; i = i + 2) {
5 | cnt = cnt * i;
6 | }
7 |
8 | return cnt;
9 | }
10 |
11 | static void main() {
12 | var k = foo();
13 | Print(k);
14 | }
15 | }
--------------------------------------------------------------------------------
/pa1a/report.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa1a/report.pdf
--------------------------------------------------------------------------------
/pa1a/src/decaf/error/BadArrElementError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:array base type must be non-void type
7 | * PA2
8 | */
9 | public class BadArrElementError extends DecafError {
10 |
11 | public BadArrElementError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "array element type must be non-void type";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa1a/src/decaf/error/BadInheritanceError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:illegal class inheritance (should be a cyclic)
7 | * PA2
8 | */
9 | public class BadInheritanceError extends DecafError {
10 |
11 | public BadInheritanceError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "illegal class inheritance (should be a cyclic)";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa1a/src/decaf/error/BadLengthError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:'length' can only be applied to arrays
7 | * PA2
8 | */
9 | public class BadLengthError extends DecafError {
10 |
11 | public BadLengthError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "'length' can only be applied to arrays";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa1a/src/decaf/error/BadNewArrayLength.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:new array length must be an integer
7 | * PA2
8 | */
9 | public class BadNewArrayLength extends DecafError {
10 |
11 | public BadNewArrayLength(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "new array length must be an integer";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa1a/src/decaf/error/BadTestExpr.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:test expression must have bool type
7 | * PA2
8 | */
9 | public class BadTestExpr extends DecafError {
10 |
11 | public BadTestExpr(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "test expression must have bool type";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa1a/src/decaf/error/BreakOutOfLoopError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:'break' is only allowed inside a loop
7 | * PA2
8 | */
9 | public class BreakOutOfLoopError extends DecafError {
10 |
11 | public BreakOutOfLoopError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "'break' is only allowed inside a loop";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa1a/src/decaf/error/ClassNotFoundError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:class 'zig' not found
7 | * PA2
8 | */
9 | public class ClassNotFoundError extends DecafError {
10 |
11 | private String name;
12 |
13 | public ClassNotFoundError(Location location, String name) {
14 | super(location);
15 | this.name = name;
16 | }
17 |
18 | @Override
19 | protected String getErrMsg() {
20 | return "class '" + name + "' not found";
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/pa1a/src/decaf/error/MsgError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * 仅供Parser的yyerror函数使用
7 | */
8 | public class MsgError extends DecafError {
9 |
10 | private String msg;
11 |
12 | public MsgError(Location location, String msg) {
13 | super(location);
14 | this.msg = msg;
15 | }
16 |
17 | @Override
18 | protected String getErrMsg() {
19 | return msg;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/pa1a/src/decaf/error/NotArrayError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:[] can only be applied to arrays
7 | * PA2
8 | */
9 | public class NotArrayError extends DecafError {
10 |
11 | public NotArrayError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "[] can only be applied to arrays";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa1a/src/decaf/error/NotClassError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * string is not a class type.
7 | */
8 | public class NotClassError extends DecafError {
9 |
10 | private String type;
11 |
12 | public NotClassError(String type, Location location) {
13 | super(location);
14 | this.type = type;
15 | }
16 |
17 | @Override
18 | protected String getErrMsg() {
19 | return type + " is not a class type";
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/pa1a/src/decaf/error/SubNotIntError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:array subscript must be an integer
7 | * PA2
8 | */
9 | public class SubNotIntError extends DecafError {
10 |
11 | public SubNotIntError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "array subscript must be an integer";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa1a/src/decaf/error/ThisInStaticFuncError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * can not use this in static function
7 | * PA2
8 | */
9 | public class ThisInStaticFuncError extends DecafError {
10 |
11 | public ThisInStaticFuncError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "can not use this in static function";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa1a/src/decaf/error/UndeclVarError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:undeclared variable 'python'
7 | * PA2
8 | */
9 | public class UndeclVarError extends DecafError {
10 |
11 | private String name;
12 |
13 | public UndeclVarError(Location location, String name) {
14 | super(location);
15 | this.name = name;
16 | }
17 |
18 | @Override
19 | protected String getErrMsg() {
20 | return "undeclared variable '" + name + "'";
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/pa1a/src/decaf/error/UnrecogCharError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:unrecognized char: '@'
7 | * PA1
8 | */
9 | public class UnrecogCharError extends DecafError {
10 |
11 | private char c;
12 |
13 | public UnrecogCharError(Location location, char c) {
14 | super(location);
15 | this.c = c;
16 | }
17 |
18 | @Override
19 | protected String getErrMsg() {
20 | return "unrecognized character '" + c + "'";
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/pa1a/tools/byacc/byacc.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa1a/tools/byacc/byacc.exe
--------------------------------------------------------------------------------
/pa1a/tools/byacc/byacc.linux:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa1a/tools/byacc/byacc.linux
--------------------------------------------------------------------------------
/pa1a/tools/byacc/byacc.linux.amd64:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa1a/tools/byacc/byacc.linux.amd64
--------------------------------------------------------------------------------
/pa1a/tools/byacc/byacc.mac:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa1a/tools/byacc/byacc.mac
--------------------------------------------------------------------------------
/pa1a/tools/byacc/byaccj1.13-extended.tar.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa1a/tools/byacc/byaccj1.13-extended.tar.gz
--------------------------------------------------------------------------------
/pa1a/tools/jflex/JFlex.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa1a/tools/jflex/JFlex.jar
--------------------------------------------------------------------------------
/pa1b/Decaf PA1-B README.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa1b/Decaf PA1-B README.pdf
--------------------------------------------------------------------------------
/pa1b/TestCases/S1+/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa1b/TestCases/S1+/.DS_Store
--------------------------------------------------------------------------------
/pa1b/TestCases/S1+/array-comp.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int[] xs;
4 | xs = new int[10];
5 |
6 | int[] plus1;
7 | plus1 = [|x+1 for x in xs|];
8 |
9 | bool[] is_positive;
10 | is_positive = [|x > 0 for x in xs|];
11 |
12 | int[] positive;
13 | positive = [|x for x in xs if x > 0|];
14 |
15 | int y;
16 | y = 3;
17 | int[] times_y_ge_5;
18 | times_y = [|x*y for x in xs if x >= 5|];
19 | }
20 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1+/array-concat.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static int[] empty() {
3 | int[] nil;
4 | nil = new int[0];
5 | return nil;
6 | }
7 |
8 | static void main() {
9 | int[] ws;
10 | int[] xs;
11 | bool[] ys;
12 | string[] zs;
13 |
14 | int[] arr;
15 | arr = ws ++ xs;
16 | int[] err;
17 | err = ws ++ xs ++ ys;
18 | int[] arr1;
19 | arr1 = ws ++ xs ++ empty();
20 | }
21 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1+/array-const.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int[] xs;
4 | xs = [1,2,3];
5 | bool[] ys;
6 | ys = [true,false,"false"];
7 | string[] zs;
8 | zs = ["one"];
9 | int[] nil;
10 | nil = [];
11 |
12 | int[] manyOnes;
13 | manyOnes = 1 %% 10;
14 | string[][] manyzs;
15 | manyzs = zs %% 5 * 6;
16 | }
17 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1+/guarded-1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | int foo(int x, int y, int z) {
3 | string s;
4 | if { x + y == z: return 2 * z;
5 | ||| x < 0 || y < 0 && z < 0: s = "negative";
6 | ||| x + y != y + x: s = "impossible";
7 | }
8 | return s;
9 | }
10 |
11 | static int main() {
12 | return foo(1,2,3);
13 | }
14 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1+/guarded-2.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | void foo() {
3 | if { true: if { false: Print("unreachable"); } }
4 | }
5 |
6 | void bar() {
7 | int x;
8 | x = ReadInteger();
9 | if { true: if (x > 0) if { x == 1: Print("x=1"); ||| x == 2: Print("x=2"); }
10 | else if {} }
11 | }
12 |
13 | static void main() {
14 | if {}
15 | foo();
16 | bar();
17 | }
18 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1+/output/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa1b/TestCases/S1+/output/.DS_Store
--------------------------------------------------------------------------------
/pa1b/TestCases/S1+/output/sealed.result:
--------------------------------------------------------------------------------
1 | program
2 | sealed class A
3 | sealed class A1 A
4 | class B
5 | class C B
6 | sealed class D B
7 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1+/output/test5.result:
--------------------------------------------------------------------------------
1 | program
2 | class Main
3 | static func main voidtype
4 | formals
5 | stmtblock
6 | vardef s stringtype
7 | assign
8 | varref s
9 | stringconst "\\\"\n"
10 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1+/output/var-1.result:
--------------------------------------------------------------------------------
1 | program
2 | class Main
3 | static func main voidtype
4 | formals
5 | stmtblock
6 | assign
7 | var x
8 | intconst 1
9 | assign
10 | var y
11 | boolconst true
12 | assign
13 | var z
14 | stringconst "hello"
15 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1+/sealed.decaf:
--------------------------------------------------------------------------------
1 | sealed class A {}
2 |
3 | sealed class A1 extends A {}
4 |
5 | class B {}
6 |
7 | class C extends B {}
8 |
9 | sealed class D extends B {}
--------------------------------------------------------------------------------
/pa1b/TestCases/S1+/test1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | bool field;
3 |
4 | class Main another;
5 |
6 | int[] foo(int y) {
7 | int[] q;
8 | int i;
9 |
10 | q = new int[y];
11 | i = 0;
12 | while (i < y) {
13 | q[i] = i;
14 | i = i + 1;
15 | }
16 |
17 | return q;
18 | }
19 |
20 | static int main() {
21 | return this.foo(5).length();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1+/test3.decaf:
--------------------------------------------------------------------------------
1 | class MultipleFormals {
2 |
3 | int foo(int x, int y, int z) {
4 | return (x + y + z)/3;
5 | }
6 |
7 | int method() {
8 | int x;
9 | int y;
10 | int z;
11 |
12 | x = 3;
13 | y = x + x * x;
14 | z = (x - y / x) % y;
15 |
16 | return foo(x, y, z);
17 | }
18 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1+/test4.decaf:
--------------------------------------------------------------------------------
1 | class Father {
2 | int field;
3 |
4 | void method(int f) {
5 | if (f > 0 && f < 10) {
6 | f = f - 3;
7 | return method(f);
8 | }
9 | }
10 | }
11 |
12 | class Child extends Father {
13 | void start() {
14 | class Father p;
15 |
16 | p = this;
17 | p.field = 5;
18 | p = null;
19 |
20 | Print(this.field);
21 | }
22 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1+/test5.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | string s;
4 | s = "\\\"\n";
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1+/var-1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | var x = 1;
4 | var y = true;
5 | var z = "hello";
6 | }
7 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1+/var-2.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static int foo() {
3 | var cnt = 1;
4 | for (var i = 0; i < 100; i = i + 2) {
5 | cnt = cnt * i;
6 | }
7 |
8 | return cnt;
9 | }
10 |
11 | static void main() {
12 | var k = foo();
13 | Print(k);
14 | }
15 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa1b/TestCases/S1-/.DS_Store
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/array-errors.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | var arr = [1,2,3,4];
4 | var foo = arr[5] default; // error 1: missing expr after `default`
5 | var bar = [|x * 2 for x in arr if|]; // error 2: missing expr after `if`
6 | foreach (var x in arr while) { // error 3: missing expr after `while`
7 | Print(x);
8 | }
9 | var x = [1,2,3,]; // error 4: extra `,`
10 | }
11 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/error1.decaf:
--------------------------------------------------------------------------------
1 | // This Program should trigger an "Unrecognized Character Error"
2 |
3 | class Main {
4 | static void main() {
5 | int i;
6 | i = i ^ -1; // error!
7 | }
8 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/error2.decaf:
--------------------------------------------------------------------------------
1 | // This Program should trigger an "Integer Too Large Error"
2 |
3 | class Main {
4 | static void main() {
5 | int i;
6 |
7 | i = 73295739294; // error!
8 | i = 3141592653; // error too!
9 | }
10 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/error3.decaf:
--------------------------------------------------------------------------------
1 | // This Program should trigger a "Syntax Error"
2 |
3 | class Main {
4 | static void main() {
5 | int i = 0; // error! we don't support this grammar
6 |
7 | i = i + 1;
8 | }
9 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/error4.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | string str;
4 | str = "string
5 | ";
6 | }
7 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/error5.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | string s;
4 | s = "str
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/guarded-error-1.decaf:
--------------------------------------------------------------------------------
1 | // Unterminated `}` for `if`.
2 |
3 | class Main {
4 | static void main() {
5 | if { true: if { false: if { } }
6 | while (false) {}
7 | }
8 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/guarded-error-2.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | void foo(int i) {
3 | return i + 1;
4 | }
5 |
6 | static void main() {
7 | int x;
8 | // Missing `:` in guard
9 | if { x == 1 : foo(1); ||| x == 2 foo(2); }
10 | }
11 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/guarded-error-3.decaf:
--------------------------------------------------------------------------------
1 | // Extra `|||` for `if`.
2 |
3 | class Main {
4 | void foo(int i) {
5 | return i + 1;
6 | }
7 |
8 | static void main() {
9 | int x;
10 | if { x == 1: foo(1); ||| x == 2: foo(2); ||| }
11 | }
12 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/guarded-error-4.decaf:
--------------------------------------------------------------------------------
1 | // syntax error: missing ';' for statement `a=a+1`
2 | class Main {
3 | static void main(){
4 | int a;
5 | a = ReadInteger();
6 | if{true:a=a+1}
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/guarded-errors.decaf:
--------------------------------------------------------------------------------
1 | // Missing `:` in guards.
2 | // Extra `|||` for `if`.
3 |
4 | class Main {
5 | void foo(int i) {
6 | return i + 1;
7 | }
8 |
9 | static void main() {
10 | int x;
11 | if { x == 1 foo(1); ||| x == 2 foo(2); ||| } ;
12 | }
13 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/multi-errors-1.decaf:
--------------------------------------------------------------------------------
1 | public class Main { // error 1: program should start with 'class', not identifier 'public'
2 | static void main() {
3 | int x = 1; // error 2: this grammar is not supported
4 | int y;
5 | y = 1;
6 | int z[]; // error 3: this grammar is not supported, 'int[] z' expected
7 | z[] = 2; // error 4: missing index for '[]'
8 | }
9 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/multi-errors-2.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int x;
4 | int y;
5 | string z: ; // error1: extra ':'
6 | bool c;
7 | c = false;
8 | if c Print("OK\n"); // error2: missing '(' and ')' for 'c'
9 | if (x == 1) {
10 | if (y == 2) {
11 | // do nothing
12 | else Print("OK\n"); // error 3: missing '}'
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/multi-errors-3.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | /* This kind of comment is not supported! */
3 |
4 | static void main() {
5 | super.Init();
6 | string str;
7 | str = "not terminate
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/multi-errors-4.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | Print("hello\n") // error 1: missing ';'
4 | int x // error 2: missing ';'
5 | bool y;;;;;
6 | return 0 // error 3: missing ';'
7 | }
8 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/multi-errors-5.decaf:
--------------------------------------------------------------------------------
1 | class Base {}
2 |
3 | class A : Base {} // error 1: 'extends' expected but ':' found
4 |
5 | class B extends {} // error 2: missing base class name
6 |
7 | class C extends Base {}
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/multi-errors-6.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int x;
4 | x = 1 * (1 + 2 * (3 + 4 - x); // error 1: first '(' is not balanced
5 | int y;
6 | y = x ^ 2; // error 2: unrecognized char '^'
7 | Obj o; // error 3: missing 'class'
8 | o = new Obj();
9 | return 0;
10 | }
11 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/multi-errors-7.decaf:
--------------------------------------------------------------------------------
1 | // error 2: missing '}' at the end
2 |
3 | class Main {
4 | static void main() {
5 | int x;
6 | x = 2 // error 1: missing ';'
7 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/multi-errors-8.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int x,y; // error 1: this grammar is not supported
4 | x = 0xf;
5 | y = 0xff;
6 | ;
7 | PrintComp(z,); // error 2: missing parameter after ','
8 | return 0;
9 | }
10 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/multi-errors-9.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | int x;
3 |
4 | static void main() {
5 | int i;
6 | int N;
7 | for (i = 0;) { // error 1: incomplete for-expr
8 | Print("main()\n");
9 | if (i == N) break // error 2: missing ';'
10 | }
11 | }; // error 3: extra ';'
12 |
13 | static void set(int v) {
14 | x = v;
15 | }
16 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa1b/TestCases/S1-/output/.DS_Store
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/array-errors.result:
--------------------------------------------------------------------------------
1 | *** Error at (4,33): syntax error
2 | *** Error at (5,42): syntax error
3 | *** Error at (6,36): syntax error
4 | *** Error at (9,24): syntax error
5 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/error1.result:
--------------------------------------------------------------------------------
1 | *** Error at (6,15): unrecognized character '^'
2 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/error2.result:
--------------------------------------------------------------------------------
1 | *** Error at (7,13): integer literal 73295739294 is too large
2 | *** Error at (8,13): integer literal 3141592653 is too large
3 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/error3.result:
--------------------------------------------------------------------------------
1 | *** Error at (5,15): syntax error
2 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/error4.result:
--------------------------------------------------------------------------------
1 | *** Error at (4,15): illegal newline in string constant "string"
2 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/error5.result:
--------------------------------------------------------------------------------
1 | *** Error at (4,13): unterminated string constant "str"
2 | *** Error at (4,17): syntax error
3 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/guarded-error-1.result:
--------------------------------------------------------------------------------
1 | *** Error at (6,9): syntax error
2 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/guarded-error-2.result:
--------------------------------------------------------------------------------
1 | *** Error at (9,42): syntax error
2 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/guarded-error-3.result:
--------------------------------------------------------------------------------
1 | *** Error at (10,54): syntax error
2 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/guarded-error-4.result:
--------------------------------------------------------------------------------
1 | *** Error at (6,22): syntax error
2 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/guarded-errors.result:
--------------------------------------------------------------------------------
1 | *** Error at (11,21): syntax error
2 | *** Error at (11,40): syntax error
3 | *** Error at (11,52): syntax error
4 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/multi-errors-1.result:
--------------------------------------------------------------------------------
1 | *** Error at (1,1): syntax error
2 | *** Error at (3,15): syntax error
3 | *** Error at (6,14): syntax error
4 | *** Error at (7,11): syntax error
5 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/multi-errors-2.result:
--------------------------------------------------------------------------------
1 | *** Error at (5,17): syntax error
2 | *** Error at (8,12): syntax error
3 | *** Error at (8,14): syntax error
4 | *** Error at (12,13): syntax error
5 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/multi-errors-3.result:
--------------------------------------------------------------------------------
1 | *** Error at (2,5): syntax error
2 | *** Error at (7,15): unterminated string constant "not terminate"
3 | *** Error at (7,29): syntax error
4 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/multi-errors-4.result:
--------------------------------------------------------------------------------
1 | *** Error at (4,9): syntax error
2 | *** Error at (5,9): syntax error
3 | *** Error at (7,5): syntax error
4 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/multi-errors-5.result:
--------------------------------------------------------------------------------
1 | *** Error at (3,9): syntax error
2 | *** Error at (5,17): syntax error
3 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/multi-errors-6.result:
--------------------------------------------------------------------------------
1 | *** Error at (4,37): syntax error
2 | *** Error at (6,15): unrecognized character '^'
3 | *** Error at (6,17): syntax error
4 | *** Error at (7,13): syntax error
5 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/multi-errors-7.result:
--------------------------------------------------------------------------------
1 | *** Error at (7,5): syntax error
2 | *** Error at (7,6): syntax error
3 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/multi-errors-8.result:
--------------------------------------------------------------------------------
1 | *** Error at (3,14): syntax error
2 | *** Error at (7,21): syntax error
3 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1-/output/multi-errors-9.result:
--------------------------------------------------------------------------------
1 | *** Error at (7,20): syntax error
2 | *** Error at (10,9): syntax error
3 | *** Error at (11,6): syntax error
4 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/array-comp.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int[] xs;
4 | xs = new int[10];
5 |
6 | int[] plus1;
7 | plus1 = [x+1 for x in xs];
8 |
9 | bool[] is_positive;
10 | is_positive = [x > 0 for x in xs];
11 |
12 | int[] positive;
13 | positive = [x for x in xs if x > 0];
14 |
15 | int y;
16 | y = 3;
17 | int[] times_y_ge_5;
18 | times_y = [x*y for x in xs if x >= 5];
19 | }
20 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/array-concat.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static int[] empty() {
3 | int[] nil;
4 | nil = new int[0];
5 | return nil;
6 | }
7 |
8 | static void main() {
9 | int[] ws;
10 | int[] xs;
11 | bool[] ys;
12 | string[] zs;
13 |
14 | int[] arr;
15 | arr = ws ++ xs;
16 | int[] err;
17 | err = ws ++ xs ++ ys;
18 | int[] arr1;
19 | arr1 = ws ++ xs ++ empty();
20 | }
21 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/array-const-err.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int[] xs;
4 | xs = [1,0,-1]; // -1 is an expression, not a constant!
5 | }
6 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/array-const.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int[] xs;
4 | xs = [1,2,3];
5 | bool[] ys;
6 | ys = [true,false,"false"];
7 | string[] zs;
8 | zs = ["one"];
9 | int[] nil;
10 | nil = [];
11 |
12 | int[] manyOnes;
13 | manyOnes = 1 %% 10;
14 | string[][] manyzs;
15 | manyzs = zs %% 5 * 6;
16 | }
17 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/error1.decaf:
--------------------------------------------------------------------------------
1 | // This Program should trigger an "Unrecognized Character Error"
2 |
3 | class Main {
4 | static void main() {
5 | int i;
6 | i = i ^ -1; // error!
7 | }
8 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/error2.decaf:
--------------------------------------------------------------------------------
1 | // This Program should trigger an "Integer Too Large Error"
2 |
3 | class Main {
4 | static void main() {
5 | int i;
6 |
7 | i = 73295739294; // error!
8 | i = 3141592653; // error too!
9 | }
10 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/error3.decaf:
--------------------------------------------------------------------------------
1 | // This Program should trigger a "Syntax Error"
2 |
3 | class Main {
4 | static void main() {
5 | int i = 0; // error! we don't support this grammar
6 |
7 | i = i + 1;
8 | }
9 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/error4.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | string str;
4 | str = "string
5 | ";
6 | }
7 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/error5.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | string s;
4 | s = "str
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/guarded-1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | int foo(int x, int y, int z) {
3 | string s;
4 | if { x + y == z: return 2 * z;
5 | ||| x < 0 || y < 0 && z < 0: s = "negative";
6 | ||| x + y != y + x: s = "impossible";
7 | }
8 | return s;
9 | }
10 |
11 | static int main() {
12 | return foo(1,2,3);
13 | }
14 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/guarded-2.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | void foo() {
3 | if { true: if { false: Print("unreachable"); } }
4 | }
5 |
6 | void bar() {
7 | int x;
8 | x = ReadInteger();
9 | if { true: if (x > 0) if { x == 1: Print("x=1"); ||| x == 2: Print("x=2"); }
10 | else if {} }
11 | }
12 |
13 | static void main() {
14 | if {}
15 | foo();
16 | bar();
17 | }
18 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/guarded-error-1.decaf:
--------------------------------------------------------------------------------
1 | // Unterminated `}` for `if`.
2 |
3 | class Main {
4 | static void main() {
5 | if { true: if { false: if { } }
6 | while (false) {}
7 | }
8 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/guarded-error-2.decaf:
--------------------------------------------------------------------------------
1 | // Missing `|||` for `if`.
2 |
3 | class Main {
4 | void foo(int i) {
5 | return i + 1;
6 | }
7 |
8 | static void main() {
9 | int x;
10 | if { x == 1: foo(1); x == 2: foo(2); }
11 | }
12 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/guarded-error-3.decaf:
--------------------------------------------------------------------------------
1 | // Extra `|||` for `if`.
2 |
3 | class Main {
4 | void foo(int i) {
5 | return i + 1;
6 | }
7 |
8 | static void main() {
9 | int x;
10 | if { x == 1: foo(1); ||| x == 2: foo(2); ||| }
11 | }
12 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/output/array-const-err.result:
--------------------------------------------------------------------------------
1 | *** Error at (4,19): syntax error
2 | *** Error at (4,21): syntax error
3 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/output/error1.result:
--------------------------------------------------------------------------------
1 | *** Error at (6,15): unrecognized character '^'
2 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/output/error2.result:
--------------------------------------------------------------------------------
1 | *** Error at (7,13): integer literal 73295739294 is too large
2 | *** Error at (8,13): integer literal 3141592653 is too large
3 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/output/error3.result:
--------------------------------------------------------------------------------
1 | *** Error at (5,15): syntax error
2 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/output/error4.result:
--------------------------------------------------------------------------------
1 | *** Error at (4,15): illegal newline in string constant "string"
2 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/output/error5.result:
--------------------------------------------------------------------------------
1 | *** Error at (4,13): unterminated string constant "str"
2 | *** Error at (4,17): syntax error
3 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/output/guarded-error-1.result:
--------------------------------------------------------------------------------
1 | *** Error at (6,9): syntax error
2 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/output/guarded-error-2.result:
--------------------------------------------------------------------------------
1 | *** Error at (10,30): syntax error
2 | *** Error at (10,36): syntax error
3 | *** Error at (10,38): syntax error
4 | *** Error at (12,1): syntax error
5 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/output/guarded-error-3.result:
--------------------------------------------------------------------------------
1 | *** Error at (10,54): syntax error
2 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/output/sealed.result:
--------------------------------------------------------------------------------
1 | program
2 | sealed class A
3 | sealed class A1 A
4 | class B
5 | class C B
6 | sealed class D B
7 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/output/test5.result:
--------------------------------------------------------------------------------
1 | program
2 | class Main
3 | static func main voidtype
4 | formals
5 | stmtblock
6 | vardef s stringtype
7 | assign
8 | varref s
9 | stringconst "\\\"\n"
10 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/output/var-1.result:
--------------------------------------------------------------------------------
1 | program
2 | class Main
3 | static func main voidtype
4 | formals
5 | stmtblock
6 | assign
7 | var x
8 | intconst 1
9 | assign
10 | var y
11 | boolconst true
12 | assign
13 | var z
14 | stringconst "hello"
15 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/sealed.decaf:
--------------------------------------------------------------------------------
1 | sealed class A {}
2 |
3 | sealed class A1 extends A {}
4 |
5 | class B {}
6 |
7 | class C extends B {}
8 |
9 | sealed class D extends B {}
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/test1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | bool field;
3 |
4 | class Main another;
5 |
6 | int[] foo(int y) {
7 | int[] q;
8 | int i;
9 |
10 | q = new int[y];
11 | i = 0;
12 | while (i < y) {
13 | q[i] = i;
14 | i = i + 1;
15 | }
16 |
17 | return q;
18 | }
19 |
20 | static int main() {
21 | return this.foo(5).length();
22 | }
23 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/test3.decaf:
--------------------------------------------------------------------------------
1 | class MultipleFormals {
2 |
3 | int foo(int x, int y, int z) {
4 | return (x + y + z)/3;
5 | }
6 |
7 | int method() {
8 | int x;
9 | int y;
10 | int z;
11 |
12 | x = 3;
13 | y = x + x * x;
14 | z = (x - y / x) % y;
15 |
16 | return foo(x, y, z);
17 | }
18 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/test4.decaf:
--------------------------------------------------------------------------------
1 | class Father {
2 | int field;
3 |
4 | void method(int f) {
5 | if (f > 0 && f < 10) {
6 | f = f - 3;
7 | return method(f);
8 | }
9 | }
10 | }
11 |
12 | class Child extends Father {
13 | void start() {
14 | class Father p;
15 |
16 | p = this;
17 | p.field = 5;
18 | p = null;
19 |
20 | Print(this.field);
21 | }
22 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/test5.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | string s;
4 | s = "\\\"\n";
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/var-1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | var x = 1;
4 | var y = true;
5 | var z = "hello";
6 | }
7 | }
--------------------------------------------------------------------------------
/pa1b/TestCases/S1/var-2.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static int foo() {
3 | var cnt = 1;
4 | for (var i = 0; i < 100; i = i + 2) {
5 | cnt = cnt * i;
6 | }
7 |
8 | return cnt;
9 | }
10 |
11 | static void main() {
12 | var k = foo();
13 | Print(k);
14 | }
15 | }
--------------------------------------------------------------------------------
/pa1b/report.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa1b/report.pdf
--------------------------------------------------------------------------------
/pa1b/src/decaf/error/BadArrElementError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:array base type must be non-void type
7 | * PA2
8 | */
9 | public class BadArrElementError extends DecafError {
10 |
11 | public BadArrElementError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "array element type must be non-void type";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa1b/src/decaf/error/BadInheritanceError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:illegal class inheritance (should be a cyclic)
7 | * PA2
8 | */
9 | public class BadInheritanceError extends DecafError {
10 |
11 | public BadInheritanceError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "illegal class inheritance (should be a cyclic)";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa1b/src/decaf/error/BadLengthError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:'length' can only be applied to arrays
7 | * PA2
8 | */
9 | public class BadLengthError extends DecafError {
10 |
11 | public BadLengthError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "'length' can only be applied to arrays";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa1b/src/decaf/error/BadNewArrayLength.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:new array length must be an integer
7 | * PA2
8 | */
9 | public class BadNewArrayLength extends DecafError {
10 |
11 | public BadNewArrayLength(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "new array length must be an integer";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa1b/src/decaf/error/BadTestExpr.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:test expression must have bool type
7 | * PA2
8 | */
9 | public class BadTestExpr extends DecafError {
10 |
11 | public BadTestExpr(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "test expression must have bool type";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa1b/src/decaf/error/BreakOutOfLoopError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:'break' is only allowed inside a loop
7 | * PA2
8 | */
9 | public class BreakOutOfLoopError extends DecafError {
10 |
11 | public BreakOutOfLoopError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "'break' is only allowed inside a loop";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa1b/src/decaf/error/ClassNotFoundError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:class 'zig' not found
7 | * PA2
8 | */
9 | public class ClassNotFoundError extends DecafError {
10 |
11 | private String name;
12 |
13 | public ClassNotFoundError(Location location, String name) {
14 | super(location);
15 | this.name = name;
16 | }
17 |
18 | @Override
19 | protected String getErrMsg() {
20 | return "class '" + name + "' not found";
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/pa1b/src/decaf/error/MsgError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * 仅供Parser的yyerror函数使用
7 | */
8 | public class MsgError extends DecafError {
9 |
10 | private String msg;
11 |
12 | public MsgError(Location location, String msg) {
13 | super(location);
14 | this.msg = msg;
15 | }
16 |
17 | @Override
18 | protected String getErrMsg() {
19 | return msg;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/pa1b/src/decaf/error/NotArrayError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:[] can only be applied to arrays
7 | * PA2
8 | */
9 | public class NotArrayError extends DecafError {
10 |
11 | public NotArrayError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "[] can only be applied to arrays";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa1b/src/decaf/error/NotClassError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * string is not a class type.
7 | */
8 | public class NotClassError extends DecafError {
9 |
10 | private String type;
11 |
12 | public NotClassError(String type, Location location) {
13 | super(location);
14 | this.type = type;
15 | }
16 |
17 | @Override
18 | protected String getErrMsg() {
19 | return type + " is not a class type";
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/pa1b/src/decaf/error/SubNotIntError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:array subscript must be an integer
7 | * PA2
8 | */
9 | public class SubNotIntError extends DecafError {
10 |
11 | public SubNotIntError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "array subscript must be an integer";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa1b/src/decaf/error/ThisInStaticFuncError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * can not use this in static function
7 | * PA2
8 | */
9 | public class ThisInStaticFuncError extends DecafError {
10 |
11 | public ThisInStaticFuncError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "can not use this in static function";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa1b/src/decaf/error/UndeclVarError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:undeclared variable 'python'
7 | * PA2
8 | */
9 | public class UndeclVarError extends DecafError {
10 |
11 | private String name;
12 |
13 | public UndeclVarError(Location location, String name) {
14 | super(location);
15 | this.name = name;
16 | }
17 |
18 | @Override
19 | protected String getErrMsg() {
20 | return "undeclared variable '" + name + "'";
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/pa1b/src/decaf/error/UnrecogCharError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:unrecognized char: '@'
7 | * PA1
8 | */
9 | public class UnrecogCharError extends DecafError {
10 |
11 | private char c;
12 |
13 | public UnrecogCharError(Location location, char c) {
14 | super(location);
15 | this.c = c;
16 | }
17 |
18 | @Override
19 | protected String getErrMsg() {
20 | return "unrecognized character '" + c + "'";
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/pa1b/src/decaf/error/UntermCommentError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example: unterminated multi comment
7 | * PA1
8 | *
9 | * @author paul
10 | */
11 |
12 | public class UntermCommentError extends DecafError {
13 | public UntermCommentError(Location location) {
14 | super(location);
15 |
16 | }
17 |
18 | @Override
19 | protected String getErrMsg() {
20 | return "unterminated multi comment";
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/pa1b/tools/pg.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa1b/tools/pg.jar
--------------------------------------------------------------------------------
/pa2/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/pa2/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | pa2
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/pa2/Decaf PA2 README.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa2/Decaf PA2 README.pdf
--------------------------------------------------------------------------------
/pa2/TestCases/S2/arrayerror.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | int[] a;
3 | static void main() {
4 |
5 | }
6 |
7 | void func() {
8 | a = new int[-1]; // valid
9 | a = new int["123"];
10 | int a;
11 | a.length();
12 | a[1] = 2;
13 | this.a.length(0);
14 | a = this.a[false];
15 | }
16 | }
--------------------------------------------------------------------------------
/pa2/TestCases/S2/d:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa2/TestCases/S2/d
--------------------------------------------------------------------------------
/pa2/TestCases/S2/miscerror.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | Print(new Main(), 1);
4 | if (true)
5 | break;
6 | Print(instanceof(1, Main));
7 | class Main m;
8 | m = (class Main)true;
9 | return 1;
10 | }
11 | }
--------------------------------------------------------------------------------
/pa2/TestCases/S2/nomainerror.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static int main() {
3 | }
4 | }
5 |
6 | class Main1 {
7 | static void main(int i) {
8 | }
9 | }
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/arrayerror.result:
--------------------------------------------------------------------------------
1 | *** Error at (9,21): new array length must be an integer
2 | *** Error at (11,11): 'length' can only be applied to arrays
3 | *** Error at (12,9): [] can only be applied to arrays
4 | *** Error at (13,16): function 'length' expects 0 argument(s) but 1 given
5 | *** Error at (14,13): array subscript must be an integer
6 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/exprerror.result:
--------------------------------------------------------------------------------
1 | *** Error at (8,15): syntax error
2 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/miscerror.result:
--------------------------------------------------------------------------------
1 | *** Error at (3,15): incompatible argument 1: class : Main given, int/bool/string expected
2 | *** Error at (5,13): 'break' is only allowed inside a loop
3 | *** Error at (6,15): int is not a class type
4 | *** Error at (8,25): bool is not a class type
5 | *** Error at (9,9): incompatible return: int given, void expected
6 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/nomainerror.result:
--------------------------------------------------------------------------------
1 | *** Error: no legal Main class named 'Main' was found
2 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/overrideerror.result:
--------------------------------------------------------------------------------
1 | *** Error at (21,10): overriding method 'func' doesn't match the type signature in class 'A'
2 | *** Error at (24,13): overriding method 'func1' doesn't match the type signature in class 'A'
3 | *** Error at (27,13): overriding method 'func2' doesn't match the type signature in class 'A'
4 | *** Error at (37,1): illegal class inheritance (should be a cyclic)
5 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q1-1.result:
--------------------------------------------------------------------------------
1 | *** Error at (18,3): undeclared variable 'x'
2 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q1-2.result:
--------------------------------------------------------------------------------
1 | *** Error at (18,3): incompatible argument dst: class : Main->int->int given, class expected
2 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q1-3.result:
--------------------------------------------------------------------------------
1 | *** Error at (19,3): incompatible dst type: class : Father and src type: int
2 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q1-4.result:
--------------------------------------------------------------------------------
1 | *** Error at (19,3): incompatible argument dst: class : Main->int->int given, class expected
2 | *** Error at (19,3): incompatible argument src: int given, class expected
3 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q2-sealed-test1.result:
--------------------------------------------------------------------------------
1 | *** Error at (13,1): illegal class inheritance from sealed class
2 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q3-1.result:
--------------------------------------------------------------------------------
1 | *** Error at (8,5): test expression must have bool type
2 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q3-guarded-test1.result:
--------------------------------------------------------------------------------
1 | GLOBAL SCOPE:
2 | (1,1) -> class Main
3 | CLASS SCOPE OF 'Main':
4 | (2,15) -> static function main : void
5 | FORMAL SCOPE OF 'main':
6 | LOCAL SCOPE:
7 | (3,6) -> variable a : int
8 | (5,7) -> variable b : int
9 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q4-1.result:
--------------------------------------------------------------------------------
1 | *** Error at (11,19): incompatible operands: unknown + int
2 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q4-2.result:
--------------------------------------------------------------------------------
1 | *** Error at (11,11): declaration of 'k' here conflicts with earlier declaration at (10,8)
2 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q4-3.result:
--------------------------------------------------------------------------------
1 | *** Error at (12,11): declaration of 'k' here conflicts with earlier declaration at (10,11)
2 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q4-4.result:
--------------------------------------------------------------------------------
1 | *** Error at (12,18): incompatible operands: unknown + int
2 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q4-5.result:
--------------------------------------------------------------------------------
1 | *** Error at (6,11): declaration of 'k' here conflicts with earlier declaration at (3,24)
2 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q4-6.result:
--------------------------------------------------------------------------------
1 | *** Error at (5,6): incompatible operands: int = unknown
2 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q5-array-test1.result:
--------------------------------------------------------------------------------
1 | GLOBAL SCOPE:
2 | (1,1) -> class Main
3 | CLASS SCOPE OF 'Main':
4 | (2,17) -> static function main : void
5 | FORMAL SCOPE OF 'main':
6 | LOCAL SCOPE:
7 | (3,13) -> variable a : int[]
8 | (5,14) -> variable b : bool[]
9 | (7,16) -> variable c : string[]
10 | (10,15) -> variable d : int[][]
11 | (13,18) -> variable e : string[][]
12 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q5-array-test2.result:
--------------------------------------------------------------------------------
1 | GLOBAL SCOPE:
2 | (1,1) -> class Main
3 | CLASS SCOPE OF 'Main':
4 | (2,17) -> static function main : void
5 | FORMAL SCOPE OF 'main':
6 | LOCAL SCOPE:
7 | (3,12) -> variable a : int[]
8 | (6,7) -> variable b : int
9 | (9,7) -> variable c : int
10 | (12,7) -> variable d : int
11 | (15,7) -> variable e : int
12 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q51-1.result:
--------------------------------------------------------------------------------
1 | *** Error at (16,16): array element type must be non-void known type
2 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q52-1.result:
--------------------------------------------------------------------------------
1 | *** Error at (15,4): incompatible operands: int = int[]
2 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q52-2.result:
--------------------------------------------------------------------------------
1 | *** Error at (15,4): incompatible operands: string = int[]
2 | *** Error at (16,4): incompatible operands: string = int
3 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q52-3.result:
--------------------------------------------------------------------------------
1 | *** Error at (16,4): incompatible operands: string = int[]
2 | *** Error at (16,8): array index must be int type
3 | *** Error at (17,6): Array Operation on non-array type
4 | *** Error at (18,4): incompatible operands: string = int
5 | *** Error at (18,8): Array has Element type int but default has type unknown
6 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q53-1.result:
--------------------------------------------------------------------------------
1 | *** Error at (16,37): test expression must have bool type
2 | *** Error at (21,29): Array Operation on non-array type
3 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q53-2.result:
--------------------------------------------------------------------------------
1 | *** Error at (17,8): declaration of 'i' here conflicts with earlier declaration at (16,11)
2 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/q53-3.result:
--------------------------------------------------------------------------------
1 | *** Error at (24,10): 'b' is not a method in class 'class : Child'
2 | *** Error at (26,20): Array Operation on non-array type
3 | *** Error at (30,20): undeclared variable 'u'
4 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/referror.result:
--------------------------------------------------------------------------------
1 | *** Error at (5,9): can not reference a non-static field 'a' from static method 'main'
2 | *** Error at (6,9): can not use this in static function
3 | *** Error at (7,14): cannot access field 'a' from 'class : Main'
4 | *** Error at (8,9): can not reference a non-static field 'func' from static method 'main'
5 | *** Error at (12,20): field 'b' of 'class : Test' not accessible here
6 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/t1.result:
--------------------------------------------------------------------------------
1 | GLOBAL SCOPE:
2 | (1,1) -> class Main
3 | CLASS SCOPE OF 'Main':
4 | (2,17) -> static function main : void
5 | FORMAL SCOPE OF 'main':
6 | LOCAL SCOPE:
7 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/t2.result:
--------------------------------------------------------------------------------
1 | GLOBAL SCOPE:
2 | (2,1) -> class Main
3 | CLASS SCOPE OF 'Main':
4 | (3,17) -> static function main : void
5 | FORMAL SCOPE OF 'main':
6 | LOCAL SCOPE:
7 | (4,13) -> variable a : int
8 | (5,16) -> variable b : string
9 | (6,14) -> variable c : bool
10 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/t9.result:
--------------------------------------------------------------------------------
1 | GLOBAL SCOPE:
2 | (1,1) -> class Main
3 | (7,1) -> class A : Main
4 | CLASS SCOPE OF 'Main':
5 | (2,9) -> variable a : int
6 | (3,17) -> static function main : void
7 | FORMAL SCOPE OF 'main':
8 | LOCAL SCOPE:
9 | CLASS SCOPE OF 'A':
10 | (8,10) -> function func : class : A->void
11 | FORMAL SCOPE OF 'func':
12 | (8,10) -> variable @this : class : A
13 | LOCAL SCOPE:
14 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/z0.result:
--------------------------------------------------------------------------------
1 | *** Error at (4,10): incompatible operands: string = int
2 | *** Error at (8,5): incompatible operands: int = string
3 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/z2.result:
--------------------------------------------------------------------------------
1 | *** Error at (3,8): field 'a' not found in 'class : Main'
2 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/z4.result:
--------------------------------------------------------------------------------
1 | *** Error at (22,13): can not use this in static function
2 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/output/z5.result:
--------------------------------------------------------------------------------
1 | *** Error at (7,9): can not reference a non-static field 'i' from static method 'main'
2 | *** Error at (9,24): can not reference a non-static field 'i' from static method 'main'
3 | *** Error at (13,24): can not reference a non-static field 'i' from static method 'main'
4 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q1-1.decaf:
--------------------------------------------------------------------------------
1 | class Father {
2 | int field;
3 |
4 | int method(int f) {
5 | if (f > 0 && f < 10) {
6 | f = f - 3;
7 | return method(f);
8 | }
9 | return f;
10 | }
11 | }
12 |
13 | class Main {
14 | static void main() {
15 | class Father a;
16 | class Father b;
17 | b = new Father();
18 | scopy(x,b);
19 | }
20 | int fun(int b ) {
21 | return b;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q1-2.decaf:
--------------------------------------------------------------------------------
1 | class Father {
2 | int field;
3 |
4 | int method(int f) {
5 | if (f > 0 && f < 10) {
6 | f = f - 3;
7 | return method(f);
8 | }
9 | return f;
10 | }
11 | }
12 |
13 | class Main {
14 | static void main() {
15 | class Father a;
16 | class Father b;
17 | b = new Father();
18 | scopy(fun,b);
19 | }
20 | int fun(int b ) {
21 | return b;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q1-3.decaf:
--------------------------------------------------------------------------------
1 | class Father {
2 | int field;
3 |
4 | int method(int f) {
5 | if (f > 0 && f < 10) {
6 | f = f - 3;
7 | return method(f);
8 | }
9 | return f;
10 | }
11 | }
12 |
13 | class Main {
14 | static void main() {
15 | class Father a;
16 | class Father b;
17 | int c;
18 | b = new Father();
19 | scopy(b,c);
20 | }
21 | int fun(int b ) {
22 | return b;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q1-4.decaf:
--------------------------------------------------------------------------------
1 | class Father {
2 | int field;
3 |
4 | int method(int f) {
5 | if (f > 0 && f < 10) {
6 | f = f - 3;
7 | return method(f);
8 | }
9 | return f;
10 | }
11 | }
12 |
13 | class Main {
14 | static void main() {
15 | class Father a;
16 | class Father b;
17 | b = new Father();
18 | int c;
19 | scopy(fun,c);
20 | }
21 | int fun(int b) {
22 | return b;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q1-scopy-test1.decaf:
--------------------------------------------------------------------------------
1 | class Father {
2 | int field;
3 |
4 | int method(int f) {
5 | if (f > 0 && f < 10) {
6 | f = f - 3;
7 | return method(f);
8 | }
9 | return f;
10 | }
11 | }
12 |
13 | class Main {
14 | static void main() {
15 | class Father a;
16 | class Father b;
17 | b = new Father();
18 | scopy(a,b);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q3-1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int a;
4 | a = ReadInteger();
5 | int b;
6 | if {a>100 : b=a-100;|||
7 | a<50 : b=a+50;|||
8 | b: {b=a+200;Print(a);}
9 | };
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q3-guarded-test1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int a;
4 | a = ReadInteger();
5 | int b;
6 | if {a>100 : b=a-100;|||
7 | a<50 : b=a+50;|||
8 | a<0: {b=a+200;Print(a);}
9 | };
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q4-1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static int foo() {
3 | int a;
4 | a=100;
5 | return a;
6 | }
7 |
8 | static void main() {
9 | int b;
10 | var k = foo();
11 | var c = var a + b;
12 | Print(k);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q4-2.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static int foo() {
3 | int a;
4 | a=100;
5 | return a;
6 | }
7 |
8 | static void main() {
9 | int b;
10 | int k;
11 | var k = foo();
12 | var c = var a + b;
13 | Print(k);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q4-3.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static int foo() {
3 | int a;
4 | a=100;
5 | return a;
6 | }
7 |
8 | static void main() {
9 | int b;
10 | var k = foo();
11 | var c = var a + b;
12 | int k;
13 | Print(k);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q4-4.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | int k;
3 | static int foo() {
4 | int a;
5 | a=100;
6 | return a;
7 | }
8 |
9 | static void main() {
10 | int b;
11 | var k = foo();
12 | var c = var a + b;
13 | Print(k);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q4-5.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | int k;
3 | static int foo(int k) {
4 | int a;
5 | a=100;
6 | var k = foo();
7 | var c = var a + b;
8 | Print(k);
9 | return a;
10 | }
11 |
12 | static void main() {
13 | int b;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q4-6.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static int foo() {
3 | int a;
4 | a=100;
5 | a = var x;
6 | int b;
7 | var k = foo();
8 | Print(k);
9 | return a;
10 | }
11 |
12 | static void main() {
13 | int b;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q4-var-test1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static int foo() {
3 | int a;
4 | a=100;
5 | return a;
6 | }
7 |
8 | static void main() {
9 | int b;
10 | var k = foo();
11 | var c = k + b;
12 | Print(c);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q5-array-test1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int [] a;
4 | a = 3 %% 2*3;
5 | bool [] b;
6 | b = true %% 10;
7 | string [] c;
8 | c = "hello" %% 3;
9 |
10 | int [][] d;
11 | d = a %% (2+3);
12 |
13 | string [][] e;
14 | e = c %% 10;
15 | }
16 | }
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q5-array-test2.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int[] a;
4 | a = [1,2,3] ++ 3 %% 2;
5 |
6 | int b;
7 | b = a[3];
8 |
9 | int c;
10 | c = a[b];
11 |
12 | int d;
13 | d= a[2] default 2 + 3 ;
14 |
15 | int e;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q5-array-test3.decaf:
--------------------------------------------------------------------------------
1 | class Father {
2 | int d;
3 | int foo(){
4 | return d;
5 | }
6 | }
7 | class Child extends Father{
8 | int b;
9 | }
10 | class Main {
11 | static void main() {
12 |
13 | class Child[] a;
14 | int c;
15 |
16 | foreach(class Father i in a while c>2){
17 | int x ;
18 | x = i.foo();
19 | }
20 |
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q51-1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int [] a;
4 | a = 3 %% 2*3;
5 | bool [] b;
6 | b = true %% 10;
7 | string [] c;
8 | c = "hello" %% 3;
9 |
10 | int [][] d;
11 | d = a %% (2+3);
12 |
13 | string [][] e;
14 | e = c %% 10;
15 |
16 | e = var d %% 10;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q52-1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int[] a;
4 |
5 | int b;
6 | b = a[3];
7 |
8 | int c;
9 | c = a[b];
10 |
11 | int d;
12 | d= a[2] default 2 + 3 ;
13 |
14 | int e;
15 | e= a[2] default 2%%3;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q52-2.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int[] a;
4 |
5 | int b;
6 | b = a[3];
7 |
8 | int c;
9 | c = a[b];
10 |
11 | int d;
12 | d= a[2] default 2 + 3 ;
13 |
14 | string e;
15 | e= a[2] default 2%%3;
16 | e= a[2] default 1;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q52-3.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int[] a;
4 |
5 | int b;
6 | b = a[3];
7 |
8 | int c;
9 | c = a[b];
10 |
11 | int d;
12 | d= a[2] default 2 + 3 ;
13 | bool z;
14 |
15 | string e;
16 | e= a[z] default 2%%3;
17 | e= e[2] default var x;
18 | e= a[2] default var x;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q53-1.decaf:
--------------------------------------------------------------------------------
1 | class Father {
2 | int d;
3 | int foo(){
4 | return d;
5 | }
6 | }
7 | class Child extends Father{
8 | int b;
9 | }
10 | class Main {
11 | static void main() {
12 |
13 | class Child[] a;
14 | int c;
15 |
16 | foreach(class Father i in a while c){
17 | int x ;
18 | x = i.foo();
19 | }
20 |
21 | foreach(class Father i in c while c>2){
22 | int x ;
23 | x = i.foo();
24 | }
25 |
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/q53-2.decaf:
--------------------------------------------------------------------------------
1 | class Father {
2 | int d;
3 | int foo(){
4 | return d;
5 | }
6 | }
7 | class Child extends Father{
8 | int b;
9 | }
10 | class Main {
11 | static void main() {
12 |
13 | class Child[] a;
14 | int c;
15 |
16 | foreach(class Father i in a while c){
17 | int i ;
18 | x = i.foo();
19 | }
20 |
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/referror.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | int a;
3 |
4 | static void main() {
5 | a = 1;
6 | this.a = 1;
7 | Main.a = 1;
8 | func();
9 | }
10 |
11 | void func() {
12 | new Test().b = 1;
13 | }
14 | }
15 |
16 | class Test extends Main {
17 | int b;
18 | }
--------------------------------------------------------------------------------
/pa2/TestCases/S2/t1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | Print("hello world");
4 | }
5 | }
6 |
7 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/t2.decaf:
--------------------------------------------------------------------------------
1 |
2 | class Main {
3 | static void main() {
4 | int a;
5 | string b;
6 | bool c;
7 |
8 | c = true;
9 | b = "wow!";
10 | a = 3;
11 | if (c)
12 | a = a * 5;
13 | Print(c, " ", a);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/t3.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int c;
4 | string s;
5 |
6 | s = "hello";
7 | c = test(4, 5);
8 | Print(c);
9 | Print(s);
10 | }
11 |
12 | static int test(int a, int b) {
13 | return a + b;
14 | }
15 | }
--------------------------------------------------------------------------------
/pa2/TestCases/S2/t5.decaf:
--------------------------------------------------------------------------------
1 | class Cow {
2 | int height;
3 | int weight;
4 |
5 | void Init(int w, int h) {
6 | weight = w;
7 | height = h;
8 | }
9 |
10 | void Moo() {
11 | Print ( this.height, " ", this.weight, "\n" );
12 | }
13 | }
14 |
15 | class Main {
16 | static void main() {
17 | class Cow betsy;
18 | betsy = new Cow();
19 | betsy.Init(100, 122);
20 | betsy.Moo();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/t6.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 |
3 | static int Binky(int a, int[] b, int[] c) {
4 | return b[c[0]];
5 | }
6 |
7 | static void main() {
8 | int[] c;
9 | int [][]d;
10 |
11 | d = new int[][5];
12 | d[0] = new int[12];
13 | c = new int[10];
14 | c[0] = 4 + 5 * 3 / 4 % 2;
15 | d[0][c[0]] = 55;
16 |
17 | Print(c[0], " ", 2 * Binky(100, d[0], c));
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/t9.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | int a;
3 | static void main() {
4 | }
5 | }
6 |
7 | class A extends Main {
8 | void func() {
9 | a = new Main().a; // no error
10 | }
11 | }
--------------------------------------------------------------------------------
/pa2/TestCases/S2/z0.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | string x;
3 | void set(int x) {
4 | this.x = x;
5 | }
6 | int get() {
7 | int x;
8 | x = this.x;
9 | return x;
10 | }
11 | static void main() {
12 | class Main f;
13 | f = new Main();
14 | f.set(5);
15 | f.set(f.get()+f.get());
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/z2.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | void foo() {
3 | this.a = "Hello world";
4 | }
5 | static void main() {
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/z4.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | bool field;
3 |
4 | class Main another;
5 |
6 | int[] foo(int y) {
7 | int[] q;
8 | int i;
9 |
10 | q = new int[y];
11 | i = 0;
12 | while (i < y) {
13 | q[i] = i;
14 | i = i + 1;
15 | }
16 |
17 | return q;
18 | }
19 |
20 | static void main() {
21 | int l;
22 | l = this.foo(5).length();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/z6.decaf:
--------------------------------------------------------------------------------
1 | class MultipleFormals {
2 |
3 | int foo(int x, int y, int z) {
4 | return (x + y + z)/3;
5 | }
6 |
7 | int method() {
8 | int x;
9 | int y;
10 | int z;
11 |
12 | x = 3;
13 | y = x + x * x;
14 | z = (x - y / x) % y;
15 |
16 | return foo(x, y, z);
17 | }
18 | }
19 |
20 | class Main {
21 | static void main () {
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/pa2/TestCases/S2/z9.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | int x;
3 | void set(int x) {
4 | this.x = x;
5 | }
6 | int get() {
7 | int x;
8 | x = this.x;
9 | return x;
10 | }
11 | static void main() {
12 | class Main f;
13 | f = new Main();
14 | f.set(5);
15 | f.set(f.get()+f.get());
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/pa2/report.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa2/report.pdf
--------------------------------------------------------------------------------
/pa2/src/decaf/error/BadArrElementError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:array base type must be non-void type
7 | * PA2
8 | */
9 | public class BadArrElementError extends DecafError {
10 |
11 | public BadArrElementError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "array element type must be non-void known type";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa2/src/decaf/error/BadArrIndexError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:array base type must be non-void type
7 | * PA2
8 | */
9 | public class BadArrIndexError extends DecafError {
10 |
11 | public BadArrIndexError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "array index must be int type";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa2/src/decaf/error/BadArrOperArgError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:incompatible argument 3: int[] given, int/bool/string expected
7 | * 3表示发生错误的是第三个参数
8 | * PA2
9 | */
10 | public class BadArrOperArgError extends DecafError {
11 |
12 | public BadArrOperArgError(Location location) {
13 | super(location);
14 | }
15 |
16 | @Override
17 | protected String getErrMsg() {
18 | return "Array Operation on non-array type" ;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/pa2/src/decaf/error/BadArrTimesError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:array base type must be non-void type
7 | * PA2
8 | */
9 | public class BadArrTimesError extends DecafError {
10 |
11 | public BadArrTimesError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "array repeats time type must be int type";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa2/src/decaf/error/BadInheritanceError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:illegal class inheritance (should be a cyclic)
7 | * PA2
8 | */
9 | public class BadInheritanceError extends DecafError {
10 |
11 | public BadInheritanceError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "illegal class inheritance (should be a cyclic)";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa2/src/decaf/error/BadLengthError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:'length' can only be applied to arrays
7 | * PA2
8 | */
9 | public class BadLengthError extends DecafError {
10 |
11 | public BadLengthError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "'length' can only be applied to arrays";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa2/src/decaf/error/BadNewArrayLength.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:new array length must be an integer
7 | * PA2
8 | */
9 | public class BadNewArrayLength extends DecafError {
10 |
11 | public BadNewArrayLength(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "new array length must be an integer";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa2/src/decaf/error/BadSealedInherError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:illegal class inheritance (should be a cyclic)
7 | * PA2
8 | */
9 | public class BadSealedInherError extends DecafError {
10 |
11 | public BadSealedInherError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "illegal class inheritance from sealed class";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa2/src/decaf/error/BadTestExpr.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:test expression must have bool type
7 | * PA2
8 | */
9 | public class BadTestExpr extends DecafError {
10 |
11 | public BadTestExpr(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "test expression must have bool type";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa2/src/decaf/error/BreakOutOfLoopError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:'break' is only allowed inside a loop
7 | * PA2
8 | */
9 | public class BreakOutOfLoopError extends DecafError {
10 |
11 | public BreakOutOfLoopError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "'break' is only allowed inside a loop";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa2/src/decaf/error/ClassNotFoundError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:class 'zig' not found
7 | * PA2
8 | */
9 | public class ClassNotFoundError extends DecafError {
10 |
11 | private String name;
12 |
13 | public ClassNotFoundError(Location location, String name) {
14 | super(location);
15 | this.name = name;
16 | }
17 |
18 | @Override
19 | protected String getErrMsg() {
20 | return "class '" + name + "' not found";
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/pa2/src/decaf/error/MsgError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * 仅供Parser的yyerror函数使用
7 | */
8 | public class MsgError extends DecafError {
9 |
10 | private String msg;
11 |
12 | public MsgError(Location location, String msg) {
13 | super(location);
14 | this.msg = msg;
15 | }
16 |
17 | @Override
18 | protected String getErrMsg() {
19 | return msg;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/pa2/src/decaf/error/NotArrayError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:[] can only be applied to arrays
7 | * PA2
8 | */
9 | public class NotArrayError extends DecafError {
10 |
11 | public NotArrayError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "[] can only be applied to arrays";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa2/src/decaf/error/NotClassError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * string is not a class type.
7 | */
8 | public class NotClassError extends DecafError {
9 |
10 | private String type;
11 |
12 | public NotClassError(String type, Location location) {
13 | super(location);
14 | this.type = type;
15 | }
16 |
17 | @Override
18 | protected String getErrMsg() {
19 | return type + " is not a class type";
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/pa2/src/decaf/error/SubNotIntError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:array subscript must be an integer
7 | * PA2
8 | */
9 | public class SubNotIntError extends DecafError {
10 |
11 | public SubNotIntError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "array subscript must be an integer";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa2/src/decaf/error/ThisInStaticFuncError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * can not use this in static function
7 | * PA2
8 | */
9 | public class ThisInStaticFuncError extends DecafError {
10 |
11 | public ThisInStaticFuncError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "can not use this in static function";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa2/src/decaf/error/UndeclVarError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:undeclared variable 'python'
7 | * PA2
8 | */
9 | public class UndeclVarError extends DecafError {
10 |
11 | private String name;
12 |
13 | public UndeclVarError(Location location, String name) {
14 | super(location);
15 | this.name = name;
16 | }
17 |
18 | @Override
19 | protected String getErrMsg() {
20 | return "undeclared variable '" + name + "'";
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/pa2/src/decaf/error/UnrecogCharError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:unrecognized char: '@'
7 | * PA1
8 | */
9 | public class UnrecogCharError extends DecafError {
10 |
11 | private char c;
12 |
13 | public UnrecogCharError(Location location, char c) {
14 | super(location);
15 | this.c = c;
16 | }
17 |
18 | @Override
19 | protected String getErrMsg() {
20 | return "unrecognized character '" + c + "'";
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/pa2/tools/byacc/byacc.linux:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa2/tools/byacc/byacc.linux
--------------------------------------------------------------------------------
/pa2/tools/byacc/byacc.linux.amd64:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa2/tools/byacc/byacc.linux.amd64
--------------------------------------------------------------------------------
/pa2/tools/byacc/byacc.mac:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa2/tools/byacc/byacc.mac
--------------------------------------------------------------------------------
/pa2/tools/byacc/byaccj1.13-extended.tar.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa2/tools/byacc/byaccj1.13-extended.tar.gz
--------------------------------------------------------------------------------
/pa2/tools/jflex/JFlex.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa2/tools/jflex/JFlex.jar
--------------------------------------------------------------------------------
/pa3/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/pa3/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | decaf3
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/pa3/Decaf PA3 README.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa3/Decaf PA3 README.pdf
--------------------------------------------------------------------------------
/pa3/TestCases/S3/a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa3/TestCases/S3/a
--------------------------------------------------------------------------------
/pa3/TestCases/S3/a.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | bool[] arr;
4 | arr = new bool[0];
5 | foreach (bool b in arr) {
6 | Print(b);
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/casterror.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | class Main m;
4 | m = new Main();
5 | class A a;
6 | a = (class A)m;
7 | }
8 | }
9 |
10 | class A extends Main {
11 | }
--------------------------------------------------------------------------------
/pa3/TestCases/S3/indexout.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int[] arr;
4 | arr = new int[2];
5 | arr[2] = 0;
6 | }
7 | }
--------------------------------------------------------------------------------
/pa3/TestCases/S3/indexout2.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int[] arr;
4 | arr = new int[2];
5 | arr[-1] = 0;
6 | }
7 | }
--------------------------------------------------------------------------------
/pa3/TestCases/S3/neglength.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | bool[] arr;
3 | static void main() {
4 | new Main().create(-1);
5 | }
6 |
7 | void create(int size) {
8 | arr = new bool[size];
9 | }
10 |
11 | }
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/a.result:
--------------------------------------------------------------------------------
1 | decaf.tacvm.exec.ExecuteException: memory access base = 4 out of bounds
2 | at decaf.tacvm.exec.Memory.checkHeapAccess(Unknown Source)
3 | at decaf.tacvm.exec.Memory.load(Unknown Source)
4 | at decaf.tacvm.exec.Executor.exec(Unknown Source)
5 | at decaf.tacvm.TacVM.run(Unknown Source)
6 | at decaf.tacvm.TacVM.main(Unknown Source)
7 | ***Error at (47,10), tac = _T16 = *(_T3 - 4): memory access base = 4 out of bounds
8 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/casterror.result:
--------------------------------------------------------------------------------
1 | Decaf runtime error: Main cannot be cast to A
2 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/indexout.result:
--------------------------------------------------------------------------------
1 | Decaf runtime error: Array subscript out of bounds
2 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/indexout2.result:
--------------------------------------------------------------------------------
1 | Decaf runtime error: Array subscript out of bounds
2 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/math.result:
--------------------------------------------------------------------------------
1 | 1
2 | 8
3 | 4
4 | 2
5 | 1
6 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/math.tac:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa3/TestCases/S3/output/math.tac
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/neglength.result:
--------------------------------------------------------------------------------
1 | Decaf runtime error: Cannot create negative-sized array
2 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/q1-scopy-test1.result:
--------------------------------------------------------------------------------
1 | 101055
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/q3-guarded-test1.result:
--------------------------------------------------------------------------------
1 | 11010
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/q3-guarded-test2.result:
--------------------------------------------------------------------------------
1 | a>0
2 | a>100
3 | a<200
4 | 110
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/q4-var-test1.result:
--------------------------------------------------------------------------------
1 | 30
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/q4-var-test2.result:
--------------------------------------------------------------------------------
1 | 101010105555
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/q5-array-test1-bool.result:
--------------------------------------------------------------------------------
1 | true
2 | false
3 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/q5-array-test1-class.result:
--------------------------------------------------------------------------------
1 | 10
2 | 15
3 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/q5-array-test1-error.result:
--------------------------------------------------------------------------------
1 | Decaf runtime error: The length of the created array should not be less than 0.
2 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/q5-array-test1-int.result:
--------------------------------------------------------------------------------
1 | 3
2 | 4
3 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/q5-array-test1-string.result:
--------------------------------------------------------------------------------
1 | first
2 | second
3 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/q5-array-test2-default.result:
--------------------------------------------------------------------------------
1 | pa1pa3
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/q5-array-test2-normal.result:
--------------------------------------------------------------------------------
1 | 93
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/q5-array-test3-break.result:
--------------------------------------------------------------------------------
1 | 36
2 | 39
3 | 312
4 | 315
5 | 318
6 | 321
7 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/q5-array-test3-var.result:
--------------------------------------------------------------------------------
1 | 123
2 | 132
3 | 213
4 | 231
5 | 312
6 | 213
7 | 231
8 | 312
9 | 2
10 | 0
11 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/q5-array-test3.result:
--------------------------------------------------------------------------------
1 | 36
2 | 39
3 | 312
4 | 315
5 | 318
6 | 321
7 | 324
8 | 327
9 | 330
10 | 333
11 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/queue.result:
--------------------------------------------------------------------------------
1 | 0 1 2 3
2 | 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 Queue Is Empty0
3 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/stack.result:
--------------------------------------------------------------------------------
1 | 4 4 7 3 1
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/strcmp.result:
--------------------------------------------------------------------------------
1 | "Jobs" and "Gates": Unequal
2 | "case sensitive" and "CASE SENSITIVE": Unequal
3 | "Hello" and "Hello": Equal
4 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/test_divisionbyzero1.result:
--------------------------------------------------------------------------------
1 | testing division by 0 runtime error1
2 | Decaf runtime error: Division by zero error.
3 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/output/test_divisionbyzero2.result:
--------------------------------------------------------------------------------
1 | testing division by 0 runtime error2
2 | Decaf runtime error: Division by zero error.
3 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/q3-guarded-test1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int a;
4 | a = 110;
5 | int b;
6 | if {a>100 : b=a-100;|||
7 | a<50 : b=a+50;|||
8 | a<0: b=a+200;
9 | };
10 | Print(a);
11 | Print(b);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/q3-guarded-test2.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int a;
4 | a = 110;
5 | if {a>0 : Print("a>0\n");|||
6 | a<50 : Print("a<50\n");|||
7 | a>100: Print("a>100\n");|||
8 | a<200: Print("a<200\n");
9 | };
10 | Print(a);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/q4-var-test1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static int foo() {
3 | int a;
4 | a=100;
5 | return a;
6 | }
7 |
8 | static void main() {
9 | int b;
10 | b = 30;
11 | var c = b;
12 | Print(c);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/q5-array-test1-bool.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | bool [] a;
4 | a = true %% 3;
5 | a[1] = false;
6 | Print(a[0]);
7 | Print("\n");
8 | Print(a[1]);
9 | Print("\n");
10 | }
11 | }
--------------------------------------------------------------------------------
/pa3/TestCases/S3/q5-array-test1-class.decaf:
--------------------------------------------------------------------------------
1 | class A {
2 | int b;
3 | int a;
4 | void seta(int a){
5 | this.a = a;
6 | }
7 | void printA(){
8 | Print(a);
9 | Print("\n");
10 | }
11 | }
12 | class Main {
13 | static void main() {
14 | class A [] a;
15 | class A b;
16 | b = new A();
17 | b.seta(10);
18 | a = b %% 6;
19 | a[1].seta(15);
20 | a[0].printA();
21 | a[1].printA();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/q5-array-test1-error.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int [] a;
4 | int b;
5 | int c;
6 | b = 2;
7 | c = 2-3;
8 | a = 3 %% c;
9 | a[1] = a[1] + 1;
10 | Print(a[0]);
11 | Print("\n");
12 | Print(a[1]);
13 | Print("\n");
14 | }
15 | }
--------------------------------------------------------------------------------
/pa3/TestCases/S3/q5-array-test1-int.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int [] a;
4 | a = 3 %% 6;
5 | a[1] = a[1] + 1;
6 | Print(a[0]);
7 | Print("\n");
8 | Print(a[1]);
9 | Print("\n");
10 | }
11 | }
--------------------------------------------------------------------------------
/pa3/TestCases/S3/q5-array-test1-string.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | string [] a;
4 | a = "first" %% 3;
5 | a[1] = "second";
6 | Print(a[0]);
7 | Print("\n");
8 | Print(a[1]);
9 | Print("\n");
10 | }
11 | }
--------------------------------------------------------------------------------
/pa3/TestCases/S3/q5-array-test2-default.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | string[] a;
4 | a = "pa1" %%2;
5 | string b;
6 | b= a[0] default "pa2";
7 | string c;
8 | c= a[2] default "pa3";
9 |
10 | Print(b);
11 | Print(c);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/q5-array-test2-normal.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int[] a;
4 | a = 3%%2;
5 | int b;
6 | b= a[2] default 9;
7 | int c;
8 | c= a[1] default 1;
9 |
10 | Print(b);
11 | Print(c);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/q5-array-test3-break.decaf:
--------------------------------------------------------------------------------
1 | class Father {
2 | int d;
3 | int foo(){
4 | return d;
5 | }
6 | }
7 | class Child extends Father{
8 | int b;
9 | }
10 | class Main {
11 | static void main() {
12 |
13 | int[] a;
14 | int c;
15 | c = 3;
16 | a = c%%10;
17 | foreach(int i in a while c>2){
18 | c = c+i;
19 | Print(i);
20 | Print(c);
21 | Print("\n");
22 | if (c>20)
23 | break;
24 | }
25 |
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/q5-array-test3.decaf:
--------------------------------------------------------------------------------
1 | class Father {
2 | int d;
3 | int foo(){
4 | return d;
5 | }
6 | }
7 | class Child extends Father{
8 | int b;
9 | }
10 | class Main {
11 | static void main() {
12 |
13 | int[] a;
14 | int c;
15 | c = 3;
16 | a = c%%10;
17 | foreach(int i in a while c>2){
18 | c = c+i;
19 | Print(i);
20 | Print(c);
21 | Print("\n");
22 | }
23 |
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/pa3/TestCases/S3/tac.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa3/TestCases/S3/tac.jar
--------------------------------------------------------------------------------
/pa3/TestCases/S3/test_divisionbyzero1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int a;
4 | Print("testing division by 0 runtime error1\n");
5 | a = 13/0;
6 | Print("end");
7 | }
8 | }
--------------------------------------------------------------------------------
/pa3/TestCases/S3/test_divisionbyzero2.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int a;
4 | Print("testing division by 0 runtime error2\n");
5 | a = 13%0;
6 | Print("end");
7 | }
8 | }
--------------------------------------------------------------------------------
/pa3/TestCases/S3/try.cpp:
--------------------------------------------------------------------------------
1 | int main(){int*a=new int[0];}
2 |
--------------------------------------------------------------------------------
/pa3/report.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa3/report.pdf
--------------------------------------------------------------------------------
/pa3/src/decaf/error/BadArrElementError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:array base type must be non-void type
7 | * PA2
8 | */
9 | public class BadArrElementError extends DecafError {
10 |
11 | public BadArrElementError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "array element type must be non-void known type";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa3/src/decaf/error/BadArrIndexError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:array base type must be non-void type
7 | * PA2
8 | */
9 | public class BadArrIndexError extends DecafError {
10 |
11 | public BadArrIndexError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "array index must be int type";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa3/src/decaf/error/BadArrOperArgError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:incompatible argument 3: int[] given, int/bool/string expected
7 | * 3表示发生错误的是第三个参数
8 | * PA2
9 | */
10 | public class BadArrOperArgError extends DecafError {
11 |
12 | public BadArrOperArgError(Location location) {
13 | super(location);
14 | }
15 |
16 | @Override
17 | protected String getErrMsg() {
18 | return "Array Operation on non-array type" ;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/pa3/src/decaf/error/BadArrTimesError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:array base type must be non-void type
7 | * PA2
8 | */
9 | public class BadArrTimesError extends DecafError {
10 |
11 | public BadArrTimesError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "array repeats time type must be int type";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa3/src/decaf/error/BadInheritanceError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:illegal class inheritance (should be a cyclic)
7 | * PA2
8 | */
9 | public class BadInheritanceError extends DecafError {
10 |
11 | public BadInheritanceError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "illegal class inheritance (should be a cyclic)";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa3/src/decaf/error/BadLengthError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:'length' can only be applied to arrays
7 | * PA2
8 | */
9 | public class BadLengthError extends DecafError {
10 |
11 | public BadLengthError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "'length' can only be applied to arrays";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa3/src/decaf/error/BadNewArrayLength.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:new array length must be an integer
7 | * PA2
8 | */
9 | public class BadNewArrayLength extends DecafError {
10 |
11 | public BadNewArrayLength(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "new array length must be an integer";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa3/src/decaf/error/BadSealedInherError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:illegal class inheritance (should be a cyclic)
7 | * PA2
8 | */
9 | public class BadSealedInherError extends DecafError {
10 |
11 | public BadSealedInherError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "illegal class inheritance from sealed class";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa3/src/decaf/error/BadTestExpr.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:test expression must have bool type
7 | * PA2
8 | */
9 | public class BadTestExpr extends DecafError {
10 |
11 | public BadTestExpr(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "test expression must have bool type";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa3/src/decaf/error/BreakOutOfLoopError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:'break' is only allowed inside a loop
7 | * PA2
8 | */
9 | public class BreakOutOfLoopError extends DecafError {
10 |
11 | public BreakOutOfLoopError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "'break' is only allowed inside a loop";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa3/src/decaf/error/ClassNotFoundError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:class 'zig' not found
7 | * PA2
8 | */
9 | public class ClassNotFoundError extends DecafError {
10 |
11 | private String name;
12 |
13 | public ClassNotFoundError(Location location, String name) {
14 | super(location);
15 | this.name = name;
16 | }
17 |
18 | @Override
19 | protected String getErrMsg() {
20 | return "class '" + name + "' not found";
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/pa3/src/decaf/error/MsgError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * 仅供Parser的yyerror函数使用
7 | */
8 | public class MsgError extends DecafError {
9 |
10 | private String msg;
11 |
12 | public MsgError(Location location, String msg) {
13 | super(location);
14 | this.msg = msg;
15 | }
16 |
17 | @Override
18 | protected String getErrMsg() {
19 | return msg;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/pa3/src/decaf/error/NotArrayError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:[] can only be applied to arrays
7 | * PA2
8 | */
9 | public class NotArrayError extends DecafError {
10 |
11 | public NotArrayError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "[] can only be applied to arrays";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa3/src/decaf/error/NotClassError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * string is not a class type.
7 | */
8 | public class NotClassError extends DecafError {
9 |
10 | private String type;
11 |
12 | public NotClassError(String type, Location location) {
13 | super(location);
14 | this.type = type;
15 | }
16 |
17 | @Override
18 | protected String getErrMsg() {
19 | return type + " is not a class type";
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/pa3/src/decaf/error/SubNotIntError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:array subscript must be an integer
7 | * PA2
8 | */
9 | public class SubNotIntError extends DecafError {
10 |
11 | public SubNotIntError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "array subscript must be an integer";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa3/src/decaf/error/ThisInStaticFuncError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * can not use this in static function
7 | * PA2
8 | */
9 | public class ThisInStaticFuncError extends DecafError {
10 |
11 | public ThisInStaticFuncError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "can not use this in static function";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa3/src/decaf/error/UndeclVarError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:undeclared variable 'python'
7 | * PA2
8 | */
9 | public class UndeclVarError extends DecafError {
10 |
11 | private String name;
12 |
13 | public UndeclVarError(Location location, String name) {
14 | super(location);
15 | this.name = name;
16 | }
17 |
18 | @Override
19 | protected String getErrMsg() {
20 | return "undeclared variable '" + name + "'";
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/pa3/src/decaf/error/UnrecogCharError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:unrecognized char: '@'
7 | * PA1
8 | */
9 | public class UnrecogCharError extends DecafError {
10 |
11 | private char c;
12 |
13 | public UnrecogCharError(Location location, char c) {
14 | super(location);
15 | this.c = c;
16 | }
17 |
18 | @Override
19 | protected String getErrMsg() {
20 | return "unrecognized character '" + c + "'";
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/pa3/src/decaf/tac/Functy.java:
--------------------------------------------------------------------------------
1 | package decaf.tac;
2 |
3 | import decaf.symbol.Function;
4 |
5 | public class Functy {
6 | public Label label;
7 |
8 | public Tac paramMemo;
9 |
10 | public Tac head;
11 |
12 | public Tac tail;
13 |
14 | public Function sym;
15 | }
16 |
--------------------------------------------------------------------------------
/pa3/src/decaf/tac/VTable.java:
--------------------------------------------------------------------------------
1 | package decaf.tac;
2 |
3 | public class VTable {
4 | public String name;
5 |
6 | public VTable parent;
7 |
8 | public String className;
9 |
10 | public Label[] entries;
11 | }
12 |
--------------------------------------------------------------------------------
/pa3/tools/byacc/byacc.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa3/tools/byacc/byacc.exe
--------------------------------------------------------------------------------
/pa3/tools/byacc/byacc.linux:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa3/tools/byacc/byacc.linux
--------------------------------------------------------------------------------
/pa3/tools/byacc/byacc.linux.amd64:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa3/tools/byacc/byacc.linux.amd64
--------------------------------------------------------------------------------
/pa3/tools/byacc/byacc.mac:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa3/tools/byacc/byacc.mac
--------------------------------------------------------------------------------
/pa3/tools/byacc/byaccj1.13-extended.tar.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa3/tools/byacc/byaccj1.13-extended.tar.gz
--------------------------------------------------------------------------------
/pa3/tools/jflex/JFlex.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa3/tools/jflex/JFlex.jar
--------------------------------------------------------------------------------
/pa3/tools/tacvm-dev/src/decaf/tacvm/Opcode.java:
--------------------------------------------------------------------------------
1 | package decaf.tacvm;
2 |
3 | public enum Opcode {
4 | ASSIGN, ADD, SUB, MUL, DIV, MOD, EQU, NEQ, LES, LEQ, GTR, GEQ, NEG, LAND,
5 | LOR, LNOT, BRANCH, BEQZ, BNEZ, LIB_CALL, DIRECT_CALL, INDIRECT_CALL, RETURN, LOAD,
6 | STORE, LOAD_VTBL, LOAD_IMM4, LOAD_STR, ENTER_FUNC, LEAVE_FUNC,
7 | MOVE_FROM_RV, PARM
8 | }
9 |
--------------------------------------------------------------------------------
/pa3/tools/tacvm-dev/src/decaf/tacvm/exec/ExecuteException.java:
--------------------------------------------------------------------------------
1 | package decaf.tacvm.exec;
2 |
3 | public class ExecuteException extends RuntimeException {
4 |
5 | private static final long serialVersionUID = -1595578849522351486L;
6 |
7 | public ExecuteException(String message, Throwable cause) {
8 | super(message, cause);
9 | }
10 |
11 | public ExecuteException(String message) {
12 | super(message);
13 | }
14 |
15 | public ExecuteException(Throwable cause) {
16 | super(cause);
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/pa3/tools/tacvm-dev/src/decaf/tacvm/exec/Inst.java:
--------------------------------------------------------------------------------
1 | package decaf.tacvm.exec;
2 |
3 | import decaf.tacvm.Location;
4 | import decaf.tacvm.Opcode;
5 |
6 | public class Inst {
7 | public Opcode opc;
8 |
9 | public int opr0;
10 |
11 | public int opr1;
12 |
13 | public int opr2;
14 |
15 | public String tac;
16 |
17 | public Location loc;
18 |
19 | @Override
20 | public String toString() {
21 | return tac != null ? tac : super.toString();
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/pa3/tools/tacvm-dev/src/decaf/tacvm/parser/Entry.java:
--------------------------------------------------------------------------------
1 | package decaf.tacvm.parser;
2 |
3 | public class Entry {
4 | public String name;
5 |
6 | public int offset;
7 | }
8 |
--------------------------------------------------------------------------------
/pa3/tools/tacvm-dev/src/decaf/tacvm/parser/Temp.java:
--------------------------------------------------------------------------------
1 | package decaf.tacvm.parser;
2 |
3 | public class Temp {
4 | public String name;
5 |
6 | public int iVal;
7 |
8 | public boolean isConst;
9 | }
10 |
--------------------------------------------------------------------------------
/pa3/tools/tacvm-dev/src/decaf/tacvm/parser/VTable.java:
--------------------------------------------------------------------------------
1 | package decaf.tacvm.parser;
2 |
3 | import java.util.List;
4 |
5 | public class VTable {
6 |
7 | public String name;
8 |
9 | public String className;
10 |
11 | public String parentName;
12 |
13 | public List entrys;
14 |
15 | public int offset;
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/pa3/tools/test_q4.result:
--------------------------------------------------------------------------------
1 | branch1
2 | branch2
3 | branch3
--------------------------------------------------------------------------------
/pa3/tools/test_q5.result:
--------------------------------------------------------------------------------
1 | branch1
2 | branch1
3 | branch1
4 | branch1
5 | branch2
6 | branch2
7 | branch2
8 | branch3
9 | branch3
10 |
11 | branch1
12 | branch1
13 | branch1
14 | branch1
15 | branch2
--------------------------------------------------------------------------------
/pa3/tools/test_q5_paint.result:
--------------------------------------------------------------------------------
1 | #
2 | ###
3 | #####
4 | #######
5 | #########
6 | #######
7 | #####
8 | ###
9 | #
10 |
--------------------------------------------------------------------------------
/pa4/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/pa4/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | decaf_PA4
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/pa4/Decaf PA4 README.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa4/Decaf PA4 README.pdf
--------------------------------------------------------------------------------
/pa4/TestCases/S2/output/z5.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | 4true4
--------------------------------------------------------------------------------
/pa4/TestCases/S2/output/z7.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | -1
7 | Exception occurred at PC=0x00400294
8 | Unaligned address in store: 0x00000009
9 | Attempt to execute non-instruction at 0x80000180
10 |
--------------------------------------------------------------------------------
/pa4/TestCases/S4/casterror.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | class Main m;
4 | m = new Main();
5 | class A a;
6 | a = (class A)m;
7 | }
8 | }
9 |
10 | class A extends Main {
11 | }
--------------------------------------------------------------------------------
/pa4/TestCases/S4/indexout.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int[] arr;
4 | arr = new int[2];
5 | arr[2] = 0;
6 | }
7 | }
--------------------------------------------------------------------------------
/pa4/TestCases/S4/neglength.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | bool[] arr;
3 | static void main() {
4 | new Main().create(-1);
5 | }
6 |
7 | void create(int size) {
8 | arr = new bool[size];
9 | }
10 |
11 | }
--------------------------------------------------------------------------------
/pa4/TestCases/S4/output/casterror.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | Decaf runtime error: Main cannot be cast to A
7 |
--------------------------------------------------------------------------------
/pa4/TestCases/S4/output/indexout.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | Decaf runtime error: Array subscript out of bounds
7 |
--------------------------------------------------------------------------------
/pa4/TestCases/S4/output/math.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | 1
7 | 8
8 | 4
9 | 2
10 | 1
11 |
--------------------------------------------------------------------------------
/pa4/TestCases/S4/output/neglength.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | Decaf runtime error: Cannot create negative-sized array
7 |
--------------------------------------------------------------------------------
/pa4/TestCases/S4/output/queue.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | 0 1 2 3
7 | 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 Queue Is Empty0
8 |
--------------------------------------------------------------------------------
/pa4/TestCases/S4/output/stack.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | 4 4 7 3 1
--------------------------------------------------------------------------------
/pa4/TestCases/S4/output/strcmp.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | "Jobs" and "Gates": Unequal
7 | "case sensitive" and "CASE SENSITIVE": Unequal
8 | "Hello" and "Hello": Equal
9 |
--------------------------------------------------------------------------------
/pa4/TestCases/S4/output/t0.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 |
--------------------------------------------------------------------------------
/pa4/TestCases/S4/output/t1.du:
--------------------------------------------------------------------------------
1 | FUNCTION _Main_New :
2 | BASIC BLOCK 0 :
3 | 1 _T0 = 4 [ 2 ]
4 | 2 parm _T0
5 | 3 _T1 = call _Alloc [ 5 6 ]
6 | 4 _T2 = VTBL <_Main> [ 5 ]
7 | 5 *(_T1 + 0) = _T2
8 | 6 END BY RETURN, result = _T1
9 |
10 | FUNCTION main :
11 | BASIC BLOCK 0 :
12 | 7 _T3 = "hello world" [ 8 ]
13 | 8 parm _T3
14 | 9 call _PrintString
15 | 10 END BY RETURN, void result
16 |
17 |
--------------------------------------------------------------------------------
/pa4/TestCases/S4/output/t1.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | hello world
--------------------------------------------------------------------------------
/pa4/TestCases/S4/output/t2.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | true 15
--------------------------------------------------------------------------------
/pa4/TestCases/S4/output/t3.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | 9hello
--------------------------------------------------------------------------------
/pa4/TestCases/S4/output/t4.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | Loop 1
7 | 0
8 | 2
9 |
--------------------------------------------------------------------------------
/pa4/TestCases/S4/output/t5.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | 122 100
7 |
--------------------------------------------------------------------------------
/pa4/TestCases/S4/output/t6.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | 5 110
--------------------------------------------------------------------------------
/pa4/TestCases/S4/output/t7.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | ack!
--------------------------------------------------------------------------------
/pa4/TestCases/S4/output/t8.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | spots: true height: 5
--------------------------------------------------------------------------------
/pa4/TestCases/S4/output/t9.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | Base
7 | Sub1
8 | Sub2
9 | Sub3
10 | Sub4
11 | Sub4
12 | Sub4
13 |
--------------------------------------------------------------------------------
/pa4/TestCases/S4/t1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | Print("hello world");
4 | }
5 | }
6 |
7 |
--------------------------------------------------------------------------------
/pa4/TestCases/S4/t2.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int a;
4 | string b;
5 | bool c;
6 |
7 | c = true;
8 | b = "wow!";
9 | a = 3;
10 | if (c)
11 | a = a * 5;
12 | Print(c, " ", a);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/pa4/TestCases/S4/t3.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int c;
4 | string s;
5 |
6 | s = "hello";
7 | c = test(4, 5);
8 | Print(c);
9 | Print(s);
10 | }
11 |
12 | static int test(int a, int b) {
13 | return a + b;
14 | }
15 | }
--------------------------------------------------------------------------------
/pa4/TestCases/S4/t5.decaf:
--------------------------------------------------------------------------------
1 | class Cow {
2 | int height;
3 | int weight;
4 |
5 | void Init(int w, int h) {
6 | weight = w;
7 | height = h;
8 | }
9 |
10 | void Moo() {
11 | Print ( this.height, " ", this.weight, "\n" );
12 | }
13 | }
14 |
15 | class Main {
16 | static void main() {
17 | class Cow betsy;
18 | betsy = new Cow();
19 | betsy.Init(100, 122);
20 | betsy.Moo();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/pa4/TestCases/S4/t6.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 |
3 | static int Binky(int a, int[] b, int[] c) {
4 | return b[c[0]];
5 | }
6 |
7 | static void main() {
8 | int[] c;
9 | int [][]d;
10 |
11 | d = new int[][5];
12 | d[0] = new int[12];
13 | c = new int[10];
14 | c[0] = 4 + 5 * 3 / 4 % 2;
15 | d[0][c[0]] = 55;
16 |
17 | Print(c[0], " ", 2 * Binky(100, d[0], c));
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/pa4/report.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa4/report.pdf
--------------------------------------------------------------------------------
/pa4/src/decaf/dataflow/IDAllocator.java:
--------------------------------------------------------------------------------
1 | package decaf.dataflow;
2 |
3 | /**
4 | * Allocate unique Ids for TAC.
5 | */
6 | public class IDAllocator {
7 | private static int cnt = 0;
8 |
9 | public static int apply() {
10 | ++cnt;
11 | return cnt;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/pa4/src/decaf/error/BadArrElementError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:array base type must be non-void type
7 | * PA2
8 | */
9 | public class BadArrElementError extends DecafError {
10 |
11 | public BadArrElementError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "array element type must be non-void type";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa4/src/decaf/error/BadInheritanceError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:illegal class inheritance (should be a cyclic)
7 | * PA2
8 | */
9 | public class BadInheritanceError extends DecafError {
10 |
11 | public BadInheritanceError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "illegal class inheritance (should be a cyclic)";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa4/src/decaf/error/BadLengthError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:'length' can only be applied to arrays
7 | * PA2
8 | */
9 | public class BadLengthError extends DecafError {
10 |
11 | public BadLengthError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "'length' can only be applied to arrays";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa4/src/decaf/error/BadNewArrayLength.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:new array length must be an integer
7 | * PA2
8 | */
9 | public class BadNewArrayLength extends DecafError {
10 |
11 | public BadNewArrayLength(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "new array length must be an integer";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa4/src/decaf/error/BadTestExpr.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:test expression must have bool type
7 | * PA2
8 | */
9 | public class BadTestExpr extends DecafError {
10 |
11 | public BadTestExpr(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "test expression must have bool type";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa4/src/decaf/error/BreakOutOfLoopError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:'break' is only allowed inside a loop
7 | * PA2
8 | */
9 | public class BreakOutOfLoopError extends DecafError {
10 |
11 | public BreakOutOfLoopError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "'break' is only allowed inside a loop";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa4/src/decaf/error/ClassNotFoundError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:class 'zig' not found
7 | * PA2
8 | */
9 | public class ClassNotFoundError extends DecafError {
10 |
11 | private String name;
12 |
13 | public ClassNotFoundError(Location location, String name) {
14 | super(location);
15 | this.name = name;
16 | }
17 |
18 | @Override
19 | protected String getErrMsg() {
20 | return "class '" + name + "' not found";
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/pa4/src/decaf/error/MsgError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * 仅供Parser的yyerror函数使用
7 | */
8 | public class MsgError extends DecafError {
9 |
10 | private String msg;
11 |
12 | public MsgError(Location location, String msg) {
13 | super(location);
14 | this.msg = msg;
15 | }
16 |
17 | @Override
18 | protected String getErrMsg() {
19 | return msg;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/pa4/src/decaf/error/NotArrayError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:[] can only be applied to arrays
7 | * PA2
8 | */
9 | public class NotArrayError extends DecafError {
10 |
11 | public NotArrayError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "[] can only be applied to arrays";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa4/src/decaf/error/NotClassError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * string is not a class type.
7 | */
8 | public class NotClassError extends DecafError {
9 |
10 | private String type;
11 |
12 | public NotClassError(String type, Location location) {
13 | super(location);
14 | this.type = type;
15 | }
16 |
17 | @Override
18 | protected String getErrMsg() {
19 | return type + " is not a class type";
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/pa4/src/decaf/error/SubNotIntError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:array subscript must be an integer
7 | * PA2
8 | */
9 | public class SubNotIntError extends DecafError {
10 |
11 | public SubNotIntError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "array subscript must be an integer";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa4/src/decaf/error/ThisInStaticFuncError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * can not use this in static function
7 | * PA2
8 | */
9 | public class ThisInStaticFuncError extends DecafError {
10 |
11 | public ThisInStaticFuncError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "can not use this in static function";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa4/src/decaf/error/UnrecogCharError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:unrecognized char: '@'
7 | * PA1
8 | */
9 | public class UnrecogCharError extends DecafError {
10 |
11 | private char c;
12 |
13 | public UnrecogCharError(Location location, char c) {
14 | super(location);
15 | this.c = c;
16 | }
17 |
18 | @Override
19 | protected String getErrMsg() {
20 | return "unrecognized character '" + c + "'";
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/pa4/src/decaf/machdesc/Asm.java:
--------------------------------------------------------------------------------
1 | package decaf.machdesc;
2 |
3 | public abstract class Asm {
4 | public abstract String toString();
5 | }
6 |
--------------------------------------------------------------------------------
/pa4/src/decaf/machdesc/MachineDescription.java:
--------------------------------------------------------------------------------
1 | package decaf.machdesc;
2 |
3 | import java.io.PrintWriter;
4 | import java.util.List;
5 |
6 | import decaf.dataflow.FlowGraph;
7 | import decaf.tac.VTable;
8 |
9 | public interface MachineDescription {
10 |
11 | public void setOutputStream(PrintWriter pw);
12 |
13 | public void emitVTable(List vtables);
14 |
15 | public void emitAsm(List gs);
16 | }
17 |
--------------------------------------------------------------------------------
/pa4/src/decaf/machdesc/Register.java:
--------------------------------------------------------------------------------
1 | package decaf.machdesc;
2 |
3 | import decaf.tac.Temp;
4 |
5 | public abstract class Register {
6 |
7 | public Temp var;
8 |
9 | public abstract String toString();
10 | }
11 |
--------------------------------------------------------------------------------
/pa4/src/decaf/tac/Functy.java:
--------------------------------------------------------------------------------
1 | package decaf.tac;
2 |
3 | import decaf.symbol.Function;
4 |
5 | public class Functy {
6 | public Label label;
7 |
8 | public Tac paramMemo;
9 |
10 | public Tac head;
11 |
12 | public Tac tail;
13 |
14 | public Function sym;
15 | }
16 |
--------------------------------------------------------------------------------
/pa4/src/decaf/tac/VTable.java:
--------------------------------------------------------------------------------
1 | package decaf.tac;
2 |
3 | public class VTable {
4 | public String name;
5 |
6 | public VTable parent;
7 |
8 | public String className;
9 |
10 | public Label[] entries;
11 | }
12 |
--------------------------------------------------------------------------------
/pa4/tools/byacc/byacc.linux:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa4/tools/byacc/byacc.linux
--------------------------------------------------------------------------------
/pa4/tools/byacc/byacc.linux.amd64:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa4/tools/byacc/byacc.linux.amd64
--------------------------------------------------------------------------------
/pa4/tools/byacc/byacc.mac:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa4/tools/byacc/byacc.mac
--------------------------------------------------------------------------------
/pa4/tools/byacc/byaccj1.13-extended.tar.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa4/tools/byacc/byaccj1.13-extended.tar.gz
--------------------------------------------------------------------------------
/pa4/tools/jflex/JFlex.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa4/tools/jflex/JFlex.jar
--------------------------------------------------------------------------------
/pa4/tools/spim/cygwin1.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa4/tools/spim/cygwin1.dll
--------------------------------------------------------------------------------
/pa4/tools/spim/spim-7.3.tar.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa4/tools/spim/spim-7.3.tar.gz
--------------------------------------------------------------------------------
/pa4/tools/spim/spim.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa4/tools/spim/spim.exe
--------------------------------------------------------------------------------
/pa4/tools/spim/spim.linux:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa4/tools/spim/spim.linux
--------------------------------------------------------------------------------
/pa4/tools/spim/spim.mac:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa4/tools/spim/spim.mac
--------------------------------------------------------------------------------
/pa5/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/pa5/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | PA5(选做)
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/pa5/Decaf PA5 README.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa5/Decaf PA5 README.pdf
--------------------------------------------------------------------------------
/pa5/TestCases/S1/error1.decaf:
--------------------------------------------------------------------------------
1 | // This Program should trigger an "Unrecognized Character Error"
2 |
3 | class Main {
4 | static void main() {
5 | int i;
6 | i = i @ -1; // error!
7 | }
8 | }
--------------------------------------------------------------------------------
/pa5/TestCases/S1/error2.decaf:
--------------------------------------------------------------------------------
1 | // This Program should trigger an "Integer Too Large Error"
2 |
3 | class Main {
4 | static void main() {
5 | int i;
6 |
7 | i = 73295739294; // error!
8 | i = 3141592653; // error too!
9 | }
10 | }
--------------------------------------------------------------------------------
/pa5/TestCases/S1/error3.decaf:
--------------------------------------------------------------------------------
1 | // This Program should trigger a "Syntax Error"
2 |
3 | class Main {
4 | static void main() {
5 | int i = 0; // error! we don't support this grammer
6 |
7 | i = i + 1;
8 | }
9 | }
--------------------------------------------------------------------------------
/pa5/TestCases/S1/error4.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | string str;
4 | str = "string
5 | ";
6 | }
7 | }
--------------------------------------------------------------------------------
/pa5/TestCases/S1/error5.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | string s;
4 | s = "str
--------------------------------------------------------------------------------
/pa5/TestCases/S1/output/error1.result:
--------------------------------------------------------------------------------
1 | *** Error at (6,15): unrecognized character '@'
2 |
--------------------------------------------------------------------------------
/pa5/TestCases/S1/output/error2.result:
--------------------------------------------------------------------------------
1 | *** Error at (7,13): integer literal 73295739294 is too large
2 | *** Error at (8,13): integer literal 3141592653 is too large
3 |
--------------------------------------------------------------------------------
/pa5/TestCases/S1/output/error3.result:
--------------------------------------------------------------------------------
1 | *** Error at (5,15): syntax error
2 |
--------------------------------------------------------------------------------
/pa5/TestCases/S1/output/error4.result:
--------------------------------------------------------------------------------
1 | *** Error at (4,15): illegal newline in string constant "string"
2 |
--------------------------------------------------------------------------------
/pa5/TestCases/S1/output/error5.result:
--------------------------------------------------------------------------------
1 | *** Error at (4,13): unterminated string constant "str"
2 | *** Error at (4,17): syntax error
3 |
--------------------------------------------------------------------------------
/pa5/TestCases/S1/output/test5.result:
--------------------------------------------------------------------------------
1 | program
2 | class Main
3 | static func main voidtype
4 | formals
5 | stmtblock
6 | vardef s stringtype
7 | assign
8 | varref s
9 | stringconst "\\\"\n"
10 |
--------------------------------------------------------------------------------
/pa5/TestCases/S1/test1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | bool field;
3 |
4 | class Main another;
5 |
6 | int[] foo(int y) {
7 | int[] q;
8 | int i;
9 |
10 | q = new int[y];
11 | i = 0;
12 | while (i < y) {
13 | q[i] = i;
14 | i = i + 1;
15 | }
16 |
17 | return q;
18 | }
19 |
20 | static int main() {
21 | return this.foo(5).length();
22 | }
23 | }
--------------------------------------------------------------------------------
/pa5/TestCases/S1/test3.decaf:
--------------------------------------------------------------------------------
1 | class MultipleFormals {
2 |
3 | int foo(int x, int y, int z) {
4 | return (x + y + z)/3;
5 | }
6 |
7 | int method() {
8 | int x;
9 | int y;
10 | int z;
11 |
12 | x = 3;
13 | y = x + x * x;
14 | z = (x - y / x) % y;
15 |
16 | return foo(x, y, z);
17 | }
18 | }
--------------------------------------------------------------------------------
/pa5/TestCases/S1/test4.decaf:
--------------------------------------------------------------------------------
1 | class Father {
2 | int field;
3 |
4 | void method(int f) {
5 | if (f > 0 && f < 10) {
6 | f = f - 3;
7 | return method(f);
8 | }
9 | }
10 | }
11 |
12 | class Child extends Father {
13 | void start() {
14 | class Father p;
15 |
16 | p = this;
17 | p.field = 5;
18 | p = null;
19 |
20 | Print(this.field);
21 | }
22 | }
--------------------------------------------------------------------------------
/pa5/TestCases/S1/test5.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | string s;
4 | s = "\\\"\n";
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/arrayerror.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | int[] a;
3 | static void main() {
4 |
5 | }
6 |
7 | void func() {
8 | a = new int[-1]; // valid
9 | a = new int["123"];
10 | int a;
11 | a.length();
12 | a[1] = 2;
13 | this.a.length(0);
14 | a = this.a[false];
15 | }
16 | }
--------------------------------------------------------------------------------
/pa5/TestCases/S2/miscerror.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | Print(new Main(), 1);
4 | if (true)
5 | break;
6 | Print(instanceof(1, Main));
7 | class Main m;
8 | m = (class Main)true;
9 | return 1;
10 | }
11 | }
--------------------------------------------------------------------------------
/pa5/TestCases/S2/nomainerror.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static int main() {
3 | }
4 | }
5 |
6 | class Main1 {
7 | static void main(int i) {
8 | }
9 | }
--------------------------------------------------------------------------------
/pa5/TestCases/S2/output/arrayerror.result:
--------------------------------------------------------------------------------
1 | *** Error at (9,21): new array length must be an integer
2 | *** Error at (11,11): 'length' can only be applied to arrays
3 | *** Error at (12,9): [] can only be applied to arrays
4 | *** Error at (13,16): function 'length' expects 0 argument(s) but 1 given
5 | *** Error at (14,13): array subscript must be an integer
6 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/output/exprerror.result:
--------------------------------------------------------------------------------
1 | *** Error at (8,15): syntax error
2 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/output/miscerror.result:
--------------------------------------------------------------------------------
1 | *** Error at (3,15): incompatible argument 1: class : Main given, int/bool/string expected
2 | *** Error at (5,13): 'break' is only allowed inside a loop
3 | *** Error at (6,15): int is not a class type
4 | *** Error at (8,25): bool is not a class type
5 | *** Error at (9,9): incompatible return: int given, void expected
6 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/output/nomainerror.result:
--------------------------------------------------------------------------------
1 | *** Error: no legal Main class named 'Main' was found
2 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/output/overrideerror.result:
--------------------------------------------------------------------------------
1 | *** Error at (21,10): overriding method 'func' doesn't match the type signature in class 'A'
2 | *** Error at (24,13): overriding method 'func1' doesn't match the type signature in class 'A'
3 | *** Error at (27,13): overriding method 'func2' doesn't match the type signature in class 'A'
4 | *** Error at (37,1): illegal class inheritance (should be a cyclic)
5 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/output/referror.result:
--------------------------------------------------------------------------------
1 | *** Error at (5,9): can not reference a non-static field 'a' from static method 'main'
2 | *** Error at (6,9): can not use this in static function
3 | *** Error at (7,14): cannot access field 'a' from 'class : Main'
4 | *** Error at (8,9): can not reference a non-static field 'func' from static method 'main'
5 | *** Error at (12,20): field 'b' of 'class : Test' not accessible here
6 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/output/t1.result:
--------------------------------------------------------------------------------
1 | GLOBAL SCOPE:
2 | (1,1) -> class Main
3 | CLASS SCOPE OF 'Main':
4 | (2,17) -> static function main : void
5 | FORMAL SCOPE OF 'main':
6 | LOCAL SCOPE:
7 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/output/t2.result:
--------------------------------------------------------------------------------
1 | GLOBAL SCOPE:
2 | (2,1) -> class Main
3 | CLASS SCOPE OF 'Main':
4 | (3,17) -> static function main : void
5 | FORMAL SCOPE OF 'main':
6 | LOCAL SCOPE:
7 | (4,13) -> variable a : int
8 | (5,16) -> variable b : string
9 | (6,14) -> variable c : bool
10 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/output/t9.result:
--------------------------------------------------------------------------------
1 | GLOBAL SCOPE:
2 | (1,1) -> class Main
3 | (7,1) -> class A : Main
4 | CLASS SCOPE OF 'Main':
5 | (2,9) -> variable a : int
6 | (3,17) -> static function main : void
7 | FORMAL SCOPE OF 'main':
8 | LOCAL SCOPE:
9 | CLASS SCOPE OF 'A':
10 | (8,10) -> function func : class : A->void
11 | FORMAL SCOPE OF 'func':
12 | (8,10) -> variable @this : class : A
13 | LOCAL SCOPE:
14 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/output/z0.result:
--------------------------------------------------------------------------------
1 | *** Error at (4,10): incompatible operands: string = int
2 | *** Error at (8,5): incompatible operands: int = string
3 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/output/z2.result:
--------------------------------------------------------------------------------
1 | *** Error at (3,8): field 'a' not found in 'class : Main'
2 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/output/z4.result:
--------------------------------------------------------------------------------
1 | *** Error at (22,13): can not use this in static function
2 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/output/z5.result:
--------------------------------------------------------------------------------
1 | *** Error at (7,9): can not reference a non-static field 'i' from static method 'main'
2 | *** Error at (9,24): can not reference a non-static field 'i' from static method 'main'
3 | *** Error at (13,24): can not reference a non-static field 'i' from static method 'main'
4 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/referror.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | int a;
3 |
4 | static void main() {
5 | a = 1;
6 | this.a = 1;
7 | Main.a = 1;
8 | func();
9 | }
10 |
11 | void func() {
12 | new Test().b = 1;
13 | }
14 | }
15 |
16 | class Test extends Main {
17 | int b;
18 | }
--------------------------------------------------------------------------------
/pa5/TestCases/S2/t1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | Print("hello world");
4 | }
5 | }
6 |
7 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/t2.decaf:
--------------------------------------------------------------------------------
1 |
2 | class Main {
3 | static void main() {
4 | int a;
5 | string b;
6 | bool c;
7 |
8 | c = true;
9 | b = "wow!";
10 | a = 3;
11 | if (c)
12 | a = a * 5;
13 | Print(c, " ", a);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/t3.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int c;
4 | string s;
5 |
6 | s = "hello";
7 | c = test(4, 5);
8 | Print(c);
9 | Print(s);
10 | }
11 |
12 | static int test(int a, int b) {
13 | return a + b;
14 | }
15 | }
--------------------------------------------------------------------------------
/pa5/TestCases/S2/t5.decaf:
--------------------------------------------------------------------------------
1 | class Cow {
2 | int height;
3 | int weight;
4 |
5 | void Init(int w, int h) {
6 | weight = w;
7 | height = h;
8 | }
9 |
10 | void Moo() {
11 | Print ( this.height, " ", this.weight, "\n" );
12 | }
13 | }
14 |
15 | class Main {
16 | static void main() {
17 | class Cow betsy;
18 | betsy = new Cow();
19 | betsy.Init(100, 122);
20 | betsy.Moo();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/t6.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 |
3 | static int Binky(int a, int[] b, int[] c) {
4 | return b[c[0]];
5 | }
6 |
7 | static void main() {
8 | int[] c;
9 | int [][]d;
10 |
11 | d = new int[][5];
12 | d[0] = new int[12];
13 | c = new int[10];
14 | c[0] = 4 + 5 * 3 / 4 % 2;
15 | d[0][c[0]] = 55;
16 |
17 | Print(c[0], " ", 2 * Binky(100, d[0], c));
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/t9.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | int a;
3 | static void main() {
4 | }
5 | }
6 |
7 | class A extends Main {
8 | void func() {
9 | a = new Main().a; // no error
10 | }
11 | }
--------------------------------------------------------------------------------
/pa5/TestCases/S2/z0.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | string x;
3 | void set(int x) {
4 | this.x = x;
5 | }
6 | int get() {
7 | int x;
8 | x = this.x;
9 | return x;
10 | }
11 | static void main() {
12 | class Main f;
13 | f = new Main();
14 | f.set(5);
15 | f.set(f.get()+f.get());
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/z2.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | void foo() {
3 | this.a = "Hello world";
4 | }
5 | static void main() {
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/z4.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | bool field;
3 |
4 | class Main another;
5 |
6 | int[] foo(int y) {
7 | int[] q;
8 | int i;
9 |
10 | q = new int[y];
11 | i = 0;
12 | while (i < y) {
13 | q[i] = i;
14 | i = i + 1;
15 | }
16 |
17 | return q;
18 | }
19 |
20 | static void main() {
21 | int l;
22 | l = this.foo(5).length();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/z6.decaf:
--------------------------------------------------------------------------------
1 | class MultipleFormals {
2 |
3 | int foo(int x, int y, int z) {
4 | return (x + y + z)/3;
5 | }
6 |
7 | int method() {
8 | int x;
9 | int y;
10 | int z;
11 |
12 | x = 3;
13 | y = x + x * x;
14 | z = (x - y / x) % y;
15 |
16 | return foo(x, y, z);
17 | }
18 | }
19 |
20 | class Main {
21 | static void main () {
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/pa5/TestCases/S2/z9.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | int x;
3 | void set(int x) {
4 | this.x = x;
5 | }
6 | int get() {
7 | int x;
8 | x = this.x;
9 | return x;
10 | }
11 | static void main() {
12 | class Main f;
13 | f = new Main();
14 | f.set(5);
15 | f.set(f.get()+f.get());
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/pa5/TestCases/S3/casterror.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | class Main m;
4 | m = new Main();
5 | class A a;
6 | a = (class A)m;
7 | }
8 | }
9 |
10 | class A extends Main {
11 | }
--------------------------------------------------------------------------------
/pa5/TestCases/S3/indexout.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int[] arr;
4 | arr = new int[2];
5 | arr[2] = 0;
6 | }
7 | }
--------------------------------------------------------------------------------
/pa5/TestCases/S3/neglength.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | bool[] arr;
3 | static void main() {
4 | new Main().create(-1);
5 | }
6 |
7 | void create(int size) {
8 | arr = new bool[size];
9 | }
10 |
11 | }
--------------------------------------------------------------------------------
/pa5/TestCases/S3/output/casterror.result:
--------------------------------------------------------------------------------
1 | Decaf runtime error: Main cannot be cast to A
2 |
--------------------------------------------------------------------------------
/pa5/TestCases/S3/output/indexout.result:
--------------------------------------------------------------------------------
1 | Decaf runtime error: Array subscript out of bounds
2 |
--------------------------------------------------------------------------------
/pa5/TestCases/S3/output/math.result:
--------------------------------------------------------------------------------
1 | 1
2 | 8
3 | 4
4 | 2
5 | 1
6 |
--------------------------------------------------------------------------------
/pa5/TestCases/S3/output/neglength.result:
--------------------------------------------------------------------------------
1 | *** Error at (30,5): syntax error
2 | *** Error: undefined function _Main.create
3 |
--------------------------------------------------------------------------------
/pa5/TestCases/S3/output/queue.result:
--------------------------------------------------------------------------------
1 | *** Error at (131,5): syntax error
2 | *** Error: undefined function _Queue.EnQueue
3 | *** Error: undefined function _Queue.DeQueue
4 |
--------------------------------------------------------------------------------
/pa5/TestCases/S3/output/stack.result:
--------------------------------------------------------------------------------
1 | *** Error at (77,5): syntax error
2 | *** Error: undefined function _Stack.Push
3 | *** Error: undefined function _Stack.Pop
4 | *** Error: undefined function _Stack.NumElems
5 |
--------------------------------------------------------------------------------
/pa5/TestCases/S3/output/strcmp.result:
--------------------------------------------------------------------------------
1 | "Jobs" and "Gates": Unequal
2 | "case sensitive" and "CASE SENSITIVE": Unequal
3 | "Hello" and "Hello": Equal
4 |
--------------------------------------------------------------------------------
/pa5/TestCases/S3/output/t1.result:
--------------------------------------------------------------------------------
1 | hello world
--------------------------------------------------------------------------------
/pa5/TestCases/S3/output/t1.tac:
--------------------------------------------------------------------------------
1 | VTABLE(_Main) {
2 |
3 | Main
4 | }
5 |
6 | FUNCTION(_Main_New) {
7 | memo ''
8 | _Main_New:
9 | _T0 = 4
10 | parm _T0
11 | _T1 = call _Alloc
12 | _T2 = VTBL <_Main>
13 | *(_T1 + 0) = _T2
14 | return _T1
15 | }
16 |
17 | FUNCTION(main) {
18 | memo ''
19 | main:
20 | _T3 = "hello world"
21 | parm _T3
22 | call _PrintString
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/pa5/TestCases/S3/output/t2.result:
--------------------------------------------------------------------------------
1 | true 15
--------------------------------------------------------------------------------
/pa5/TestCases/S3/output/t3.result:
--------------------------------------------------------------------------------
1 | 9hello
--------------------------------------------------------------------------------
/pa5/TestCases/S3/output/t4.result:
--------------------------------------------------------------------------------
1 | *** Error at (95,13): syntax error
2 |
--------------------------------------------------------------------------------
/pa5/TestCases/S3/output/t5.result:
--------------------------------------------------------------------------------
1 | *** Error at (76,5): syntax error
2 |
--------------------------------------------------------------------------------
/pa5/TestCases/S3/output/t6.result:
--------------------------------------------------------------------------------
1 | 5 110
--------------------------------------------------------------------------------
/pa5/TestCases/S3/output/t7.result:
--------------------------------------------------------------------------------
1 | *** Error at (94,5): syntax error
2 |
--------------------------------------------------------------------------------
/pa5/TestCases/S3/output/t8.result:
--------------------------------------------------------------------------------
1 | *** Error at (97,5): syntax error
2 | *** Error: undefined function _Cow.IsSpottedCow
3 |
--------------------------------------------------------------------------------
/pa5/TestCases/S3/output/t9.result:
--------------------------------------------------------------------------------
1 | Base
2 | Sub1
3 | Sub2
4 | Sub3
5 | Sub4
6 | Sub4
7 | Sub4
8 |
--------------------------------------------------------------------------------
/pa5/TestCases/S3/t1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | Print("hello world");
4 | }
5 | }
6 |
7 |
--------------------------------------------------------------------------------
/pa5/TestCases/S3/t2.decaf:
--------------------------------------------------------------------------------
1 |
2 | class Main {
3 | static void main() {
4 | int a;
5 | string b;
6 | bool c;
7 |
8 | c = true;
9 | b = "wow!";
10 | a = 3;
11 | if (c)
12 | a = a * 5;
13 | Print(c, " ", a);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/pa5/TestCases/S3/t3.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int c;
4 | string s;
5 |
6 | s = "hello";
7 | c = test(4, 5);
8 | Print(c);
9 | Print(s);
10 | }
11 |
12 | static int test(int a, int b) {
13 | return a + b;
14 | }
15 | }
--------------------------------------------------------------------------------
/pa5/TestCases/S3/t5.decaf:
--------------------------------------------------------------------------------
1 | class Cow {
2 | int height;
3 | int weight;
4 |
5 | void Init(int w, int h) {
6 | weight = w;
7 | height = h;
8 | }
9 |
10 | void Moo() {
11 | Print ( this.height, " ", this.weight, "\n" );
12 | }
13 | }
14 |
15 | class Main {
16 | static void main() {
17 | class Cow betsy;
18 | betsy = new Cow();
19 | betsy.Init(100, 122);
20 | betsy.Moo();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/pa5/TestCases/S3/t6.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 |
3 | static int Binky(int a, int[] b, int[] c) {
4 | return b[c[0]];
5 | }
6 |
7 | static void main() {
8 | int[] c;
9 | int [][]d;
10 |
11 | d = new int[][5];
12 | d[0] = new int[12];
13 | c = new int[10];
14 | c[0] = 4 + 5 * 3 / 4 % 2;
15 | d[0][c[0]] = 55;
16 |
17 | Print(c[0], " ", 2 * Binky(100, d[0], c));
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/pa5/TestCases/S3/tac.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa5/TestCases/S3/tac.jar
--------------------------------------------------------------------------------
/pa5/TestCases/S4/casterror.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | class Main m;
4 | m = new Main();
5 | class A a;
6 | a = (class A)m;
7 | }
8 | }
9 |
10 | class A extends Main {
11 | }
--------------------------------------------------------------------------------
/pa5/TestCases/S4/indexout.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int[] arr;
4 | arr = new int[2];
5 | arr[2] = 0;
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/pa5/TestCases/S4/neglength.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | bool[] arr;
3 | static void main() {
4 | new Main().create(-1);
5 | }
6 |
7 | void create(int size) {
8 | arr = new bool[size];
9 | }
10 |
11 | }
--------------------------------------------------------------------------------
/pa5/TestCases/S4/output/casterror.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | Decaf runtime error: Main cannot be cast to A
7 |
--------------------------------------------------------------------------------
/pa5/TestCases/S4/output/indexout.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | Decaf runtime error: Array subscript out of bounds
7 |
--------------------------------------------------------------------------------
/pa5/TestCases/S4/output/math.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | 1
7 | 8
8 | 4
9 | 2
10 | 1
11 |
--------------------------------------------------------------------------------
/pa5/TestCases/S4/output/neglength.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | Decaf runtime error: Cannot create negative-sized array
7 |
--------------------------------------------------------------------------------
/pa5/TestCases/S4/output/queue.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | 0 1 2 3
7 | 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 Queue Is Empty0
8 |
--------------------------------------------------------------------------------
/pa5/TestCases/S4/output/stack.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | 4 4 7 3 1
--------------------------------------------------------------------------------
/pa5/TestCases/S4/output/strcmp.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | "Jobs" and "Gates": Unequal
7 | "case sensitive" and "CASE SENSITIVE": Unequal
8 | "Hello" and "Hello": Equal
9 |
--------------------------------------------------------------------------------
/pa5/TestCases/S4/output/t0.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 |
--------------------------------------------------------------------------------
/pa5/TestCases/S4/output/t1.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | hello world
--------------------------------------------------------------------------------
/pa5/TestCases/S4/output/t10.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | 45
--------------------------------------------------------------------------------
/pa5/TestCases/S4/output/t2.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | true 15
--------------------------------------------------------------------------------
/pa5/TestCases/S4/output/t3.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | 9hello
--------------------------------------------------------------------------------
/pa5/TestCases/S4/output/t4.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | Loop 1
7 | 0
8 | 2
9 |
--------------------------------------------------------------------------------
/pa5/TestCases/S4/output/t5.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | 122 100
7 |
--------------------------------------------------------------------------------
/pa5/TestCases/S4/output/t6.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | 5 110
--------------------------------------------------------------------------------
/pa5/TestCases/S4/output/t7.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | ack!
--------------------------------------------------------------------------------
/pa5/TestCases/S4/output/t8.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | spots: true height: 5
--------------------------------------------------------------------------------
/pa5/TestCases/S4/output/t9.result:
--------------------------------------------------------------------------------
1 | SPIM Version 7.3. of August 28, 2006
2 | Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
3 | All Rights Reserved.
4 | See the file README for a full copyright notice.
5 | Loaded: ./exceptions.s
6 | Base
7 | Sub1
8 | Sub2
9 | Sub3
10 | Sub4
11 | Sub4
12 | Sub4
13 |
--------------------------------------------------------------------------------
/pa5/TestCases/S4/t1.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | Print("hello world");
4 | }
5 | }
6 |
7 |
--------------------------------------------------------------------------------
/pa5/TestCases/S4/t2.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int a;
4 | string b;
5 | bool c;
6 |
7 | c = true;
8 | b = "wow!";
9 | a = 3;
10 | if (c)
11 | a = a * 5;
12 | Print(c, " ", a);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/pa5/TestCases/S4/t3.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 | static void main() {
3 | int c;
4 | string s;
5 |
6 | s = "hello";
7 | c = test(4, 5);
8 | Print(c);
9 | Print(s);
10 | }
11 |
12 | static int test(int a, int b) {
13 | return a + b;
14 | }
15 | }
--------------------------------------------------------------------------------
/pa5/TestCases/S4/t5.decaf:
--------------------------------------------------------------------------------
1 | class Cow {
2 | int height;
3 | int weight;
4 |
5 | void Init(int w, int h) {
6 | weight = w;
7 | height = h;
8 | }
9 |
10 | void Moo() {
11 | Print ( this.height, " ", this.weight, "\n" );
12 | }
13 | }
14 |
15 | class Main {
16 | static void main() {
17 | class Cow betsy;
18 | betsy = new Cow();
19 | betsy.Init(100, 122);
20 | betsy.Moo();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/pa5/TestCases/S4/t6.decaf:
--------------------------------------------------------------------------------
1 | class Main {
2 |
3 | static int Binky(int a, int[] b, int[] c) {
4 | return b[c[0]];
5 | }
6 |
7 | static void main() {
8 | int[] c;
9 | int [][]d;
10 |
11 | d = new int[][5];
12 | d[0] = new int[12];
13 | c = new int[10];
14 | c[0] = 4 + 5 * 3 / 4 % 2;
15 | d[0][c[0]] = 55;
16 |
17 | Print(c[0], " ", 2 * Binky(100, d[0], c));
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/pa5/report.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa5/report.pdf
--------------------------------------------------------------------------------
/pa5/src/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/pa5/src/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 |
--------------------------------------------------------------------------------
/pa5/src/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | src
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/pa5/src/decaf/error/BadArrElementError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:array base type must be non-void type
7 | * PA2
8 | */
9 | public class BadArrElementError extends DecafError {
10 |
11 | public BadArrElementError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "array element type must be non-void type";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa5/src/decaf/error/BadInheritanceError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:illegal class inheritance (should be a cyclic)
7 | * PA2
8 | */
9 | public class BadInheritanceError extends DecafError {
10 |
11 | public BadInheritanceError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "illegal class inheritance (should be a cyclic)";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa5/src/decaf/error/BadLengthError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:'length' can only be applied to arrays
7 | * PA2
8 | */
9 | public class BadLengthError extends DecafError {
10 |
11 | public BadLengthError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "'length' can only be applied to arrays";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa5/src/decaf/error/BadNewArrayLength.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:new array length must be an integer
7 | * PA2
8 | */
9 | public class BadNewArrayLength extends DecafError {
10 |
11 | public BadNewArrayLength(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "new array length must be an integer";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa5/src/decaf/error/BadTestExpr.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:test expression must have bool type
7 | * PA2
8 | */
9 | public class BadTestExpr extends DecafError {
10 |
11 | public BadTestExpr(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "test expression must have bool type";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa5/src/decaf/error/BreakOutOfLoopError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:'break' is only allowed inside a loop
7 | * PA2
8 | */
9 | public class BreakOutOfLoopError extends DecafError {
10 |
11 | public BreakOutOfLoopError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "'break' is only allowed inside a loop";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa5/src/decaf/error/MsgError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * 仅供Parser的yyerror函数使用
7 | */
8 | public class MsgError extends DecafError {
9 |
10 | private String msg;
11 |
12 | public MsgError(Location location, String msg) {
13 | super(location);
14 | this.msg = msg;
15 | }
16 |
17 | @Override
18 | protected String getErrMsg() {
19 | return msg;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/pa5/src/decaf/error/NotArrayError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:[] can only be applied to arrays
7 | * PA2
8 | */
9 | public class NotArrayError extends DecafError {
10 |
11 | public NotArrayError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "[] can only be applied to arrays";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa5/src/decaf/error/NotClassError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * string is not a class type.
7 | */
8 | public class NotClassError extends DecafError {
9 |
10 | private String type;
11 |
12 | public NotClassError(String type, Location location) {
13 | super(location);
14 | this.type = type;
15 | }
16 |
17 | @Override
18 | protected String getErrMsg() {
19 | return type + " is not a class type";
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/pa5/src/decaf/error/SubNotIntError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:array subscript must be an integer
7 | * PA2
8 | */
9 | public class SubNotIntError extends DecafError {
10 |
11 | public SubNotIntError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "array subscript must be an integer";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa5/src/decaf/error/ThisInStaticFuncError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * can not use this in static function
7 | * PA2
8 | */
9 | public class ThisInStaticFuncError extends DecafError {
10 |
11 | public ThisInStaticFuncError(Location location) {
12 | super(location);
13 | }
14 |
15 | @Override
16 | protected String getErrMsg() {
17 | return "can not use this in static function";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/pa5/src/decaf/error/UnrecogCharError.java:
--------------------------------------------------------------------------------
1 | package decaf.error;
2 |
3 | import decaf.Location;
4 |
5 | /**
6 | * example:unrecognized char: '@'
7 | * PA1
8 | */
9 | public class UnrecogCharError extends DecafError {
10 |
11 | private char c;
12 |
13 | public UnrecogCharError(Location location, char c) {
14 | super(location);
15 | this.c = c;
16 | }
17 |
18 | @Override
19 | protected String getErrMsg() {
20 | return "unrecognized character '" + c + "'";
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/pa5/src/decaf/machdesc/Asm.java:
--------------------------------------------------------------------------------
1 | package decaf.machdesc;
2 |
3 | public abstract class Asm {
4 | public abstract String toString();
5 | }
6 |
--------------------------------------------------------------------------------
/pa5/src/decaf/machdesc/MachineDescription.java:
--------------------------------------------------------------------------------
1 | package decaf.machdesc;
2 |
3 | import java.io.PrintWriter;
4 | import java.util.List;
5 |
6 | import decaf.dataflow.FlowGraph;
7 | import decaf.tac.VTable;
8 |
9 | public interface MachineDescription {
10 |
11 | public void setOutputStream(PrintWriter pw);
12 |
13 | public void emitVTable(List vtables);
14 |
15 | public void emitAsm(List gs);
16 | }
17 |
--------------------------------------------------------------------------------
/pa5/src/decaf/machdesc/Register.java:
--------------------------------------------------------------------------------
1 | package decaf.machdesc;
2 |
3 | import decaf.tac.Temp;
4 |
5 | public abstract class Register {
6 |
7 | public Temp var;
8 |
9 | public abstract String toString();
10 | }
11 |
--------------------------------------------------------------------------------
/pa5/src/decaf/tac/Functy.java:
--------------------------------------------------------------------------------
1 | package decaf.tac;
2 |
3 | import decaf.symbol.Function;
4 |
5 | public class Functy {
6 | public Label label;
7 |
8 | public Tac paramMemo;
9 |
10 | public Tac head;
11 |
12 | public Tac tail;
13 |
14 | public Function sym;
15 | }
16 |
--------------------------------------------------------------------------------
/pa5/src/decaf/tac/TacTypes.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa5/src/decaf/tac/TacTypes.class
--------------------------------------------------------------------------------
/pa5/src/decaf/tac/VTable.java:
--------------------------------------------------------------------------------
1 | package decaf.tac;
2 |
3 | public class VTable {
4 | public String name;
5 |
6 | public VTable parent;
7 |
8 | public String className;
9 |
10 | public Label[] entries;
11 | }
12 |
--------------------------------------------------------------------------------
/pa5/tools/byacc/byacc.linux:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa5/tools/byacc/byacc.linux
--------------------------------------------------------------------------------
/pa5/tools/byacc/byacc.linux.amd64:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa5/tools/byacc/byacc.linux.amd64
--------------------------------------------------------------------------------
/pa5/tools/byacc/byacc.mac:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa5/tools/byacc/byacc.mac
--------------------------------------------------------------------------------
/pa5/tools/jflex/JFlex.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa5/tools/jflex/JFlex.jar
--------------------------------------------------------------------------------
/pa5/tools/spim/cygwin1.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa5/tools/spim/cygwin1.dll
--------------------------------------------------------------------------------
/pa5/tools/spim/spim.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa5/tools/spim/spim.exe
--------------------------------------------------------------------------------
/pa5/tools/spim/spim.linux:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa5/tools/spim/spim.linux
--------------------------------------------------------------------------------
/pa5/tools/spim/spim.mac:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Trinkle23897/decaf-complier/fe0ecc70692d73ea8d0fa75b8837f00245d27ddf/pa5/tools/spim/spim.mac
--------------------------------------------------------------------------------