This commit is contained in:
swrup 2025-11-11 02:07:51 +01:00
parent aa2ff7b2f0
commit 2f3113f55d
11742 changed files with 1223940 additions and 0 deletions

View file

@ -0,0 +1 @@
let () = Calc.Cli.main ()

View file

@ -0,0 +1,3 @@
(executable
(public_name calc)
(libraries calc))

View file

@ -0,0 +1,27 @@
let rec eval = function Ast.Int n -> n | Add (a, b) -> eval a + eval b
let info = Cmdliner.Cmd.info "calc"
let eval_lb lb =
let e = Parser.main Lexer.token lb in
Printf.printf "%d\n" (eval e)
let repl () =
while true do
Printf.printf ">> %!";
let lb = Lexing.from_channel Stdlib.stdin in
eval_lb lb
done
let term =
let open Cmdliner.Term.Syntax in
let+ expr_opt =
let open Cmdliner.Arg in
value & opt (some string) None & info [ "e" ]
in
match expr_opt with
| Some s -> eval_lb (Lexing.from_string s)
| None -> repl ()
let cmd = Cmdliner.Cmd.v info term
let main () = Cmdliner.Cmd.eval cmd |> Stdlib.exit

View file

@ -0,0 +1,8 @@
(library
(name calc)
(libraries cmdliner))
(ocamllex lexer)
(menhir
(modules parser))

View file

@ -0,0 +1,2 @@
$ calc -e '1+2'
3

View file

@ -0,0 +1,2 @@
(cram
(deps %{bin:calc}))