Commits

Maxime Buquet  committed 97beb50

Parser done

  • Participants
  • Parent commits 2cfdf41

Comments (0)

Files changed (1)

                 else
                     eval env (Loop loop :: tl)
     | [] -> env
+
+let to_list str =
+    let stop = String.length str in
+    let rec to_list = function
+        | i when i = stop -> []
+        | i -> str.[i] :: to_list (i + 1)
+    in
+        to_list 0
+
+let parse exp =
+    let (||) exp (l1, l2) = (exp :: l1, l2) in
+    let rec sub = function
+        | '+' :: tl -> (||) Plus (sub tl)
+        | '-' :: tl -> (||) Minus (sub tl)
+        | '>' :: tl -> (||) Right (sub tl)
+        | '<' :: tl -> (||) Left (sub tl)
+        | '.' :: tl -> (||) Print (sub tl)
+        | ',' :: tl -> (||) Read (sub tl)
+        | '[' :: tl -> let loop, tl = (sub tl) in
+                           (||) (Loop loop) (sub tl)
+        | ']' :: tl -> ([], tl)
+        | _ :: tl -> sub tl
+        | [] -> ([], [])
+    in
+        fst (sub exp)