From ab5fa70b7bcd91e2399a1aec26c15fe821a9e1ca Mon Sep 17 00:00:00 2001 From: erius Date: Thu, 30 May 2024 01:57:28 +0300 Subject: [PATCH] Removed num module, using external num crate once again, started working on expr module (math expression parser) --- src/expr.rs | 1 + src/expr/bexpr_tree.rs | 19 +++++++++++++++++++ src/lib.rs | 2 +- src/num.rs | 40 ---------------------------------------- src/num/bigint.rs | 35 ----------------------------------- 5 files changed, 21 insertions(+), 76 deletions(-) create mode 100644 src/expr.rs create mode 100644 src/expr/bexpr_tree.rs delete mode 100644 src/num.rs delete mode 100644 src/num/bigint.rs diff --git a/src/expr.rs b/src/expr.rs new file mode 100644 index 0000000..816b347 --- /dev/null +++ b/src/expr.rs @@ -0,0 +1 @@ +mod bexpr_tree; diff --git a/src/expr/bexpr_tree.rs b/src/expr/bexpr_tree.rs new file mode 100644 index 0000000..4456727 --- /dev/null +++ b/src/expr/bexpr_tree.rs @@ -0,0 +1,19 @@ +pub struct BExprTree { + children: Box>> +} + +type BinaryOp = Box T>; +type UnaryOp = Box T>; + +enum Node { + Binary(BinaryOp, Box>, Box>), + Unary(UnaryOp, Box>), + Token(T) +} + +#[cfg(test)] +mod tests { + use super::*; + + +} diff --git a/src/lib.rs b/src/lib.rs index 41b0a1d..c0db143 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,2 +1,2 @@ -pub mod num; +pub mod expr; pub mod matrix; diff --git a/src/num.rs b/src/num.rs deleted file mode 100644 index 628c2a2..0000000 --- a/src/num.rs +++ /dev/null @@ -1,40 +0,0 @@ -mod bigint; - -use std::ops::*; - -pub trait Signed: Neg {} -pub trait NumOps: Sized + Add + Sub + Mul + Div {} -pub trait NumAssignOps: AddAssign + SubAssign + MulAssign + DivAssign {} -pub trait Num: PartialEq + Default + NumOps + NumAssignOps {} - -macro_rules! impl_num { - ($t:ty) => { - impl NumOps for $t {} - impl NumAssignOps for $t {} - impl Num for $t {} - }; -} - -macro_rules! impl_sign_num { - ($t:ty) => { - impl_num!($t); - impl Signed for $t {} - }; -} - -impl_num!(u8); -impl_num!(u16); -impl_num!(u32); -impl_num!(u64); -impl_num!(u128); -impl_num!(usize); - -impl_sign_num!(i8); -impl_sign_num!(i16); -impl_sign_num!(i32); -impl_sign_num!(i64); -impl_sign_num!(i128); -impl_sign_num!(isize); - -impl_sign_num!(f32); -impl_sign_num!(f64); diff --git a/src/num/bigint.rs b/src/num/bigint.rs deleted file mode 100644 index 867b4a7..0000000 --- a/src/num/bigint.rs +++ /dev/null @@ -1,35 +0,0 @@ -pub struct BigInt { - negative: bool, - num: BigUInt -} - -pub struct BigUInt { - data: Vec -} - -impl BigUInt { - pub fn new() -> Self { - Self::new_from(0) - } - - pub fn new_from(num: u64) -> Self { - Self { data: vec![num] } - } -} - -impl BigInt { - pub fn new() -> Self { - Self { negative: false, num: BigUInt::new() } - } - - pub fn new_from(num: i64) -> Self { - let (negative, num) = if num < 0 { (true, -num as u64) } - else { (false, num as u64) }; - Self { negative, num: BigUInt::new_from(num) } - } -} - -#[cfg(test)] -mod tests { - -}