Removed num module, using external num crate once again, started working on expr module (math expression parser)

This commit is contained in:
Egor 2024-05-30 01:57:28 +03:00
parent 182f73db27
commit ab5fa70b7b
5 changed files with 21 additions and 76 deletions

1
src/expr.rs Normal file
View file

@ -0,0 +1 @@
mod bexpr_tree;

19
src/expr/bexpr_tree.rs Normal file
View file

@ -0,0 +1,19 @@
pub struct BExprTree<T> {
children: Box<Vec<Node<T>>>
}
type BinaryOp<T> = Box<dyn Fn(T, T) -> T>;
type UnaryOp<T> = Box<dyn Fn(T) -> T>;
enum Node<T> {
Binary(BinaryOp<T>, Box<Node<T>>, Box<Node<T>>),
Unary(UnaryOp<T>, Box<Node<T>>),
Token(T)
}
#[cfg(test)]
mod tests {
use super::*;
}

View file

@ -1,2 +1,2 @@
pub mod num;
pub mod expr;
pub mod matrix;

View file

@ -1,40 +0,0 @@
mod bigint;
use std::ops::*;
pub trait Signed: Neg {}
pub trait NumOps<Rhs = Self>: Sized + Add<Rhs> + Sub<Rhs> + Mul<Rhs> + Div<Rhs> {}
pub trait NumAssignOps<Rhs = Self>: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> {}
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);

View file

@ -1,35 +0,0 @@
pub struct BigInt {
negative: bool,
num: BigUInt
}
pub struct BigUInt {
data: Vec<u64>
}
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 {
}