| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- type loc = string * int * int * int * int
- type monop = Neg | Not
- type binop = Add | Sub | Mul | Div | Mod
- | Eq | Ne | Lt | Le | Gt | Ge
- | And | Or
- type ctype = Void | Bool | Int | Float
- | ArrayDec of ctype * string list
- | ArrayDef of ctype * node list
- and node =
- (* global *)
- | Program of node list * loc
- | Param of ctype * string
- | FunDec of ctype * string * node list
- | FunDef of bool * ctype * string * node list * node list
- | GlobalDec of ctype * string
- | GlobalDef of bool * ctype * string * node option
- (* statements *)
- | VarDec of ctype * string * node option
- | Assign of string * node
- | Return of node
- | If of node * node list
- | IfElse of node * node list * node list
- | While of node * node list
- | DoWhile of node * node list
- | For of string * node * node * node * node list
- | Allocate of string * node list
- | Expr of node
- | Statements of node list
- (* expressions *)
- | BoolConst of bool
- | IntConst of int
- | FloatConst of float
- | ArrayConst of node list
- | ArrayScalar of node
- | Var of string
- | Deref of string * node list
- | Monop of monop * node
- | Binop of binop * node * node
- | Cond of node * node * node
- | TypeCast of ctype * node
- | FunCall of string * node list
- (* intermediate representations between phases *)
- type repr =
- | Inputfile of string option * int (* filename, verbose *)
- | Node of node * int (* ast, verbose *)
- | Assembly of string list * int (* instructions *)
- exception LocError of string * loc
- exception CompileError of string
- (*
- * Template for node matching follows below.
- *
- * let rec visit = function
- * | Program (decls, loc) ->
- * | Param (ctype, name, loc) ->
- * | FunDec (ret_type, name, params, loc) ->
- * | FunDef (export, ret_type, name, params, body, loc) ->
- * | GlobalDec (ctype, name, loc) ->
- * | GlobalDef (export, ctype, name, None, loc) ->
- * | GlobalDef (export, ctype, name, Some init, loc) ->
- *
- * | VarDec (ctype, name, None, loc) ->
- * | VarDec (ctype, name, Some init, loc) ->
- * | Assign (name, value, loc) ->
- * | Return (value, loc) ->
- * | If (cond, body, loc) ->
- * | IfElse (cond, true_body, false_body, loc) ->
- * | While (cond, body, loc) ->
- * | DoWhile (cond, body, loc) ->
- * | For (counter, start, stop, step, body, loc) ->
- * | Expr (value, loc) ->
- *
- * | BoolConst (value, loc) ->
- * | IntConst (value, loc) ->
- * | FloatConst (value, loc) ->
- * | Var (name, loc) ->
- * | Monop (op, value, loc) ->
- * | Binop (op, left, right, loc) ->
- * | Cond (cond, true_expr, false_expr, loc) ->
- * | TypeCast (ctype, value, loc) ->
- * | FunCall (name, args, loc) ->
- *
- * | Statements (stats, loc) ->
- *
- * | node -> transform visit node
- *
- *)
|