ast.ml 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. | Array of ctype * node list
  9. | ArrayDepth of ctype * int
  10. and node =
  11. (* global *)
  12. | Program of node list * loc
  13. | Param of ctype * string * loc
  14. | Dim of string * loc
  15. | FunDec of ctype * string * node list * loc
  16. | FunDef of bool * ctype * string * node list * node * loc
  17. | GlobalDec of ctype * string * loc
  18. | GlobalDef of bool * ctype * string * node option * loc
  19. (* statements *)
  20. | VarDec of ctype * string * node option * loc
  21. | Assign of string * node list option * node * loc
  22. | Return of node * loc
  23. | If of node * node * loc
  24. | IfElse of node * node * node * loc
  25. | While of node * node * loc
  26. | DoWhile of node * node * loc
  27. | For of string * node * node * node * node * loc
  28. | Allocate of string * node list * node * loc
  29. | Expr of node
  30. | Block of node list
  31. (* expressions *)
  32. | BoolConst of bool * loc
  33. | IntConst of int * loc
  34. | FloatConst of float * loc
  35. | ArrayConst of node list * loc
  36. | Var of string * loc
  37. | Deref of string * node list * loc
  38. | Monop of operator * node * loc
  39. | Binop of operator * node * node * loc
  40. | TypeCast of ctype * node * loc
  41. | FunCall of string * node list * loc
  42. | Arg of node
  43. (* additional types for convenience in traversals *)
  44. | ArrayScalar of node
  45. | ArrayInit of node * ctype
  46. | Cond of node * node * node * loc
  47. | VarLet of node * ctype * int
  48. | VarUse of node * ctype * int
  49. | FunUse of node * node * int
  50. | DimDec of node
  51. | Type of node * ctype
  52. | DummyNode
  53. (* container for command-line arguments *)
  54. type args = {
  55. mutable infile : string option;
  56. mutable outfile : string option;
  57. mutable verbose : int;
  58. mutable cpp : bool;
  59. }
  60. (* intermediate representations between phases *)
  61. type intermediate =
  62. | Args of args
  63. | FileContent of string * string * args
  64. | Ast of node * args
  65. | Assembly of string list * args
  66. (* exceptions *)
  67. exception LocError of loc * string
  68. exception NodeError of node * string
  69. exception CompileError of string
  70. exception EmptyError
  71. exception InvalidNode
  72. exception InvalidInput of string