A MiniC++ (C++ subset) compiler for a course.

ast.mli 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. (* Syntaxe abstraite pour mini-C++ *)
  2. type loc = Lexing.position * Lexing.position
  3. (* Opérateurs binaires *)
  4. type operateur = Eq | Neq | Lt | Leq | Gt | Geq | Plus | Minus | Times | Div | Mod | And | Or
  5. (* Opérateurs unaires *)
  6. type uoperateur = EComm | Not | UMinus | UPlus | UTimes
  7. type incr = IncrL (* ++e *) | DecrL | IncrR | DecrR
  8. type ident = string
  9. type tident = string
  10. type qident = Ident of ident | Tident of tident * ident
  11. type ast_type = Void | Int | ASTTident of tident
  12. type var = VIdent of ident | VUTimes of var | VEComm of var
  13. type qvar = Qident of qident | QUTimes of qvar | QEComm of qvar
  14. type expr = EInt of int
  15. | EThis
  16. | ENull
  17. | EQident of qident
  18. | Dot of expr * ident
  19. | Assign of expr * expr
  20. | Apply of expr * (expr list)
  21. | Instance of tident * (expr list)
  22. | Incr of incr * expr
  23. | UOp of uoperateur * expr
  24. | Op of operateur * expr * expr
  25. type expr_string = Expr of expr | String of string
  26. type some_expr = expr option
  27. type some_assign = NoAssign | SAExpr of expr | SATident of tident * (expr list)
  28. type instruction_content = Nop
  29. | IExpr of expr
  30. | IVar of ast_type * var * some_assign
  31. | If of expr * instruction
  32. | IfElse of expr * instruction * instruction
  33. | While of expr * instruction
  34. | For of expr list * some_expr * expr list * instruction
  35. | IBloc of bloc
  36. | Cout of expr_string list
  37. | Return of some_expr
  38. and
  39. bloc_content = Bloc_content of instruction list
  40. and
  41. instruction = { instruction_content : instruction_content; instruction_loc : loc }
  42. and
  43. bloc = { bloc_content : bloc_content; bloc_loc : loc }
  44. type argument = ast_type * var
  45. type proto_ident = Qvar of ast_type * qvar | Type of tident | Herit of tident * tident
  46. type proto = {
  47. ident : proto_ident;
  48. args : argument list;
  49. proto_loc : loc
  50. }
  51. type decl_vars = { decl_vars_content : ast_type * (var list); decl_vars_loc : loc }
  52. type member = MVar of decl_vars | Proto of bool * proto
  53. type supers = (tident list) option
  54. type decl_class = { decl_class_content : ident * supers * (member list); decl_class_loc : loc }
  55. type fonction = { fonction_content : proto * bloc; fonction_loc : loc }
  56. type decl = DVar of decl_vars | Class of decl_class | Fonction of fonction
  57. type program = {
  58. includes : bool;
  59. program : decl list;
  60. program_loc : loc;
  61. }