1 个不稳定版本
使用旧的 Rust 2015
0.0.1 | 2014年11月21日 |
---|
#14 in #var
13KB
353 行
truth
一个布尔表达式解析器和评估器。
示例
表达式:!A
> Truth table:
A Result
0 1
1 0
> Parsed tree:
Operation { components: [Component { value: Var(A), negated: true }], ops: [] }
> Variables: [A]
表达式:X & Y
> Truth table:
X Y Result
0 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]
表达式:(A & B) | (C ^ D)
> Truth table:
A B C D Result
0 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]
注意:与(&
)、或(|
)和异或(^
)运算符具有相同的优先级。