Boolli is a boolean expressions interpreter.
What is Boolli able to do? Saying true
or false
given a boolean expression!
To Boolli, a boolean expression is something generated by this EBNF
grammar:
expr: factor((and | or) factor)*
factor: (not)* factor | boolean | LPAR expr RPAR
boolean: true | false | 0 | 1
Bolli is composed of:
- A lexer
- A parser
- An interpreter
The base data structure is Abstract Syntax Tree
How can it be helpful?
- To understand how to parse a simple grammar
- When you substitute boolean tokens with
Func<bool>
(evenFunc<Task<bool>>
) tokens and define a simple rule system
PM> Install-Package Boolli
var boolli = new Evaluator();
string booleanExpression = "not true and false or (true and false)";
bool result = boolli.EvaluateBooleanExpression(booleanExpression);
You can also use 0
as false
and 1
as true
:
var boolli = new Evaluator();
string booleanExpression = "not 1 and 0 or (true and false)";
bool result = boolli.EvaluateBooleanExpression(booleanExpression);
var boolli = new Evaluator();
bool result = boolli.EvaluateFuncOfBoolExpression(
"f1 and f2",
new NamedBooleanFunction[]
{
new NamedBooleanFunction("f1", () => true),
new NamedBooleanFunction("f2", () => false),
});
var boolli = new Evaluator();
bool result = await boolli.EvaluateFuncOfBoolExpressionAsync(
"f3 and f4",
new NamedAsyncBooleanFunction[]
{
new NamedAsyncBooleanFunction("f3", async () => { await Task.Delay(100); return true; }),
new NamedAsyncBooleanFunction("f4", async () => { await Task.Delay(100); return true; }),
});
I made a very very very simple scenario (if you want you can improve it, thanks 😁) to make a basic rule based alerting system. This is the source code. Run it and tell me what you think!
Simply clone this repository and build the Boolli.sln
solution.
- Report any issues
- Propose new features / improvements
- Just telling your opinion :-)