Compleating assignment for interpreter, modified grammars, fixed tests

This commit is contained in:
elvis
2024-11-16 15:40:00 +01:00
parent 40055899c9
commit 9e599cc018
24 changed files with 593 additions and 1238 deletions

View File

@ -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

View File

@ -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

View File

@ -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) -> (

View File

@ -1 +1 @@
val typecheck : Types.t_exp -> (Types.ftype, Types.error) result
val typecheck : Types.t_exp -> (Types.ftype, [> Types.typechecking_error]) result

View File

@ -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
]

View File

@ -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
]

View File

@ -13,4 +13,4 @@
(modules Lexer Parser Types Semantics TypeChecker)
(libraries utility menhirLib))
(include_subdirs qualified)
(include_subdirs qualified)