diff options
author | Alex AUVOLAT <alex.auvolat@ens.fr> | 2013-11-16 10:57:43 +0100 |
---|---|---|
committer | Alex AUVOLAT <alex.auvolat@ens.fr> | 2013-11-16 10:57:43 +0100 |
commit | deb235f3045138908339cec56f0ce34dbb4e936b (patch) | |
tree | 8adc5dbee6113c25c2c0588a6d3c2fb20db58ad8 /src/ast.ml | |
parent | 5dacc48b53568f673b03de794a9a13f7a5c11b0f (diff) | |
download | LPC-Projet-deb235f3045138908339cec56f0ce34dbb4e936b.tar.gz LPC-Projet-deb235f3045138908339cec56f0ce34dbb4e936b.zip |
Started parser anew
Diffstat (limited to 'src/ast.ml')
-rw-r--r-- | src/ast.ml | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/ast.ml b/src/ast.ml new file mode 100644 index 0000000..0a346e5 --- /dev/null +++ b/src/ast.ml @@ -0,0 +1,65 @@ +(* + Langages de Programmation et Compilation (J.-C. Filliatre) + 2013-2014 + Alex AUVOLAT + + AST for Mini-C++ +*) + +module Sset = Set.Make(String) +let type_names = ref Sset.empty + +type ident = string +type tident = string + +type binop = + | Equal | NotEqual + | Lt | Le | Gt | Ge + | Add | Sub | Mul | Div | Modulo + | Land | Lor + +type unop = + | PreIncr | PostIncr | PreDecr | PostDecr + | Ref | Deref + | Not + | Minus | Plus + +type var_type = + | TVoid + | TInt + | TPtr of var_type + | TRef of var_type + | TIdent of tident + +type expression = + | EInt of int + | EBool of bool + | ENull + | EIdent of ident + | EAssign of expression * expression + | ECall of expression * expression list + | EUnary of unop * expression + | EBinary of expression * binop * expression + +type statement = + | SEmpty + | SExpr of expression + | SIf of expression * statement * statement + | SWhile of expression * statement + | SFor of expression list * expression option * expression list * statement + | SBlock of block + | SReturn of expression option + | SDeclare of ident * var_type * expression option +and block = statement list + +type proto = { + p_name : ident; + p_ret_type : var_type; + p_args : (ident * var_type) list; +} + +type declaration = + | DGlobal of (ident * var_type) + | DFunction of (proto * block) + +type program = declaration list |