Just a simple evaluator/interpretter based on an AST
- just clone the repo
cdtherecargo build
Important
All characters in an expression must be lower case
Operator Character AND & OR | NOT ! XOR ^
Literal Value true true 1 true false false 0 false
- Any expression can be wrapped in
(...)to make a group
a-zare identifiers if they are not part of a literal- each identifier can be true or false
- identifiers are placeholders that get a value during evaluation
- they resemble the state of an hypotetical bus
- the evaluator handles them not strictly so if you use
a&c&e&awill be the first bit,cthe second andethe third so there will overall be still only7variants not a..e (1-5)63variants - during truth table generation each identifier combination gets evaluated
| Priority | Operator | Symbol(s) |
|---|---|---|
| Highest | NOT | ¬, ̄, ! |
| AND | ∧, · | |
| OR | ∨, + | |
| XOR | ⊕, ⊻ | |
| Lowest | EQUALS | =, ≡, ↔, ⇔ |
Prints the help
Evaluates a pure bool expression, no identifiers, for example "true^false"
Evaluates all posible combinations of expression and prints it as a truth table
You can optionally add a-fXOR-tflags to filter for-f=false,-t=trueresults only
> .\booleval -T "a^b"
╭───────┬───────┬────────╮
│ b │ a │ Result │
├───────┼───────┼────────┤
│ false │ false │ false │
│ false │ true │ true │
│ true │ false │ true │
│ true │ true │ false │
╰───────┴───────┴────────╯Evaluates the specefied expression with a specified identifier state
> booleval -t 111 "a&b&c"
true
# ...args = binary string each bit mapping to 1 identifier (a = 1, b = 1, c = 1) = 111
> booleval -t 7 "a&b&c"
true
# ...args = numeric string each bit mapping to 1 identifier (a = 1, b = 1, c = 1) = 111 = 7
> booleval -t true true true "a&b&c"
#OR
> booleval -t 1 1 1 "a&b&c"
true
# ...args = boolean string each mapping to 1 bit (a = 1, b = 1, c = 1) = true true true or 1 1 1Prints the ast for the boolean expression, identifiers are allowed
# Default
> booleval -a "a|b"
|
/ \
/ \
/ \
a b
# Pretty
> booleval -a "a|b" -p
|
┌┴┐
a b
# Extended
> booleval -a "a|b" -e
OR
/ \
/ \
/ \
a b
# Extended & Pretty
> booleval -a "a|b" -ep
OR
┌┴┐
a bMore Complex example: 2-4 Muliplexer
"(!a & !b & c) | (!a & b & d) | (a & !b & e) | (a & b & f)"where a & b are the selector bits and c, d, e and f are the value bits
> booleval -a "(!a & !b & c) | (!a & b & d) | (a & !b & e) | (a & b & f)" -pe
OR
┌─────┴──────┐
OR GRP
┌─────┴─────┐ │
OR GRP AND
┌───┴────┐ │ ┌┴─┐
GRP GRP AND AND f
│ │ ┌─┴──┐ ┌┴┐
AND AND AND e a b
┌──┴──┐ ┌─┴─┐ ┌┴┐
AND c AND d a NOT
┌─┴─┐ ┌─┴─┐ │
NOT NOT NOT b b
│ │ │
a b a