Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/augustt198/truth
A boolean expression parser and evaluator
https://github.com/augustt198/truth
Last synced: about 2 months ago
JSON representation
A boolean expression parser and evaluator
- Host: GitHub
- URL: https://github.com/augustt198/truth
- Owner: augustt198
- Created: 2014-10-14T03:43:51.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2021-09-30T06:59:01.000Z (over 3 years ago)
- Last Synced: 2023-08-02T15:35:24.520Z (over 1 year ago)
- Language: Rust
- Homepage:
- Size: 258 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# truth
A boolean expression parser and evaluator.
### Examples:
Expression: **`!A`**
```
> Truth table:
A Result0 1
1 0
> Parsed tree:
Operation { components: [Component { value: Var(A), negated: true }], ops: [] }
> Variables: [A]
```Expression: **`X & Y`**
```
> Truth table:
X Y Result0 0 0
0 1 0
1 0 0
1 1 1
> Parsed tree:
Operation { components: [Component { value: Var(X), negated: false }, Component { value: Var(Y), negated: false }], ops: [Token { token_type: And, col: 3, line: 1 }] }
> Variables: [X, Y]
```Expression: **`(A & B) | (C ^ D)`**
```
> Truth table:
A B C D Result0 0 0 0 0
0 0 0 1 1
0 0 1 0 1
0 0 1 1 0
0 1 0 0 0
0 1 0 1 1
0 1 1 0 1
0 1 1 1 0
1 0 0 0 0
1 0 0 1 1
1 0 1 0 1
1 0 1 1 0
1 1 0 0 1
1 1 0 1 1
1 1 1 0 1
1 1 1 1 1
> Parsed tree:
Operation { components: [Component { value: Expr(Operation { components: [Component { value: Var(A), negated: false }, Component { value: Var(B), negated: false }], ops: [Token { token_type: And, col: 4, line: 1 }] }), negated: false }, Component { value: Expr(Operation { components: [Component { value: Var(C), negated: false }, Component { value: Var(D), negated: false }], ops: [Token { token_type: Xor, col: 14, line: 1 }] }), negated: false }], ops: [Token { token_type: Or, col: 9, line: 1 }] }
> Variables: [A, B, C, D]
```---
**Note:** the AND (`&`), OR (`|`) and XOR (`^`) operators have the same precedence.