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;
(*    while true do
      let t =  Lexer.token lexbuf in
      prerr_endline (stoken t);
      flush stderr;
    done
*)
  with
  | Lexer.Eof ->
      prerr_endline "eof"; exit 0
  | e -> prerr_endline ( "ERRR: " ^ Printexc.to_string e)