Module Whilelib.Cinterpreter
Given the while syntax presented in While_ast, in this module Cinterpreter provides the concrete interpreter for the AST containing expressions and commands. Towards this goal, we utlize Var module to refer to named storage locations and then define each concrete state using State as a map from each Var.t to an integer Z.t.
With concrete states defined, the concrete interpreter Interp module provides functions to interpret arithmetic expressions, boolean expressions, and commands.
This is detailed in the While tutorial in chapter1.
module State : sig ... endThe module State is a map that maps each variable to a concrete integer Z.t
val initial_state : unit -> State.tval interp_aexp : While_ast.aexp -> State.t -> Z.tThe arithmetic‐expression interpreter. It is a straightforward recursive traversal of the aexp AST that computes an integer result in a given program state.
val interp_bexp : While_ast.bexp -> State.t -> boolThe boolean-expression interpreter is also recursive traversal of the bexp boolean expression AST that outputs a boolean value in a given program state.
val interp_stmt : While_ast.stmt -> State.t -> State.tIn the While language, each statement represents a state‐transforming operation on the program’s state. We capture these transformations in a single recursive function, which takes a stmt and an initial state and returns the updated state after executing that statement