3 Commits 73ce7caccb ... af19870b14

Autor SHA1 Mensaje Fecha
  Chimrod af19870b14 Updated the tests hace 5 meses
  Chimrod 60ed612d20 Implemented the For in the Tree module hace 5 meses
  Chimrod 847957fb0b Update hace 5 meses
Se han modificado 7 ficheros con 115 adiciones y 0 borrados
  1. 11 0
      lib/syntax/S.ml
  2. 15 0
      lib/syntax/dead_end.ml
  3. 19 0
      lib/syntax/dup_test.ml
  4. 16 0
      lib/syntax/nested_strings.ml
  5. 27 0
      lib/syntax/tree.ml
  6. 8 0
      lib/syntax/tree.mli
  7. 19 0
      lib/syntax/type_of.ml

+ 11 - 0
lib/syntax/S.ml

@@ -99,6 +99,17 @@ module type Instruction = sig
     step:expression option ->
     t list ->
     t
+  (** 
+
+	for j = 1 to 5 step var:
+		stri = 1 & strmax = 3
+		for i = stri to strmax:
+            …
+		end
+	end
+
+
+   *)
 end
 
 module type Location = sig

+ 15 - 0
lib/syntax/dead_end.ml

@@ -145,6 +145,21 @@ module Instruction = struct
       Expression.t' ->
       t =
    fun _ _ _ _ -> default
+
+  let for_ :
+      S.pos ->
+      (S.pos, Expression.t') S.variable ->
+      start:Expression.t' ->
+      to_:Expression.t' ->
+      step:Expression.t' option ->
+      t list ->
+      t =
+   fun pos variable ~start ~to_ ~step statements ->
+    ignore variable;
+    ignore start;
+    ignore to_;
+    ignore step;
+    check_block pos statements
 end
 
 module Location = struct

+ 19 - 0
lib/syntax/dup_test.ml

@@ -135,6 +135,25 @@ module Instruction = struct
 
   let call : S.pos -> T.keywords -> Expression.t' list -> t =
    fun _ _ _ -> default
+
+  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 ->
+    ignore variable;
+    ignore start;
+    ignore to_;
+    ignore step;
+    List.fold_left ~init:default statements ~f:(fun state ex ->
+        {
+          predicates = [];
+          duplicates = List.rev_append ex.duplicates state.duplicates;
+        })
 end
 
 module Location = struct

+ 16 - 0
lib/syntax/nested_strings.ml

@@ -141,6 +141,22 @@ struct
     match variable.index with
     | None -> expression
     | Some v -> List.rev_append v expression
+
+  let for_ :
+      S.pos ->
+      (S.pos, Expression.t') S.variable ->
+      start:Expression.t' ->
+      to_:Expression.t' ->
+      step:Expression.t' option ->
+      t list ->
+      t =
+   fun pos variable ~start ~to_ ~step statements ->
+    ignore variable;
+    ignore start;
+    ignore to_;
+    ignore step;
+    ignore pos;
+    List.concat statements
 end
 
 module Location = struct

+ 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
 

+ 19 - 0
lib/syntax/type_of.ml

@@ -479,6 +479,25 @@ module Instruction = struct
             Helper.compare_args ~strict:true ~level:Report.Warn pos expected
               [ op1; op2 ] report
         | reports -> reports @ report)
+
+  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 ->
+    ignore variable;
+    ignore start;
+    ignore to_;
+    ignore step;
+    (* TODO ensure all the variable are INT *)
+    let report = [] in
+    List.fold_left statements ~init:report ~f:(fun acc a ->
+        let report = a in
+        (List.rev_append report) acc)
 end
 
 module Location = struct