X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=ocaml%2Fparser.ml;h=fbce730c78915d11457b701ee46691fef2cae988;hb=461dcd3dc0bf5090be9980548bc1874a423dc6cc;hp=ea885d20434283ce72f1405487c8826d9af02a19;hpb=9223a25e0e3079058d498ad21da17296bd6edc82;p=fireball-separation.git diff --git a/ocaml/parser.ml b/ocaml/parser.ml index ea885d2..fbce730 100644 --- a/ocaml/parser.ml +++ b/ocaml/parser.ml @@ -1,8 +1,14 @@ -exception ParsingError of string;; +type term = + | Var of int + | App of term * term + | Lam of term +;; -let mk_app x y = Num.mk_app x y;; -let mk_lam x = `Lam(true, x);; -let mk_var x = `Var(x, -666);; +let mk_app x y = App(x, y);; +let mk_lam x = Lam x;; +let mk_var x = Var x;; + +exception ParsingError of string;; let isAlphaNum c = let n = Char.code c in (48 <= n && n <= 90) || (95 <= n && n <= 122) ;; @@ -30,10 +36,10 @@ let explode s = ;; let implode l = - let res = Bytes.create (List.length l) in + let res = String.create (List.length l) in let rec aux i = function | [] -> res - | c :: l -> Bytes.set res i c; aux (i + 1) l in + | c :: l -> String.set res i c; aux (i + 1) l in aux 0 l ;; @@ -146,7 +152,7 @@ let _ = prerr_endline (">>>" ^ string_of_term (parse "(\\x. x y z z1 k) z1 z j") *******************************************************************************) -let problem_of_string s = +(* let problem_of_string s = let lines = Str.split (Str.regexp "[\n\r\x0c\t;]+") s in let head, lines = List.hd lines, List.tl lines in let name = String.trim (String.sub head 1 (String.length head - 1)) in @@ -241,4 +247,20 @@ let from_file path = let txt = String.concat "\n" (List.rev !lines) in let problems = Str.split (Str.regexp "[\n\r]+\\$") txt in List.map problem_of_string (List.tl (List.map ((^) "$") problems)) +;; *) + +let parse x = + match read_smt ([],[]) (explode x) with + | Some [y], [], _ -> y + | _, _, _ -> assert false +;; + + +let parse_many strs = + let f (x, y) z = match read_smt y (explode z) with + | Some[tm], [], vars -> (tm :: x, vars) + | _, _, _ -> assert false + in let aux = List.fold_left f ([], ([], [])) + in let (tms, (_, free)) = aux strs + in (List.rev tms, free) ;;