(* File: ddktoploop.ml Author: Scott Smith This file allows interactive testing of your interpreter using the DDK. Before this file can be #use-d you need to execute make byte from the src/ directory of the DDK-1.1 distribution. *) (* First load all the relevant compiled structs. These commands assume ocaml was launched from src/D/ directory. If not, do a # #cd "my/directory/src/D";; to get there. *) #load "dast.cmo";; #load "dparser.cmo";; #load "dlexer.cmo";; #load "dpp.cmo";; #load "dinterp.cmo";; (* Make some structs available at the top for easier use *) open Dast;; open Dinterp;; (* function parse parses DST concrete syntax you enter as a string *) let parse s = let lexbuf = Lexing.from_string s in Dparser.main Dlexer.token lexbuf;; (* Function pp is a top-loop pretty printer using DDK's pretty printer *) let pp e = print_string (Dpp.pretty_print e);; (* ppeval evals then pretty prints the result *) let ppeval x = print_string "==> ";pp (eval x);; (* function rep is a read-eval-print function for D programs *) let rep s = ppeval (parse s);; (* Examples. *) let s1 = "Let Rec x1 x2 = If x2 = 1 Then (Function x3 -> x3 (x2 - 1)) (Function x4 -> x4) Else x1 (x2 - 1) In x1 100";; let ex1 = parse s1;; let result1 = eval ex1;; pp result1;; ppeval ex1;; rep s1;;