-exception ParsingError of string;;\r
+type term =\r
+ | Var of int\r
+ | App of term * term\r
+ | Lam of term\r
+;;\r
\r
-let mk_app x y = Num.mk_app x y;;\r
-let mk_lam x = `Lam(true, x);;\r
-let mk_var x = `Var(x, -666);;\r
+let mk_app x y = App(x, y);;\r
+let mk_lam x = Lam x;;\r
+let mk_var x = Var x;;\r
+\r
+exception ParsingError of string;;\r
\r
let isAlphaNum c = let n = Char.code c in\r
(48 <= n && n <= 90) || (95 <= n && n <= 122) ;;\r
;;\r
\r
let implode l =\r
- let res = Bytes.create (List.length l) in\r
+ let res = String.create (List.length l) in\r
let rec aux i = function\r
| [] -> res\r
- | c :: l -> Bytes.set res i c; aux (i + 1) l in\r
+ | c :: l -> String.set res i c; aux (i + 1) l in\r
aux 0 l\r
;;\r
\r
\r
*******************************************************************************)\r
\r
-let problem_of_string s =\r
+(* let problem_of_string s =\r
let lines = Str.split (Str.regexp "[\n\r\x0c\t;]+") s in\r
let head, lines = List.hd lines, List.tl lines in\r
let name = String.trim (String.sub head 1 (String.length head - 1)) in\r
let txt = String.concat "\n" (List.rev !lines) in\r
let problems = Str.split (Str.regexp "[\n\r]+\\$") txt in\r
List.map problem_of_string (List.tl (List.map ((^) "$") problems))\r
+;; *)\r
+\r
+let parse x =\r
+ match read_smt ([],[]) (explode x) with\r
+ | Some [y], [], _ -> y\r
+ | _, _, _ -> assert false\r
+;;\r
+\r
+\r
+let parse_many strs =\r
+ let f (x, y) z = match read_smt y (explode z) with\r
+ | Some[tm], [], vars -> (tm :: x, vars)\r
+ | _, _, _ -> assert false\r
+ in let aux = List.fold_left f ([], ([], []))\r
+ in let (tms, (_, free)) = aux strs\r
+ in (List.rev tms, free)\r
;;\r
+type term =\r
+ | Var of int\r
+ | App of term * term\r
+ | Lam of term\r
+\r
exception ParsingError of string\r
\r
-val problem_of_string:\r
+(* val problem_of_string:\r
string ->\r
string (* problem label *)\r
* Num.i_var option (* div *)\r
* Num.i_var option (* div *)\r
* Num.i_n_var list (* conv *)\r
* Num.i_n_var list (* ps *)\r
- * string list (* names of free variables *)) list\r
+ * string list (* names of free variables *)) list *)\r
+\r
+ (* parses a string to a term *)\r
+ val parse: string -> term\r
+ (* parse many strings/terms, and returns the list of parsed terms + the list of free variables; variable 0 is not used *)\r
+ val parse_many: string list -> term list * string list\r