2024-10-04 19:38:34 +02:00
|
|
|
type variable = string
|
|
|
|
|
|
|
|
|
|
type p_exp =
|
2025-01-27 16:28:23 +01:00
|
|
|
Main of variable * variable * c_exp
|
|
|
|
|
(* def main with input x output y as c *)
|
2024-10-04 19:38:34 +02:00
|
|
|
and c_exp =
|
|
|
|
|
Skip
|
2025-01-27 16:28:23 +01:00
|
|
|
| Assignment of variable * a_exp (* x := a *)
|
|
|
|
|
| Sequence of c_exp * c_exp (* c; c *)
|
|
|
|
|
| If of b_exp * c_exp * c_exp (* if b then c else c *)
|
|
|
|
|
| While of b_exp * c_exp (* while b do c *)
|
|
|
|
|
| For of c_exp * b_exp * c_exp * c_exp
|
|
|
|
|
(* for (c; b; c) do c *)
|
2024-10-04 19:38:34 +02:00
|
|
|
and b_exp =
|
2025-01-27 16:28:23 +01:00
|
|
|
Boolean of bool (* v *)
|
|
|
|
|
| BAnd of b_exp * b_exp (* b && b *)
|
|
|
|
|
| BOr of b_exp * b_exp (* b || b *)
|
|
|
|
|
| BNot of b_exp (* not b *)
|
|
|
|
|
| BCmp of a_exp * a_exp (* a == a *)
|
|
|
|
|
| BCmpLess of a_exp * a_exp (* a < a *)
|
|
|
|
|
| BCmpLessEq of a_exp * a_exp (* a <= a *)
|
|
|
|
|
| BCmpGreater of a_exp * a_exp (* a > a *)
|
|
|
|
|
| BCmpGreaterEq of a_exp * a_exp (* a >= a *)
|
2024-10-04 19:38:34 +02:00
|
|
|
and a_exp =
|
2025-01-27 16:28:23 +01:00
|
|
|
Variable of variable (* x *)
|
|
|
|
|
| Integer of int (* n *)
|
|
|
|
|
| Plus of a_exp * a_exp (* a + a *)
|
|
|
|
|
| Minus of a_exp * a_exp (* a - a *)
|
|
|
|
|
| Times of a_exp * a_exp (* a * a *)
|
|
|
|
|
| Division of a_exp * a_exp (* a / a *)
|
|
|
|
|
| Modulo of a_exp * a_exp (* a % a *)
|
|
|
|
|
| Power of a_exp * a_exp (* a ^ a *)
|
|
|
|
|
| PowerMod of a_exp * a_exp * a_exp (* a ^ a % a *)
|
|
|
|
|
| Rand of a_exp (* rand(0, a) *)
|
2024-10-04 19:38:34 +02:00
|
|
|
|
2024-12-03 17:18:42 +01:00
|
|
|
val pp_p_exp : Format.formatter -> p_exp -> unit
|
2024-10-04 19:38:34 +02:00
|
|
|
|
|
|
|
|
module VariableMap : Map.S with type key = variable
|
|
|
|
|
|
|
|
|
|
type memory = {
|
|
|
|
|
assignments: int VariableMap.t
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-16 15:40:00 +01:00
|
|
|
type error = [
|
|
|
|
|
`AbsentAssignment of string
|
|
|
|
|
| `DivisionByZero of string
|
|
|
|
|
]
|