Forráskód Böngészése

Implemented the For in the Tree module

Chimrod 5 hónapja
szülő
commit
60ed612d20
2 módosított fájl, 35 hozzáadás és 0 törlés
  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