Commits

Louis Cadet committed 6fe9502

modified: main.ml
deleted: CodesFournis.tar.bz2
deleted: CodesFournis/ast.mli
deleted: CodesFournis/ex01.bl
deleted: CodesFournis/ex02.bl
deleted: CodesFournis/ex03.bl
deleted: CodesFournis/lexer.ml
deleted: CodesFournis/lexer.mll
deleted: CodesFournis/parser.ml
deleted: CodesFournis/parser.mli
deleted: CodesFournis/parser.mly
deleted: CodesFournis/vrac.bl

Comments (0)

Files changed (1)

     end
 
 
-let rec evalstat body hash hash2 =
-    let rec evalexpr hash hash2 = function
+let rec evalstat body hash =
+    let rec evalexpr hash = function
     | Int a -> a
     | Var s -> Hashtbl.find hash s
     | BinOp (a,s,b) -> (match s with
-       |"+" -> (evalexpr hash hash2 a) + (evalexpr hash hash2 b)
-       |"-" -> (evalexpr hash hash2 a) - (evalexpr hash hash2 b)
-       |"*" -> (evalexpr hash hash2 a) * (evalexpr hash hash2 b)
-       |"/" -> (evalexpr hash hash2 a) / (evalexpr hash hash2 b)
-       |">" -> if ((evalexpr hash hash2 a) > (evalexpr hash hash2 b)) then 1 else 0
-       |"<" -> if ((evalexpr hash hash2 a) < (evalexpr hash hash2 b)) then 1 else 0
-       |">=" -> if ((evalexpr hash hash2 a) >= (evalexpr hash hash2 b)) then 1 else 0
-       |"<=" -> if ((evalexpr hash hash2 a) <= (evalexpr hash hash2 b)) then 1 else 0
-       |"==" -> if ((evalexpr hash hash2 a) == (evalexpr hash hash2 b)) then 1 else 0
-       |"||" -> (evalexpr hash hash2 a) + (evalexpr hash hash2 b)
-       |"&&" -> (evalexpr hash hash2 a) * (evalexpr hash hash2 b)
-       |"!" -> if ((evalexpr hash hash2 a) <> (evalexpr hash hash2 b)) then 1 else 0)
+       |"+" -> (evalexpr hash a) + (evalexpr hash b)
+       |"-" -> (evalexpr hash a) - (evalexpr hash b)
+       |"*" -> (evalexpr hash a) * (evalexpr hash b)
+       |"/" -> (evalexpr hash a) / (evalexpr hash b)
+       |">" -> if ((evalexpr hash a) > (evalexpr hash b)) then 1 else 0
+       |"<" -> if ((evalexpr hash a) < (evalexpr hash b)) then 1 else 0
+       |">=" -> if ((evalexpr hash a) >= (evalexpr hash b)) then 1 else 0
+       |"<=" -> if ((evalexpr hash a) <= (evalexpr hash b)) then 1 else 0
+       |"==" -> if ((evalexpr hash a) == (evalexpr hash b)) then 1 else 0
+       |"||" -> (evalexpr hash a) + (evalexpr hash b)
+       |"&&" -> (evalexpr hash a) * (evalexpr hash b)
+       |"!" -> if ((evalexpr hash a) <> (evalexpr hash b)) then 1 else 0)
     | UniOp (s,a) -> (match s with
-       |"!" -> if (evalexpr hash hash2 a) == 0 then 1 else 0
-       |"-" -> (evalexpr hash hash2 a) * (-1)
-       |"++" -> (evalexpr hash hash2 a) + 1
-       |"--" -> (evalexpr hash hash2 a) - 1)
+       |"!" -> if (evalexpr hash a) == 0 then 1 else 0
+       |"-" -> (evalexpr hash a) * (-1)
+       |"++" -> (evalexpr hash a) + 1
+       |"--" -> (evalexpr hash a) - 1)
     | Call (s, el) -> (
         match s with
         |"write" ->
                 else
                     begin
                         for i=0 to (List.length el)-1 do
-                            Printf.printf "%i" (evalexpr hash hash2 (List.nth el i));
+                            Printf.printf "%i" (evalexpr hash (List.nth el i));
                             print_newline ();
                         done;
                         1
                     end
-        |s  -> evalstat (Hashtbl.find hash2 s) hash hash2; 1
         |_ -> 1) in
     let l2 = List.length body in
     for i = 0 to l2-1 do
         match (List.nth body i) with
         (* Evaluer une expression avec variable *)
         (* Evaluer un appel a "write" *)
-        |Expr expr -> evalexpr hash hash2 expr
+        |Expr expr -> evalexpr hash expr
         (* Evaluer une affectation *)
-        |Assign (s, expr) -> Hashtbl.replace hash s (evalexpr hash hash2 expr); 1
-        |If (c, i, e) -> if ((evalexpr hash hash2 c) == 0) then evalstat e hash hash2
-        else evalstat i hash hash2; 1
-        |While (c, d) -> while ((evalexpr hash hash2 c) <> 0) do
-            evalstat d hash hash2
+        |Assign (s, expr) -> Hashtbl.replace hash s (evalexpr hash expr); 1
+        |If (c, i, e) -> if ((evalexpr hash c) == 0) then evalstat e hash
+        else evalstat i hash; 1
+        |While (c, d) -> while ((evalexpr hash c) <> 0) do
+            evalstat d hash
                         done;
                         1
     done
     let l = List.length ast.main.mainvars in
     let l2 = List.length ast.func in
     let hash = Hashtbl.create l in
-    let hash2 = Hashtbl.create l2 in
     for i=0 to l-1 do
         Hashtbl.add hash (List.nth ast.main.mainvars i) 0
     done;
-    for i=0 to l2-1 do
-        Hashtbl.add hash2 (List.nth ast.func i).fname (List.nth ast.func i)
-    done;
     (* Evaluation du corps du Main *)
     let body = ast.main.mainbody in
-    evalstat body hash hash2
+    evalstat body hash
 
 
 let main () =
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.