Module While_ast
Abstract syntax for the while language
module Var : sig ... endThe aexp type represents integer-valued expressions in the While language. It includes literal constants and has three basic binary operations: addition, subtraction, and multiplication. Each constructor takes one or two sub-expressions of type aexp, allowing arbitrarily nested arithmetic trees (for example, (x + 2) * (y - 1)).
The bexp boolean expression captures logical predicates used in conditionals and loops. It provides the Boolean constants (True, False), comparison operators over arithmetic expressions -- equality (Eq), less-than-or-equal (Le), and greater-than (Ge) -- as well as logical negation (Not) and conjunction (And).
With nesting, one can form complex expressions such as (v <= 5 && !(v == 0)).
type stmt = | Skip| Assign of Var.t * aexp| Seq of stmt * stmt| If of bexp * stmt * stmt| While of bexp * stmt(*Finally, the
*)stmttype defines the statements of the While language.Skipis a no operation;Assignupdates a variable from an arithmetic expression;Seqcomposes two commands sequentially;Ifchooses one of two branches based on a boolean test; andWhilerepeatedly executes its body while a condition holds.
val pp_aexp : Stdlib.Format.formatter -> aexp -> unitval pp_bexp : Stdlib.Format.formatter -> bexp -> unitval pp_stmt : Stdlib.Format.formatter -> stmt -> unit