| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- 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
- | 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
- | Expr of node
- (* Expressions *)
- | BoolConst of bool
- | IntConst of int
- | FloatConst of float
- | ArrayConst of node list
- | 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 CompileError of string
- (*
- * Template for node matching follows below.
- *
- * let rec visit = function
- * | Program (decls) ->
- * | Param (ctype, name) ->
- * | FunDec (ret_type, name, params) ->
- * | FunDef (export, ret_type, name, params, body) ->
- * | GlobalDec (ctype, name) ->
- * | GlobalDef (export, ctype, name, None) ->
- * | GlobalDef (export, ctype, name, Some init) ->
- *
- * | VarDec (ctype, name, None) ->
- * | VarDec (ctype, name, Some init) ->
- * | Assign (name, value) ->
- * | Return (value) ->
- * | If (cond, body) ->
- * | IfElse (cond, true_body, false_body) ->
- * | While (cond, body) ->
- * | DoWhile (cond, body) ->
- * | For (counter, start, stop, step, body) ->
- * | Expr (value) ->
- *
- * | BoolConst (value) ->
- * | IntConst (value) ->
- * | FloatConst (value) ->
- * | Var (name) ->
- * | Monop (op, value) ->
- * | Binop (op, left, right) ->
- * | Cond (cond, true_expr, false_expr) ->
- * | TypeCast (ctype, value) ->
- * | FunCall (name, args) ->
- *
- * | node -> transform visit node
- *
- *)
|