Преглед на файлове

Implemented the For in the Tree module

Chimrod преди 5 месеца
родител
ревизия
60ed612d20
променени са 2 файла, в които са добавени 35 реда и са изтрити 0 реда
  1. 27 0
      lib/syntax/tree.ml
  2. 8 0
      lib/syntax/tree.mli

+ 27 - 0
lib/syntax/tree.ml

@@ -41,6 +41,14 @@ module Ast = struct
     | Comment of 'a
     | Call of 'a * T.keywords * 'a expression list
     | Location of 'a * string
+    | For of {
+        loc : 'a;
+        variable : 'a variable;
+        start : 'a expression;
+        to_ : 'a expression;
+        step : 'a expression option;
+        statements : 'a statement list;
+      }
   [@@deriving eq, show]
 end
 
@@ -156,6 +164,25 @@ module Instruction :
    fun pos_loc { pos; name; index } op expr ->
     (*let index = Option.map (fun i -> fst @@ Expression.observe (i [])) index*)
     Ast.Declaration (pos_loc, { pos; name; index }, op, expr)
+
+  let for_ :
+      S.pos ->
+      (S.pos, Expression.t') S.variable ->
+      start:Expression.t' ->
+      to_:Expression.t' ->
+      step:Expression.t' option ->
+      t list ->
+      t =
+   fun loc variable ~start ~to_ ~step statements ->
+    let variable =
+      Ast.
+        {
+          pos = variable.S.pos;
+          name = variable.S.name;
+          index = variable.S.index;
+        }
+    in
+    Ast.For { loc; variable; start; to_; step; statements }
 end
 
 module Location = struct

+ 8 - 0
lib/syntax/tree.mli

@@ -40,6 +40,14 @@ module Ast : sig
     | Comment of 'a
     | Call of 'a * T.keywords * 'a expression list
     | Location of 'a * string
+    | For of {
+        loc : 'a;
+        variable : 'a variable;
+        start : 'a expression;
+        to_ : 'a expression;
+        step : 'a expression option;
+        statements : 'a statement list;
+      }
   [@@deriving eq, show]
 end