Compleating assignment for interpreter, modified grammars, fixed tests
This commit is contained in:
@ -5,7 +5,7 @@ Random.self_init ()
|
||||
|
||||
let (let*) = Result.bind
|
||||
|
||||
let rec evaluate (mem: memory) (command: t_exp) : (permittedValues, error) result =
|
||||
let rec evaluate (mem: memory) (command: t_exp) : (permittedValues, [> error]) result =
|
||||
match command with
|
||||
Integer n -> Ok (IntegerPermitted n)
|
||||
| Boolean b -> Ok (BooleanPermitted b)
|
||||
@ -341,7 +341,7 @@ let rec evaluate (mem: memory) (command: t_exp) : (permittedValues, error) resul
|
||||
evaluate mem2 rest
|
||||
|
||||
|
||||
let reduce (program: t_exp) (iin : int) : (int, error) result =
|
||||
let reduce (program: t_exp) (iin : int) : (int, [> error]) result =
|
||||
let program' = (Application (program, (Integer iin))) in
|
||||
let mem : memory = {assignments = VariableMap.empty} in
|
||||
match (evaluate mem program') with
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
val reduce : Types.t_exp -> int -> (int, Types.error) result
|
||||
val evaluate : Types.memory -> Types.t_exp -> (Types.permittedValues, [> Types.error]) result
|
||||
|
||||
val evaluate : Types.memory -> Types.t_exp -> (Types.permittedValues, Types.error) result
|
||||
val reduce : Types.t_exp -> int -> (int, [> Types.error]) result
|
||||
|
||||
@ -5,7 +5,7 @@ Random.self_init ()
|
||||
|
||||
let (let*) = Result.bind
|
||||
|
||||
let rec evaluate_type (program: t_exp) (context: ftype VariableMap.t) : (ftype, error) result =
|
||||
let rec evaluate_type (program: t_exp) (context: ftype VariableMap.t) : (ftype, [> typechecking_error]) result =
|
||||
match program with
|
||||
Integer _ -> Ok IntegerType
|
||||
| Boolean _ -> Ok BooleanType
|
||||
@ -150,7 +150,7 @@ let rec evaluate_type (program: t_exp) (context: ftype VariableMap.t) : (ftype,
|
||||
| _ -> Error (`WrongTypeSpecification
|
||||
"Specification of function is not a function type.")
|
||||
|
||||
let typecheck (program: t_exp) : (ftype, error) result =
|
||||
let typecheck (program: t_exp) : (ftype, [> typechecking_error]) result =
|
||||
let* typeprogram = evaluate_type program VariableMap.empty in
|
||||
match typeprogram with
|
||||
FunctionType (IntegerType, IntegerType) -> (
|
||||
|
||||
@ -1 +1 @@
|
||||
val typecheck : Types.t_exp -> (Types.ftype, Types.error) result
|
||||
val typecheck : Types.t_exp -> (Types.ftype, [> Types.typechecking_error]) result
|
||||
|
||||
@ -53,9 +53,18 @@ type memory = {
|
||||
assignments: permittedValues VariableMap.t
|
||||
}
|
||||
|
||||
type error = [
|
||||
|
||||
type base_error = [
|
||||
`AbsentAssignment of string
|
||||
| `WrongType of string
|
||||
| `DivisionByZero of string
|
||||
]
|
||||
|
||||
type typechecking_error = [
|
||||
| base_error
|
||||
| `WrongTypeSpecification of string
|
||||
]
|
||||
|
||||
type error = [
|
||||
| base_error
|
||||
| `DivisionByZero of string
|
||||
]
|
||||
|
||||
@ -53,9 +53,18 @@ type memory = {
|
||||
assignments: permittedValues VariableMap.t
|
||||
}
|
||||
|
||||
type error = [
|
||||
|
||||
type base_error = [
|
||||
`AbsentAssignment of string
|
||||
| `WrongType of string
|
||||
| `DivisionByZero of string
|
||||
]
|
||||
|
||||
type typechecking_error = [
|
||||
| base_error
|
||||
| `WrongTypeSpecification of string
|
||||
]
|
||||
|
||||
type error = [
|
||||
| base_error
|
||||
| `DivisionByZero of string
|
||||
]
|
||||
|
||||
@ -13,4 +13,4 @@
|
||||
(modules Lexer Parser Types Semantics TypeChecker)
|
||||
(libraries utility menhirLib))
|
||||
|
||||
(include_subdirs qualified)
|
||||
(include_subdirs qualified)
|
||||
|
||||
Reference in New Issue
Block a user