feat: add a propositional logic expression tree
This commit is contained in:
parent
fcb4dc9740
commit
32d92df549
3 changed files with 55 additions and 14 deletions
|
|
@ -6,3 +6,6 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
|
||||
[dev-dependencies]
|
||||
proptest = "1.1.0"
|
||||
|
|
|
|||
51
argus-core/src/expr.rs
Normal file
51
argus-core/src/expr.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/// All expressions that are numeric
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum NumExpr {
|
||||
IntLit(i64),
|
||||
UIntLit(u64),
|
||||
FloatLit(f64),
|
||||
IntVar { name: String },
|
||||
UIntVar { name: String },
|
||||
FloatVar { name: String },
|
||||
|
||||
Neg { arg: Box<NumExpr> },
|
||||
Add { args: Vec<NumExpr> },
|
||||
Mul { args: Vec<NumExpr> },
|
||||
Div { dividend: Box<NumExpr>, divisor: Box<NumExpr> },
|
||||
}
|
||||
|
||||
/// Types of comparison operations
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum Ordering {
|
||||
Eq,
|
||||
NotEq,
|
||||
Less { strict: bool },
|
||||
Greater { strict: bool },
|
||||
}
|
||||
|
||||
/// All expressions that are evaluated to be of type `bool`
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum BoolExpr {
|
||||
BoolLit(bool),
|
||||
BoolVar {
|
||||
name: String,
|
||||
},
|
||||
Cmp {
|
||||
op: Ordering,
|
||||
lhs: Box<NumExpr>,
|
||||
rhs: Box<NumExpr>,
|
||||
},
|
||||
Not {
|
||||
arg: Box<BoolExpr>,
|
||||
},
|
||||
And {
|
||||
args: Vec<BoolExpr>,
|
||||
},
|
||||
Or {
|
||||
args: Vec<BoolExpr>,
|
||||
},
|
||||
}
|
||||
|
||||
/// Expression builder
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ExprBuilder {}
|
||||
|
|
@ -1,14 +1 @@
|
|||
pub fn add(left: usize, right: usize) -> usize {
|
||||
left + right
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = add(2, 2);
|
||||
assert_eq!(result, 4);
|
||||
}
|
||||
}
|
||||
pub mod expr;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue