tree.mli 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. (**
  2. Implementation for S.Analyzer for building a complete Ast.
  3. Used in the unit test in order to check if the grammar is interpreted as
  4. expected, not really usefull over a big qsp.
  5. *)
  6. (** This module is the result of the evaluation. *)
  7. module Ast : sig
  8. type 'a literal = 'a T.literal = Text of string | Expression of 'a
  9. [@@deriving eq, show]
  10. type 'a variable = { pos : 'a; name : string; index : 'a expression option }
  11. [@@deriving eq, show]
  12. (** A variable, used both in an expression (reference) or in a statement
  13. (assignation) *)
  14. and 'a expression =
  15. | Integer of 'a * string
  16. | Literal of 'a * 'a expression literal list
  17. | Ident of 'a variable
  18. | BinaryOp of 'a * T.boperator * 'a expression * 'a expression
  19. | Op of 'a * T.uoperator * 'a expression
  20. | Function of 'a * T.function_ * 'a expression list
  21. [@@deriving eq, show]
  22. and 'a condition = 'a * 'a expression * 'a statement list
  23. (** A condition in if or elseif statement *)
  24. and 'a statement =
  25. | If of {
  26. loc : 'a;
  27. then_ : 'a condition;
  28. elifs : 'a condition list;
  29. else_ : 'a statement list;
  30. }
  31. | Act of { loc : 'a; label : 'a expression; statements : 'a statement list }
  32. | Declaration of ('a * 'a variable * T.assignation_operator * 'a expression)
  33. | Expression of 'a expression
  34. | Comment of 'a
  35. | Call of 'a * T.keywords * 'a expression list
  36. | Location of 'a * string
  37. [@@deriving eq, show]
  38. end
  39. include
  40. S.Analyzer
  41. with type Expression.t' = S.pos Ast.expression
  42. and type Instruction.t' = S.pos Ast.statement
  43. and type Location.t = S.pos * S.pos Ast.statement list
  44. and type context = unit