Source

lambda-translator / main.ml

(**
  $ ocamllex lexer.mll
  $ ocamlc lexer.ml main.ml
**)

open Util
open Lexer
open Parser
open Term

let stoken = function
  | Lambda -> "LAMBDA"
  | Dot -> "DOT"
  | Ident s -> "var:" ^ s
  | Open -> "OPEN"
  | Close -> "CLOSE"
  | Int i -> "int:" ^ string_of_int i
  | EOL -> "EOL"

let _ =
  try
    let lexbuf = Lexing.from_channel stdin in
    let rec tokens store =
      try tokens (Lexer.token lexbuf :: store) with
      | Lexer.Eof -> List.rev store
    in
    let ts = tokens [] in
    let tm = Parser.parse ts in
    prerr_endline @@ "parse: " ^ sterm tm;
    prerr_newline ();
    prerr_endline @@ " -- scheme code";
    prerr_endline @@ Gen_scheme.gen tm;

    prerr_newline ();
    prerr_endline @@ " -- ruby code";
    prerr_endline @@ Gen_ruby.gen tm;

    prerr_newline ();
    prerr_endline @@ " -- javascript code";
    prerr_endline @@ Gen_javascript.gen tm;

  with
  | Parser.Error msg -> prerr_endline @@ "parse error: " ^ msg;
  | e -> prerr_endline ("ERRR: " ^ Printexc.to_string e)