aboutsummaryrefslogtreecommitdiff
path: root/syntax/tree.mli
diff options
context:
space:
mode:
authorChimrod <>2023-09-22 14:12:14 +0200
committerChimrod <>2023-09-22 14:12:14 +0200
commitbd9d82035b21c8b0695c18208827c184785398af (patch)
tree5c6b03d6a82155b867e5ec2ceecd260b8868579a /syntax/tree.mli
first commit
Diffstat (limited to 'syntax/tree.mli')
-rw-r--r--syntax/tree.mli51
1 files changed, 51 insertions, 0 deletions
diff --git a/syntax/tree.mli b/syntax/tree.mli
new file mode 100644
index 0000000..ca5a639
--- /dev/null
+++ b/syntax/tree.mli
@@ -0,0 +1,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 * string * '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