-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimpdriver.ml
37 lines (33 loc) · 996 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_newline();
print_endline ("Propgram: " ^ 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_st 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']) ^ " ...]"))
;;
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";;