ast.ml 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. type loc = string * int * int * int * int
  2. let noloc = ("", 0, 0, 0, 0)
  3. type operator = Neg | Not
  4. | Add | Sub | Mul | Div | Mod
  5. | Eq | Ne | Lt | Le | Gt | Ge
  6. | And | Or
  7. type ctype = Void | Bool | Int | Float
  8. | ArrayDec of ctype * node list
  9. | ArrayDef of ctype * node list
  10. | ArraySpec of ctype * int
  11. and node =
  12. (* global *)
  13. | Program of node list * loc
  14. | Param of ctype * string * loc
  15. | Dim of string * loc
  16. | FunDec of ctype * string * node list * loc
  17. | FunDef of bool * ctype * string * node list * node * loc
  18. | GlobalDec of ctype * string * loc
  19. | GlobalDef of bool * ctype * string * node option * loc
  20. (* statements *)
  21. | VarDec of ctype * string * node option * loc
  22. | Assign of string * node list option * node * loc
  23. | Return of node * loc
  24. | If of node * node * loc
  25. | IfElse of node * node * node * loc
  26. | While of node * node * loc
  27. | DoWhile of node * node * loc
  28. | For of string * node * node * node * node * loc
  29. | Allocate of string * node list * node * loc
  30. | Expr of node
  31. | Block of node list
  32. (* expressions *)
  33. | BoolConst of bool * loc
  34. | IntConst of int * loc
  35. | FloatConst of float * loc
  36. | ArrayConst of node list * loc
  37. | Var of string * loc
  38. | Deref of string * node list * loc
  39. | Monop of operator * node * loc
  40. | Binop of operator * node * node * loc
  41. | TypeCast of ctype * node * loc
  42. | FunCall of string * node list * loc
  43. | Arg of node
  44. (* additional types for convenience in traversals *)
  45. | ArrayScalar of node
  46. | ArrayInit of node * ctype
  47. | Cond of node * node * node * loc
  48. | VarLet of node * ctype * int
  49. | VarUse of node * ctype * int
  50. | FunUse of node * node * int
  51. | DimDec of node
  52. | Type of node * ctype
  53. | DummyNode
  54. (* container for command-line arguments *)
  55. type args = {
  56. mutable infile : string option;
  57. mutable outfile : string option;
  58. mutable verbose : int;
  59. mutable cpp : bool;
  60. }
  61. (* intermediate representations between phases *)
  62. type intermediate =
  63. | Args of args
  64. | FileContent of string * string * args
  65. | Ast of node * args
  66. | Assembly of string list * args
  67. (* exceptions *)
  68. exception LocError of loc * string
  69. exception NodeError of node * string
  70. exception CompileError of string
  71. exception EmptyError
  72. exception InvalidNode
  73. exception InvalidInput of string