Commits

Anonymous committed 3961e1e

gen scheme

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
+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)

sample/test01.lambda

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

sample/test02.lambda

+(lambda x. x x) (lambda x. x x)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.