tree.mli 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 variable = { pos : 'a; name : string; index : 'a expression option }
  9. [@@deriving eq, show]
  10. (** A variable, used both in an expression (reference) or in a statement
  11. (assignation) *)
  12. and 'a expression =
  13. | Integer of 'a * string
  14. | Literal of 'a * string
  15. | Ident of 'a variable
  16. | BinaryOp of 'a * T.boperator * 'a expression * 'a expression
  17. | Op of 'a * T.uoperator * 'a expression
  18. | Function of 'a * T.function_ * 'a expression list
  19. [@@deriving eq, show]
  20. and 'a condition = 'a * 'a expression * 'a statement list
  21. (** A condition in if or elseif statement *)
  22. and 'a statement =
  23. | If of {
  24. loc : 'a;
  25. then_ : 'a condition;
  26. elifs : 'a condition list;
  27. else_ : 'a statement list;
  28. }
  29. | Act of { loc : 'a; label : 'a expression; statements : 'a statement list }
  30. | Declaration of ('a * 'a variable * T.assignation_operator * 'a expression)
  31. | Expression of 'a expression
  32. | Comment of 'a
  33. | Call of 'a * T.keywords * 'a expression list
  34. | Location of 'a * string
  35. [@@deriving eq, show]
  36. end
  37. include
  38. S.Analyzer
  39. with type Expression.t' = S.pos Ast.expression
  40. and type Instruction.t' = S.pos Ast.statement
  41. and type Location.t = S.pos * S.pos Ast.statement list