Module Mini_ml_lib.Ast

type name =
  1. | Wildcard
    (*

    Wildcard name _

    *)
  2. | Real of string
    (*

    Real name (any string)

    *)

Type for name of variable, used in variable, abstraction, let, letrec

type unary_operation =
  1. | Neg
    (*

    Integer negation -x

    *)
  2. | Not
    (*

    Logical inversion !x

    *)

Type for any unary operation in language

type binary_operation =
  1. | Add
    (*

    Addition a + b

    *)
  2. | Sub
    (*

    Subtraction a - b

    *)
  3. | Mul
    (*

    Multiplication a * b

    *)
  4. | Div
    (*

    Division a / b

    *)
  5. | Mod
    (*

    Remainder a mod b

    *)
  6. | And
    (*

    a && b

    *)
  7. | Or
    (*

    a || b

    *)
  8. | Equal
    (*

    Comparing on equal a = b

    *)
  9. | NotEqual
    (*

    Comparing on not eqaul a <> b

    *)
  10. | Less
    (*

    Compare on less a < b

    *)
  11. | LessEqual
    (*

    Compare on less or equal a <= b

    *)
  12. | Greater
    (*

    Compare on greater a > b

    *)
  13. | GreaterEqual
    (*

    Compare on greater or equal a >= b

    *)

Type for any binary operation in language

type let_mnemonic =
  1. | Let
    (*

    Common let

    *)
  2. | LetRec
    (*

    Recursive let rec

    *)

Type for indicating recursive let expression

type t =
  1. | Unit
    (*

    Unit literal

    *)
  2. | Int of int
    (*

    Integer literal 42

    *)
  3. | Bool of bool
    (*

    Boolean literal true

    *)
  4. | Var of name
    (*

    Variable x

    *)
  5. | Tuple of t * t * t list
    (*

    Tuple (x, y, ..., z)

    *)
  6. | UnaryOp of unary_operation * t
    (*

    Unary operation ..y

    *)
  7. | BinaryOp of binary_operation * t * t
    (*

    Binary operation x .. y

    *)
  8. | IfThenElse of t * t * t
    (*

    If-then-else expression if ... then ... else ...

    *)
  9. | LetExpr of let_mnemonic * name * t * t
    (*

    Let expression let x = ... in ...

    *)
  10. | Abstraction of name * t
    (*

    Lambda abstraction fun x -> ...

    *)
  11. | Application of t * t
    (*

    Application (f x)

    *)
  12. | Exception of string * t
    (*

    Exception declaration let exception E1 in ...

    *)
  13. | TryWith of t * string * t
    (*

    Try with statement try (...) with ... -> (...)

    *)
  14. | Raise of t
    (*

    Fail with statement raise ...

    *)

Type for abstract-syntax tree node

val show_ast_verbose : t -> string

Shows AST in verbose format

val show_ast : t -> string

Shows AST in human readable format

val show_name : name -> string

Shows name of any named entity in AST