Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open Tfbsrxast;;
- open Tfbsrxpp;;
- exception TypeError
- (*
- * If you would like typechecking to be enabled by your interpreter by default,
- * then change the following value to true. Whether or not typechecking is
- * enabled by default, you can explicitly enable it or disable it using
- * command-line arguments.
- *)
- let typecheck_default_enabled = true;;
- (*
- * Replace this with your typechecker code. Your code should not throw the
- * following exception; if you need to raise an exception, create your own
- * exception type here.
- *)
- let rec typecheck_aux gamma e = match e with
- | Var(ident) -> TInt
- | Function(ident, fbtype, expr) -> TInt
- | Letrec(ident, ident2, fbtype, expr1, fbtype2, expr2) -> TInt
- | Appl(expr1, expr2) -> TInt
- | Plus(expr1, expr2) ->
- if (typecheck_aux gamma expr1 = TInt && typecheck_aux gamma expr2 = TInt)
- then TInt else raise TypeError
- | Minus(expr1, expr2) ->
- if (typecheck_aux gamma expr1 = TInt && typecheck_aux gamma expr2 = TInt)
- then TInt else raise TypeError
- | Equal(expr1, expr2) ->
- if (typecheck_aux gamma expr1 = TInt && typecheck_aux gamma expr2 = TInt)
- then TInt else raise TypeError
- | And(expr1, expr2) -> TInt
- | Or(expr1, expr2) -> TInt
- | Not(expr1) -> TInt
- | If(expr1, expr2, expr3) -> TInt
- | Int(int) -> TInt
- | Bool(bool) -> TBool
- | Ref(expr) -> TInt
- | Set(expr1, expr2) -> TInt
- | Get(expr) -> TInt
- | Record(recordlist) -> TInt
- | Select(label, expr) -> TInt
- | Raise(exnid, fbtype, expr) -> TInt
- | Try(expr1, exnid, ident, fbtype, expr2) -> TInt
- | Cell(int) -> TInt
- ;;
- let typecheck e = typecheck_aux [] e;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement