A terminal based calculator based on pratt's parser and written in D
Run it using dub package manager
dub fetch calcool
dub run calcool
You can also build this repository
cd Calcool
dub --compiler=ldc
Usage: calcool [OPTION] [ARGUMENT]
-h : Print this help message
-i : Set input file (each expression in a separate line)
-c : Calculate the given expression
You can run it without arguments to open an interactive shell.
Add calcool to your dependencies
"dependencies": {
"calcool": "~>1.3.1"
}
Set its subconfiguration to Library
"configurations": [{
"name": "your app's name",
"subConfigurations": {
"calcool": "Library"
}
}]
Use it in your app
import calcool.parser;
auto p = new Prser();
try {
// You can call evaluateFromString as many times as you want
string result = p.evaluateFromString("sin(45*2) - 22 * -exp(3)");
writeln(result);
} catch (CalcoolException ce) {
// CalcoolException means your expression was not valid
stderr.writefln(ce.msg);
} catch (Exception e) {
// Something bad happened! Do what you have to do.
}
GPL-3.0+