We'll use OCamlbuild from OCaml 3.12.1, rely on findlib/ocamlfind, use a few modules from the standard library that are not made available by default.
The code will take a fairly simple expression on the command-line and evaluate it:
% ./calc '3+4'
3 + 4 = 12
% ./calc '7/3'
7 /3 = 2
We'll start with a simple code which simply prints its first command-line argument to stdout:
% cat calc.ml
let () =
print_endline Sys.argv.(0)
The 'let () =' constructs makes it possible to evaluate the corresponding code at startup. We can compile the code with ocamlc or ocamlopt:
ocamlopt calc.ml -o calc
We can also compile with ocamlbuild very easily:
ocamlbuild calc.native
Unlike with ocamlopt, we don't completely control the name of the output file: if we ask ocamlbuild for '.native', it will use native-code compilation with ocamlopt and if we ask it for '.byte' instead, it will use bytecode compilation with ocamlc.
Now we'll split the