spooky/lib/ast.mli

71 lines
1.2 KiB
OCaml
Raw Permalink Normal View History

2026-04-29 15:25:15 +00:00
type typ =
| TInt
| TBool
| TVoid
| TStruct of string
| TArray of typ
2026-04-29 18:56:41 +00:00
| TComptime of typ
| TCombo of typ * typ
2026-04-29 15:25:15 +00:00
type binop =
| Add
| Sub
| Mul
| Div
| Mod
| And
| Or
| Eq
| Ne
| Lt
| Le
| Gt
| Ge
type unop = Neg | Not
type expr =
| IntLit of int
| BoolLit of bool
| Var of string
| Binop of binop * expr * expr
| Unop of unop * expr
| Assign of expr * expr
| Call of expr * expr list
| ArrayGet of expr * expr
| StructGet of expr * string
type stmt =
2026-04-29 18:56:41 +00:00
| VarDecl of bool * string * typ option * expr option
2026-04-29 15:25:15 +00:00
| Expr of expr
| If of expr * stmt list * stmt list
| ForEach of typ * string * expr * stmt list
| Return of expr option
| Block of stmt list
type func = {
name : string;
2026-04-29 18:56:41 +00:00
params : (string * typ) list;
2026-04-29 15:25:15 +00:00
ret : typ;
body : stmt list;
}
type struct_def = {
sname : string;
fields : (typ * string) list;
}
type top =
| TopStruct of struct_def
| TopFunc of func
2026-04-29 18:56:41 +00:00
| TopGlobalVar of bool * string * typ option * expr option
2026-04-29 15:25:15 +00:00
type program = top list
val string_of_typ : typ -> string
2026-04-29 15:50:03 +00:00
val string_of_binop : binop -> string
val string_of_unop : unop -> string
val string_of_expr : expr -> string
2026-04-29 15:28:57 +00:00
val string_of_program : program -> string
2026-04-29 15:50:03 +00:00
val equal_typ : typ -> typ -> bool