feat: add a propositional logic expression tree

This commit is contained in:
Anand Balakrishnan 2023-03-17 13:51:50 -07:00
parent fcb4dc9740
commit 32d92df549
No known key found for this signature in database
3 changed files with 55 additions and 14 deletions

View file

@ -6,3 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
[dev-dependencies]
proptest = "1.1.0"

51
argus-core/src/expr.rs Normal file
View 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 {}

View file

@ -1,14 +1 @@
pub fn add(left: usize, right: usize) -> usize { pub mod expr;
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}