type loc = string * int * int * int * int let noloc = ("", 0, 0, 0, 0) type operator = Neg | Not | Add | Sub | Mul | Div | Mod | Eq | Ne | Lt | Le | Gt | Ge | And | Or type ctype = Void | Bool | Int | Float | Array of ctype * node list | ArrayDepth of ctype * int and node = (* global *) | Program of node list * loc | Param of ctype * string * loc | Dim of string * loc | FunDec of ctype * string * node list * loc | FunDef of bool * ctype * string * node list * node * loc | GlobalDec of ctype * string * loc | GlobalDef of bool * ctype * string * node option * loc (* statements *) | VarDec of ctype * string * node option * loc | Assign of string * node list option * node * loc | Return of node * loc | If of node * node * loc | IfElse of node * node * node * loc | While of node * node * loc | DoWhile of node * node * loc | For of string * node * node * node * node * loc | Allocate of string * node list * node * loc | Expr of node | Block of node list (* expressions *) | BoolConst of bool * loc | IntConst of int * loc | FloatConst of float * loc | ArrayConst of node list * loc | Var of string * loc | Deref of string * node list * loc | Monop of operator * node * loc | Binop of operator * node * node * loc | TypeCast of ctype * node * loc | FunCall of string * node list * loc | Arg of node (* additional types for convenience in traversals *) | ArrayScalar of node | ArrayInit of node * ctype | Cond of node * node * node * loc | VarLet of node * ctype * int | VarUse of node * ctype * int | FunUse of node * node * int | DimDec of node | Type of node * ctype | DummyNode (* container for command-line arguments *) type args_record = { mutable infile : string option; mutable outfile : string option; mutable verbose : int; mutable cpp : bool; } (* Default config *) let verbosity_default = 2 (* TODO: set to 1 when done with debugging *) let verbosity_debug = 3 (* Commandline args are stored in a global struct * (yes, it IS dirty, but I'd rather have this than having to pass [args] around * everywhere) *) let args = { infile = None; outfile = None; verbose = verbosity_default; cpp = true; } (* intermediate representations between phases *) type intermediate = | Empty | FileContent of string * string | Ast of node | Assembly of string list (* exceptions *) exception LocError of loc * string exception NodeError of node * string exception CompileError of string exception EmptyError exception InvalidNode exception InvalidInput of string