From f40428251aef1a1890f1f3108404e659010cc559 Mon Sep 17 00:00:00 2001 From: elvis Date: Sun, 6 Oct 2024 17:05:19 +0200 Subject: [PATCH] Fib program, deleted commented exercise test code --- bin/main.ml | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/bin/main.ml b/bin/main.ml index 64ed0ff..ee3e4f3 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1,20 +1,3 @@ -(* - -open Lang.Exercises -(* let () = Printf.printf "%d\n" (eval_a_exp (Of_bool (Bval true))); *) - -let myfsa: fsa = {vertices = (StringMap.add "node 2" true (StringMap.singleton "node 1" false)); - edges = (StringMap.add "node 2" ("node 2", 'b') (StringMap.singleton "node 1" ("node 2", 'a'))); - state = "node 1"} - -let mystr = ['a'; 'b'; 'a'; 'b'] - -let ret = (Lang.Exercises.ex8 mystr myfsa);; -if ret -then print_endline "true" -else print_endline "false" - - *) open Lang.MiniImp (* -------------------------------------------------------------------------- *) @@ -137,3 +120,33 @@ let program = Printf.printf "%d\n" (reduce 10 program) ;; + +(* -------------------------------------------------------------------------- *) +(* rand program *) +let program = + Main + ("n", + "fnext", + (Sequence ( + Sequence ( + (Assignment ("fnow", Integer 0)), + (Assignment ("fnext", Integer 1)) + ), + (While ( + (BCmpGreater (Variable "n", Integer 1)), + (Sequence ( + (Sequence ( + (Assignment ("tmp", Plus (Variable "fnow", Variable "fnext"))), + (Assignment ("fnow", Variable "fnext")) + )), + (Sequence ( + (Assignment ("fnext", Variable "tmp")), + (Assignment ("n", Minus (Variable "n", Integer 1))) + )) + )))) + )) + ) +;; + +Printf.printf "%d\n" (reduce 48 program) +;;