aboutsummaryrefslogtreecommitdiff
path: root/lib/syntax/tree.mli
blob: ad052e9742c44addf03cc2d960c84f5f4d053de1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(** 
    Implementation for S.Analyzer for building a complete Ast.

    Used in the unit test in order to check if the grammar is interpreted as
    expected, not really usefull over a big qsp.
 *)

(** This module is the result of the evaluation. *)
module Ast : sig
  type pos = Lexing.position * Lexing.position

  type 'a variable = { pos : 'a; name : string; index : 'a expression option }
  [@@deriving eq, show]
  (** A variable, used both in an expression (reference) or in a statement
      (assignation) *)

  and 'a expression =
    | Integer of 'a * string
    | Literal of 'a * string
    | Ident of 'a variable
    | BinaryOp of 'a * T.boperator * 'a expression * 'a expression
    | Op of 'a * T.uoperator * 'a expression
    | Function of 'a * T.function_ * 'a expression list
  [@@deriving eq, show]

  and 'a condition = 'a * 'a expression * 'a statement list
  (** A condition in if or elseif statement *)

  and 'a statement =
    | If of {
        loc : 'a;
        then_ : 'a condition;
        elifs : 'a condition list;
        else_ : 'a statement list;
      }
    | Act of { loc : 'a; label : 'a expression; statements : 'a statement list }
    | Declaration of ('a * 'a variable * T.assignation_operator * 'a expression)
    | Expression of 'a expression
    | Comment of 'a
    | Call of 'a * T.keywords * 'a expression list
    | Location of 'a * string
  [@@deriving eq, show]
end

(** / **)

include
  S.Analyzer
    with type Expression.repr = Ast.pos Ast.expression
     and type Instruction.repr = Ast.pos Ast.statement
     and type Location.repr = Ast.pos * Ast.pos Ast.statement list