-
Notifications
You must be signed in to change notification settings - Fork 8
/
impdriver.ml
37 lines (33 loc) · 993 Bytes
/
impdriver.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
open Imp
let explode s =
let rec exp i l =
if i < 0 then l else exp (i - 1) (s.[i] :: l) in
exp (String.length s - 1) [];;
let test s =
print_endline s;
let parse_res = parse (explode s) in
(match parse_res with
NoneE _ -> print_endline ("Syntax error");
| SomeE (c, _) ->
let fuel = 1000 in
match (ceval_step empty_state c fuel) with
None ->
print_endline
("Still running after " ^ string_of_int fuel ^ " steps")
| Some res ->
print_endline (
"Result: ["
^ string_of_int (res ['w']) ^ " "
^ string_of_int (res ['x']) ^ " "
^ string_of_int (res ['y']) ^ " "
^ string_of_int (res ['z']) ^ " ...]"));
print_newline();
;;
test "x:=1 ;; y:=2";;
test "true";; (* syntax error *)
test "SKIP";;
test "SKIP;;SKIP";;
test "WHILE true DO SKIP END";;
test "x:=3";;
test "x:=3;; WHILE 0<=x DO SKIP END";;
test "x:=3;; WHILE 1<=x DO y:=y+1;; x:=x-1 END";;