OCaml CAS requires the opam packages async
, base
, core
.
To get started, run
dune exec -- ./main.exe <port>
and to connect, (if you have nc
installed), run
nc localhost <port>
> 3+4
7.
> ...
Most of the project lies within the ./cas
directory.
cas
├── expr
│ ├── dune
│ ├── expr.ml
│ └── expr.mli
├── parser
│ ├── dune
│ ├── parser.ml
│ └── parser.mli
├── repl
│ ├── dune
│ ├── engine.ml
│ ├── engine.mli
│ ├── eval.ml
│ ├── eval.mli
│ ├── repl.ml
│ ├── repl_state.ml
│ └── repl_state.mli
└── tokenizer
├── dune
├── tokenizer.ml
└── tokenizer.mli
The parser
and tokenizer
moduels are used to parse input strings into syntax trees. The expr
module defines an expression tree and a function to convert a syntax tree into an expression tree. Finally, the repl
module contains eval.ml
, which takes an expression tree and evaluates it.
-
To add a new function or constant, simply add it into
repl_state.ml
(with the right classification ofFunction
orConstant
), and in theeval.ml
module, implement how it should be evaluated. -
To add a new gramamr rule, go into
parser.ml
and modify theget_substitution
function to add a new grammar rule. The available substitutions are defined intype substitution
. If a new substitution type is added, make sure to implement how it should be matched in theperform_sub
function (as well as how the resulting syntax tree should be constructed).
- Support user defined constants and functions
- Symbolic calculations (partially implemented)
- Integrate arbitrary precision numbers
- Expression tree simplifications