53 lines
802 B
OCaml
53 lines
802 B
OCaml
type binop =
|
|
| Add
|
|
| Sub
|
|
| Mul
|
|
| Div
|
|
| Eq
|
|
| Ne
|
|
| Lt
|
|
| Le
|
|
| Gt
|
|
| Ge
|
|
| And
|
|
| Or
|
|
|
|
type expr = {
|
|
e : expr_desc;
|
|
espan : Location.span;
|
|
}
|
|
|
|
and expr_desc =
|
|
| EInt of int
|
|
| EBool of bool
|
|
| EString of string
|
|
| EUnit
|
|
| EVar of string
|
|
| ELet of string * expr * expr
|
|
| ELambda of string * expr
|
|
| EApp of expr * expr
|
|
| EIf of expr * expr * expr
|
|
| EBinop of binop * expr * expr
|
|
| ENeg of expr
|
|
| ETuple of expr list
|
|
| ERecord of (string * expr) list
|
|
| EField of expr * string
|
|
|
|
let make e espan = { e = e; espan = espan }
|
|
|
|
let binop_name = function
|
|
| Add -> "+"
|
|
| Sub -> "-"
|
|
| Mul -> "*"
|
|
| Div -> "/"
|
|
| Eq -> "="
|
|
| Ne -> "<>"
|
|
| Lt -> "<"
|
|
| Le -> "<="
|
|
| Gt -> ">"
|
|
| Ge -> ">="
|
|
| And -> "&&"
|
|
| Or -> "||"
|
|
|
|
let string_of_binop = binop_name
|