Commits

yoshihiro503  committed 3961e1e

gen scheme

  • Participants
  • Parent commits 215e086

Comments (0)

Files changed (7)

 
 - parsing lambda expression
 - generate Scheme code
+(** TODO
 - generate Ruby code
+- generate Javascript code
 - generate OCaml code
 - generate Haskell code
 - generate Gallina(Coq) code
-
+- generate HaXe code
+- generate Scala code
+**)
 
 BUILD:
 	$ sh compile.sh
 
 USAGE:
-	$ echo 'lambda f. lambda x. f x' | ./lambda
+	$ echo 'lambda f. lambda x. f x' | ./run
 #!/bin/sh
 ocamllex lexer.mll
-ocamlc -o lambda util.ml lexer.ml term.ml parserUtil.ml parser.ml main.ml
+ocamlc -o run util.ml lexer.ml term.ml parserUtil.ml parser.ml gen_scheme.ml main.ml
 rm *.cmi *.cmo

File gen_scheme.ml

+open Term
+
+let rec gen = function
+  | Var v -> v
+  | Abs (v, t) -> "(lambda (" ^ v ^ ") " ^ gen t ^ ")"
+  | App (t1, t2) -> "(" ^ gen t1 ^ " " ^ gen t2 ^ ")"
     let ts = tokens [] in
     let tm = Parser.parse ts in
     prerr_endline @@ "parse: " ^ sterm tm;
+    prerr_endline @@ Gen_scheme.gen tm;
   with
-  | Parse.Error -> prerr_endline ("parse error");
+  | Parser.Error msg -> prerr_endline @@ "parse error: " ^ msg;
   | e -> prerr_endline ("ERRR: " ^ Printexc.to_string e)
 open Term
 
 type 'a parser = ('a, token list) ParserUtil.parser
+exception Error of ParserUtil.error_msg
 
 let ident : var parser = function
   | Ident s :: ts -> Inl (s, ts)

File sample/test01.lambda

+lambda f. lambda x. f (f x)

File sample/test02.lambda

+(lambda x. x x) (lambda x. x x)