This repository has been archived on 2024-01-18. You can view files and clone it, but cannot push or open issues or pull requests.
compilation/tp/tp-menhir/code/marthe.ml

37 lines
794 B
OCaml
Raw Permalink Normal View History

2023-10-02 09:39:12 +02:00
let rec interactive_loop () =
welcome_message ();
let rec loop () =
2023-10-02 09:57:43 +02:00
try
2023-10-02 09:39:12 +02:00
read () |> eval |> print
2023-10-02 09:57:43 +02:00
with End_of_file -> print_newline ()
| exn ->
Printf.printf "Error: %s\n%!" (Printexc.to_string exn);
loop ()
2023-10-02 09:39:12 +02:00
in
loop ()
and welcome_message () =
Printf.printf "
====================================================\n
Welcome to the incredible Marthe interactive loop! \n
====================================================\n
"
and read () =
2023-10-02 09:57:43 +02:00
prompt (); input_line stdin |> parse
2023-10-02 09:39:12 +02:00
2023-10-02 09:57:43 +02:00
and prompt () =
2023-10-02 09:39:12 +02:00
Printf.printf "> %!"
and parse input =
let lexbuf = Lexing.from_string input in
Parser.phrase Lexer.token lexbuf
and print e =
Printf.printf ":- %s\n%!" (Printer.string_of_exp e)
and eval e =
e
let main = interactive_loop ()